EIP-1559 V2 : Adding advancedGasFee property to Preference Controller (#12577)

feature/default_network_editable
Niranjana Binoy 3 years ago committed by GitHub
parent 3de02a528c
commit 7cf4a16a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/scripts/controllers/preferences.js
  2. 24
      app/scripts/controllers/preferences.test.js
  3. 4
      app/scripts/metamask-controller.js
  4. 4
      test/data/mock-state.json
  5. 20
      ui/selectors/selectors.js
  6. 13
      ui/selectors/selectors.test.js
  7. 13
      ui/store/actions.js

@ -37,6 +37,7 @@ export default class PreferencesController {
// set to true means the dynamic list from the API is being used
// set to false will be using the static list from contract-metadata
useTokenDetection: false,
advancedGasFee: null,
// WARNING: Do not use feature flags for security-sensitive things.
// Feature flag toggling is available in the global namespace
@ -129,6 +130,16 @@ export default class PreferencesController {
this.store.updateState({ useTokenDetection: val });
}
/**
* Setter for the `advancedGasFee` property
*
* @param {object} val - holds the maxBaseFee and PriorityFee that the user set as default advanced settings.
*
*/
setAdvancedGasFee(val) {
this.store.updateState({ advancedGasFee: val });
}
/**
* Add new methodData to state, to avoid requesting this information again through Infura
*

@ -266,4 +266,28 @@ describe('preferences controller', function () {
);
});
});
describe('setAdvancedGasFee', function () {
it('should default to null', function () {
const state = preferencesController.store.getState();
assert.equal(state.advancedGasFee, null);
});
it('should set the setAdvancedGasFee property in state', function () {
const state = preferencesController.store.getState();
assert.equal(state.advancedGasFee, null);
preferencesController.setAdvancedGasFee({
maxBaseFee: '1.5',
priorityFee: '2',
});
assert.equal(
preferencesController.store.getState().advancedGasFee.maxBaseFee,
'1.5',
);
assert.equal(
preferencesController.store.getState().advancedGasFee.priorityFee,
'2',
);
});
});
});

@ -924,6 +924,10 @@ export default class MetamaskController extends EventEmitter {
this.preferencesController.setDismissSeedBackUpReminder,
this.preferencesController,
),
setAdvancedGasFee: nodeify(
preferencesController.setAdvancedGasFee,
preferencesController,
),
// AddressController
setAddressBook: nodeify(

@ -160,6 +160,10 @@
"toNickname": ""
},
"useTokenDetection": true,
"advancedGasFee": {
"maxBaseFee": "1.5",
"priorityFee": "2"
},
"tokenList": {
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",

@ -718,3 +718,23 @@ export function getNetworkSupportsSettingGasPrice(state) {
export function getIsMultiLayerFeeNetwork(state) {
return getIsOptimism(state);
}
/**
* To retrieve the maxBaseFee and priotitFee teh user has set as default
* @param {*} state
* @returns Boolean
*/
export function getAdvancedGasFeeValues(state) {
return state.metamask.advancedGasFee;
}
/**
* To check if the user has set advanced gas fee settings as default with a non empty maxBaseFee and priotityFee.
* @param {*} state
* @returns Boolean
*/
export function getIsAdvancedGasFeeDefault(state) {
const { advancedGasFee } = state.metamask;
return (
Boolean(advancedGasFee?.maxBaseFee) && Boolean(advancedGasFee?.priorityFee)
);
}

@ -245,4 +245,17 @@ describe('Selectors', () => {
},
});
});
it('#getAdvancedGasFeeValues', () => {
const advancedGasFee = selectors.getAdvancedGasFeeValues(mockState);
expect(advancedGasFee).toStrictEqual({
maxBaseFee: '1.5',
priorityFee: '2',
});
});
it('#getIsAdvancedGasFeeDefault', () => {
const isAdvancedGasFeeDefault = selectors.getIsAdvancedGasFeeDefault(
mockState,
);
expect(isAdvancedGasFeeDefault).toStrictEqual(true);
});
});

@ -2090,6 +2090,19 @@ export function setUseTokenDetection(val) {
};
}
export function setAdvancedGasFee(val) {
return (dispatch) => {
dispatch(showLoadingIndication());
log.debug(`background.setAdvancedGasFee`);
background.setAdvancedGasFee(val, (err) => {
dispatch(hideLoadingIndication());
if (err) {
dispatch(displayWarning(err.message));
}
});
};
}
export function setIpfsGateway(val) {
return (dispatch) => {
dispatch(showLoadingIndication());

Loading…
Cancel
Save