From 2ee2cdad5efb3c9bb772317417ee42736d0836fb Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 25 Nov 2022 12:41:07 +0000 Subject: [PATCH 1/2] Reject grants with an empty string denyList --- src/autostake/NetworkRunner.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autostake/NetworkRunner.mjs b/src/autostake/NetworkRunner.mjs index 53c29552..d91f6d39 100644 --- a/src/autostake/NetworkRunner.mjs +++ b/src/autostake/NetworkRunner.mjs @@ -167,7 +167,7 @@ export default class NetworkRunner { if(allow_list?.address){ grantValidators = allow_list?.address || [] }else if(deny_list?.address){ - grantValidators = deny_list.address.includes(validatorAddress) ? [] : [validatorAddress] + grantValidators = deny_list.address.includes(validatorAddress) || deny_list.address.includes('') ? [] : [validatorAddress] }else{ grantValidators = [] } From be048eb885d863f61f2c640cb5bd82b9e03eb6fb Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 25 Nov 2022 12:43:34 +0000 Subject: [PATCH 2/2] Improve UI for invalid grants --- src/components/Delegations.js | 12 +++++++++--- src/components/Grants.js | 6 ++++-- src/components/ValidatorStake.js | 10 ++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/Delegations.js b/src/components/Delegations.js index e820dc38..09b79f12 100644 --- a/src/components/Delegations.js +++ b/src/components/Delegations.js @@ -221,9 +221,15 @@ class Delegations extends React.Component { const { claimGrant, stakeGrant } = parseGrants(grants, grantee, granter) let grantValidators, maxTokens; if (stakeGrant) { - grantValidators = - stakeGrant.authorization.allow_list?.address; - maxTokens = stakeGrant.authorization.max_tokens + const { allow_list, deny_list, max_tokens } = stakeGrant.authorization + if (allow_list?.address) { + grantValidators = allow_list?.address || [] + } else if (deny_list?.address) { + grantValidators = deny_list.address.includes('') ? [] : this.props.validators.map(el => el.address).filter(address => !deny_list.address.includes(address)) + } else { + grantValidators = [] + } + maxTokens = max_tokens } return { claimGrant: claimGrant, diff --git a/src/components/Grants.js b/src/components/Grants.js index b18e151c..59fe13df 100644 --- a/src/components/Grants.js +++ b/src/components/Grants.js @@ -96,12 +96,14 @@ function Grants(props) { const maxTokens = grant.authorization.max_tokens switch (grant.authorization['@type']) { case "/cosmos.staking.v1beta1.StakeAuthorization": + const restrictionType = grant.authorization.allow_list ? 'Validators' : 'Denied Validators' + const restrictionList = grant.authorization.allow_list || grant.authorization.deny_list return ( Maximum: {maxTokens ? : 'unlimited'}
- Validators: {grant.authorization.allow_list.address.map(address => { + {restrictionType}: {restrictionList.address.map(address => { const validator = validators[address] - return
{validator?.moniker ||
}
+ return address ?
{validator?.moniker ||
}
: null })}
) diff --git a/src/components/ValidatorStake.js b/src/components/ValidatorStake.js index 4cb85f5e..324601f1 100644 --- a/src/components/ValidatorStake.js +++ b/src/components/ValidatorStake.js @@ -328,10 +328,12 @@ function ValidatorStake(props) { {!props.isLoading('grants') ? ( grantsValid ? Active
expires {expiryDate().fromNow()}
- : grantsExist - ? maxTokens && smaller(maxTokens, reward) - ? Not enough grant remaining - : Invalid / total delegation reached + : grantsExist + ? !validatorGrants.validators.includes(validator.address) + ? Grant invalid + : maxTokens && smaller(maxTokens, reward) + ? Not enough grant remaining + : Invalid / total delegation reached : network.authzSupport ? Inactive : Authz not supported ) : (