Skip to content

Commit

Permalink
SOV-1903: Reward SOV claiming using stakingRewardsProxy contract bala…
Browse files Browse the repository at this point in the history
…nce check (#2486)

fix: Reward SOV claiming using stakingRewardsProxy contract balance check
  • Loading branch information
soulBit authored Feb 24, 2023
1 parent 0aab0a2 commit 4426284
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, ButtonSize } from 'app/components/Button';
import { ErrorBadge } from 'app/components/Form/ErrorBadge';
import { Input } from 'app/components/Form/Input';
import { TransactionDialog } from 'app/components/TransactionDialog';
import { useCacheCallWithValue } from 'app/hooks/useCacheCallWithValue';

import { useMaintenance } from 'app/hooks/useMaintenance';
import { ResetTxResponseInterface } from 'app/hooks/useSendContractTx';
import classNames from 'classnames';
Expand All @@ -14,14 +14,15 @@ import React, { useMemo } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { TxStatus } from 'store/global/transactions-store/types';
import { Asset } from 'types';
import { getContract } from 'utils/blockchain/contract-helpers';

import { weiTo18 } from 'utils/blockchain/math-helpers';
import { discordInvite } from 'utils/classifiers';
import { weiToNumberFormat } from 'utils/display-text/format';

interface IBaseClaimFormProps {
className?: string;
amountToClaim: string;
hasTokenBalance: boolean;
tx: ResetTxResponseInterface;
footer?: JSX.Element;
onSubmit: () => void;
Expand All @@ -33,6 +34,7 @@ interface IBaseClaimFormProps {
export const BaseClaimForm: React.FC<IBaseClaimFormProps> = ({
className,
amountToClaim,
hasTokenBalance,
tx,
footer,
onSubmit,
Expand All @@ -43,17 +45,6 @@ export const BaseClaimForm: React.FC<IBaseClaimFormProps> = ({
const { t } = useTranslation();
const { checkMaintenance, States } = useMaintenance();
const rewardsLocked = checkMaintenance(States.CLAIM_REWARDS);
const { address } = getContract('stakingRewards');
const { value: tokenBalance } = useCacheCallWithValue(
'SOV_token',
'balanceOf',
'0',
address,
);

const isTokenBalance = useMemo(() => {
return bignumber(tokenBalance).greaterThanOrEqualTo(amountToClaim);
}, [amountToClaim, tokenBalance]);

const isDisabled = useMemo(
() =>
Expand Down Expand Up @@ -119,14 +110,14 @@ export const BaseClaimForm: React.FC<IBaseClaimFormProps> = ({
<Tooltip
position="bottom"
className="tw-max-w-lg tw-block"
disabled={isTokenBalance}
disabled={hasTokenBalance}
interactionKind="hover"
content={
<>{t(translations.rewardPage.claimForm.claimDisabled)}</>
}
>
<Button
disabled={isDisabled || !isTokenBalance}
disabled={isDisabled || !hasTokenBalance}
onClick={onSubmit}
className="tw-w-full tw-mb-4 tw-mt-16"
size={ButtonSize.lg}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import { Trans } from 'react-i18next';

import { useSendContractTx } from '../../../../../hooks/useSendContractTx';
Expand All @@ -9,6 +9,9 @@ import { useAccount } from 'app/hooks/useAccount';
import { translations } from 'locales/i18n';
import { gasLimit } from 'utils/classifiers';
import { useMaintenance } from 'app/hooks/useMaintenance';
import { useCacheCallWithValue } from 'app/hooks/useCacheCallWithValue';
import { getContract } from 'utils/blockchain/contract-helpers';
import { bignumber } from 'mathjs';

export const LiquidClaimForm: React.FC<IClaimFormProps> = ({
className,
Expand All @@ -20,6 +23,18 @@ export const LiquidClaimForm: React.FC<IClaimFormProps> = ({
const claimLiquidSovLocked = checkMaintenance(States.CLAIM_LIQUID_SOV);
const { send, ...tx } = useSendContractTx('stakingRewards', 'collectReward');

const { address: stakingRewardAddress } = getContract('stakingRewards');
const { value: tokenBalance } = useCacheCallWithValue(
'SOV_token',
'balanceOf',
'0',
stakingRewardAddress,
);

const hasTokenBalance = useMemo(() => {
return bignumber(tokenBalance).greaterThanOrEqualTo(amountToClaim);
}, [amountToClaim, tokenBalance]);

const onSubmit = useCallback(() => {
send(
[lastWithdrawalInterval],
Expand All @@ -37,6 +52,7 @@ export const LiquidClaimForm: React.FC<IClaimFormProps> = ({
<BaseClaimForm
className={className}
amountToClaim={amountToClaim}
hasTokenBalance={hasTokenBalance}
tx={tx}
onSubmit={onSubmit}
footer={<Footer />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { Trans } from 'react-i18next';

import { translations } from 'locales/i18n';
Expand All @@ -7,6 +7,9 @@ import { BaseClaimForm } from '../BaseClaimForm';
import { IClaimFormProps } from '../BaseClaimForm/types';
import { useMaintenance } from 'app/hooks/useMaintenance';
import { useContractPauseState } from 'app/hooks/useContractPauseState';
import { getContract } from 'utils/blockchain/contract-helpers';
import { useCacheCallWithValue } from 'app/hooks/useCacheCallWithValue';
import { bignumber } from 'mathjs';

export const RewardClaimForm: React.FC<IClaimFormProps> = ({
className,
Expand All @@ -16,11 +19,27 @@ export const RewardClaimForm: React.FC<IClaimFormProps> = ({
const claimRewardSovLocked = checkMaintenance(States.CLAIM_REWARD_SOV);
const { send, ...tx } = useClaimRewardSov();
const { paused, frozen } = useContractPauseState('staking'); // underlying Reward SOV claiming contract uses staking contract so must be disabled

const { address: liquidityMiningProxyAddress } = getContract(
'liquidityMiningProxy',
);
const { value: tokenBalance } = useCacheCallWithValue(
'SOV_token',
'balanceOf',
'0',
liquidityMiningProxyAddress,
);

const hasTokenBalance = useMemo(() => {
return bignumber(tokenBalance).greaterThanOrEqualTo(amountToClaim);
}, [amountToClaim, tokenBalance]);

return (
<>
<BaseClaimForm
className={className}
amountToClaim={amountToClaim}
hasTokenBalance={hasTokenBalance}
tx={tx}
footer={<Footer />}
onSubmit={send}
Expand Down

0 comments on commit 4426284

Please sign in to comment.