@metamask-previews/gas-fee-controller
Advanced tools
Comparing version 7.0.0-preview.1b84247 to 8.0.0-preview.7cc5454
@@ -9,2 +9,18 @@ # Changelog | ||
## [8.0.0] | ||
### Added | ||
- Add optional `gasFeeEstimatesByChainId` property to GasFeeController state ([#1673](https://github.com/MetaMask/core/pull/1673) | ||
- Add dependency on `@metamask/polling-controller` ([#1748])(https://github.com/MetaMask/core/pull/1748)) | ||
### Changed | ||
- **BREAKING:** Messenger must allow controller actions `NetworkController:getNetworkClientById` and `NetworkController:getEIP1559Compatibility` ([#1673](https://github.com/MetaMask/core/pull/1673) | ||
- Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639)) | ||
- Bump dependency on `@metamask/base-controller` to ^3.2.3 | ||
- Bump dependency on `@metamask/controller-utils` to ^5.0.2 | ||
- Bump dependency and peer dependency on `@metamask/network-controller` to ^14.0.0 | ||
## [7.0.1] | ||
### Changed | ||
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718)) | ||
## [7.0.0] | ||
@@ -22,3 +38,3 @@ ### Changed | ||
## [6.1.1] | ||
### Uncategorized | ||
### Changed | ||
- Replace `eth-query` ^2.1.2 with `@metamask/eth-query` ^3.0.1 ([#1546](https://github.com/MetaMask/core/pull/1546)) | ||
@@ -87,3 +103,5 @@ | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@7.0.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@8.0.0...HEAD | ||
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@7.0.1...@metamask/gas-fee-controller@8.0.0 | ||
[7.0.1]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@7.0.0...@metamask/gas-fee-controller@7.0.1 | ||
[7.0.0]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.1.2...@metamask/gas-fee-controller@7.0.0 | ||
@@ -90,0 +108,0 @@ [6.1.2]: https://github.com/MetaMask/core/compare/@metamask/gas-fee-controller@6.1.1...@metamask/gas-fee-controller@6.1.2 |
import type { RestrictedControllerMessenger } from '@metamask/base-controller'; | ||
import { BaseControllerV2 } from '@metamask/base-controller'; | ||
import type { NetworkControllerGetStateAction, NetworkControllerStateChangeEvent, NetworkState, ProviderProxy } from '@metamask/network-controller'; | ||
import type { NetworkControllerGetEIP1559CompatibilityAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent, NetworkState, ProviderProxy } from '@metamask/network-controller'; | ||
import { PollingController } from '@metamask/polling-controller'; | ||
import type { Hex } from '@metamask/utils'; | ||
@@ -136,3 +136,7 @@ import type { Patch } from 'immer'; | ||
*/ | ||
export declare type GasFeeState = GasFeeStateEthGasPrice | GasFeeStateFeeMarket | GasFeeStateLegacy | GasFeeStateNoEstimates; | ||
export declare type SingleChainGasFeeState = GasFeeStateEthGasPrice | GasFeeStateFeeMarket | GasFeeStateLegacy | GasFeeStateNoEstimates; | ||
export declare type GasFeeEstimatesByChainId = { | ||
gasFeeEstimatesByChainId?: Record<string, SingleChainGasFeeState>; | ||
}; | ||
export declare type GasFeeState = GasFeeEstimatesByChainId & SingleChainGasFeeState; | ||
declare const name = "GasFeeController"; | ||
@@ -147,7 +151,7 @@ export declare type GasFeeStateChange = { | ||
}; | ||
declare type GasFeeMessenger = RestrictedControllerMessenger<typeof name, GetGasFeeState | NetworkControllerGetStateAction, GasFeeStateChange | NetworkControllerStateChangeEvent, NetworkControllerGetStateAction['type'], NetworkControllerStateChangeEvent['type']>; | ||
declare type GasFeeMessenger = RestrictedControllerMessenger<typeof name, GetGasFeeState | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetEIP1559CompatibilityAction, GasFeeStateChange | NetworkControllerStateChangeEvent, NetworkControllerGetStateAction['type'] | NetworkControllerGetNetworkClientByIdAction['type'] | NetworkControllerGetEIP1559CompatibilityAction['type'], NetworkControllerStateChangeEvent['type']>; | ||
/** | ||
* Controller that retrieves gas fee estimate data and polls for updated data on a set interval | ||
*/ | ||
export declare class GasFeeController extends BaseControllerV2<typeof name, GasFeeState, GasFeeMessenger> { | ||
export declare class GasFeeController extends PollingController<typeof name, GasFeeState, GasFeeMessenger> { | ||
#private; | ||
@@ -228,2 +232,3 @@ private intervalId?; | ||
private _poll; | ||
executePoll(networkClientId: string): Promise<void>; | ||
private resetState; | ||
@@ -230,0 +235,0 @@ private getEIP1559Compatibility; |
@@ -25,8 +25,8 @@ "use strict"; | ||
}; | ||
var _GasFeeController_instances, _GasFeeController_getProvider, _GasFeeController_onNetworkControllerStateChange; | ||
var _GasFeeController_instances, _GasFeeController_getProvider, _GasFeeController_fetchGasFeeEstimateForNetworkClientId, _GasFeeController_onNetworkControllerStateChange; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GasFeeController = exports.GAS_ESTIMATE_TYPES = exports.LEGACY_GAS_PRICES_API_URL = void 0; | ||
const base_controller_1 = require("@metamask/base-controller"); | ||
const controller_utils_1 = require("@metamask/controller-utils"); | ||
const eth_query_1 = __importDefault(require("@metamask/eth-query")); | ||
const polling_controller_1 = require("@metamask/polling-controller"); | ||
const uuid_1 = require("uuid"); | ||
@@ -50,2 +50,6 @@ const determineGasFeeCalculations_1 = __importDefault(require("./determineGasFeeCalculations")); | ||
const metadata = { | ||
gasFeeEstimatesByChainId: { | ||
persist: true, | ||
anonymous: false, | ||
}, | ||
gasFeeEstimates: { persist: true, anonymous: false }, | ||
@@ -57,2 +61,3 @@ estimatedGasFeeTimeBounds: { persist: true, anonymous: false }, | ||
const defaultState = { | ||
gasFeeEstimatesByChainId: {}, | ||
gasFeeEstimates: {}, | ||
@@ -65,3 +70,3 @@ estimatedGasFeeTimeBounds: {}, | ||
*/ | ||
class GasFeeController extends base_controller_1.BaseControllerV2 { | ||
class GasFeeController extends polling_controller_1.PollingController { | ||
/** | ||
@@ -100,2 +105,3 @@ * Creates a GasFeeController instance. | ||
this.intervalDelay = interval; | ||
this.setIntervalLength(interval); | ||
this.pollTokens = new Set(); | ||
@@ -234,2 +240,7 @@ this.getCurrentNetworkEIP1559Compatibility = | ||
} | ||
executePoll(networkClientId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield __classPrivateFieldGet(this, _GasFeeController_instances, "m", _GasFeeController_fetchGasFeeEstimateForNetworkClientId).call(this, networkClientId); | ||
}); | ||
} | ||
resetState() { | ||
@@ -257,4 +268,40 @@ this.update(() => { | ||
exports.GasFeeController = GasFeeController; | ||
_GasFeeController_getProvider = new WeakMap(), _GasFeeController_instances = new WeakSet(), _GasFeeController_onNetworkControllerStateChange = function _GasFeeController_onNetworkControllerStateChange(networkControllerState) { | ||
_GasFeeController_getProvider = new WeakMap(), _GasFeeController_instances = new WeakSet(), _GasFeeController_fetchGasFeeEstimateForNetworkClientId = function _GasFeeController_fetchGasFeeEstimateForNetworkClientId(networkClientId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let isEIP1559Compatible = false; | ||
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId); | ||
const isLegacyGasAPICompatible = networkClient.configuration.chainId === '0x38'; | ||
const decimalChainId = (0, controller_utils_1.convertHexToDecimal)(networkClient.configuration.chainId); | ||
try { | ||
const result = yield this.messagingSystem.call('NetworkController:getEIP1559Compatibility', networkClientId); | ||
isEIP1559Compatible = result || false; | ||
} | ||
catch (_a) { | ||
isEIP1559Compatible = false; | ||
} | ||
const ethQuery = new eth_query_1.default(networkClient.provider); | ||
const gasFeeCalculations = yield (0, determineGasFeeCalculations_1.default)({ | ||
isEIP1559Compatible, | ||
isLegacyGasAPICompatible, | ||
fetchGasEstimates: gas_util_1.fetchGasEstimates, | ||
fetchGasEstimatesUrl: this.EIP1559APIEndpoint.replace('<chain_id>', `${decimalChainId}`), | ||
fetchGasEstimatesViaEthFeeHistory: fetchGasEstimatesViaEthFeeHistory_1.default, | ||
fetchLegacyGasPriceEstimates: gas_util_1.fetchLegacyGasPriceEstimates, | ||
fetchLegacyGasPriceEstimatesUrl: this.legacyAPIEndpoint.replace('<chain_id>', `${decimalChainId}`), | ||
fetchEthGasPriceEstimate: gas_util_1.fetchEthGasPriceEstimate, | ||
calculateTimeEstimate: gas_util_1.calculateTimeEstimate, | ||
clientId: this.clientId, | ||
ethQuery, | ||
}); | ||
this.update((state) => { | ||
state.gasFeeEstimatesByChainId = state.gasFeeEstimatesByChainId || {}; | ||
state.gasFeeEstimatesByChainId[networkClient.configuration.chainId] = { | ||
gasFeeEstimates: gasFeeCalculations.gasFeeEstimates, | ||
estimatedGasFeeTimeBounds: gasFeeCalculations.estimatedGasFeeTimeBounds, | ||
gasEstimateType: gasFeeCalculations.gasEstimateType, | ||
}; | ||
}); | ||
}); | ||
}, _GasFeeController_onNetworkControllerStateChange = function _GasFeeController_onNetworkControllerStateChange(networkControllerState) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const newChainId = networkControllerState.providerConfig.chainId; | ||
@@ -261,0 +308,0 @@ if (newChainId !== this.currentChainId) { |
{ | ||
"name": "@metamask-previews/gas-fee-controller", | ||
"version": "7.0.0-preview.1b84247", | ||
"version": "8.0.0-preview.7cc5454", | ||
"description": "Periodically calculates gas fee estimates based on various gas limits as well as other data displayed on transaction confirm screens", | ||
@@ -28,10 +28,12 @@ "keywords": [ | ||
"test": "jest", | ||
"test:clean": "jest --clearCache", | ||
"test:watch": "jest --watch" | ||
}, | ||
"dependencies": { | ||
"@metamask/base-controller": "^3.2.1", | ||
"@metamask/controller-utils": "^5.0.0", | ||
"@metamask/base-controller": "^3.2.3", | ||
"@metamask/controller-utils": "^5.0.2", | ||
"@metamask/eth-query": "^3.0.1", | ||
"@metamask/network-controller": "^13.0.0", | ||
"@metamask/utils": "^6.2.0", | ||
"@metamask/network-controller": "^14.0.0", | ||
"@metamask/polling-controller": "^0.1.0", | ||
"@metamask/utils": "^8.1.0", | ||
"@types/uuid": "^8.3.0", | ||
@@ -53,8 +55,8 @@ "ethereumjs-util": "^7.0.10", | ||
"ts-jest": "^27.1.4", | ||
"typedoc": "^0.23.15", | ||
"typedoc-plugin-missing-exports": "^0.23.0", | ||
"typescript": "~4.6.3" | ||
"typedoc": "^0.24.8", | ||
"typedoc-plugin-missing-exports": "^2.0.0", | ||
"typescript": "~4.8.4" | ||
}, | ||
"peerDependencies": { | ||
"@metamask/network-controller": "^13.0.0" | ||
"@metamask/network-controller": "^14.0.0" | ||
}, | ||
@@ -61,0 +63,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170342
1443
12
+ Added@metamask/network-controller@14.0.0(transitive)
+ Added@metamask/polling-controller@0.1.0(transitive)
- Removed@metamask/network-controller@13.0.1(transitive)
- Removed@metamask/utils@6.2.0(transitive)
Updated@metamask/utils@^8.1.0