Skip to content

Commit

Permalink
feat(dHEDGE V1 Withdraw): set balance value as redeem input value and…
Browse files Browse the repository at this point in the history
… disable input
  • Loading branch information
dimlbc committed Sep 13, 2024
1 parent b112484 commit fbaeffb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const TokenInputs = (props: BoxProps) => {
width: 1,
padding: (theme) => theme.spacing(0.5, 2, 0.5, 2),
},
input: {
InputProps: {
disabled: true,
},
},
}}
/>
<Stack
Expand Down
19 changes: 8 additions & 11 deletions libs/dhedge/withdraw/src/components/BurnForm/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useCallback, useEffect, useState } from 'react';

import { useDebounce } from '@frontend/shared-hooks';
import { BigDecimal } from '@frontend/shared-utils';
import produce from 'immer';
import { createContainer } from 'react-tracked';
Expand Down Expand Up @@ -121,17 +120,19 @@ export const { Provider, useTrackedState, useUpdate } = createContainer(() => {

useEffect(() => {
if (data) {
const l1TokenBalance = new BigDecimal(
data[2] as unknown as BigNumberish,
state.l1token.contract.decimals,
);
setState(
produce((draft) => {
draft.l1token.contract.name = data[0] as unknown as string;
draft.allowance = new BigDecimal(
data[1] as unknown as BigNumberish,
state.l1token.contract.decimals,
);
draft.l1token.balance = new BigDecimal(
data[2] as unknown as BigNumberish,
state.l1token.contract.decimals,
);
draft.l1token.balance = l1TokenBalance;
draft.l1token.amount = l1TokenBalance;
draft.l2token.balance = new BigDecimal(
data[3] as unknown as BigNumberish,
state.l1token.contract.decimals,
Expand All @@ -149,10 +150,6 @@ export const { Provider, useTrackedState, useUpdate } = createContainer(() => {
}
}, [data, refetch, state.l1token.contract.decimals]);

const debouncedL1TokenAmount = useDebounce(
state.l1token.amount.exact.toString(),
500,
);
useContractRead({
address: l2ComptrollerContract.address,
abi: l2ComptrollerContract.abi,
Expand All @@ -161,9 +158,9 @@ export const { Provider, useTrackedState, useUpdate } = createContainer(() => {
args: [
state.l1token.contract.address,
state.l2token.contract.address,
debouncedL1TokenAmount,
state.l1token.amount.exact,
],
enabled: debouncedL1TokenAmount !== '0',
enabled: !state.l1token.amount.exact.isZero(),
onSuccess: (data) => {
setState(
produce((draft) => {
Expand Down
4 changes: 1 addition & 3 deletions libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMemo } from 'react';

import { constants } from 'ethers';
import { useAccount } from 'wagmi';

import { useTrackedState } from '../components/BurnForm/state';
Expand Down Expand Up @@ -41,8 +40,7 @@ export const useRedeemCallConfig = () => {
encodedArbAdditionalData,
{ value: ethValue },
],
enabled:
!isError && l1token.amount.exact.gt(constants.Zero) && !needsApproval,
enabled: !isError && !l1token.amount.exact.isZero() && !needsApproval,
address: l1ComptrollerContract.address,
abi: l1ComptrollerContract.abi,
chainId: l1ComptrollerContract.chainId,
Expand Down

0 comments on commit fbaeffb

Please sign in to comment.