From 6dd141ebfddd0d9fecbad05b7beed136eb710508 Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Wed, 23 Feb 2022 22:10:28 +0100 Subject: [PATCH] Small fixes for Swaps (#13732) * Fix: Insufficient number of substitutions for key "stxSuccessDescription" * Only calculate "approvalGas" if the "approvalNeeded" param is truthy in a quote * "Swap from" has to be set to enable "Review Swap", set a default token for "Swap from" * Fix: Unable to find value of key "undefined" for locale * Use array destructuring --- app/scripts/controllers/swaps.js | 6 ++++-- .../transaction-status/transaction-status.component.js | 2 +- ui/pages/swaps/awaiting-swap/awaiting-swap.js | 8 ++++++-- ui/pages/swaps/build-quote/build-quote.js | 1 + .../smart-transaction-status/smart-transaction-status.js | 4 +++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index 5684c8ba4..8b16a86dc 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -289,14 +289,16 @@ export default class SwapsController { fetchParams.fromAddress, chainId, ); + const [firstQuote] = Object.values(newQuotes); // For a user to be able to swap a token, they need to have approved the MetaSwap contract to withdraw that token. // _getERC20Allowance() returns the amount of the token they have approved for withdrawal. If that amount is greater // than 0, it means that approval has already occurred and is not needed. Otherwise, for tokens to be swapped, a new // call of the ERC-20 approve method is required. approvalRequired = + firstQuote.approvalNeeded && allowance.eq(0) && - Object.values(newQuotes)[0].aggregator !== 'wrappedNative'; + firstQuote.aggregator !== 'wrappedNative'; if (!approvalRequired) { newQuotes = mapValues(newQuotes, (quote) => ({ ...quote, @@ -304,7 +306,7 @@ export default class SwapsController { })); } else if (!isPolledRequest) { const { gasLimit: approvalGas } = await this.timedoutGasReturn( - Object.values(newQuotes)[0].approvalNeeded, + firstQuote.approvalNeeded, ); newQuotes = mapValues(newQuotes, (quote) => ({ diff --git a/ui/components/app/transaction-status/transaction-status.component.js b/ui/components/app/transaction-status/transaction-status.component.js index 584989adb..000c84a28 100644 --- a/ui/components/app/transaction-status/transaction-status.component.js +++ b/ui/components/app/transaction-status/transaction-status.component.js @@ -57,7 +57,7 @@ export default function TransactionStatus({ const statusText = statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly ? date - : t(statusKey); + : statusKey && t(statusKey); return ( { + onClick={async () => { makeAnotherSwapEvent(); - dispatch(navigateBackToBuildQuote(history)); + await dispatch(navigateBackToBuildQuote(history)); + dispatch(setSwapsFromToken(defaultSwapsToken)); }} > {t('makeAnotherSwap')} diff --git a/ui/pages/swaps/build-quote/build-quote.js b/ui/pages/swaps/build-quote/build-quote.js index 363edd5e7..d4eccac17 100644 --- a/ui/pages/swaps/build-quote/build-quote.js +++ b/ui/pages/swaps/build-quote/build-quote.js @@ -510,6 +510,7 @@ export default function BuildQuote({ !isFeatureFlagLoaded || !Number(fromTokenInputValue) || !selectedToToken?.address || + !fromTokenAddress || Number(maxSlippage) < 0 || Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE || (toTokenIsNotDefault && occurrences < 2 && !verificationClicked); 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 b605495d3..8087020b2 100644 --- a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js +++ b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js @@ -188,7 +188,9 @@ export default function SmartTransactionStatus() { } if (smartTransactionStatus === SMART_TRANSACTION_STATUSES.SUCCESS) { headerText = t('stxSuccess'); - description = t('stxSuccessDescription', [destinationTokenInfo?.symbol]); + if (destinationTokenInfo?.symbol) { + description = t('stxSuccessDescription', [destinationTokenInfo.symbol]); + } icon = ; } else if (smartTransactionStatus === 'cancelled_user_cancelled') { headerText = t('stxUserCancelled');