Skip to content

Commit

Permalink
fix: key farmRewards by accountId
Browse files Browse the repository at this point in the history
  • Loading branch information
esaminu committed May 16, 2022
1 parent 2549cac commit 303e615
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/frontend/src/components/staking/StakingContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ export function StakingContainer({ history, match }) {

validators
.filter((validator) => validator.version === FARMING_VALIDATOR_VERSION)
.forEach((validator) => dispatch(getValidatorFarmData(validator, accountId)));
}, [accountId, validators]);
.forEach((validator) => dispatch(getValidatorFarmData(validator, currentAccount.accountId)));
}, [currentAccount, validators]);

const handleAction = async (action, validator, amount) => {
let id = Mixpanel.get_distinct_id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default function Validator({
dispatch(getValidatorFarmData(validator, currentAccountId));
}, [validator, currentAccountId]);

const farmList = validatorFarmData?.farmRewards || [];
const farmList = validatorFarmData?.farmRewards?.[currentAccountId] || [];
const tokenPriceMetadata = { tokenFiatValues, tokenWhitelist };
const hasUnwhitelistedTokens = useMemo(
() =>
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/redux/actions/staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export const getValidatorFarmData = (validator, accountId) => async (dispatch, g

const farmData = {
poolSummary: {...poolSummary},
farmRewards: farmList,
farmRewards: {[accountId]: farmList},
};
await dispatch(staking.setValidatorFarmData(validator.accountId, farmData));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BN from 'bn.js';
import { isEmpty, some } from 'lodash';
import { createSelector } from 'reselect';

import { selectValidatorsFarmData } from '../slices/staking';
import { selectStakingCurrentAccountAccountId, selectValidatorsFarmData } from '../slices/staking';
import {
selectTokensFiatValueUSD,
selectTokenWhiteList,
Expand All @@ -18,9 +18,10 @@ const collectFarmingData = (args) => {
contractMetadataByContractId,
tokenFiatValues,
tokenWhitelist,
accountId
} = args;
const filteredFarms = Object.values(validatorsFarmData)
.reduce((acc, {farmRewards}) => [...acc, ...farmRewards], []);
.reduce((acc, {farmRewards}) => [...acc, ...(farmRewards?.[accountId] || [])], []);

const collectedBalance = filteredFarms.reduce((acc, farm) => ({
...acc,
Expand Down Expand Up @@ -51,18 +52,21 @@ export default createSelector(
selectAllContractMetadata,
selectTokensFiatValueUSD,
selectTokenWhiteList,
selectStakingCurrentAccountAccountId
],
(
validatorsFarmData,
contractMetadataByContractId,
tokenFiatValues,
tokenWhitelist
tokenWhitelist,
accountId
) => {
return collectFarmingData({
validatorsFarmData,
contractMetadataByContractId,
tokenFiatValues,
tokenWhitelist
tokenWhitelist,
accountId
});
}
);
7 changes: 6 additions & 1 deletion packages/frontend/src/redux/reducers/staking/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ const stakingHandlers = handleActions({
farmingValidators: {
...state.farmingValidators,
[payload.validatorId]: {
...payload.farmData
...payload.farmData,
farmRewards: {
...state.farmingValidators?.[payload.validatorId]
?.farmRewards,
...payload.farmData.farmRewards,
}
},
}
}),
Expand Down

0 comments on commit 303e615

Please sign in to comment.