Skip to content

Commit

Permalink
Merge origin/master into add-leap-wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Oct 3, 2022
2 parents 9325413 + b16295b commit c1cf93e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/autostake/NetworkRunner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ 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,
delegationsTimeout: 20000,
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 = {}
Expand Down
2 changes: 1 addition & 1 deletion src/autostake/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 11 additions & 5 deletions src/components/ValidatorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const app = (
<Route path="/:network/govern/:proposalId" element={<NetworkFinder />} />
<Route path="/:network/grant" element={<NetworkFinder />} />
<Route path="/:network/:validator" element={<NetworkFinder />} />
<Route path="/:network/:validator/:section" element={<NetworkFinder />} />
</Routes>
</BrowserRouter>
</React.StrictMode>
Expand Down
5 changes: 3 additions & 2 deletions src/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
},
{
"name": "chihuahua",
"gasPrice": "0.025uhuahua",
"ownerAddress": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz"
"ownerAddress": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz",
"gasPrice": "1uhuahua",
"gasPricePrefer": "1uhuahua"
},
{
"name": "gravitybridge",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class Network {
this.txTimeout = this.data.txTimeout || 60_000
}

async connect() {
async connect(opts) {
try {
this.queryClient = await QueryClient(this.chain.chainId, this.restUrl)
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) {
Expand Down
12 changes: 8 additions & 4 deletions src/utils/QueryClient.mjs
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -209,7 +212,7 @@ const QueryClient = async (chainId, restUrls) => {
return pages;
};

async function findAvailableUrl(urls, type) {
async function findAvailableUrl(urls, type, opts) {
if(!urls) return

if (!Array.isArray(urls)) {
Expand All @@ -220,10 +223,11 @@ const QueryClient = async (chainId, restUrls) => {
}
}
const path = type === "rest" ? "/blocks/latest" : "/block";
const { timeout } = opts || {}
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) {
Expand Down

0 comments on commit c1cf93e

Please sign in to comment.