Merge branch 'master' into Version-v10.10.0

feature/default_network_editable
Dan Miller 3 years ago
commit b0dfe2109c
  1. 7
      CHANGELOG.md
  2. 6
      app/scripts/controllers/permissions/specifications.js
  3. 2
      app/scripts/controllers/permissions/specifications.test.js
  4. 6
      app/scripts/controllers/swaps.js
  5. 6
      app/scripts/controllers/swaps.test.js
  6. 3
      app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js
  7. 24
      app/scripts/metamask-controller.js
  8. 2
      ui/hooks/gasFeeInput/useGasEstimates.js

@ -92,6 +92,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adding user setting option for EIP-1559 V2 ([#13242](https://github.com/MetaMask/metamask-extension/pull/13242)) - Adding user setting option for EIP-1559 V2 ([#13242](https://github.com/MetaMask/metamask-extension/pull/13242))
- Update Bug Report issue template ([#13267](https://github.com/MetaMask/metamask-extension/pull/13267)) - Update Bug Report issue template ([#13267](https://github.com/MetaMask/metamask-extension/pull/13267))
- Remove unused localized messages ([#13272](https://github.com/MetaMask/metamask-extension/pull/13272)) - Remove unused localized messages ([#13272](https://github.com/MetaMask/metamask-extension/pull/13272))
## [10.9.2]
### Fixed
- Prevent errors on the swaps "View Quote" screen that can occur if the swaps API returns incorrect refund and max gas fees on some test networks ([#13511](https://github.com/MetaMask/metamask-extension/pull/13511))
- Prevent errors on startup in Chrome Versions earlier than 69, caused by use of unsupported browser `Array.prototype.flat` method ([#13520](https://github.com/MetaMask/metamask-extension/pull/13520))
## [10.9.1] ## [10.9.1]
### Fixed ### Fixed
@ -2780,6 +2785,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.10.0...HEAD [Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.10.0...HEAD
[10.10.0]: https://github.com/MetaMask/metamask-extension/compare/v10.9.1...v10.10.0 [10.10.0]: https://github.com/MetaMask/metamask-extension/compare/v10.9.1...v10.10.0
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.9.2...HEAD
[10.9.2]: https://github.com/MetaMask/metamask-extension/compare/v10.9.1...v10.9.2
[10.9.1]: https://github.com/MetaMask/metamask-extension/compare/v10.9.0...v10.9.1 [10.9.1]: https://github.com/MetaMask/metamask-extension/compare/v10.9.0...v10.9.1
[10.9.0]: https://github.com/MetaMask/metamask-extension/compare/v10.8.2...v10.9.0 [10.9.0]: https://github.com/MetaMask/metamask-extension/compare/v10.8.2...v10.9.0
[10.8.2]: https://github.com/MetaMask/metamask-extension/compare/v10.8.1...v10.8.2 [10.8.2]: https://github.com/MetaMask/metamask-extension/compare/v10.8.1...v10.8.2

@ -78,11 +78,15 @@ export const getCaveatSpecifications = ({ getIdentities }) => {
* in the current MetaMask instance. * in the current MetaMask instance.
* @param options.getIdentities - A function that returns the * @param options.getIdentities - A function that returns the
* `PreferencesController` identity objects for all Ethereum accounts in the * `PreferencesController` identity objects for all Ethereum accounts in the
* @param options.captureKeyringTypesWithMissingIdentities - A function that
* captures extra error information about the "Missing identity for address"
* error.
* current MetaMask instance. * current MetaMask instance.
*/ */
export const getPermissionSpecifications = ({ export const getPermissionSpecifications = ({
getAllAccounts, getAllAccounts,
getIdentities, getIdentities,
captureKeyringTypesWithMissingIdentities,
}) => { }) => {
return { return {
[PermissionKeys.eth_accounts]: { [PermissionKeys.eth_accounts]: {
@ -119,8 +123,10 @@ export const getPermissionSpecifications = ({
return accounts.sort((firstAddress, secondAddress) => { return accounts.sort((firstAddress, secondAddress) => {
if (!identities[firstAddress]) { if (!identities[firstAddress]) {
captureKeyringTypesWithMissingIdentities(identities, accounts);
throw new Error(`Missing identity for address: "${firstAddress}".`); throw new Error(`Missing identity for address: "${firstAddress}".`);
} else if (!identities[secondAddress]) { } else if (!identities[secondAddress]) {
captureKeyringTypesWithMissingIdentities(identities, accounts);
throw new Error( throw new Error(
`Missing identity for address: "${secondAddress}".`, `Missing identity for address: "${secondAddress}".`,
); );

@ -247,6 +247,7 @@ describe('PermissionController specifications', () => {
const { methodImplementation } = getPermissionSpecifications({ const { methodImplementation } = getPermissionSpecifications({
getIdentities, getIdentities,
getAllAccounts, getAllAccounts,
captureKeyringTypesWithMissingIdentities: jest.fn(),
})[RestrictedMethods.eth_accounts]; })[RestrictedMethods.eth_accounts];
await expect(() => methodImplementation()).rejects.toThrow( await expect(() => methodImplementation()).rejects.toThrow(
@ -272,6 +273,7 @@ describe('PermissionController specifications', () => {
const { methodImplementation } = getPermissionSpecifications({ const { methodImplementation } = getPermissionSpecifications({
getIdentities, getIdentities,
getAllAccounts, getAllAccounts,
captureKeyringTypesWithMissingIdentities: jest.fn(),
})[RestrictedMethods.eth_accounts]; })[RestrictedMethods.eth_accounts];
await expect(() => methodImplementation()).rejects.toThrow( await expect(() => methodImplementation()).rejects.toThrow(

@ -51,9 +51,11 @@ function calculateGasEstimateWithRefund(
estimatedRefund, estimatedRefund,
10, 10,
); );
const isMaxGasMinusRefundNegative = maxGasMinusRefund.lt(0);
const gasEstimateWithRefund = maxGasMinusRefund.lt(estimatedGas, 16) const gasEstimateWithRefund =
? maxGasMinusRefund.toString(16) !isMaxGasMinusRefundNegative && maxGasMinusRefund.lt(estimatedGas, 16)
? `0x${maxGasMinusRefund.toString(16)}`
: estimatedGas; : estimatedGas;
return gasEstimateWithRefund; return gasEstimateWithRefund;

@ -372,7 +372,9 @@ describe('SwapsController', function () {
assert.strictEqual(gasEstimate, bufferedGasLimit); assert.strictEqual(gasEstimate, bufferedGasLimit);
assert.strictEqual( assert.strictEqual(
gasEstimateWithRefund, gasEstimateWithRefund,
new BigNumber(maxGas, 10).minus(estimatedRefund, 10).toString(16), `0x${new BigNumber(maxGas, 10)
.minus(estimatedRefund, 10)
.toString(16)}`,
); );
}); });
@ -690,7 +692,7 @@ describe('SwapsController', function () {
isBestQuote: true, isBestQuote: true,
// TODO: find a way to calculate these values dynamically // TODO: find a way to calculate these values dynamically
gasEstimate: 2000000, gasEstimate: 2000000,
gasEstimateWithRefund: 'b8cae', gasEstimateWithRefund: '0xb8cae',
savings: { savings: {
fee: '0', fee: '0',
metaMaskFee: '0.5050505050505050505', metaMaskFee: '0.5050505050505050505',

@ -1,3 +1,4 @@
import { flatten } from 'lodash';
import { permissionRpcMethods } from '@metamask/snap-controllers'; import { permissionRpcMethods } from '@metamask/snap-controllers';
import { selectHooks } from '@metamask/rpc-methods'; import { selectHooks } from '@metamask/rpc-methods';
import { ethErrors } from 'eth-rpc-errors'; import { ethErrors } from 'eth-rpc-errors';
@ -15,7 +16,7 @@ const handlerMap = allHandlers.reduce((map, handler) => {
const expectedHookNames = Array.from( const expectedHookNames = Array.from(
new Set( new Set(
allHandlers.map(({ hookNames }) => Object.keys(hookNames)).flat(), flatten(allHandlers.map(({ hookNames }) => Object.keys(hookNames))),
).values(), ).values(),
); );

@ -505,6 +505,30 @@ export default class MetamaskController extends EventEmitter {
getAllAccounts: this.keyringController.getAccounts.bind( getAllAccounts: this.keyringController.getAccounts.bind(
this.keyringController, this.keyringController,
), ),
captureKeyringTypesWithMissingIdentities: (
identities = {},
accounts = [],
) => {
const accountsMissingIdentities = accounts.filter(
(address) => !identities[address],
);
const keyringTypesWithMissingIdentities = accountsMissingIdentities.map(
(address) =>
this.keyringController.getKeyringForAccount(address)?.type,
);
const identitiesCount = Object.keys(identities || {}).length;
const accountTrackerCount = Object.keys(
this.accountTracker.store.getState().accounts || {},
).length;
captureException(
new Error(
`Attempt to get permission specifications failed because their were ${accounts.length} accounts, but ${identitiesCount} identities, and the ${keyringTypesWithMissingIdentities} keyrings included accounts with missing identities. Meanwhile, there are ${accountTrackerCount} accounts in the account tracker.`,
),
);
},
}), }),
unrestrictedMethods, unrestrictedMethods,
}); });

@ -111,7 +111,7 @@ export function useGasEstimates({
const maximumCostInHexWei = getMaximumGasTotalInHexWei(gasSettings); const maximumCostInHexWei = getMaximumGasTotalInHexWei(gasSettings);
if (editGasMode === EDIT_GAS_MODES.SWAPS) { if (editGasMode === EDIT_GAS_MODES.SWAPS) {
gasSettings = { ...gasSettings, gasLimit: decimalToHex(minimumGasLimit) }; gasSettings = { ...gasSettings, gasLimit: minimumGasLimit };
} }
// The minimum amount this transaction will cost // The minimum amount this transaction will cost

Loading…
Cancel
Save