diff --git a/src/features/staking/components/modals/rewards.tsx b/src/features/staking/components/modals/rewards.tsx index 20f8dc7..380552a 100644 --- a/src/features/staking/components/modals/rewards.tsx +++ b/src/features/staking/components/modals/rewards.tsx @@ -4,15 +4,16 @@ import { toast } from "react-toastify"; import { Button, HeroText } from "@/features/core/components/base"; import CommonModal from "@/features/core/components/common-modal"; -import { claimRewardsAction } from "../../context/actions"; +import { fetchUserDataAction } from "../../context/actions"; import { useStaking } from "../../context/hooks"; import { setModalOpened } from "../../context/reducer"; +import { claimRewards } from "../../lib/core/tx"; type Step = "completed" | "loading"; const initialStep: Step = "loading"; -const claimRewards = async ( +const claimRewardsLoop = async ( stakingRef: ReturnType, setStep: (step: Step) => void, ) => { @@ -23,17 +24,20 @@ const claimRewards = async ( if (!client || !delegations?.length) return; + const delegatorAddress = stakingRef.account.bech32Address; + delegations .reduce(async (promise, delegation) => { await promise; const addresses = { - delegator: stakingRef.account.bech32Address, + delegator: delegatorAddress, validator: delegation.validatorAddress, }; - return claimRewardsAction(addresses, client, stakingRef.staking); + await claimRewards(addresses, client); }, Promise.resolve()) + .then(() => fetchUserDataAction(delegatorAddress, staking)) .then(() => { setStep("completed"); }) @@ -62,7 +66,7 @@ const RewardsModal = () => { if (requested.current) return; requested.current = true; - claimRewards(stakingRef, setStep); + claimRewardsLoop(stakingRef, setStep); } }, [isOpen, stakingRef]); diff --git a/src/features/staking/context/actions.ts b/src/features/staking/context/actions.ts index b9d811b..ce53a5f 100644 --- a/src/features/staking/context/actions.ts +++ b/src/features/staking/context/actions.ts @@ -13,7 +13,7 @@ import { import type { AbstraxionSigningClient } from "../lib/core/client"; import { sumAllCoins } from "../lib/core/coins"; import type { StakeAddresses } from "../lib/core/tx"; -import { claimRewards, stakeAmount, unstakeAmount } from "../lib/core/tx"; +import { stakeAmount, unstakeAmount } from "../lib/core/tx"; import { addDelegations, addUnbondings, @@ -182,16 +182,6 @@ export const unstakeValidatorAction = async ( }; }; -export const claimRewardsAction = async ( - addresses: StakeAddresses, - client: AbstraxionSigningClient, - staking: StakingContextType, -) => { - await claimRewards(addresses, client); - - await fetchUserDataAction(addresses.delegator, staking); -}; - export const getValidatorDetailsAction = async ( validatorAddress: string, staking: StakingContextType, diff --git a/src/features/staking/lib/core/tx.ts b/src/features/staking/lib/core/tx.ts index feb6794..3875ba4 100644 --- a/src/features/staking/lib/core/tx.ts +++ b/src/features/staking/lib/core/tx.ts @@ -130,7 +130,7 @@ export const claimRewards = async ( ) => { const msg = MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: addresses.delegator, - // validatorAddress: addresses.validator, + validatorAddress: addresses.validator, }); const messageWrapper = [