Skip to content

Conversation

@danjm
Copy link
Contributor

@danjm danjm commented Jul 15, 2022

Fixes #15184

Preceding v10.18.0 there was a problem whereby changing from a token transfer to a simple send on the send edit screen would not change the transaction data. This would incorrectly leave the rendered type as transfer and incorrectly leave hex data on the transaction.

With v10.18.0, this could cause an unhandled error when trying to edit a transaction in this state of faulty data, because we would attempt to parse the recipient address of a simple send as if it were a token address.

The solution requires two parts:

  1. Ensure that the transaction data gets correctly reset when changing a transaction from a transfer to a simple send
  2. Ensure that we wait for the background state update to complete and be reflected in the UI state before returning to the confirm screen after editing a transaction

@danjm danjm requested a review from a team as a code owner July 15, 2022 00:08
@danjm danjm requested a review from digiwand July 15, 2022 00:08
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

};

// 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

@metamaskbot
Copy link
Collaborator

Builds ready [e7e053b]
Page Load Metrics (1805 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90145111157
domContentLoaded15522251179014871
load15522271180514670
domInteractive15522251179014871

highlights:

storybook

// transaction from being a token transfer to a simple send.
if (
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM ||
unapprovedTx?.type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is nitty, but when I read this comment I thought unapprovedTx was like...any unapproved tx. Can we change this comment to be something along the lines of if the original type of this transaction was a token method then we need to null out he usetInputHeadData (words are not important just specifying original and ensuring that the unapprovedTx is clearly marked as the original tx in an edit flow)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment improved in 91d8a85d2

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include TOKEN_METHOD_SAFE_TRANSFER_FROM here. I don't believe it's possible for it to be a problem at the moment because it's a method on ERC721's and we don't enable the edit button on ERC721 sends at the moment, but we may want to soon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added in 1eed22c

Comment on lines 2145 to 2164
// If, after edit, we are sending the native asset,
// and if the send duck hex data was reset on this edit,
// and if the hex data from the tx's background state matches
// one of the special token methods that we handle,
// then we conclude that the user does not want to send hex data,
// and ensure it gets reset in the background state as well.
const sendingNativeAsset =
draftTransaction.asset.type === ASSET_TYPES.NATIVE;
const userInputHexDataHasBeenReset =
draftTransaction.userInputHexData === '';
const priorHexDataMatchesSpecialTokenTxSignatures =
parseStandardTokenTransactionData(editingTx.txParams.data) !==
undefined;
if (
sendingNativeAsset &&
userInputHexDataHasBeenReset &&
priorHexDataMatchesSpecialTokenTxSignatures
) {
editingTx.txParams.data = '';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I"m confused why we can't just rely upon the value of userInputHexData to override this? It should be set to an empty string n 1920, therefor the call to generateTransactionParams on line 2115 should return an appropriate txParams object. with data null. Can you help me understand why this contract breaks down under these special conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes removed in ee260f475

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

@danjm danjm added this to the v10.18.0 milestone Jul 20, 2022
@danjm danjm force-pushed the modify-tx-type-send-edit branch from ee260f4 to 97745fa Compare July 20, 2022 19:42
Comment on lines 941 to 946
// If an asset update occurs that changes the type from 'NATIVE' to
// 'NATIVE' then this is likely the initial asset set of an edit
// transaction. We don't need to set the amount to zero in this case.
// The only times where an update would occur of this nature that we
// would want to set the amount to zero is on a network or account change
// but that update is handled elsewhere.
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this comment added back?

Copy link
Contributor

Choose a reason for hiding this comment

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

rebase issue more than likely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will reapprove after this is removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in 9514f02

Comment on lines 941 to 946
// If an asset update occurs that changes the type from 'NATIVE' to
// 'NATIVE' then this is likely the initial asset set of an edit
// transaction. We don't need to set the amount to zero in this case.
// The only times where an update would occur of this nature that we
// would want to set the amount to zero is on a network or account change
// but that update is handled elsewhere.
Copy link
Contributor

Choose a reason for hiding this comment

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

I will reapprove after this is removed

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [1eed22c]
Page Load Metrics (1690 ± 36 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint851906265504242
domContentLoaded1603191016867536
load1603191116907536
domInteractive1603191016867536

highlights:

storybook

Copy link
Contributor

@NiranjanaBinoy NiranjanaBinoy left a comment

Choose a reason for hiding this comment

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

LGTM

@danjm danjm merged commit a0c9738 into develop Jul 20, 2022
@danjm danjm deleted the modify-tx-type-send-edit branch July 20, 2022 23:03
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Uncaught (in promise) Error: Unable to determine contract standard

6 participants