Skip to content

Commit

Permalink
Merge pull request #682 from eco-stake/handle-invalid-grant-deny-list
Browse files Browse the repository at this point in the history
Handle invalid grant deny list
  • Loading branch information
tombeynon authored Nov 25, 2022
2 parents df43d6f + be048eb commit 16c9461
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/autostake/NetworkRunner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}
Expand Down
12 changes: 9 additions & 3 deletions src/components/Delegations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/components/Grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<small>
Maximum: {maxTokens ? <Coins coins={maxTokens} asset={network.baseAsset} fullPrecision={true} hideValue={true} /> : 'unlimited'}<br />
Validators: {grant.authorization.allow_list.address.map(address => {
{restrictionType}: {restrictionList.address.map(address => {
const validator = validators[address]
return <div>{validator?.moniker || <Address address={address} />}</div>
return address ? <div key={address}>{validator?.moniker || <Address address={address} />}</div> : null
})}
</small>
)
Expand Down
10 changes: 6 additions & 4 deletions src/components/ValidatorStake.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ function ValidatorStake(props) {
{!props.isLoading('grants') ? (
grantsValid
? <span><span className="text-success">Active</span><br /><small className="text-muted">expires {expiryDate().fromNow()}</small></span>
: grantsExist
? maxTokens && smaller(maxTokens, reward)
? <span className="text-danger">Not enough grant remaining</span>
: <span className="text-danger">Invalid / total delegation reached</span>
: grantsExist
? !validatorGrants.validators.includes(validator.address)
? <span className="text-danger">Grant invalid</span>
: maxTokens && smaller(maxTokens, reward)
? <span className="text-danger">Not enough grant remaining</span>
: <span className="text-danger">Invalid / total delegation reached</span>
: network.authzSupport ? <em>Inactive</em> : <em>Authz not supported</em>
) : (
<Spinner animation="border" role="status" className="spinner-border-sm">
Expand Down

0 comments on commit 16c9461

Please sign in to comment.