Skip to content

Ensure that gas for swap tx submitted at same time as approval is in hex#10135

Merged
danjm merged 1 commit intodevelopfrom
fix-swap-tx-submission-after-approval
Jan 4, 2021
Merged

Ensure that gas for swap tx submitted at same time as approval is in hex#10135
danjm merged 1 commit intodevelopfrom
fix-swap-tx-submission-after-approval

Conversation

@danjm
Copy link
Copy Markdown
Contributor

@danjm danjm commented Jan 4, 2021

Users have experienced the following issue with swaps:

  • attempt to swap an ERC-20 token that they have not yet approved MetaSwaps to transfer (so 2 transactions will be needed: an approval tx and a swap)
  • the approve transaction successfully completes but the swap transaction does not even submit
  • then, when attempting the swap again, it completes successfully

To recreate this issue, you can do the following to test swaps on local host:

  1. Update the timeout number on line 341 of app/scripts/controllers/swaps.js of metamask from 5000 to 15000
  2. Run metamask locally, on develoop
  3. Get an infura account and copy your accounts infura endpoint
  4. Run ganache-cli --fork YOUR_INFURA_ENDPOINT
  5. copy one of the private keys that are output in the terminal
  6. connect to localhost in metamask and import the private key you just copied

The account you have just imported should have 100 eth on the local network. You should be able to make swaps with this account.

  1. Swap eth to an ERC-20, the swap should complete successfully
  2. Swap your ERC-20 tokens to something else, the approval tx should go through and the swap tx won't even be submitted, like it didn't exist

This PR fixes this issue.

Before this PR, the addUnapprovedTransaction call on line 694 of ducks/swaps/swaps.js silently fails when an approval is required because in that case usedTradeTxParams.gas is set to maxGas, which is a decimal number, but it is required to be a hex number. This issue was introduced here: https://github.com/MetaMask/metamask-extension/pull/10043/files#diff-79e282e22d97801a4a8ac7638c098e38eb40e3c46ad24ff4f7db7405dac2faabR606

This PR correctly formats the usedTradeTxParams.gas property, and everything works correctly again.

We probably should also update our error handling so that this does not fail silently, but we should do so in another PR as this relates to this issue #9948, which requires a small amount of design work.

@danjm danjm requested a review from a team as a code owner January 4, 2021 17:27
@danjm danjm requested review from Gudahtt and darkwing January 4, 2021 17:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 4, 2021

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.

darkwing
darkwing previously approved these changes Jan 4, 2021
@danjm danjm force-pushed the fix-swap-tx-submission-after-approval branch from e55c39f to 1677637 Compare January 4, 2021 17:48
@darkwing darkwing self-requested a review January 4, 2021 17:54
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [1677637]
Page Load Metrics (480 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30534474
domContentLoaded3226214789847
load3246224809847
domInteractive3226214789847

@danjm danjm merged commit 2957906 into develop Jan 4, 2021
@danjm danjm deleted the fix-swap-tx-submission-after-approval branch January 4, 2021 18:13
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2021
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.

3 participants