diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 50e90f061..932ad5b8a 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -95,7 +95,10 @@ export default class TransactionController extends EventEmitter { this.networkStore = opts.networkStore || new ObservableStore({}); this._getCurrentChainId = opts.getCurrentChainId; this.getProviderConfig = opts.getProviderConfig; - this.getEIP1559Compatibility = opts.getEIP1559Compatibility; + this._getCurrentNetworkEIP1559Compatibility = + opts.getCurrentNetworkEIP1559Compatibility; + this._getCurrentAccountEIP1559Compatibility = + opts.getCurrentAccountEIP1559Compatibility; this.preferencesStore = opts.preferencesStore || new ObservableStore({}); this.provider = opts.provider; this.getPermittedAccounts = opts.getPermittedAccounts; @@ -177,6 +180,14 @@ export default class TransactionController extends EventEmitter { return integerChainId; } + async getEIP1559Compatibility(fromAddress) { + const currentNetworkIsCompatible = await this._getCurrentNetworkEIP1559Compatibility(); + const fromAccountIsCompatible = this._getCurrentAccountEIP1559Compatibility( + fromAddress, + ); + return currentNetworkIsCompatible && fromAccountIsCompatible; + } + /** * @ethereumjs/tx uses @ethereumjs/common as a configuration tool for * specifying which chain, network, hardfork and EIPs to support for @@ -185,9 +196,9 @@ export default class TransactionController extends EventEmitter { * transaction type to use. * @returns {Common} common configuration object */ - async getCommonConfiguration() { + async getCommonConfiguration(fromAddress) { const { type, nickname: name } = this.getProviderConfig(); - const supportsEIP1559 = await this.getEIP1559Compatibility(); + const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress); // This logic below will have to be updated each time a hardfork happens // that carries with it a new Transaction type. It is inconsequential for @@ -739,7 +750,7 @@ export default class TransactionController extends EventEmitter { }; // sign tx const fromAddress = txParams.from; - const common = await this.getCommonConfiguration(); + const common = await this.getCommonConfiguration(txParams.from); const unsignedEthTx = TransactionFactory.fromTxData(txParams, { common }); const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress); diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index 08ae84919..9a415b280 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -51,6 +51,8 @@ describe('Transaction Controller', function () { }, networkStore: new ObservableStore(currentNetworkId), getEIP1559Compatibility: () => Promise.resolve(true), + getCurrentNetworkEIP1559Compatibility: () => Promise.resolve(true), + getCurrentAccountEIP1559Compatibility: () => true, txHistoryLimit: 10, blockTracker: blockTrackerStub, signTransaction: (ethTx) => diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 1f9aeca20..5e095e2a5 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -401,9 +401,12 @@ export default class MetamaskController extends EventEmitter { getProviderConfig: this.networkController.getProviderConfig.bind( this.networkController, ), - getEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind( + getCurrentNetworkEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind( this.networkController, ), + getCurrentAccountEIP1559Compatibility: this.getCurrentAccountEIP1559Compatibility.bind( + this, + ), networkStore: this.networkController.networkStore, getCurrentChainId: this.networkController.getCurrentChainId.bind( this.networkController, @@ -2037,11 +2040,10 @@ export default class MetamaskController extends EventEmitter { * client utilities for EIP-1559 * @returns {boolean} true if the keyring type supports EIP-1559 */ - getCurrentAccountEIP1559Compatibility() { - const selectedAddress = this.preferencesController.getSelectedAddress(); - const keyring = this.keyringController.getKeyringForAccount( - selectedAddress, - ); + getCurrentAccountEIP1559Compatibility(fromAddress) { + const address = + fromAddress || this.preferencesController.getSelectedAddress(); + const keyring = this.keyringController.getKeyringForAccount(address); return ( keyring.type !== KEYRING_TYPES.LEDGER && keyring.type !== KEYRING_TYPES.TREZOR