From f5ae53bb5640b6d33234df85752c2c80113d8497 Mon Sep 17 00:00:00 2001 From: smelnikov Date: Sun, 26 Mar 2023 13:03:36 +0400 Subject: [PATCH] feat(KEEP-1217): warn about differences in amounts --- src/i18n/locales/en/extension.en.json | 1 + src/i18n/locales/ru/extension.ru.json | 1 + src/ui/components/pages/swap/form.module.css | 12 +++++ src/ui/components/pages/swap/form.tsx | 52 +++++++++++++++++--- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/i18n/locales/en/extension.en.json b/src/i18n/locales/en/extension.en.json index 618c7d845..d66c6fadf 100644 --- a/src/i18n/locales/en/extension.en.json +++ b/src/i18n/locales/en/extension.en.json @@ -590,6 +590,7 @@ }, "swap": { "amountToSendError": "Could not perform swap due to SwopFi dApp state. Please try again or slightly increase slippage tolerance if possible", + "amountDifferenceTooltip": "Some vendors cache their results, so Keeper has adjusted them to give you the most up-to-date value", "closeBtnText": "Close", "exchangeChannelConnectionError": "Could not connect to swap service. Please try again later", "exchangeChannelInvalidAssetPairError": "Asset pair is not available", diff --git a/src/i18n/locales/ru/extension.ru.json b/src/i18n/locales/ru/extension.ru.json index 2826da7ec..652fa86da 100644 --- a/src/i18n/locales/ru/extension.ru.json +++ b/src/i18n/locales/ru/extension.ru.json @@ -570,6 +570,7 @@ }, "swap": { "amountToSendError": "Не удалось выполнить обмен из-за состояния SwopFi dApp. Пожалуйста, попробуйте еще раз или немного увеличьте допуск проскальзывания, если это возможно", + "amountDifferenceTooltip": "Некоторые вендоры кешируют свои результаты, поэтому Keeper скорректировал их, чтобы предоставить вам самое актуальное значение", "closeBtnText": "Закрыть", "exchangeChannelConnectionError": "Не удалось подключиться к сервису обмена. Пожалуйста, повторите попытку позже", "exchangeChannelInvalidAssetPairError": "Валютная пара недоступна", diff --git a/src/ui/components/pages/swap/form.module.css b/src/ui/components/pages/swap/form.module.css index d185ca80a..46c7f958c 100644 --- a/src/ui/components/pages/swap/form.module.css +++ b/src/ui/components/pages/swap/form.module.css @@ -122,6 +122,12 @@ align-items: flex-end; } +.toAmountCardValueRow { + display: flex; + gap: 4px; + align-items: center; +} + .toAmountCardFormattedValue { overflow: hidden; font-size: 14px; @@ -129,6 +135,12 @@ white-space: nowrap; } +.toAmountInfoIcon { + width: 16px; + height: 16px; + fill: var(--color-black); +} + .toAmountCardUsdAmount { color: var(--color-basic500); font-size: 11px; diff --git a/src/ui/components/pages/swap/form.tsx b/src/ui/components/pages/swap/form.tsx index 20cba9682..9f3c50f80 100644 --- a/src/ui/components/pages/swap/form.tsx +++ b/src/ui/components/pages/swap/form.tsx @@ -72,6 +72,7 @@ type SwapInfoVendorState = | { type: 'data'; minimumReceivedTokens: BigNumber; + originalMinimumReceivedTokens: BigNumber; priceImpact: number; toAmountTokens: BigNumber; tx: SwapClientInvokeTransaction; @@ -322,6 +323,10 @@ export function SwapForm({ response.minimumReceivedCoins, toAsset ).getTokens(), + originalMinimumReceivedTokens: new Money( + response.originalMinimumReceivedCoins, + toAsset + ).getTokens(), priceImpact: response.priceImpact, toAmountTokens: new Money( response.amountCoins, @@ -620,6 +625,22 @@ export function SwapForm({ : info.toAmountTokens ).toFixed() ); + const minimumReceivedTokens = new BigNumber( + info.type !== 'data' + ? '0' + : (fromAmountTokens.eq(0) + ? new BigNumber(0) + : info.minimumReceivedTokens + ).toFixed() + ); + const originalMinimumReceviedTokens = new BigNumber( + info.type !== 'data' + ? '0' + : (fromAmountTokens.eq(0) + ? new BigNumber(0) + : info.originalMinimumReceivedTokens + ).toFixed() + ); const formattedValue = amountTokens.toFormat( toAssetBalance.asset.precision, @@ -675,13 +696,32 @@ export function SwapForm({ ) : info.type === 'data' ? (
-
- {formattedValue} +
+
+ {formattedValue} +
+ {minimumReceivedTokens.lt( + originalMinimumReceviedTokens + ) ? ( + + {props => ( +
+ +
+ )} +
+ ) : null}
-