diff --git a/lib/cosmosV0-source.js b/lib/cosmosV0-source.js index 98262fa219..16515c5391 100644 --- a/lib/cosmosV0-source.js +++ b/lib/cosmosV0-source.js @@ -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) { diff --git a/lib/cosmosV2-source.js b/lib/cosmosV2-source.js index 33e6e3a167..0ffaedad3f 100644 --- a/lib/cosmosV2-source.js +++ b/lib/cosmosV2-source.js @@ -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], diff --git a/lib/reducers/cosmosV0-reducers.js b/lib/reducers/cosmosV0-reducers.js index d341a70103..41693e164c 100644 --- a/lib/reducers/cosmosV0-reducers.js +++ b/lib/reducers/cosmosV0-reducers.js @@ -251,7 +251,7 @@ function delegationReducer(delegation, validator) { validatorAddress: delegation.validator_address, delegatorAddress: delegation.delegator_address, validator, - amount: atoms(balance) + amount: balance } } diff --git a/lib/resolvers.js b/lib/resolvers.js index b6faa31d70..1e12b2135b 100644 --- a/lib/resolvers.js +++ b/lib/resolvers.js @@ -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,