From 82dc658c92a66d40cf1d804370c2f2a2b77a1f87 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 825ef3c2d..dd8524f6f 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 ad885d64e..193b6e833 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"; @@ -124,15 +128,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. +

+
+ )}