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: Resolve max withdraw bug #122

Merged
merged 17 commits into from
Sep 10, 2024
8 changes: 4 additions & 4 deletions .env.sample
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_RPC_URL=
RPC_URL=
DATABASE_URL=
NEXT_PUBLIC_RPC_URL=
RPC_URL=

DATABASE_URL=
14 changes: 11 additions & 3 deletions src/components/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { useAccount, useProvider } from '@starknet-react/core';
import { useAtomValue } from 'jotai';
import mixpanel from 'mixpanel-browser';
import { useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { ProviderInterface } from 'starknet';
import LoadingWrap from './LoadingWrap';
import TxButton from './TxButton';
Expand All @@ -51,6 +51,7 @@ export default function Deposit(props: DepositProps) {
const { address } = useAccount();
const { provider } = useProvider();
const [dirty, setDirty] = useState(false);
const [isMaxClicked, setIsMaxClicked] = useState(false);

const tvlInfo = useAtomValue(props.strategy.tvlAtom);

Expand Down Expand Up @@ -103,7 +104,6 @@ export default function Deposit(props: DepositProps) {
selectedMarket.decimals,
);
let reducedBalance = balance;

if (props.buttonText === 'Deposit') {
if (selectedMarket.name === 'STRK') {
reducedBalance = balance.subtract(
Expand All @@ -120,6 +120,13 @@ export default function Deposit(props: DepositProps) {
return MyNumber.max(min, MyNumber.fromEther('0', selectedMarket.decimals));
}, [balance, props.strategy, selectedMarket]);

useEffect(() => {
if (isMaxClicked) {
setRawAmount(maxAmount.toEtherStr());
setAmount(maxAmount);
}
}, [maxAmount, isMaxClicked]);

function BalanceComponent(props: {
token: TokenInfo;
strategy: StrategyInfo;
Expand Down Expand Up @@ -166,6 +173,7 @@ export default function Deposit(props: DepositProps) {
onClick={() => {
setAmount(maxAmount);
setRawAmount(maxAmount.toEtherStr());
setIsMaxClicked(true);
mixpanel.track('Chose max amount', {
strategyId: props.strategy.id,
strategyName: props.strategy.name,
Expand All @@ -183,7 +191,6 @@ export default function Deposit(props: DepositProps) {
</Box>
);
}

return (
<Box>
<Grid templateColumns="repeat(5, 1fr)" gap={6}>
Expand Down Expand Up @@ -259,6 +266,7 @@ export default function Deposit(props: DepositProps) {
else {
setAmount(new MyNumber('0', selectedMarket.decimals));
}
setIsMaxClicked(false);
setRawAmount(value);
setDirty(true);
mixpanel.track('Enter amount', {
Expand Down
Loading