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: foxy canClaimWithdraw loading state #5488

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const FoxyOverview: React.FC<FoxyOverviewProps> = ({
stakingAssetId,
} = useFoxyQuery()
const foxyApi = getFoxyApi()
const [canClaim, setCanClaim] = useState<boolean>(false)
const [canClaim, setCanClaim] = useState<boolean | null>(null)
// The highest level AssetId/OpportunityId, in this case of the single FOXy contract
const assetId = toAssetId({
chainId,
Expand Down Expand Up @@ -209,6 +209,7 @@ export const FoxyOverview: React.FC<FoxyOverviewProps> = ({
action: DefiAction.Claim,
variant: 'ghost-filled',
colorScheme: 'green',
isLoading: canClaim === null,
isDisabled: claimDisabled,
toolTip: translate('defi.modals.overview.noWithdrawals'),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Stack, useColorModeValue } from '@chakra-ui/react'
import { Button, Skeleton, Stack, useColorModeValue } from '@chakra-ui/react'
import dayjs from 'dayjs'
import type {
DefiParams,
Expand All @@ -20,7 +20,7 @@ import type { UserUndelegation } from 'state/slices/opportunitiesSlice/resolvers
type WithdrawCardProps = {
asset: Asset
undelegation: UserUndelegation | undefined
canClaimWithdraw: boolean
canClaimWithdraw: boolean | null
}

export const WithdrawCard = ({ asset, undelegation, canClaimWithdraw }: WithdrawCardProps) => {
Expand All @@ -31,6 +31,7 @@ export const WithdrawCard = ({ asset, undelegation, canClaimWithdraw }: Withdraw
} = useWallet()
const hasClaim = bnOrZero(undelegation?.undelegationAmountCryptoBaseUnit).gt(0)
const textColor = useColorModeValue('black', 'white')
const canClaimWithdrawLoading = canClaimWithdraw === null
const isUndelegationAvailable =
canClaimWithdraw && undelegation && dayjs().isAfter(dayjs.unix(undelegation.completionTime))
const successColor = useColorModeValue('green.500', 'green.200')
Expand Down Expand Up @@ -106,21 +107,23 @@ export const WithdrawCard = ({ asset, undelegation, canClaimWithdraw }: Withdraw
symbol={asset.symbol}
maximumFractionDigits={4}
/>
{isUndelegationAvailable ? (
<Stack direction='row' alignItems='center' color='blue.500'>
<Text translation='defi.modals.claim.claimNow' />
<FaArrowRight />
</Stack>
) : (
<Text
fontWeight='normal'
lineHeight='shorter'
translation={[
'defi.modals.foxyOverview.availableDate',
{ date: dayjs(dayjs.unix(undelegation.completionTime)).fromNow() },
]}
/>
)}
<Skeleton isLoaded={!canClaimWithdrawLoading}>
{isUndelegationAvailable ? (
<Stack direction='row' alignItems='center' color='blue.500'>
<Text translation='defi.modals.claim.claimNow' />
<FaArrowRight />
</Stack>
) : (
<Text
fontWeight='normal'
lineHeight='shorter'
translation={[
'defi.modals.foxyOverview.availableDate',
{ date: dayjs(dayjs.unix(undelegation.completionTime)).fromNow() },
]}
/>
)}
</Skeleton>
</Stack>
</Button>
)}
Expand Down