Merge pull request #11517 from MetaMask/Version-v9.8.1

Version v9.8.1 RC
feature/default_network_editable
ryanml 3 years ago committed by GitHub
commit 458483ed10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      CHANGELOG.md
  2. 4
      app/scripts/controllers/swaps.js
  3. 48
      app/scripts/controllers/transactions/index.js
  4. 108
      app/scripts/controllers/transactions/index.test.js
  5. 2
      package.json

@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [9.8.1]
### Changed
- Adjusting transaction metrics values
### Fixed
- [11538](https://github.com/MetaMask/metamask-extension/pull/11538): Fixed bug that prevented users from continuing to swap after going 'back' from the View Quote page of the swaps flow.
## [9.8.0] ## [9.8.0]
### Added ### Added
- [#11435](https://github.com/MetaMask/metamask-extension/pull/11435): Add gas limit buffers for optimism network - [#11435](https://github.com/MetaMask/metamask-extension/pull/11435): Add gas limit buffers for optimism network
@ -2329,7 +2336,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Uncategorized ### Uncategorized
- Added the ability to restore accounts from seed words. - Added the ability to restore accounts from seed words.
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.8.0...HEAD [Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.8.1...HEAD
[9.8.1]: https://github.com/MetaMask/metamask-extension/compare/v9.8.0...v9.8.1
[9.8.0]: https://github.com/MetaMask/metamask-extension/compare/v9.7.1...v9.8.0 [9.8.0]: https://github.com/MetaMask/metamask-extension/compare/v9.7.1...v9.8.0
[9.7.1]: https://github.com/MetaMask/metamask-extension/compare/v9.7.0...v9.7.1 [9.7.1]: https://github.com/MetaMask/metamask-extension/compare/v9.7.0...v9.7.1
[9.7.0]: https://github.com/MetaMask/metamask-extension/compare/v9.6.1...v9.7.0 [9.7.0]: https://github.com/MetaMask/metamask-extension/compare/v9.6.1...v9.7.0

@ -130,8 +130,10 @@ export default class SwapsController {
console.error('Request for swaps quote refresh time failed: ', e); console.error('Request for swaps quote refresh time failed: ', e);
} }
const { swapsState: latestSwapsState } = this.store.getState();
this.store.updateState({ this.store.updateState({
swapsState: { ...swapsState, swapsQuoteRefreshTime }, swapsState: { ...latestSwapsState, swapsQuoteRefreshTime },
}); });
} }

@ -1,7 +1,7 @@
import EventEmitter from 'safe-event-emitter'; import EventEmitter from 'safe-event-emitter';
import { ObservableStore } from '@metamask/obs-store'; import { ObservableStore } from '@metamask/obs-store';
import { bufferToHex, keccak, toBuffer } from 'ethereumjs-util';
import Transaction from 'ethereumjs-tx'; import Transaction from 'ethereumjs-tx';
import { bufferToHex, keccak, toBuffer, isHexString } from 'ethereumjs-util';
import EthQuery from 'ethjs-query'; import EthQuery from 'ethjs-query';
import { ethErrors } from 'eth-rpc-errors'; import { ethErrors } from 'eth-rpc-errors';
import abi from 'human-standard-token-abi'; import abi from 'human-standard-token-abi';
@ -19,6 +19,7 @@ import {
} from '../../lib/util'; } from '../../lib/util';
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys'; import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys';
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util'; import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util';
import { hexWEIToDecGWEI } from '../../../../ui/helpers/utils/conversions.util';
import { import {
TRANSACTION_STATUSES, TRANSACTION_STATUSES,
TRANSACTION_TYPES, TRANSACTION_TYPES,
@ -669,15 +670,12 @@ export default class TransactionController extends EventEmitter {
this._markNonceDuplicatesDropped(txId); this._markNonceDuplicatesDropped(txId);
const { submittedTime } = txMeta; const { submittedTime } = txMeta;
const { blockNumber } = txReceipt;
const metricsParams = { gas_used: gasUsed }; const metricsParams = { gas_used: gasUsed };
const completionTime = await this._getTransactionCompletionTime(
blockNumber, if (submittedTime) {
metricsParams.completion_time = this._getTransactionCompletionTime(
submittedTime, submittedTime,
); );
if (completionTime) {
metricsParams.completion_time = completionTime;
} }
if (txReceipt.status === '0x0') { if (txReceipt.status === '0x0') {
@ -1084,41 +1082,43 @@ export default class TransactionController extends EventEmitter {
gasParams.gas_price = gasPrice; gasParams.gas_price = gasPrice;
} }
const gasParamsInGwei = this._getGasValuesInGWEI(gasParams);
this._trackMetaMetricsEvent({ this._trackMetaMetricsEvent({
event, event,
category: 'Transactions', category: 'Transactions',
sensitiveProperties: { properties: {
type, chain_id: chainId,
status,
referrer, referrer,
source, source,
network, network,
chain_id: chainId, type,
},
sensitiveProperties: {
status,
transaction_envelope_type: isEIP1559Transaction(txMeta) transaction_envelope_type: isEIP1559Transaction(txMeta)
? 'fee-market' ? 'fee-market'
: 'legacy', : 'legacy',
first_seen: time, first_seen: time,
gas_limit: gasLimit, gas_limit: gasLimit,
...gasParams, ...gasParamsInGwei,
...extraParams, ...extraParams,
}, },
}); });
} }
async _getTransactionCompletionTime(blockNumber, submittedTime) { _getTransactionCompletionTime(submittedTime) {
const transactionBlock = await this.query.getBlockByNumber( return Math.round((Date.now() - submittedTime) / 1000).toString();
blockNumber.toString(16),
false,
);
if (!transactionBlock) {
return '';
} }
return new BigNumber(transactionBlock.timestamp, 10) _getGasValuesInGWEI(gasParams) {
.minus(submittedTime / 1000) const gasValuesInGwei = {};
.round() for (const param in gasParams) {
.toString(10); if (isHexString(gasParams[param])) {
gasValuesInGwei[param] = hexWEIToDecGWEI(gasParams[param]);
}
}
return gasValuesInGwei;
} }
_failTransaction(txId, error) { _failTransaction(txId, error) {

@ -1212,18 +1212,20 @@ describe('Transaction Controller', function () {
const expectedPayload = { const expectedPayload = {
event: 'Transaction Added', event: 'Transaction Added',
category: 'Transactions', category: 'Transactions',
sensitiveProperties: { properties: {
chain_id: '0x2a', chain_id: '0x2a',
gas_price: '0x77359400',
gas_limit: '0x7b0d',
first_seen: 1624408066355,
transaction_envelope_type: 'legacy',
network: '42', network: '42',
referrer: 'metamask', referrer: 'metamask',
source: 'user', source: 'user',
status: 'unapproved',
type: 'sentEther', type: 'sentEther',
}, },
sensitiveProperties: {
gas_price: '2',
gas_limit: '0x7b0d',
first_seen: 1624408066355,
transaction_envelope_type: 'legacy',
status: 'unapproved',
},
}; };
txController._trackTransactionMetricsEvent( txController._trackTransactionMetricsEvent(
@ -1257,18 +1259,20 @@ describe('Transaction Controller', function () {
const expectedPayload = { const expectedPayload = {
event: 'Transaction Added', event: 'Transaction Added',
category: 'Transactions', category: 'Transactions',
sensitiveProperties: { properties: {
chain_id: '0x2a', chain_id: '0x2a',
gas_price: '0x77359400',
gas_limit: '0x7b0d',
first_seen: 1624408066355,
transaction_envelope_type: 'legacy',
network: '42', network: '42',
referrer: 'other', referrer: 'other',
source: 'dapp', source: 'dapp',
status: 'unapproved',
type: 'sentEther', type: 'sentEther',
}, },
sensitiveProperties: {
gas_price: '2',
gas_limit: '0x7b0d',
first_seen: 1624408066355,
transaction_envelope_type: 'legacy',
status: 'unapproved',
},
}; };
txController._trackTransactionMetricsEvent( txController._trackTransactionMetricsEvent(
@ -1302,19 +1306,21 @@ describe('Transaction Controller', function () {
const expectedPayload = { const expectedPayload = {
event: 'Transaction Added', event: 'Transaction Added',
category: 'Transactions', category: 'Transactions',
properties: {
network: '42',
referrer: 'other',
source: 'dapp',
type: 'sentEther',
chain_id: '0x2a',
},
sensitiveProperties: { sensitiveProperties: {
baz: 3.0, baz: 3.0,
foo: 'bar', foo: 'bar',
chain_id: '0x2a', gas_price: '2',
gas_price: '0x77359400',
gas_limit: '0x7b0d', gas_limit: '0x7b0d',
first_seen: 1624408066355, first_seen: 1624408066355,
transaction_envelope_type: 'legacy', transaction_envelope_type: 'legacy',
network: '42',
referrer: 'other',
source: 'dapp',
status: 'unapproved', status: 'unapproved',
type: 'sentEther',
}, },
}; };
@ -1354,20 +1360,22 @@ describe('Transaction Controller', function () {
const expectedPayload = { const expectedPayload = {
event: 'Transaction Added', event: 'Transaction Added',
category: 'Transactions', category: 'Transactions',
properties: {
chain_id: '0x2a',
network: '42',
referrer: 'other',
source: 'dapp',
type: 'sentEther',
},
sensitiveProperties: { sensitiveProperties: {
baz: 3.0, baz: 3.0,
foo: 'bar', foo: 'bar',
chain_id: '0x2a', max_fee_per_gas: '2',
max_fee_per_gas: '0x77359400', max_priority_fee_per_gas: '2',
max_priority_fee_per_gas: '0x77359400',
gas_limit: '0x7b0d', gas_limit: '0x7b0d',
first_seen: 1624408066355, first_seen: 1624408066355,
transaction_envelope_type: 'fee-market', transaction_envelope_type: 'fee-market',
network: '42',
referrer: 'other',
source: 'dapp',
status: 'unapproved', status: 'unapproved',
type: 'sentEther',
}, },
}; };
@ -1386,4 +1394,54 @@ describe('Transaction Controller', function () {
); );
}); });
}); });
describe('#_getTransactionCompletionTime', function () {
let nowStub;
beforeEach(function () {
nowStub = sinon.stub(Date, 'now').returns(1625782016341);
});
afterEach(function () {
nowStub.restore();
});
it('calculates completion time (one)', function () {
const submittedTime = 1625781997397;
const result = txController._getTransactionCompletionTime(submittedTime);
assert.equal(result, '19');
});
it('calculates completion time (two)', function () {
const submittedTime = 1625781995397;
const result = txController._getTransactionCompletionTime(submittedTime);
assert.equal(result, '21');
});
});
describe('#_getGasValuesInGWEI', function () {
it('converts gas values in hex GWEi to dec GWEI (EIP-1559)', function () {
const params = {
max_fee_per_gas: '0x77359400',
max_priority_fee_per_gas: '0x77359400',
};
const expectedParams = {
max_fee_per_gas: '2',
max_priority_fee_per_gas: '2',
};
const result = txController._getGasValuesInGWEI(params);
assert.deepEqual(result, expectedParams);
});
it('converts gas values in hex GWEi to dec GWEI (non EIP-1559)', function () {
const params = {
gas_price: '0x37e11d600',
};
const expectedParams = {
gas_price: '15',
};
const result = txController._getGasValuesInGWEI(params);
assert.deepEqual(result, expectedParams);
});
});
}); });

@ -1,6 +1,6 @@
{ {
"name": "metamask-crx", "name": "metamask-crx",
"version": "9.8.0", "version": "9.8.1",
"private": true, "private": true,
"repository": { "repository": {
"type": "git", "type": "git",

Loading…
Cancel
Save