From f8cd7f4f93f337517b346ccdca4c8412316b8688 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Thu, 2 May 2024 16:56:37 +0200 Subject: [PATCH] check for init status --- .../api/MoralisNFTRepository.server.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/bridge-ui/src/libs/nft/infrastructure/api/MoralisNFTRepository.server.ts b/packages/bridge-ui/src/libs/nft/infrastructure/api/MoralisNFTRepository.server.ts index b70637cb265..442500a6b41 100644 --- a/packages/bridge-ui/src/libs/nft/infrastructure/api/MoralisNFTRepository.server.ts +++ b/packages/bridge-ui/src/libs/nft/infrastructure/api/MoralisNFTRepository.server.ts @@ -12,17 +12,21 @@ import type { FetchNftArgs } from '../types/common'; class MoralisNFTRepository implements INFTRepository { private static instance: MoralisNFTRepository; + private static isInitialized = false; private cursor: string; private lastFetchedAddress: Address; private hasFetchedAll: boolean; - private nfts: NFT[] = []; private constructor() { - Moralis.start({ - apiKey: MORALIS_API_KEY, - }).catch(console.error); + if (!MoralisNFTRepository.isInitialized) { + Moralis.start({ apiKey: MORALIS_API_KEY }) + .then(() => { + MoralisNFTRepository.isInitialized = true; + }) + .catch(console.error); + } this.cursor = ''; this.lastFetchedAddress = zeroAddress; @@ -38,7 +42,6 @@ class MoralisNFTRepository implements INFTRepository { async findByAddress({ address, chainId, refresh = false }: FetchNftArgs): Promise { this.lastFetchedAddress = address; - if (refresh) { this.reset(); }