Skip to content

Commit

Permalink
Fixed CollectionTableController.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Le Ponner <eric.leponner@icloud.com>
  • Loading branch information
ericleponner committed Jan 23, 2024
1 parent 93d8634 commit d0ba728
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/components/account/CollectionTableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@
*
*/

import {
Nft,
Nfts,
NftTransactionHistory,
TokenBalancesResponse,
TokenDistribution,
TokenRelationship
} from "@/schemas/HederaSchemas";
import {Nft, Nfts} from "@/schemas/HederaSchemas";
import {ComputedRef, Ref} from "vue";
import axios, {AxiosResponse} from "axios";
import axios from "axios";
import {KeyOperator, SortOrder, TableController} from "@/utils/table/TableController";
import {Router} from "vue-router";

export class CollectionTableController extends TableController<Nft, string> {
export class CollectionTableController extends TableController<Nft, number> {

public readonly accountId: Ref<string | null>
public readonly tokenId: string
Expand All @@ -50,52 +43,44 @@ export class CollectionTableController extends TableController<Nft, string> {
// TableController
//

public async load(tokenId: string | null, operator: KeyOperator, order: SortOrder, limit: number): Promise<Nft[] | null> {
if (this.accountId.value == null) {
public async load(serialNumber: number | null, operator: KeyOperator, order: SortOrder, limit: number): Promise<Nft[] | null> {
if (this.tokenId == null || this.accountId.value == null) {
return Promise.resolve(null)
}

const params = {} as {
limit: number
"token.id": string | undefined
serialnumber: string | undefined
order: string
}
params.limit = 10000
params.limit = limit
params.order = order
if (tokenId !== null) {
params["token.id"] = operator + ":" + tokenId
params["token.id"] = this.tokenId

if (serialNumber !== null) {
params.serialnumber = operator + ":" + serialNumber
}

const { data } = await axios.get<Nfts>(
`api/v1/accounts/${this.accountId.value}/nfts`,
{params: params},
)

const collectionsMap = new Map();
for (const nft of data.nfts!) {
let collection = collectionsMap.get(nft.token_id);
if (collection === undefined) {
collection = { count: 0, nfts: [] };
collectionsMap.set(nft.token_id, collection);
}
collection.count += 1;
collection.nfts.push(nft);
}

const nfts = collectionsMap.get(this.tokenId).nfts
const nfts = data.nfts ?? null

return nfts
return Promise.resolve(nfts)
}

public keyFor(row: Nft): string {
return row.token_id ?? ""
public keyFor(row: Nft): number {
return row.serial_number ?? 0
}

public stringFromKey(key: string): string {
return key;
public stringFromKey(serialNumber: number): string {
return serialNumber.toString()
}

public keyFromString(s: string): string | null {
return s;
public keyFromString(s: string): number | null {
return Number(s)
}
}

0 comments on commit d0ba728

Please sign in to comment.