From 267f295bd38532428818331d0e78fa92b0c6f548 Mon Sep 17 00:00:00 2001 From: mintdart <96025197+mintdart@users.noreply.github.com> Date: Sun, 29 Dec 2024 06:24:16 -0600 Subject: [PATCH 1/2] add button to set amount near allowance --- .../Aggregator/hooks/useTokenApprove.ts | 5 ++- src/components/Aggregator/index.tsx | 43 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/components/Aggregator/hooks/useTokenApprove.ts b/src/components/Aggregator/hooks/useTokenApprove.ts index e65ebbe0..8ba3a2cb 100644 --- a/src/components/Aggregator/hooks/useTokenApprove.ts +++ b/src/components/Aggregator/hooks/useTokenApprove.ts @@ -243,6 +243,7 @@ export const useTokenApprove = ({ isConfirmingResetApproval: isResetLoading, allowance, shouldRemoveApproval, - refetch + refetch, + isAllowanceNearAmount: allowance && normalizedAmount && BigInt(normalizedAmount) > 0n && allowance > 0n && (BigInt(normalizedAmount) - (BigInt(normalizedAmount) / 10n)) <= allowance, }; -}; +}; \ No newline at end of file diff --git a/src/components/Aggregator/index.tsx b/src/components/Aggregator/index.tsx index 3098cd66..9d2816a9 100644 --- a/src/components/Aggregator/index.tsx +++ b/src/components/Aggregator/index.tsx @@ -735,7 +735,8 @@ export function AggregatorContainer({ tokenList }) { shouldRemoveApproval, allowance, errorFetchingAllowance, - refetch: refetchTokenAllowance + refetch: refetchTokenAllowance, + isAllowanceNearAmount } = useTokenApprove({ token: finalSelectedFromToken?.address as `0x${string}`, spender: @@ -1219,6 +1220,26 @@ export function AggregatorContainer({ tokenList }) { )} + {finalSelectedFromToken && isAllowanceNearAmount ? ( + <> + + {`You have approved ${(Number(allowance) / 10 ** finalSelectedFromToken.decimals).toLocaleString(undefined, { maximumFractionDigits: 2 })} ${finalSelectedFromToken.symbol} tokens previously`} + + + + ) : null} + {(hasPriceImapct || isUnknownPrice) && !isLoading && selectedRoute && isApproved ? ( )} + {finalSelectedFromToken && isAllowanceNearAmount ? ( + <> + + {`You have approved ${(Number(allowance) / 10 ** finalSelectedFromToken.decimals).toLocaleString(undefined, { maximumFractionDigits: 2 })} ${finalSelectedFromToken.symbol} tokens previously`} + + + + ) : null} + {(hasPriceImapct || isUnknownPrice) && !isLoading && selectedRoute && isApproved ? ( Date: Mon, 3 Feb 2025 03:09:21 -0600 Subject: [PATCH 2/2] update styles --- src/components/Aggregator/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Aggregator/index.tsx b/src/components/Aggregator/index.tsx index 9d2816a9..0da42fe6 100644 --- a/src/components/Aggregator/index.tsx +++ b/src/components/Aggregator/index.tsx @@ -1229,12 +1229,12 @@ export function AggregatorContainer({ tokenList }) { textAlign={'center'} >{`You have approved ${(Number(allowance) / 10 ** finalSelectedFromToken.decimals).toLocaleString(undefined, { maximumFractionDigits: 2 })} ${finalSelectedFromToken.symbol} tokens previously`} @@ -1526,12 +1526,12 @@ export function AggregatorContainer({ tokenList }) { textAlign={'center'} >{`You have approved ${(Number(allowance) / 10 ** finalSelectedFromToken.decimals).toLocaleString(undefined, { maximumFractionDigits: 2 })} ${finalSelectedFromToken.symbol} tokens previously`}