Skip to content

Commit

Permalink
Merge pull request #115 from kateberryd/reset
Browse files Browse the repository at this point in the history
fix: deposit/withdraw form doesn't reset once tx is sent
  • Loading branch information
akiraonstarknet authored Sep 10, 2024
2 parents bfabfe3 + 8956a96 commit 76bb460
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/slinks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function GetCardSimple(strat: StrategyInfo) {
return balance;
}, [balance]);

// Function to reset the input fields to their initial state
const resetDepositForm = () => {
setAmount(MyNumber.fromZero());
};

return (
<Card
key={strat.id}
Expand Down Expand Up @@ -111,6 +116,7 @@ function GetCardSimple(strat: StrategyInfo) {
isDisabled:
amount.isZero() || amount.compare(maxAmount.toEtherStr(), 'gt'),
}}
resetDepositForm={resetDepositForm}
/>
</Box>
</Flex>
Expand Down
8 changes: 8 additions & 0 deletions src/components/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export default function Deposit(props: DepositProps) {
};
}, [amount, props]);

// Function to reset the input fields to their initial state
const resetDepositForm = () => {
setAmount(MyNumber.fromEther('0', selectedMarket.decimals));
setRawAmount('');
setDirty(false);
};

// constructs tx calls
const { calls, actions } = useMemo(() => {
const actions = props.callsInfo(amount, address || '0x0', provider);
Expand Down Expand Up @@ -310,6 +317,7 @@ export default function Deposit(props: DepositProps) {
}}
selectedMarket={selectedMarket}
strategy={props.strategy}
resetDepositForm={resetDepositForm}
/>
</Center>

Expand Down
2 changes: 2 additions & 0 deletions src/components/TxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface TxButtonProps {
justDisableIfNoWalletConnect?: boolean;
selectedMarket?: TokenInfo;
strategy?: IStrategyProps;
resetDepositForm: () => void;
}

export default function TxButton(props: TxButtonProps) {
Expand All @@ -60,6 +61,7 @@ export default function TxButton(props: TxButtonProps) {

useEffect(() => {
if (data && data.transaction_hash) {
props.resetDepositForm();
// initiates a toast and adds the tx to tx history if successful
monitorNewTx({
txHash: data.transaction_hash,
Expand Down

0 comments on commit 76bb460

Please sign in to comment.