diff --git a/resources/js/api/collection.ts b/resources/js/api/collection.ts index a20af04..fa33dd1 100644 --- a/resources/js/api/collection.ts +++ b/resources/js/api/collection.ts @@ -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, }, }; diff --git a/resources/js/store/connection.ts b/resources/js/store/connection.ts index 2b47180..5a361bf 100644 --- a/resources/js/store/connection.ts +++ b/resources/js/store/connection.ts @@ -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'; @@ -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)]; + }, }, }); diff --git a/resources/js/store/index.ts b/resources/js/store/index.ts index 2fbfa73..62b7aef 100644 --- a/resources/js/store/index.ts +++ b/resources/js/store/index.ts @@ -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); @@ -101,7 +102,6 @@ export const useAppStore = defineStore('app', { } await useConnectionStore().getSession(); - await this.fetchCollectionIds(); } catch (error: any) { snackbar.error({ title: error }); @@ -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;