Skip to content

Commit

Permalink
feat: time based delay check, switch width fix
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Jul 25, 2024
1 parent 6892951 commit 73c91bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
12 changes: 9 additions & 3 deletions libs/defi/oeth/src/redeem/components/ClaimForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ClaimForm = (props: StackProps) => {
: {
contract: contracts.mainnet.OETHVault,
functionName: 'claimWithdrawals',
args: selectedClaimIds,
args: [selectedClaimIds],
};

const selectedAmount = useMemo(
Expand Down Expand Up @@ -101,7 +101,7 @@ export const ClaimForm = (props: StackProps) => {
};

return (
<Stack>
<Stack {...props}>
<SectionCard
title={intl.formatMessage({ defaultMessage: 'Your claims' })}
titleProps={{ fontWeight: 'medium' }}
Expand Down Expand Up @@ -189,11 +189,17 @@ const ClaimRow = ({ request, selected, onSelect, ...rest }: ClaimRowProps) => {
spacing={1}
p={2}
justifyContent="space-between"
{...rest}
>
<FormControlLabel
control={<Checkbox checked={request.claimable && selected} />}
label={
<Stack direction="row" alignItems="baseline" spacing={0.5}>
<Stack
direction="row"
alignItems="baseline"
spacing={0.5}
color={request.claimable ? 'text.primary' : 'text.secondary'}
>
<Typography variant="body2" fontWeight="medium">
{format(amt, getFormatPrecision(amt))}
</Typography>
Expand Down
23 changes: 10 additions & 13 deletions libs/defi/oeth/src/redeem/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useMemo } from 'react';
import { contracts } from '@origin/shared/contracts';
import { isFulfilled, ZERO_ADDRESS } from '@origin/shared/utils';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { getBlock, readContract } from '@wagmi/core';
import { addMinutes, fromUnixTime, isAfter } from 'date-fns';
import { readContract } from '@wagmi/core';
import { addMinutes, isAfter } from 'date-fns';
import { useSearchParams } from 'react-router-dom';
import { useAccount, useConfig } from 'wagmi';

Expand Down Expand Up @@ -69,27 +69,24 @@ export const useWithdrawalRequests = (
address: address ?? ZERO_ADDRESS,
}),
}),
getBlock(config, {
blockTag: 'finalized',
chainId: contracts.mainnet.OETHVault.chainId,
}),
]);
const queueData = isFulfilled(res[0]) ? res[0].value : null;
const requests = isFulfilled(res[1])
? (res[1].value?.oethWithdrawalRequests ?? [])
: [];
const block = isFulfilled(res[2]) ? res[2].value : null;

console.log(queueData);
return requests.map((r) => {
console.log(
r.queued,
queueData?.claimable,
BigInt(r.queued) <= BigInt(queueData?.claimable ?? 0),
);
const claimable =
!r.claimed &&
BigInt(r.queued) <= BigInt(queueData?.claimable ?? 0) &&
isAfter(
new Date(r.timestamp),
addMinutes(
fromUnixTime(Number(block?.timestamp ?? 0)),
WITHDRAW_DELAY + 1,
),
new Date(),
addMinutes(new Date(r.timestamp), WITHDRAW_DELAY + 1),
);

return {
Expand Down
1 change: 1 addition & 0 deletions libs/shared/components/src/Switches/SliderSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const SliderSwitch = ({
zIndex: 1,
top: 0,
left: 0,
right: 0,
width: itemsWidth[idx],
height: 1,
transform: `translateX(${translateX}px)`,
Expand Down

0 comments on commit 73c91bb

Please sign in to comment.