diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index 0bbed0998..7ebcde2b0 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -2218,7 +2218,6 @@ describe('Transaction Controller', function () { }); result = txStateManager.getTransaction('1'); - console.log(result); assert.equal(result.estimateUsed, '0x13'); assert.equal(result.txParams.gasPrice, '0x14'); assert.equal(result.destinationTokenAddress, VALID_ADDRESS_TWO); // not updated even though it's passed in to update diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 1946fa9d2..8acf69a68 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1531,6 +1531,14 @@ export default class MetamaskController extends EventEmitter { updateTransactionGasFees: txController.updateTransactionGasFees.bind( txController, ), + + updateSwapApprovalTransaction: txController.updateSwapApprovalTransaction.bind( + txController, + ), + updateSwapTransaction: txController.updateSwapTransaction.bind( + txController, + ), + // messageManager signMessage: this.signMessage.bind(this), cancelMessage: this.cancelMessage.bind(this), diff --git a/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js b/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js index 26727090d..21f16a640 100644 --- a/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js +++ b/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js @@ -12,8 +12,8 @@ import { ASSET_ROUTE, } from '../../../../helpers/constants/routes'; import { getCollectibles } from '../../../../ducks/metamask/metamask'; -import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils'; import { removeToken } from '../../../../store/actions'; +import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils'; const ConvertTokenToNFTModal = ({ hideModal, tokenAddress }) => { const history = useHistory(); diff --git a/ui/ducks/swaps/swaps.js b/ui/ducks/swaps/swaps.js index 84d26b2a2..95fe8d22b 100644 --- a/ui/ducks/swaps/swaps.js +++ b/ui/ducks/swaps/swaps.js @@ -18,7 +18,8 @@ import { setTradeTxId, stopPollingForQuotes, updateAndApproveTx, - updateTransaction, + updateSwapApprovalTransaction, + updateSwapTransaction, resetBackgroundSwapsState, setSwapsLiveness, setSwapsFeatureFlags, @@ -1152,15 +1153,10 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => { ); await dispatch(setApproveTxId(approveTxMeta.id)); finalApproveTxMeta = await dispatch( - updateTransaction( - { - ...approveTxMeta, - estimatedBaseFee: decEstimatedBaseFee, - type: TRANSACTION_TYPES.SWAP_APPROVAL, - sourceTokenSymbol: sourceTokenInfo.symbol, - }, - true, - ), + updateSwapApprovalTransaction(approveTxMeta.id, { + type: TRANSACTION_TYPES.SWAP_APPROVAL, + sourceTokenSymbol: sourceTokenInfo.symbol, + }), ); try { await dispatch(updateAndApproveTx(finalApproveTxMeta, true)); @@ -1196,21 +1192,17 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => { return; } const finalTradeTxMeta = await dispatch( - updateTransaction( - { - ...tradeTxMeta, - estimatedBaseFee: decEstimatedBaseFee, - sourceTokenSymbol: sourceTokenInfo.symbol, - destinationTokenSymbol: destinationTokenInfo.symbol, - type: TRANSACTION_TYPES.SWAP, - destinationTokenDecimals: destinationTokenInfo.decimals, - destinationTokenAddress: destinationTokenInfo.address, - swapMetaData, - swapTokenValue, - approvalTxId: finalApproveTxMeta?.id, - }, - true, - ), + updateSwapTransaction(tradeTxMeta.id, { + estimatedBaseFee: decEstimatedBaseFee, + sourceTokenSymbol: sourceTokenInfo.symbol, + destinationTokenSymbol: destinationTokenInfo.symbol, + type: TRANSACTION_TYPES.SWAP, + destinationTokenDecimals: destinationTokenInfo.decimals, + destinationTokenAddress: destinationTokenInfo.address, + swapMetaData, + swapTokenValue, + approvalTxId: finalApproveTxMeta?.id, + }), ); try { await dispatch(updateAndApproveTx(finalTradeTxMeta, true)); diff --git a/ui/store/actions.js b/ui/store/actions.js index 698508883..6461f29da 100644 --- a/ui/store/actions.js +++ b/ui/store/actions.js @@ -671,6 +671,24 @@ const updateMetamaskStateFromBackground = () => { }); }; +export function updateSwapApprovalTransaction(txId, txSwapApproval) { + return async (dispatch) => { + try { + await promisifiedBackground.updateSwapApprovalTransaction( + txId, + txSwapApproval, + ); + } catch (error) { + dispatch(txError(error)); + dispatch(goHome()); + log.error(error.message); + throw error; + } + + return txSwapApproval; + }; +} + export function updateEditableParams(txId, editableParams) { return async (dispatch) => { try { @@ -682,12 +700,6 @@ export function updateEditableParams(txId, editableParams) { throw error; } - dispatch( - updateTransactionParams(editableParams.id, editableParams.txParams), - ); - const newState = await updateMetamaskStateFromBackground(); - dispatch(updateMetamaskState(newState)); - dispatch(showConfTxPage({ id: editableParams.id })); return editableParams; }; } @@ -703,14 +715,25 @@ export function updateTransactionGasFees(txId, txGasFees) { throw error; } - dispatch(updateTransactionParams(txGasFees.id, txGasFees.txParams)); - const newState = await updateMetamaskStateFromBackground(); - dispatch(updateMetamaskState(newState)); - dispatch(showConfTxPage({ id: txGasFees.id })); return txGasFees; }; } +export function updateSwapTransaction(txId, txSwap) { + return async (dispatch) => { + try { + await promisifiedBackground.updateSwapTransaction(txId, txSwap); + } catch (error) { + dispatch(txError(error)); + dispatch(goHome()); + log.error(error.message); + throw error; + } + + return txSwap; + }; +} + export function updateTransaction(txData, dontShowLoadingIndicator) { return async (dispatch) => { !dontShowLoadingIndicator && dispatch(showLoadingIndication());