From 5fa88bebce879de62dea0e69372b43055780af81 Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Wed, 22 Jun 2022 18:58:51 +0200 Subject: [PATCH] Show how much a cancellation of a smart transaction will cost (#15011) --- app/_locales/de/messages.json | 3 -- app/_locales/el/messages.json | 3 -- app/_locales/en/messages.json | 8 +++- app/_locales/es/messages.json | 3 -- app/_locales/fr/messages.json | 3 -- app/_locales/hi/messages.json | 3 -- app/_locales/id/messages.json | 3 -- app/_locales/ja/messages.json | 3 -- app/_locales/ko/messages.json | 3 -- app/_locales/pt/messages.json | 3 -- app/_locales/ru/messages.json | 3 -- app/_locales/tl/messages.json | 3 -- app/_locales/tr/messages.json | 3 -- app/_locales/vi/messages.json | 3 -- app/_locales/zh/messages.json | 3 -- .../smart-transaction-status.js | 38 +++++++++++++++++-- 16 files changed, 40 insertions(+), 48 deletions(-) diff --git a/app/_locales/de/messages.json b/app/_locales/de/messages.json index 295dd083a..7dd71c5cd 100644 --- a/app/_locales/de/messages.json +++ b/app/_locales/de/messages.json @@ -466,9 +466,6 @@ "message": "Für eine Transaktion im Wert von $1 muss die Gasgebühr um mindestens 10 % erhöht werden, damit sie vom Netz erkannt wird.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Swap abbrechen" - }, "cancellationGasFee": { "message": "Stornierungs-Gasgebühr" }, diff --git a/app/_locales/el/messages.json b/app/_locales/el/messages.json index 4e0ea8ea2..3ddbb409e 100644 --- a/app/_locales/el/messages.json +++ b/app/_locales/el/messages.json @@ -466,9 +466,6 @@ "message": "Για να $1 τη συναλλαγή, τα τέλη συναλλαγής πρέπει να αυξηθούν κατά τουλάχιστον 10% ώστε να αναγνωριστούν από το δίκτυο.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Ακύρωση ανταλλαγής" - }, "cancellationGasFee": { "message": "Ακύρωση Χρέωσης Αερίου" }, diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 378eec13c..0f6747b4b 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -466,8 +466,12 @@ "message": "To $1 a transaction the gas fee must be increased by at least 10% for it to be recognized by the network.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Cancel swap" + "cancelSwapForFee": { + "message": "Cancel swap for ~$1", + "description": "$1 could be e.g. $2.98, it is a cost for cancelling a Smart Transaction" + }, + "cancelSwapForFree": { + "message": "Cancel swap for free" }, "cancellationGasFee": { "message": "Cancellation Gas Fee" diff --git a/app/_locales/es/messages.json b/app/_locales/es/messages.json index b71e4888a..785728f1e 100644 --- a/app/_locales/es/messages.json +++ b/app/_locales/es/messages.json @@ -466,9 +466,6 @@ "message": "Para $1 una transacción, la tarifa de gas debe aumentar al menos un 10% para que sea reconocida por la red.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Cancelar swap" - }, "cancellationGasFee": { "message": "Cuota de gas por cancelación" }, diff --git a/app/_locales/fr/messages.json b/app/_locales/fr/messages.json index abedcf7a5..5e9bb0b99 100644 --- a/app/_locales/fr/messages.json +++ b/app/_locales/fr/messages.json @@ -466,9 +466,6 @@ "message": "Pour $1 la transaction, les gas fees doivent être augmentés d’au moins 10 % pour être reconnus par le réseau.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Annuler le swap" - }, "cancellationGasFee": { "message": "Frais d’annulation de carburant" }, diff --git a/app/_locales/hi/messages.json b/app/_locales/hi/messages.json index fec5aae6c..b3b6cafec 100644 --- a/app/_locales/hi/messages.json +++ b/app/_locales/hi/messages.json @@ -466,9 +466,6 @@ "message": "किसी लेनदेन को $1 करने के लिए गैस शुल्क में कम से कम 10% की वृद्धि की जानी चाहिए ताकि उसे नेटवर्क द्वारा मान्यता मिल सके।", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "स्वैप रद्द करें" - }, "cancellationGasFee": { "message": "रद्दीकरण गैस शुल्क" }, diff --git a/app/_locales/id/messages.json b/app/_locales/id/messages.json index 84da2486d..f30dc5943 100644 --- a/app/_locales/id/messages.json +++ b/app/_locales/id/messages.json @@ -466,9 +466,6 @@ "message": "Untuk $1 suatu transaksi, biaya gas harus dinaikkan minimal 10% agar dapat dikenali oleh jaringan.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Batalkan pertukaran" - }, "cancellationGasFee": { "message": "Biaya Pembatalan Gas" }, diff --git a/app/_locales/ja/messages.json b/app/_locales/ja/messages.json index 48387e220..b4a6108af 100644 --- a/app/_locales/ja/messages.json +++ b/app/_locales/ja/messages.json @@ -466,9 +466,6 @@ "message": "トランザクションを$1するには、ネットワークに認識されるようにガス代を 10% 以上増額する必要があります。", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "スワップをキャンセル" - }, "cancellationGasFee": { "message": "キャンセルのガス代" }, diff --git a/app/_locales/ko/messages.json b/app/_locales/ko/messages.json index a0171e5fb..a0ad41425 100644 --- a/app/_locales/ko/messages.json +++ b/app/_locales/ko/messages.json @@ -466,9 +466,6 @@ "message": "거래를 $1하려면 가스비를 최소 10%를 인상해야 네트워크에서 인식될 수 있습니다.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "스왑 취소" - }, "cancellationGasFee": { "message": "가스 수수료 취소" }, diff --git a/app/_locales/pt/messages.json b/app/_locales/pt/messages.json index ac914de3b..3fbbd87ca 100644 --- a/app/_locales/pt/messages.json +++ b/app/_locales/pt/messages.json @@ -466,9 +466,6 @@ "message": "Para $1 uma transação, a taxa de gás deve ser aumentada em pelo menos 10% para que seja reconhecida pela rede.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Cancelar swap" - }, "cancellationGasFee": { "message": "Taxa de gás por cancelamento" }, diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 28ca61273..aa8be8ffd 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -466,9 +466,6 @@ "message": "Чтобы $1 транзакции плата за газ должна быть увеличена как минимум на 10%. Это позволит обеспечить прием транзакции сетью.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Отменить обмен" - }, "cancellationGasFee": { "message": "Плата за газ при отмене" }, diff --git a/app/_locales/tl/messages.json b/app/_locales/tl/messages.json index 46f47d2b3..4b8404a21 100644 --- a/app/_locales/tl/messages.json +++ b/app/_locales/tl/messages.json @@ -466,9 +466,6 @@ "message": "Sa $1 na transaksyon ang singil sa gas ay dapat tumaas nang hindi bababa sa 10% para ito ay makilala ng network.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Kanselahin ang pagpapalit" - }, "cancellationGasFee": { "message": "Bayarin sa Gasolina para sa Pagkansela" }, diff --git a/app/_locales/tr/messages.json b/app/_locales/tr/messages.json index 442079f51..1a0468bf7 100644 --- a/app/_locales/tr/messages.json +++ b/app/_locales/tr/messages.json @@ -466,9 +466,6 @@ "message": "İşlemi $1 için, gaz ücretinin ağ tarafından tanınması amacıyla en az %10 oranında artırılması gerekir.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Takası iptal et" - }, "cancellationGasFee": { "message": "İptal İşlemi Gaz Ücreti" }, diff --git a/app/_locales/vi/messages.json b/app/_locales/vi/messages.json index 6ac2d7884..1b7b5534a 100644 --- a/app/_locales/vi/messages.json +++ b/app/_locales/vi/messages.json @@ -466,9 +466,6 @@ "message": "Để $1 một giao dịch, phí gas phải tăng tối thiểu 10% để mạng nhận ra giao dịch này.", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "Hủy hoán đổi" - }, "cancellationGasFee": { "message": "Phí gas hủy" }, diff --git a/app/_locales/zh/messages.json b/app/_locales/zh/messages.json index 53e0cdb4e..83080c849 100644 --- a/app/_locales/zh/messages.json +++ b/app/_locales/zh/messages.json @@ -466,9 +466,6 @@ "message": "若要$1交易,燃料费用必须增加至少10%才能被网络认可。", "description": "$1 is string 'cancel' or 'speed up'" }, - "cancelSwap": { - "message": "取消交换" - }, "cancellationGasFee": { "message": "取消燃料费用" }, diff --git a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js index dabc29869..c11b7b82e 100644 --- a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js +++ b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js @@ -18,7 +18,12 @@ import { import { isHardwareWallet, getHardwareWalletType, -} from '../../../selectors/selectors'; + getCurrentChainId, + getUSDConversionRate, + conversionRateSelector, + getCurrentCurrency, +} from '../../../selectors'; +import { getNativeCurrency } from '../../../ducks/metamask/metamask'; import { DEFAULT_ROUTE, BUILD_QUOTE_ROUTE, @@ -44,7 +49,10 @@ import { SMART_TRANSACTION_STATUSES } from '../../../../shared/constants/transac import SwapsFooter from '../swaps-footer'; import { calcTokenAmount } from '../../../helpers/utils/token-util'; -import { showRemainingTimeInMinAndSec } from '../swaps.util'; +import { + showRemainingTimeInMinAndSec, + getFeeForSmartTransaction, +} from '../swaps.util'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import SuccessIcon from './success-icon'; import RevertedIcon from './reverted-icon'; @@ -76,9 +84,16 @@ export default function SmartTransactionStatus() { const currentSmartTransactionsEnabled = useSelector( getCurrentSmartTransactionsEnabled, ); + const chainId = useSelector(getCurrentChainId); + const nativeCurrencySymbol = useSelector(getNativeCurrency); + const conversionRate = useSelector(conversionRateSelector); + const USDConversionRate = useSelector(getUSDConversionRate); + const currentCurrency = useSelector(getCurrentCurrency); + let smartTransactionStatus = SMART_TRANSACTION_STATUSES.PENDING; let latestSmartTransaction = {}; let latestSmartTransactionUuid; + let cancellationFeeWei; if (currentSmartTransactions && currentSmartTransactions.length > 0) { latestSmartTransaction = @@ -86,6 +101,8 @@ export default function SmartTransactionStatus() { latestSmartTransactionUuid = latestSmartTransaction?.uuid; smartTransactionStatus = latestSmartTransaction?.status || SMART_TRANSACTION_STATUSES.PENDING; + cancellationFeeWei = + latestSmartTransaction?.statusMetadata?.cancellationFeeWei; } const [timeLeftForPendingStxInSec, setTimeLeftForPendingStxInSec] = useState( @@ -176,7 +193,7 @@ export default function SmartTransactionStatus() { if (isSmartTransactionPending) { if (cancelSwapLinkClicked) { headerText = t('stxTryingToCancel'); - } else if (latestSmartTransaction?.statusMetadata?.cancellationFeeWei > 0) { + } else if (cancellationFeeWei > 0) { headerText = t('stxPendingPubliclySubmittingSwap'); } } @@ -226,6 +243,17 @@ export default function SmartTransactionStatus() { latestSmartTransaction.cancellable && !cancelSwapLinkClicked; const CancelSwap = () => { + let feeInFiat; + if (cancellationFeeWei > 0) { + ({ feeInFiat } = getFeeForSmartTransaction({ + chainId, + currentCurrency, + conversionRate, + USDConversionRate, + nativeCurrencySymbol, + feeInWeiDec: cancellationFeeWei, + })); + } return ( - {t('cancelSwap')} + {feeInFiat + ? t('cancelSwapForFee', [feeInFiat]) + : t('cancelSwapForFree')} );