Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@ export default class TransactionController extends EventEmitter {
};

// only update what is defined
editableParams.txParams = pickBy(editableParams.txParams);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to set txParams to empty strings

editableParams.txParams = pickBy(
editableParams.txParams,
(prop) => prop !== undefined,
);

// update transaction type in case it has changes
const transactionBeforeEdit = this._getTransaction(txId);
Expand Down
24 changes: 22 additions & 2 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ const slice = createSlice({
draftTransaction.asset.type = asset.type;
draftTransaction.asset.balance = asset.balance;
draftTransaction.asset.error = asset.error;

if (
draftTransaction.asset.type === ASSET_TYPES.TOKEN ||
draftTransaction.asset.type === ASSET_TYPES.COLLECTIBLE
Expand Down Expand Up @@ -1963,6 +1964,9 @@ export function updateSendAsset(
getSelectedAddress(state);
const account = getTargetAccount(state, sendingAddress);
if (type === ASSET_TYPES.NATIVE) {
const unapprovedTxs = getUnapprovedTxs(state);
const unapprovedTx = unapprovedTxs?.[draftTransaction.id];

await dispatch(
addHistoryEntry(
`sendFlow - user set asset of type ${
Expand All @@ -1981,6 +1985,20 @@ export function updateSendAsset(
initialAssetSet,
}),
);

// This is meant to handle cases where we are editing an unapprovedTx from the background state
// and its type is a token method. In such a case, the hex data will be the necessary hex data
// for calling the contract transfer method.
// Now that we are updating the transaction to be a send of a native asset type, we should
// set the hex data of the transaction being editing to be empty.
// then the user will not want to send any hex data now that they have change the
if (
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM ||
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER ||
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_SAFE_TRANSFER_FROM
) {
await dispatch(actions.updateUserInputHexData(''));
}
} else {
await dispatch(showLoadingIndication());
const details = {
Expand Down Expand Up @@ -2217,8 +2235,10 @@ export function signTransaction() {
draftTransaction.history,
),
);
dispatch(updateEditableParams(draftTransaction.id, editingTx.txParams));
dispatch(
await dispatch(
updateEditableParams(draftTransaction.id, editingTx.txParams),
);
await dispatch(
updateTransactionGasFees(draftTransaction.id, editingTx.txParams),
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ export function updateEditableParams(txId, editableParams) {
log.error(error.message);
throw error;
}

await forceUpdateMetamaskState(dispatch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure that transaction state is properly updated before hitting the confirm screen routing logic after clicking the "Next" button

return updatedTransaction;
};
}
Expand Down