require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/cache.types.cjs`),t=require(`../../functions/utils/caseInsensitive.utils.cjs`),n=require(`../../API/API.cjs`),r=require(`../../error-handling/logger.cjs`),i=require(`../../functions/utils/string.utils.cjs`),a=require(`./token-visibility-db.cjs`);let o=require(`idb-keyval`);var s=class{fetchedTokens={};initalFetched=!1;async updateFetchedTokens(){let t=await(0,o.get)(e.StorageKeys.PRIVATE_TOKENS);this.fetchedTokens=t??{},this.initalFetched=!0}async getPrivateTokens(t,n){let r=i.getStateKey(n,t);return(await(0,o.get)(e.StorageKeys.PRIVATE_TOKENS))?.[r]||[]}async fetchPrivateTokens(e,i,a){try{let r=[...new Set(i)].filter(e=>e&&!t.lowerCaseIncludes(a,e));if(!r.length)return[];let o=(await n.API.tokensInfoCall(e,r)).filter(e=>!!e),s=new Map;return o.forEach(e=>{s.set(e.erc20TokenAddress.toLowerCase(),e)}),Array.from(s.values())}catch(e){return r.Logger.error(`Error fetching private tokens:`,e),[]}}async fetchAndUpdatePrivateTokens(n,r,s,c){let l=(await this.getPrivateTokens(r,s)).map(e=>e.erc20TokenAddress),u=c??await this.fetchPrivateTokens(r,n,l),d=await a.tokenVisibilityStorage.hideSpamsAndFetchHiddenTokensAddresses(r,u),f=i.getStateKey(s,r);await(0,o.update)(e.StorageKeys.PRIVATE_TOKENS,(e={})=>{let n=e?.[f]||[],r=n.map(e=>e.erc20TokenAddress),i=u.filter(e=>!t.lowerCaseIncludes(r,e.erc20TokenAddress));n.push(...i);let a=n.filter(e=>!t.lowerCaseIncludes(d,e.erc20TokenAddress)),o={...e,[f]:a};return this.fetchedTokens=o,o})}getFetchedTokens(e,t){let n=i.getStateKey(t,e);return this.fetchedTokens[n]||[]}},c=new s;exports.PrivateTokensDB=s,exports.privateTokensDB=c;