1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
Commit Graph

185 Commits

Author SHA1 Message Date
Brad Decker
e5688c024e
consolidate segment setup (#9617)
Consolidates the background and UI segment implementations into a shared solution.

This results in the introduction of our first shared module.

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
2020-10-21 16:10:55 -05:00
Dan J Miller
00c8609f95
Add data point to 'Swaps Completed' segment event: estimated vs used gas (#9571)
* Add data point to 'Swaps Completed' segment event: estimated vs used gas

* Linted

* Correct property name for estimated gas on swapMetaData in _trackSwapsMetrics()

* Set estimated_gas property on swapMetaData to a hex string

* Correct base when dividing by estimated_gas

Co-authored-by: Dan Finlay <dan@danfinlay.com>
2020-10-13 16:11:26 -02:30
Dan J Miller
f3bd717184
Account for approval gas costs in eth received (#9559)
* Account for approval gas costs in eth received

* Pass approval txMeta to getSwapsTokensReceivedFromTxMeta in swaps/index.js
2020-10-12 17:26:53 -02:30
Dan J Miller
dc5edb5431
Fix calculation and display of eth received amounts in swaps (#9546)
* Update txMeta after postTxBalance has been retrieved

* Use gas used from txReceipt to calculate eth received

* Return null from getSwapsTokensReceivedFromTxMeta in tokenSymbol is ETH and txReceipt is missing

* Get latest txMeta before updating it with postTxBalance in case of a swaps tx in confirmTransaction

* Lint fix
2020-10-12 07:52:51 -02:30
Dan J Miller
6409caa081
Use initial transaction for settings swap transaction title params (#9543)
* Use initial transaction for settings swap transaction title params, and remove addition of swap properties to cancel transcations

* Update unit test data

* Use token symbol properties from initial transaction for filitering in transaction list
2020-10-10 17:20:20 -02:30
Dan J Miller
325dd9c036
call this.txStateManager.setTxStatusConfirmed before async call in confirmTransaction (#9522)
* call this.txStateManager.setTxStatusConfirmed before async call in confirmTransaction in the transactions controller

* Clone txMeta before setTxStatusConfirmed in confirmTransaction

* Correctly updateTx in confirmTransaction

* Track swaps event only if it is a swap transaction
2020-10-08 11:31:35 -07:00
Erik Marks
7870d6d194
Use Segment for web3 usage metrics; fix background Segment bugs (#9525)
* Use segment for window.web3 usage metrics
* Add Segment referrer information
* Fix track segment event bug
* Fix missing category bug in tx segment event

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-10-08 11:00:56 -07:00
Erik Marks
30d6ad83f7
Refactor background Segment usage (#9509)
* Create wrapper function for segment events
* Extract transaction controller metrics calls into own function

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-10-08 09:41:23 -07:00
Dan J Miller
443c280b4a
quote_vs_executionRatio property to Swap Completed segment event (#9508) 2020-10-07 23:54:04 -02:30
Whymarrh Whitby
b89c8fec13
Fix version used by TransactionController#confirmTransaction (#9503) 2020-10-07 14:27:39 -07:00
Erik Marks
6a6600c730
Use networkVersion for network state; chainId for signing transactions (#9487) 2020-10-06 17:48:24 -02:30
Dan J Miller
30d13422b5
Add MetaMask Swaps (#9482) 2020-10-06 15:58:38 -02:30
Erik Marks
3aaa41ef44
Replace abi-decoder with ethers (#9290)
* replace abi-decoder with ethers

* handle transaction parsing errors

* update token param getter function names

* add docstrings
2020-08-21 19:29:19 -07:00
Whymarrh Whitby
b6ccd22d6c
Update ESLint shared config to v3 (#9274)
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-08-19 13:57:05 -02:30
Whymarrh Whitby
6ab12001e3
Fix prefer-destructuring issues (#9263)
See [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring) for more information.

This change enables `prefer-destructuring` and fixes the issues raised by the rule.
2020-08-18 17:36:58 -02:30
Whymarrh Whitby
c1e3c229bc
Fix import/order issues (#9239)
See [`import/order`](https://eslint.org/docs/rules/import/order) for more information.

This change enables `import/order` and fixes the issues raised by the rule.
2020-08-18 16:48:25 -02:30
Whymarrh Whitby
b7259e5d6a
Fix radix issues (#9247)
See [`radix`](https://eslint.org/docs/rules/radix) for more information.

This change enables `radix` and fixes the issues raised by the rule.
2020-08-18 16:38:22 -02:30
Whymarrh Whitby
4357cda7b8
Fix no-shadow issues (#9246)
See [`no-shadow`](https://eslint.org/docs/rules/no-shadow) for more information.

This change enables `no-shadow` and fixes the issues raised by the rule.
2020-08-18 14:06:45 -02:30
Whymarrh Whitby
e803807dd9
Fix no-param-reassign issues (#9235)
See [`no-param-reassign`](https://eslint.org/docs/rules/no-param-reassign) for more information.

This change enables `no-param-reassign` and fixes the issues raised by the rule.
2020-08-15 09:28:11 -02:30
Whymarrh Whitby
884775cf71
Fix no-negated-condition issues (#9222)
See [`no-negated-condition`](https://eslint.org/docs/rules/no-negated-condition) for more information.

This change enables `no-negated-condition` and fixes the issues raised by the rule.
2020-08-14 09:17:43 -02:30
Whymarrh Whitby
9b78d3ab07
Fix import/extensions issues (#9217)
See [`import/extensions`](https://eslint.org/docs/rules/import/extensions) for more information.

This change enables `import/extensions` and fixes the issues raised by the rule.
2020-08-14 09:16:45 -02:30
Whymarrh Whitby
cd370be728
Fix no-invalid-this issues (#9207)
See [`no-invalid-this`](https://eslint.org/docs/rules/no-invalid-this) for more information.

This change enables `no-invalid-this` and fixes the issues raised by the rule.
2020-08-12 21:19:33 -02:30
Whymarrh Whitby
c0f05ccae6
Fix implicit-arrow-linebreak issues (#9201)
See [`implicit-arrow-linebreak`](https://eslint.org/docs/rules/implicit-arrow-linebreak) for more information.

This change enables `implicit-arrow-linebreak` and fixes the issues raised by the rule.
2020-08-12 21:19:10 -02:30
Whymarrh Whitby
310b15ba4a
Fix no-plusplus issues (#9206)
See [`no-plusplus`](https://eslint.org/docs/rules/no-plusplus) for more information.

This change enables `no-plusplus` and fixes the issues raised by the rule.
2020-08-12 20:36:44 -02:30
Whymarrh Whitby
a8863a3446
Fix consistent-return issues (#9192)
See [`consistent-return`](https://eslint.org/docs/rules/consistent-return) for more information.

This change enables `consistent-return` and fixes the issues raised by the rule.
2020-08-12 16:36:57 -02:30
Whymarrh Whitby
93978f139e
Fix typo (#9069) 2020-07-23 18:01:13 -02:30
Whymarrh Whitby
2ae4720443
Fix words (#9038) 2020-07-20 14:32:49 -02:30
Thomas Huang
7b2218ac6e
Clear unapprovedTxs on createNewVaultAndRestore (#9026)
Clear unapproved transactions from txStateManager.transactions on createNewVaultAndRestore
2020-07-16 18:37:56 -07:00
Whymarrh Whitby
c7fad8f400
Limit number of transactions passed outside of TransactionController (#9010)
Refs #8572
Refs #8991

This change limits the number of transactions (`txMeta`s) that are passed
outside of the `TransactionController`, resulting in shorter serialization and
deserialization times when state is moved between the background and UI
contexts.

`TransactionController#_updateMemstore`
---------------------------------------

The `currentNetworkTxList` state of the `TransactionController` is used
externally (i.e. outside of the controller) as the canonical source for
the full transaction history. Prior to this change, the method would iterate
the full transaction history and possibly return all of it.

This change limits it to `MAX_MEMSTORE_TX_LIST_SIZE` to make sure that:

1. Calls to `_updateMemstore` are fast(er)
2. Passing `currentNetworkTxList` around is fast(er)

(Shown in #8377, `_updateMemstore`, is called _frequently_ when a transaction
is pending.)

The list is iterated backwards because it is possible that new transactions are
at the end of the list. [1]

Results
-------

In profiles before this change, with ~3k transactions locally,
`PortDuplexStream._onMessage` took up to ~4.5s to complete when the set of
transactions is included. [2]

In profiles after this change, `PortDuplexStream._onMessage` took ~90ms to
complete. [3]

Before vs. after profile screenshots:

![Profile 1][2]
![Profile 2][3]

  [1]:5a3ae85b72/app/scripts/controllers/transactions/tx-state-manager.js (L172-L174)
  [2]:https://user-images.githubusercontent.com/1623628/87613203-36f51d80-c6e7-11ea-89bc-11a1cc2f3b1e.png
  [3]:https://user-images.githubusercontent.com/1623628/87613215-3bb9d180-c6e7-11ea-8d85-aff3acbd0374.png
  [8337]:https://github.com/MetaMask/metamask-extension/issues/8377
  [8572]:https://github.com/MetaMask/metamask-extension/issues/8572
  [8991]:https://github.com/MetaMask/metamask-extension/issues/8991
2020-07-16 17:52:41 -02:30
Whymarrh Whitby
4f0a205369
Use eslint@6.8.0 (#8978)
* Use eslint@6.8.0
* yarn lint:fix
2020-07-14 12:50:41 -02:30
Mark Stacey
8ff1d05df3
Remove recipient blocklist checker (#8943)
It seems that this blocklist checker never worked correctly. Ever since
the initial commit, it was comparing the Number `1` to the `networkId`,
which is a string. Additionally, even if it did throw, the transaction
continued unhindered. The user could still approve it, and there was no
indication shown to the user that anything went wrong. Also some of the
blocklist entries were incorrectly mixed-case, and were never hit.

We can remove this for now, and re-add it later on after we rewrite the
transaction controller.
2020-07-08 18:34:54 -03:00
Erik Marks
652db3fd36
Use string network and chain IDs (#8628)
* convert network id enums to string

* stringify appropriate chain/network ids in tests

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-07-08 14:05:09 -07:00
Thomas Huang
259d19850f
Account for a custom nonce of zero (#8883)
* Account for a custom nonce of zero
* Remove default value for customNonceValue
2020-07-02 12:58:12 -07:00
Erik Marks
04de9a92c5
Fix signing method bugs (#8833)
* update signTypedData validation

* update tests for new eth-json-rpc-middleware

* remove lowercasing of tx 'from' addresses
2020-06-23 09:12:11 -07:00
Thomas Huang
753a3eb4c9
ParseInt nextworkNextNonce correction (#8827)
* networkNextNonce toNumber

* nonceBN for all getTransactionCount

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-06-17 14:13:33 -07:00
Thomas Huang
792366a20f
Use error.value.message with error.message as fallback (#8825)
* Use  over the whole stringified error object which doesn't show the actual error message that is set as the

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
* Feedback commit
2020-06-16 16:21:56 -07:00
Mark Stacey
3b2bbe0705
Fix dropped tx detection (#8824)
The code for checking whether a transaction was dropped or not was
refactored in #8398, but in the process an off-by-one error was
introduced.

The old version of `_checkIfTxWasDropped` would query for an updated
transaction count from the network, and would consider the pending
transaction to be dropped if the count was above the nonce. However,
the version introduced in #8398 considers the transaction to be dropped
if the count is above *or equal to* the nonce.

The pending transaction nonce is expected to be equal to the
transaction count, because the nonce starts at zero. The transaction
count is equal to the expected next nonce.

The variable name has been updated to make this more clear
(`networkNextNonce` is how the `nonce-tracker` refers to this value).

`parseInt` is now called with an explicit radix of `16` as well, to
ensure both nonce strings are always parsed as hex. In all cases I am
aware of, these nonce strings were prefixed by `0x`, meaning that
`parseInt` would default to a radix of `16`, so this likely doesn't
constitute a functional change.

Fixes #8688
2020-06-16 18:05:48 -03:00
Victor Baranov
d0a28087dc
Remove 2nd parameter from the call of estimateTxGas (#8783) 2020-06-11 10:16:50 -02:30
Erik Marks
56004db8bf blocklisted -> blocked 2020-06-08 17:57:59 -07:00
Jenny Pollack
7a4bb7f73a replace blacklist with blocklist 2020-06-08 17:49:23 -07:00
Erik Marks
24cbb6fc66
Delete retryTransaction action and background (#8576)
* delete retryTransaction action and background
2020-05-12 16:19:33 -07:00
Erik Marks
0470386326
Delete recent blocks controller (#8575)
* delete recent blocks controller

* delete percentile from direct dependencies
2020-05-12 12:40:33 -07:00
Mark Stacey
9c06b07c3c
Synchronously update transaction status (#8563)
All transaction status updates were moved into a `setTimeout` callback
and wrapped in a `try...catch` block in #4131, apparently in an attempt
to prevent failures in event subscribers from interrupting the
transaction logic. The `try...catch` block did accomplish that, but by
putting the status update in a `setTimeout` callback the operation was
made asynchronous.

Transaction status updates now happen unpredictably, in some future
event loop from when they're triggered. This creates a race condition,
where the transaction status update may occur before or after
subsequent state changes. This also introduces a risk of accidentally
undoing a change to the transaction state, as the update made to the
transaction inside the `setTimeout` callback uses a reference to
`txMeta` obtained synchronously before the `setTimeout` call. Any
replacement of the `txMeta` between the `setTxStatus` call and the
execution of the timeout would be erased. Luckily the `txMeta` object
is more often than not mutated rather than replaced, which may explain
why we haven't seen this happen yet.

Everything seems to work correctly with the `setTimeout` call removed,
and now the transaction logic is easier to understand.
2020-05-09 10:46:58 -03:00
Whymarrh Whitby
18b00ed835
Update TransactionController README (#8526) 2020-05-05 20:28:45 -02:30
Whymarrh Whitby
85453a2588
Rework pending tx logic (#8398) 2020-05-01 15:19:29 -02:30
Mark Stacey
5b5b67a985
Fix default gas race condition (#8490)
A race condition exists where after adding an unapproved transaction,
it could be mutated and then replaced when the default gas parameters
are set. This happens because the transaction is added to state and
broadcast before the default gas parameters are set, because
calculating the default gas parameters to use takes some time.
Once they've been calculated, the false assumption was made that the
transaction hadn't changed.

The method responsible for setting the default gas now retrieves an
up-to-date copy of `txMeta`, and conditionally sets the defaults only
if they haven't yet been set.

This race condition was introduced in #2962, though that PR also added
a loading screen that avoided this issue by preventing the user from
interacting with the transaction until after the gas had been
estimated. Unfortunately this loading screen was not carried forward to
the new UI.
2020-05-01 12:25:45 -03:00
Mark Stacey
165666b315
Remove unnecessary tx meta properties (#8489)
* Remove `estimatedGas` property from `txMeta`

The `estimatedGas` property was a cache of the gas value estimated for
a transaction when the default gas limit was set. This property wasn't
used anywhere. It may have been useful for debugging purposes, but the
same gas estimate is already stored on the `history` property so it
should be present in state logs regardless.

* Remove `gasLimitSpecified` txMeta property

The `gasLimitSpecified` property of `txMeta` wasn't used for anything.
It might have been useful for debugging purposes, but whether or not
the gas limit was specified can also be determined from looking at the
transaction history, so it's not a huge loss.

* Remove `gasPriceSpecified` txMeta property

The `gasPriceSpecified` property of `txMeta` wasn't used for anything.
It might have been useful for debugging purposes, but whether or not
the gas price was specified can also be determined from looking at the
transaction history, so it's not a huge loss.

* Remove `simpleSend` txMeta property

The `simpleSend` property of `txMeta` was used to ensure a buffer was
not added to the gas limit during gas estimation for simple send
transactions. It was made redundant by #8484, which accomplishes this
without the use of this property.
2020-05-01 08:44:05 -03:00
Mark Stacey
92592fc905
Ensure tx has value before it's added (#8486)
Previously a transaction would get assigned a default value during the
`addTxGasDefaults` function, after the transaction was added and sent
to the UI.

Instead the transaction is assigned a default value before it gets
added. This flow is simpler to follow, and it avoids the race condition
where the transaction is assigned a value from the UI before this
default is set. In that situation, the UI-assigned value would be
overridden, which is obviously not desired.
2020-04-30 21:50:44 -03:00
Mark Stacey
c2b588975c
Refactor analyzeGasUsage to return results (#8487)
`analyzeGasUsage` now returns the results of the analysis rather than
setting them directly on `txMeta`. The caller is now responsible for
mutating `txMeta` instead. Functionally this should be identical to
before.
2020-04-30 21:44:51 -03:00
Mark Stacey
157cc98c3a
Refactor gas limit estimation when gas limit specified (#8485)
The `analyzeGasUsage` function is skipped entirely now when the gas
limit is specified. This is functionally equivalent to how it worked
before.
2020-04-30 20:53:35 -03:00