@metamask/assets-controllers 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,13 +43,14 @@ class NftController extends base_controller_1.BaseController {
43
43
  * @param options.getERC721OwnerOf - Get the owner of a ERC-721 NFT.
44
44
  * @param options.getERC1155BalanceOf - Gets balance of a ERC-1155 NFT.
45
45
  * @param options.getERC1155TokenURI - Gets the URI of the ERC1155 token at the given address, with the given ID.
46
+ * @param options.getNetworkClientById - Gets the network client for the given networkClientId.
46
47
  * @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data
47
48
  * for tracking the NFT added event.
48
49
  * @param options.messenger - The controller messenger.
49
50
  * @param config - Initial options used to configure this controller.
50
51
  * @param state - Initial state to set on this controller.
51
52
  */
52
- constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, getERC721AssetName, getERC721AssetSymbol, getERC721TokenURI, getERC721OwnerOf, getERC1155BalanceOf, getERC1155TokenURI, onNftAdded, messenger, }, config, state) {
53
+ constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, getERC721AssetName, getERC721AssetSymbol, getERC721TokenURI, getERC721OwnerOf, getERC1155BalanceOf, getERC1155TokenURI, getNetworkClientById, onNftAdded, messenger, }, config, state) {
53
54
  super(config, state);
54
55
  this.mutex = new async_mutex_1.Mutex();
55
56
  /**
@@ -80,6 +81,7 @@ class NftController extends base_controller_1.BaseController {
80
81
  this.getERC721OwnerOf = getERC721OwnerOf;
81
82
  this.getERC1155BalanceOf = getERC1155BalanceOf;
82
83
  this.getERC1155TokenURI = getERC1155TokenURI;
84
+ this.getNetworkClientById = getNetworkClientById;
83
85
  this.onNftAdded = onNftAdded;
84
86
  this.messagingSystem = messenger;
85
87
  onPreferencesStateChange(({ selectedAddress, ipfsGateway, openSeaEnabled, isIpfsGatewayEnabled, }) => {
@@ -131,6 +133,7 @@ class NftController extends base_controller_1.BaseController {
131
133
  */
132
134
  getNftInformationFromApi(contractAddress, tokenId) {
133
135
  return __awaiter(this, void 0, void 0, function* () {
136
+ // TODO Parameterize this by chainId for non-mainnet token detection
134
137
  // Attempt to fetch the data with the proxy
135
138
  const nftInformation = yield (0, controller_utils_1.fetchWithErrorHandling)({
136
139
  url: this.getNftApi({
@@ -162,12 +165,13 @@ class NftController extends base_controller_1.BaseController {
162
165
  *
163
166
  * @param contractAddress - Hex address of the NFT contract.
164
167
  * @param tokenId - The NFT identifier.
168
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
165
169
  * @returns Promise resolving to the current NFT name and image.
166
170
  */
167
- getNftInformationFromTokenURI(contractAddress, tokenId) {
171
+ getNftInformationFromTokenURI(contractAddress, tokenId, networkClientId) {
168
172
  return __awaiter(this, void 0, void 0, function* () {
169
173
  const { ipfsGateway, useIPFSSubdomains, isIpfsGatewayEnabled } = this.config;
170
- const result = yield this.getNftURIAndStandard(contractAddress, tokenId);
174
+ const result = yield this.getNftURIAndStandard(contractAddress, tokenId, networkClientId);
171
175
  let tokenURI = result[0];
172
176
  const standard = result[1];
173
177
  const hasIpfsTokenURI = tokenURI.startsWith('ipfs://');
@@ -216,13 +220,14 @@ class NftController extends base_controller_1.BaseController {
216
220
  *
217
221
  * @param contractAddress - NFT contract address.
218
222
  * @param tokenId - NFT token id.
223
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
219
224
  * @returns Promise resolving NFT uri and token standard.
220
225
  */
221
- getNftURIAndStandard(contractAddress, tokenId) {
226
+ getNftURIAndStandard(contractAddress, tokenId, networkClientId) {
222
227
  return __awaiter(this, void 0, void 0, function* () {
223
228
  // try ERC721 uri
224
229
  try {
225
- const uri = yield this.getERC721TokenURI(contractAddress, tokenId);
230
+ const uri = yield this.getERC721TokenURI(contractAddress, tokenId, networkClientId);
226
231
  return [uri, controller_utils_1.ERC721];
227
232
  }
228
233
  catch (_a) {
@@ -230,7 +235,7 @@ class NftController extends base_controller_1.BaseController {
230
235
  }
231
236
  // try ERC1155 uri
232
237
  try {
233
- const tokenURI = yield this.getERC1155TokenURI(contractAddress, tokenId);
238
+ const tokenURI = yield this.getERC1155TokenURI(contractAddress, tokenId, networkClientId);
234
239
  /**
235
240
  * According to EIP1155 the URI value allows for ID substitution
236
241
  * in case the string `{id}` exists.
@@ -255,16 +260,23 @@ class NftController extends base_controller_1.BaseController {
255
260
  *
256
261
  * @param contractAddress - Hex address of the NFT contract.
257
262
  * @param tokenId - The NFT identifier.
263
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
258
264
  * @returns Promise resolving to the current NFT name and image.
259
265
  */
260
- getNftInformation(contractAddress, tokenId) {
266
+ getNftInformation(contractAddress, tokenId, networkClientId) {
261
267
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
262
268
  return __awaiter(this, void 0, void 0, function* () {
269
+ let { chainId } = this.config;
270
+ if (networkClientId) {
271
+ chainId =
272
+ this.getNetworkClientById(networkClientId).configuration.chainId;
273
+ }
263
274
  const blockchainMetadata = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
264
- return yield this.getNftInformationFromTokenURI(contractAddress, tokenId);
275
+ return yield this.getNftInformationFromTokenURI(contractAddress, tokenId, networkClientId);
265
276
  }));
266
277
  let openSeaMetadata;
267
- if (this.config.openSeaEnabled) {
278
+ // currently we only need to enter this block if we are on mainnet
279
+ if (this.config.openSeaEnabled && chainId === '0x1') {
268
280
  openSeaMetadata = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
269
281
  return yield this.getNftInformationFromApi(contractAddress, tokenId);
270
282
  }));
@@ -312,12 +324,13 @@ class NftController extends base_controller_1.BaseController {
312
324
  * Request NFT contract information from the contract itself.
313
325
  *
314
326
  * @param contractAddress - Hex address of the NFT contract.
327
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
315
328
  * @returns Promise resolving to the current NFT name and image.
316
329
  */
317
- getNftContractInformationFromContract(contractAddress) {
330
+ getNftContractInformationFromContract(contractAddress, networkClientId) {
318
331
  return __awaiter(this, void 0, void 0, function* () {
319
- const name = yield this.getERC721AssetName(contractAddress);
320
- const symbol = yield this.getERC721AssetSymbol(contractAddress);
332
+ const name = yield this.getERC721AssetName(contractAddress, networkClientId);
333
+ const symbol = yield this.getERC721AssetSymbol(contractAddress, networkClientId);
321
334
  return {
322
335
  collection: { name },
323
336
  symbol,
@@ -329,15 +342,21 @@ class NftController extends base_controller_1.BaseController {
329
342
  * Request NFT contract information from OpenSea API.
330
343
  *
331
344
  * @param contractAddress - Hex address of the NFT contract.
345
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
332
346
  * @returns Promise resolving to the NFT contract name, image and description.
333
347
  */
334
- getNftContractInformation(contractAddress) {
348
+ getNftContractInformation(contractAddress, networkClientId) {
335
349
  return __awaiter(this, void 0, void 0, function* () {
336
350
  const blockchainContractData = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
337
- return yield this.getNftContractInformationFromContract(contractAddress);
351
+ return yield this.getNftContractInformationFromContract(contractAddress, networkClientId);
338
352
  }));
353
+ const { chainId } = this.config;
354
+ const getCurrentChainId = this.getCorrectChainId({
355
+ chainId,
356
+ networkClientId,
357
+ });
339
358
  let openSeaContractData;
340
- if (this.config.openSeaEnabled) {
359
+ if (this.config.openSeaEnabled && getCurrentChainId === '0x1') {
341
360
  openSeaContractData = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
342
361
  return yield this.getNftContractInformationFromApi(contractAddress);
343
362
  }));
@@ -362,39 +381,31 @@ class NftController extends base_controller_1.BaseController {
362
381
  /**
363
382
  * Adds an individual NFT to the stored NFT list.
364
383
  *
365
- * @param address - Hex address of the NFT contract.
384
+ * @param tokenAddress - Hex address of the NFT contract.
366
385
  * @param tokenId - The NFT identifier.
367
386
  * @param nftMetadata - NFT optional information (name, image and description).
368
387
  * @param nftContract - An object containing contract data of the NFT being added.
369
- * @param accountParams - The chain ID and address of network and account to which the nftContract should be added.
388
+ * @param chainId - The chainId of the network where the NFT is being added.
389
+ * @param userAddress - The address of the account where the NFT is being added.
370
390
  * @param source - Whether the NFT was detected, added manually or suggested by a dapp.
371
391
  * @returns Promise resolving to the current NFT list.
372
392
  */
373
- addIndividualNft(address, tokenId, nftMetadata, nftContract, accountParams, source = constants_1.Source.Custom) {
393
+ addIndividualNft(tokenAddress, tokenId, nftMetadata, nftContract, chainId, userAddress, source) {
374
394
  var _a;
375
395
  return __awaiter(this, void 0, void 0, function* () {
376
396
  // TODO: Remove unused return
377
397
  const releaseLock = yield this.mutex.acquire();
378
398
  try {
379
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
399
+ tokenAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
380
400
  const { allNfts } = this.state;
381
- let chainId, selectedAddress;
382
- if (accountParams) {
383
- chainId = accountParams.chainId;
384
- selectedAddress = accountParams.userAddress;
385
- }
386
- else {
387
- chainId = this.config.chainId;
388
- selectedAddress = this.config.selectedAddress;
389
- }
390
- const nfts = ((_a = allNfts[selectedAddress]) === null || _a === void 0 ? void 0 : _a[chainId]) || [];
391
- const existingEntry = nfts.find((nft) => nft.address.toLowerCase() === address.toLowerCase() &&
401
+ const nfts = ((_a = allNfts[userAddress]) === null || _a === void 0 ? void 0 : _a[chainId]) || [];
402
+ const existingEntry = nfts.find((nft) => nft.address.toLowerCase() === tokenAddress.toLowerCase() &&
392
403
  nft.tokenId === tokenId);
393
404
  if (existingEntry) {
394
405
  const differentMetadata = (0, assetsUtil_1.compareNftMetadata)(nftMetadata, existingEntry);
395
406
  if (differentMetadata || !existingEntry.isCurrentlyOwned) {
396
407
  // TODO: Switch to indexToUpdate
397
- const indexToRemove = nfts.findIndex((nft) => nft.address.toLowerCase() === address.toLowerCase() &&
408
+ const indexToRemove = nfts.findIndex((nft) => nft.address.toLowerCase() === tokenAddress.toLowerCase() &&
398
409
  nft.tokenId === tokenId);
399
410
  /* istanbul ignore next */
400
411
  if (indexToRemove !== -1) {
@@ -405,16 +416,15 @@ class NftController extends base_controller_1.BaseController {
405
416
  return nfts;
406
417
  }
407
418
  }
408
- const newEntry = Object.assign({ address,
409
- tokenId, favorite: (existingEntry === null || existingEntry === void 0 ? void 0 : existingEntry.favorite) || false, isCurrentlyOwned: true }, nftMetadata);
419
+ const newEntry = Object.assign({ address: tokenAddress, tokenId, favorite: (existingEntry === null || existingEntry === void 0 ? void 0 : existingEntry.favorite) || false, isCurrentlyOwned: true }, nftMetadata);
410
420
  const newNfts = [...nfts, newEntry];
411
421
  this.updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {
412
422
  chainId,
413
- userAddress: selectedAddress,
423
+ userAddress,
414
424
  });
415
425
  if (this.onNftAdded) {
416
426
  this.onNftAdded({
417
- address,
427
+ address: tokenAddress,
418
428
  symbol: nftContract.symbol,
419
429
  tokenId: tokenId.toString(),
420
430
  standard: nftMetadata.standard,
@@ -431,33 +441,34 @@ class NftController extends base_controller_1.BaseController {
431
441
  /**
432
442
  * Adds an NFT contract to the stored NFT contracts list.
433
443
  *
434
- * @param address - Hex address of the NFT contract.
435
- * @param accountParams - The chain ID and address of network and account to which the nftContract should be added.
436
- * @param source - Whether the NFT was detected, added manually or suggested by a dapp.
444
+ * @param options - options.
445
+ * @param options.tokenAddress - Hex address of the NFT contract.
446
+ * @param options.chainId - The chainId of the network where the NFT is being added.
447
+ * @param options.userAddress - The address of the account where the NFT is being added.
448
+ * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
449
+ * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.
437
450
  * @returns Promise resolving to the current NFT contracts list.
438
451
  */
439
- addNftContract(address, accountParams, source) {
452
+ addNftContract({ tokenAddress, chainId, userAddress, networkClientId, source, }) {
440
453
  var _a;
441
454
  return __awaiter(this, void 0, void 0, function* () {
442
455
  const releaseLock = yield this.mutex.acquire();
443
456
  try {
444
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
457
+ tokenAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
445
458
  const { allNftContracts } = this.state;
446
- let chainId, selectedAddress;
447
- if (accountParams) {
448
- chainId = accountParams.chainId;
449
- selectedAddress = accountParams.userAddress;
450
- }
451
- else {
452
- chainId = this.config.chainId;
453
- selectedAddress = this.config.selectedAddress;
454
- }
455
- const nftContracts = ((_a = allNftContracts[selectedAddress]) === null || _a === void 0 ? void 0 : _a[chainId]) || [];
456
- const existingEntry = nftContracts.find((nftContract) => nftContract.address.toLowerCase() === address.toLowerCase());
459
+ const currentChainId = this.getCorrectChainId({
460
+ chainId,
461
+ networkClientId,
462
+ });
463
+ const selectedAddress = userAddress !== null && userAddress !== void 0 ? userAddress : this.config.selectedAddress;
464
+ const nftContracts = ((_a = allNftContracts[selectedAddress]) === null || _a === void 0 ? void 0 : _a[currentChainId]) || [];
465
+ const existingEntry = nftContracts.find((nftContract) => nftContract.address.toLowerCase() === tokenAddress.toLowerCase());
457
466
  if (existingEntry) {
458
467
  return nftContracts;
459
468
  }
460
- const contractInformation = yield this.getNftContractInformation(address);
469
+ // this doesn't work currently for detection if the user switches networks while the detection is processing
470
+ // will be fixed once detection uses networkClientIds
471
+ const contractInformation = yield this.getNftContractInformation(tokenAddress, networkClientId);
461
472
  const { asset_contract_type, created_date, schema_name, symbol, total_supply, description, external_link, collection: { name, image_url }, } = contractInformation;
462
473
  // If the nft is auto-detected we want some valid metadata to be present
463
474
  if (source === constants_1.Source.Detected &&
@@ -474,11 +485,11 @@ class NftController extends base_controller_1.BaseController {
474
485
  return nftContracts;
475
486
  }
476
487
  /* istanbul ignore next */
477
- const newEntry = Object.assign({}, { address }, description && { description }, name && { name }, image_url && { logo: image_url }, symbol && { symbol }, total_supply !== null &&
488
+ const newEntry = Object.assign({}, { address: tokenAddress }, description && { description }, name && { name }, image_url && { logo: image_url }, symbol && { symbol }, total_supply !== null &&
478
489
  typeof total_supply !== 'undefined' && { totalSupply: total_supply }, asset_contract_type && { assetContractType: asset_contract_type }, created_date && { createdDate: created_date }, schema_name && { schemaName: schema_name }, external_link && { externalLink: external_link });
479
490
  const newNftContracts = [...nftContracts, newEntry];
480
491
  this.updateNestedNftState(newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY, {
481
- chainId,
492
+ chainId: currentChainId,
482
493
  userAddress: selectedAddress,
483
494
  });
484
495
  return newNftContracts;
@@ -547,7 +558,7 @@ class NftController extends base_controller_1.BaseController {
547
558
  this.updateNestedNftState(newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY);
548
559
  return newNftContracts;
549
560
  }
550
- validateWatchNft(asset, type, accountAddress) {
561
+ validateWatchNft(asset, type, userAddress) {
551
562
  return __awaiter(this, void 0, void 0, function* () {
552
563
  const { address: contractAddress, tokenId } = asset;
553
564
  // Validate parameters
@@ -568,7 +579,7 @@ class NftController extends base_controller_1.BaseController {
568
579
  }
569
580
  // Check if the user owns the suggested NFT
570
581
  try {
571
- const isOwner = yield this.isNftOwner(accountAddress, contractAddress, tokenId);
582
+ const isOwner = yield this.isNftOwner(userAddress, contractAddress, tokenId);
572
583
  if (!isOwner) {
573
584
  throw rpc_errors_1.rpcErrors.invalidInput('Suggested NFT is not owned by the selected account');
574
585
  }
@@ -579,6 +590,17 @@ class NftController extends base_controller_1.BaseController {
579
590
  }
580
591
  });
581
592
  }
593
+ // temporary method to get the correct chainId until we remove chainId from the config & the chainId arg from the detection logic
594
+ // Just a helper method to prefer the networkClient chainId first then the chainId argument and then finally the config chainId
595
+ getCorrectChainId({ chainId, networkClientId, }) {
596
+ if (networkClientId) {
597
+ return this.getNetworkClientById(networkClientId).configuration.chainId;
598
+ }
599
+ else if (chainId) {
600
+ return chainId;
601
+ }
602
+ return this.config.chainId;
603
+ }
582
604
  /**
583
605
  * Adds a new suggestedAsset to state. Parameters will be validated according to
584
606
  * asset type being watched. A `<suggestedNftMeta.id>:pending` hub event will be emitted once added.
@@ -588,13 +610,14 @@ class NftController extends base_controller_1.BaseController {
588
610
  * @param asset.tokenId - The ID of the asset.
589
611
  * @param type - The asset type.
590
612
  * @param origin - Domain origin to register the asset from.
613
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
591
614
  * @returns Object containing a Promise resolving to the suggestedAsset address if accepted.
592
615
  */
593
- watchNft(asset, type, origin) {
616
+ watchNft(asset, type, origin, networkClientId) {
594
617
  return __awaiter(this, void 0, void 0, function* () {
595
618
  const { selectedAddress, chainId } = this.config;
596
619
  yield this.validateWatchNft(asset, type, selectedAddress);
597
- const nftMetadata = yield this.getNftInformation(asset.address, asset.tokenId);
620
+ const nftMetadata = yield this.getNftInformation(asset.address, asset.tokenId, networkClientId);
598
621
  if (nftMetadata.standard && nftMetadata.standard !== type) {
599
622
  throw rpc_errors_1.rpcErrors.invalidInput(`Suggested NFT of type ${nftMetadata.standard} does not match received type ${type}`);
600
623
  }
@@ -610,14 +633,17 @@ class NftController extends base_controller_1.BaseController {
610
633
  const { address, tokenId } = asset;
611
634
  const { name, standard, description, image } = nftMetadata;
612
635
  yield this.addNft(address, tokenId, {
613
- name: name !== null && name !== void 0 ? name : null,
614
- description: description !== null && description !== void 0 ? description : null,
615
- image: image !== null && image !== void 0 ? image : null,
616
- standard: standard !== null && standard !== void 0 ? standard : null,
617
- }, {
636
+ nftMetadata: {
637
+ name: name !== null && name !== void 0 ? name : null,
638
+ description: description !== null && description !== void 0 ? description : null,
639
+ image: image !== null && image !== void 0 ? image : null,
640
+ standard: standard !== null && standard !== void 0 ? standard : null,
641
+ },
618
642
  chainId,
619
643
  userAddress: selectedAddress,
620
- }, constants_1.Source.Dapp);
644
+ source: constants_1.Source.Dapp,
645
+ networkClientId,
646
+ });
621
647
  });
622
648
  }
623
649
  /**
@@ -633,14 +659,15 @@ class NftController extends base_controller_1.BaseController {
633
659
  *
634
660
  * @param ownerAddress - User public address.
635
661
  * @param nftAddress - NFT contract address.
636
- * @param nftId - NFT token ID.
662
+ * @param tokenId - NFT token ID.
663
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
637
664
  * @returns Promise resolving the NFT ownership.
638
665
  */
639
- isNftOwner(ownerAddress, nftAddress, nftId) {
666
+ isNftOwner(ownerAddress, nftAddress, tokenId, networkClientId) {
640
667
  return __awaiter(this, void 0, void 0, function* () {
641
668
  // Checks the ownership for ERC-721.
642
669
  try {
643
- const owner = yield this.getERC721OwnerOf(nftAddress, nftId);
670
+ const owner = yield this.getERC721OwnerOf(nftAddress, tokenId, networkClientId);
644
671
  return ownerAddress.toLowerCase() === owner.toLowerCase();
645
672
  // eslint-disable-next-line no-empty
646
673
  }
@@ -649,7 +676,7 @@ class NftController extends base_controller_1.BaseController {
649
676
  }
650
677
  // Checks the ownership for ERC-1155.
651
678
  try {
652
- const balance = yield this.getERC1155BalanceOf(ownerAddress, nftAddress, nftId);
679
+ const balance = yield this.getERC1155BalanceOf(ownerAddress, nftAddress, tokenId, networkClientId);
653
680
  return !balance.isZero();
654
681
  // eslint-disable-next-line no-empty
655
682
  }
@@ -665,37 +692,52 @@ class NftController extends base_controller_1.BaseController {
665
692
  *
666
693
  * @param address - Hex address of the NFT contract.
667
694
  * @param tokenId - The NFT identifier.
695
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
696
+ * @param source - Whether the NFT was detected, added manually or suggested by a dapp.
668
697
  */
669
- addNftVerifyOwnership(address, tokenId) {
698
+ addNftVerifyOwnership(address, tokenId, networkClientId, source) {
670
699
  return __awaiter(this, void 0, void 0, function* () {
671
700
  const { selectedAddress } = this.config;
672
- if (!(yield this.isNftOwner(selectedAddress, address, tokenId))) {
701
+ if (!(yield this.isNftOwner(selectedAddress, address, tokenId, networkClientId))) {
673
702
  throw new Error('This NFT is not owned by the user');
674
703
  }
675
- yield this.addNft(address, tokenId);
704
+ yield this.addNft(address, tokenId, { networkClientId, source });
676
705
  });
677
706
  }
678
707
  /**
679
708
  * Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.
680
709
  *
681
- * @param address - Hex address of the NFT contract.
710
+ * @param tokenAddress - Hex address of the NFT contract.
682
711
  * @param tokenId - The NFT identifier.
683
- * @param nftMetadata - NFT optional metadata.
684
- * @param accountParams - The chain ID and address of network and account to which the nftContract should be added.
685
- * @param source - Whether the NFT was detected, added manually or suggested by a dapp.
712
+ * @param options - an object of arguments
713
+ * @param options.nftMetadata - NFT optional metadata.
714
+ * @param options.chainId - The chain ID of the current network.
715
+ * @param options.userAddress - The address of the current user.
716
+ * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.
717
+ * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.
686
718
  * @returns Promise resolving to the current NFT list.
687
719
  */
688
- addNft(address, tokenId, nftMetadata, accountParams, source = constants_1.Source.Custom) {
720
+ addNft(tokenAddress, tokenId, { nftMetadata, chainId, // TODO remove and replace chainId arg with fetch chainId using getNetworkClientById(networkClientId).configuration.chainId once polling refactor is complete
721
+ userAddress, source = constants_1.Source.Custom, networkClientId, } = {}) {
689
722
  return __awaiter(this, void 0, void 0, function* () {
690
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
691
- const newNftContracts = yield this.addNftContract(address, accountParams, source);
723
+ tokenAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
724
+ const currentChainId = this.getCorrectChainId({ chainId, networkClientId });
725
+ const selectedAddress = userAddress !== null && userAddress !== void 0 ? userAddress : this.config.selectedAddress;
726
+ const newNftContracts = yield this.addNftContract({
727
+ tokenAddress,
728
+ chainId: currentChainId,
729
+ userAddress: selectedAddress,
730
+ networkClientId,
731
+ source,
732
+ });
692
733
  nftMetadata =
693
- nftMetadata || (yield this.getNftInformation(address, tokenId));
734
+ nftMetadata ||
735
+ (yield this.getNftInformation(tokenAddress, tokenId, networkClientId));
694
736
  // If NFT contract was not added, do not add individual NFT
695
- const nftContract = newNftContracts.find((contract) => contract.address.toLowerCase() === address.toLowerCase());
737
+ const nftContract = newNftContracts.find((contract) => contract.address.toLowerCase() === tokenAddress.toLowerCase());
696
738
  // If NFT contract information, add individual NFT
697
739
  if (nftContract) {
698
- yield this.addIndividualNft(address, tokenId, nftMetadata, nftContract, accountParams, source);
740
+ yield this.addIndividualNft(tokenAddress, tokenId, nftMetadata, nftContract, currentChainId, selectedAddress, source);
699
741
  }
700
742
  });
701
743
  }