-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Majorfi
committed
Oct 18, 2023
1 parent
4bdb4e8
commit 299c81c
Showing
11 changed files
with
191 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {QueryParamProvider} from 'use-query-params'; | ||
import {NextQueryParamAdapter} from '@common/utils/QueryParamsProvider'; | ||
|
||
import {StakeUnstakeGauges} from './ViewStakeUnstakeGauges'; | ||
import {VoteGauge} from './ViewVoteGauges'; | ||
|
||
import type {ReactElement} from 'react'; | ||
|
||
export function TabManageGauges(): ReactElement { | ||
return ( | ||
<div className={'grid gap-10'}> | ||
<VoteGauge /> | ||
<div className={'h-[1px] w-full bg-neutral-300'} /> | ||
<div> | ||
<QueryParamProvider | ||
adapter={NextQueryParamAdapter} | ||
options={{removeDefaultsFromUrl: true}}> | ||
<StakeUnstakeGauges /> | ||
</QueryParamProvider> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {useVotingEscrow} from '@veYFI/contexts/useVotingEscrow'; | ||
import {toBigInt, toNormalizedBN} from '@yearn-finance/web-lib/utils/format.bigNumber'; | ||
import {getTimeUntil, toWeeks} from '@yearn-finance/web-lib/utils/time'; | ||
|
||
import {ClaimVeYFI} from './ViewClaimVeYFI'; | ||
import {EarlyExitVeYFI} from './ViewEarlyExitVeYFI'; | ||
import {ExtendLockVeYFI} from './ViewExtendLockVeYFI'; | ||
import {LockVeYFI} from './ViewLockVeYFI'; | ||
|
||
import type {ReactElement} from 'react'; | ||
|
||
export function TabManageVeYFI(): ReactElement { | ||
const {positions} = useVotingEscrow(); | ||
const hasLock = toNormalizedBN(toBigInt(positions?.deposit?.underlyingBalance), 18); | ||
const timeUntilUnlock = positions?.unlockTime ? getTimeUntil(positions?.unlockTime) : undefined; | ||
const weeksToUnlock = toWeeks(timeUntilUnlock); | ||
|
||
return ( | ||
<div className={'grid gap-10'}> | ||
<LockVeYFI /> | ||
{(hasLock && weeksToUnlock > 0) ? ( | ||
<> | ||
<div className={'h-[1px] w-full bg-neutral-300'} /> | ||
<ExtendLockVeYFI /> | ||
<div className={'h-[1px] w-full bg-neutral-300'} /> | ||
<EarlyExitVeYFI /> | ||
<div className={'h-[1px] w-full bg-neutral-300'} /> | ||
<ClaimVeYFI /> | ||
</> | ||
) : null} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {useCallback, useState} from 'react'; | ||
import {useVotingEscrow} from '@veYFI/contexts/useVotingEscrow'; | ||
import {withdrawLockedVeYFI} from '@veYFI/utils/actions'; | ||
import {VEYFI_CHAIN_ID} from '@veYFI/utils/constants'; | ||
import {Button} from '@yearn-finance/web-lib/components/Button'; | ||
import {useWeb3} from '@yearn-finance/web-lib/contexts/useWeb3'; | ||
import {toBigInt, toNormalizedBN} from '@yearn-finance/web-lib/utils/format.bigNumber'; | ||
import {getTimeUntil, toWeeks} from '@yearn-finance/web-lib/utils/time'; | ||
import {defaultTxStatus} from '@yearn-finance/web-lib/utils/web3/transaction'; | ||
import {AmountInput} from '@common/components/AmountInput'; | ||
import {useWallet} from '@common/contexts/useWallet'; | ||
|
||
import type {ReactElement} from 'react'; | ||
|
||
export function EarlyExitVeYFI(): ReactElement { | ||
const {provider, address, isActive} = useWeb3(); | ||
const {refresh: refreshBalances} = useWallet(); | ||
const {votingEscrow, positions, refresh: refreshVotingEscrow} = useVotingEscrow(); | ||
const timeUntilUnlock = positions?.unlockTime ? getTimeUntil(positions?.unlockTime) : undefined; | ||
const weeksToUnlock = toNormalizedBN(toWeeks(timeUntilUnlock), 0); | ||
const hasPenalty = toBigInt(positions?.penalty) > 0n; | ||
const [withdrawLockedStatus, set_withdrawLockedStatus] = useState(defaultTxStatus); | ||
|
||
const onTxSuccess = useCallback(async (): Promise<void> => { | ||
await Promise.all([refreshVotingEscrow(), refreshBalances()]); | ||
}, [refreshBalances, refreshVotingEscrow]); | ||
|
||
const onWithdrawLocked = useCallback(async (): Promise<void> => { | ||
const result = await withdrawLockedVeYFI({ | ||
connector: provider, | ||
chainID: VEYFI_CHAIN_ID, | ||
contractAddress: votingEscrow?.address, | ||
statusHandler: set_withdrawLockedStatus | ||
}); | ||
if (result.isSuccessful) { | ||
onTxSuccess(); | ||
} | ||
}, [onTxSuccess, provider, votingEscrow?.address]); | ||
|
||
return ( | ||
<div className={'grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-16'}> | ||
<div className={'col-span-1 w-full'}> | ||
<h2 className={'m-0 text-2xl font-bold'}> | ||
{'Early exit'} | ||
</h2> | ||
<div className={'mt-6 text-neutral-600'} > | ||
<p>{'Or you can exit early by paying a penalty based on lock duration.'}</p> | ||
</div> | ||
</div> | ||
|
||
<div className={'col-span-1 grid w-full gap-6'}> | ||
<div className={'mt-0 grid grid-cols-1 gap-6 md:mt-14 md:grid-cols-2'}> | ||
<AmountInput | ||
label={'veYFI you have'} | ||
amount={toNormalizedBN(toBigInt(positions?.deposit?.underlyingBalance), 18)} | ||
disabled /> | ||
<AmountInput | ||
label={'Current lock time (weeks)'} | ||
amount={weeksToUnlock} | ||
disabled /> | ||
</div> | ||
<div className={'grid grid-cols-1 gap-6 md:grid-cols-2'}> | ||
<AmountInput | ||
label={'YFI you get'} | ||
amount={toNormalizedBN(toBigInt(positions?.withdrawable), 18)} | ||
legend={`Penalty: ${((positions?.penaltyRatio ?? 0) * 100).toFixed(2)}%`} | ||
disabled /> | ||
<Button | ||
className={'w-full md:mt-7'} | ||
onClick={onWithdrawLocked} | ||
isBusy={withdrawLockedStatus.pending} | ||
isDisabled={!isActive || !hasPenalty || withdrawLockedStatus.pending || !votingEscrow || !address}> | ||
{'Exit'} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.