From 71fc68289a1ed38f2c997264b3a59f21643140df Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Thu, 29 Sep 2022 18:39:22 +0100 Subject: [PATCH 1/4] Add timeout option for availableUrl check --- src/autostake/NetworkRunner.mjs | 6 ++---- src/autostake/index.mjs | 2 +- src/utils/Network.mjs | 4 ++-- src/utils/QueryClient.mjs | 11 +++++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/autostake/NetworkRunner.mjs b/src/autostake/NetworkRunner.mjs index 6a3fcf2c..f2c4821c 100644 --- a/src/autostake/NetworkRunner.mjs +++ b/src/autostake/NetworkRunner.mjs @@ -11,7 +11,7 @@ export default class NetworkRunner { this.operator = operator this.signingClient = signingClient this.queryClient = network.queryClient - this.opts = { + this.opts = _.merge({ batchPageSize: 100, batchQueries: 25, batchTxs: 50, @@ -19,9 +19,7 @@ export default class NetworkRunner { queryTimeout: network.data.autostake?.delegatorTimeout || 5000, // deprecate delegatorTimeout queryThrottle: 100, gasModifier: 1.1, - ...network.data.autostake, - ...opts - } + }, network.data.autostake, opts) this.batch = {} this.messages = [] this.processed = {} diff --git a/src/autostake/index.mjs b/src/autostake/index.mjs index 3a78b342..1fecb1f7 100644 --- a/src/autostake/index.mjs +++ b/src/autostake/index.mjs @@ -132,7 +132,7 @@ export default function Autostake(mnemonic, opts) { if (!network.authzSupport) return timeStamp('No Authz support') - await network.connect() + await network.connect({ timeout: opts.delegationsTimeout || 20000 }) const { restUrl, usingDirectory } = network diff --git a/src/utils/Network.mjs b/src/utils/Network.mjs index b9236d36..8b47b272 100644 --- a/src/utils/Network.mjs +++ b/src/utils/Network.mjs @@ -102,9 +102,9 @@ class Network { this.txTimeout = this.data.txTimeout || 60_000 } - async connect() { + async connect({ timeout }) { try { - this.queryClient = await QueryClient(this.chain.chainId, this.restUrl) + this.queryClient = await QueryClient(this.chain.chainId, this.restUrl, { connectTimeout: timeout }) this.restUrl = this.queryClient.restUrl this.connected = this.queryClient.connected && (!this.usingDirectory || this.connectedDirectory()) } catch (error) { diff --git a/src/utils/QueryClient.mjs b/src/utils/QueryClient.mjs index 56f01388..c237e9e1 100644 --- a/src/utils/QueryClient.mjs +++ b/src/utils/QueryClient.mjs @@ -1,8 +1,11 @@ import axios from "axios"; import _ from "lodash"; -const QueryClient = async (chainId, restUrls) => { - let restUrl = await findAvailableUrl(restUrls, "rest") +const QueryClient = async (chainId, restUrls, opts) => { + const config = _.merge({ + connectTimeout: 10000, + }, opts) + const restUrl = await findAvailableUrl(restUrls, "rest", { timeout: config.connectTimeout }) const getAllValidators = (pageSize, opts, pageCallback) => { return getAllPages((nextKey) => { @@ -209,7 +212,7 @@ const QueryClient = async (chainId, restUrls) => { return pages; }; - async function findAvailableUrl(urls, type) { + async function findAvailableUrl(urls, type, { timeout }) { if(!urls) return if (!Array.isArray(urls)) { @@ -223,7 +226,7 @@ const QueryClient = async (chainId, restUrls) => { return Promise.any(urls.map(async (url) => { url = url.replace(/\/$/, '') try { - let data = await axios.get(url + path, { timeout: 10000 }) + let data = await axios.get(url + path, { timeout }) .then((res) => res.data) if (type === "rpc") data = data.result; if (data.block?.header?.chain_id === chainId) { From 9bd781c66704f2c3b3cba2a344c5df6478a54845 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Thu, 29 Sep 2022 00:31:47 +0100 Subject: [PATCH 2/4] Link directly to validator profile tabs --- src/components/ValidatorModal.js | 16 +++++++++++----- src/index.js | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/ValidatorModal.js b/src/components/ValidatorModal.js index a0609685..38b57a2a 100644 --- a/src/components/ValidatorModal.js +++ b/src/components/ValidatorModal.js @@ -19,24 +19,30 @@ import ValidatorGrants from './ValidatorGrants'; function ValidatorModal(props) { const { redelegate, undelegate, validator, delegations, operators, network, validators, grants } = props - const [selectedValidator, setSelectedValidator] = useState(!redelegate && validator); - const [activeTab, setActiveTab] = useState(); const navigate = useNavigate() const params = useParams(); + const [selectedValidator, setSelectedValidator] = useState(!redelegate && validator); + const [activeTab, setActiveTab] = useState(params.section); useEffect(() => { if(params.network !== network.name) return - if (props.show && selectedValidator && validator?.operator_address === selectedValidator.operator_address && params.validator !== selectedValidator.operator_address) { - navigate(`/${network.name}/${selectedValidator.operator_address}`) + const shouldShow = props.show && selectedValidator && validator?.operator_address === selectedValidator.operator_address + const shouldChangeValidator = params.validator !== selectedValidator?.operator_address + const shouldChangeTab = activeTab === 'profile' ? !!params.section : params.section !== activeTab + const shouldChangeUrl = shouldShow && (shouldChangeValidator || shouldChangeTab) + if (shouldChangeUrl) { + navigate(`/${network.name}/${selectedValidator.operator_address}${activeTab === 'profile' ? '' : `/${activeTab}`}`) } else if (params.validator && props.show === false) { navigate(`/${network.name}`) } - }, [props.show, params.validator, selectedValidator]) + }, [props.show, params.validator, params.section, activeTab, selectedValidator]) useEffect(() => { if (props.activeTab && props.activeTab != activeTab) { setActiveTab(props.activeTab) + } else if (params.section && params.section != activeTab) { + setActiveTab(params.section) } else if (redelegate || undelegate) { setActiveTab('delegate') } else if (!activeTab) { diff --git a/src/index.js b/src/index.js index 2531b46b..9b6914ab 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,7 @@ const app = ( } /> } /> } /> + } /> From aa8ced443ee145107df3ab713b5527e1964b74a4 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 30 Sep 2022 15:14:17 +0100 Subject: [PATCH 3/4] Update Chihuahua gas prices --- src/networks.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/networks.json b/src/networks.json index 468b357e..3b593eca 100644 --- a/src/networks.json +++ b/src/networks.json @@ -21,8 +21,9 @@ }, { "name": "chihuahua", - "gasPrice": "0.025uhuahua", - "ownerAddress": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz" + "ownerAddress": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz", + "gasPrice": "1uhuahua", + "gasPricePrefer": "1uhuahua" }, { "name": "gravitybridge", From 12b8d1df64a69f1b302d619a3f5021fc8720683f Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 30 Sep 2022 15:25:26 +0100 Subject: [PATCH 4/4] Handle no opts for connect --- src/utils/Network.mjs | 4 ++-- src/utils/QueryClient.mjs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/Network.mjs b/src/utils/Network.mjs index 8b47b272..7be0eabc 100644 --- a/src/utils/Network.mjs +++ b/src/utils/Network.mjs @@ -102,9 +102,9 @@ class Network { this.txTimeout = this.data.txTimeout || 60_000 } - async connect({ timeout }) { + async connect(opts) { try { - this.queryClient = await QueryClient(this.chain.chainId, this.restUrl, { connectTimeout: timeout }) + this.queryClient = await QueryClient(this.chain.chainId, this.restUrl, { connectTimeout: opts?.timeout }) this.restUrl = this.queryClient.restUrl this.connected = this.queryClient.connected && (!this.usingDirectory || this.connectedDirectory()) } catch (error) { diff --git a/src/utils/QueryClient.mjs b/src/utils/QueryClient.mjs index c237e9e1..f645a0fc 100644 --- a/src/utils/QueryClient.mjs +++ b/src/utils/QueryClient.mjs @@ -212,7 +212,7 @@ const QueryClient = async (chainId, restUrls, opts) => { return pages; }; - async function findAvailableUrl(urls, type, { timeout }) { + async function findAvailableUrl(urls, type, opts) { if(!urls) return if (!Array.isArray(urls)) { @@ -223,6 +223,7 @@ const QueryClient = async (chainId, restUrls, opts) => { } } const path = type === "rest" ? "/blocks/latest" : "/block"; + const { timeout } = opts || {} return Promise.any(urls.map(async (url) => { url = url.replace(/\/$/, '') try {