Skip to content

Commit

Permalink
fix collection ids fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine committed Sep 23, 2024
1 parent c61479d commit cf6a66e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion resources/js/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export class CollectionApi {
return ApiService.sendPlatformRequest(data);
}

static async getCollectionsIds(first: number = 20) {
static async getCollectionsIds(first: number = 20, after?: string) {
const data = {
query: queries.GetCollectionIds,
variables: {
first,
after,
},
};

Expand Down
21 changes: 21 additions & 0 deletions resources/js/store/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { wcNamespaces, wcProjectId } from '~/util/constants';
import { useAppStore } from '.';
import snackbar from '~/util/snackbar';
import { Web3Modal, Web3ModalConfig } from '@web3modal/standalone';
import { publicKeyToAddress } from '~/util/address';

export const PrivacyPolicyLink = 'https://nft.io/legal/privacy-policy';
export const TermsOfServiceLink = 'https://nft.io/legal/terms-of-service';
Expand Down Expand Up @@ -205,5 +206,25 @@ export const useConnectionStore = defineStore('connection', {

return this.accounts;
},
async getTrackableAccounts() {
const appStore = useAppStore();
const accounts: string[] = [];
if (appStore.user?.account) {
accounts.push(publicKeyToAddress(appStore.user?.account));
}
if (appStore.config.daemon && !appStore.isMultiTenant) {
accounts.push(publicKeyToAddress(appStore.config.daemon));
}
if (this.accounts?.length) {
const walletAccounts = this.accounts.map((account) => publicKeyToAddress(account.address));
accounts.push(...walletAccounts);
}
if (appStore.user?.walletAccounts?.length) {
const walletAccounts = appStore.user?.walletAccounts?.map((account) => publicKeyToAddress(account));
accounts.push(...walletAccounts);
}

return [...new Set(accounts)];
},
},
});
24 changes: 18 additions & 6 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import appConfig from '~/config.json';
import { defineStore } from 'pinia';
import snackbar from '~/util/snackbar';
import { useConnectionStore } from './connection';
import { publicKeyToAddress } from '~/util/address';

const parseConfigURL = (url: string): URL => {
return new URL(url);
Expand Down Expand Up @@ -101,7 +102,6 @@ export const useAppStore = defineStore('app', {
}

await useConnectionStore().getSession();

await this.fetchCollectionIds();
} catch (error: any) {
snackbar.error({ title: error });
Expand Down Expand Up @@ -172,18 +172,30 @@ export const useAppStore = defineStore('app', {
this.tokensCount = res.data.User?.apiTokens.length;
}
},
async fetchCollectionIds(totalCount?: number) {
async fetchCollectionIds(totalCount?: number, after?: string) {
if (!this.loggedIn) return false;

try {
this.newCollection = false;

const res = await CollectionApi.getCollectionsIds(totalCount);
const res = await CollectionApi.getCollectionsIds(totalCount, after);
const collectionsData = res.data.GetCollections;
if (collectionsData.pageInfo.hasNextPage) {
await this.fetchCollectionIds(collectionsData.totalCount > 500 ? 500 : collectionsData.totalCount);
await this.fetchCollectionIds(
collectionsData.totalCount > 500 ? 500 : collectionsData.totalCount,
collectionsData.pageInfo.endCursor
);
} else {
this.collections = collectionsData.edges.map((collection: any) => collection.node.collectionId);
const accounts = await useConnectionStore().getTrackableAccounts();
this.collections = [
...this.collections,
...collectionsData.edges
.filter(async (collection: any) => {
return accounts.find(
(account) => account === publicKeyToAddress(collection.owner.account.publicKey)
);
})
.map((collection: any) => collection.node.collectionId),
];
}
} catch {
return false;
Expand Down

0 comments on commit cf6a66e

Please sign in to comment.