@metamask-previews/assets-controllers 26.0.0-preview.e5c396b → 26.0.0-preview.eb2135e

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.
Files changed (229) hide show
  1. package/dist/AccountTrackerController.js +9 -239
  2. package/dist/AccountTrackerController.js.map +1 -1
  3. package/dist/AccountTrackerController.mjs +10 -0
  4. package/dist/AccountTrackerController.mjs.map +1 -0
  5. package/dist/AssetsContractController.js +17 -384
  6. package/dist/AssetsContractController.js.map +1 -1
  7. package/dist/AssetsContractController.mjs +18 -0
  8. package/dist/AssetsContractController.mjs.map +1 -0
  9. package/dist/CurrencyRateController.js +10 -157
  10. package/dist/CurrencyRateController.js.map +1 -1
  11. package/dist/CurrencyRateController.mjs +11 -0
  12. package/dist/CurrencyRateController.mjs.map +1 -0
  13. package/dist/NftController.js +15 -1041
  14. package/dist/NftController.js.map +1 -1
  15. package/dist/NftController.mjs +16 -0
  16. package/dist/NftController.mjs.map +1 -0
  17. package/dist/NftDetectionController.js +12 -213
  18. package/dist/NftDetectionController.js.map +1 -1
  19. package/dist/NftDetectionController.mjs +13 -0
  20. package/dist/NftDetectionController.mjs.map +1 -0
  21. package/dist/Standards/ERC20Standard.js +8 -142
  22. package/dist/Standards/ERC20Standard.js.map +1 -1
  23. package/dist/Standards/ERC20Standard.mjs +9 -0
  24. package/dist/Standards/ERC20Standard.mjs.map +1 -0
  25. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +8 -217
  26. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +1 -1
  27. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +9 -0
  28. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -0
  29. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +8 -174
  30. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +1 -1
  31. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +9 -0
  32. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -0
  33. package/dist/TokenBalancesController.js +11 -141
  34. package/dist/TokenBalancesController.js.map +1 -1
  35. package/dist/TokenBalancesController.mjs +12 -0
  36. package/dist/TokenBalancesController.mjs.map +1 -0
  37. package/dist/TokenDetectionController.js +16 -362
  38. package/dist/TokenDetectionController.js.map +1 -1
  39. package/dist/TokenDetectionController.mjs +17 -0
  40. package/dist/TokenDetectionController.mjs.map +1 -0
  41. package/dist/TokenListController.js +13 -250
  42. package/dist/TokenListController.js.map +1 -1
  43. package/dist/TokenListController.mjs +14 -0
  44. package/dist/TokenListController.mjs.map +1 -0
  45. package/dist/TokenRatesController.js +11 -328
  46. package/dist/TokenRatesController.js.map +1 -1
  47. package/dist/TokenRatesController.mjs +12 -0
  48. package/dist/TokenRatesController.mjs.map +1 -0
  49. package/dist/TokensController.js +15 -629
  50. package/dist/TokensController.js.map +1 -1
  51. package/dist/TokensController.mjs +16 -0
  52. package/dist/TokensController.mjs.map +1 -0
  53. package/dist/assetsUtil.js +41 -384
  54. package/dist/assetsUtil.js.map +1 -1
  55. package/dist/assetsUtil.mjs +42 -0
  56. package/dist/assetsUtil.mjs.map +1 -0
  57. package/dist/chunk-23F5W3A2.mjs +157 -0
  58. package/dist/chunk-23F5W3A2.mjs.map +1 -0
  59. package/dist/chunk-27KOXCQK.mjs +1 -0
  60. package/dist/chunk-27KOXCQK.mjs.map +1 -0
  61. package/dist/chunk-3FMWI46J.mjs +361 -0
  62. package/dist/chunk-3FMWI46J.mjs.map +1 -0
  63. package/dist/chunk-3FOTFZIL.mjs +411 -0
  64. package/dist/chunk-3FOTFZIL.mjs.map +1 -0
  65. package/dist/chunk-4LY47RPI.mjs +139 -0
  66. package/dist/chunk-4LY47RPI.mjs.map +1 -0
  67. package/dist/chunk-5C7ZVZNM.mjs +267 -0
  68. package/dist/chunk-5C7ZVZNM.mjs.map +1 -0
  69. package/dist/chunk-64EHFYLM.mjs +245 -0
  70. package/dist/chunk-64EHFYLM.mjs.map +1 -0
  71. package/dist/chunk-6C2ZIK7A.js +245 -0
  72. package/dist/chunk-6C2ZIK7A.js.map +1 -0
  73. package/dist/chunk-6DTCHPBB.mjs +178 -0
  74. package/dist/chunk-6DTCHPBB.mjs.map +1 -0
  75. package/dist/chunk-74IP34EL.js +1177 -0
  76. package/dist/chunk-74IP34EL.js.map +1 -0
  77. package/dist/chunk-BZI7P3TD.js +115 -0
  78. package/dist/chunk-BZI7P3TD.js.map +1 -0
  79. package/dist/chunk-C4PQK53K.js +32 -0
  80. package/dist/chunk-C4PQK53K.js.map +1 -0
  81. package/dist/chunk-CP3HC7AQ.mjs +12 -0
  82. package/dist/chunk-CP3HC7AQ.mjs.map +1 -0
  83. package/dist/chunk-GHZX5DE4.js +215 -0
  84. package/dist/chunk-GHZX5DE4.js.map +1 -0
  85. package/dist/chunk-GMKIOYCB.js +361 -0
  86. package/dist/chunk-GMKIOYCB.js.map +1 -0
  87. package/dist/chunk-H6TOSWUM.js +157 -0
  88. package/dist/chunk-H6TOSWUM.js.map +1 -0
  89. package/dist/chunk-HWFBJFHS.js +284 -0
  90. package/dist/chunk-HWFBJFHS.js.map +1 -0
  91. package/dist/chunk-J2JQQNHN.mjs +115 -0
  92. package/dist/chunk-J2JQQNHN.mjs.map +1 -0
  93. package/dist/chunk-J6HPEQL3.mjs +704 -0
  94. package/dist/chunk-J6HPEQL3.mjs.map +1 -0
  95. package/dist/chunk-JC4WAN2J.mjs +1177 -0
  96. package/dist/chunk-JC4WAN2J.mjs.map +1 -0
  97. package/dist/chunk-LD4GC7OR.js +139 -0
  98. package/dist/chunk-LD4GC7OR.js.map +1 -0
  99. package/dist/chunk-NG2UOKDD.js +178 -0
  100. package/dist/chunk-NG2UOKDD.js.map +1 -0
  101. package/dist/chunk-NGIXA5M5.mjs +418 -0
  102. package/dist/chunk-NGIXA5M5.mjs.map +1 -0
  103. package/dist/chunk-NLNXQHAU.js +704 -0
  104. package/dist/chunk-NLNXQHAU.js.map +1 -0
  105. package/dist/chunk-OBUR4TXH.js +1 -0
  106. package/dist/chunk-OBUR4TXH.js.map +1 -0
  107. package/dist/chunk-PAJTKWEC.mjs +246 -0
  108. package/dist/chunk-PAJTKWEC.mjs.map +1 -0
  109. package/dist/chunk-PRIXT2R6.js +411 -0
  110. package/dist/chunk-PRIXT2R6.js.map +1 -0
  111. package/dist/chunk-PUFSYRJZ.js +74 -0
  112. package/dist/chunk-PUFSYRJZ.js.map +1 -0
  113. package/dist/chunk-QHRPRO5U.mjs +74 -0
  114. package/dist/chunk-QHRPRO5U.mjs.map +1 -0
  115. package/dist/chunk-QR4CX2JT.mjs +284 -0
  116. package/dist/chunk-QR4CX2JT.mjs.map +1 -0
  117. package/dist/chunk-RGHTNZQ6.js +12 -0
  118. package/dist/chunk-RGHTNZQ6.js.map +1 -0
  119. package/dist/chunk-TCO22VIO.mjs +32 -0
  120. package/dist/chunk-TCO22VIO.mjs.map +1 -0
  121. package/dist/chunk-TDKCVCGP.mjs +215 -0
  122. package/dist/chunk-TDKCVCGP.mjs.map +1 -0
  123. package/dist/chunk-UAH5YURZ.js +343 -0
  124. package/dist/chunk-UAH5YURZ.js.map +1 -0
  125. package/dist/chunk-V4ZO3F2S.js +246 -0
  126. package/dist/chunk-V4ZO3F2S.js.map +1 -0
  127. package/dist/chunk-VDJBJAUB.js +418 -0
  128. package/dist/chunk-VDJBJAUB.js.map +1 -0
  129. package/dist/chunk-WRQ7POD7.mjs +343 -0
  130. package/dist/chunk-WRQ7POD7.mjs.map +1 -0
  131. package/dist/chunk-XUI43LEZ.mjs +30 -0
  132. package/dist/chunk-XUI43LEZ.mjs.map +1 -0
  133. package/dist/chunk-YD3NRMFC.js +267 -0
  134. package/dist/chunk-YD3NRMFC.js.map +1 -0
  135. package/dist/chunk-Z4BLTVTB.js +30 -0
  136. package/dist/chunk-Z4BLTVTB.js.map +1 -0
  137. package/dist/constants.js +7 -9
  138. package/dist/constants.js.map +1 -1
  139. package/dist/constants.mjs +8 -0
  140. package/dist/constants.mjs.map +1 -0
  141. package/dist/crypto-compare.js +7 -66
  142. package/dist/crypto-compare.js.map +1 -1
  143. package/dist/crypto-compare.mjs +8 -0
  144. package/dist/crypto-compare.mjs.map +1 -0
  145. package/dist/index.js +72 -39
  146. package/dist/index.js.map +1 -1
  147. package/dist/index.mjs +73 -0
  148. package/dist/index.mjs.map +1 -0
  149. package/dist/token-prices-service/abstract-token-prices-service.js +1 -3
  150. package/dist/token-prices-service/abstract-token-prices-service.js.map +1 -1
  151. package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
  152. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -0
  153. package/dist/token-prices-service/codefi-v2.js +11 -353
  154. package/dist/token-prices-service/codefi-v2.js.map +1 -1
  155. package/dist/token-prices-service/codefi-v2.mjs +12 -0
  156. package/dist/token-prices-service/codefi-v2.mjs.map +1 -0
  157. package/dist/token-prices-service/index.js +8 -5
  158. package/dist/token-prices-service/index.js.map +1 -1
  159. package/dist/token-prices-service/index.mjs +9 -0
  160. package/dist/token-prices-service/index.mjs.map +1 -0
  161. package/dist/token-service.js +14 -133
  162. package/dist/token-service.js.map +1 -1
  163. package/dist/token-service.mjs +15 -0
  164. package/dist/token-service.mjs.map +1 -0
  165. package/dist/tsconfig.build.tsbuildinfo +1 -0
  166. package/dist/types/AccountTrackerController.d.ts.map +1 -0
  167. package/dist/types/AssetsContractController.d.ts.map +1 -0
  168. package/dist/types/CurrencyRateController.d.ts.map +1 -0
  169. package/dist/types/NftController.d.ts.map +1 -0
  170. package/dist/types/NftDetectionController.d.ts.map +1 -0
  171. package/dist/types/Standards/ERC20Standard.d.ts.map +1 -0
  172. package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +1 -0
  173. package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +1 -0
  174. package/dist/types/TokenBalancesController.d.ts.map +1 -0
  175. package/dist/types/TokenDetectionController.d.ts.map +1 -0
  176. package/dist/types/TokenListController.d.ts.map +1 -0
  177. package/dist/types/TokenRatesController.d.ts.map +1 -0
  178. package/dist/{TokensController.d.ts → types/TokensController.d.ts} +10 -3
  179. package/dist/types/TokensController.d.ts.map +1 -0
  180. package/dist/types/assetsUtil.d.ts.map +1 -0
  181. package/dist/types/constants.d.ts.map +1 -0
  182. package/dist/types/crypto-compare.d.ts.map +1 -0
  183. package/dist/types/index.d.ts.map +1 -0
  184. package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -0
  185. package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -0
  186. package/dist/types/token-prices-service/index.d.ts.map +1 -0
  187. package/dist/types/token-service.d.ts.map +1 -0
  188. package/package.json +11 -1
  189. package/dist/AccountTrackerController.d.ts.map +0 -1
  190. package/dist/AssetsContractController.d.ts.map +0 -1
  191. package/dist/CurrencyRateController.d.ts.map +0 -1
  192. package/dist/NftController.d.ts.map +0 -1
  193. package/dist/NftDetectionController.d.ts.map +0 -1
  194. package/dist/Standards/ERC20Standard.d.ts.map +0 -1
  195. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
  196. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
  197. package/dist/TokenBalancesController.d.ts.map +0 -1
  198. package/dist/TokenDetectionController.d.ts.map +0 -1
  199. package/dist/TokenListController.d.ts.map +0 -1
  200. package/dist/TokenRatesController.d.ts.map +0 -1
  201. package/dist/TokensController.d.ts.map +0 -1
  202. package/dist/assetsUtil.d.ts.map +0 -1
  203. package/dist/constants.d.ts.map +0 -1
  204. package/dist/crypto-compare.d.ts.map +0 -1
  205. package/dist/index.d.ts.map +0 -1
  206. package/dist/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
  207. package/dist/token-prices-service/codefi-v2.d.ts.map +0 -1
  208. package/dist/token-prices-service/index.d.ts.map +0 -1
  209. package/dist/token-service.d.ts.map +0 -1
  210. /package/dist/{AccountTrackerController.d.ts → types/AccountTrackerController.d.ts} +0 -0
  211. /package/dist/{AssetsContractController.d.ts → types/AssetsContractController.d.ts} +0 -0
  212. /package/dist/{CurrencyRateController.d.ts → types/CurrencyRateController.d.ts} +0 -0
  213. /package/dist/{NftController.d.ts → types/NftController.d.ts} +0 -0
  214. /package/dist/{NftDetectionController.d.ts → types/NftDetectionController.d.ts} +0 -0
  215. /package/dist/{Standards → types/Standards}/ERC20Standard.d.ts +0 -0
  216. /package/dist/{Standards → types/Standards}/NftStandards/ERC1155/ERC1155Standard.d.ts +0 -0
  217. /package/dist/{Standards → types/Standards}/NftStandards/ERC721/ERC721Standard.d.ts +0 -0
  218. /package/dist/{TokenBalancesController.d.ts → types/TokenBalancesController.d.ts} +0 -0
  219. /package/dist/{TokenDetectionController.d.ts → types/TokenDetectionController.d.ts} +0 -0
  220. /package/dist/{TokenListController.d.ts → types/TokenListController.d.ts} +0 -0
  221. /package/dist/{TokenRatesController.d.ts → types/TokenRatesController.d.ts} +0 -0
  222. /package/dist/{assetsUtil.d.ts → types/assetsUtil.d.ts} +0 -0
  223. /package/dist/{constants.d.ts → types/constants.d.ts} +0 -0
  224. /package/dist/{crypto-compare.d.ts → types/crypto-compare.d.ts} +0 -0
  225. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  226. /package/dist/{token-prices-service → types/token-prices-service}/abstract-token-prices-service.d.ts +0 -0
  227. /package/dist/{token-prices-service → types/token-prices-service}/codefi-v2.d.ts +0 -0
  228. /package/dist/{token-prices-service → types/token-prices-service}/index.d.ts +0 -0
  229. /package/dist/{token-service.d.ts → types/token-service.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ERC721Standard.js","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAoD;AAEpD,iEAOoC;AACpC,mEAAwD;AAExD,oDAA0D;AAE1D,MAAa,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAA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AC,OAAO,EAAE,6BAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;KAAA;CAwFF;AA5MD,wCA4MC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata = await this.contractSupportsMetadataInterface(\n address,\n );\n if (!supportsMetadata) {\n throw new Error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\n };\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n let image;\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import {
2
+ ERC721Standard
3
+ } from "../../../chunk-6DTCHPBB.mjs";
4
+ import "../../../chunk-5C7ZVZNM.mjs";
5
+ import "../../../chunk-XUI43LEZ.mjs";
6
+ export {
7
+ ERC721Standard
8
+ };
9
+ //# sourceMappingURL=ERC721Standard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,142 +1,12 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
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 _TokenBalancesController_handle, _TokenBalancesController_getERC20BalanceOf, _TokenBalancesController_interval, _TokenBalancesController_tokens, _TokenBalancesController_disabled;
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.TokenBalancesController = exports.getDefaultTokenBalancesState = void 0;
25
- const base_controller_1 = require("@metamask/base-controller");
26
- const controller_utils_1 = require("@metamask/controller-utils");
27
- const DEFAULT_INTERVAL = 180000;
28
- const controllerName = 'TokenBalancesController';
29
- const metadata = {
30
- contractBalances: { persist: true, anonymous: false },
31
- };
32
- /**
33
- * Get the default TokenBalancesController state.
34
- *
35
- * @returns The default TokenBalancesController state.
36
- */
37
- function getDefaultTokenBalancesState() {
38
- return {
39
- contractBalances: {},
40
- };
41
- }
42
- exports.getDefaultTokenBalancesState = getDefaultTokenBalancesState;
43
- /**
44
- * Controller that passively polls on a set interval token balances
45
- * for tokens stored in the TokensController
46
- */
47
- class TokenBalancesController extends base_controller_1.BaseController {
48
- /**
49
- * Construct a Token Balances Controller.
50
- *
51
- * @param options - The controller options.
52
- * @param options.interval - Polling interval used to fetch new token balances.
53
- * @param options.tokens - List of tokens to track balances for.
54
- * @param options.disabled - If set to true, all tracked tokens contract balances updates are blocked.
55
- * @param options.getERC20BalanceOf - Gets the balance of the given account at the given contract address.
56
- * @param options.state - Initial state to set on this controller.
57
- * @param options.messenger - The controller restricted messenger.
58
- */
59
- constructor({ interval = DEFAULT_INTERVAL, tokens = [], disabled = false, getERC20BalanceOf, messenger, state = {}, }) {
60
- super({
61
- name: controllerName,
62
- metadata,
63
- messenger,
64
- state: Object.assign(Object.assign({}, getDefaultTokenBalancesState()), state),
65
- });
66
- _TokenBalancesController_handle.set(this, void 0);
67
- _TokenBalancesController_getERC20BalanceOf.set(this, void 0);
68
- _TokenBalancesController_interval.set(this, void 0);
69
- _TokenBalancesController_tokens.set(this, void 0);
70
- _TokenBalancesController_disabled.set(this, void 0);
71
- __classPrivateFieldSet(this, _TokenBalancesController_disabled, disabled, "f");
72
- __classPrivateFieldSet(this, _TokenBalancesController_interval, interval, "f");
73
- __classPrivateFieldSet(this, _TokenBalancesController_tokens, tokens, "f");
74
- this.messagingSystem.subscribe('TokensController:stateChange', ({ tokens: newTokens, detectedTokens }) => {
75
- __classPrivateFieldSet(this, _TokenBalancesController_tokens, [...newTokens, ...detectedTokens], "f");
76
- this.updateBalances();
77
- });
78
- __classPrivateFieldSet(this, _TokenBalancesController_getERC20BalanceOf, getERC20BalanceOf, "f");
79
- this.poll();
80
- }
81
- /**
82
- * Allows controller to update tracked tokens contract balances.
83
- */
84
- enable() {
85
- __classPrivateFieldSet(this, _TokenBalancesController_disabled, false, "f");
86
- }
87
- /**
88
- * Blocks controller from updating tracked tokens contract balances.
89
- */
90
- disable() {
91
- __classPrivateFieldSet(this, _TokenBalancesController_disabled, true, "f");
92
- }
93
- /**
94
- * Starts a new polling interval.
95
- *
96
- * @param interval - Polling interval used to fetch new token balances.
97
- */
98
- poll(interval) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- if (interval) {
101
- __classPrivateFieldSet(this, _TokenBalancesController_interval, interval, "f");
102
- }
103
- if (__classPrivateFieldGet(this, _TokenBalancesController_handle, "f")) {
104
- clearTimeout(__classPrivateFieldGet(this, _TokenBalancesController_handle, "f"));
105
- }
106
- yield (0, controller_utils_1.safelyExecute)(() => this.updateBalances());
107
- __classPrivateFieldSet(this, _TokenBalancesController_handle, setTimeout(() => {
108
- this.poll(__classPrivateFieldGet(this, _TokenBalancesController_interval, "f"));
109
- }, __classPrivateFieldGet(this, _TokenBalancesController_interval, "f")), "f");
110
- });
111
- }
112
- /**
113
- * Updates balances for all tokens.
114
- */
115
- updateBalances() {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- if (__classPrivateFieldGet(this, _TokenBalancesController_disabled, "f")) {
118
- return;
119
- }
120
- const newContractBalances = {};
121
- for (const token of __classPrivateFieldGet(this, _TokenBalancesController_tokens, "f")) {
122
- const { address } = token;
123
- const { selectedAddress } = this.messagingSystem.call('PreferencesController:getState');
124
- try {
125
- newContractBalances[address] = (0, controller_utils_1.toHex)(yield __classPrivateFieldGet(this, _TokenBalancesController_getERC20BalanceOf, "f").call(this, address, selectedAddress));
126
- token.balanceError = null;
127
- }
128
- catch (error) {
129
- newContractBalances[address] = (0, controller_utils_1.toHex)(0);
130
- token.balanceError = error;
131
- }
132
- }
133
- this.update((state) => {
134
- state.contractBalances = newContractBalances;
135
- });
136
- });
137
- }
138
- }
139
- exports.TokenBalancesController = TokenBalancesController;
140
- _TokenBalancesController_handle = new WeakMap(), _TokenBalancesController_getERC20BalanceOf = new WeakMap(), _TokenBalancesController_interval = new WeakMap(), _TokenBalancesController_tokens = new WeakMap(), _TokenBalancesController_disabled = new WeakMap();
141
- exports.default = TokenBalancesController;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkLD4GC7ORjs = require('./chunk-LD4GC7OR.js');
6
+ require('./chunk-Z4BLTVTB.js');
7
+
8
+
9
+
10
+
11
+ exports.TokenBalancesController = _chunkLD4GC7ORjs.TokenBalancesController; exports.default = _chunkLD4GC7ORjs.TokenBalancesController_default; exports.getDefaultTokenBalancesState = _chunkLD4GC7ORjs.getDefaultTokenBalancesState;
142
12
  //# sourceMappingURL=TokenBalancesController.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TokenBalancesController.js","sourceRoot":"","sources":["../src/TokenBalancesController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAKmC;AACnC,iEAAkE;AAOlE,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,QAAQ,GAAG;IACf,gBAAgB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;CACtD,CAAC;AA4DF;;;;GAIG;AACH,SAAgB,4BAA4B;IAC1C,OAAO;QACL,gBAAgB,EAAE,EAAE;KACrB,CAAC;AACJ,CAAC;AAJD,oEAIC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,gCAI5C;IAWC;;;;;;;;;;OAUG;IACH,YAAY,EACV,QAAQ,GAAG,gBAAgB,EAC3B,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG,KAAK,EAChB,iBAAiB,EACjB,SAAS,EACT,KAAK,GAAG,EAAE,GACqB;QAC/B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ;YACR,SAAS;YACT,KAAK,kCACA,4BAA4B,EAAE,GAC9B,KAAK,CACT;SACF,CAAC,CAAC;QArCL,kDAAwC;QAExC,6DAAkE;QAElE,oDAAkB;QAElB,kDAAiB;QAEjB,oDAAmB;QA+BjB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M,mBAAmB,GAAqB,EAAE,CAAC;YACjD,KAAK,MAAM,KAAK,IAAI,uBAAA,IAAI,uCAAQ,EAAE;gBAChC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;gBAC1B,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CACnD,gCAAgC,CACjC,CAAC;gBACF,IAAI;oBACF,mBAAmB,CAAC,OAAO,CAAC,GAAG,IAAA,wBAAK,EAClC,MAAM,uBAAA,IAAI,kDAAmB,MAAvB,IAAI,EAAoB,OAAO,EAAE,eAAe,CAAC,CACxD,CAAC;oBACF,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;iBAC3B;gBAAC,OAAO,KAAK,EAAE;oBACd,mBAAmB,CAAC,OAAO,CAAC,GAAG,IAAA,wBAAK,EAAC,CAAC,CAAC,CAAC;oBACxC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;iBAC5B;aACF;YAED,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpB,KAAK,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;YAC/C,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AA7HD,0DA6HC;;AAED,kBAAe,uBAAuB,CAAC","sourcesContent":["import {\n type RestrictedControllerMessenger,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n BaseController,\n} from '@metamask/base-controller';\nimport { safelyExecute, toHex } from '@metamask/controller-utils';\nimport type { PreferencesControllerGetStateAction } from '@metamask/preferences-controller';\n\nimport type { AssetsContractController } from './AssetsContractController';\nimport type { Token } from './TokenRatesController';\nimport type { TokensControllerStateChangeEvent } from './TokensController';\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst controllerName = 'TokenBalancesController';\n\nconst metadata = {\n contractBalances: { persist: true, anonymous: false },\n};\n\n/**\n * Token balances controller options\n * @property interval - Polling interval used to fetch new token balances.\n * @property tokens - List of tokens to track balances for.\n * @property disabled - If set to true, all tracked tokens contract balances updates are blocked.\n * @property getERC20BalanceOf - Gets the balance of the given account at the given contract address.\n */\ntype TokenBalancesControllerOptions = {\n interval?: number;\n tokens?: Token[];\n disabled?: boolean;\n getERC20BalanceOf: AssetsContractController['getERC20BalanceOf'];\n messenger: TokenBalancesControllerMessenger;\n state?: Partial<TokenBalancesControllerState>;\n};\n\n/**\n * Represents a mapping of hash token contract addresses to their balances.\n */\ntype ContractBalances = Record<string, string>;\n\n/**\n * Token balances controller state\n * @property contractBalances - Hash of token contract addresses to balances\n */\nexport type TokenBalancesControllerState = {\n contractBalances: ContractBalances;\n};\n\nexport type TokenBalancesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n TokenBalancesControllerState\n>;\n\nexport type TokenBalancesControllerActions =\n TokenBalancesControllerGetStateAction;\n\nexport type AllowedActions = PreferencesControllerGetStateAction;\n\nexport type TokenBalancesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n TokenBalancesControllerState\n >;\n\nexport type TokenBalancesControllerEvents =\n TokenBalancesControllerStateChangeEvent;\n\nexport type AllowedEvents = TokensControllerStateChangeEvent;\n\nexport type TokenBalancesControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n TokenBalancesControllerActions | AllowedActions,\n TokenBalancesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Get the default TokenBalancesController state.\n *\n * @returns The default TokenBalancesController state.\n */\nexport function getDefaultTokenBalancesState(): TokenBalancesControllerState {\n return {\n contractBalances: {},\n };\n}\n\n/**\n * Controller that passively polls on a set interval token balances\n * for tokens stored in the TokensController\n */\nexport class TokenBalancesController extends BaseController<\n typeof controllerName,\n TokenBalancesControllerState,\n TokenBalancesControllerMessenger\n> {\n #handle?: ReturnType<typeof setTimeout>;\n\n #getERC20BalanceOf: AssetsContractController['getERC20BalanceOf'];\n\n #interval: number;\n\n #tokens: Token[];\n\n #disabled: boolean;\n\n /**\n * Construct a Token Balances Controller.\n *\n * @param options - The controller options.\n * @param options.interval - Polling interval used to fetch new token balances.\n * @param options.tokens - List of tokens to track balances for.\n * @param options.disabled - If set to true, all tracked tokens contract balances updates are blocked.\n * @param options.getERC20BalanceOf - Gets the balance of the given account at the given contract address.\n * @param options.state - Initial state to set on this controller.\n * @param options.messenger - The controller restricted messenger.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n tokens = [],\n disabled = false,\n getERC20BalanceOf,\n messenger,\n state = {},\n }: TokenBalancesControllerOptions) {\n super({\n name: controllerName,\n metadata,\n messenger,\n state: {\n ...getDefaultTokenBalancesState(),\n ...state,\n },\n });\n\n this.#disabled = disabled;\n this.#interval = interval;\n this.#tokens = tokens;\n\n this.messagingSystem.subscribe(\n 'TokensController:stateChange',\n ({ tokens: newTokens, detectedTokens }) => {\n this.#tokens = [...newTokens, ...detectedTokens];\n this.updateBalances();\n },\n );\n\n this.#getERC20BalanceOf = getERC20BalanceOf;\n\n this.poll();\n }\n\n /**\n * Allows controller to update tracked tokens contract balances.\n */\n enable() {\n this.#disabled = false;\n }\n\n /**\n * Blocks controller from updating tracked tokens contract balances.\n */\n disable() {\n this.#disabled = true;\n }\n\n /**\n * Starts a new polling interval.\n *\n * @param interval - Polling interval used to fetch new token balances.\n */\n async poll(interval?: number): Promise<void> {\n if (interval) {\n this.#interval = interval;\n }\n\n if (this.#handle) {\n clearTimeout(this.#handle);\n }\n\n await safelyExecute(() => this.updateBalances());\n\n this.#handle = setTimeout(() => {\n this.poll(this.#interval);\n }, this.#interval);\n }\n\n /**\n * Updates balances for all tokens.\n */\n async updateBalances() {\n if (this.#disabled) {\n return;\n }\n\n const newContractBalances: ContractBalances = {};\n for (const token of this.#tokens) {\n const { address } = token;\n const { selectedAddress } = this.messagingSystem.call(\n 'PreferencesController:getState',\n );\n try {\n newContractBalances[address] = toHex(\n await this.#getERC20BalanceOf(address, selectedAddress),\n );\n token.balanceError = null;\n } catch (error) {\n newContractBalances[address] = toHex(0);\n token.balanceError = error;\n }\n }\n\n this.update((state) => {\n state.contractBalances = newContractBalances;\n });\n }\n}\n\nexport default TokenBalancesController;\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import {
2
+ TokenBalancesController,
3
+ TokenBalancesController_default,
4
+ getDefaultTokenBalancesState
5
+ } from "./chunk-4LY47RPI.mjs";
6
+ import "./chunk-XUI43LEZ.mjs";
7
+ export {
8
+ TokenBalancesController,
9
+ TokenBalancesController_default as default,
10
+ getDefaultTokenBalancesState
11
+ };
12
+ //# sourceMappingURL=TokenBalancesController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,363 +1,17 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
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 __rest = (this && this.__rest) || function (s, e) {
23
- var t = {};
24
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25
- t[p] = s[p];
26
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
27
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
29
- t[p[i]] = s[p[i]];
30
- }
31
- return t;
32
- };
33
- var __importDefault = (this && this.__importDefault) || function (mod) {
34
- return (mod && mod.__esModule) ? mod : { "default": mod };
35
- };
36
- var _TokenDetectionController_instances, _TokenDetectionController_intervalId, _TokenDetectionController_selectedAddress, _TokenDetectionController_networkClientId, _TokenDetectionController_tokenList, _TokenDetectionController_disabled, _TokenDetectionController_isUnlocked, _TokenDetectionController_isDetectionEnabledFromPreferences, _TokenDetectionController_isDetectionEnabledForNetwork, _TokenDetectionController_getBalancesInSingleCall, _TokenDetectionController_trackMetaMetricsEvent, _TokenDetectionController_registerEventListeners, _TokenDetectionController_stopPolling, _TokenDetectionController_startPolling, _TokenDetectionController_getCorrectChainIdAndNetworkClientId, _TokenDetectionController_restartTokenDetection, _TokenDetectionController_getSlicesOfTokensToDetect, _TokenDetectionController_addDetectedTokens;
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.TokenDetectionController = exports.controllerName = exports.STATIC_MAINNET_TOKEN_LIST = exports.isEqualCaseInsensitive = void 0;
39
- const contract_metadata_1 = __importDefault(require("@metamask/contract-metadata"));
40
- const controller_utils_1 = require("@metamask/controller-utils");
41
- const polling_controller_1 = require("@metamask/polling-controller");
42
- const assetsUtil_1 = require("./assetsUtil");
43
- const DEFAULT_INTERVAL = 180000;
44
- /**
45
- * Compare 2 given strings and return boolean
46
- * eg: "foo" and "FOO" => true
47
- * eg: "foo" and "bar" => false
48
- * eg: "foo" and 123 => false
49
- *
50
- * @param value1 - first string to compare
51
- * @param value2 - first string to compare
52
- * @returns true if 2 strings are identical when they are lowercase
53
- */
54
- function isEqualCaseInsensitive(value1, value2) {
55
- if (typeof value1 !== 'string' || typeof value2 !== 'string') {
56
- return false;
57
- }
58
- return value1.toLowerCase() === value2.toLowerCase();
59
- }
60
- exports.isEqualCaseInsensitive = isEqualCaseInsensitive;
61
- exports.STATIC_MAINNET_TOKEN_LIST = Object.entries(contract_metadata_1.default).reduce((acc, [base, contract]) => {
62
- const { logo, erc20, erc721 } = contract, tokenMetadata = __rest(contract, ["logo", "erc20", "erc721"]);
63
- return Object.assign(Object.assign({}, acc), { [base.toLowerCase()]: Object.assign(Object.assign({}, tokenMetadata), { address: base.toLowerCase(), iconUrl: `images/contract/${logo}`, aggregators: [] }) });
64
- }, {});
65
- exports.controllerName = 'TokenDetectionController';
66
- /**
67
- * Controller that passively polls on a set interval for Tokens auto detection
68
- * @property intervalId - Polling interval used to fetch new token rates
69
- * @property selectedAddress - Vault selected address
70
- * @property networkClientId - The network client ID of the current selected network
71
- * @property disabled - Boolean to track if network requests are blocked
72
- * @property isUnlocked - Boolean to track if the keyring state is unlocked
73
- * @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController
74
- * @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network
75
- */
76
- class TokenDetectionController extends polling_controller_1.StaticIntervalPollingController {
77
- /**
78
- * Creates a TokenDetectionController instance.
79
- *
80
- * @param options - The controller options.
81
- * @param options.messenger - The controller messaging system.
82
- * @param options.disabled - If set to true, all network requests are blocked.
83
- * @param options.interval - Polling interval used to fetch new token rates
84
- * @param options.selectedAddress - Vault selected address
85
- * @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
86
- * @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
87
- */
88
- constructor({ selectedAddress, interval = DEFAULT_INTERVAL, disabled = true, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, }) {
89
- super({
90
- name: exports.controllerName,
91
- messenger,
92
- state: {},
93
- metadata: {},
94
- });
95
- _TokenDetectionController_instances.add(this);
96
- _TokenDetectionController_intervalId.set(this, void 0);
97
- _TokenDetectionController_selectedAddress.set(this, void 0);
98
- _TokenDetectionController_networkClientId.set(this, void 0);
99
- _TokenDetectionController_tokenList.set(this, {});
100
- _TokenDetectionController_disabled.set(this, void 0);
101
- _TokenDetectionController_isUnlocked.set(this, void 0);
102
- _TokenDetectionController_isDetectionEnabledFromPreferences.set(this, void 0);
103
- _TokenDetectionController_isDetectionEnabledForNetwork.set(this, void 0);
104
- _TokenDetectionController_getBalancesInSingleCall.set(this, void 0);
105
- _TokenDetectionController_trackMetaMetricsEvent.set(this, void 0);
106
- __classPrivateFieldSet(this, _TokenDetectionController_disabled, disabled, "f");
107
- this.setIntervalLength(interval);
108
- __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, selectedAddress !== null && selectedAddress !== void 0 ? selectedAddress : this.messagingSystem.call('AccountsController:getSelectedAccount')
109
- .address, "f");
110
- const { chainId, networkClientId } = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainIdAndNetworkClientId).call(this);
111
- __classPrivateFieldSet(this, _TokenDetectionController_networkClientId, networkClientId, "f");
112
- const { useTokenDetection: defaultUseTokenDetection } = this.messagingSystem.call('PreferencesController:getState');
113
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, defaultUseTokenDetection, "f");
114
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledForNetwork, (0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(chainId), "f");
115
- __classPrivateFieldSet(this, _TokenDetectionController_getBalancesInSingleCall, getBalancesInSingleCall, "f");
116
- __classPrivateFieldSet(this, _TokenDetectionController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
117
- const { isUnlocked } = this.messagingSystem.call('KeyringController:getState');
118
- __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, isUnlocked, "f");
119
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_registerEventListeners).call(this);
120
- }
121
- /**
122
- * Allows controller to make active and passive polling requests
123
- */
124
- enable() {
125
- __classPrivateFieldSet(this, _TokenDetectionController_disabled, false, "f");
126
- }
127
- /**
128
- * Blocks controller from making network calls
129
- */
130
- disable() {
131
- __classPrivateFieldSet(this, _TokenDetectionController_disabled, true, "f");
132
- }
133
- /**
134
- * Internal isActive state
135
- * @type {boolean}
136
- */
137
- get isActive() {
138
- return !__classPrivateFieldGet(this, _TokenDetectionController_disabled, "f") && __classPrivateFieldGet(this, _TokenDetectionController_isUnlocked, "f");
139
- }
140
- /**
141
- * Start polling for detected tokens.
142
- */
143
- start() {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- this.enable();
146
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_startPolling).call(this);
147
- });
148
- }
149
- /**
150
- * Stop polling for detected tokens.
151
- */
152
- stop() {
153
- this.disable();
154
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
155
- }
156
- _executePoll(networkClientId, options) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- if (!this.isActive) {
159
- return;
160
- }
161
- yield this.detectTokens({
162
- networkClientId,
163
- selectedAddress: options.address,
164
- });
165
- });
166
- }
167
- /**
168
- * For each token in the token list provided by the TokenListController, checks the token's balance for the selected account address on the active network.
169
- * On mainnet, if token detection is disabled in preferences, ERC20 token auto detection will be triggered for each contract address in the legacy token list from the @metamask/contract-metadata repo.
170
- *
171
- * @param options - Options for token detection.
172
- * @param options.networkClientId - The ID of the network client to use.
173
- * @param options.selectedAddress - the selectedAddress against which to detect for token balances.
174
- */
175
- detectTokens({ networkClientId, selectedAddress, } = {}) {
176
- var _a, _b;
177
- return __awaiter(this, void 0, void 0, function* () {
178
- if (!this.isActive) {
179
- return;
180
- }
181
- const addressAgainstWhichToDetect = selectedAddress !== null && selectedAddress !== void 0 ? selectedAddress : __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f");
182
- const { chainId, networkClientId: selectedNetworkClientId } = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainIdAndNetworkClientId).call(this, networkClientId);
183
- const chainIdAgainstWhichToDetect = chainId;
184
- const networkClientIdAgainstWhichToDetect = selectedNetworkClientId;
185
- if (!(0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(chainIdAgainstWhichToDetect)) {
186
- return;
187
- }
188
- if (!__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") &&
189
- chainIdAgainstWhichToDetect !== controller_utils_1.ChainId.mainnet) {
190
- return;
191
- }
192
- const isTokenDetectionInactiveInMainnet = !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") &&
193
- chainIdAgainstWhichToDetect === controller_utils_1.ChainId.mainnet;
194
- const { tokensChainsCache } = this.messagingSystem.call('TokenListController:getState');
195
- __classPrivateFieldSet(this, _TokenDetectionController_tokenList, isTokenDetectionInactiveInMainnet
196
- ? exports.STATIC_MAINNET_TOKEN_LIST
197
- : (_b = (_a = tokensChainsCache[chainIdAgainstWhichToDetect]) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {}, "f");
198
- for (const tokensSlice of __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getSlicesOfTokensToDetect).call(this, {
199
- chainId: chainIdAgainstWhichToDetect,
200
- selectedAddress: addressAgainstWhichToDetect,
201
- })) {
202
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addDetectedTokens).call(this, {
203
- tokensSlice,
204
- selectedAddress: addressAgainstWhichToDetect,
205
- networkClientId: networkClientIdAgainstWhichToDetect,
206
- chainId: chainIdAgainstWhichToDetect,
207
- });
208
- }
209
- });
210
- }
211
- }
212
- exports.TokenDetectionController = TokenDetectionController;
213
- _TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_selectedAddress = new WeakMap(), _TokenDetectionController_networkClientId = new WeakMap(), _TokenDetectionController_tokenList = new WeakMap(), _TokenDetectionController_disabled = new WeakMap(), _TokenDetectionController_isUnlocked = new WeakMap(), _TokenDetectionController_isDetectionEnabledFromPreferences = new WeakMap(), _TokenDetectionController_isDetectionEnabledForNetwork = new WeakMap(), _TokenDetectionController_getBalancesInSingleCall = new WeakMap(), _TokenDetectionController_trackMetaMetricsEvent = new WeakMap(), _TokenDetectionController_instances = new WeakSet(), _TokenDetectionController_registerEventListeners = function _TokenDetectionController_registerEventListeners() {
214
- this.messagingSystem.subscribe('KeyringController:unlock', () => __awaiter(this, void 0, void 0, function* () {
215
- __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, true, "f");
216
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
217
- }));
218
- this.messagingSystem.subscribe('KeyringController:lock', () => {
219
- __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, false, "f");
220
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
221
- });
222
- this.messagingSystem.subscribe('TokenListController:stateChange', ({ tokenList }) => __awaiter(this, void 0, void 0, function* () {
223
- const hasTokens = Object.keys(tokenList).length;
224
- if (hasTokens) {
225
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
226
- }
227
- }));
228
- this.messagingSystem.subscribe('PreferencesController:stateChange', ({ selectedAddress: newSelectedAddress, useTokenDetection }) => __awaiter(this, void 0, void 0, function* () {
229
- const isSelectedAddressChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f") !== newSelectedAddress;
230
- const isDetectionChangedFromPreferences = __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") !== useTokenDetection;
231
- __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, newSelectedAddress, "f");
232
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, useTokenDetection, "f");
233
- if (useTokenDetection &&
234
- (isSelectedAddressChanged || isDetectionChangedFromPreferences)) {
235
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
236
- selectedAddress: __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f"),
237
- });
238
- }
239
- }));
240
- this.messagingSystem.subscribe('AccountsController:selectedAccountChange', ({ address: newSelectedAddress }) => __awaiter(this, void 0, void 0, function* () {
241
- const isSelectedAddressChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f") !== newSelectedAddress;
242
- if (isSelectedAddressChanged &&
243
- __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f")) {
244
- __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, newSelectedAddress, "f");
245
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
246
- selectedAddress: __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f"),
247
- });
248
- }
249
- }));
250
- this.messagingSystem.subscribe('NetworkController:networkDidChange', ({ selectedNetworkClientId }) => __awaiter(this, void 0, void 0, function* () {
251
- const isNetworkClientIdChanged = __classPrivateFieldGet(this, _TokenDetectionController_networkClientId, "f") !== selectedNetworkClientId;
252
- const { chainId: newChainId } = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainIdAndNetworkClientId).call(this, selectedNetworkClientId);
253
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledForNetwork, (0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(newChainId), "f");
254
- if (isNetworkClientIdChanged && __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledForNetwork, "f")) {
255
- __classPrivateFieldSet(this, _TokenDetectionController_networkClientId, selectedNetworkClientId, "f");
256
- yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
257
- networkClientId: __classPrivateFieldGet(this, _TokenDetectionController_networkClientId, "f"),
258
- });
259
- }
260
- }));
261
- }, _TokenDetectionController_stopPolling = function _TokenDetectionController_stopPolling() {
262
- if (__classPrivateFieldGet(this, _TokenDetectionController_intervalId, "f")) {
263
- clearInterval(__classPrivateFieldGet(this, _TokenDetectionController_intervalId, "f"));
264
- }
265
- }, _TokenDetectionController_startPolling = function _TokenDetectionController_startPolling() {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- if (!this.isActive) {
268
- return;
269
- }
270
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
271
- yield this.detectTokens();
272
- __classPrivateFieldSet(this, _TokenDetectionController_intervalId, setInterval(() => __awaiter(this, void 0, void 0, function* () {
273
- yield this.detectTokens();
274
- }), this.getIntervalLength()), "f");
275
- });
276
- }, _TokenDetectionController_getCorrectChainIdAndNetworkClientId = function _TokenDetectionController_getCorrectChainIdAndNetworkClientId(networkClientId) {
277
- if (networkClientId) {
278
- const networkConfiguration = this.messagingSystem.call('NetworkController:getNetworkConfigurationByNetworkClientId', networkClientId);
279
- if (networkConfiguration) {
280
- return {
281
- chainId: networkConfiguration.chainId,
282
- networkClientId,
283
- };
284
- }
285
- }
286
- const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
287
- const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
288
- return {
289
- chainId,
290
- networkClientId: selectedNetworkClientId,
291
- };
292
- }, _TokenDetectionController_restartTokenDetection = function _TokenDetectionController_restartTokenDetection({ selectedAddress, networkClientId, } = {}) {
293
- return __awaiter(this, void 0, void 0, function* () {
294
- yield this.detectTokens({
295
- networkClientId,
296
- selectedAddress,
297
- });
298
- this.setIntervalLength(DEFAULT_INTERVAL);
299
- });
300
- }, _TokenDetectionController_getSlicesOfTokensToDetect = function _TokenDetectionController_getSlicesOfTokensToDetect({ chainId, selectedAddress, }) {
301
- const { allTokens, allDetectedTokens, allIgnoredTokens } = this.messagingSystem.call('TokensController:getState');
302
- const [tokensAddresses, detectedTokensAddresses, ignoredTokensAddresses] = [
303
- allTokens,
304
- allDetectedTokens,
305
- allIgnoredTokens,
306
- ].map((tokens) => {
307
- var _a, _b;
308
- return ((_b = (_a = tokens[chainId]) === null || _a === void 0 ? void 0 : _a[selectedAddress]) !== null && _b !== void 0 ? _b : []).map((value) => typeof value === 'string' ? value : value.address);
309
- });
310
- const tokensToDetect = [];
311
- for (const tokenAddress of Object.keys(__classPrivateFieldGet(this, _TokenDetectionController_tokenList, "f"))) {
312
- if ([
313
- tokensAddresses,
314
- detectedTokensAddresses,
315
- ignoredTokensAddresses,
316
- ].every((addresses) => !addresses.find((address) => isEqualCaseInsensitive(address, tokenAddress)))) {
317
- tokensToDetect.push(tokenAddress);
318
- }
319
- }
320
- const slicesOfTokensToDetect = [];
321
- for (let i = 0, size = 1000; i < tokensToDetect.length; i += size) {
322
- slicesOfTokensToDetect.push(tokensToDetect.slice(i, i + size));
323
- }
324
- return slicesOfTokensToDetect;
325
- }, _TokenDetectionController_addDetectedTokens = function _TokenDetectionController_addDetectedTokens({ tokensSlice, selectedAddress, networkClientId, chainId, }) {
326
- return __awaiter(this, void 0, void 0, function* () {
327
- yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
328
- const balances = yield __classPrivateFieldGet(this, _TokenDetectionController_getBalancesInSingleCall, "f").call(this, selectedAddress, tokensSlice, networkClientId);
329
- const tokensWithBalance = [];
330
- const eventTokensDetails = [];
331
- for (const nonZeroTokenAddress of Object.keys(balances)) {
332
- const { decimals, symbol, aggregators, iconUrl, name } = __classPrivateFieldGet(this, _TokenDetectionController_tokenList, "f")[nonZeroTokenAddress];
333
- eventTokensDetails.push(`${symbol} - ${nonZeroTokenAddress}`);
334
- tokensWithBalance.push({
335
- address: nonZeroTokenAddress,
336
- decimals,
337
- symbol,
338
- aggregators,
339
- image: iconUrl,
340
- isERC721: false,
341
- name,
342
- });
343
- }
344
- if (tokensWithBalance.length) {
345
- __classPrivateFieldGet(this, _TokenDetectionController_trackMetaMetricsEvent, "f").call(this, {
346
- event: 'Token Detected',
347
- category: 'Wallet',
348
- properties: {
349
- tokens: eventTokensDetails,
350
- token_standard: 'ERC20',
351
- asset_type: 'TOKEN',
352
- },
353
- });
354
- yield this.messagingSystem.call('TokensController:addDetectedTokens', tokensWithBalance, {
355
- selectedAddress,
356
- chainId,
357
- });
358
- }
359
- }));
360
- });
361
- };
362
- exports.default = TokenDetectionController;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+ var _chunkPRIXT2R6js = require('./chunk-PRIXT2R6.js');
8
+ require('./chunk-YD3NRMFC.js');
9
+ require('./chunk-Z4BLTVTB.js');
10
+
11
+
12
+
13
+
14
+
15
+
16
+ exports.STATIC_MAINNET_TOKEN_LIST = _chunkPRIXT2R6js.STATIC_MAINNET_TOKEN_LIST; exports.TokenDetectionController = _chunkPRIXT2R6js.TokenDetectionController; exports.controllerName = _chunkPRIXT2R6js.controllerName; exports.default = _chunkPRIXT2R6js.TokenDetectionController_default; exports.isEqualCaseInsensitive = _chunkPRIXT2R6js.isEqualCaseInsensitive;
363
17
  //# sourceMappingURL=TokenDetectionController.js.map