Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upd staking section #614

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 51 additions & 15 deletions apps/vaults-v3/components/details/RewardsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {useCallback, useMemo, useState} from 'react';
import {useRouter} from 'next/router';
import {useReadContract} from 'wagmi';
import {useWeb3} from '@builtbymom/web3/contexts/useWeb3';
import {cl, formatAmount, formatCounterValue, isZero, toAddress, toBigInt} from '@builtbymom/web3/utils';
import {approveERC20, defaultTxStatus} from '@builtbymom/web3/utils/wagmi';
import {useVaultStakingData} from '@vaults/hooks/useVaultStakingData';
import {VEYFI_GAUGE_ABI} from '@vaults/utils/abi/veYFIGauge.abi';
import {
claim as claimAction,
stake as stakeAction,
Expand Down Expand Up @@ -156,6 +158,13 @@ export function RewardsTab(props: {currentVault: TYDaemonVault; hasStakingReward
const [unstakeStatus, set_unstakeStatus] = useState(defaultTxStatus);
const isApproved = vaultData.vaultAllowance.raw >= vaultData.vaultBalanceOf.raw;

const {data: symbol} = useReadContract({
address: vaultData.address,
abi: VEYFI_GAUGE_ABI,
functionName: 'symbol',
chainId: props.currentVault.chainID
});

/**********************************************************************************************
** The refreshData function will be called when the user interacts with the stake, unstake, or
** claim buttons. It will refresh the user's balances and the staking rewards data so the app
Expand Down Expand Up @@ -345,17 +354,50 @@ export function RewardsTab(props: {currentVault: TYDaemonVault; hasStakingReward
)
}
/>
<div>
<Button
className={'w-full md:w-[200px]'}
onClick={(): unknown => (isApproved ? onStake() : onApprove())}
isBusy={stakeStatus.pending || approveStakeStatus.pending}
isDisabled={
!isActive ||
toBigInt(vaultData.vaultBalanceOf.raw) <= 0n ||
(!props.hasStakingRewardsLive && props.currentVault.staking.source !== 'VeYFI')
}>
{isApproved ? 'Stake' : 'Approve & Stake'}
</Button>
</div>
</div>
</div>
<div className={'flex flex-col gap-2'}>
<div>
<div className={'font-bold'}>{'Unstake'}</div>
</div>
<div className={'flex flex-col gap-4 md:flex-row'}>
<FakeInput
className={'w-full md:w-1/3'}
legend={
<div className={'flex items-center justify-between'}>
<p>{`${formatAmount(vaultData.stakedBalanceOf.normalized, 6)} ${symbol} staked`}</p>
<p>{`${formatCounterValue(vaultData.stakedBalanceOf.normalized, vaultTokenPrice.normalized)}`}</p>
</div>
}
value={
toBigInt(vaultData.stakedBalanceOf.raw) === 0n ? undefined : (
<Counter
value={Number(vaultData.stakedBalanceOf.normalized)}
decimals={18}
/>
)
}
/>

<Button
className={'w-full md:w-[200px]'}
onClick={(): unknown => (isApproved ? onStake() : onApprove())}
isBusy={stakeStatus.pending || approveStakeStatus.pending}
isDisabled={
!isActive ||
toBigInt(vaultData.vaultBalanceOf.raw) <= 0n ||
(!props.hasStakingRewardsLive && props.currentVault.staking.source !== 'VeYFI')
}>
{isApproved ? 'Stake' : 'Approve & Stake'}
onClick={onUnstake}
isBusy={unstakeStatus.pending}
isDisabled={!isActive || Number(vaultData.stakedBalanceOf.normalized) <= 0}>
{'Claim & Exit'}
</Button>
</div>
</div>
Expand All @@ -381,13 +423,7 @@ export function RewardsTab(props: {currentVault: TYDaemonVault; hasStakingReward
)
}
/>
<Button
className={'w-full md:w-[200px]'}
onClick={onUnstake}
isBusy={unstakeStatus.pending}
isDisabled={!isActive || Number(vaultData.stakedBalanceOf.normalized) <= 0}>
{'Claim & Exit'}
</Button>

<Button
className={'w-full md:w-[200px]'}
onClick={onClaim}
Expand Down
Loading