Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/idls/dab_registries/nft_registry.did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export default ({ IDL }) => {
'details' : IDL.Vec(IDL.Tuple(IDL.Text, detail_value)),
'principal_id' : IDL.Principal,
});
const paginated_nft_canisters = IDL.Record({
'offset': IDL.Nat64,
'limit': IDL.Nat64,
'amount': IDL.Nat64,
'nft_canisters': IDL.Vec(nft_canister),
});
const operation_error = IDL.Variant({
'NotAuthorized' : IDL.Null,
'BadParameters' : IDL.Null,
Expand All @@ -35,6 +41,7 @@ export default ({ IDL }) => {
'add' : IDL.Func([nft_canister], [operation_response], []),
'get' : IDL.Func([IDL.Principal], [IDL.Opt(nft_canister)], ['query']),
'get_all' : IDL.Func([], [IDL.Vec(nft_canister)], ['query']),
'get_all_paginated' : IDL.Func([IDL.Nat64, IDL.Nat64], [paginated_nft_canisters], 'query'),
'name' : IDL.Func([], [IDL.Text], ['query']),
'remove' : IDL.Func([IDL.Principal], [operation_response], []),
'set_controller' : IDL.Func([IDL.Principal], [operation_response], []),
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/dab_registries/nft_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface NFTCanisterMetadata {
'principal_id' : Principal,
'details' : Array<[string, DetailValue]>,
}
export interface PaginatedNftCanisters {
'offset': number,
'limit': number,
'amount': number,
'nft_canisters': Array<NFTCanisterMetadata>,
}
export type Error = { 'NotAuthorized' : null } |
{ 'BadParameters' : null } |
{ 'Unknown' : string } |
Expand All @@ -36,6 +42,7 @@ export default interface NFTRegistryInterface extends RegistryStandard {
) => Promise<Response>,
'get' : (arg_0: Principal) => Promise<[] | [NFTCanisterMetadata]>,
'get_all' : () => Promise<Array<NFTCanisterMetadata>>,
'get_all_paginated': (arg_0: number, arg_1: number) => Promise<PaginatedNftCanisters>
'name' : () => Promise<string>,
'remove' : (arg_0: Principal) => Promise<Response>,
'set_controller' : (arg_0: Principal) => Promise<Response>,
Expand Down
18 changes: 18 additions & 0 deletions src/registries/nfts_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Principal } from '@dfinity/principal';
import fetch from 'cross-fetch';

import NFTRegistryInterface from '../interfaces/dab_registries/nft_registry';
import { PaginatedNftCanisters } from '../interfaces/dab_registries/nft_registry';
import { NFTStandards, NFTCollection } from '../interfaces/nft';
import { DABCollection } from '../interfaces/dab_nfts';

Expand Down Expand Up @@ -71,6 +72,10 @@ export class NFTRegistry extends Registry {
const canistersMetadata = await (this.actor as ActorSubclass<NFTRegistryInterface>).get_all();
return canistersMetadata.map(formatMetadata);
}
public getAllPaginated = async(offset: number, limit: number): Promise<PaginatedNftCanisters> => {
const canistersMetadata = await (this.actor as ActorSubclass<NFTRegistryInterface>).get_all_paginated(offset, limit);
return canistersMetadata;
}
}

export const getUserCollectionTokens = async (
Expand Down Expand Up @@ -144,6 +149,19 @@ export const getAllNFTS = async (
return allNFTs.map((nft) => ({ ...nft, icon: nft.thumbnail, standard: nft.details.standard as string }));
};

export const getAllNFTSPaginated = async (
{ agent = DEFAULT_AGENT }: { agent?: HttpAgent } = {}, offset: number, limit: number
): Promise<PaginatedNftCanisters> => {
const registry = new NFTRegistry(agent);
const allNFTs = await registry.getAllPaginated(offset, limit);
return {
offset: allNFTs.offset,
limit: allNFTs.limit,
amount: allNFTs.amount,
nft_canisters: allNFTs.nft_canisters,
}
};

export const getAllUserNFTs = async (
{ user,
agent = DEFAULT_AGENT }: GetAllUserNFTsParams
Expand Down