Skip to content

Commit

Permalink
fix: remove button shimmer
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonLin authored Feb 7, 2023
1 parent 08ab3a7 commit 1fd7691
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Button from '@lyra/ui/components/Button'
import CardSection from '@lyra/ui/components/Card/CardSection'
import Flex from '@lyra/ui/components/Flex'
import Grid from '@lyra/ui/components/Grid'
import ButtonShimmer from '@lyra/ui/components/Shimmer/ButtonShimmer'
import TextShimmer from '@lyra/ui/components/Shimmer/TextShimmer'
import Text from '@lyra/ui/components/Text'
import useIsMobile from '@lyra/ui/hooks/useIsMobile'
Expand Down Expand Up @@ -88,25 +87,19 @@ const WethLyraRewardsGridItems = withSuspense(
)
)

const WethLyraStakingRewardsL1ClaimButton = withSuspense(
({ onOpenModal }: ClaimButtonProps) => {
const accountWethLyraStaking = useAccountWethLyraStaking()
const rewards = accountWethLyraStaking?.rewards ?? ZERO_BN
return rewards.gt(ZERO_BN) ? <Button label="Claim" size="lg" variant="primary" onClick={onOpenModal} /> : null
},
() => <ButtonShimmer size="lg" width={250} />
)
const WethLyraStakingRewardsL1ClaimButton = withSuspense(({ onOpenModal }: ClaimButtonProps) => {
const accountWethLyraStaking = useAccountWethLyraStaking()
const rewards = accountWethLyraStaking?.rewards ?? ZERO_BN
return rewards.gt(ZERO_BN) ? <Button label="Claim" size="lg" variant="primary" onClick={onOpenModal} /> : null
})

const UnstakeOldWethLyraButton = withSuspense(
({ onOpenModal }: UnstakeOldButtonProps) => {
const wethLyraStakingL2 = useAccountWethLyraStakingL2()
const oldStakedAmount = wethLyraStakingL2?.stakedLPTokenBalance ?? ZERO_BN
return oldStakedAmount.gt(ZERO_BN) ? (
<Button label="Unstake L2 WETH/LYRA" size="lg" variant="warning" onClick={onOpenModal} />
) : null
},
() => <ButtonShimmer size="lg" width={250} />
)
const UnstakeOldWethLyraButton = withSuspense(({ onOpenModal }: UnstakeOldButtonProps) => {
const wethLyraStakingL2 = useAccountWethLyraStakingL2()
const oldStakedAmount = wethLyraStakingL2?.stakedLPTokenBalance ?? ZERO_BN
return oldStakedAmount.gt(ZERO_BN) ? (
<Button label="Unstake L2 WETH/LYRA" size="lg" variant="warning" onClick={onOpenModal} />
) : null
})

export default function WethLyraStakingRewardsCardSection() {
const isMobile = useIsMobile()
Expand Down
59 changes: 26 additions & 33 deletions sdk/src/utils/fetchWethLyraStakingData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BigNumber } from 'ethers'

import { ZERO_BN } from '../constants/bn'
import {
LYRA_ETHEREUM_MAINNET_ADDRESS,
LyraGlobalContractId,
Expand Down Expand Up @@ -45,44 +44,38 @@ const fetchWethLyraStakingData = async (

const getUnderlyingBalancesCallData = arrakisVaultContract.interface.encodeFunctionData('getUnderlyingBalances')
const totalSupplyCallData = wethLyraStakingContract.interface.encodeFunctionData('totalSupply')
const rewardPerTokenCallData = wethLyraStakingContract.interface.encodeFunctionData('rewardPerToken')
const rewardsDurationCallData = wethLyraStakingContract.interface.encodeFunctionData('rewardsDuration')
const rewardRateCallData = wethLyraStakingContract.interface.encodeFunctionData('rewardRate')

const [[amount0Current, amount1Current], [supply], [rewardPerToken], [rewardsDuration]] =
await callContractWithMulticall<[[BigNumber, BigNumber], [BigNumber], [BigNumber], [BigNumber]]>(
lyra,
[
{
contract: arrakisVaultContract,
callData: getUnderlyingBalancesCallData,
functionFragment: 'getUnderlyingBalances',
},
{
contract: arrakisVaultContract,
callData: totalSupplyCallData,
functionFragment: 'totalSupply',
},
{
contract: wethLyraStakingContract,
callData: rewardPerTokenCallData,
functionFragment: 'rewardPerToken',
},
{
contract: wethLyraStakingContract,
callData: rewardsDurationCallData,
functionFragment: 'rewardsDuration',
},
],
lyra.ethereumProvider
)
const [[amount0Current, amount1Current], [supply], [rewardRate]] = await callContractWithMulticall<
[[BigNumber, BigNumber], [BigNumber], [BigNumber], [BigNumber]]
>(
lyra,
[
{
contract: arrakisVaultContract,
callData: getUnderlyingBalancesCallData,
functionFragment: 'getUnderlyingBalances',
},
{
contract: wethLyraStakingContract,
callData: totalSupplyCallData,
functionFragment: 'totalSupply',
},
{
contract: wethLyraStakingContract,
callData: rewardRateCallData,
functionFragment: 'rewardRate',
},
],
lyra.ethereumProvider
)

const poolLyraValue = fromBigNumber(amount0Current) * lyraPrice
const poolWethValue = fromBigNumber(amount1Current) * wethPrice
const tvl = poolWethValue + poolLyraValue
const tokenValue = supply ? tvl / fromBigNumber(supply) : 0
const rewardsPerSecondPerToken = rewardsDuration.gt(0) ? rewardPerToken.div(rewardsDuration) : ZERO_BN
const apy =
tokenValue > 0 ? (fromBigNumber(rewardsPerSecondPerToken) * SECONDS_IN_YEAR * (lyraPrice ?? 0)) / tokenValue : 0
const rewardsPerSecondPerToken = supply.gt(0) ? fromBigNumber(rewardRate) / fromBigNumber(supply) : 0
const apy = tokenValue > 0 ? (rewardsPerSecondPerToken * SECONDS_IN_YEAR * (lyraPrice ?? 0)) / tokenValue : 0
return { apy, tokenValue }
}

Expand Down

0 comments on commit 1fd7691

Please sign in to comment.