1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

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

This commit is contained in:
Niranjana Binoy 2021-11-11 14:18:50 -05:00 committed by GitHub
parent 3de02a528c
commit 7cf4a16a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 0 deletions

View File

@ -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
*

View File

@ -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',
);
});
});
});

View File

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

View File

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

View File

@ -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)
);
}

View File

@ -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);
});
});

View File

@ -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());