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:
parent
d4f694c49f
commit
6dd141ebfd
@ -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) => ({
|
||||
|
@ -57,7 +57,7 @@ export default function TransactionStatus({
|
||||
const statusText =
|
||||
statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly
|
||||
? date
|
||||
: t(statusKey);
|
||||
: statusKey && t(statusKey);
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
getUSDConversionRate,
|
||||
isHardwareWallet,
|
||||
getHardwareWalletType,
|
||||
getSwapsDefaultToken,
|
||||
} from '../../../selectors';
|
||||
|
||||
import {
|
||||
@ -32,6 +33,7 @@ import {
|
||||
getSmartTransactionsEnabled,
|
||||
getFromTokenInputValue,
|
||||
getMaxSlippage,
|
||||
setSwapsFromToken,
|
||||
} from '../../../ducks/swaps/swaps';
|
||||
import Mascot from '../../../components/ui/mascot';
|
||||
import Box from '../../../components/ui/box';
|
||||
@ -82,6 +84,7 @@ export default function AwaitingSwap({
|
||||
const usdConversionRate = useSelector(getUSDConversionRate);
|
||||
const chainId = useSelector(getCurrentChainId);
|
||||
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual);
|
||||
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
|
||||
|
||||
const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState(
|
||||
false,
|
||||
@ -251,9 +254,10 @@ export default function AwaitingSwap({
|
||||
<Box marginBottom={3}>
|
||||
<a
|
||||
href="#"
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
makeAnotherSwapEvent();
|
||||
dispatch(navigateBackToBuildQuote(history));
|
||||
await dispatch(navigateBackToBuildQuote(history));
|
||||
dispatch(setSwapsFromToken(defaultSwapsToken));
|
||||
}}
|
||||
>
|
||||
{t('makeAnotherSwap')}
|
||||
|
@ -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);
|
||||
|
@ -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 = <SuccessIcon />;
|
||||
} else if (smartTransactionStatus === 'cancelled_user_cancelled') {
|
||||
headerText = t('stxUserCancelled');
|
||||
|
Loading…
Reference in New Issue
Block a user