Skip to content

Commit f5ae53b

Browse files
committed
feat(KEEP-1217): warn about differences in amounts
1 parent 25f82f1 commit f5ae53b

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

src/i18n/locales/en/extension.en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@
590590
},
591591
"swap": {
592592
"amountToSendError": "Could not perform swap due to SwopFi dApp state. Please try again or slightly increase slippage tolerance if possible",
593+
"amountDifferenceTooltip": "Some vendors cache their results, so Keeper has adjusted them to give you the most up-to-date value",
593594
"closeBtnText": "Close",
594595
"exchangeChannelConnectionError": "Could not connect to swap service. Please try again later",
595596
"exchangeChannelInvalidAssetPairError": "Asset pair is not available",

src/i18n/locales/ru/extension.ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@
570570
},
571571
"swap": {
572572
"amountToSendError": "Не удалось выполнить обмен из-за состояния SwopFi dApp. Пожалуйста, попробуйте еще раз или немного увеличьте допуск проскальзывания, если это возможно",
573+
"amountDifferenceTooltip": "Некоторые вендоры кешируют свои результаты, поэтому Keeper скорректировал их, чтобы предоставить вам самое актуальное значение",
573574
"closeBtnText": "Закрыть",
574575
"exchangeChannelConnectionError": "Не удалось подключиться к сервису обмена. Пожалуйста, повторите попытку позже",
575576
"exchangeChannelInvalidAssetPairError": "Валютная пара недоступна",

src/ui/components/pages/swap/form.module.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,25 @@
122122
align-items: flex-end;
123123
}
124124

125+
.toAmountCardValueRow {
126+
display: flex;
127+
gap: 4px;
128+
align-items: center;
129+
}
130+
125131
.toAmountCardFormattedValue {
126132
overflow: hidden;
127133
font-size: 14px;
128134
text-overflow: ellipsis;
129135
white-space: nowrap;
130136
}
131137

138+
.toAmountInfoIcon {
139+
width: 16px;
140+
height: 16px;
141+
fill: var(--color-black);
142+
}
143+
132144
.toAmountCardUsdAmount {
133145
color: var(--color-basic500);
134146
font-size: 11px;

src/ui/components/pages/swap/form.tsx

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type SwapInfoVendorState =
7272
| {
7373
type: 'data';
7474
minimumReceivedTokens: BigNumber;
75+
originalMinimumReceivedTokens: BigNumber;
7576
priceImpact: number;
7677
toAmountTokens: BigNumber;
7778
tx: SwapClientInvokeTransaction;
@@ -322,6 +323,10 @@ export function SwapForm({
322323
response.minimumReceivedCoins,
323324
toAsset
324325
).getTokens(),
326+
originalMinimumReceivedTokens: new Money(
327+
response.originalMinimumReceivedCoins,
328+
toAsset
329+
).getTokens(),
325330
priceImpact: response.priceImpact,
326331
toAmountTokens: new Money(
327332
response.amountCoins,
@@ -620,6 +625,22 @@ export function SwapForm({
620625
: info.toAmountTokens
621626
).toFixed()
622627
);
628+
const minimumReceivedTokens = new BigNumber(
629+
info.type !== 'data'
630+
? '0'
631+
: (fromAmountTokens.eq(0)
632+
? new BigNumber(0)
633+
: info.minimumReceivedTokens
634+
).toFixed()
635+
);
636+
const originalMinimumReceviedTokens = new BigNumber(
637+
info.type !== 'data'
638+
? '0'
639+
: (fromAmountTokens.eq(0)
640+
? new BigNumber(0)
641+
: info.originalMinimumReceivedTokens
642+
).toFixed()
643+
);
623644

624645
const formattedValue = amountTokens.toFormat(
625646
toAssetBalance.asset.precision,
@@ -675,13 +696,32 @@ export function SwapForm({
675696
<Loader />
676697
) : info.type === 'data' ? (
677698
<div className={styles.toAmountCardValue}>
678-
<div
679-
className={styles.toAmountCardFormattedValue}
680-
title={formattedValue}
681-
>
682-
{formattedValue}
699+
<div className={styles.toAmountCardValueRow}>
700+
<div
701+
className={styles.toAmountCardFormattedValue}
702+
title={formattedValue}
703+
>
704+
{formattedValue}
705+
</div>
706+
{minimumReceivedTokens.lt(
707+
originalMinimumReceviedTokens
708+
) ? (
709+
<Tooltip
710+
className={styles.tooltipContent}
711+
content={t('swap.amountDifferenceTooltip')}
712+
placement="top"
713+
>
714+
{props => (
715+
<div
716+
{...props}
717+
className={styles.toAmountInfoIcon}
718+
>
719+
<InfoIcon />
720+
</div>
721+
)}
722+
</Tooltip>
723+
) : null}
683724
</div>
684-
685725
<UsdAmount
686726
id={toAssetId}
687727
className={styles.toAmountCardUsdAmount}

0 commit comments

Comments
 (0)