From 64ea9c60639b286ca07100094dd7266a27add977 Mon Sep 17 00:00:00 2001 From: Ana G <40721795+Bitcoinera@users.noreply.github.com> Date: Wed, 1 Apr 2020 00:41:12 +0200 Subject: [PATCH] fix claimrewardsamount reducer. get all (#548) --- lib/reducers/cosmosV2-reducers.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/reducers/cosmosV2-reducers.js b/lib/reducers/cosmosV2-reducers.js index 9e82a34e96..8787ec3021 100644 --- a/lib/reducers/cosmosV2-reducers.js +++ b/lib/reducers/cosmosV2-reducers.js @@ -92,12 +92,25 @@ function claimRewardsAmountReducer(transaction, reducers, stakingDenom) { } ] } - return reducers.rewardCoinReducer( - transaction.events - .find(event => event.type === `transfer`) - .attributes.find(attribute => attribute.key === `amount`).value, - stakingDenom + const allClaimedRewards = transaction.events + .find(event => event.type === `transfer`) + .attributes.filter(attribute => attribute.key === `amount`) + .map(amount => amount.value) + .map(rewardValue => reducers.rewardCoinReducer(rewardValue)) + const aggregatedClaimRewardsObject = allClaimedRewards.reduce( + (all, rewards) => { + rewards.forEach(reward => { + all = { + ...all, + [reward.denom]: reward.amount.plus(all[reward.denom] || 0) + } + }) + return all + }, + {} ) + const claimedRewardsDenomArray = Object.entries(aggregatedClaimRewardsObject) + return claimedRewardsDenomArray.map(([denom, amount]) => ({ denom, amount })) } function submitProposalDetailsReducer(message, reducers) {