Skip to content

Commit

Permalink
Fabo/minor fixes (#51)
Browse files Browse the repository at this point in the history
* gracefully handle no rewards

* always return balance

* prevent error when no rewards

* fix wrong delegation amount showing
  • Loading branch information
faboweb authored and colw committed Oct 29, 2019
1 parent e308020 commit f0a78d4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions lib/cosmosV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ class CosmosV0API extends RESTDataSource {
)) || []
}))
)
return rewards.map(({ rewards, validator }) =>
this.reducers.rewardReducer(rewards[0], validator)
)
return rewards
.filter(({ rewards }) => rewards.length > 0)
.map(({ rewards, validator }) =>
this.reducers.rewardReducer(rewards[0], validator)
)
}

async getOverview(delegatorAddress) {
Expand Down
4 changes: 2 additions & 2 deletions lib/cosmosV2-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class CosmosV2API extends CosmosV0API {
`distribution/delegators/${delegatorAddress}/rewards`
)
const validators = await this.getAllValidators()
return rewards
.filter(({ rewards }) => !!rewards)
return (rewards || [])
.filter(({ rewards }) => rewards.length > 0)
.map(({ rewards, validator_address }) =>
this.reducers.rewardReducer(
rewards[0],
Expand Down
2 changes: 1 addition & 1 deletion lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function delegationReducer(delegation, validator) {
validatorAddress: delegation.validator_address,
delegatorAddress: delegation.delegator_address,
validator,
amount: atoms(balance)
amount: balance
}
}

Expand Down
10 changes: 6 additions & 4 deletions lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ const resolvers = {
balances: async (_, { networkId, address }, { dataSources }) =>
selectFrom(dataSources, networkId).getBalancesFromAddress(address),
balance: async (_, { networkId, address, denom }, { dataSources }) => {
const balances = await selectFrom(dataSources, networkId)
.getBalancesFromAddress(address)
.then(result => result.find(balance => balance.denom === denom))
return balances
const balances = await selectFrom(
dataSources,
networkId
).getBalancesFromAddress(address)
const balance = balances.find(balance => balance.denom === denom)
return balance || { denom, amount: 0 }
},
delegations,
undelegations,
Expand Down

0 comments on commit f0a78d4

Please sign in to comment.