1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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
This commit is contained in:
Daniel 2022-02-23 22:10:28 +01:00 committed by ryanml
parent 676507a518
commit e937d9c8e3
4 changed files with 12 additions and 5 deletions

View File

@ -270,14 +270,16 @@ export default class SwapsController {
fetchParams.fromAddress, fetchParams.fromAddress,
chainId, 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. // 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 // _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 // 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. // call of the ERC-20 approve method is required.
approvalRequired = approvalRequired =
firstQuote.approvalNeeded &&
allowance.eq(0) && allowance.eq(0) &&
Object.values(newQuotes)[0].aggregator !== 'wrappedNative'; firstQuote.aggregator !== 'wrappedNative';
if (!approvalRequired) { if (!approvalRequired) {
newQuotes = mapValues(newQuotes, (quote) => ({ newQuotes = mapValues(newQuotes, (quote) => ({
...quote, ...quote,
@ -285,7 +287,7 @@ export default class SwapsController {
})); }));
} else if (!isPolledRequest) { } else if (!isPolledRequest) {
const { gasLimit: approvalGas } = await this.timedoutGasReturn( const { gasLimit: approvalGas } = await this.timedoutGasReturn(
Object.values(newQuotes)[0].approvalNeeded, firstQuote.approvalNeeded,
); );
newQuotes = mapValues(newQuotes, (quote) => ({ newQuotes = mapValues(newQuotes, (quote) => ({

View File

@ -57,7 +57,7 @@ export default function TransactionStatus({
const statusText = const statusText =
statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly
? date ? date
: t(statusKey); : statusKey && t(statusKey);
return ( return (
<Tooltip <Tooltip

View File

@ -17,6 +17,7 @@ import {
getUSDConversionRate, getUSDConversionRate,
isHardwareWallet, isHardwareWallet,
getHardwareWalletType, getHardwareWalletType,
getSwapsDefaultToken,
} from '../../../selectors'; } from '../../../selectors';
import { import {
@ -30,6 +31,7 @@ import {
prepareToLeaveSwaps, prepareToLeaveSwaps,
getFromTokenInputValue, getFromTokenInputValue,
getMaxSlippage, getMaxSlippage,
setSwapsFromToken,
} from '../../../ducks/swaps/swaps'; } from '../../../ducks/swaps/swaps';
import Mascot from '../../../components/ui/mascot'; import Mascot from '../../../components/ui/mascot';
import Box from '../../../components/ui/box'; import Box from '../../../components/ui/box';
@ -80,6 +82,7 @@ export default function AwaitingSwap({
const usdConversionRate = useSelector(getUSDConversionRate); const usdConversionRate = useSelector(getUSDConversionRate);
const chainId = useSelector(getCurrentChainId); const chainId = useSelector(getCurrentChainId);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual); const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual);
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState( const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState(
false, false,
@ -243,9 +246,10 @@ export default function AwaitingSwap({
<Box marginBottom={3}> <Box marginBottom={3}>
<a <a
href="#" href="#"
onClick={() => { onClick={async () => {
makeAnotherSwapEvent(); makeAnotherSwapEvent();
dispatch(navigateBackToBuildQuote(history)); await dispatch(navigateBackToBuildQuote(history));
dispatch(setSwapsFromToken(defaultSwapsToken));
}} }}
> >
{t('makeAnotherSwap')} {t('makeAnotherSwap')}

View File

@ -454,6 +454,7 @@ export default function BuildQuote({
!isFeatureFlagLoaded || !isFeatureFlagLoaded ||
!Number(fromTokenInputValue) || !Number(fromTokenInputValue) ||
!selectedToToken?.address || !selectedToToken?.address ||
!fromTokenAddress ||
Number(maxSlippage) < 0 || Number(maxSlippage) < 0 ||
Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE || Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE ||
(toTokenIsNotDefault && occurrences < 2 && !verificationClicked); (toTokenIsNotDefault && occurrences < 2 && !verificationClicked);