@@ -11,6 +11,7 @@ import type { NFT } from "../utils/nft/parseNft.js";
1111
1212import { getCachedChain } from "../chains/utils.js" ;
1313import { getContract } from "../contract/contract.js" ;
14+ import { getAddress } from "../utils/address.js" ;
1415type OwnedNFT = GetV1NftsResponse [ "data" ] [ number ] ;
1516type ContractNFT = GetV1NftsByContractAddressResponse [ "data" ] [ number ] ;
1617
@@ -268,21 +269,25 @@ async function transformNFTModel(
268269 token_type,
269270 ...rest
270271 } = nft ;
272+
273+ let metadataToUse = rest ;
274+ let owners : string [ ] | undefined = ownerAddress
275+ ? [ getAddress ( ownerAddress ) ]
276+ : undefined ;
277+
278+ if ( "owner_addresses" in rest ) {
279+ const { owner_addresses, ...restWithoutOwnerAddresses } = rest ;
280+ metadataToUse = restWithoutOwnerAddresses ;
281+ owners = owners ?? owner_addresses ?. map ( ( o ) => getAddress ( o ) ) ;
282+ }
283+
271284 const metadata = replaceIPFSGatewayRecursively ( {
272285 uri : nft . metadata_url ?? "" ,
273286 image : nft . image_url ,
274287 attributes : nft . extra_metadata ?. attributes ?? undefined ,
275- ...rest ,
288+ ...metadataToUse ,
276289 } ) ;
277290
278- // replace the ipfs gateway with the ipfs gateway from the client recusively for each key in the metadata object
279-
280- const owner_addresses = ownerAddress
281- ? [ ownerAddress ]
282- : "owner_addresses" in nft
283- ? nft . owner_addresses
284- : undefined ;
285-
286291 if ( contract ?. type === "erc1155" ) {
287292 // TODO (insight): this needs to be added in the API
288293 const supply = await totalSupply ( {
@@ -298,7 +303,7 @@ async function transformNFTModel(
298303 tokenId : BigInt ( token_id ) ,
299304 tokenUri : replaceIPFSGateway ( metadata_url ) ?? "" ,
300305 type : "ERC1155" ,
301- owner : owner_addresses ?. [ 0 ] ,
306+ owner : owners ?. [ 0 ] ,
302307 tokenAddress : contract ?. address ?? "" ,
303308 chainId : contract ?. chain_id ?? 0 ,
304309 supply : supply ,
@@ -307,7 +312,7 @@ async function transformNFTModel(
307312 parsedNft = parseNFT ( metadata , {
308313 tokenId : BigInt ( token_id ) ,
309314 type : "ERC721" ,
310- owner : owner_addresses ?. [ 0 ] ,
315+ owner : owners ?. [ 0 ] ,
311316 tokenUri : replaceIPFSGateway ( metadata_url ) ?? "" ,
312317 tokenAddress : contract ?. address ?? "" ,
313318 chainId : contract ?. chain_id ?? 0 ,
0 commit comments