Skip to content

Commit

Permalink
feat: remove claim all
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 17, 2023
1 parent d45428f commit 0236396
Showing 1 changed file with 4 additions and 51 deletions.
55 changes: 4 additions & 51 deletions apps/veyfi/components/RewardsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {useCallback, useMemo, useState} from 'react';
import {useCallback, useState} from 'react';
import {useGauge} from '@veYFI/contexts/useGauge';
import {useOption} from '@veYFI/contexts/useOption';
import * as GaugeActions from '@veYFI/utils/actions/gauge';
import {VEYFI_CHAIN_ID, VEYFI_CLAIM_REWARDS_ZAP_ADDRESS} from '@veYFI/utils/constants';
import {VEYFI_CHAIN_ID} from '@veYFI/utils/constants';
import {validateNetwork} from '@veYFI/utils/validations';
import {Button} from '@yearn-finance/web-lib/components/Button';
import {useWeb3} from '@yearn-finance/web-lib/contexts/useWeb3';
import {toAddress} from '@yearn-finance/web-lib/utils/address';
import {BIG_ZERO} from '@yearn-finance/web-lib/utils/constants';
import {toAddress, truncateHex} from '@yearn-finance/web-lib/utils/address';
import {toBigInt, toNormalizedAmount} from '@yearn-finance/web-lib/utils/format.bigNumber';
import {formatCounterValue} from '@yearn-finance/web-lib/utils/format.value';
import {isZero} from '@yearn-finance/web-lib/utils/isZero';
Expand All @@ -27,7 +26,6 @@ export function RewardsTab(): ReactElement {
const {vaults} = useYearn();
const refreshData = useCallback((): unknown => Promise.all([refreshGauges()]), [refreshGauges]);
const [claimStatus, set_claimStatus] = useState(defaultTxStatus);
const [claimAllStatus, set_claimAllStatus] = useState(defaultTxStatus);
const selectedGaugeAddress = toAddress(selectedGauge?.id);
const selectedGaugeRewards = toBigInt(positionsMap[selectedGaugeAddress]?.reward?.balance?.raw);

Expand All @@ -43,20 +41,6 @@ export function RewardsTab(): ReactElement {
}
}, [provider, refreshData, selectedGaugeAddress]);

const onClaimAll = useCallback(async (): Promise<void> => {
const result = await GaugeActions.claimAllRewards({
connector: provider,
chainID: VEYFI_CHAIN_ID,
contractAddress: VEYFI_CLAIM_REWARDS_ZAP_ADDRESS,
gaugeAddresses,
willLockRewards: false,
statusHandler: set_claimAllStatus
});
if (result.isSuccessful) {
refreshData();
}
}, [gaugeAddresses, provider, refreshData]);

const gaugeOptions = gaugeAddresses.filter((address): boolean => toBigInt(positionsMap[address]?.reward?.balance?.raw) > 0n ?? false)
.map((address): TDropdownOption => {
const gauge = gaugesMap[address];
Expand All @@ -65,17 +49,11 @@ export function RewardsTab(): ReactElement {

return {
id: address,
label: vault?.display_name ?? '',
label: vault?.display_name ?? `Vault ${truncateHex(vaultAddress, 4)}`,
icon: `${process.env.BASE_YEARN_ASSETS_URI}/1/${vaultAddress}/logo-128.png`
};
});

const gaugesRewards = useMemo((): bigint => {
return gaugeAddresses.reduce<bigint>((acc, address): bigint => {
return acc + toBigInt(positionsMap[address]?.reward?.balance?.raw);
}, BIG_ZERO);
}, [gaugeAddresses, positionsMap]);

const {isValid: isValidNetwork} = validateNetwork({supportedNetwork: VEYFI_CHAIN_ID, walletNetwork: chainID});

return (
Expand All @@ -87,31 +65,6 @@ export function RewardsTab(): ReactElement {
</h2>
</div>

<div className={'grid grid-cols-1 gap-4 md:grid-cols-4'}>
<AmountInput
label={'Total unclaimed rewards (dYFI)'}
amount={toNormalizedAmount(gaugesRewards, 18)}
legend={formatCounterValue(toNormalizedAmount(gaugesRewards, 18), optionPrice ?? 0)}
disabled
/>
<Button
className={'w-full md:mt-7'}
onClick={onClaimAll}
isDisabled={!isActive || !isValidNetwork || isZero(gaugesRewards) || !claimAllStatus.none}
isBusy={claimAllStatus.pending}
>
{'Claim All'}
</Button>
</div>
</div>

<div className={'flex flex-col gap-4'}>
<div className={'flex flex-col gap-4'}>
<h2 className={'m-0 text-2xl font-bold'}>
{'Claim Separately'}
</h2>
</div>

<div className={'grid grid-cols-1 gap-4 md:grid-cols-4'}>
<Dropdown
label={'Gauge'}
Expand Down

0 comments on commit 0236396

Please sign in to comment.