@metamask/assets-controllers 17.0.0 → 18.0.0
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 +30 -3
- package/dist/CurrencyRateController.d.ts +22 -38
- package/dist/CurrencyRateController.d.ts.map +1 -1
- package/dist/CurrencyRateController.js +52 -113
- package/dist/CurrencyRateController.js.map +1 -1
- package/dist/NftController.d.ts.map +1 -1
- package/dist/NftController.js +16 -21
- package/dist/NftController.js.map +1 -1
- package/dist/Standards/ERC20Standard.d.ts.map +1 -1
- package/dist/Standards/ERC20Standard.js +2 -5
- package/dist/Standards/ERC20Standard.js.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +12 -20
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +1 -1
- package/dist/TokensController.d.ts.map +1 -1
- package/dist/TokensController.js +24 -22
- package/dist/TokensController.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [18.0.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING**: `CurrencyRateController` is now keyed by `nativeCurrency` (i.e. ticker) for `conversionDate`, `conversionRate`, and `usdConversionRate` in the `currencyRates` object. `nativeCurrency`, `pendingNativeCurrency`, and `pendingCurrentCurrency` have been removed.
|
|
12
|
+
- ```
|
|
13
|
+
export type CurrencyRateState = {
|
|
14
|
+
currentCurrency: string;
|
|
15
|
+
currencyRates: Record<
|
|
16
|
+
string, // nativeCurrency
|
|
17
|
+
{
|
|
18
|
+
conversionDate: number | null;
|
|
19
|
+
conversionRate: number | null;
|
|
20
|
+
usdConversionRate: number | null;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
- **BREAKING**: `CurrencyRateController` now extends `PollingController` ([#1805](https://github.com/MetaMask/core/pull/1805))
|
|
26
|
+
- `start()` and `stop()` methods replaced with `startPollingByNetworkClientId()`, `stopPollingByPollingToken()`, and `stopAllPolling()`
|
|
27
|
+
- **BREAKING**: `CurrencyRateController` now sends the `NetworkController:getNetworkClientById` action via messaging controller ([#1805](https://github.com/MetaMask/core/pull/1805))
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- Parallelize network requests in assets controllers for performance enhancement ([#1801](https://github.com/MetaMask/core/pull/1801))
|
|
31
|
+
- Fix token detection on accounts when user changes account after token detection request is inflight ([#1848](https://github.com/MetaMask/core/pull/1848))
|
|
32
|
+
|
|
9
33
|
## [17.0.0]
|
|
10
34
|
### Changed
|
|
11
35
|
- **BREAKING:** Bump dependency on `@metamask/polling-controller` to ^1.0.0
|
|
@@ -16,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
40
|
- Add way to start and stop different polling sessions for the same network client ID by providing extra scoping data ([#1776](https://github.com/MetaMask/core/pull/1776))
|
|
17
41
|
- Add optional second argument to `stopPollingByPollingToken` (formerly `stopPollingByNetworkClientId`)
|
|
18
42
|
- Add optional second argument to `onPollingCompleteByNetworkClientId`
|
|
43
|
+
- Add support for token detection for Linea mainnet and Linea Goerli ([#1799](https://github.com/MetaMask/core/pull/1799))
|
|
19
44
|
|
|
20
45
|
### Changed
|
|
21
46
|
- **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^15.0.0
|
|
@@ -24,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
24
49
|
- Add missing dependency on `@metamask/polling-controller` ([#1831](https://github.com/MetaMask/core/pull/1831))
|
|
25
50
|
- Bump dependency and peer dependency on `@metamask/approval-controller` to ^4.0.1
|
|
26
51
|
- Bump dependency and peer dependency on `@metamask/preferences-controller` to ^4.4.3
|
|
52
|
+
- Fix support for NFT metadata stored outside IPFS ([#1772](https://github.com/MetaMask/core/pull/1772))
|
|
27
53
|
|
|
28
54
|
## [15.0.0]
|
|
29
55
|
### Changed
|
|
@@ -195,8 +221,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
195
221
|
- The `NFTController` now requires an instance of a ControllerMessenger to be passed to its constructor. This is messenger is used to pass the `watchNFT` message to the `ApprovalController`.
|
|
196
222
|
|
|
197
223
|
### Changed
|
|
198
|
-
- Add dependency on `@ethersproject/address` ([#1173](https://github.com/MetaMask/core
|
|
199
|
-
- Replace `eth-rpc-errors` with `@metamask/rpc-errors` ([#1173](https://github.com/MetaMask/core
|
|
224
|
+
- Add dependency on `@ethersproject/address` ([#1173](https://github.com/MetaMask/core/pull/1173))
|
|
225
|
+
- Replace `eth-rpc-errors` with `@metamask/rpc-errors` ([#1173](https://github.com/MetaMask/core/pull/1173))
|
|
200
226
|
|
|
201
227
|
## [8.0.0]
|
|
202
228
|
### Added
|
|
@@ -339,7 +365,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
339
365
|
### Changed
|
|
340
366
|
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
|
|
341
367
|
|
|
342
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@
|
|
368
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@18.0.0...HEAD
|
|
369
|
+
[18.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@17.0.0...@metamask/assets-controllers@18.0.0
|
|
343
370
|
[17.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@16.0.0...@metamask/assets-controllers@17.0.0
|
|
344
371
|
[16.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@15.0.0...@metamask/assets-controllers@16.0.0
|
|
345
372
|
[15.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@14.0.0...@metamask/assets-controllers@15.0.0
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
-
import {
|
|
2
|
+
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';
|
|
3
|
+
import { PollingController } from '@metamask/polling-controller';
|
|
3
4
|
import type { Patch } from 'immer';
|
|
4
5
|
import { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare';
|
|
5
6
|
/**
|
|
6
7
|
* @type CurrencyRateState
|
|
7
|
-
* @property
|
|
8
|
-
* @property
|
|
8
|
+
* @property currencyRates - Object keyed by native currency
|
|
9
|
+
* @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch
|
|
10
|
+
* @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency
|
|
9
11
|
* @property currentCurrency - Currently-active ISO 4217 currency code
|
|
10
|
-
* @property nativeCurrency - Symbol for the base asset used for conversion
|
|
11
|
-
* @property pendingCurrentCurrency - The currency being switched to
|
|
12
|
-
* @property pendingNativeCurrency - The base asset currency being switched to
|
|
13
12
|
* @property usdConversionRate - Conversion rate from usd to the current currency
|
|
14
13
|
*/
|
|
15
14
|
export declare type CurrencyRateState = {
|
|
16
|
-
conversionDate: number | null;
|
|
17
|
-
conversionRate: number | null;
|
|
18
15
|
currentCurrency: string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
currencyRates: Record<string, {
|
|
17
|
+
conversionDate: number | null;
|
|
18
|
+
conversionRate: number | null;
|
|
19
|
+
usdConversionRate: number | null;
|
|
20
|
+
}>;
|
|
23
21
|
};
|
|
24
22
|
declare const name = "CurrencyRateController";
|
|
25
23
|
export declare type CurrencyRateStateChange = {
|
|
@@ -30,16 +28,14 @@ export declare type GetCurrencyRateState = {
|
|
|
30
28
|
type: `${typeof name}:getState`;
|
|
31
29
|
handler: () => CurrencyRateState;
|
|
32
30
|
};
|
|
33
|
-
declare type
|
|
31
|
+
declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | GetCurrencyRateState;
|
|
32
|
+
declare type CurrencyRateMessenger = RestrictedControllerMessenger<typeof name, AllowedActions, CurrencyRateStateChange, AllowedActions['type'], never>;
|
|
34
33
|
/**
|
|
35
34
|
* Controller that passively polls on a set interval for an exchange rate from the current network
|
|
36
35
|
* asset to the user's preferred currency.
|
|
37
36
|
*/
|
|
38
|
-
export declare class CurrencyRateController extends
|
|
39
|
-
#private;
|
|
37
|
+
export declare class CurrencyRateController extends PollingController<typeof name, CurrencyRateState, CurrencyRateMessenger> {
|
|
40
38
|
private readonly mutex;
|
|
41
|
-
private intervalId?;
|
|
42
|
-
private readonly intervalDelay;
|
|
43
39
|
private readonly fetchExchangeRate;
|
|
44
40
|
private readonly includeUsdRate;
|
|
45
41
|
/**
|
|
@@ -59,20 +55,6 @@ export declare class CurrencyRateController extends BaseControllerV2<typeof name
|
|
|
59
55
|
state?: Partial<CurrencyRateState>;
|
|
60
56
|
fetchExchangeRate?: typeof defaultFetchExchangeRate;
|
|
61
57
|
});
|
|
62
|
-
/**
|
|
63
|
-
* Start polling for the currency rate.
|
|
64
|
-
*/
|
|
65
|
-
start(): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Stop polling for the currency rate.
|
|
68
|
-
*/
|
|
69
|
-
stop(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Prepare to discard this controller.
|
|
72
|
-
*
|
|
73
|
-
* This stops any active polling.
|
|
74
|
-
*/
|
|
75
|
-
destroy(): void;
|
|
76
58
|
/**
|
|
77
59
|
* Sets a currency to track.
|
|
78
60
|
*
|
|
@@ -80,22 +62,24 @@ export declare class CurrencyRateController extends BaseControllerV2<typeof name
|
|
|
80
62
|
*/
|
|
81
63
|
setCurrentCurrency(currentCurrency: string): Promise<void>;
|
|
82
64
|
/**
|
|
83
|
-
*
|
|
65
|
+
* Updates the exchange rate for the current currency and native currency pair.
|
|
84
66
|
*
|
|
85
|
-
* @param
|
|
67
|
+
* @param nativeCurrency - The ticker symbol for the chain.
|
|
86
68
|
*/
|
|
87
|
-
|
|
88
|
-
private stopPolling;
|
|
69
|
+
updateExchangeRate(nativeCurrency: string): Promise<void>;
|
|
89
70
|
/**
|
|
90
|
-
*
|
|
71
|
+
* Prepare to discard this controller.
|
|
72
|
+
*
|
|
73
|
+
* This stops any active polling.
|
|
91
74
|
*/
|
|
92
|
-
|
|
75
|
+
destroy(): void;
|
|
93
76
|
/**
|
|
94
77
|
* Updates exchange rate for the current currency.
|
|
95
78
|
*
|
|
79
|
+
* @param networkClientId - The network client ID used to get a ticker value.
|
|
96
80
|
* @returns The controller state.
|
|
97
81
|
*/
|
|
98
|
-
|
|
82
|
+
_executePoll(networkClientId: NetworkClientId): Promise<void>;
|
|
99
83
|
}
|
|
100
84
|
export default CurrencyRateController;
|
|
101
85
|
//# sourceMappingURL=CurrencyRateController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyRateController.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrencyRateController.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAK/E,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC5C,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;;;;;;GAOG;AACH,oBAAY,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,CA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AO,wBAAwB,CAAC;KACrD;IAYD;;;;OAIG;IACG,kBAAkB,CAAC,eAAe,EAAE,MAAM;IAgBhD;;;;OAIG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgE/D;;;;OAIG;IACM,OAAO;IAKhB;;;;;OAKG;IACG,YAAY,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAOpE;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -8,48 +8,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _CurrencyRateController_enabled;
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
12
|
exports.CurrencyRateController = void 0;
|
|
25
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
26
13
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
14
|
+
const polling_controller_1 = require("@metamask/polling-controller");
|
|
27
15
|
const async_mutex_1 = require("async-mutex");
|
|
28
16
|
const crypto_compare_1 = require("./crypto-compare");
|
|
29
17
|
const name = 'CurrencyRateController';
|
|
30
18
|
const metadata = {
|
|
31
|
-
conversionDate: { persist: true, anonymous: true },
|
|
32
|
-
conversionRate: { persist: true, anonymous: true },
|
|
33
19
|
currentCurrency: { persist: true, anonymous: true },
|
|
34
|
-
|
|
35
|
-
pendingCurrentCurrency: { persist: false, anonymous: true },
|
|
36
|
-
pendingNativeCurrency: { persist: false, anonymous: true },
|
|
37
|
-
usdConversionRate: { persist: true, anonymous: true },
|
|
20
|
+
currencyRates: { persist: true, anonymous: true },
|
|
38
21
|
};
|
|
39
22
|
const defaultState = {
|
|
40
|
-
conversionDate: 0,
|
|
41
|
-
conversionRate: 0,
|
|
42
23
|
currentCurrency: 'usd',
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
24
|
+
currencyRates: {
|
|
25
|
+
ETH: {
|
|
26
|
+
conversionDate: 0,
|
|
27
|
+
conversionRate: 0,
|
|
28
|
+
usdConversionRate: null,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
47
31
|
};
|
|
48
32
|
/**
|
|
49
33
|
* Controller that passively polls on a set interval for an exchange rate from the current network
|
|
50
34
|
* asset to the user's preferred currency.
|
|
51
35
|
*/
|
|
52
|
-
class CurrencyRateController extends
|
|
36
|
+
class CurrencyRateController extends polling_controller_1.PollingController {
|
|
53
37
|
/**
|
|
54
38
|
* Creates a CurrencyRateController instance.
|
|
55
39
|
*
|
|
@@ -68,39 +52,9 @@ class CurrencyRateController extends base_controller_1.BaseControllerV2 {
|
|
|
68
52
|
state: Object.assign(Object.assign({}, defaultState), state),
|
|
69
53
|
});
|
|
70
54
|
this.mutex = new async_mutex_1.Mutex();
|
|
71
|
-
/**
|
|
72
|
-
* A boolean that controls whether or not network requests can be made by the controller
|
|
73
|
-
*/
|
|
74
|
-
_CurrencyRateController_enabled.set(this, void 0);
|
|
75
55
|
this.includeUsdRate = includeUsdRate;
|
|
76
|
-
this.
|
|
56
|
+
this.setIntervalLength(interval);
|
|
77
57
|
this.fetchExchangeRate = fetchExchangeRate;
|
|
78
|
-
__classPrivateFieldSet(this, _CurrencyRateController_enabled, false, "f");
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Start polling for the currency rate.
|
|
82
|
-
*/
|
|
83
|
-
start() {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
__classPrivateFieldSet(this, _CurrencyRateController_enabled, true, "f");
|
|
86
|
-
yield this.startPolling();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Stop polling for the currency rate.
|
|
91
|
-
*/
|
|
92
|
-
stop() {
|
|
93
|
-
__classPrivateFieldSet(this, _CurrencyRateController_enabled, false, "f");
|
|
94
|
-
this.stopPolling();
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Prepare to discard this controller.
|
|
98
|
-
*
|
|
99
|
-
* This stops any active polling.
|
|
100
|
-
*/
|
|
101
|
-
destroy() {
|
|
102
|
-
super.destroy();
|
|
103
|
-
this.stopPolling();
|
|
104
58
|
}
|
|
105
59
|
/**
|
|
106
60
|
* Sets a currency to track.
|
|
@@ -109,61 +63,31 @@ class CurrencyRateController extends base_controller_1.BaseControllerV2 {
|
|
|
109
63
|
*/
|
|
110
64
|
setCurrentCurrency(currentCurrency) {
|
|
111
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
setNativeCurrency(symbol) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
this.update((state) => {
|
|
126
|
-
state.pendingNativeCurrency = symbol;
|
|
127
|
-
});
|
|
128
|
-
yield this.updateExchangeRate();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
stopPolling() {
|
|
132
|
-
if (this.intervalId) {
|
|
133
|
-
clearInterval(this.intervalId);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Starts a new polling interval.
|
|
138
|
-
*/
|
|
139
|
-
startPolling() {
|
|
140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
this.stopPolling();
|
|
142
|
-
// TODO: Expose polling currency rate update errors
|
|
143
|
-
yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () { return yield this.updateExchangeRate(); }));
|
|
144
|
-
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () { return yield this.updateExchangeRate(); }));
|
|
146
|
-
}), this.intervalDelay);
|
|
66
|
+
const releaseLock = yield this.mutex.acquire();
|
|
67
|
+
const nativeCurrencies = Object.keys(this.state.currencyRates);
|
|
68
|
+
try {
|
|
69
|
+
this.update(() => {
|
|
70
|
+
return Object.assign(Object.assign({}, defaultState), { currentCurrency });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
releaseLock();
|
|
75
|
+
}
|
|
76
|
+
nativeCurrencies.forEach(this.updateExchangeRate.bind(this));
|
|
147
77
|
});
|
|
148
78
|
}
|
|
149
79
|
/**
|
|
150
|
-
* Updates exchange rate for the current currency.
|
|
80
|
+
* Updates the exchange rate for the current currency and native currency pair.
|
|
151
81
|
*
|
|
152
|
-
* @
|
|
82
|
+
* @param nativeCurrency - The ticker symbol for the chain.
|
|
153
83
|
*/
|
|
154
|
-
updateExchangeRate() {
|
|
84
|
+
updateExchangeRate(nativeCurrency) {
|
|
155
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
if (!__classPrivateFieldGet(this, _CurrencyRateController_enabled, "f")) {
|
|
157
|
-
console.info('[CurrencyRateController] Not updating exchange rate since network requests have been disabled');
|
|
158
|
-
return this.state;
|
|
159
|
-
}
|
|
160
86
|
const releaseLock = yield this.mutex.acquire();
|
|
161
|
-
const { currentCurrency
|
|
87
|
+
const { currentCurrency, currencyRates } = this.state;
|
|
162
88
|
let conversionDate = null;
|
|
163
89
|
let conversionRate = null;
|
|
164
90
|
let usdConversionRate = null;
|
|
165
|
-
const currentCurrency = pendingCurrentCurrency !== null && pendingCurrentCurrency !== void 0 ? pendingCurrentCurrency : stateCurrentCurrency;
|
|
166
|
-
const nativeCurrency = pendingNativeCurrency !== null && pendingNativeCurrency !== void 0 ? pendingNativeCurrency : stateNativeCurrency;
|
|
167
91
|
// For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.
|
|
168
92
|
const nativeCurrencyForExchangeRate = Object.values(controller_utils_1.TESTNET_TICKER_SYMBOLS).includes(nativeCurrency)
|
|
169
93
|
? controller_utils_1.FALL_BACK_VS_CURRENCY // ETH
|
|
@@ -192,16 +116,12 @@ class CurrencyRateController extends base_controller_1.BaseControllerV2 {
|
|
|
192
116
|
try {
|
|
193
117
|
this.update(() => {
|
|
194
118
|
return {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
nativeCurrency,
|
|
119
|
+
currencyRates: Object.assign(Object.assign({}, currencyRates), { [nativeCurrency]: {
|
|
120
|
+
conversionDate,
|
|
121
|
+
conversionRate,
|
|
122
|
+
usdConversionRate,
|
|
123
|
+
} }),
|
|
201
124
|
currentCurrency,
|
|
202
|
-
pendingCurrentCurrency: null,
|
|
203
|
-
pendingNativeCurrency: null,
|
|
204
|
-
usdConversionRate,
|
|
205
125
|
};
|
|
206
126
|
});
|
|
207
127
|
}
|
|
@@ -209,11 +129,30 @@ class CurrencyRateController extends base_controller_1.BaseControllerV2 {
|
|
|
209
129
|
releaseLock();
|
|
210
130
|
}
|
|
211
131
|
}
|
|
212
|
-
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Prepare to discard this controller.
|
|
136
|
+
*
|
|
137
|
+
* This stops any active polling.
|
|
138
|
+
*/
|
|
139
|
+
destroy() {
|
|
140
|
+
super.destroy();
|
|
141
|
+
this.stopAllPolling();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Updates exchange rate for the current currency.
|
|
145
|
+
*
|
|
146
|
+
* @param networkClientId - The network client ID used to get a ticker value.
|
|
147
|
+
* @returns The controller state.
|
|
148
|
+
*/
|
|
149
|
+
_executePoll(networkClientId) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
|
152
|
+
yield this.updateExchangeRate(networkClient.configuration.ticker);
|
|
213
153
|
});
|
|
214
154
|
}
|
|
215
155
|
}
|
|
216
156
|
exports.CurrencyRateController = CurrencyRateController;
|
|
217
|
-
_CurrencyRateController_enabled = new WeakMap();
|
|
218
157
|
exports.default = CurrencyRateController;
|
|
219
158
|
//# sourceMappingURL=CurrencyRateController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyRateController.js","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,+DAA6D;AAC7D,iEAIoC;AACpC,6CAAoC;AAGpC,qDAAiF;AAsBjF,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAoBtC,MAAM,QAAQ,GAAG;IACf,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAClD,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;I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pC;aACF;YAAC,OAAO,KAAK,EAAE;gBACd,IACE,CAAC,CACC,KAAK,YAAY,KAAK;oBACtB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,0CAA0C,CAAC,CACnE,EACD;oBACA,MAAM,KAAK,CAAC;iBACb;aACF;oBAAS;gBACR,IAAI;oBACF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;wBACf,OAAO;4BACL,cAAc;4BACd,cAAc;4BACd,0EAA0E;4BAC1E,oFAAoF;4BACpF,uFAAuF;4BACvF,cAAc;4BACd,eAAe;4BACf,sBAAsB,EAAE,IAAI;4BAC5B,qBAAqB,EAAE,IAAI;4BAC3B,iBAAiB;yBAClB,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACJ;wBAAS;oBACR,WAAW,EAAE,CAAC;iBACf;aACF;YACD,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;KAAA;CACF;AAnND,wDAmNC;;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 } from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { Mutex } from 'async-mutex';\nimport type { Patch } from 'immer';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare';\n\n/**\n * @type CurrencyRateState\n * @property conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property nativeCurrency - Symbol for the base asset used for conversion\n * @property pendingCurrentCurrency - The currency being switched to\n * @property pendingNativeCurrency - The base asset currency being switched to\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n conversionDate: number | null;\n conversionRate: number | null;\n currentCurrency: string;\n nativeCurrency: string;\n pendingCurrentCurrency: string | null;\n pendingNativeCurrency: string | null;\n usdConversionRate: number | null;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = {\n type: `${typeof name}:stateChange`;\n payload: [CurrencyRateState, Patch[]];\n};\n\nexport type GetCurrencyRateState = {\n type: `${typeof name}:getState`;\n handler: () => CurrencyRateState;\n};\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n GetCurrencyRateState,\n CurrencyRateStateChange,\n never,\n never\n>;\n\nconst metadata = {\n conversionDate: { persist: true, anonymous: true },\n conversionRate: { persist: true, anonymous: true },\n currentCurrency: { persist: true, anonymous: true },\n nativeCurrency: { persist: true, anonymous: true },\n pendingCurrentCurrency: { persist: false, anonymous: true },\n pendingNativeCurrency: { persist: false, anonymous: true },\n usdConversionRate: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n conversionDate: 0,\n conversionRate: 0,\n currentCurrency: 'usd',\n nativeCurrency: 'ETH',\n pendingCurrentCurrency: null,\n pendingNativeCurrency: null,\n usdConversionRate: null,\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 BaseControllerV2<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private intervalId?: ReturnType<typeof setTimeout>;\n\n private readonly intervalDelay;\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * A boolean that controls whether or not network requests can be made by the controller\n */\n #enabled;\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.intervalDelay = interval;\n this.fetchExchangeRate = fetchExchangeRate;\n this.#enabled = false;\n }\n\n /**\n * Start polling for the currency rate.\n */\n async start() {\n this.#enabled = true;\n\n await this.startPolling();\n }\n\n /**\n * Stop polling for the currency rate.\n */\n stop() {\n this.#enabled = false;\n\n this.stopPolling();\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.stopPolling();\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n this.update((state) => {\n state.pendingCurrentCurrency = currentCurrency;\n });\n await this.updateExchangeRate();\n }\n\n /**\n * Sets a new native currency.\n *\n * @param symbol - Symbol for the base asset.\n */\n async setNativeCurrency(symbol: string) {\n this.update((state) => {\n state.pendingNativeCurrency = symbol;\n });\n await this.updateExchangeRate();\n }\n\n private stopPolling() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n }\n\n /**\n * Starts a new polling interval.\n */\n private async startPolling(): Promise<void> {\n this.stopPolling();\n // TODO: Expose polling currency rate update errors\n\n await safelyExecute(async () => await this.updateExchangeRate());\n\n this.intervalId = setInterval(async () => {\n await safelyExecute(async () => await this.updateExchangeRate());\n }, this.intervalDelay);\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @returns The controller state.\n */\n async updateExchangeRate(): Promise<CurrencyRateState | void> {\n if (!this.#enabled) {\n console.info(\n '[CurrencyRateController] Not updating exchange rate since network requests have been disabled',\n );\n return this.state;\n }\n const releaseLock = await this.mutex.acquire();\n const {\n currentCurrency: stateCurrentCurrency,\n nativeCurrency: stateNativeCurrency,\n pendingCurrentCurrency,\n pendingNativeCurrency,\n } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n const currentCurrency = pendingCurrentCurrency ?? stateCurrentCurrency;\n const nativeCurrency = pendingNativeCurrency ?? stateNativeCurrency;\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\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 conversionDate,\n conversionRate,\n // we currently allow and handle an empty string as a valid nativeCurrency\n // in cases where a user has not entered a native ticker symbol for a custom network\n // currentCurrency is not from user input but this protects us from unexpected changes.\n nativeCurrency,\n currentCurrency,\n pendingCurrentCurrency: null,\n pendingNativeCurrency: null,\n usdConversionRate,\n };\n });\n } finally {\n releaseLock();\n }\n }\n return this.state;\n }\n}\n\nexport default CurrencyRateController;\n"]}
|
|
1
|
+
{"version":3,"file":"CurrencyRateController.js","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iEAGoC;AAKpC,qEAAiE;AACjE,6CAAoC;AAGpC,qDAAiF;AAsBjF,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAwBtC,MAAM,QAA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,EAAE;wBACf,OAAO;4BACL,aAAa,kCACR,aAAa,KAChB,CAAC,cAAc,CAAC,EAAE;oCAChB,cAAc;oCACd,cAAc;oCACd,iBAAiB;iCAClB,GACF;4BACD,eAAe;yBAChB,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACJ;wBAAS;oBACR,WAAW,EAAE,CAAC;iBACf;aACF;QACH,CAAC;KAAA;IAED;;;;OAIG;IACM,OAAO;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACG,YAAY,CAAC,eAAgC;;YACjD,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,wCAAwC,EACxC,eAAe,CAChB,CAAC;YACF,MAAM,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACpE,CAAC;KAAA;CACF;AA9JD,wDA8JC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { RestrictedControllerMessenger } 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 { PollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\nimport type { Patch } from 'immer';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare';\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 = {\n type: `${typeof name}:stateChange`;\n payload: [CurrencyRateState, Patch[]];\n};\n\nexport type GetCurrencyRateState = {\n type: `${typeof name}:getState`;\n handler: () => CurrencyRateState;\n};\n\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | GetCurrencyRateState;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n AllowedActions,\n CurrencyRateStateChange,\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 PollingController<\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NftController.d.ts","sourceRoot":"","sources":["../src/NftController.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAa3D,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,YAAY,EACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAEV,aAAa,EAEb,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,aAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5C,aAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW,CAAC;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb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QAAQ,EAAE,OAAO;IAuB3E;;;;;;;;OAQG;IACH,0BAA0B,CACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAgBrC;;;;;;;OAOG;IACH,SAAS,CACP,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG;IA6Bd;;;;;;;OAOG;IACH,wCAAwC,CACtC,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX,OAAO;IAyBJ,gBAAgB,CAAC,gBAAgB,EAAE,gBAAgB;CAuB1D;AAED,eAAe,aAAa,CAAC"}
|
package/dist/NftController.js
CHANGED
|
@@ -282,16 +282,12 @@ class NftController extends base_controller_1.BaseController {
|
|
|
282
282
|
chainId =
|
|
283
283
|
this.getNetworkClientById(networkClientId).configuration.chainId;
|
|
284
284
|
}
|
|
285
|
-
const blockchainMetadata = yield
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
openSeaMetadata = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
return yield this.getNftInformationFromApi(contractAddress, tokenId);
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
285
|
+
const [blockchainMetadata, openSeaMetadata] = yield Promise.all([
|
|
286
|
+
(0, controller_utils_1.safelyExecute)(() => this.getNftInformationFromTokenURI(contractAddress, tokenId, networkClientId)),
|
|
287
|
+
this.config.openSeaEnabled && chainId === '0x1'
|
|
288
|
+
? (0, controller_utils_1.safelyExecute)(() => this.getNftInformationFromApi(contractAddress, tokenId))
|
|
289
|
+
: undefined,
|
|
290
|
+
]);
|
|
295
291
|
return Object.assign(Object.assign({}, openSeaMetadata), { name: (_b = (_a = blockchainMetadata.name) !== null && _a !== void 0 ? _a : openSeaMetadata === null || openSeaMetadata === void 0 ? void 0 : openSeaMetadata.name) !== null && _b !== void 0 ? _b : null, description: (_d = (_c = blockchainMetadata.description) !== null && _c !== void 0 ? _c : openSeaMetadata === null || openSeaMetadata === void 0 ? void 0 : openSeaMetadata.description) !== null && _d !== void 0 ? _d : null, image: (_f = (_e = blockchainMetadata.image) !== null && _e !== void 0 ? _e : openSeaMetadata === null || openSeaMetadata === void 0 ? void 0 : openSeaMetadata.image) !== null && _f !== void 0 ? _f : null, standard: (_h = (_g = blockchainMetadata.standard) !== null && _g !== void 0 ? _g : openSeaMetadata === null || openSeaMetadata === void 0 ? void 0 : openSeaMetadata.standard) !== null && _h !== void 0 ? _h : null, tokenURI: (_j = blockchainMetadata.tokenURI) !== null && _j !== void 0 ? _j : null });
|
|
296
292
|
});
|
|
297
293
|
}
|
|
@@ -340,8 +336,10 @@ class NftController extends base_controller_1.BaseController {
|
|
|
340
336
|
*/
|
|
341
337
|
getNftContractInformationFromContract(contractAddress, networkClientId) {
|
|
342
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
|
-
const name = yield
|
|
344
|
-
|
|
339
|
+
const [name, symbol] = yield Promise.all([
|
|
340
|
+
this.getERC721AssetName(contractAddress, networkClientId),
|
|
341
|
+
this.getERC721AssetSymbol(contractAddress, networkClientId),
|
|
342
|
+
]);
|
|
345
343
|
return {
|
|
346
344
|
collection: { name },
|
|
347
345
|
symbol,
|
|
@@ -358,20 +356,17 @@ class NftController extends base_controller_1.BaseController {
|
|
|
358
356
|
*/
|
|
359
357
|
getNftContractInformation(contractAddress, networkClientId) {
|
|
360
358
|
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
-
const blockchainContractData = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
|
|
362
|
-
return yield this.getNftContractInformationFromContract(contractAddress, networkClientId);
|
|
363
|
-
}));
|
|
364
359
|
const { chainId } = this.config;
|
|
365
360
|
const getCurrentChainId = this.getCorrectChainId({
|
|
366
361
|
chainId,
|
|
367
362
|
networkClientId,
|
|
368
363
|
});
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
364
|
+
const [blockchainContractData, openSeaContractData] = yield Promise.all([
|
|
365
|
+
(0, controller_utils_1.safelyExecute)(() => this.getNftContractInformationFromContract(contractAddress, networkClientId)),
|
|
366
|
+
this.config.openSeaEnabled && getCurrentChainId === '0x1'
|
|
367
|
+
? (0, controller_utils_1.safelyExecute)(() => this.getNftContractInformationFromApi(contractAddress))
|
|
368
|
+
: undefined,
|
|
369
|
+
]);
|
|
375
370
|
if (blockchainContractData || openSeaContractData) {
|
|
376
371
|
return Object.assign(Object.assign(Object.assign({}, openSeaContractData), blockchainContractData), { collection: Object.assign(Object.assign({ image_url: null }, openSeaContractData === null || openSeaContractData === void 0 ? void 0 : openSeaContractData.collection), blockchainContractData === null || blockchainContractData === void 0 ? void 0 : blockchainContractData.collection) });
|
|
377
372
|
}
|