From a7ff441fc169ff11052ec3a12c910db1b24a6841 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Tue, 15 Oct 2024 11:38:31 +0200 Subject: [PATCH] chore: revert "sort by nft_serial when getting all vaults" This reverts commit 981056066ed3f11a247f8b40fe3939977dcd80b9. --- src/network-handlers/ripple-handler.ts | 41 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/network-handlers/ripple-handler.ts b/src/network-handlers/ripple-handler.ts index 707e1e2..4d017f3 100644 --- a/src/network-handlers/ripple-handler.ts +++ b/src/network-handlers/ripple-handler.ts @@ -122,11 +122,8 @@ export class RippleHandler { let nftUUID = uuid.substring(0, 2) === '0x' ? uuid.slice(2) : uuid; nftUUID = nftUUID.toUpperCase(); const nfts: xrpl.AccountNFTsResponse = await this.client.request(getNFTsTransaction); - - const matchingNFT = nfts.result.account_nfts.filter( - nft => decodeURI(nft.URI!).uuid.slice(2) === uuid - ); - + const nftTokenId = await this.getNFTokenIdForVault(nftUUID); + const matchingNFT = nfts.result.account_nfts.filter(nft => nft.NFTokenID === nftTokenId); if (matchingNFT.length === 0) { throw new RippleError(`Vault with UUID: ${nftUUID} not found`); } else if (matchingNFT.length > 1) { @@ -288,22 +285,38 @@ export class RippleHandler { account: this.issuerAddress, }; - // does this return all the NFTs? or only a max of 50 or so, and need pagination? - // https://xrpl.org/docs/references/protocol/ledger-data/ledger-entry-types/nftokenpage const nfts: xrpl.AccountNFTsResponse = await this.client.request(getNFTsTransaction); const allNFTs = nfts.result.account_nfts; const allVaults: RawVault[] = allNFTs.map(nft => lowercaseHexFields(decodeURI(nft.URI!))); - const uniqueUUIDs = Array.from(new Set(allVaults.map(vault => vault.uuid))); - const uniqueVaults: RawVault[] = []; + return allVaults; + } catch (error) { + throw new RippleError(`Could not fetch All Vaults: ${error}`); + } + } + + async getNFTokenIdForVault(uuid: string): Promise { + if (!this.client.isConnected()) { + await this.client.connect(); + } + console.log(`Getting NFTokenId for vault: ${uuid}`); + try { + const getNFTsTransaction: AccountNFTsRequest = { + command: 'account_nfts', + account: this.issuerAddress, + }; - uniqueUUIDs.forEach(async uuid => { - uniqueVaults.push(await this.getRawVault(uuid)); - }); + const nfts: xrpl.AccountNFTsResponse = await this.client.request(getNFTsTransaction); + const matchingNFT = nfts.result.account_nfts.find( + nft => decodeURI(nft.URI!).uuid.slice(2) === uuid + ); - return uniqueVaults; + if (!matchingNFT) { + throw new RippleError(`Vault for uuid: ${uuid} not found`); + } + return matchingNFT.NFTokenID; } catch (error) { - throw new RippleError(`Could not fetch All Vaults: ${error}`); + throw new RippleError(`Could not find NFTokenId for vault Vault: ${error}`); } }