@metamask-previews/assets-controllers 28.0.0-preview-96ea89dc → 29.0.0-preview-4a029d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/dist/AssetsContractController.js +3 -3
- package/dist/AssetsContractController.mjs +2 -2
- package/dist/BtcRateController/BtcRateController.js +10 -0
- package/dist/BtcRateController/BtcRateController.mjs +10 -0
- package/dist/BtcRateController/index.js +11 -0
- package/dist/BtcRateController/index.js.map +1 -0
- package/dist/BtcRateController/index.mjs +11 -0
- package/dist/BtcRateController/index.mjs.map +1 -0
- package/dist/CurrencyRateController.js +4 -3
- package/dist/CurrencyRateController.mjs +3 -2
- package/dist/TokenRatesController.js +4 -3
- package/dist/TokenRatesController.mjs +3 -2
- package/dist/TokensController.js +3 -3
- package/dist/TokensController.mjs +2 -2
- package/dist/{chunk-PWZE6KJV.mjs → chunk-2H3C35ES.mjs} +2 -2
- package/dist/chunk-2H3C35ES.mjs.map +1 -0
- package/dist/{chunk-DYH5P3VY.js → chunk-AORTOLZC.js} +2 -2
- package/dist/chunk-AORTOLZC.js.map +1 -0
- package/dist/{chunk-QWACHXRH.mjs → chunk-COEHYUR5.mjs} +2 -2
- package/dist/chunk-COEHYUR5.mjs.map +1 -0
- package/dist/chunk-D7WROCMA.mjs +148 -0
- package/dist/chunk-D7WROCMA.mjs.map +1 -0
- package/dist/{chunk-LRKDZWS6.js → chunk-EBBQRZW3.js} +3 -3
- package/dist/chunk-EBBQRZW3.js.map +1 -0
- package/dist/chunk-GY2QVELJ.js +148 -0
- package/dist/chunk-GY2QVELJ.js.map +1 -0
- package/dist/{chunk-QHU4H6HP.js → chunk-JW7WUU3F.js} +3 -3
- package/dist/{chunk-6XOM7KOQ.mjs → chunk-JZWPCTIR.mjs} +4 -4
- package/dist/{chunk-SOK5YX7I.js → chunk-Q5H4TKNS.js} +3 -3
- package/dist/chunk-SE7AY5BK.js +1 -0
- package/dist/chunk-SE7AY5BK.js.map +1 -0
- package/dist/chunk-SYSB5PAB.mjs +1 -0
- package/dist/chunk-SYSB5PAB.mjs.map +1 -0
- package/dist/chunk-V23BWSM6.mjs +1 -0
- package/dist/chunk-V23BWSM6.mjs.map +1 -0
- package/dist/{chunk-5MRF7YPD.mjs → chunk-WAIP34TZ.mjs} +4 -4
- package/dist/chunk-X4WSYARY.js +1 -0
- package/dist/chunk-X4WSYARY.js.map +1 -0
- package/dist/{chunk-OWTCG2N3.mjs → chunk-YOMCL2SJ.mjs} +2 -2
- package/dist/chunk-YOMCL2SJ.mjs.map +1 -0
- package/dist/{chunk-IOQX3VTD.js → chunk-ZIY545UX.js} +3 -3
- package/dist/chunk-ZIY545UX.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.js +8 -0
- package/dist/crypto-compare-service/crypto-compare.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +8 -0
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -0
- package/dist/crypto-compare-service/index.js +9 -0
- package/dist/crypto-compare-service/index.js.map +1 -0
- package/dist/crypto-compare-service/index.mjs +9 -0
- package/dist/crypto-compare-service/index.mjs.map +1 -0
- package/dist/index.js +13 -7
- package/dist/index.mjs +12 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/BtcRateController/BtcRateController.d.ts +60 -0
- package/dist/types/BtcRateController/BtcRateController.d.ts.map +1 -0
- package/dist/types/BtcRateController/index.d.ts +3 -0
- package/dist/types/BtcRateController/index.d.ts.map +1 -0
- package/dist/types/CurrencyRateController.d.ts +1 -1
- package/dist/types/CurrencyRateController.d.ts.map +1 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +1 -0
- package/dist/types/crypto-compare-service/index.d.ts +3 -0
- package/dist/types/crypto-compare-service/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-DYH5P3VY.js.map +0 -1
- package/dist/chunk-IOQX3VTD.js.map +0 -1
- package/dist/chunk-LRKDZWS6.js.map +0 -1
- package/dist/chunk-OWTCG2N3.mjs.map +0 -1
- package/dist/chunk-PWZE6KJV.mjs.map +0 -1
- package/dist/chunk-QWACHXRH.mjs.map +0 -1
- package/dist/crypto-compare.js +0 -8
- package/dist/crypto-compare.mjs +0 -8
- package/dist/types/crypto-compare.d.ts.map +0 -1
- /package/dist/{crypto-compare.js.map → BtcRateController/BtcRateController.js.map} +0 -0
- /package/dist/{crypto-compare.mjs.map → BtcRateController/BtcRateController.mjs.map} +0 -0
- /package/dist/{chunk-QHU4H6HP.js.map → chunk-JW7WUU3F.js.map} +0 -0
- /package/dist/{chunk-6XOM7KOQ.mjs.map → chunk-JZWPCTIR.mjs.map} +0 -0
- /package/dist/{chunk-SOK5YX7I.js.map → chunk-Q5H4TKNS.js.map} +0 -0
- /package/dist/{chunk-5MRF7YPD.mjs.map → chunk-WAIP34TZ.mjs.map} +0 -0
- /package/dist/types/{crypto-compare.d.ts → crypto-compare-service/crypto-compare.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [29.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add token detection on 7 more networks ([#4184](https://github.com/MetaMask/core/pull/4184))
|
|
15
|
+
- New supported networks are: cronos, celo, gnosis, fantom, polygon_zkevm, moonbeam, and moonriver
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **BREAKING** Changed `NftDetectionController` constructor `options` argument ([#4178](https://github.com/MetaMask/core/pull/4178))
|
|
20
|
+
- Added `options.disabled` and `options.selectedAddress` properties
|
|
21
|
+
- **BREAKING** Bump `@metamask/keyring-controller` peer dependency to ^16.0.0 ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
22
|
+
- **BREAKING** Bump `@metamask/accounts-controller` peer dependency to ^14.0.0 ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
23
|
+
- **BREAKING** Bump `@metamask/preferences-controller` peer dependency to ^11.0.0 ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
24
|
+
- Bump `@metamask/keyring-api` to `^6.0.0` ([#4193](https://github.com/MetaMask/core/pull/4193))
|
|
25
|
+
- Lower number of tokens returned by API calls ([#4207](https://github.com/MetaMask/core/pull/4207))
|
|
26
|
+
- Limit changed from `200` to `50`
|
|
27
|
+
- Bump `@metamask/base-controller` to `^5.0.2` ([#4232](https://github.com/MetaMask/core/pull/4232))
|
|
28
|
+
- Bump `@metamask/approval-controller` to `^6.0.2` ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
29
|
+
- Bump `@metamask/polling-controller` to `^6.0.2` ([#4234](https://github.com/MetaMask/core/pull/4234))
|
|
30
|
+
|
|
10
31
|
## [28.0.0]
|
|
11
32
|
|
|
12
33
|
### Added
|
|
@@ -752,7 +773,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
752
773
|
|
|
753
774
|
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
|
|
754
775
|
|
|
755
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@
|
|
776
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@29.0.0...HEAD
|
|
777
|
+
[29.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@28.0.0...@metamask/assets-controllers@29.0.0
|
|
756
778
|
[28.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@27.2.0...@metamask/assets-controllers@28.0.0
|
|
757
779
|
[27.2.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@27.1.0...@metamask/assets-controllers@27.2.0
|
|
758
780
|
[27.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@27.0.1...@metamask/assets-controllers@27.1.0
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkJW7WUU3Fjs = require('./chunk-JW7WUU3F.js');
|
|
7
7
|
require('./chunk-OBOWNEJU.js');
|
|
8
|
-
require('./chunk-3ZHN4GFT.js');
|
|
9
8
|
require('./chunk-BO2WZDUM.js');
|
|
9
|
+
require('./chunk-3ZHN4GFT.js');
|
|
10
10
|
require('./chunk-LS6R3HQL.js');
|
|
11
11
|
require('./chunk-Z4BLTVTB.js');
|
|
12
12
|
|
|
@@ -14,5 +14,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
exports.AssetsContractController =
|
|
17
|
+
exports.AssetsContractController = _chunkJW7WUU3Fjs.AssetsContractController; exports.MISSING_PROVIDER_ERROR = _chunkJW7WUU3Fjs.MISSING_PROVIDER_ERROR; exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID = _chunkJW7WUU3Fjs.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID; exports.default = _chunkJW7WUU3Fjs.AssetsContractController_default;
|
|
18
18
|
//# sourceMappingURL=AssetsContractController.js.map
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
AssetsContractController_default,
|
|
4
4
|
MISSING_PROVIDER_ERROR,
|
|
5
5
|
SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WAIP34TZ.mjs";
|
|
7
7
|
import "./chunk-V46CHMOU.mjs";
|
|
8
|
-
import "./chunk-S7UA2DU7.mjs";
|
|
9
8
|
import "./chunk-LLYYJY7H.mjs";
|
|
9
|
+
import "./chunk-S7UA2DU7.mjs";
|
|
10
10
|
import "./chunk-X5PLVMOQ.mjs";
|
|
11
11
|
import "./chunk-XUI43LEZ.mjs";
|
|
12
12
|
export {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkGY2QVELJjs = require('../chunk-GY2QVELJ.js');
|
|
4
|
+
require('../chunk-X4WSYARY.js');
|
|
5
|
+
require('../chunk-AORTOLZC.js');
|
|
6
|
+
require('../chunk-Z4BLTVTB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.BtcRateController = _chunkGY2QVELJjs.BtcRateController;
|
|
10
|
+
//# sourceMappingURL=BtcRateController.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-SE7AY5BK.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkGY2QVELJjs = require('../chunk-GY2QVELJ.js');
|
|
5
|
+
require('../chunk-X4WSYARY.js');
|
|
6
|
+
require('../chunk-AORTOLZC.js');
|
|
7
|
+
require('../chunk-Z4BLTVTB.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.BtcRateController = _chunkGY2QVELJjs.BtcRateController;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "../chunk-SYSB5PAB.mjs";
|
|
2
|
+
import {
|
|
3
|
+
BtcRateController
|
|
4
|
+
} from "../chunk-D7WROCMA.mjs";
|
|
5
|
+
import "../chunk-V23BWSM6.mjs";
|
|
6
|
+
import "../chunk-2H3C35ES.mjs";
|
|
7
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
8
|
+
export {
|
|
9
|
+
BtcRateController
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('./chunk-
|
|
4
|
+
var _chunkEBBQRZW3js = require('./chunk-EBBQRZW3.js');
|
|
5
|
+
require('./chunk-X4WSYARY.js');
|
|
6
|
+
require('./chunk-AORTOLZC.js');
|
|
6
7
|
require('./chunk-Z4BLTVTB.js');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
exports.CurrencyRateController =
|
|
11
|
+
exports.CurrencyRateController = _chunkEBBQRZW3js.CurrencyRateController; exports.default = _chunkEBBQRZW3js.CurrencyRateController_default;
|
|
11
12
|
//# sourceMappingURL=CurrencyRateController.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CurrencyRateController,
|
|
3
3
|
CurrencyRateController_default
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-COEHYUR5.mjs";
|
|
5
|
+
import "./chunk-V23BWSM6.mjs";
|
|
6
|
+
import "./chunk-2H3C35ES.mjs";
|
|
6
7
|
import "./chunk-XUI43LEZ.mjs";
|
|
7
8
|
export {
|
|
8
9
|
CurrencyRateController,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('./chunk-
|
|
4
|
+
var _chunkZIY545UXjs = require('./chunk-ZIY545UX.js');
|
|
5
|
+
require('./chunk-X4WSYARY.js');
|
|
6
|
+
require('./chunk-AORTOLZC.js');
|
|
6
7
|
require('./chunk-LS6R3HQL.js');
|
|
7
8
|
require('./chunk-Z4BLTVTB.js');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
exports.TokenRatesController =
|
|
12
|
+
exports.TokenRatesController = _chunkZIY545UXjs.TokenRatesController; exports.default = _chunkZIY545UXjs.TokenRatesController_default;
|
|
12
13
|
//# sourceMappingURL=TokenRatesController.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TokenRatesController,
|
|
3
3
|
TokenRatesController_default
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-YOMCL2SJ.mjs";
|
|
5
|
+
import "./chunk-V23BWSM6.mjs";
|
|
6
|
+
import "./chunk-2H3C35ES.mjs";
|
|
6
7
|
import "./chunk-X5PLVMOQ.mjs";
|
|
7
8
|
import "./chunk-XUI43LEZ.mjs";
|
|
8
9
|
export {
|
package/dist/TokensController.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('./chunk-3ZHN4GFT.js');
|
|
5
|
+
var _chunkQ5H4TKNSjs = require('./chunk-Q5H4TKNS.js');
|
|
7
6
|
require('./chunk-BO2WZDUM.js');
|
|
7
|
+
require('./chunk-3ZHN4GFT.js');
|
|
8
8
|
require('./chunk-OHSQRYVL.js');
|
|
9
9
|
require('./chunk-LS6R3HQL.js');
|
|
10
10
|
require('./chunk-Z4BLTVTB.js');
|
|
@@ -12,5 +12,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.TokensController =
|
|
15
|
+
exports.TokensController = _chunkQ5H4TKNSjs.TokensController; exports.default = _chunkQ5H4TKNSjs.TokensController_default; exports.getDefaultTokensState = _chunkQ5H4TKNSjs.getDefaultTokensState;
|
|
16
16
|
//# sourceMappingURL=TokensController.js.map
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
TokensController,
|
|
3
3
|
TokensController_default,
|
|
4
4
|
getDefaultTokensState
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-S7UA2DU7.mjs";
|
|
5
|
+
} from "./chunk-JZWPCTIR.mjs";
|
|
7
6
|
import "./chunk-LLYYJY7H.mjs";
|
|
7
|
+
import "./chunk-S7UA2DU7.mjs";
|
|
8
8
|
import "./chunk-NXGX7LZJ.mjs";
|
|
9
9
|
import "./chunk-X5PLVMOQ.mjs";
|
|
10
10
|
import "./chunk-XUI43LEZ.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/crypto-compare.ts
|
|
1
|
+
// src/crypto-compare-service/crypto-compare.ts
|
|
2
2
|
import { handleFetch } from "@metamask/controller-utils";
|
|
3
3
|
var nativeSymbolOverrides = /* @__PURE__ */ new Map([["MNT", "MANTLE"]]);
|
|
4
4
|
function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
|
|
@@ -32,4 +32,4 @@ async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
|
|
|
32
32
|
export {
|
|
33
33
|
fetchExchangeRate
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=chunk-
|
|
35
|
+
//# sourceMappingURL=chunk-2H3C35ES.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto-compare-service/crypto-compare.ts"],"sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([['MNT', 'MANTLE']]);\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `https://min-api.cryptocompare.com/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n /*\n Example expected error response (if pair is not found)\n {\n Response: \"Error\",\n Message: \"cccagg_or_exchange market does not exist for this coin pair (ETH-<NON_EXISTENT_TOKEN>)\",\n HasWarning: false,\n }\n */\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAM5B,IAAM,wBAAwB,oBAAI,IAAI,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;AAazD,SAAS,cACP,iBACA,gBACA,gBACA;AACA,mBAAiB,eAAe,YAAY;AAC5C,QAAM,OAAO,sBAAsB,IAAI,cAAc,KAAK;AAC1D,SACE,qDACG,IAAI,UAAU,gBAAgB,YAAY,CAAC,GAC3C,kBAAkB,gBAAgB,YAAY,MAAM,QAAQ,SAAS,EAAE;AAE9E;AAUA,eAAsB,kBACpB,UACA,gBACA,gBAIC;AACD,QAAM,OAAO,MAAM;AAAA,IACjB,cAAc,UAAU,gBAAgB,cAAc;AAAA,EACxD;AAUA,MAAI,KAAK,aAAa,SAAS;AAC7B,UAAM,IAAI,MAAM,KAAK,OAAO;AAAA,EAC9B;AAEA,QAAM,iBAAiB,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC;AAE1D,QAAM,oBAAoB,OAAO,KAAK,GAAG;AACzC,MAAI,CAAC,OAAO,SAAS,cAAc,GAAG;AACpC,UAAM,IAAI;AAAA,MACR,wBAAwB,SAAS,YAAY,CAAC,KAC5C,KAAK,SAAS,YAAY,CAAC,CAC7B;AAAA,IACF;AAAA,EACF;AAEA,MAAI,kBAAkB,CAAC,OAAO,SAAS,iBAAiB,GAAG;AACzD,UAAM,IAAI,MAAM,2CAA2C,KAAK,GAAG,EAAE;AAAA,EACvE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/crypto-compare.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/crypto-compare-service/crypto-compare.ts
|
|
2
2
|
var _controllerutils = require('@metamask/controller-utils');
|
|
3
3
|
var nativeSymbolOverrides = /* @__PURE__ */ new Map([["MNT", "MANTLE"]]);
|
|
4
4
|
function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
|
|
@@ -32,4 +32,4 @@ async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
exports.fetchExchangeRate = fetchExchangeRate;
|
|
35
|
-
//# sourceMappingURL=chunk-
|
|
35
|
+
//# sourceMappingURL=chunk-AORTOLZC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAM5B,IAAM,wBAAwB,oBAAI,IAAI,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;AAazD,SAAS,cACP,iBACA,gBACA,gBACA;AACA,mBAAiB,eAAe,YAAY;AAC5C,QAAM,OAAO,sBAAsB,IAAI,cAAc,KAAK;AAC1D,SACE,qDACG,IAAI,UAAU,gBAAgB,YAAY,CAAC,GAC3C,kBAAkB,gBAAgB,YAAY,MAAM,QAAQ,SAAS,EAAE;AAE9E;AAUA,eAAsB,kBACpB,UACA,gBACA,gBAIC;AACD,QAAM,OAAO,MAAM;AAAA,IACjB,cAAc,UAAU,gBAAgB,cAAc;AAAA,EACxD;AAUA,MAAI,KAAK,aAAa,SAAS;AAC7B,UAAM,IAAI,MAAM,KAAK,OAAO;AAAA,EAC9B;AAEA,QAAM,iBAAiB,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC;AAE1D,QAAM,oBAAoB,OAAO,KAAK,GAAG;AACzC,MAAI,CAAC,OAAO,SAAS,cAAc,GAAG;AACpC,UAAM,IAAI;AAAA,MACR,wBAAwB,SAAS,YAAY,CAAC,KAC5C,KAAK,SAAS,YAAY,CAAC,CAC7B;AAAA,IACF;AAAA,EACF;AAEA,MAAI,kBAAkB,CAAC,OAAO,SAAS,iBAAiB,GAAG;AACzD,UAAM,IAAI,MAAM,2CAA2C,KAAK,GAAG,EAAE;AAAA,EACvE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([['MNT', 'MANTLE']]);\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `https://min-api.cryptocompare.com/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n /*\n Example expected error response (if pair is not found)\n {\n Response: \"Error\",\n Message: \"cccagg_or_exchange market does not exist for this coin pair (ETH-<NON_EXISTENT_TOKEN>)\",\n HasWarning: false,\n }\n */\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchExchangeRate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2H3C35ES.mjs";
|
|
4
4
|
|
|
5
5
|
// src/CurrencyRateController.ts
|
|
6
6
|
import {
|
|
@@ -154,4 +154,4 @@ export {
|
|
|
154
154
|
CurrencyRateController,
|
|
155
155
|
CurrencyRateController_default
|
|
156
156
|
};
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
//# sourceMappingURL=chunk-COEHYUR5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/CurrencyRateController.ts"],"sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';\n\n/**\n * @type CurrencyRateState\n * @property currencyRates - Object keyed by native currency\n * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type GetCurrencyRateState = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions = GetCurrencyRateState;\n\ntype AllowedActions = NetworkControllerGetNetworkClientByIdAction;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents,\n AllowedActions['type'],\n never\n>;\n\nconst metadata = {\n currentCurrency: { persist: true, anonymous: true },\n currencyRates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n messenger,\n state,\n fetchExchangeRate = defaultFetchExchangeRate,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.includeUsdRate = includeUsdRate;\n this.setIntervalLength(interval);\n this.fetchExchangeRate = fetchExchangeRate;\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n const releaseLock = await this.mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n nativeCurrencies.forEach(this.updateExchangeRate.bind(this));\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pair.\n *\n * @param nativeCurrency - The ticker symbol for the chain.\n */\n async updateExchangeRate(nativeCurrency: string): Promise<void> {\n const releaseLock = await this.mutex.acquire();\n const { currentCurrency, currencyRates } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n const nativeCurrencyForExchangeRate = Object.values(\n TESTNET_TICKER_SYMBOLS,\n ).includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY // ETH\n : nativeCurrency;\n\n try {\n if (\n currentCurrency &&\n nativeCurrency &&\n // if either currency is an empty string we can skip the comparison\n // because it will result in an error from the api and ultimately\n // a null conversionRate either way.\n currentCurrency !== '' &&\n nativeCurrency !== ''\n ) {\n const fetchExchangeRateResponse = await this.fetchExchangeRate(\n currentCurrency,\n nativeCurrencyForExchangeRate,\n this.includeUsdRate,\n );\n conversionRate = fetchExchangeRateResponse.conversionRate;\n usdConversionRate = fetchExchangeRateResponse.usdConversionRate;\n conversionDate = Date.now() / 1000;\n }\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n )\n ) {\n throw error;\n }\n } finally {\n try {\n this.update(() => {\n return {\n currencyRates: {\n ...currencyRates,\n [nativeCurrency]: {\n conversionDate,\n conversionRate,\n usdConversionRate,\n },\n },\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n await this.updateExchangeRate(networkClient.configuration.ticker);\n }\n}\n\nexport default CurrencyRateController;\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,IAAO,iCAAQ;","names":["fetchExchangeRate"]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchExchangeRate
|
|
3
|
+
} from "./chunk-2H3C35ES.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet,
|
|
7
|
+
__privateMethod,
|
|
8
|
+
__privateSet
|
|
9
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
10
|
+
|
|
11
|
+
// src/BtcRateController/BtcRateController.ts
|
|
12
|
+
import { BaseController } from "@metamask/base-controller";
|
|
13
|
+
var name = "BtcRateController";
|
|
14
|
+
var metadata = {
|
|
15
|
+
currency: { persist: true, anonymous: true },
|
|
16
|
+
rates: { persist: true, anonymous: true }
|
|
17
|
+
};
|
|
18
|
+
var defaultState = {
|
|
19
|
+
currency: "usd",
|
|
20
|
+
rates: {
|
|
21
|
+
btc: {
|
|
22
|
+
conversionDate: 0,
|
|
23
|
+
conversionRate: 0,
|
|
24
|
+
usdConversionRate: null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var DEFAULT_CURRENCIES = {
|
|
29
|
+
btc: "BTC"
|
|
30
|
+
};
|
|
31
|
+
var _fetchExchangeRate, _onStart, _onStop, _includeUsdRate, _intervalId, _intervalLength, _setIntervalLength, setIntervalLength_fn, _updateRates, updateRates_fn, _executePoll, executePoll_fn;
|
|
32
|
+
var BtcRateController = class extends BaseController {
|
|
33
|
+
/**
|
|
34
|
+
* Creates a BtcRateController instance.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Constructor options.
|
|
37
|
+
* @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.
|
|
38
|
+
* @param options.interval - The polling interval, in milliseconds.
|
|
39
|
+
* @param options.messenger - A reference to the messaging system.
|
|
40
|
+
* @param options.state - Initial state to set on this controller.
|
|
41
|
+
* @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.
|
|
42
|
+
* @param options.onStart - Optional callback to be executed when the polling stops.
|
|
43
|
+
* @param options.onStop - Optional callback to be executed when the polling starts.
|
|
44
|
+
*/
|
|
45
|
+
constructor({
|
|
46
|
+
interval = 18e4,
|
|
47
|
+
messenger,
|
|
48
|
+
state,
|
|
49
|
+
includeUsdRate,
|
|
50
|
+
fetchExchangeRate: fetchExchangeRate2 = fetchExchangeRate,
|
|
51
|
+
onStart,
|
|
52
|
+
onStop
|
|
53
|
+
}) {
|
|
54
|
+
super({
|
|
55
|
+
name,
|
|
56
|
+
metadata,
|
|
57
|
+
messenger,
|
|
58
|
+
state: { ...defaultState, ...state }
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Sets the interval length for polling.
|
|
62
|
+
*
|
|
63
|
+
* @param intervalLength - The length of the interval in milliseconds.
|
|
64
|
+
*/
|
|
65
|
+
__privateAdd(this, _setIntervalLength);
|
|
66
|
+
/**
|
|
67
|
+
* Updates the BTC rates by fetching new data.
|
|
68
|
+
*/
|
|
69
|
+
__privateAdd(this, _updateRates);
|
|
70
|
+
/**
|
|
71
|
+
* Executes the polling operation to update rates.
|
|
72
|
+
*/
|
|
73
|
+
__privateAdd(this, _executePoll);
|
|
74
|
+
__privateAdd(this, _fetchExchangeRate, void 0);
|
|
75
|
+
__privateAdd(this, _onStart, void 0);
|
|
76
|
+
__privateAdd(this, _onStop, void 0);
|
|
77
|
+
__privateAdd(this, _includeUsdRate, void 0);
|
|
78
|
+
__privateAdd(this, _intervalId, void 0);
|
|
79
|
+
__privateAdd(this, _intervalLength, 1e3);
|
|
80
|
+
__privateSet(this, _includeUsdRate, includeUsdRate);
|
|
81
|
+
__privateSet(this, _fetchExchangeRate, fetchExchangeRate2);
|
|
82
|
+
__privateSet(this, _onStart, onStart);
|
|
83
|
+
__privateSet(this, _onStop, onStop);
|
|
84
|
+
__privateMethod(this, _setIntervalLength, setIntervalLength_fn).call(this, interval);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Starts the polling process.
|
|
88
|
+
*/
|
|
89
|
+
async start() {
|
|
90
|
+
var _a;
|
|
91
|
+
if (__privateGet(this, _intervalId)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await ((_a = __privateGet(this, _onStart)) == null ? void 0 : _a.call(this));
|
|
95
|
+
__privateSet(this, _intervalId, setInterval(() => {
|
|
96
|
+
__privateMethod(this, _executePoll, executePoll_fn).call(this).catch(console.error);
|
|
97
|
+
}, __privateGet(this, _intervalLength)));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Stops the polling process.
|
|
101
|
+
*/
|
|
102
|
+
async stop() {
|
|
103
|
+
var _a;
|
|
104
|
+
if (!__privateGet(this, _intervalId)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
clearInterval(__privateGet(this, _intervalId));
|
|
108
|
+
__privateSet(this, _intervalId, void 0);
|
|
109
|
+
await ((_a = __privateGet(this, _onStop)) == null ? void 0 : _a.call(this));
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
_fetchExchangeRate = new WeakMap();
|
|
113
|
+
_onStart = new WeakMap();
|
|
114
|
+
_onStop = new WeakMap();
|
|
115
|
+
_includeUsdRate = new WeakMap();
|
|
116
|
+
_intervalId = new WeakMap();
|
|
117
|
+
_intervalLength = new WeakMap();
|
|
118
|
+
_setIntervalLength = new WeakSet();
|
|
119
|
+
setIntervalLength_fn = function(intervalLength) {
|
|
120
|
+
__privateSet(this, _intervalLength, intervalLength);
|
|
121
|
+
};
|
|
122
|
+
_updateRates = new WeakSet();
|
|
123
|
+
updateRates_fn = async function() {
|
|
124
|
+
const { currency } = this.state;
|
|
125
|
+
const response = await __privateGet(this, _fetchExchangeRate).call(this, currency, DEFAULT_CURRENCIES.btc);
|
|
126
|
+
const { conversionRate, usdConversionRate } = response;
|
|
127
|
+
this.update(() => {
|
|
128
|
+
return {
|
|
129
|
+
rates: {
|
|
130
|
+
btc: {
|
|
131
|
+
conversionDate: Date.now() / 1e3,
|
|
132
|
+
conversionRate,
|
|
133
|
+
usdConversionRate
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
currency
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
_executePoll = new WeakSet();
|
|
141
|
+
executePoll_fn = async function() {
|
|
142
|
+
await __privateMethod(this, _updateRates, updateRates_fn).call(this);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
BtcRateController
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=chunk-D7WROCMA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/BtcRateController/BtcRateController.ts"],"sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\n\n/**\n * Represents the state structure for the BtcRateController.\n */\nexport type BtcRateState = {\n currency: string;\n rates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'BtcRateController';\n\n/**\n * Type definition for BtcRateController state change events.\n */\nexport type BtcRateStateChange = ControllerStateChangeEvent<\n typeof name,\n BtcRateState\n>;\n\nexport type BtcRateControllerEvents = BtcRateStateChange;\n\n/**\n * Type definition for getting the BtcRateController.\n */\nexport type GetBtcRateState = ControllerGetStateAction<\n typeof name,\n BtcRateState\n>;\n\nexport type BtcRateControllerActions = GetBtcRateState;\n\ntype BtcRateMessenger = RestrictedControllerMessenger<\n typeof name,\n BtcRateControllerActions,\n BtcRateControllerEvents,\n never,\n never\n>;\n\nconst metadata = {\n currency: { persist: true, anonymous: true },\n rates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currency: 'usd',\n rates: {\n btc: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\nconst DEFAULT_CURRENCIES = {\n btc: 'BTC',\n};\n\nexport class BtcRateController extends BaseController<\n typeof name,\n BtcRateState,\n BtcRateMessenger\n> {\n readonly #fetchExchangeRate;\n\n readonly #onStart;\n\n readonly #onStop;\n\n readonly #includeUsdRate;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n #intervalLength: number | undefined = 1000;\n\n /**\n * Creates a BtcRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n * @param options.onStart - Optional callback to be executed when the polling stops.\n * @param options.onStop - Optional callback to be executed when the polling starts.\n */\n constructor({\n interval = 180000,\n messenger,\n state,\n includeUsdRate,\n fetchExchangeRate = defaultFetchExchangeRate,\n onStart,\n onStop,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: BtcRateMessenger;\n state?: Partial<BtcRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n onStart?: () => Promise<unknown>;\n onStop?: () => Promise<unknown>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchExchangeRate = fetchExchangeRate;\n this.#onStart = onStart;\n this.#onStop = onStop;\n this.#setIntervalLength(interval);\n }\n\n /**\n * Sets the interval length for polling.\n *\n * @param intervalLength - The length of the interval in milliseconds.\n */\n #setIntervalLength(intervalLength: number) {\n this.#intervalLength = intervalLength;\n }\n\n /**\n * Updates the BTC rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n const { currency } = this.state;\n const response = await this.#fetchExchangeRate(\n currency,\n DEFAULT_CURRENCIES.btc,\n );\n const { conversionRate, usdConversionRate } = response;\n this.update(() => {\n return {\n rates: {\n btc: {\n conversionDate: Date.now() / 1000,\n conversionRate,\n usdConversionRate,\n },\n },\n currency,\n };\n });\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n await this.#onStart?.();\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n await this.#onStop?.();\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,sBAAsB;AAwB/B,IAAM,OAAO;AA8Bb,IAAM,WAAW;AAAA,EACf,UAAU,EAAE,SAAS,MAAM,WAAW,KAAK;AAAA,EAC3C,OAAO,EAAE,SAAS,MAAM,WAAW,KAAK;AAC1C;AAEA,IAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,OAAO;AAAA,IACL,KAAK;AAAA,MACH,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,MAChB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEA,IAAM,qBAAqB;AAAA,EACzB,KAAK;AACP;AAxEA;AA0EO,IAAM,oBAAN,cAAgC,eAIrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,YAAY;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAAA,qBAAoB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAQG;AACD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,EAAE,GAAG,cAAc,GAAG,MAAM;AAAA,IACrC,CAAC;AAaH;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA,uBAAM;AAwBN;AAAA;AAAA;AA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@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkAORTOLZCjs = require('./chunk-AORTOLZC.js');
|
|
4
4
|
|
|
5
5
|
// src/CurrencyRateController.ts
|
|
6
6
|
|
|
@@ -40,7 +40,7 @@ var CurrencyRateController = class extends _pollingcontroller.StaticIntervalPoll
|
|
|
40
40
|
interval = 18e4,
|
|
41
41
|
messenger,
|
|
42
42
|
state,
|
|
43
|
-
fetchExchangeRate: fetchExchangeRate2 =
|
|
43
|
+
fetchExchangeRate: fetchExchangeRate2 = _chunkAORTOLZCjs.fetchExchangeRate
|
|
44
44
|
}) {
|
|
45
45
|
super({
|
|
46
46
|
name,
|
|
@@ -154,4 +154,4 @@ var CurrencyRateController_default = CurrencyRateController;
|
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
exports.CurrencyRateController = CurrencyRateController; exports.CurrencyRateController_default = CurrencyRateController_default;
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
//# sourceMappingURL=chunk-EBBQRZW3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/CurrencyRateController.ts"],"names":["fetchExchangeRate"],"mappings":";;;;;AAKA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAKP,SAAS,uCAAuC;AAChD,SAAS,aAAa;AAwBtB,IAAM,OAAO;AA0Bb,IAAM,WAAW;AAAA,EACf,iBAAiB,EAAE,SAAS,MAAM,WAAW,KAAK;AAAA,EAClD,eAAe,EAAE,SAAS,MAAM,WAAW,KAAK;AAClD;AAEA,IAAM,eAAe;AAAA,EACnB,iBAAiB;AAAA,EACjB,eAAe;AAAA,IACb,KAAK;AAAA,MACH,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,MAChB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAMO,IAAM,yBAAN,cAAqC,gCAI1C;AAAA;AAAA;AAAA;AAAA;AAAA;A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AA0B;AAC3C,4BAAoB,0BAA0B;AAC9C,yBAAiB,KAAK,IAAI,IAAI;AAAA,MAChC;AAAA,IACF,SAAS,OAAO;AACd,UACE,EACE,iBAAiB,SACjB,MAAM,QAAQ,SAAS,0CAA0C,IAEnE;AACA,cAAM;AAAA,MACR;AAAA,IACF,UAAE;AACA,UAAI;AACF,aAAK,OAAO,MAAM;AAChB,iBAAO;AAAA,YACL,eAAe;AAAA,cACb,GAAG;AAAA,cACH,CAAC,cAAc,GAAG;AAAA,gBAChB;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA,YACF;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,UAAE;AACA,oBAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOS,UAAU;AACjB,UAAM,QAAQ;AACd,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,iBAAiD;AAClE,UAAM,gBAAgB,KAAK,gBAAgB;AAAA,MACzC;AAAA,MACA;AAAA,IACF;AACA,UAAM,KAAK,mBAAmB,cAAc,cAAc,MAAM;AAAA,EAClE;AACF;AAEA,IAAO,iCAAQ","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';\n\n/**\n * @type CurrencyRateState\n * @property currencyRates - Object keyed by native currency\n * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type GetCurrencyRateState = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions = GetCurrencyRateState;\n\ntype AllowedActions = NetworkControllerGetNetworkClientByIdAction;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents,\n AllowedActions['type'],\n never\n>;\n\nconst metadata = {\n currentCurrency: { persist: true, anonymous: true },\n currencyRates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n messenger,\n state,\n fetchExchangeRate = defaultFetchExchangeRate,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.includeUsdRate = includeUsdRate;\n this.setIntervalLength(interval);\n this.fetchExchangeRate = fetchExchangeRate;\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n const releaseLock = await this.mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n nativeCurrencies.forEach(this.updateExchangeRate.bind(this));\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pair.\n *\n * @param nativeCurrency - The ticker symbol for the chain.\n */\n async updateExchangeRate(nativeCurrency: string): Promise<void> {\n const releaseLock = await this.mutex.acquire();\n const { currentCurrency, currencyRates } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n const nativeCurrencyForExchangeRate = Object.values(\n TESTNET_TICKER_SYMBOLS,\n ).includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY // ETH\n : nativeCurrency;\n\n try {\n if (\n currentCurrency &&\n nativeCurrency &&\n // if either currency is an empty string we can skip the comparison\n // because it will result in an error from the api and ultimately\n // a null conversionRate either way.\n currentCurrency !== '' &&\n nativeCurrency !== ''\n ) {\n const fetchExchangeRateResponse = await this.fetchExchangeRate(\n currentCurrency,\n nativeCurrencyForExchangeRate,\n this.includeUsdRate,\n );\n conversionRate = fetchExchangeRateResponse.conversionRate;\n usdConversionRate = fetchExchangeRateResponse.usdConversionRate;\n conversionDate = Date.now() / 1000;\n }\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n )\n ) {\n throw error;\n }\n } finally {\n try {\n this.update(() => {\n return {\n currencyRates: {\n ...currencyRates,\n [nativeCurrency]: {\n conversionDate,\n conversionRate,\n usdConversionRate,\n },\n },\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n await this.updateExchangeRate(networkClient.configuration.ticker);\n }\n}\n\nexport default CurrencyRateController;\n"]}
|