Skip to content

Commit

Permalink
feat(KEEP-1217): warn about differences in amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
smelnikov committed Mar 30, 2023
1 parent 25f82f1 commit f5ae53b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/i18n/locales/en/extension.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ru/extension.ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@
},
"swap": {
"amountToSendError": "Не удалось выполнить обмен из-за состояния SwopFi dApp. Пожалуйста, попробуйте еще раз или немного увеличьте допуск проскальзывания, если это возможно",
"amountDifferenceTooltip": "Некоторые вендоры кешируют свои результаты, поэтому Keeper скорректировал их, чтобы предоставить вам самое актуальное значение",
"closeBtnText": "Закрыть",
"exchangeChannelConnectionError": "Не удалось подключиться к сервису обмена. Пожалуйста, повторите попытку позже",
"exchangeChannelInvalidAssetPairError": "Валютная пара недоступна",
Expand Down
12 changes: 12 additions & 0 deletions src/ui/components/pages/swap/form.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,25 @@
align-items: flex-end;
}

.toAmountCardValueRow {
display: flex;
gap: 4px;
align-items: center;
}

.toAmountCardFormattedValue {
overflow: hidden;
font-size: 14px;
text-overflow: ellipsis;
white-space: nowrap;
}

.toAmountInfoIcon {
width: 16px;
height: 16px;
fill: var(--color-black);
}

.toAmountCardUsdAmount {
color: var(--color-basic500);
font-size: 11px;
Expand Down
52 changes: 46 additions & 6 deletions src/ui/components/pages/swap/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type SwapInfoVendorState =
| {
type: 'data';
minimumReceivedTokens: BigNumber;
originalMinimumReceivedTokens: BigNumber;
priceImpact: number;
toAmountTokens: BigNumber;
tx: SwapClientInvokeTransaction;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -675,13 +696,32 @@ export function SwapForm({
<Loader />
) : info.type === 'data' ? (
<div className={styles.toAmountCardValue}>
<div
className={styles.toAmountCardFormattedValue}
title={formattedValue}
>
{formattedValue}
<div className={styles.toAmountCardValueRow}>
<div
className={styles.toAmountCardFormattedValue}
title={formattedValue}
>
{formattedValue}
</div>
{minimumReceivedTokens.lt(
originalMinimumReceviedTokens
) ? (
<Tooltip
className={styles.tooltipContent}
content={t('swap.amountDifferenceTooltip')}
placement="top"
>
{props => (
<div
{...props}
className={styles.toAmountInfoIcon}
>
<InfoIcon />
</div>
)}
</Tooltip>
) : null}
</div>

<UsdAmount
id={toAssetId}
className={styles.toAmountCardUsdAmount}
Expand Down

0 comments on commit f5ae53b

Please sign in to comment.