Skip to content

Commit

Permalink
fix(namadillo): fixing staking rewards not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorezende committed Sep 13, 2024
1 parent 38922ec commit 6ebdf42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
12 changes: 4 additions & 8 deletions apps/namadillo/src/App/Staking/StakingRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import {
claimableRewardsAtom,
claimAndStakeRewardsAtom,
claimRewardsAtom,
getStakingRewardsTotalAtom,
} from "atoms/staking";
import BigNumber from "bignumber.js";
import { useModalCloseEvent } from "hooks/useModalCloseEvent";
import { useTransaction } from "hooks/useTransaction";
import { useAtomValue } from "jotai";
import { useMemo } from "react";
import claimRewardsSvg from "./assets/claim-rewards.svg";

export const StakingRewards = (): JSX.Element => {
Expand All @@ -28,6 +27,8 @@ export const StakingRewards = (): JSX.Element => {
data: rewards,
} = useAtomValue(claimableRewardsAtom);

const availableRewards = useAtomValue(getStakingRewardsTotalAtom);

const { onCloseModal } = useModalCloseEvent();

const parseStakingRewardsParams = (): ClaimRewardsMsgValue[] => {
Expand Down Expand Up @@ -79,19 +80,14 @@ export const StakingRewards = (): JSX.Element => {
},
});

const availableRewards = useMemo(() => {
if (!rewards || Object.keys(rewards).length === 0) return BigNumber(0);
return BigNumber.sum(...Object.values(rewards || []));
}, [rewards]);

const isLoading = claimRewardsPending || claimAndStakePending;

return (
<Modal onClose={onCloseModal}>
<ModalContainer
header="Claimable Staking Rewards"
onClose={onCloseModal}
containerProps={{ className: "lg:w-[540px] lg:h-[auto]" }}
containerProps={{ className: "md:!w-[540px] md:!h-[auto]" }}
contentProps={{ className: "flex" }}
>
<Stack gap={8} className="bg-rblack py-7 px-8 rounded-md flex-1">
Expand Down
13 changes: 2 additions & 11 deletions apps/namadillo/src/App/Staking/StakingRewardsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@ import { ActionButton, AmountSummaryCard } from "@namada/components";
import { NamCurrency } from "App/Common/NamCurrency";
import StakingRoutes from "App/Staking/routes";
import { applicationFeaturesAtom } from "atoms/settings";
import { claimableRewardsAtom } from "atoms/staking";
import BigNumber from "bignumber.js";
import { getStakingRewardsTotalAtom } from "atoms/staking";
import clsx from "clsx";
import { useAtomValue } from "jotai";
import { useMemo } from "react";
import { GoStack } from "react-icons/go";
import { useLocation, useNavigate } from "react-router-dom";

export const StakingRewardsPanel = (): JSX.Element => {
const { claimRewardsEnabled } = useAtomValue(applicationFeaturesAtom);
const { data: rewards } = useAtomValue(claimableRewardsAtom);
const availableRewards = useAtomValue(getStakingRewardsTotalAtom);
const location = useLocation();
const navigate = useNavigate();

const availableRewards = useMemo(() => {
if (!claimRewardsEnabled || !rewards || Object.keys(rewards).length === 0) {
return new BigNumber(0);
}
return BigNumber.sum(...Object.values(rewards));
}, [rewards]);

const title =
claimRewardsEnabled ?
"Unclaimed Staking Rewards"
Expand Down
11 changes: 11 additions & 0 deletions apps/namadillo/src/atoms/staking/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { chainAtom, chainParametersAtom } from "atoms/chain";
import { queryDependentFn } from "atoms/utils";
import { myValidatorsAtom } from "atoms/validators";
import BigNumber from "bignumber.js";
import { atom } from "jotai";
import { atomWithMutation, atomWithQuery } from "jotai-tanstack-query";
import { atomFamily } from "jotai/utils";
import { AddressBalance, BuildTxAtomParams, StakingTotals } from "types";
Expand Down Expand Up @@ -142,6 +143,16 @@ export const claimRewardsAtom = atomWithMutation((get) => {
};
});

export const getStakingRewardsTotalAtom = atom((get) => {
const { data: rewards } = get(claimableRewardsAtom);

if (!rewards || Object.keys(rewards).length === 0) {
return new BigNumber(0);
}

return BigNumber.sum(...Object.values(rewards));
});

export const claimAndStakeRewardsAtom = atomWithMutation((get) => {
const chain = get(chainAtom);
const claimableRewards = get(claimableRewardsAtom);
Expand Down

0 comments on commit 6ebdf42

Please sign in to comment.