Skip to content

Commit

Permalink
Merge pull request #525 from eco-stake/fix-full-grant-lookup
Browse files Browse the repository at this point in the history
UI: Set all grants properly if supported
  • Loading branch information
tombeynon authored Jun 15, 2022
2 parents a9d53c6 + 3783ab8 commit b7f52f6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/components/Delegations.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ class Delegations extends React.Component {
let allGrants
try {
allGrants = await this.props.queryClient.getGranterGrants(this.props.address)
this.setAllGrants(allGrants, this.orderedOperators(), this.props.address)
return
} catch (e) { console.log('Failed to get all grants in batch') }

const calls = this.orderedOperators().map((operator) => {
return () => {
const { botAddress } = operator;
if (!this.props.operators.includes(operator)) return;
if(allGrants) return new Promise(() => this.setGrants(allGrants, botAddress, this.props.address))

return this.props.queryClient.getGrants(botAddress, this.props.address).then(
(result) => {
Expand All @@ -180,20 +181,33 @@ class Delegations extends React.Component {
}
}

setGrants(grants, grantee, granter){
buildGrants(grants, grantee, granter){
const { claimGrant, stakeGrant } = parseGrants(grants, grantee, granter)
let grantValidators, maxTokens;
if (stakeGrant) {
grantValidators =
stakeGrant.authorization.allow_list?.address;
maxTokens = stakeGrant.authorization.max_tokens
}
const operatorGrant = {
return {
claimGrant: claimGrant,
stakeGrant: stakeGrant,
validators: grantValidators,
maxTokens: maxTokens ? bignumber(maxTokens.amount) : null
};
}

setAllGrants(grants, operators, granter){
const operatorGrants = operators.reduce((sum, operator) => {
const grantee = operator.botAddress
sum[grantee] = this.buildGrants(grants, grantee, granter)
return sum
}, {})
this.setState({operatorGrants: operatorGrants})
}

setGrants(grants, grantee, granter){
const operatorGrant = this.buildGrants(grants, grantee, granter)
this.setState((state, props) => ({
operatorGrants: _.set(
state.operatorGrants,
Expand Down

0 comments on commit b7f52f6

Please sign in to comment.