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:
parent
3de02a528c
commit
7cf4a16a63
@ -37,6 +37,7 @@ export default class PreferencesController {
|
|||||||
// set to true means the dynamic list from the API is being used
|
// 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
|
// set to false will be using the static list from contract-metadata
|
||||||
useTokenDetection: false,
|
useTokenDetection: false,
|
||||||
|
advancedGasFee: null,
|
||||||
|
|
||||||
// WARNING: Do not use feature flags for security-sensitive things.
|
// WARNING: Do not use feature flags for security-sensitive things.
|
||||||
// Feature flag toggling is available in the global namespace
|
// Feature flag toggling is available in the global namespace
|
||||||
@ -129,6 +130,16 @@ export default class PreferencesController {
|
|||||||
this.store.updateState({ useTokenDetection: val });
|
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
|
* 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.setDismissSeedBackUpReminder,
|
||||||
this.preferencesController,
|
this.preferencesController,
|
||||||
),
|
),
|
||||||
|
setAdvancedGasFee: nodeify(
|
||||||
|
preferencesController.setAdvancedGasFee,
|
||||||
|
preferencesController,
|
||||||
|
),
|
||||||
|
|
||||||
// AddressController
|
// AddressController
|
||||||
setAddressBook: nodeify(
|
setAddressBook: nodeify(
|
||||||
|
@ -160,6 +160,10 @@
|
|||||||
"toNickname": ""
|
"toNickname": ""
|
||||||
},
|
},
|
||||||
"useTokenDetection": true,
|
"useTokenDetection": true,
|
||||||
|
"advancedGasFee": {
|
||||||
|
"maxBaseFee": "1.5",
|
||||||
|
"priorityFee": "2"
|
||||||
|
},
|
||||||
"tokenList": {
|
"tokenList": {
|
||||||
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
|
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
|
||||||
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
||||||
|
@ -718,3 +718,23 @@ export function getNetworkSupportsSettingGasPrice(state) {
|
|||||||
export function getIsMultiLayerFeeNetwork(state) {
|
export function getIsMultiLayerFeeNetwork(state) {
|
||||||
return getIsOptimism(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) {
|
export function setIpfsGateway(val) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(showLoadingIndication());
|
dispatch(showLoadingIndication());
|
||||||
|
Loading…
Reference in New Issue
Block a user