@metamask/assets-controllers 29.0.0 → 31.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 +105 -1
- package/README.md +29 -0
- package/dist/AccountTrackerController.js +2 -2
- package/dist/AccountTrackerController.mjs +1 -1
- package/dist/AssetsContractController.js +6 -6
- package/dist/AssetsContractController.mjs +5 -5
- package/dist/CurrencyRateController.js +4 -3
- package/dist/CurrencyRateController.mjs +3 -2
- package/dist/NftController.js +3 -3
- package/dist/NftController.mjs +4 -4
- package/dist/NftDetectionController.js +2 -2
- package/dist/NftDetectionController.mjs +1 -1
- package/dist/RatesController/RatesController.js +14 -0
- package/dist/RatesController/RatesController.mjs +14 -0
- package/dist/RatesController/index.js +13 -0
- package/dist/RatesController/index.js.map +1 -0
- package/dist/RatesController/index.mjs +13 -0
- package/dist/RatesController/index.mjs.map +1 -0
- package/dist/RatesController/types.js +1 -0
- package/dist/RatesController/types.js.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -0
- package/dist/Standards/ERC20Standard.js +3 -3
- package/dist/Standards/ERC20Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +2 -2
- package/dist/TokenBalancesController.js +2 -2
- package/dist/TokenBalancesController.mjs +1 -1
- package/dist/TokenDetectionController.js +3 -3
- package/dist/TokenDetectionController.mjs +2 -2
- package/dist/TokenListController.js +4 -4
- package/dist/TokenListController.mjs +3 -3
- package/dist/TokenRatesController.js +6 -4
- package/dist/TokenRatesController.mjs +5 -3
- package/dist/TokensController.js +6 -6
- package/dist/TokensController.mjs +5 -5
- package/dist/assetsUtil.js +2 -2
- package/dist/assetsUtil.mjs +1 -1
- package/dist/chunk-4AC3X2U5.js +771 -0
- package/dist/chunk-4AC3X2U5.js.map +1 -0
- package/dist/chunk-543CC74T.mjs +253 -0
- package/dist/chunk-543CC74T.mjs.map +1 -0
- package/dist/{chunk-NXGX7LZJ.mjs → chunk-5W5OO2Q5.mjs} +17 -6
- package/dist/chunk-5W5OO2Q5.mjs.map +1 -0
- package/dist/chunk-62T7RKU3.mjs +1265 -0
- package/dist/chunk-62T7RKU3.mjs.map +1 -0
- package/dist/{chunk-PAJTKWEC.mjs → chunk-65PB33TE.mjs} +1 -1
- package/dist/chunk-65PB33TE.mjs.map +1 -0
- package/dist/{chunk-6XOM7KOQ.mjs → chunk-73F3SN5O.mjs} +337 -270
- package/dist/chunk-73F3SN5O.mjs.map +1 -0
- package/dist/chunk-7K6PSEAA.js +1 -0
- package/dist/chunk-7K6PSEAA.js.map +1 -0
- package/dist/{chunk-RUE635TV.mjs → chunk-A2DDWXMS.mjs} +3 -3
- package/dist/{chunk-V46CHMOU.mjs → chunk-ASA5RLBY.mjs} +2 -2
- package/dist/chunk-B5YVX5IO.mjs +202 -0
- package/dist/chunk-B5YVX5IO.mjs.map +1 -0
- package/dist/{chunk-BO2WZDUM.js → chunk-B5YY22QQ.js} +3 -3
- package/dist/{chunk-QWACHXRH.mjs → chunk-B6W4CQOR.mjs} +2 -2
- package/dist/chunk-B6W4CQOR.mjs.map +1 -0
- package/dist/{chunk-3ZHN4GFT.js → chunk-BOTVAG4A.js} +5 -5
- package/dist/chunk-CGLUTXI7.js +1265 -0
- package/dist/chunk-CGLUTXI7.js.map +1 -0
- package/dist/chunk-CNKVITJO.mjs +66 -0
- package/dist/chunk-CNKVITJO.mjs.map +1 -0
- package/dist/{chunk-LLYYJY7H.mjs → chunk-D3K5MPMW.mjs} +2 -2
- package/dist/{chunk-OWTCG2N3.mjs → chunk-E4ECCGJV.mjs} +53 -39
- package/dist/chunk-E4ECCGJV.mjs.map +1 -0
- package/dist/{chunk-LRKDZWS6.js → chunk-ELSMS5S7.js} +3 -3
- package/dist/chunk-ELSMS5S7.js.map +1 -0
- package/dist/{chunk-V4ZO3F2S.js → chunk-GU53EI7A.js} +1 -1
- package/dist/chunk-GU53EI7A.js.map +1 -0
- package/dist/{chunk-I53XGBU3.js → chunk-HDI4L2DD.js} +5 -5
- package/dist/{chunk-5MRF7YPD.mjs → chunk-HLCGZGPA.mjs} +6 -6
- package/dist/chunk-HLCGZGPA.mjs.map +1 -0
- package/dist/{chunk-LD4GC7OR.js → chunk-IBK6AXPP.js} +8 -9
- package/dist/chunk-IBK6AXPP.js.map +1 -0
- package/dist/{chunk-DEQZ35QE.js → chunk-JUI3XNEF.js} +7 -7
- package/dist/chunk-JYHAAA6W.mjs +1 -0
- package/dist/chunk-JYHAAA6W.mjs.map +1 -0
- package/dist/{chunk-S7UA2DU7.mjs → chunk-LZ5ZGQEX.mjs} +2 -2
- package/dist/{chunk-D3PCUDTX.mjs → chunk-MR6EF4B7.mjs} +2 -2
- package/dist/{chunk-LS6R3HQL.js → chunk-NEXY7SE2.js} +2 -2
- package/dist/chunk-NEXY7SE2.js.map +1 -0
- package/dist/{chunk-OHSQRYVL.js → chunk-PYMUBJQX.js} +17 -6
- package/dist/chunk-PYMUBJQX.js.map +1 -0
- package/dist/{chunk-X5PLVMOQ.mjs → chunk-Q5JRBGWO.mjs} +2 -2
- package/dist/chunk-Q5JRBGWO.mjs.map +1 -0
- package/dist/chunk-QFDTOEYR.js +253 -0
- package/dist/chunk-QFDTOEYR.js.map +1 -0
- package/dist/{chunk-QHU4H6HP.js → chunk-QHWKLZUC.js} +7 -7
- package/dist/chunk-QHWKLZUC.js.map +1 -0
- package/dist/chunk-TTH3ES66.mjs +1 -0
- package/dist/chunk-TTH3ES66.mjs.map +1 -0
- package/dist/{chunk-OBOWNEJU.js → chunk-U3DJJN4X.js} +4 -4
- package/dist/{chunk-IOQX3VTD.js → chunk-UEDNQBJN.js} +56 -42
- package/dist/chunk-UEDNQBJN.js.map +1 -0
- package/dist/chunk-WB6KJX4N.js +66 -0
- package/dist/chunk-WB6KJX4N.js.map +1 -0
- package/dist/{chunk-4LY47RPI.mjs → chunk-WCCLSUOI.mjs} +8 -9
- package/dist/{chunk-4LY47RPI.mjs.map → chunk-WCCLSUOI.mjs.map} +1 -1
- package/dist/chunk-XC3SOOGC.js +1 -0
- package/dist/chunk-XC3SOOGC.js.map +1 -0
- package/dist/{chunk-OSEZFHQ3.mjs → chunk-Y35SM7TO.mjs} +19 -14
- package/dist/chunk-Y35SM7TO.mjs.map +1 -0
- package/dist/chunk-YIFA2HXH.js +202 -0
- package/dist/chunk-YIFA2HXH.js.map +1 -0
- package/dist/{chunk-4FMVFW2T.js → chunk-Z6TBQQE5.js} +20 -15
- package/dist/chunk-Z6TBQQE5.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.js +10 -0
- package/dist/crypto-compare-service/crypto-compare.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +10 -0
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -0
- package/dist/crypto-compare-service/index.js +11 -0
- package/dist/crypto-compare-service/index.js.map +1 -0
- package/dist/crypto-compare-service/index.mjs +11 -0
- package/dist/crypto-compare-service/index.mjs.map +1 -0
- package/dist/index.js +24 -18
- package/dist/index.mjs +29 -23
- package/dist/token-prices-service/codefi-v2.js +4 -2
- package/dist/token-prices-service/codefi-v2.mjs +5 -3
- package/dist/token-prices-service/index.js +2 -2
- package/dist/token-prices-service/index.mjs +1 -1
- package/dist/token-service.js +3 -3
- package/dist/token-service.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/AccountTrackerController.d.ts +1 -1
- package/dist/types/AccountTrackerController.d.ts.map +1 -1
- package/dist/types/AssetsContractController.d.ts +1 -1
- package/dist/types/AssetsContractController.d.ts.map +1 -1
- package/dist/types/CurrencyRateController.d.ts +1 -1
- package/dist/types/CurrencyRateController.d.ts.map +1 -1
- package/dist/types/NftController.d.ts +65 -184
- package/dist/types/NftController.d.ts.map +1 -1
- package/dist/types/NftDetectionController.d.ts +34 -75
- package/dist/types/NftDetectionController.d.ts.map +1 -1
- package/dist/types/RatesController/RatesController.d.ts +44 -0
- package/dist/types/RatesController/RatesController.d.ts.map +1 -0
- package/dist/types/RatesController/index.d.ts +3 -0
- package/dist/types/RatesController/index.d.ts.map +1 -0
- package/dist/types/RatesController/types.d.ts +100 -0
- package/dist/types/RatesController/types.d.ts.map +1 -0
- package/dist/types/TokenRatesController.d.ts +32 -10
- package/dist/types/TokenRatesController.d.ts.map +1 -1
- package/dist/types/TokensController.d.ts +27 -131
- package/dist/types/TokensController.d.ts.map +1 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts +22 -0
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +1 -0
- package/dist/types/crypto-compare-service/index.d.ts +2 -0
- package/dist/types/crypto-compare-service/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts +18 -0
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts +7 -0
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -1
- package/dist/types/token-service.d.ts +1 -1
- package/dist/types/token-service.d.ts.map +1 -1
- package/package.json +14 -14
- package/dist/chunk-4FMVFW2T.js.map +0 -1
- package/dist/chunk-5MRF7YPD.mjs.map +0 -1
- package/dist/chunk-6XOM7KOQ.mjs.map +0 -1
- package/dist/chunk-ASFD56OL.mjs +0 -235
- package/dist/chunk-ASFD56OL.mjs.map +0 -1
- package/dist/chunk-DYH5P3VY.js +0 -35
- package/dist/chunk-DYH5P3VY.js.map +0 -1
- package/dist/chunk-IOQX3VTD.js.map +0 -1
- package/dist/chunk-KM3J4DO6.js +0 -1182
- package/dist/chunk-KM3J4DO6.js.map +0 -1
- package/dist/chunk-LD4GC7OR.js.map +0 -1
- package/dist/chunk-LRKDZWS6.js.map +0 -1
- package/dist/chunk-LS6R3HQL.js.map +0 -1
- package/dist/chunk-NXGX7LZJ.mjs.map +0 -1
- package/dist/chunk-OHSQRYVL.js.map +0 -1
- package/dist/chunk-OSEZFHQ3.mjs.map +0 -1
- package/dist/chunk-OWTCG2N3.mjs.map +0 -1
- package/dist/chunk-PAJTKWEC.mjs.map +0 -1
- package/dist/chunk-PWZE6KJV.mjs +0 -35
- package/dist/chunk-PWZE6KJV.mjs.map +0 -1
- package/dist/chunk-QHU4H6HP.js.map +0 -1
- package/dist/chunk-QWACHXRH.mjs.map +0 -1
- package/dist/chunk-S6CZP74C.mjs +0 -1182
- package/dist/chunk-S6CZP74C.mjs.map +0 -1
- package/dist/chunk-SOK5YX7I.js +0 -704
- package/dist/chunk-SOK5YX7I.js.map +0 -1
- package/dist/chunk-V4ZO3F2S.js.map +0 -1
- package/dist/chunk-X2MMIBYW.js +0 -235
- package/dist/chunk-X2MMIBYW.js.map +0 -1
- package/dist/chunk-X5PLVMOQ.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 +0 -13
- package/dist/types/crypto-compare.d.ts.map +0 -1
- /package/dist/{crypto-compare.js.map → RatesController/RatesController.js.map} +0 -0
- /package/dist/{crypto-compare.mjs.map → RatesController/RatesController.mjs.map} +0 -0
- /package/dist/{chunk-RUE635TV.mjs.map → chunk-A2DDWXMS.mjs.map} +0 -0
- /package/dist/{chunk-V46CHMOU.mjs.map → chunk-ASA5RLBY.mjs.map} +0 -0
- /package/dist/{chunk-BO2WZDUM.js.map → chunk-B5YY22QQ.js.map} +0 -0
- /package/dist/{chunk-3ZHN4GFT.js.map → chunk-BOTVAG4A.js.map} +0 -0
- /package/dist/{chunk-LLYYJY7H.mjs.map → chunk-D3K5MPMW.mjs.map} +0 -0
- /package/dist/{chunk-I53XGBU3.js.map → chunk-HDI4L2DD.js.map} +0 -0
- /package/dist/{chunk-DEQZ35QE.js.map → chunk-JUI3XNEF.js.map} +0 -0
- /package/dist/{chunk-S7UA2DU7.mjs.map → chunk-LZ5ZGQEX.mjs.map} +0 -0
- /package/dist/{chunk-D3PCUDTX.mjs.map → chunk-MR6EF4B7.mjs.map} +0 -0
- /package/dist/{chunk-OBOWNEJU.js.map → chunk-U3DJJN4X.js.map} +0 -0
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ERC1155Standard
|
|
3
|
-
} from "./chunk-S7UA2DU7.mjs";
|
|
4
1
|
import {
|
|
5
2
|
ERC20Standard
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-D3K5MPMW.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ERC1155Standard
|
|
6
|
+
} from "./chunk-LZ5ZGQEX.mjs";
|
|
7
7
|
import {
|
|
8
8
|
TOKEN_METADATA_NO_SUPPORT_ERROR,
|
|
9
9
|
fetchTokenMetadata
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5W5OO2Q5.mjs";
|
|
11
11
|
import {
|
|
12
12
|
formatAggregatorNames,
|
|
13
13
|
formatIconUrlWithProxy
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-Q5JRBGWO.mjs";
|
|
15
|
+
import {
|
|
16
|
+
__privateAdd,
|
|
17
|
+
__privateGet,
|
|
18
|
+
__privateMethod,
|
|
19
|
+
__privateSet
|
|
20
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
15
21
|
|
|
16
22
|
// src/TokensController.ts
|
|
17
23
|
import { Contract } from "@ethersproject/contracts";
|
|
18
24
|
import { Web3Provider } from "@ethersproject/providers";
|
|
19
|
-
import {
|
|
25
|
+
import { BaseController } from "@metamask/base-controller";
|
|
20
26
|
import contractsMap from "@metamask/contract-metadata";
|
|
21
27
|
import {
|
|
22
28
|
toChecksumHexAddress,
|
|
@@ -32,8 +38,33 @@ import {
|
|
|
32
38
|
import { abiERC721 } from "@metamask/metamask-eth-abis";
|
|
33
39
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
34
40
|
import { Mutex } from "async-mutex";
|
|
35
|
-
import { EventEmitter } from "events";
|
|
36
41
|
import { v1 as random } from "uuid";
|
|
42
|
+
var metadata = {
|
|
43
|
+
tokens: {
|
|
44
|
+
persist: true,
|
|
45
|
+
anonymous: false
|
|
46
|
+
},
|
|
47
|
+
ignoredTokens: {
|
|
48
|
+
persist: true,
|
|
49
|
+
anonymous: false
|
|
50
|
+
},
|
|
51
|
+
detectedTokens: {
|
|
52
|
+
persist: true,
|
|
53
|
+
anonymous: false
|
|
54
|
+
},
|
|
55
|
+
allTokens: {
|
|
56
|
+
persist: true,
|
|
57
|
+
anonymous: false
|
|
58
|
+
},
|
|
59
|
+
allIgnoredTokens: {
|
|
60
|
+
persist: true,
|
|
61
|
+
anonymous: false
|
|
62
|
+
},
|
|
63
|
+
allDetectedTokens: {
|
|
64
|
+
persist: true,
|
|
65
|
+
anonymous: false
|
|
66
|
+
}
|
|
67
|
+
};
|
|
37
68
|
var controllerName = "TokensController";
|
|
38
69
|
var getDefaultTokensState = () => {
|
|
39
70
|
return {
|
|
@@ -45,109 +76,117 @@ var getDefaultTokensState = () => {
|
|
|
45
76
|
allDetectedTokens: {}
|
|
46
77
|
};
|
|
47
78
|
};
|
|
48
|
-
var
|
|
79
|
+
var _mutex, _chainId, _selectedAddress, _provider, _abortController, _onNetworkDidChange, onNetworkDidChange_fn, _onPreferenceControllerStateChange, onPreferenceControllerStateChange_fn, _fetchTokenMetadata, fetchTokenMetadata_fn, _updateTokensAttribute, updateTokensAttribute_fn, _detectIsERC721, detectIsERC721_fn, _getProvider, getProvider_fn, _createEthersContract, createEthersContract_fn, _generateRandomId, generateRandomId_fn, _getNewAllTokensState, getNewAllTokensState_fn, _requestApproval, requestApproval_fn;
|
|
80
|
+
var TokensController = class extends BaseController {
|
|
49
81
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @param options - The controller options.
|
|
82
|
+
* Tokens controller options
|
|
83
|
+
* @param options - Constructor options.
|
|
53
84
|
* @param options.chainId - The chain ID of the current network.
|
|
54
|
-
* @param options.
|
|
85
|
+
* @param options.selectedAddress - Vault selected address
|
|
86
|
+
* @param options.provider - Network provider.
|
|
55
87
|
* @param options.state - Initial state to set on this controller.
|
|
56
88
|
* @param options.messenger - The controller messenger.
|
|
57
89
|
*/
|
|
58
90
|
constructor({
|
|
59
91
|
chainId: initialChainId,
|
|
60
|
-
|
|
92
|
+
selectedAddress,
|
|
93
|
+
provider,
|
|
61
94
|
state,
|
|
62
95
|
messenger
|
|
63
96
|
}) {
|
|
64
|
-
super(
|
|
65
|
-
|
|
97
|
+
super({
|
|
98
|
+
name: controllerName,
|
|
99
|
+
metadata,
|
|
100
|
+
messenger,
|
|
101
|
+
state: {
|
|
102
|
+
...getDefaultTokensState(),
|
|
103
|
+
...state
|
|
104
|
+
}
|
|
105
|
+
});
|
|
66
106
|
/**
|
|
67
|
-
*
|
|
107
|
+
* Handles the event when the network changes.
|
|
108
|
+
*
|
|
109
|
+
* @param networkState - The changed network state.
|
|
110
|
+
* @param networkState.providerConfig - RPC URL and network name provider settings of the currently connected network
|
|
68
111
|
*/
|
|
69
|
-
this
|
|
112
|
+
__privateAdd(this, _onNetworkDidChange);
|
|
70
113
|
/**
|
|
71
|
-
*
|
|
114
|
+
* Handles the state change of the preference controller.
|
|
115
|
+
* @param preferencesState - The new state of the preference controller.
|
|
116
|
+
* @param preferencesState.selectedAddress - The current selected address of the preference controller.
|
|
72
117
|
*/
|
|
73
|
-
this
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
118
|
+
__privateAdd(this, _onPreferenceControllerStateChange);
|
|
119
|
+
/**
|
|
120
|
+
* Fetch metadata for a token.
|
|
121
|
+
*
|
|
122
|
+
* @param tokenAddress - The address of the token.
|
|
123
|
+
* @returns The token metadata.
|
|
124
|
+
*/
|
|
125
|
+
__privateAdd(this, _fetchTokenMetadata);
|
|
126
|
+
/**
|
|
127
|
+
* This is a function that updates the tokens name for the tokens name if it is not defined.
|
|
128
|
+
*
|
|
129
|
+
* @param tokenList - Represents the fetched token list from service API
|
|
130
|
+
* @param tokenAttribute - Represents the token attribute that we want to update on the token list
|
|
131
|
+
*/
|
|
132
|
+
__privateAdd(this, _updateTokensAttribute);
|
|
133
|
+
/**
|
|
134
|
+
* Detects whether or not a token is ERC-721 compatible.
|
|
135
|
+
*
|
|
136
|
+
* @param tokenAddress - The token contract address.
|
|
137
|
+
* @param networkClientId - Optional network client ID to fetch contract info with.
|
|
138
|
+
* @returns A boolean indicating whether the token address passed in supports the EIP-721
|
|
139
|
+
* interface.
|
|
140
|
+
*/
|
|
141
|
+
__privateAdd(this, _detectIsERC721);
|
|
142
|
+
__privateAdd(this, _getProvider);
|
|
143
|
+
__privateAdd(this, _createEthersContract);
|
|
144
|
+
__privateAdd(this, _generateRandomId);
|
|
145
|
+
/**
|
|
146
|
+
* Takes a new tokens and ignoredTokens array for the current network/account combination
|
|
147
|
+
* and returns new allTokens and allIgnoredTokens state to update to.
|
|
148
|
+
*
|
|
149
|
+
* @param params - Object that holds token params.
|
|
150
|
+
* @param params.newTokens - The new tokens to set for the current network and selected account.
|
|
151
|
+
* @param params.newIgnoredTokens - The new ignored tokens to set for the current network and selected account.
|
|
152
|
+
* @param params.newDetectedTokens - The new detected tokens to set for the current network and selected account.
|
|
153
|
+
* @param params.interactingAddress - The account address to use to store the tokens.
|
|
154
|
+
* @param params.interactingChainId - The chainId to use to store the tokens.
|
|
155
|
+
* @returns The updated `allTokens` and `allIgnoredTokens` state.
|
|
156
|
+
*/
|
|
157
|
+
__privateAdd(this, _getNewAllTokensState);
|
|
158
|
+
__privateAdd(this, _requestApproval);
|
|
159
|
+
__privateAdd(this, _mutex, new Mutex());
|
|
160
|
+
__privateAdd(this, _chainId, void 0);
|
|
161
|
+
__privateAdd(this, _selectedAddress, void 0);
|
|
162
|
+
__privateAdd(this, _provider, void 0);
|
|
163
|
+
__privateAdd(this, _abortController, void 0);
|
|
164
|
+
__privateSet(this, _chainId, initialChainId);
|
|
165
|
+
__privateSet(this, _provider, provider);
|
|
166
|
+
__privateSet(this, _selectedAddress, selectedAddress);
|
|
167
|
+
__privateSet(this, _abortController, new AbortController());
|
|
87
168
|
this.messagingSystem.registerActionHandler(
|
|
88
169
|
`${controllerName}:addDetectedTokens`,
|
|
89
170
|
this.addDetectedTokens.bind(this)
|
|
90
171
|
);
|
|
91
172
|
this.messagingSystem.subscribe(
|
|
92
173
|
"PreferencesController:stateChange",
|
|
93
|
-
(
|
|
94
|
-
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
95
|
-
const { chainId } = this.config;
|
|
96
|
-
this.configure({ selectedAddress });
|
|
97
|
-
this.update({
|
|
98
|
-
tokens: allTokens[chainId]?.[selectedAddress] ?? [],
|
|
99
|
-
ignoredTokens: allIgnoredTokens[chainId]?.[selectedAddress] ?? [],
|
|
100
|
-
detectedTokens: allDetectedTokens[chainId]?.[selectedAddress] ?? []
|
|
101
|
-
});
|
|
102
|
-
}
|
|
174
|
+
__privateMethod(this, _onPreferenceControllerStateChange, onPreferenceControllerStateChange_fn).bind(this)
|
|
103
175
|
);
|
|
104
176
|
this.messagingSystem.subscribe(
|
|
105
177
|
"NetworkController:networkDidChange",
|
|
106
|
-
(
|
|
107
|
-
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
108
|
-
const { selectedAddress } = this.config;
|
|
109
|
-
const { chainId } = providerConfig;
|
|
110
|
-
this.abortController.abort();
|
|
111
|
-
this.abortController = new AbortController();
|
|
112
|
-
this.configure({ chainId });
|
|
113
|
-
this.update({
|
|
114
|
-
tokens: allTokens[chainId]?.[selectedAddress] || [],
|
|
115
|
-
ignoredTokens: allIgnoredTokens[chainId]?.[selectedAddress] || [],
|
|
116
|
-
detectedTokens: allDetectedTokens[chainId]?.[selectedAddress] || []
|
|
117
|
-
});
|
|
118
|
-
}
|
|
178
|
+
__privateMethod(this, _onNetworkDidChange, onNetworkDidChange_fn).bind(this)
|
|
119
179
|
);
|
|
120
180
|
this.messagingSystem.subscribe(
|
|
121
181
|
"TokenListController:stateChange",
|
|
122
182
|
({ tokenList }) => {
|
|
123
183
|
const { tokens } = this.state;
|
|
124
184
|
if (tokens.length && !tokens[0].name) {
|
|
125
|
-
this.
|
|
185
|
+
__privateMethod(this, _updateTokensAttribute, updateTokensAttribute_fn).call(this, tokenList, "name");
|
|
126
186
|
}
|
|
127
187
|
}
|
|
128
188
|
);
|
|
129
189
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Fetch metadata for a token.
|
|
132
|
-
*
|
|
133
|
-
* @param tokenAddress - The address of the token.
|
|
134
|
-
* @returns The token metadata.
|
|
135
|
-
*/
|
|
136
|
-
async fetchTokenMetadata(tokenAddress) {
|
|
137
|
-
try {
|
|
138
|
-
const token = await fetchTokenMetadata(
|
|
139
|
-
this.config.chainId,
|
|
140
|
-
tokenAddress,
|
|
141
|
-
this.abortController.signal
|
|
142
|
-
);
|
|
143
|
-
return token;
|
|
144
|
-
} catch (error) {
|
|
145
|
-
if (error instanceof Error && error.message.includes(TOKEN_METADATA_NO_SUPPORT_ERROR)) {
|
|
146
|
-
return void 0;
|
|
147
|
-
}
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
190
|
/**
|
|
152
191
|
* Adds a token to the stored token list.
|
|
153
192
|
*
|
|
@@ -170,8 +209,9 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
170
209
|
interactingAddress,
|
|
171
210
|
networkClientId
|
|
172
211
|
}) {
|
|
173
|
-
const
|
|
174
|
-
const
|
|
212
|
+
const chainId = __privateGet(this, _chainId);
|
|
213
|
+
const selectedAddress = __privateGet(this, _selectedAddress);
|
|
214
|
+
const releaseLock = await __privateGet(this, _mutex).acquire();
|
|
175
215
|
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
176
216
|
let currentChainId = chainId;
|
|
177
217
|
if (networkClientId) {
|
|
@@ -189,11 +229,11 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
189
229
|
const detectedTokens = allDetectedTokens[currentChainId]?.[accountAddress] || [];
|
|
190
230
|
const newTokens = [...tokens];
|
|
191
231
|
const [isERC721, tokenMetadata] = await Promise.all([
|
|
192
|
-
this.
|
|
232
|
+
__privateMethod(this, _detectIsERC721, detectIsERC721_fn).call(this, address, networkClientId),
|
|
193
233
|
// TODO parameterize the token metadata fetch by networkClientId
|
|
194
|
-
this.
|
|
234
|
+
__privateMethod(this, _fetchTokenMetadata, fetchTokenMetadata_fn).call(this, address)
|
|
195
235
|
]);
|
|
196
|
-
if (!networkClientId && currentChainId !== this
|
|
236
|
+
if (!networkClientId && currentChainId !== __privateGet(this, _chainId)) {
|
|
197
237
|
throw new Error(
|
|
198
238
|
"TokensController Error: Switched networks while adding token"
|
|
199
239
|
);
|
|
@@ -224,7 +264,7 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
224
264
|
const newDetectedTokens = detectedTokens.filter(
|
|
225
265
|
(token) => token.address.toLowerCase() !== address.toLowerCase()
|
|
226
266
|
);
|
|
227
|
-
const { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens } = this.
|
|
267
|
+
const { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens } = __privateMethod(this, _getNewAllTokensState, getNewAllTokensState_fn).call(this, {
|
|
228
268
|
newTokens,
|
|
229
269
|
newIgnoredTokens,
|
|
230
270
|
newDetectedTokens,
|
|
@@ -244,7 +284,9 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
244
284
|
detectedTokens: newDetectedTokens
|
|
245
285
|
};
|
|
246
286
|
}
|
|
247
|
-
this.update(
|
|
287
|
+
this.update((state) => {
|
|
288
|
+
Object.assign(state, newState);
|
|
289
|
+
});
|
|
248
290
|
return newTokens;
|
|
249
291
|
} finally {
|
|
250
292
|
releaseLock();
|
|
@@ -257,7 +299,7 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
257
299
|
* @param networkClientId - Optional network client ID used to determine interacting chain ID.
|
|
258
300
|
*/
|
|
259
301
|
async addTokens(tokensToImport, networkClientId) {
|
|
260
|
-
const releaseLock = await this.
|
|
302
|
+
const releaseLock = await __privateGet(this, _mutex).acquire();
|
|
261
303
|
const { tokens, detectedTokens, ignoredTokens } = this.state;
|
|
262
304
|
const importedTokensMap = {};
|
|
263
305
|
const newTokensMap = tokens.reduce((output, current) => {
|
|
@@ -294,19 +336,19 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
294
336
|
networkClientId
|
|
295
337
|
).configuration.chainId;
|
|
296
338
|
}
|
|
297
|
-
const { newAllTokens, newAllDetectedTokens, newAllIgnoredTokens } = this.
|
|
339
|
+
const { newAllTokens, newAllDetectedTokens, newAllIgnoredTokens } = __privateMethod(this, _getNewAllTokensState, getNewAllTokensState_fn).call(this, {
|
|
298
340
|
newTokens,
|
|
299
341
|
newDetectedTokens,
|
|
300
342
|
newIgnoredTokens,
|
|
301
343
|
interactingChainId
|
|
302
344
|
});
|
|
303
|
-
this.update({
|
|
304
|
-
tokens
|
|
305
|
-
allTokens
|
|
306
|
-
detectedTokens
|
|
307
|
-
allDetectedTokens
|
|
308
|
-
ignoredTokens
|
|
309
|
-
allIgnoredTokens
|
|
345
|
+
this.update((state) => {
|
|
346
|
+
state.tokens = newTokens;
|
|
347
|
+
state.allTokens = newAllTokens;
|
|
348
|
+
state.detectedTokens = newDetectedTokens;
|
|
349
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
350
|
+
state.ignoredTokens = newIgnoredTokens;
|
|
351
|
+
state.allIgnoredTokens = newAllIgnoredTokens;
|
|
310
352
|
});
|
|
311
353
|
} finally {
|
|
312
354
|
releaseLock();
|
|
@@ -333,18 +375,18 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
333
375
|
const newTokens = tokens.filter(
|
|
334
376
|
(token) => !ignoredTokensMap[token.address.toLowerCase()]
|
|
335
377
|
);
|
|
336
|
-
const { newAllIgnoredTokens, newAllDetectedTokens, newAllTokens } = this.
|
|
378
|
+
const { newAllIgnoredTokens, newAllDetectedTokens, newAllTokens } = __privateMethod(this, _getNewAllTokensState, getNewAllTokensState_fn).call(this, {
|
|
337
379
|
newIgnoredTokens,
|
|
338
380
|
newDetectedTokens,
|
|
339
381
|
newTokens
|
|
340
382
|
});
|
|
341
|
-
this.update({
|
|
342
|
-
ignoredTokens
|
|
343
|
-
tokens
|
|
344
|
-
detectedTokens
|
|
345
|
-
allIgnoredTokens
|
|
346
|
-
allDetectedTokens
|
|
347
|
-
allTokens
|
|
383
|
+
this.update((state) => {
|
|
384
|
+
state.ignoredTokens = newIgnoredTokens;
|
|
385
|
+
state.tokens = newTokens;
|
|
386
|
+
state.detectedTokens = newDetectedTokens;
|
|
387
|
+
state.allIgnoredTokens = newAllIgnoredTokens;
|
|
388
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
389
|
+
state.allTokens = newAllTokens;
|
|
348
390
|
});
|
|
349
391
|
}
|
|
350
392
|
/**
|
|
@@ -356,9 +398,9 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
356
398
|
* @param detectionDetails.chainId - the chainId on which the incomingDetectedTokens were detected.
|
|
357
399
|
*/
|
|
358
400
|
async addDetectedTokens(incomingDetectedTokens, detectionDetails) {
|
|
359
|
-
const releaseLock = await this.
|
|
360
|
-
const chainId = detectionDetails?.chainId ?? this
|
|
361
|
-
const accountAddress = detectionDetails?.selectedAddress ?? this
|
|
401
|
+
const releaseLock = await __privateGet(this, _mutex).acquire();
|
|
402
|
+
const chainId = detectionDetails?.chainId ?? __privateGet(this, _chainId);
|
|
403
|
+
const accountAddress = detectionDetails?.selectedAddress ?? __privateGet(this, _selectedAddress);
|
|
362
404
|
const { allTokens, allDetectedTokens, allIgnoredTokens } = this.state;
|
|
363
405
|
let newTokens = [...allTokens?.[chainId]?.[accountAddress] ?? []];
|
|
364
406
|
let newDetectedTokens = [
|
|
@@ -404,22 +446,19 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
404
446
|
}
|
|
405
447
|
}
|
|
406
448
|
});
|
|
407
|
-
const { newAllTokens, newAllDetectedTokens } = this.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
allTokens: newAllTokens,
|
|
421
|
-
detectedTokens: newDetectedTokens,
|
|
422
|
-
allDetectedTokens: newAllDetectedTokens
|
|
449
|
+
const { newAllTokens, newAllDetectedTokens } = __privateMethod(this, _getNewAllTokensState, getNewAllTokensState_fn).call(this, {
|
|
450
|
+
newTokens,
|
|
451
|
+
newDetectedTokens,
|
|
452
|
+
interactingAddress: accountAddress,
|
|
453
|
+
interactingChainId: chainId
|
|
454
|
+
});
|
|
455
|
+
newTokens = newAllTokens?.[__privateGet(this, _chainId)]?.[__privateGet(this, _selectedAddress)] || [];
|
|
456
|
+
newDetectedTokens = newAllDetectedTokens?.[__privateGet(this, _chainId)]?.[__privateGet(this, _selectedAddress)] || [];
|
|
457
|
+
this.update((state) => {
|
|
458
|
+
state.tokens = newTokens;
|
|
459
|
+
state.allTokens = newAllTokens;
|
|
460
|
+
state.detectedTokens = newDetectedTokens;
|
|
461
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
423
462
|
});
|
|
424
463
|
} finally {
|
|
425
464
|
releaseLock();
|
|
@@ -433,71 +472,17 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
433
472
|
* @returns The new token object with the added isERC721 field.
|
|
434
473
|
*/
|
|
435
474
|
async updateTokenType(tokenAddress) {
|
|
436
|
-
const isERC721 = await this.
|
|
437
|
-
const
|
|
475
|
+
const isERC721 = await __privateMethod(this, _detectIsERC721, detectIsERC721_fn).call(this, tokenAddress);
|
|
476
|
+
const tokens = [...this.state.tokens];
|
|
438
477
|
const tokenIndex = tokens.findIndex((token) => {
|
|
439
478
|
return token.address.toLowerCase() === tokenAddress.toLowerCase();
|
|
440
479
|
});
|
|
441
|
-
tokens[tokenIndex]
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* This is a function that updates the tokens name for the tokens name if it is not defined.
|
|
447
|
-
*
|
|
448
|
-
* @param tokenList - Represents the fetched token list from service API
|
|
449
|
-
* @param tokenAttribute - Represents the token attribute that we want to update on the token list
|
|
450
|
-
*/
|
|
451
|
-
updateTokensAttribute(tokenList, tokenAttribute) {
|
|
452
|
-
const { tokens } = this.state;
|
|
453
|
-
const newTokens = tokens.map((token) => {
|
|
454
|
-
const newToken = tokenList[token.address.toLowerCase()];
|
|
455
|
-
return !token[tokenAttribute] && newToken?.[tokenAttribute] ? { ...token, [tokenAttribute]: newToken[tokenAttribute] } : { ...token };
|
|
480
|
+
const updatedToken = { ...tokens[tokenIndex], isERC721 };
|
|
481
|
+
tokens[tokenIndex] = updatedToken;
|
|
482
|
+
this.update((state) => {
|
|
483
|
+
state.tokens = tokens;
|
|
456
484
|
});
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Detects whether or not a token is ERC-721 compatible.
|
|
461
|
-
*
|
|
462
|
-
* @param tokenAddress - The token contract address.
|
|
463
|
-
* @param networkClientId - Optional network client ID to fetch contract info with.
|
|
464
|
-
* @returns A boolean indicating whether the token address passed in supports the EIP-721
|
|
465
|
-
* interface.
|
|
466
|
-
*/
|
|
467
|
-
async _detectIsERC721(tokenAddress, networkClientId) {
|
|
468
|
-
const checksumAddress = toChecksumHexAddress(tokenAddress);
|
|
469
|
-
if (contractsMap[checksumAddress]?.erc721 === true) {
|
|
470
|
-
return Promise.resolve(true);
|
|
471
|
-
} else if (contractsMap[checksumAddress]?.erc20 === true) {
|
|
472
|
-
return Promise.resolve(false);
|
|
473
|
-
}
|
|
474
|
-
const tokenContract = this._createEthersContract(
|
|
475
|
-
tokenAddress,
|
|
476
|
-
abiERC721,
|
|
477
|
-
networkClientId
|
|
478
|
-
);
|
|
479
|
-
try {
|
|
480
|
-
return await tokenContract.supportsInterface(ERC721_INTERFACE_ID);
|
|
481
|
-
} catch (error) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
_getProvider(networkClientId) {
|
|
486
|
-
return new Web3Provider(
|
|
487
|
-
// @ts-expect-error TODO: remove this annotation once the `Eip1193Provider` class is released
|
|
488
|
-
networkClientId ? this.messagingSystem.call(
|
|
489
|
-
"NetworkController:getNetworkClientById",
|
|
490
|
-
networkClientId
|
|
491
|
-
).provider : this.config.provider
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
_createEthersContract(tokenAddress, abi, networkClientId) {
|
|
495
|
-
const web3provider = this._getProvider(networkClientId);
|
|
496
|
-
const tokenContract = new Contract(tokenAddress, abi, web3provider);
|
|
497
|
-
return tokenContract;
|
|
498
|
-
}
|
|
499
|
-
_generateRandomId() {
|
|
500
|
-
return random();
|
|
485
|
+
return updatedToken;
|
|
501
486
|
}
|
|
502
487
|
/**
|
|
503
488
|
* Adds a new suggestedAsset to the list of watched assets.
|
|
@@ -525,12 +510,12 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
525
510
|
if (!isValidHexAddress(asset.address)) {
|
|
526
511
|
throw rpcErrors.invalidParams(`Invalid address "${asset.address}"`);
|
|
527
512
|
}
|
|
528
|
-
if (await this.
|
|
513
|
+
if (await __privateMethod(this, _detectIsERC721, detectIsERC721_fn).call(this, asset.address, networkClientId)) {
|
|
529
514
|
throw rpcErrors.invalidParams(
|
|
530
515
|
`Contract ${asset.address} must match type ${type}, but was detected as ${ERC721}`
|
|
531
516
|
);
|
|
532
517
|
}
|
|
533
|
-
const provider = this.
|
|
518
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this, networkClientId);
|
|
534
519
|
const isErc1155 = await safelyExecute(
|
|
535
520
|
() => new ERC1155Standard(provider).contractSupportsBase1155Interface(
|
|
536
521
|
asset.address
|
|
@@ -587,12 +572,12 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
587
572
|
asset.decimals = decimalsNum;
|
|
588
573
|
const suggestedAssetMeta = {
|
|
589
574
|
asset,
|
|
590
|
-
id: this.
|
|
575
|
+
id: __privateMethod(this, _generateRandomId, generateRandomId_fn).call(this),
|
|
591
576
|
time: Date.now(),
|
|
592
577
|
type,
|
|
593
|
-
interactingAddress: interactingAddress || this
|
|
578
|
+
interactingAddress: interactingAddress || __privateGet(this, _selectedAddress)
|
|
594
579
|
};
|
|
595
|
-
await this.
|
|
580
|
+
await __privateMethod(this, _requestApproval, requestApproval_fn).call(this, suggestedAssetMeta);
|
|
596
581
|
const { address, symbol, decimals, name, image } = asset;
|
|
597
582
|
await this.addToken({
|
|
598
583
|
address,
|
|
@@ -604,95 +589,177 @@ var TokensController = class extends BaseControllerV1 {
|
|
|
604
589
|
networkClientId
|
|
605
590
|
});
|
|
606
591
|
}
|
|
607
|
-
/**
|
|
608
|
-
* Takes a new tokens and ignoredTokens array for the current network/account combination
|
|
609
|
-
* and returns new allTokens and allIgnoredTokens state to update to.
|
|
610
|
-
*
|
|
611
|
-
* @param params - Object that holds token params.
|
|
612
|
-
* @param params.newTokens - The new tokens to set for the current network and selected account.
|
|
613
|
-
* @param params.newIgnoredTokens - The new ignored tokens to set for the current network and selected account.
|
|
614
|
-
* @param params.newDetectedTokens - The new detected tokens to set for the current network and selected account.
|
|
615
|
-
* @param params.interactingAddress - The account address to use to store the tokens.
|
|
616
|
-
* @param params.interactingChainId - The chainId to use to store the tokens.
|
|
617
|
-
* @returns The updated `allTokens` and `allIgnoredTokens` state.
|
|
618
|
-
*/
|
|
619
|
-
_getNewAllTokensState(params) {
|
|
620
|
-
const {
|
|
621
|
-
newTokens,
|
|
622
|
-
newIgnoredTokens,
|
|
623
|
-
newDetectedTokens,
|
|
624
|
-
interactingAddress,
|
|
625
|
-
interactingChainId
|
|
626
|
-
} = params;
|
|
627
|
-
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
628
|
-
const { chainId, selectedAddress } = this.config;
|
|
629
|
-
const userAddressToAddTokens = interactingAddress ?? selectedAddress;
|
|
630
|
-
const chainIdToAddTokens = interactingChainId ?? chainId;
|
|
631
|
-
let newAllTokens = allTokens;
|
|
632
|
-
if (newTokens?.length || newTokens && allTokens && allTokens[chainIdToAddTokens] && allTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
633
|
-
const networkTokens = allTokens[chainIdToAddTokens];
|
|
634
|
-
const newNetworkTokens = {
|
|
635
|
-
...networkTokens,
|
|
636
|
-
...{ [userAddressToAddTokens]: newTokens }
|
|
637
|
-
};
|
|
638
|
-
newAllTokens = {
|
|
639
|
-
...allTokens,
|
|
640
|
-
...{ [chainIdToAddTokens]: newNetworkTokens }
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
let newAllIgnoredTokens = allIgnoredTokens;
|
|
644
|
-
if (newIgnoredTokens?.length || newIgnoredTokens && allIgnoredTokens && allIgnoredTokens[chainIdToAddTokens] && allIgnoredTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
645
|
-
const networkIgnoredTokens = allIgnoredTokens[chainIdToAddTokens];
|
|
646
|
-
const newIgnoredNetworkTokens = {
|
|
647
|
-
...networkIgnoredTokens,
|
|
648
|
-
...{ [userAddressToAddTokens]: newIgnoredTokens }
|
|
649
|
-
};
|
|
650
|
-
newAllIgnoredTokens = {
|
|
651
|
-
...allIgnoredTokens,
|
|
652
|
-
...{ [chainIdToAddTokens]: newIgnoredNetworkTokens }
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
let newAllDetectedTokens = allDetectedTokens;
|
|
656
|
-
if (newDetectedTokens?.length || newDetectedTokens && allDetectedTokens && allDetectedTokens[chainIdToAddTokens] && allDetectedTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
657
|
-
const networkDetectedTokens = allDetectedTokens[chainIdToAddTokens];
|
|
658
|
-
const newDetectedNetworkTokens = {
|
|
659
|
-
...networkDetectedTokens,
|
|
660
|
-
...{ [userAddressToAddTokens]: newDetectedTokens }
|
|
661
|
-
};
|
|
662
|
-
newAllDetectedTokens = {
|
|
663
|
-
...allDetectedTokens,
|
|
664
|
-
...{ [chainIdToAddTokens]: newDetectedNetworkTokens }
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
return { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens };
|
|
668
|
-
}
|
|
669
592
|
/**
|
|
670
593
|
* Removes all tokens from the ignored list.
|
|
671
594
|
*/
|
|
672
595
|
clearIgnoredTokens() {
|
|
673
|
-
this.update(
|
|
596
|
+
this.update((state) => {
|
|
597
|
+
state.ignoredTokens = [];
|
|
598
|
+
state.allIgnoredTokens = {};
|
|
599
|
+
});
|
|
674
600
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
601
|
+
};
|
|
602
|
+
_mutex = new WeakMap();
|
|
603
|
+
_chainId = new WeakMap();
|
|
604
|
+
_selectedAddress = new WeakMap();
|
|
605
|
+
_provider = new WeakMap();
|
|
606
|
+
_abortController = new WeakMap();
|
|
607
|
+
_onNetworkDidChange = new WeakSet();
|
|
608
|
+
onNetworkDidChange_fn = function({ providerConfig }) {
|
|
609
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
610
|
+
const { chainId } = providerConfig;
|
|
611
|
+
__privateGet(this, _abortController).abort();
|
|
612
|
+
__privateSet(this, _abortController, new AbortController());
|
|
613
|
+
__privateSet(this, _chainId, chainId);
|
|
614
|
+
this.update((state) => {
|
|
615
|
+
state.tokens = allTokens[chainId]?.[__privateGet(this, _selectedAddress)] || [];
|
|
616
|
+
state.ignoredTokens = allIgnoredTokens[chainId]?.[__privateGet(this, _selectedAddress)] || [];
|
|
617
|
+
state.detectedTokens = allDetectedTokens[chainId]?.[__privateGet(this, _selectedAddress)] || [];
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
_onPreferenceControllerStateChange = new WeakSet();
|
|
621
|
+
onPreferenceControllerStateChange_fn = function({ selectedAddress }) {
|
|
622
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
623
|
+
__privateSet(this, _selectedAddress, selectedAddress);
|
|
624
|
+
this.update((state) => {
|
|
625
|
+
state.tokens = allTokens[__privateGet(this, _chainId)]?.[selectedAddress] ?? [];
|
|
626
|
+
state.ignoredTokens = allIgnoredTokens[__privateGet(this, _chainId)]?.[selectedAddress] ?? [];
|
|
627
|
+
state.detectedTokens = allDetectedTokens[__privateGet(this, _chainId)]?.[selectedAddress] ?? [];
|
|
628
|
+
});
|
|
629
|
+
};
|
|
630
|
+
_fetchTokenMetadata = new WeakSet();
|
|
631
|
+
fetchTokenMetadata_fn = async function(tokenAddress) {
|
|
632
|
+
try {
|
|
633
|
+
const token = await fetchTokenMetadata(
|
|
634
|
+
__privateGet(this, _chainId),
|
|
635
|
+
tokenAddress,
|
|
636
|
+
__privateGet(this, _abortController).signal
|
|
694
637
|
);
|
|
638
|
+
return token;
|
|
639
|
+
} catch (error) {
|
|
640
|
+
if (error instanceof Error && error.message.includes(TOKEN_METADATA_NO_SUPPORT_ERROR)) {
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
_updateTokensAttribute = new WeakSet();
|
|
647
|
+
updateTokensAttribute_fn = function(tokenList, tokenAttribute) {
|
|
648
|
+
const { tokens } = this.state;
|
|
649
|
+
const newTokens = tokens.map((token) => {
|
|
650
|
+
const newToken = tokenList[token.address.toLowerCase()];
|
|
651
|
+
return !token[tokenAttribute] && newToken?.[tokenAttribute] ? { ...token, [tokenAttribute]: newToken[tokenAttribute] } : { ...token };
|
|
652
|
+
});
|
|
653
|
+
this.update((state) => {
|
|
654
|
+
state.tokens = newTokens;
|
|
655
|
+
});
|
|
656
|
+
};
|
|
657
|
+
_detectIsERC721 = new WeakSet();
|
|
658
|
+
detectIsERC721_fn = async function(tokenAddress, networkClientId) {
|
|
659
|
+
const checksumAddress = toChecksumHexAddress(tokenAddress);
|
|
660
|
+
if (contractsMap[checksumAddress]?.erc721 === true) {
|
|
661
|
+
return Promise.resolve(true);
|
|
662
|
+
} else if (contractsMap[checksumAddress]?.erc20 === true) {
|
|
663
|
+
return Promise.resolve(false);
|
|
695
664
|
}
|
|
665
|
+
const tokenContract = __privateMethod(this, _createEthersContract, createEthersContract_fn).call(this, tokenAddress, abiERC721, networkClientId);
|
|
666
|
+
try {
|
|
667
|
+
return await tokenContract.supportsInterface(ERC721_INTERFACE_ID);
|
|
668
|
+
} catch (error) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
_getProvider = new WeakSet();
|
|
673
|
+
getProvider_fn = function(networkClientId) {
|
|
674
|
+
return new Web3Provider(
|
|
675
|
+
// @ts-expect-error TODO: remove this annotation once the `Eip1193Provider` class is released
|
|
676
|
+
networkClientId ? this.messagingSystem.call(
|
|
677
|
+
"NetworkController:getNetworkClientById",
|
|
678
|
+
networkClientId
|
|
679
|
+
).provider : __privateGet(this, _provider)
|
|
680
|
+
);
|
|
681
|
+
};
|
|
682
|
+
_createEthersContract = new WeakSet();
|
|
683
|
+
createEthersContract_fn = function(tokenAddress, abi, networkClientId) {
|
|
684
|
+
const web3provider = __privateMethod(this, _getProvider, getProvider_fn).call(this, networkClientId);
|
|
685
|
+
const tokenContract = new Contract(tokenAddress, abi, web3provider);
|
|
686
|
+
return tokenContract;
|
|
687
|
+
};
|
|
688
|
+
_generateRandomId = new WeakSet();
|
|
689
|
+
generateRandomId_fn = function() {
|
|
690
|
+
return random();
|
|
691
|
+
};
|
|
692
|
+
_getNewAllTokensState = new WeakSet();
|
|
693
|
+
getNewAllTokensState_fn = function(params) {
|
|
694
|
+
const {
|
|
695
|
+
newTokens,
|
|
696
|
+
newIgnoredTokens,
|
|
697
|
+
newDetectedTokens,
|
|
698
|
+
interactingAddress,
|
|
699
|
+
interactingChainId
|
|
700
|
+
} = params;
|
|
701
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
702
|
+
const userAddressToAddTokens = interactingAddress ?? __privateGet(this, _selectedAddress);
|
|
703
|
+
const chainIdToAddTokens = interactingChainId ?? __privateGet(this, _chainId);
|
|
704
|
+
let newAllTokens = allTokens;
|
|
705
|
+
if (newTokens?.length || newTokens && allTokens && allTokens[chainIdToAddTokens] && allTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
706
|
+
const networkTokens = allTokens[chainIdToAddTokens];
|
|
707
|
+
const newNetworkTokens = {
|
|
708
|
+
...networkTokens,
|
|
709
|
+
...{ [userAddressToAddTokens]: newTokens }
|
|
710
|
+
};
|
|
711
|
+
newAllTokens = {
|
|
712
|
+
...allTokens,
|
|
713
|
+
...{ [chainIdToAddTokens]: newNetworkTokens }
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
let newAllIgnoredTokens = allIgnoredTokens;
|
|
717
|
+
if (newIgnoredTokens?.length || newIgnoredTokens && allIgnoredTokens && allIgnoredTokens[chainIdToAddTokens] && allIgnoredTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
718
|
+
const networkIgnoredTokens = allIgnoredTokens[chainIdToAddTokens];
|
|
719
|
+
const newIgnoredNetworkTokens = {
|
|
720
|
+
...networkIgnoredTokens,
|
|
721
|
+
...{ [userAddressToAddTokens]: newIgnoredTokens }
|
|
722
|
+
};
|
|
723
|
+
newAllIgnoredTokens = {
|
|
724
|
+
...allIgnoredTokens,
|
|
725
|
+
...{ [chainIdToAddTokens]: newIgnoredNetworkTokens }
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
let newAllDetectedTokens = allDetectedTokens;
|
|
729
|
+
if (newDetectedTokens?.length || newDetectedTokens && allDetectedTokens && allDetectedTokens[chainIdToAddTokens] && allDetectedTokens[chainIdToAddTokens][userAddressToAddTokens]) {
|
|
730
|
+
const networkDetectedTokens = allDetectedTokens[chainIdToAddTokens];
|
|
731
|
+
const newDetectedNetworkTokens = {
|
|
732
|
+
...networkDetectedTokens,
|
|
733
|
+
...{ [userAddressToAddTokens]: newDetectedTokens }
|
|
734
|
+
};
|
|
735
|
+
newAllDetectedTokens = {
|
|
736
|
+
...allDetectedTokens,
|
|
737
|
+
...{ [chainIdToAddTokens]: newDetectedNetworkTokens }
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
return { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens };
|
|
741
|
+
};
|
|
742
|
+
_requestApproval = new WeakSet();
|
|
743
|
+
requestApproval_fn = async function(suggestedAssetMeta) {
|
|
744
|
+
return this.messagingSystem.call(
|
|
745
|
+
"ApprovalController:addRequest",
|
|
746
|
+
{
|
|
747
|
+
id: suggestedAssetMeta.id,
|
|
748
|
+
origin: ORIGIN_METAMASK,
|
|
749
|
+
type: ApprovalType.WatchAsset,
|
|
750
|
+
requestData: {
|
|
751
|
+
id: suggestedAssetMeta.id,
|
|
752
|
+
interactingAddress: suggestedAssetMeta.interactingAddress,
|
|
753
|
+
asset: {
|
|
754
|
+
address: suggestedAssetMeta.asset.address,
|
|
755
|
+
decimals: suggestedAssetMeta.asset.decimals,
|
|
756
|
+
symbol: suggestedAssetMeta.asset.symbol,
|
|
757
|
+
image: suggestedAssetMeta.asset.image || null
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
true
|
|
762
|
+
);
|
|
696
763
|
};
|
|
697
764
|
var TokensController_default = TokensController;
|
|
698
765
|
|
|
@@ -701,4 +768,4 @@ export {
|
|
|
701
768
|
TokensController,
|
|
702
769
|
TokensController_default
|
|
703
770
|
};
|
|
704
|
-
//# sourceMappingURL=chunk-
|
|
771
|
+
//# sourceMappingURL=chunk-73F3SN5O.mjs.map
|