@metamask/assets-controllers 37.0.0 → 38.0.1
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 +50 -1
- package/dist/AccountTrackerController.cjs +245 -0
- package/dist/AccountTrackerController.cjs.map +1 -0
- package/dist/{types/AccountTrackerController.d.ts → AccountTrackerController.d.cts} +6 -6
- package/dist/AccountTrackerController.d.cts.map +1 -0
- package/dist/AccountTrackerController.d.mts +112 -0
- package/dist/AccountTrackerController.d.mts.map +1 -0
- package/dist/AccountTrackerController.mjs +244 -8
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +389 -0
- package/dist/AssetsContractController.cjs.map +1 -0
- package/dist/{types/AssetsContractController.d.ts → AssetsContractController.d.cts} +10 -9
- package/dist/AssetsContractController.d.cts.map +1 -0
- package/dist/AssetsContractController.d.mts +277 -0
- package/dist/AssetsContractController.d.mts.map +1 -0
- package/dist/AssetsContractController.mjs +387 -16
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs +156 -0
- package/dist/CurrencyRateController.cjs.map +1 -0
- package/dist/{types/CurrencyRateController.d.ts → CurrencyRateController.d.cts} +5 -5
- package/dist/CurrencyRateController.d.cts.map +1 -0
- package/dist/CurrencyRateController.d.mts +80 -0
- package/dist/CurrencyRateController.d.mts.map +1 -0
- package/dist/CurrencyRateController.mjs +150 -10
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/NftController.cjs +1159 -0
- package/dist/NftController.cjs.map +1 -0
- package/dist/{types/NftController.d.ts → NftController.d.cts} +11 -11
- package/dist/NftController.d.cts.map +1 -0
- package/dist/NftController.d.mts +424 -0
- package/dist/NftController.d.mts.map +1 -0
- package/dist/NftController.mjs +1156 -12
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +237 -0
- package/dist/NftDetectionController.cjs.map +1 -0
- package/dist/{types/NftDetectionController.d.ts → NftDetectionController.d.cts} +9 -9
- package/dist/NftDetectionController.d.cts.map +1 -0
- package/dist/NftDetectionController.d.mts +368 -0
- package/dist/NftDetectionController.d.mts.map +1 -0
- package/dist/NftDetectionController.mjs +231 -14
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/RatesController.cjs +189 -0
- package/dist/RatesController/RatesController.cjs.map +1 -0
- package/dist/{types/RatesController/RatesController.d.ts → RatesController/RatesController.d.cts} +5 -5
- package/dist/RatesController/RatesController.d.cts.map +1 -0
- package/dist/RatesController/RatesController.d.mts +44 -0
- package/dist/RatesController/RatesController.d.mts.map +1 -0
- package/dist/RatesController/RatesController.mjs +183 -12
- package/dist/RatesController/RatesController.mjs.map +1 -1
- package/dist/RatesController/index.cjs +7 -0
- package/dist/RatesController/index.cjs.map +1 -0
- package/dist/{types/RatesController/index.d.ts → RatesController/index.d.cts} +3 -3
- package/dist/RatesController/index.d.cts.map +1 -0
- package/dist/RatesController/index.d.mts +3 -0
- package/dist/RatesController/index.d.mts.map +1 -0
- package/dist/RatesController/index.mjs +1 -12
- package/dist/RatesController/index.mjs.map +1 -1
- package/dist/RatesController/types.cjs +3 -0
- package/dist/RatesController/types.cjs.map +1 -0
- package/dist/{types/RatesController/types.d.ts → RatesController/types.d.cts} +4 -4
- package/dist/RatesController/types.d.cts.map +1 -0
- package/dist/RatesController/types.d.mts +100 -0
- package/dist/RatesController/types.d.mts.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/Standards/ERC20Standard.cjs +124 -0
- package/dist/Standards/ERC20Standard.cjs.map +1 -0
- package/dist/{types/Standards/ERC20Standard.d.ts → Standards/ERC20Standard.d.cts} +3 -3
- package/dist/Standards/ERC20Standard.d.cts.map +1 -0
- package/dist/Standards/ERC20Standard.d.mts +49 -0
- package/dist/Standards/ERC20Standard.d.mts.map +1 -0
- package/dist/Standards/ERC20Standard.mjs +121 -8
- package/dist/Standards/ERC20Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +189 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts → Standards/NftStandards/ERC1155/ERC1155Standard.d.cts} +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts +95 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +184 -8
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +167 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC721/ERC721Standard.d.ts → Standards/NftStandards/ERC721/ERC721Standard.d.cts} +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts +89 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +162 -8
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +136 -0
- package/dist/TokenBalancesController.cjs.map +1 -0
- package/dist/{types/TokenBalancesController.d.ts → TokenBalancesController.d.cts} +7 -7
- package/dist/TokenBalancesController.d.cts.map +1 -0
- package/dist/TokenBalancesController.d.mts +82 -0
- package/dist/TokenBalancesController.d.mts.map +1 -0
- package/dist/TokenBalancesController.mjs +129 -10
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +369 -0
- package/dist/TokenDetectionController.cjs.map +1 -0
- package/dist/{types/TokenDetectionController.d.ts → TokenDetectionController.d.cts} +10 -10
- package/dist/TokenDetectionController.d.cts.map +1 -0
- package/dist/TokenDetectionController.d.mts +109 -0
- package/dist/TokenDetectionController.d.mts.map +1 -0
- package/dist/TokenDetectionController.mjs +366 -15
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +274 -0
- package/dist/TokenListController.cjs.map +1 -0
- package/dist/{types/TokenListController.d.ts → TokenListController.d.cts} +5 -5
- package/dist/TokenListController.d.cts.map +1 -0
- package/dist/TokenListController.d.mts +117 -0
- package/dist/TokenListController.d.mts.map +1 -0
- package/dist/TokenListController.mjs +267 -12
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +452 -0
- package/dist/TokenRatesController.cjs.map +1 -0
- package/dist/{types/TokenRatesController.d.ts → TokenRatesController.d.cts} +9 -9
- package/dist/TokenRatesController.d.cts.map +1 -0
- package/dist/TokenRatesController.d.mts +170 -0
- package/dist/TokenRatesController.d.mts.map +1 -0
- package/dist/TokenRatesController.mjs +446 -16
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokensController.cjs +678 -0
- package/dist/TokensController.cjs.map +1 -0
- package/dist/{types/TokensController.d.ts → TokensController.d.cts} +10 -10
- package/dist/TokensController.d.cts.map +1 -0
- package/dist/TokensController.d.mts +165 -0
- package/dist/TokensController.d.mts.map +1 -0
- package/dist/TokensController.mjs +675 -14
- package/dist/TokensController.mjs.map +1 -1
- package/dist/assetsUtil.cjs +358 -0
- package/dist/assetsUtil.cjs.map +1 -0
- package/dist/{types/assetsUtil.d.ts → assetsUtil.d.cts} +7 -7
- package/dist/assetsUtil.d.cts.map +1 -0
- package/dist/assetsUtil.d.mts +177 -0
- package/dist/assetsUtil.d.mts.map +1 -0
- package/dist/assetsUtil.mjs +343 -36
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/constants.cjs +10 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +6 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +6 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.cjs +119 -0
- package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -0
- package/dist/{types/crypto-compare-service/crypto-compare.d.ts → crypto-compare-service/crypto-compare.d.cts} +1 -1
- package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts +22 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +113 -9
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
- package/dist/crypto-compare-service/index.cjs +7 -0
- package/dist/crypto-compare-service/index.cjs.map +1 -0
- package/dist/crypto-compare-service/index.d.cts +2 -0
- package/dist/crypto-compare-service/index.d.cts.map +1 -0
- package/dist/crypto-compare-service/index.d.mts +2 -0
- package/dist/crypto-compare-service/index.d.mts.map +1 -0
- package/dist/crypto-compare-service/index.mjs +1 -10
- package/dist/crypto-compare-service/index.mjs.map +1 -1
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +24 -24
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -80
- package/dist/index.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs +3 -0
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -0
- package/dist/{types/token-prices-service/abstract-token-prices-service.d.ts → token-prices-service/abstract-token-prices-service.d.cts} +2 -2
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +79 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +352 -0
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -0
- package/dist/{types/token-prices-service/codefi-v2.d.ts → token-prices-service/codefi-v2.d.cts} +3 -3
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -0
- package/dist/token-prices-service/codefi-v2.d.mts +97 -0
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -0
- package/dist/token-prices-service/codefi-v2.mjs +347 -12
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-prices-service/index.cjs +7 -0
- package/dist/token-prices-service/index.cjs.map +1 -0
- package/dist/token-prices-service/index.d.cts +3 -0
- package/dist/token-prices-service/index.d.cts.map +1 -0
- package/dist/token-prices-service/index.d.mts +3 -0
- package/dist/token-prices-service/index.d.mts.map +1 -0
- package/dist/token-prices-service/index.mjs +1 -10
- package/dist/token-prices-service/index.mjs.map +1 -1
- package/dist/token-service.cjs +130 -0
- package/dist/token-service.cjs.map +1 -0
- package/dist/{types/token-service.d.ts → token-service.d.cts} +2 -2
- package/dist/token-service.d.cts.map +1 -0
- package/dist/token-service.d.mts +31 -0
- package/dist/token-service.d.mts.map +1 -0
- package/dist/token-service.mjs +124 -14
- package/dist/token-service.mjs.map +1 -1
- package/package.json +24 -18
- package/dist/AccountTrackerController.js +0 -10
- package/dist/AccountTrackerController.js.map +0 -1
- package/dist/AssetsContractController.js +0 -18
- package/dist/AssetsContractController.js.map +0 -1
- package/dist/CurrencyRateController.js +0 -12
- package/dist/CurrencyRateController.js.map +0 -1
- package/dist/NftController.js +0 -14
- package/dist/NftController.js.map +0 -1
- package/dist/NftDetectionController.js +0 -16
- package/dist/NftDetectionController.js.map +0 -1
- package/dist/RatesController/RatesController.js +0 -14
- package/dist/RatesController/RatesController.js.map +0 -1
- package/dist/RatesController/index.js +0 -13
- package/dist/RatesController/index.js.map +0 -1
- package/dist/RatesController/types.js +0 -1
- package/dist/RatesController/types.js.map +0 -1
- package/dist/Standards/ERC20Standard.js +0 -9
- package/dist/Standards/ERC20Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +0 -1
- package/dist/TokenBalancesController.js +0 -12
- package/dist/TokenBalancesController.js.map +0 -1
- package/dist/TokenDetectionController.js +0 -17
- package/dist/TokenDetectionController.js.map +0 -1
- package/dist/TokenListController.js +0 -14
- package/dist/TokenListController.js.map +0 -1
- package/dist/TokenRatesController.js +0 -18
- package/dist/TokenRatesController.js.map +0 -1
- package/dist/TokensController.js +0 -16
- package/dist/TokensController.js.map +0 -1
- package/dist/assetsUtil.js +0 -38
- package/dist/assetsUtil.js.map +0 -1
- package/dist/chunk-27KOXCQK.mjs +0 -1
- package/dist/chunk-27KOXCQK.mjs.map +0 -1
- package/dist/chunk-2TZK6YZA.js +0 -1405
- package/dist/chunk-2TZK6YZA.js.map +0 -1
- package/dist/chunk-3LPQTUGG.js +0 -434
- package/dist/chunk-3LPQTUGG.js.map +0 -1
- package/dist/chunk-3QDXAE2D.mjs +0 -178
- package/dist/chunk-3QDXAE2D.mjs.map +0 -1
- package/dist/chunk-46KUC5FH.mjs +0 -434
- package/dist/chunk-46KUC5FH.mjs.map +0 -1
- package/dist/chunk-54JUUBXY.mjs +0 -813
- package/dist/chunk-54JUUBXY.mjs.map +0 -1
- package/dist/chunk-5QLC2MHV.js +0 -215
- package/dist/chunk-5QLC2MHV.js.map +0 -1
- package/dist/chunk-7K6PSEAA.js +0 -1
- package/dist/chunk-7K6PSEAA.js.map +0 -1
- package/dist/chunk-ADJ3IFJH.js +0 -813
- package/dist/chunk-ADJ3IFJH.js.map +0 -1
- package/dist/chunk-AX522TDL.mjs +0 -85
- package/dist/chunk-AX522TDL.mjs.map +0 -1
- package/dist/chunk-BBCZM5P4.js +0 -300
- package/dist/chunk-BBCZM5P4.js.map +0 -1
- package/dist/chunk-BZEAPSD5.mjs +0 -215
- package/dist/chunk-BZEAPSD5.mjs.map +0 -1
- package/dist/chunk-C7LNCQXM.mjs +0 -300
- package/dist/chunk-C7LNCQXM.mjs.map +0 -1
- package/dist/chunk-CN53OZAM.mjs +0 -428
- package/dist/chunk-CN53OZAM.mjs.map +0 -1
- package/dist/chunk-CP3HC7AQ.mjs +0 -12
- package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
- package/dist/chunk-CUFSPB7T.mjs +0 -530
- package/dist/chunk-CUFSPB7T.mjs.map +0 -1
- package/dist/chunk-F6L3DFOZ.js +0 -204
- package/dist/chunk-F6L3DFOZ.js.map +0 -1
- package/dist/chunk-GHG3DOUK.js +0 -428
- package/dist/chunk-GHG3DOUK.js.map +0 -1
- package/dist/chunk-HJ5GXVDT.mjs +0 -157
- package/dist/chunk-HJ5GXVDT.mjs.map +0 -1
- package/dist/chunk-HVOIBGYN.js +0 -282
- package/dist/chunk-HVOIBGYN.js.map +0 -1
- package/dist/chunk-ISK2VSBB.js +0 -178
- package/dist/chunk-ISK2VSBB.js.map +0 -1
- package/dist/chunk-JCR4H6YL.js +0 -115
- package/dist/chunk-JCR4H6YL.js.map +0 -1
- package/dist/chunk-JJX7TMH5.mjs +0 -135
- package/dist/chunk-JJX7TMH5.mjs.map +0 -1
- package/dist/chunk-JTXPJ6TK.mjs +0 -68
- package/dist/chunk-JTXPJ6TK.mjs.map +0 -1
- package/dist/chunk-JYHAAA6W.mjs +0 -1
- package/dist/chunk-JYHAAA6W.mjs.map +0 -1
- package/dist/chunk-K7A3EOIM.js +0 -85
- package/dist/chunk-K7A3EOIM.js.map +0 -1
- package/dist/chunk-KPBNX6GP.mjs +0 -215
- package/dist/chunk-KPBNX6GP.mjs.map +0 -1
- package/dist/chunk-MZI3SDQN.js +0 -215
- package/dist/chunk-MZI3SDQN.js.map +0 -1
- package/dist/chunk-OBUR4TXH.js +0 -1
- package/dist/chunk-OBUR4TXH.js.map +0 -1
- package/dist/chunk-RGHTNZQ6.js +0 -12
- package/dist/chunk-RGHTNZQ6.js.map +0 -1
- package/dist/chunk-S5CFNNOM.mjs +0 -115
- package/dist/chunk-S5CFNNOM.mjs.map +0 -1
- package/dist/chunk-SBWPU4VT.mjs +0 -204
- package/dist/chunk-SBWPU4VT.mjs.map +0 -1
- package/dist/chunk-SK2B36Q4.mjs +0 -1405
- package/dist/chunk-SK2B36Q4.mjs.map +0 -1
- package/dist/chunk-T5ZX5BV7.js +0 -157
- package/dist/chunk-T5ZX5BV7.js.map +0 -1
- package/dist/chunk-TFLYM4PY.mjs +0 -291
- package/dist/chunk-TFLYM4PY.mjs.map +0 -1
- package/dist/chunk-TTH3ES66.mjs +0 -1
- package/dist/chunk-TTH3ES66.mjs.map +0 -1
- package/dist/chunk-V6DNVROD.js +0 -348
- package/dist/chunk-V6DNVROD.js.map +0 -1
- package/dist/chunk-X2HRAVDO.js +0 -530
- package/dist/chunk-X2HRAVDO.js.map +0 -1
- package/dist/chunk-XC3SOOGC.js +0 -1
- package/dist/chunk-XC3SOOGC.js.map +0 -1
- package/dist/chunk-XQO3EG4J.mjs +0 -348
- package/dist/chunk-XQO3EG4J.mjs.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-YGGUAMHV.js +0 -135
- package/dist/chunk-YGGUAMHV.js.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/chunk-Z7RMCHD4.mjs +0 -282
- package/dist/chunk-Z7RMCHD4.mjs.map +0 -1
- package/dist/chunk-ZAR4BIOC.js +0 -291
- package/dist/chunk-ZAR4BIOC.js.map +0 -1
- package/dist/chunk-ZG5MS2TO.js +0 -68
- package/dist/chunk-ZG5MS2TO.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/crypto-compare-service/crypto-compare.js +0 -10
- package/dist/crypto-compare-service/crypto-compare.js.map +0 -1
- package/dist/crypto-compare-service/index.js +0 -11
- package/dist/crypto-compare-service/index.js.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js.map +0 -1
- package/dist/token-prices-service/codefi-v2.js +0 -14
- package/dist/token-prices-service/codefi-v2.js.map +0 -1
- package/dist/token-prices-service/index.js +0 -11
- package/dist/token-prices-service/index.js.map +0 -1
- package/dist/token-service.js +0 -15
- package/dist/token-service.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/AccountTrackerController.d.ts.map +0 -1
- package/dist/types/AssetsContractController.d.ts.map +0 -1
- package/dist/types/CurrencyRateController.d.ts.map +0 -1
- package/dist/types/NftController.d.ts.map +0 -1
- package/dist/types/NftDetectionController.d.ts.map +0 -1
- package/dist/types/RatesController/RatesController.d.ts.map +0 -1
- package/dist/types/RatesController/index.d.ts.map +0 -1
- package/dist/types/RatesController/types.d.ts.map +0 -1
- package/dist/types/Standards/ERC20Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
- package/dist/types/TokenBalancesController.d.ts.map +0 -1
- package/dist/types/TokenDetectionController.d.ts.map +0 -1
- package/dist/types/TokenListController.d.ts.map +0 -1
- package/dist/types/TokenRatesController.d.ts.map +0 -1
- package/dist/types/TokensController.d.ts.map +0 -1
- package/dist/types/assetsUtil.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/index.d.ts +0 -2
- package/dist/types/crypto-compare-service/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +0 -1
- package/dist/types/token-prices-service/index.d.ts +0 -3
- package/dist/types/token-prices-service/index.d.ts.map +0 -1
- package/dist/types/token-service.d.ts.map +0 -1
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _NftController_instances, _NftController_mutex, _NftController_selectedAccountId, _NftController_chainId, _NftController_ipfsGateway, _NftController_openSeaEnabled, _NftController_useIpfsSubdomains, _NftController_isIpfsGatewayEnabled, _NftController_onNftAdded, _NftController_onNetworkControllerNetworkDidChange, _NftController_onPreferencesControllerStateChange, _NftController_onSelectedAccountChange, _NftController_updateNestedNftState, _NftController_getNftCollectionApi, _NftController_getNftInformationFromApi, _NftController_getNftInformationFromTokenURI, _NftController_getNftURIAndStandard, _NftController_getNftInformation, _NftController_getNftContractInformationFromContract, _NftController_getNftContractInformation, _NftController_addIndividualNft, _NftController_addNftContract, _NftController_removeAndIgnoreIndividualNft, _NftController_removeIndividualNft, _NftController_removeNftContract, _NftController_validateWatchNft, _NftController_getCorrectChainId, _NftController_getAddressOrSelectedAddress, _NftController_updateNftUpdateForAccount;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NftController = exports.getDefaultNftControllerState = void 0;
|
|
19
|
+
const address_1 = require("@ethersproject/address");
|
|
20
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
21
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
22
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
23
|
+
const utils_1 = require("@metamask/utils");
|
|
24
|
+
const async_mutex_1 = require("async-mutex");
|
|
25
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
|
+
const uuid_1 = require("uuid");
|
|
27
|
+
const assetsUtil_1 = require("./assetsUtil.cjs");
|
|
28
|
+
const constants_1 = require("./constants.cjs");
|
|
29
|
+
const nftControllerMetadata = {
|
|
30
|
+
allNftContracts: { persist: true, anonymous: false },
|
|
31
|
+
allNfts: { persist: true, anonymous: false },
|
|
32
|
+
ignoredNfts: { persist: true, anonymous: false },
|
|
33
|
+
};
|
|
34
|
+
const ALL_NFTS_STATE_KEY = 'allNfts';
|
|
35
|
+
const ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';
|
|
36
|
+
/**
|
|
37
|
+
* The name of the {@link NftController}.
|
|
38
|
+
*/
|
|
39
|
+
const controllerName = 'NftController';
|
|
40
|
+
const getDefaultNftControllerState = () => ({
|
|
41
|
+
allNftContracts: {},
|
|
42
|
+
allNfts: {},
|
|
43
|
+
ignoredNfts: [],
|
|
44
|
+
});
|
|
45
|
+
exports.getDefaultNftControllerState = getDefaultNftControllerState;
|
|
46
|
+
/**
|
|
47
|
+
* Controller that stores assets and exposes convenience methods
|
|
48
|
+
*/
|
|
49
|
+
class NftController extends base_controller_1.BaseController {
|
|
50
|
+
/**
|
|
51
|
+
* Creates an NftController instance.
|
|
52
|
+
*
|
|
53
|
+
* @param options - The controller options.
|
|
54
|
+
* @param options.chainId - The chain ID of the current network.
|
|
55
|
+
* @param options.ipfsGateway - The configured IPFS gateway.
|
|
56
|
+
* @param options.openSeaEnabled - Controls whether the OpenSea API is used.
|
|
57
|
+
* @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used.
|
|
58
|
+
* @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.
|
|
59
|
+
* @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data
|
|
60
|
+
* for tracking the NFT added event.
|
|
61
|
+
* @param options.messenger - The controller messenger.
|
|
62
|
+
* @param options.state - Initial state to set on this controller.
|
|
63
|
+
*/
|
|
64
|
+
constructor({ chainId: initialChainId, ipfsGateway = controller_utils_1.IPFS_DEFAULT_GATEWAY_URL, openSeaEnabled = false, useIpfsSubdomains = true, isIpfsGatewayEnabled = true, onNftAdded, messenger, state = {}, }) {
|
|
65
|
+
super({
|
|
66
|
+
name: controllerName,
|
|
67
|
+
metadata: nftControllerMetadata,
|
|
68
|
+
messenger,
|
|
69
|
+
state: {
|
|
70
|
+
...(0, exports.getDefaultNftControllerState)(),
|
|
71
|
+
...state,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
_NftController_instances.add(this);
|
|
75
|
+
_NftController_mutex.set(this, new async_mutex_1.Mutex());
|
|
76
|
+
_NftController_selectedAccountId.set(this, void 0);
|
|
77
|
+
_NftController_chainId.set(this, void 0);
|
|
78
|
+
_NftController_ipfsGateway.set(this, void 0);
|
|
79
|
+
_NftController_openSeaEnabled.set(this, void 0);
|
|
80
|
+
_NftController_useIpfsSubdomains.set(this, void 0);
|
|
81
|
+
_NftController_isIpfsGatewayEnabled.set(this, void 0);
|
|
82
|
+
_NftController_onNftAdded.set(this, void 0);
|
|
83
|
+
__classPrivateFieldSet(this, _NftController_selectedAccountId, this.messagingSystem.call('AccountsController:getSelectedAccount').id, "f");
|
|
84
|
+
__classPrivateFieldSet(this, _NftController_chainId, initialChainId, "f");
|
|
85
|
+
__classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
|
|
86
|
+
__classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
|
|
87
|
+
__classPrivateFieldSet(this, _NftController_useIpfsSubdomains, useIpfsSubdomains, "f");
|
|
88
|
+
__classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
|
|
89
|
+
__classPrivateFieldSet(this, _NftController_onNftAdded, onNftAdded, "f");
|
|
90
|
+
this.messagingSystem.subscribe('PreferencesController:stateChange',
|
|
91
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
93
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onPreferencesControllerStateChange).bind(this));
|
|
94
|
+
this.messagingSystem.subscribe('NetworkController:networkDidChange', __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onNetworkControllerNetworkDidChange).bind(this));
|
|
95
|
+
this.messagingSystem.subscribe('AccountsController:selectedEvmAccountChange',
|
|
96
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
98
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onSelectedAccountChange).bind(this));
|
|
99
|
+
}
|
|
100
|
+
getNftApi() {
|
|
101
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
103
|
+
return `${controller_utils_1.NFT_API_BASE_URL}/tokens`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Adds a new suggestedAsset to state. Parameters will be validated according to
|
|
107
|
+
* asset type being watched. A `<suggestedNftMeta.id>:pending` hub event will be emitted once added.
|
|
108
|
+
*
|
|
109
|
+
* @param asset - The asset to be watched. For now ERC721 and ERC1155 tokens are accepted.
|
|
110
|
+
* @param asset.address - The address of the asset contract.
|
|
111
|
+
* @param asset.tokenId - The ID of the asset.
|
|
112
|
+
* @param type - The asset type.
|
|
113
|
+
* @param origin - Domain origin to register the asset from.
|
|
114
|
+
* @param options - Options bag.
|
|
115
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
116
|
+
* @param options.userAddress - The address of the account where the NFT is being added.
|
|
117
|
+
* @returns Object containing a Promise resolving to the suggestedAsset address if accepted.
|
|
118
|
+
*/
|
|
119
|
+
async watchNft(asset, type, origin, { networkClientId, userAddress, } = {}) {
|
|
120
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
121
|
+
if (!addressToSearch) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_validateWatchNft).call(this, asset, type, addressToSearch);
|
|
125
|
+
const nftMetadata = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformation).call(this, asset.address, asset.tokenId, networkClientId);
|
|
126
|
+
if (nftMetadata.standard && nftMetadata.standard !== type) {
|
|
127
|
+
throw rpc_errors_1.rpcErrors.invalidInput(`Suggested NFT of type ${nftMetadata.standard} does not match received type ${type}`);
|
|
128
|
+
}
|
|
129
|
+
const suggestedNftMeta = {
|
|
130
|
+
asset: { ...asset, ...nftMetadata },
|
|
131
|
+
type,
|
|
132
|
+
id: (0, uuid_1.v4)(),
|
|
133
|
+
time: Date.now(),
|
|
134
|
+
interactingAddress: addressToSearch,
|
|
135
|
+
origin,
|
|
136
|
+
};
|
|
137
|
+
await this._requestApproval(suggestedNftMeta);
|
|
138
|
+
const { address, tokenId } = asset;
|
|
139
|
+
const { name, standard, description, image } = nftMetadata;
|
|
140
|
+
await this.addNft(address, tokenId, {
|
|
141
|
+
nftMetadata: {
|
|
142
|
+
name: name ?? null,
|
|
143
|
+
description: description ?? null,
|
|
144
|
+
image: image ?? null,
|
|
145
|
+
standard: standard ?? null,
|
|
146
|
+
},
|
|
147
|
+
userAddress,
|
|
148
|
+
source: constants_1.Source.Dapp,
|
|
149
|
+
networkClientId,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sets an OpenSea API key to retrieve NFT information.
|
|
154
|
+
*
|
|
155
|
+
* @param openSeaApiKey - OpenSea API key.
|
|
156
|
+
*/
|
|
157
|
+
setApiKey(openSeaApiKey) {
|
|
158
|
+
this.openSeaApiKey = openSeaApiKey;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.
|
|
162
|
+
*
|
|
163
|
+
* @param ownerAddress - User public address.
|
|
164
|
+
* @param nftAddress - NFT contract address.
|
|
165
|
+
* @param tokenId - NFT token ID.
|
|
166
|
+
* @param options - Options bag.
|
|
167
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
168
|
+
* @returns Promise resolving the NFT ownership.
|
|
169
|
+
*/
|
|
170
|
+
async isNftOwner(ownerAddress, nftAddress, tokenId, { networkClientId, } = {}) {
|
|
171
|
+
// Checks the ownership for ERC-721.
|
|
172
|
+
try {
|
|
173
|
+
const owner = await this.messagingSystem.call('AssetsContractController:getERC721OwnerOf', nftAddress, tokenId, networkClientId);
|
|
174
|
+
return ownerAddress.toLowerCase() === owner.toLowerCase();
|
|
175
|
+
// eslint-disable-next-line no-empty
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Ignore ERC-721 contract error
|
|
179
|
+
}
|
|
180
|
+
// Checks the ownership for ERC-1155.
|
|
181
|
+
try {
|
|
182
|
+
const balance = await this.messagingSystem.call('AssetsContractController:getERC1155BalanceOf', ownerAddress, nftAddress, tokenId, networkClientId);
|
|
183
|
+
return !balance.isZero();
|
|
184
|
+
// eslint-disable-next-line no-empty
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// Ignore ERC-1155 contract error
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question.`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Verifies currently selected address owns entered NFT address/tokenId combo and
|
|
193
|
+
* adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.
|
|
194
|
+
*
|
|
195
|
+
* @param address - Hex address of the NFT contract.
|
|
196
|
+
* @param tokenId - The NFT identifier.
|
|
197
|
+
* @param options - an object of arguments
|
|
198
|
+
* @param options.userAddress - The address of the current user.
|
|
199
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
200
|
+
* @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.
|
|
201
|
+
*/
|
|
202
|
+
async addNftVerifyOwnership(address, tokenId, { userAddress, networkClientId, source, } = {}) {
|
|
203
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
204
|
+
if (!(await this.isNftOwner(addressToSearch, address, tokenId, {
|
|
205
|
+
networkClientId,
|
|
206
|
+
}))) {
|
|
207
|
+
throw new Error('This NFT is not owned by the user');
|
|
208
|
+
}
|
|
209
|
+
await this.addNft(address, tokenId, {
|
|
210
|
+
networkClientId,
|
|
211
|
+
userAddress: addressToSearch,
|
|
212
|
+
source,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.
|
|
217
|
+
*
|
|
218
|
+
* @param tokenAddress - Hex address of the NFT contract.
|
|
219
|
+
* @param tokenId - The NFT identifier.
|
|
220
|
+
* @param options - an object of arguments
|
|
221
|
+
* @param options.nftMetadata - NFT optional metadata.
|
|
222
|
+
* @param options.userAddress - The address of the current user.
|
|
223
|
+
* @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.
|
|
224
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
225
|
+
* @returns Promise resolving to the current NFT list.
|
|
226
|
+
*/
|
|
227
|
+
async addNft(tokenAddress, tokenId, { nftMetadata, userAddress, source = constants_1.Source.Custom, networkClientId, } = {}) {
|
|
228
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
229
|
+
if (!addressToSearch) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
|
|
233
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
234
|
+
nftMetadata =
|
|
235
|
+
nftMetadata ||
|
|
236
|
+
(await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformation).call(this, checksumHexAddress, tokenId, networkClientId));
|
|
237
|
+
const newNftContracts = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_addNftContract).call(this, {
|
|
238
|
+
tokenAddress: checksumHexAddress,
|
|
239
|
+
userAddress: addressToSearch,
|
|
240
|
+
networkClientId,
|
|
241
|
+
source,
|
|
242
|
+
nftMetadata,
|
|
243
|
+
});
|
|
244
|
+
// If NFT contract was not added, do not add individual NFT
|
|
245
|
+
const nftContract = newNftContracts.find((contract) => contract.address.toLowerCase() === checksumHexAddress.toLowerCase());
|
|
246
|
+
// If NFT contract information, add individual NFT
|
|
247
|
+
if (nftContract) {
|
|
248
|
+
await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_addIndividualNft).call(this, checksumHexAddress, tokenId, nftMetadata, nftContract, chainId, addressToSearch, source);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Refetches NFT metadata and updates the state
|
|
253
|
+
*
|
|
254
|
+
* @param options - Options for refetching NFT metadata
|
|
255
|
+
* @param options.nfts - nfts to update metadata for.
|
|
256
|
+
* @param options.userAddress - The current user address
|
|
257
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
258
|
+
*/
|
|
259
|
+
async updateNftMetadata({ nfts, userAddress, networkClientId, }) {
|
|
260
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
261
|
+
const releaseLock = await __classPrivateFieldGet(this, _NftController_mutex, "f").acquire();
|
|
262
|
+
try {
|
|
263
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
264
|
+
const nftsWithChecksumAdr = nfts.map((nft) => {
|
|
265
|
+
return {
|
|
266
|
+
...nft,
|
|
267
|
+
address: (0, controller_utils_1.toChecksumHexAddress)(nft.address),
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
const nftMetadataResults = await Promise.all(nftsWithChecksumAdr.map(async (nft) => {
|
|
271
|
+
const resMetadata = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformation).call(this, nft.address, nft.tokenId, networkClientId);
|
|
272
|
+
return {
|
|
273
|
+
nft,
|
|
274
|
+
newMetadata: resMetadata,
|
|
275
|
+
};
|
|
276
|
+
}));
|
|
277
|
+
// We want to avoid updating the state if the state and fetched nft info are the same
|
|
278
|
+
const nftsWithDifferentMetadata = [];
|
|
279
|
+
const { allNfts } = this.state;
|
|
280
|
+
const stateNfts = allNfts[addressToSearch]?.[chainId] || [];
|
|
281
|
+
nftMetadataResults.forEach((singleNft) => {
|
|
282
|
+
const existingEntry = stateNfts.find((nft) => nft.address.toLowerCase() === singleNft.nft.address.toLowerCase() &&
|
|
283
|
+
nft.tokenId === singleNft.nft.tokenId);
|
|
284
|
+
if (existingEntry) {
|
|
285
|
+
const differentMetadata = (0, assetsUtil_1.compareNftMetadata)(singleNft.newMetadata, existingEntry);
|
|
286
|
+
if (differentMetadata) {
|
|
287
|
+
nftsWithDifferentMetadata.push(singleNft);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
if (nftsWithDifferentMetadata.length !== 0) {
|
|
292
|
+
nftsWithDifferentMetadata.forEach((elm) => this.updateNft(elm.nft, elm.newMetadata, addressToSearch, chainId));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
releaseLock();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Removes an NFT from the stored token list.
|
|
301
|
+
*
|
|
302
|
+
* @param address - Hex address of the NFT contract.
|
|
303
|
+
* @param tokenId - Token identifier of the NFT.
|
|
304
|
+
* @param options - an object of arguments
|
|
305
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
306
|
+
* @param options.userAddress - The address of the account where the NFT is being removed.
|
|
307
|
+
*/
|
|
308
|
+
removeNft(address, tokenId, { networkClientId, userAddress, } = {}) {
|
|
309
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
310
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
311
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
312
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeIndividualNft).call(this, checksumHexAddress, tokenId, {
|
|
313
|
+
chainId,
|
|
314
|
+
userAddress: addressToSearch,
|
|
315
|
+
});
|
|
316
|
+
const { allNfts } = this.state;
|
|
317
|
+
const nfts = allNfts[addressToSearch]?.[chainId] || [];
|
|
318
|
+
const remainingNft = nfts.find((nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase());
|
|
319
|
+
if (!remainingNft) {
|
|
320
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeNftContract).call(this, checksumHexAddress, {
|
|
321
|
+
chainId,
|
|
322
|
+
userAddress: addressToSearch,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Removes an NFT from the stored token list and saves it in ignored NFTs list.
|
|
328
|
+
*
|
|
329
|
+
* @param address - Hex address of the NFT contract.
|
|
330
|
+
* @param tokenId - Token identifier of the NFT.
|
|
331
|
+
* @param options - an object of arguments
|
|
332
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
333
|
+
* @param options.userAddress - The address of the account where the NFT is being removed.
|
|
334
|
+
*/
|
|
335
|
+
removeAndIgnoreNft(address, tokenId, { networkClientId, userAddress, } = {}) {
|
|
336
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
337
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
338
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
339
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeAndIgnoreIndividualNft).call(this, checksumHexAddress, tokenId, {
|
|
340
|
+
chainId,
|
|
341
|
+
userAddress: addressToSearch,
|
|
342
|
+
});
|
|
343
|
+
const { allNfts } = this.state;
|
|
344
|
+
const nfts = allNfts[addressToSearch]?.[chainId] || [];
|
|
345
|
+
const remainingNft = nfts.find((nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase());
|
|
346
|
+
if (!remainingNft) {
|
|
347
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeNftContract).call(this, checksumHexAddress, {
|
|
348
|
+
chainId,
|
|
349
|
+
userAddress: addressToSearch,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Removes all NFTs from the ignored list.
|
|
355
|
+
*/
|
|
356
|
+
clearIgnoredNfts() {
|
|
357
|
+
this.update((state) => {
|
|
358
|
+
state.ignoredNfts = [];
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Checks whether input NFT is still owned by the user
|
|
363
|
+
* And updates the isCurrentlyOwned value on the NFT object accordingly.
|
|
364
|
+
*
|
|
365
|
+
* @param nft - The NFT object to check and update.
|
|
366
|
+
* @param batch - A boolean indicating whether this method is being called as part of a batch or single update.
|
|
367
|
+
* @param accountParams - The userAddress and chainId to check ownership against
|
|
368
|
+
* @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account
|
|
369
|
+
* @param accountParams.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
370
|
+
* @returns the NFT with the updated isCurrentlyOwned value
|
|
371
|
+
*/
|
|
372
|
+
async checkAndUpdateSingleNftOwnershipStatus(nft, batch, { userAddress, networkClientId, } = {}) {
|
|
373
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
374
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
375
|
+
const { address, tokenId } = nft;
|
|
376
|
+
let isOwned = nft.isCurrentlyOwned;
|
|
377
|
+
try {
|
|
378
|
+
isOwned = await this.isNftOwner(addressToSearch, address, tokenId, {
|
|
379
|
+
networkClientId,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
// ignore error
|
|
384
|
+
// this will only throw an error 'Unable to verify ownership' in which case
|
|
385
|
+
// we want to keep the current value of isCurrentlyOwned for this flow.
|
|
386
|
+
}
|
|
387
|
+
const updatedNft = {
|
|
388
|
+
...nft,
|
|
389
|
+
isCurrentlyOwned: isOwned,
|
|
390
|
+
};
|
|
391
|
+
if (batch) {
|
|
392
|
+
return updatedNft;
|
|
393
|
+
}
|
|
394
|
+
// if this is not part of a batched update we update this one NFT in state
|
|
395
|
+
const { allNfts } = this.state;
|
|
396
|
+
const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];
|
|
397
|
+
const indexToUpdate = nfts.findIndex((item) => item.tokenId === tokenId &&
|
|
398
|
+
item.address.toLowerCase() === address.toLowerCase());
|
|
399
|
+
if (indexToUpdate !== -1) {
|
|
400
|
+
nfts[indexToUpdate] = updatedNft;
|
|
401
|
+
this.update((state) => {
|
|
402
|
+
state.allNfts[addressToSearch] = Object.assign({}, state.allNfts[addressToSearch], {
|
|
403
|
+
[chainId]: nfts,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, nfts, ALL_NFTS_STATE_KEY, {
|
|
407
|
+
userAddress: addressToSearch,
|
|
408
|
+
chainId,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return updatedNft;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user
|
|
415
|
+
* And updates the isCurrentlyOwned value on each accordingly.
|
|
416
|
+
* @param options - an object of arguments
|
|
417
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
418
|
+
* @param options.userAddress - The address of the account where the NFT ownership status is checked/updated.
|
|
419
|
+
*/
|
|
420
|
+
async checkAndUpdateAllNftsOwnershipStatus({ networkClientId, userAddress, } = {}) {
|
|
421
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
422
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
423
|
+
const { allNfts } = this.state;
|
|
424
|
+
const nfts = allNfts[addressToSearch]?.[chainId] || [];
|
|
425
|
+
const updatedNfts = await Promise.all(nfts.map(async (nft) => {
|
|
426
|
+
return ((await this.checkAndUpdateSingleNftOwnershipStatus(nft, true, {
|
|
427
|
+
networkClientId,
|
|
428
|
+
userAddress,
|
|
429
|
+
})) ?? nft);
|
|
430
|
+
}));
|
|
431
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, updatedNfts, ALL_NFTS_STATE_KEY, {
|
|
432
|
+
userAddress: addressToSearch,
|
|
433
|
+
chainId,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Update NFT favorite status.
|
|
438
|
+
*
|
|
439
|
+
* @param address - Hex address of the NFT contract.
|
|
440
|
+
* @param tokenId - Hex address of the NFT contract.
|
|
441
|
+
* @param favorite - NFT new favorite status.
|
|
442
|
+
* @param options - an object of arguments
|
|
443
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
444
|
+
* @param options.userAddress - The address of the account where the NFT is being removed.
|
|
445
|
+
*/
|
|
446
|
+
updateNftFavoriteStatus(address, tokenId, favorite, { networkClientId, userAddress, } = {}) {
|
|
447
|
+
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
448
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, { networkClientId });
|
|
449
|
+
const { allNfts } = this.state;
|
|
450
|
+
const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];
|
|
451
|
+
const index = nfts.findIndex((nft) => nft.address === address && nft.tokenId === tokenId);
|
|
452
|
+
if (index === -1) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const updatedNft = {
|
|
456
|
+
...nfts[index],
|
|
457
|
+
favorite,
|
|
458
|
+
};
|
|
459
|
+
// Update Nfts array
|
|
460
|
+
nfts[index] = updatedNft;
|
|
461
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, nfts, ALL_NFTS_STATE_KEY, {
|
|
462
|
+
chainId,
|
|
463
|
+
userAddress: addressToSearch,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Returns an NFT by the address and token id.
|
|
468
|
+
*
|
|
469
|
+
* @param address - Hex address of the NFT contract.
|
|
470
|
+
* @param tokenId - Number that represents the id of the token.
|
|
471
|
+
* @param selectedAddress - Hex address of the user account.
|
|
472
|
+
* @param chainId - Id of the current network.
|
|
473
|
+
* @returns Object containing the NFT and its position in the array
|
|
474
|
+
*/
|
|
475
|
+
findNftByAddressAndTokenId(address, tokenId, selectedAddress, chainId) {
|
|
476
|
+
const { allNfts } = this.state;
|
|
477
|
+
const nfts = allNfts[selectedAddress]?.[chainId] || [];
|
|
478
|
+
const index = nfts.findIndex((nft) => nft.address.toLowerCase() === address.toLowerCase() &&
|
|
479
|
+
nft.tokenId === tokenId);
|
|
480
|
+
if (index === -1) {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
return { nft: nfts[index], index };
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Update NFT data.
|
|
487
|
+
*
|
|
488
|
+
* @param nft - NFT object to find the right NFT to updates.
|
|
489
|
+
* @param updates - NFT partial object to update properties of the NFT.
|
|
490
|
+
* @param selectedAddress - Hex address of the user account.
|
|
491
|
+
* @param chainId - Id of the current network.
|
|
492
|
+
*/
|
|
493
|
+
updateNft(nft, updates, selectedAddress, chainId) {
|
|
494
|
+
const { allNfts } = this.state;
|
|
495
|
+
const nfts = allNfts[selectedAddress]?.[chainId] || [];
|
|
496
|
+
const nftInfo = this.findNftByAddressAndTokenId(nft.address, nft.tokenId, selectedAddress, chainId);
|
|
497
|
+
if (!nftInfo) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const updatedNft = {
|
|
501
|
+
...nft,
|
|
502
|
+
...updates,
|
|
503
|
+
};
|
|
504
|
+
const newNfts = [
|
|
505
|
+
...nfts.slice(0, nftInfo.index),
|
|
506
|
+
updatedNft,
|
|
507
|
+
...nfts.slice(nftInfo.index + 1),
|
|
508
|
+
];
|
|
509
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNfts, ALL_NFTS_STATE_KEY, {
|
|
510
|
+
chainId,
|
|
511
|
+
userAddress: selectedAddress,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Resets the transaction status of an NFT.
|
|
516
|
+
*
|
|
517
|
+
* @param transactionId - NFT transaction id.
|
|
518
|
+
* @param selectedAddress - Hex address of the user account.
|
|
519
|
+
* @param chainId - Id of the current network.
|
|
520
|
+
* @returns a boolean indicating if the reset was well succeeded or not
|
|
521
|
+
*/
|
|
522
|
+
resetNftTransactionStatusByTransactionId(transactionId, selectedAddress, chainId) {
|
|
523
|
+
const { allNfts } = this.state;
|
|
524
|
+
const nfts = allNfts[selectedAddress]?.[chainId] || [];
|
|
525
|
+
const index = nfts.findIndex((nft) => nft.transactionId === transactionId);
|
|
526
|
+
if (index === -1) {
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
const updatedNft = {
|
|
530
|
+
...nfts[index],
|
|
531
|
+
transactionId: undefined,
|
|
532
|
+
};
|
|
533
|
+
const newNfts = [
|
|
534
|
+
...nfts.slice(0, index),
|
|
535
|
+
updatedNft,
|
|
536
|
+
...nfts.slice(index + 1),
|
|
537
|
+
];
|
|
538
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNfts, ALL_NFTS_STATE_KEY, {
|
|
539
|
+
chainId,
|
|
540
|
+
userAddress: selectedAddress,
|
|
541
|
+
});
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Fetches NFT Collection Metadata from the NFT API.
|
|
546
|
+
*
|
|
547
|
+
* @param contractAddresses - The contract addresses of the NFTs.
|
|
548
|
+
* @param chainId - The chain ID of the network where the NFT is located.
|
|
549
|
+
* @returns NFT collections metadata.
|
|
550
|
+
*/
|
|
551
|
+
async getNFTContractInfo(contractAddresses, chainId) {
|
|
552
|
+
const url = new URL(__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftCollectionApi).call(this));
|
|
553
|
+
url.searchParams.append('chainId', chainId);
|
|
554
|
+
for (const address of contractAddresses) {
|
|
555
|
+
url.searchParams.append('contract', address);
|
|
556
|
+
}
|
|
557
|
+
return await (0, controller_utils_1.handleFetch)(url, {
|
|
558
|
+
headers: {
|
|
559
|
+
Version: controller_utils_1.NFT_API_VERSION,
|
|
560
|
+
},
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
async _requestApproval(suggestedNftMeta) {
|
|
564
|
+
return this.messagingSystem.call('ApprovalController:addRequest', {
|
|
565
|
+
id: suggestedNftMeta.id,
|
|
566
|
+
origin: suggestedNftMeta.origin,
|
|
567
|
+
type: controller_utils_1.ApprovalType.WatchAsset,
|
|
568
|
+
requestData: {
|
|
569
|
+
id: suggestedNftMeta.id,
|
|
570
|
+
interactingAddress: suggestedNftMeta.interactingAddress,
|
|
571
|
+
asset: {
|
|
572
|
+
address: suggestedNftMeta.asset.address,
|
|
573
|
+
tokenId: suggestedNftMeta.asset.tokenId,
|
|
574
|
+
name: suggestedNftMeta.asset.name,
|
|
575
|
+
description: suggestedNftMeta.asset.description,
|
|
576
|
+
image: suggestedNftMeta.asset.image,
|
|
577
|
+
standard: suggestedNftMeta.asset.standard,
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
}, true);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
exports.NftController = NftController;
|
|
584
|
+
_NftController_mutex = new WeakMap(), _NftController_selectedAccountId = new WeakMap(), _NftController_chainId = new WeakMap(), _NftController_ipfsGateway = new WeakMap(), _NftController_openSeaEnabled = new WeakMap(), _NftController_useIpfsSubdomains = new WeakMap(), _NftController_isIpfsGatewayEnabled = new WeakMap(), _NftController_onNftAdded = new WeakMap(), _NftController_instances = new WeakSet(), _NftController_onNetworkControllerNetworkDidChange = function _NftController_onNetworkControllerNetworkDidChange({ selectedNetworkClientId, }) {
|
|
585
|
+
const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
586
|
+
__classPrivateFieldSet(this, _NftController_chainId, chainId, "f");
|
|
587
|
+
}, _NftController_onPreferencesControllerStateChange =
|
|
588
|
+
/**
|
|
589
|
+
* Handles the state change of the preference controller.
|
|
590
|
+
* @param preferencesState - The new state of the preference controller.
|
|
591
|
+
* @param preferencesState.ipfsGateway - The configured IPFS gateway.
|
|
592
|
+
* @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used.
|
|
593
|
+
* @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.
|
|
594
|
+
*/
|
|
595
|
+
async function _NftController_onPreferencesControllerStateChange({ ipfsGateway, openSeaEnabled, isIpfsGatewayEnabled, }) {
|
|
596
|
+
const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
597
|
+
__classPrivateFieldSet(this, _NftController_selectedAccountId, selectedAccount.id, "f");
|
|
598
|
+
__classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
|
|
599
|
+
__classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
|
|
600
|
+
__classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
|
|
601
|
+
const needsUpdateNftMetadata = (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;
|
|
602
|
+
if (needsUpdateNftMetadata && selectedAccount) {
|
|
603
|
+
await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, selectedAccount);
|
|
604
|
+
}
|
|
605
|
+
}, _NftController_onSelectedAccountChange =
|
|
606
|
+
/**
|
|
607
|
+
* Handles the selected account change on the accounts controller.
|
|
608
|
+
* @param internalAccount - The new selected account.
|
|
609
|
+
*/
|
|
610
|
+
async function _NftController_onSelectedAccountChange(internalAccount) {
|
|
611
|
+
const oldSelectedAccountId = __classPrivateFieldGet(this, _NftController_selectedAccountId, "f");
|
|
612
|
+
__classPrivateFieldSet(this, _NftController_selectedAccountId, internalAccount.id, "f");
|
|
613
|
+
const needsUpdateNftMetadata = ((__classPrivateFieldGet(this, _NftController_isIpfsGatewayEnabled, "f") && __classPrivateFieldGet(this, _NftController_ipfsGateway, "f") !== '') ||
|
|
614
|
+
__classPrivateFieldGet(this, _NftController_openSeaEnabled, "f")) &&
|
|
615
|
+
oldSelectedAccountId !== internalAccount.id;
|
|
616
|
+
if (needsUpdateNftMetadata) {
|
|
617
|
+
await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, internalAccount);
|
|
618
|
+
}
|
|
619
|
+
}, _NftController_updateNestedNftState = function _NftController_updateNestedNftState(newCollection, baseStateKey, { userAddress, chainId }) {
|
|
620
|
+
// userAddress can be an empty string if it is not set via an account change or in constructor
|
|
621
|
+
// while this doesn't cause any issues, we want to ensure that we don't store assets to an empty string address
|
|
622
|
+
if (!userAddress) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
this.update((state) => {
|
|
626
|
+
const oldState = state[baseStateKey];
|
|
627
|
+
const addressState = oldState[userAddress] || {};
|
|
628
|
+
const newAddressState = {
|
|
629
|
+
...addressState,
|
|
630
|
+
[chainId]: newCollection,
|
|
631
|
+
};
|
|
632
|
+
state[baseStateKey] = {
|
|
633
|
+
...oldState,
|
|
634
|
+
[userAddress]: newAddressState,
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
}, _NftController_getNftCollectionApi = function _NftController_getNftCollectionApi() {
|
|
638
|
+
// False negative.
|
|
639
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
640
|
+
return `${controller_utils_1.NFT_API_BASE_URL}/collections`;
|
|
641
|
+
}, _NftController_getNftInformationFromApi =
|
|
642
|
+
/**
|
|
643
|
+
* Request individual NFT information from NFT API.
|
|
644
|
+
*
|
|
645
|
+
* @param contractAddress - Hex address of the NFT contract.
|
|
646
|
+
* @param tokenId - The NFT identifier.
|
|
647
|
+
* @returns Promise resolving to the current NFT name and image.
|
|
648
|
+
*/
|
|
649
|
+
async function _NftController_getNftInformationFromApi(contractAddress, tokenId) {
|
|
650
|
+
// TODO Parameterize this by chainId for non-mainnet token detection
|
|
651
|
+
// Attempt to fetch the data with the nft-api
|
|
652
|
+
const urlParams = new URLSearchParams({
|
|
653
|
+
chainIds: '1',
|
|
654
|
+
tokens: `${contractAddress}:${tokenId}`,
|
|
655
|
+
includeTopBid: 'true',
|
|
656
|
+
includeAttributes: 'true',
|
|
657
|
+
includeLastSale: 'true',
|
|
658
|
+
}).toString();
|
|
659
|
+
// First fetch token information
|
|
660
|
+
const nftInformation = await (0, controller_utils_1.fetchWithErrorHandling)({
|
|
661
|
+
url: `${this.getNftApi()}?${urlParams}`,
|
|
662
|
+
options: {
|
|
663
|
+
headers: {
|
|
664
|
+
Version: controller_utils_1.NFT_API_VERSION,
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
});
|
|
668
|
+
// Params for getCollections API call
|
|
669
|
+
const getCollectionParams = new URLSearchParams({
|
|
670
|
+
chainId: '1',
|
|
671
|
+
id: `${nftInformation?.tokens[0]?.token?.collection?.id}`,
|
|
672
|
+
}).toString();
|
|
673
|
+
// Fetch collection information using collectionId
|
|
674
|
+
const collectionInformation = await (0, controller_utils_1.fetchWithErrorHandling)({
|
|
675
|
+
url: `${controller_utils_1.NFT_API_BASE_URL}/collections?${getCollectionParams}`,
|
|
676
|
+
options: {
|
|
677
|
+
headers: {
|
|
678
|
+
Version: controller_utils_1.NFT_API_VERSION,
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
});
|
|
682
|
+
// if we were still unable to fetch the data we return out the default/null of `NftMetadata`
|
|
683
|
+
if (!nftInformation?.tokens?.[0]?.token) {
|
|
684
|
+
return {
|
|
685
|
+
name: null,
|
|
686
|
+
description: null,
|
|
687
|
+
image: null,
|
|
688
|
+
standard: null,
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
// if we've reached this point, we have successfully fetched some data for nftInformation
|
|
692
|
+
// now we reconfigure the data to conform to the `NftMetadata` type for storage.
|
|
693
|
+
const { image, metadata: { imageOriginal } = {}, name, description, collection, kind, rarityRank, rarity, attributes, lastSale, imageSmall, } = nftInformation.tokens[0].token;
|
|
694
|
+
/* istanbul ignore next */
|
|
695
|
+
const nftMetadata = Object.assign({}, { name: name || null }, { description: description || null }, { image: image || null }, collection?.creator && { creator: collection.creator }, imageOriginal && { imageOriginal }, imageSmall && { imageThumbnail: imageSmall }, kind && { standard: kind.toUpperCase() }, lastSale && { lastSale }, attributes && { attributes }, nftInformation.tokens[0].market?.topBid && {
|
|
696
|
+
topBid: nftInformation.tokens[0].market?.topBid,
|
|
697
|
+
}, rarityRank && { rarityRank }, rarity && { rarity }, (collection || collectionInformation) && {
|
|
698
|
+
collection: {
|
|
699
|
+
...(collection || {}),
|
|
700
|
+
creator: collection?.creator ||
|
|
701
|
+
collectionInformation?.collections[0].creator,
|
|
702
|
+
openseaVerificationStatus: collectionInformation?.collections[0].openseaVerificationStatus,
|
|
703
|
+
contractDeployedAt: collectionInformation?.collections[0].contractDeployedAt,
|
|
704
|
+
ownerCount: collectionInformation?.collections[0].ownerCount,
|
|
705
|
+
topBid: collectionInformation?.collections[0].topBid,
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
return nftMetadata;
|
|
709
|
+
}, _NftController_getNftInformationFromTokenURI =
|
|
710
|
+
/**
|
|
711
|
+
* Request individual NFT information from contracts that follows Metadata Interface.
|
|
712
|
+
*
|
|
713
|
+
* @param contractAddress - Hex address of the NFT contract.
|
|
714
|
+
* @param tokenId - The NFT identifier.
|
|
715
|
+
* @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
716
|
+
* @returns Promise resolving to the current NFT name and image.
|
|
717
|
+
*/
|
|
718
|
+
async function _NftController_getNftInformationFromTokenURI(contractAddress, tokenId, networkClientId) {
|
|
719
|
+
const result = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftURIAndStandard).call(this, contractAddress, tokenId, networkClientId);
|
|
720
|
+
let tokenURI = result[0];
|
|
721
|
+
const standard = result[1];
|
|
722
|
+
const hasIpfsTokenURI = tokenURI.startsWith('ipfs://');
|
|
723
|
+
if (hasIpfsTokenURI && !__classPrivateFieldGet(this, _NftController_isIpfsGatewayEnabled, "f")) {
|
|
724
|
+
return {
|
|
725
|
+
image: null,
|
|
726
|
+
name: null,
|
|
727
|
+
description: null,
|
|
728
|
+
standard: standard || null,
|
|
729
|
+
favorite: false,
|
|
730
|
+
tokenURI: tokenURI ?? null,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
const isDisplayNFTMediaToggleEnabled = __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f");
|
|
734
|
+
if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) {
|
|
735
|
+
return {
|
|
736
|
+
image: null,
|
|
737
|
+
name: null,
|
|
738
|
+
description: null,
|
|
739
|
+
standard: standard || null,
|
|
740
|
+
favorite: false,
|
|
741
|
+
tokenURI: tokenURI ?? null,
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
if (hasIpfsTokenURI) {
|
|
745
|
+
tokenURI = await (0, assetsUtil_1.getFormattedIpfsUrl)(__classPrivateFieldGet(this, _NftController_ipfsGateway, "f"), tokenURI, __classPrivateFieldGet(this, _NftController_useIpfsSubdomains, "f"));
|
|
746
|
+
}
|
|
747
|
+
if (tokenURI.startsWith('data:image/')) {
|
|
748
|
+
return {
|
|
749
|
+
image: tokenURI,
|
|
750
|
+
name: null,
|
|
751
|
+
description: null,
|
|
752
|
+
standard: standard || null,
|
|
753
|
+
favorite: false,
|
|
754
|
+
tokenURI: tokenURI ?? null,
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
const object = await (0, controller_utils_1.handleFetch)(tokenURI);
|
|
759
|
+
// TODO: Check image_url existence. This is not part of EIP721 nor EIP1155
|
|
760
|
+
const image = Object.prototype.hasOwnProperty.call(object, 'image')
|
|
761
|
+
? 'image'
|
|
762
|
+
: /* istanbul ignore next */ 'image_url';
|
|
763
|
+
return {
|
|
764
|
+
image: object[image],
|
|
765
|
+
name: object.name,
|
|
766
|
+
description: object.description,
|
|
767
|
+
standard,
|
|
768
|
+
favorite: false,
|
|
769
|
+
tokenURI: tokenURI ?? null,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
return {
|
|
774
|
+
image: null,
|
|
775
|
+
name: null,
|
|
776
|
+
description: null,
|
|
777
|
+
standard: standard || null,
|
|
778
|
+
favorite: false,
|
|
779
|
+
tokenURI: tokenURI ?? null,
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
}, _NftController_getNftURIAndStandard =
|
|
783
|
+
/**
|
|
784
|
+
* Retrieve NFT uri with metadata. TODO Update method to use IPFS.
|
|
785
|
+
*
|
|
786
|
+
* @param contractAddress - NFT contract address.
|
|
787
|
+
* @param tokenId - NFT token id.
|
|
788
|
+
* @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
789
|
+
* @returns Promise resolving NFT uri and token standard.
|
|
790
|
+
*/
|
|
791
|
+
async function _NftController_getNftURIAndStandard(contractAddress, tokenId, networkClientId) {
|
|
792
|
+
// try ERC721 uri
|
|
793
|
+
try {
|
|
794
|
+
const uri = await this.messagingSystem.call('AssetsContractController:getERC721TokenURI', contractAddress, tokenId, networkClientId);
|
|
795
|
+
return [uri, controller_utils_1.ERC721];
|
|
796
|
+
}
|
|
797
|
+
catch {
|
|
798
|
+
// Ignore error
|
|
799
|
+
}
|
|
800
|
+
// try ERC1155 uri
|
|
801
|
+
try {
|
|
802
|
+
const tokenURI = await this.messagingSystem.call('AssetsContractController:getERC1155TokenURI', contractAddress, tokenId, networkClientId);
|
|
803
|
+
/**
|
|
804
|
+
* According to EIP1155 the URI value allows for ID substitution
|
|
805
|
+
* in case the string `{id}` exists.
|
|
806
|
+
* https://eips.ethereum.org/EIPS/eip-1155#metadata
|
|
807
|
+
*/
|
|
808
|
+
if (!tokenURI.includes('{id}')) {
|
|
809
|
+
return [tokenURI, controller_utils_1.ERC1155];
|
|
810
|
+
}
|
|
811
|
+
const hexTokenId = (0, utils_1.remove0x)((0, controller_utils_1.BNToHex)(new bn_js_1.default(tokenId)))
|
|
812
|
+
.padStart(64, '0')
|
|
813
|
+
.toLowerCase();
|
|
814
|
+
return [tokenURI.replace('{id}', hexTokenId), controller_utils_1.ERC1155];
|
|
815
|
+
}
|
|
816
|
+
catch {
|
|
817
|
+
// Ignore error
|
|
818
|
+
}
|
|
819
|
+
return ['', ''];
|
|
820
|
+
}, _NftController_getNftInformation =
|
|
821
|
+
/**
|
|
822
|
+
* Request individual NFT information (name, image url and description).
|
|
823
|
+
*
|
|
824
|
+
* @param contractAddress - Hex address of the NFT contract.
|
|
825
|
+
* @param tokenId - The NFT identifier.
|
|
826
|
+
* @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
827
|
+
* @returns Promise resolving to the current NFT name and image.
|
|
828
|
+
*/
|
|
829
|
+
async function _NftController_getNftInformation(contractAddress, tokenId, networkClientId) {
|
|
830
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, {
|
|
831
|
+
networkClientId,
|
|
832
|
+
});
|
|
833
|
+
const [blockchainMetadata, nftApiMetadata] = await Promise.all([
|
|
834
|
+
(0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformationFromTokenURI).call(this, contractAddress, tokenId, networkClientId)),
|
|
835
|
+
__classPrivateFieldGet(this, _NftController_openSeaEnabled, "f") && chainId === '0x1'
|
|
836
|
+
? (0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformationFromApi).call(this, contractAddress, tokenId))
|
|
837
|
+
: undefined,
|
|
838
|
+
]);
|
|
839
|
+
return {
|
|
840
|
+
...nftApiMetadata,
|
|
841
|
+
name: blockchainMetadata?.name ?? nftApiMetadata?.name ?? null,
|
|
842
|
+
description: blockchainMetadata?.description ?? nftApiMetadata?.description ?? null,
|
|
843
|
+
image: nftApiMetadata?.image ?? blockchainMetadata?.image ?? null,
|
|
844
|
+
standard: blockchainMetadata?.standard ?? nftApiMetadata?.standard ?? null,
|
|
845
|
+
tokenURI: blockchainMetadata?.tokenURI ?? null,
|
|
846
|
+
};
|
|
847
|
+
}, _NftController_getNftContractInformationFromContract =
|
|
848
|
+
/**
|
|
849
|
+
* Request NFT contract information from the contract itself.
|
|
850
|
+
*
|
|
851
|
+
* @param contractAddress - Hex address of the NFT contract.
|
|
852
|
+
* @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
853
|
+
* @returns Promise resolving to the current NFT name and image.
|
|
854
|
+
*/
|
|
855
|
+
async function _NftController_getNftContractInformationFromContract(contractAddress, networkClientId) {
|
|
856
|
+
const [name, symbol] = await Promise.all([
|
|
857
|
+
this.messagingSystem.call('AssetsContractController:getERC721AssetName', contractAddress, networkClientId),
|
|
858
|
+
this.messagingSystem.call('AssetsContractController:getERC721AssetSymbol', contractAddress, networkClientId),
|
|
859
|
+
]);
|
|
860
|
+
return {
|
|
861
|
+
collection: { name },
|
|
862
|
+
symbol,
|
|
863
|
+
address: contractAddress,
|
|
864
|
+
};
|
|
865
|
+
}, _NftController_getNftContractInformation =
|
|
866
|
+
/**
|
|
867
|
+
* Request NFT contract information from Blockchain and aggregate with received data from NFTMetadata.
|
|
868
|
+
*
|
|
869
|
+
* @param contractAddress - Hex address of the NFT contract.
|
|
870
|
+
* @param nftMetadataFromApi - Received NFT information to be aggregated with blockchain contract information.
|
|
871
|
+
* @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
872
|
+
* @returns Promise resolving to the NFT contract name, image and description.
|
|
873
|
+
*/
|
|
874
|
+
async function _NftController_getNftContractInformation(contractAddress, nftMetadataFromApi, networkClientId) {
|
|
875
|
+
const blockchainContractData = await (0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftContractInformationFromContract).call(this, contractAddress, networkClientId));
|
|
876
|
+
if (blockchainContractData ||
|
|
877
|
+
!Object.values(nftMetadataFromApi).every((value) => value === null)) {
|
|
878
|
+
return {
|
|
879
|
+
address: contractAddress,
|
|
880
|
+
...blockchainContractData,
|
|
881
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
882
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
883
|
+
schema_name: nftMetadataFromApi?.standard ?? null,
|
|
884
|
+
collection: {
|
|
885
|
+
name: null,
|
|
886
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
887
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
888
|
+
image_url: nftMetadataFromApi?.collection?.image ??
|
|
889
|
+
nftMetadataFromApi?.collection?.imageUrl ??
|
|
890
|
+
null,
|
|
891
|
+
tokenCount: nftMetadataFromApi?.collection?.tokenCount ?? null,
|
|
892
|
+
...nftMetadataFromApi?.collection,
|
|
893
|
+
...blockchainContractData?.collection,
|
|
894
|
+
},
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
/* istanbul ignore next */
|
|
898
|
+
return {
|
|
899
|
+
address: contractAddress,
|
|
900
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
901
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
902
|
+
asset_contract_type: null,
|
|
903
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
904
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
905
|
+
created_date: null,
|
|
906
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
907
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
908
|
+
schema_name: null,
|
|
909
|
+
symbol: null,
|
|
910
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
911
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
912
|
+
total_supply: null,
|
|
913
|
+
description: null,
|
|
914
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
915
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
916
|
+
external_link: null,
|
|
917
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
918
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
919
|
+
collection: { name: null, image_url: null },
|
|
920
|
+
};
|
|
921
|
+
}, _NftController_addIndividualNft =
|
|
922
|
+
/**
|
|
923
|
+
* Adds an individual NFT to the stored NFT list.
|
|
924
|
+
*
|
|
925
|
+
* @param tokenAddress - Hex address of the NFT contract.
|
|
926
|
+
* @param tokenId - The NFT identifier.
|
|
927
|
+
* @param nftMetadata - NFT optional information (name, image and description).
|
|
928
|
+
* @param nftContract - An object containing contract data of the NFT being added.
|
|
929
|
+
* @param chainId - The chainId of the network where the NFT is being added.
|
|
930
|
+
* @param userAddress - The address of the account where the NFT is being added.
|
|
931
|
+
* @param source - Whether the NFT was detected, added manually or suggested by a dapp.
|
|
932
|
+
* @returns A promise resolving to `undefined`.
|
|
933
|
+
*/
|
|
934
|
+
async function _NftController_addIndividualNft(tokenAddress, tokenId, nftMetadata, nftContract, chainId, userAddress, source) {
|
|
935
|
+
const releaseLock = await __classPrivateFieldGet(this, _NftController_mutex, "f").acquire();
|
|
936
|
+
try {
|
|
937
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
|
|
938
|
+
const { allNfts } = this.state;
|
|
939
|
+
const nfts = [...(allNfts[userAddress]?.[chainId] ?? [])];
|
|
940
|
+
const existingEntry = nfts.find((nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&
|
|
941
|
+
nft.tokenId === tokenId);
|
|
942
|
+
if (existingEntry) {
|
|
943
|
+
const differentMetadata = (0, assetsUtil_1.compareNftMetadata)(nftMetadata, existingEntry);
|
|
944
|
+
const hasNewFields = (0, assetsUtil_1.hasNewCollectionFields)(nftMetadata, existingEntry);
|
|
945
|
+
if (!differentMetadata &&
|
|
946
|
+
existingEntry.isCurrentlyOwned &&
|
|
947
|
+
!hasNewFields) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const indexToUpdate = nfts.findIndex((nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&
|
|
951
|
+
nft.tokenId === tokenId);
|
|
952
|
+
if (indexToUpdate !== -1) {
|
|
953
|
+
nfts[indexToUpdate] = {
|
|
954
|
+
...existingEntry,
|
|
955
|
+
...nftMetadata,
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
const newEntry = {
|
|
961
|
+
address: checksumHexAddress,
|
|
962
|
+
tokenId,
|
|
963
|
+
favorite: false,
|
|
964
|
+
isCurrentlyOwned: true,
|
|
965
|
+
...nftMetadata,
|
|
966
|
+
};
|
|
967
|
+
nfts.push(newEntry);
|
|
968
|
+
}
|
|
969
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, nfts, ALL_NFTS_STATE_KEY, {
|
|
970
|
+
chainId,
|
|
971
|
+
userAddress,
|
|
972
|
+
});
|
|
973
|
+
if (__classPrivateFieldGet(this, _NftController_onNftAdded, "f")) {
|
|
974
|
+
__classPrivateFieldGet(this, _NftController_onNftAdded, "f").call(this, {
|
|
975
|
+
address: checksumHexAddress,
|
|
976
|
+
symbol: nftContract.symbol,
|
|
977
|
+
tokenId: tokenId.toString(),
|
|
978
|
+
standard: nftMetadata.standard,
|
|
979
|
+
source,
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
finally {
|
|
984
|
+
releaseLock();
|
|
985
|
+
}
|
|
986
|
+
}, _NftController_addNftContract =
|
|
987
|
+
/**
|
|
988
|
+
* Adds an NFT contract to the stored NFT contracts list.
|
|
989
|
+
*
|
|
990
|
+
* @param options - options.
|
|
991
|
+
* @param options.tokenAddress - Hex address of the NFT contract.
|
|
992
|
+
* @param options.userAddress - The address of the account where the NFT is being added.
|
|
993
|
+
* @param options.nftMetadata - The retrieved NFTMetadata from API.
|
|
994
|
+
* @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
|
|
995
|
+
* @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.
|
|
996
|
+
* @returns Promise resolving to the current NFT contracts list.
|
|
997
|
+
*/
|
|
998
|
+
async function _NftController_addNftContract({ tokenAddress, userAddress, networkClientId, source, nftMetadata, }) {
|
|
999
|
+
const releaseLock = await __classPrivateFieldGet(this, _NftController_mutex, "f").acquire();
|
|
1000
|
+
try {
|
|
1001
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
|
|
1002
|
+
const { allNftContracts } = this.state;
|
|
1003
|
+
const chainId = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getCorrectChainId).call(this, {
|
|
1004
|
+
networkClientId,
|
|
1005
|
+
});
|
|
1006
|
+
const nftContracts = allNftContracts[userAddress]?.[chainId] || [];
|
|
1007
|
+
const existingEntry = nftContracts.find((nftContract) => nftContract.address.toLowerCase() ===
|
|
1008
|
+
checksumHexAddress.toLowerCase());
|
|
1009
|
+
if (existingEntry) {
|
|
1010
|
+
return nftContracts;
|
|
1011
|
+
}
|
|
1012
|
+
// this doesn't work currently for detection if the user switches networks while the detection is processing
|
|
1013
|
+
// will be fixed once detection uses networkClientIds
|
|
1014
|
+
// get name and symbol if ERC721 then put together the metadata
|
|
1015
|
+
const contractInformation = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftContractInformation).call(this, checksumHexAddress, nftMetadata, networkClientId);
|
|
1016
|
+
const {
|
|
1017
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1018
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1019
|
+
asset_contract_type,
|
|
1020
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1021
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1022
|
+
created_date, symbol, description,
|
|
1023
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1024
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1025
|
+
external_link,
|
|
1026
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1027
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1028
|
+
schema_name,
|
|
1029
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1030
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1031
|
+
collection: { name, image_url, tokenCount }, } = contractInformation;
|
|
1032
|
+
// If the nft is auto-detected we want some valid metadata to be present
|
|
1033
|
+
if (source === constants_1.Source.Detected &&
|
|
1034
|
+
'address' in contractInformation &&
|
|
1035
|
+
typeof contractInformation.address === 'string' &&
|
|
1036
|
+
'collection' in contractInformation &&
|
|
1037
|
+
contractInformation.collection.name === null &&
|
|
1038
|
+
'image_url' in contractInformation.collection &&
|
|
1039
|
+
contractInformation.collection.image_url === null &&
|
|
1040
|
+
Object.entries(contractInformation).every(([key, value]) => {
|
|
1041
|
+
return key === 'address' || key === 'collection' || !value;
|
|
1042
|
+
})) {
|
|
1043
|
+
return nftContracts;
|
|
1044
|
+
}
|
|
1045
|
+
/* istanbul ignore next */
|
|
1046
|
+
const newEntry = Object.assign({}, { address: checksumHexAddress }, description && { description }, name && { name }, image_url && { logo: image_url }, symbol && { symbol }, tokenCount !== null &&
|
|
1047
|
+
typeof tokenCount !== 'undefined' && { totalSupply: tokenCount }, asset_contract_type && { assetContractType: asset_contract_type }, created_date && { createdDate: created_date }, schema_name && { schemaName: schema_name }, external_link && { externalLink: external_link });
|
|
1048
|
+
const newNftContracts = [...nftContracts, newEntry];
|
|
1049
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY, {
|
|
1050
|
+
chainId,
|
|
1051
|
+
userAddress,
|
|
1052
|
+
});
|
|
1053
|
+
return newNftContracts;
|
|
1054
|
+
}
|
|
1055
|
+
finally {
|
|
1056
|
+
releaseLock();
|
|
1057
|
+
}
|
|
1058
|
+
}, _NftController_removeAndIgnoreIndividualNft = function _NftController_removeAndIgnoreIndividualNft(address, tokenId, { chainId, userAddress, }) {
|
|
1059
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
1060
|
+
const { allNfts, ignoredNfts } = this.state;
|
|
1061
|
+
const newIgnoredNfts = [...ignoredNfts];
|
|
1062
|
+
const nfts = allNfts[userAddress]?.[chainId] || [];
|
|
1063
|
+
const newNfts = nfts.filter((nft) => {
|
|
1064
|
+
if (nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&
|
|
1065
|
+
nft.tokenId === tokenId) {
|
|
1066
|
+
const alreadyIgnored = newIgnoredNfts.find((c) => c.address === checksumHexAddress && c.tokenId === tokenId);
|
|
1067
|
+
!alreadyIgnored && newIgnoredNfts.push(nft);
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
return true;
|
|
1071
|
+
});
|
|
1072
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNfts, ALL_NFTS_STATE_KEY, {
|
|
1073
|
+
userAddress,
|
|
1074
|
+
chainId,
|
|
1075
|
+
});
|
|
1076
|
+
this.update((state) => {
|
|
1077
|
+
state.ignoredNfts = newIgnoredNfts;
|
|
1078
|
+
});
|
|
1079
|
+
}, _NftController_removeIndividualNft = function _NftController_removeIndividualNft(address, tokenId, { chainId, userAddress }) {
|
|
1080
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
1081
|
+
const { allNfts } = this.state;
|
|
1082
|
+
const nfts = allNfts[userAddress]?.[chainId] || [];
|
|
1083
|
+
const newNfts = nfts.filter((nft) => !(nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&
|
|
1084
|
+
nft.tokenId === tokenId));
|
|
1085
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNfts, ALL_NFTS_STATE_KEY, {
|
|
1086
|
+
userAddress,
|
|
1087
|
+
chainId,
|
|
1088
|
+
});
|
|
1089
|
+
}, _NftController_removeNftContract = function _NftController_removeNftContract(address, { chainId, userAddress }) {
|
|
1090
|
+
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
1091
|
+
const { allNftContracts } = this.state;
|
|
1092
|
+
const nftContracts = allNftContracts[userAddress]?.[chainId] || [];
|
|
1093
|
+
const newNftContracts = nftContracts.filter((nftContract) => !(nftContract.address.toLowerCase() === checksumHexAddress.toLowerCase()));
|
|
1094
|
+
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY, {
|
|
1095
|
+
chainId,
|
|
1096
|
+
userAddress,
|
|
1097
|
+
});
|
|
1098
|
+
return newNftContracts;
|
|
1099
|
+
}, _NftController_validateWatchNft = async function _NftController_validateWatchNft(asset, type, userAddress, { networkClientId } = {}) {
|
|
1100
|
+
const { address: contractAddress, tokenId } = asset;
|
|
1101
|
+
// Validate parameters
|
|
1102
|
+
if (!type) {
|
|
1103
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Asset type is required');
|
|
1104
|
+
}
|
|
1105
|
+
if (type !== controller_utils_1.ERC721 && type !== controller_utils_1.ERC1155) {
|
|
1106
|
+
throw rpc_errors_1.rpcErrors.invalidParams(
|
|
1107
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1108
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1109
|
+
`Non NFT asset type ${type} not supported by watchNft`);
|
|
1110
|
+
}
|
|
1111
|
+
if (!contractAddress || !tokenId) {
|
|
1112
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Both address and tokenId are required');
|
|
1113
|
+
}
|
|
1114
|
+
if (!(0, address_1.isAddress)(contractAddress)) {
|
|
1115
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Invalid address');
|
|
1116
|
+
}
|
|
1117
|
+
if (!/^\d+$/u.test(tokenId)) {
|
|
1118
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Invalid tokenId');
|
|
1119
|
+
}
|
|
1120
|
+
// Check if the user owns the suggested NFT
|
|
1121
|
+
try {
|
|
1122
|
+
const isOwner = await this.isNftOwner(userAddress, contractAddress, tokenId, { networkClientId });
|
|
1123
|
+
if (!isOwner) {
|
|
1124
|
+
throw rpc_errors_1.rpcErrors.invalidInput('Suggested NFT is not owned by the selected account');
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
catch (error) {
|
|
1128
|
+
// error thrown here: "Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question."
|
|
1129
|
+
if (error instanceof Error) {
|
|
1130
|
+
throw rpc_errors_1.rpcErrors.resourceUnavailable(error.message);
|
|
1131
|
+
}
|
|
1132
|
+
throw error;
|
|
1133
|
+
}
|
|
1134
|
+
}, _NftController_getCorrectChainId = function _NftController_getCorrectChainId({ networkClientId, }) {
|
|
1135
|
+
if (networkClientId) {
|
|
1136
|
+
const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
|
1137
|
+
return chainId;
|
|
1138
|
+
}
|
|
1139
|
+
return __classPrivateFieldGet(this, _NftController_chainId, "f");
|
|
1140
|
+
}, _NftController_getAddressOrSelectedAddress = function _NftController_getAddressOrSelectedAddress(address) {
|
|
1141
|
+
if (address) {
|
|
1142
|
+
return address;
|
|
1143
|
+
}
|
|
1144
|
+
// If the address is not defined (or empty), we fallback to the currently selected account's address
|
|
1145
|
+
const selectedAccount = this.messagingSystem.call('AccountsController:getAccount', __classPrivateFieldGet(this, _NftController_selectedAccountId, "f"));
|
|
1146
|
+
return selectedAccount?.address || '';
|
|
1147
|
+
}, _NftController_updateNftUpdateForAccount = async function _NftController_updateNftUpdateForAccount(account) {
|
|
1148
|
+
const nfts = this.state.allNfts[account.address]?.[__classPrivateFieldGet(this, _NftController_chainId, "f")] ?? [];
|
|
1149
|
+
// Filter only nfts
|
|
1150
|
+
const nftsToUpdate = nfts.filter((singleNft) => !singleNft.name && !singleNft.description && !singleNft.image);
|
|
1151
|
+
if (nftsToUpdate.length !== 0) {
|
|
1152
|
+
await this.updateNftMetadata({
|
|
1153
|
+
nfts: nftsToUpdate,
|
|
1154
|
+
userAddress: account.address,
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
exports.default = NftController;
|
|
1159
|
+
//# sourceMappingURL=NftController.cjs.map
|