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

fix: deposit/withdraw form doesn't reset once tx is sent #115

Merged
merged 4 commits into from
Sep 10, 2024
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
6 changes: 6 additions & 0 deletions src/app/slinks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { Metadata } from 'next';
import { useMemo, useState } from 'react';

const metadata: Metadata = {

Check warning on line 24 in src/app/slinks/page.tsx

View workflow job for this annotation

GitHub Actions / Performs linting, formatting on the application

'metadata' is assigned a value but never used. Allowed unused vars must match /^_/u
title: 'STRKFarm | Yield aggregator on Starknet',
description:
'Find and invest in high yield pools. STRKFarm is the best yield aggregator on Starknet.',
Expand All @@ -46,12 +46,17 @@
amount,
tokenAddr: depositMethods[0].tokenInfo.token,
};
}, [amount, balData]);

Check warning on line 49 in src/app/slinks/page.tsx

View workflow job for this annotation

GitHub Actions / Performs linting, formatting on the application

React Hook useMemo has missing dependencies: 'depositMethods' and 'strat.id'. Either include them or remove the dependency array

const maxAmount: MyNumber = useMemo(() => {
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 @@
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
Loading