Skip to content

Commit a0c9738

Browse files
authored
Ensure that editing a tx from a transfer to a simple send resets data and updates type (#15248)
* Ensure that editing a transaction from a transfer to a simple send properly resets data and updates type * Handle case where there are no unapproved txes * Improve comment in updateSendAsset * Remove unnecessary code in send transaction edit function * Fix * Ensure hex data is properly reset when changing from a safe transfer from tx to native send
1 parent 9e18149 commit a0c9738

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

app/scripts/controllers/transactions/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,10 @@ export default class TransactionController extends EventEmitter {
462462
};
463463

464464
// only update what is defined
465-
editableParams.txParams = pickBy(editableParams.txParams);
465+
editableParams.txParams = pickBy(
466+
editableParams.txParams,
467+
(prop) => prop !== undefined,
468+
);
466469

467470
// update transaction type in case it has changes
468471
const transactionBeforeEdit = this._getTransaction(txId);

ui/ducks/send/send.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ const slice = createSlice({
937937
draftTransaction.asset.type = asset.type;
938938
draftTransaction.asset.balance = asset.balance;
939939
draftTransaction.asset.error = asset.error;
940+
940941
if (
941942
draftTransaction.asset.type === ASSET_TYPES.TOKEN ||
942943
draftTransaction.asset.type === ASSET_TYPES.COLLECTIBLE
@@ -1963,6 +1964,9 @@ export function updateSendAsset(
19631964
getSelectedAddress(state);
19641965
const account = getTargetAccount(state, sendingAddress);
19651966
if (type === ASSET_TYPES.NATIVE) {
1967+
const unapprovedTxs = getUnapprovedTxs(state);
1968+
const unapprovedTx = unapprovedTxs?.[draftTransaction.id];
1969+
19661970
await dispatch(
19671971
addHistoryEntry(
19681972
`sendFlow - user set asset of type ${
@@ -1981,6 +1985,20 @@ export function updateSendAsset(
19811985
initialAssetSet,
19821986
}),
19831987
);
1988+
1989+
// This is meant to handle cases where we are editing an unapprovedTx from the background state
1990+
// and its type is a token method. In such a case, the hex data will be the necessary hex data
1991+
// for calling the contract transfer method.
1992+
// Now that we are updating the transaction to be a send of a native asset type, we should
1993+
// set the hex data of the transaction being editing to be empty.
1994+
// then the user will not want to send any hex data now that they have change the
1995+
if (
1996+
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM ||
1997+
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER ||
1998+
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_SAFE_TRANSFER_FROM
1999+
) {
2000+
await dispatch(actions.updateUserInputHexData(''));
2001+
}
19842002
} else {
19852003
await dispatch(showLoadingIndication());
19862004
const details = {
@@ -2217,8 +2235,10 @@ export function signTransaction() {
22172235
draftTransaction.history,
22182236
),
22192237
);
2220-
dispatch(updateEditableParams(draftTransaction.id, editingTx.txParams));
2221-
dispatch(
2238+
await dispatch(
2239+
updateEditableParams(draftTransaction.id, editingTx.txParams),
2240+
);
2241+
await dispatch(
22222242
updateTransactionGasFees(draftTransaction.id, editingTx.txParams),
22232243
);
22242244
} else {

ui/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ export function updateEditableParams(txId, editableParams) {
745745
log.error(error.message);
746746
throw error;
747747
}
748-
748+
await forceUpdateMetamaskState(dispatch);
749749
return updatedTransaction;
750750
};
751751
}

0 commit comments

Comments
 (0)