Skip to content

Commit

Permalink
chore: revert "sort by nft_serial when getting all vaults"
Browse files Browse the repository at this point in the history
This reverts commit 9810560.
  • Loading branch information
Polybius93 committed Oct 15, 2024
1 parent 112d065 commit a7ff441
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/network-handlers/ripple-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<string> {
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}`);
}
}

Expand Down

0 comments on commit a7ff441

Please sign in to comment.