From ec1a18142360176ac4cb8fc40c708069a0b07ef9 Mon Sep 17 00:00:00 2001 From: Pedro Yves Fracari Date: Tue, 11 Jun 2024 14:18:49 -0300 Subject: [PATCH] refactor: separete thresholds into constants file --- .../new/(components)/CreateAMMForm.tsx | 3 ++- .../src/components/DepositForm.tsx | 23 +++++++++++-------- apps/cow-amm-deployer/src/lib/constants.ts | 6 +++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/cow-amm-deployer/src/app/[userId]/new/(components)/CreateAMMForm.tsx b/apps/cow-amm-deployer/src/app/[userId]/new/(components)/CreateAMMForm.tsx index c836d4e39..f710780ea 100644 --- a/apps/cow-amm-deployer/src/app/[userId]/new/(components)/CreateAMMForm.tsx +++ b/apps/cow-amm-deployer/src/app/[userId]/new/(components)/CreateAMMForm.tsx @@ -23,6 +23,7 @@ import { Form } from "#/components/ui/form"; import { useManagedTransaction } from "#/hooks/tx-manager/useManagedTransaction"; import { useDebounce } from "#/hooks/useDebounce"; import { ConstantProductFactoryABI } from "#/lib/abis/ConstantProductFactory"; +import { UNBALANCED_USD_DIFF_THRESHOLD } from "#/lib/constants"; import { COW_CONSTANT_PRODUCT_FACTORY } from "#/lib/contracts"; import { IToken } from "#/lib/fetchAmmData"; import { ammFormSchema } from "#/lib/schema"; @@ -227,7 +228,7 @@ export function CreateAMMForm({ userId }: { userId: string }) { {amountUsdDiff} {debouncedAmountUsdDiff} - {(debouncedAmountUsdDiff || 0) > 5000 && ( + {(debouncedAmountUsdDiff || 0) > UNBALANCED_USD_DIFF_THRESHOLD && (

The difference between the USD value of the two token amounts is diff --git a/apps/cow-amm-deployer/src/components/DepositForm.tsx b/apps/cow-amm-deployer/src/components/DepositForm.tsx index 5c8825641..dbd3c5b96 100644 --- a/apps/cow-amm-deployer/src/components/DepositForm.tsx +++ b/apps/cow-amm-deployer/src/components/DepositForm.tsx @@ -10,6 +10,10 @@ import { TokenInfo } from "#/components/TokenInfo"; import { Form, FormMessage } from "#/components/ui/form"; import { useManagedTransaction } from "#/hooks/tx-manager/useManagedTransaction"; import { useDebounce } from "#/hooks/useDebounce"; +import { + PRICE_IMPACT_THRESHOLD, + USD_VALUE_FOR_PRICE_IMPACT_WARNING, +} from "#/lib/constants"; import { ICowAmm } from "#/lib/fetchAmmData"; import { calculatePriceImpact } from "#/lib/priceImpact"; import { getDepositSchema } from "#/lib/schema"; @@ -123,15 +127,16 @@ export function DepositForm({ ) } - {debouncedDepositUsdValue > 5000 && debouncedPriceImpact > 0.1 && ( - -

- The price impact of this deposit is{" "} - {formatNumber(debouncedPriceImpact * 100, 2)}%. Deposits with high - price impact may result in lost funds. -

-
- )} + {debouncedDepositUsdValue > USD_VALUE_FOR_PRICE_IMPACT_WARNING && + debouncedPriceImpact > PRICE_IMPACT_THRESHOLD && ( + +

+ The price impact of this deposit is{" "} + {formatNumber(debouncedPriceImpact * 100, 2)}%. Deposits with high + price impact may result in lost funds. +

+
+ )}