var d=Object.defineProperty;var l=(a,e,s)=>e in a?d(a,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[e]=s;var i=(a,e,s)=>(l(a,typeof e!="symbol"?e+"":e,s),s);var n=class{constructor(){i(this,"storageKey","userTokens")}async getTokens(){let e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):[]}async addToken(e){let s=await this.getTokens();s.push(e),localStorage.setItem(this.storageKey,JSON.stringify(s))}async removeToken(e){let s=await this.getTokens();s=s.filter(r=>r.address!==e),localStorage.setItem(this.storageKey,JSON.stringify(s))}async getTokenPrice(e){let s=localStorage.getItem("tokenPrices");return s?JSON.parse(s)[e]:0}async saveTokenPrice(e,s){let r=localStorage.getItem("tokenPrices"),o=r?JSON.parse(r):{};o[e]=s,localStorage.setItem("tokenPrices",JSON.stringify(o))}async updateToken(e){let s=await this.getTokens();s=s.map(r=>r.address===e.address?e:r),localStorage.setItem(this.storageKey,JSON.stringify(s))}async getUserWalletAliases(){throw new Error("Method not implemented.")}async upsertWalletAlias(e,s){throw console.log("upsertWalletAlias",e,s),new Error("Method not implemented.")}};import{v4 as m}from"uuid";var c=class{constructor(e){i(this,"supabase");this.supabase=e}async getUserId(){let{data:e,error:s}=await this.supabase.auth.getUser();if(s)throw new Error(s.message);return e?.user?.id||""}async getUserWalletAliases(){let e=await this.getUserId(),{data:s,error:r}=await this.supabase.from("wallet_alias").select("*").eq("user_id",e);if(console.log("getUserWalletAliases",s,r),r)throw new Error(r.message);return s}async upsertWalletAlias(e,s){let r={address:s,alias:e},o=await this.getUserId(),{error:t}=await this.supabase.from("wallet_alias").upsert({...r,user_id:o});if(t)throw new Error(t.message);console.log("upsertWalletAlias",r)}async getOneUserDbToken(e,s,r){let{data:o,error:t}=await this.supabase.from("user_tokens").select("*").eq("user_id",e).eq("address",s).eq("chain_id",r).limit(1);if(console.log("getOneUserDbToken",o,t),t)throw new Error(t.message);return o[0]}async getTokens(){let e=await this.getUserId(),{data:s,error:r}=await this.supabase.from("user_tokens").select("*").eq("user_id",e);if(console.log("getTokens",s,r),r)throw new Error(r.message);return s?.map(t=>({name:t.name,symbol:t.symbol,coinGeckoId:t.coin_gecko_id,decimals:t.decimals,address:t.address,chainId:t.chain_id,icon:t.logo_uri,type:t.type}))}async updateToken(e){let s=await this.getUserId(),r=await this.getOneUserDbToken(s||"",e.address,e.chainId);if(!r)throw new Error("updateToken::Token not found");r.name=e.name,r.symbol=e.symbol,r.coin_gecko_id=e.coinGeckoId,r.decimals=e.decimals,r.logo_uri=e.icon||"",r.chain_id=e.chainId,r.address=e.address,console.log("updateToken",r);let{error:o}=await this.supabase.from("user_tokens").update(r).eq("id",r.id);if(o)throw new Error(o.message)}async addToken(e){let s=await this.getUserId(),r={id:m(),user_id:s||"",name:e.name,symbol:e.symbol,coin_gecko_id:e.coinGeckoId,decimals:e.decimals,address:e.address,chain_id:e.chainId,logo_uri:e.icon||"",type:e.type};console.log("addToken",r);let{error:o}=await this.supabase.from("user_tokens").insert(r);if(o)throw new Error(o.message)}async removeToken(e){let{error:s}=await this.supabase.from("user_tokens").delete().eq("address",e);if(s)throw new Error(s.message)}async getTokenPrice(e){let{data:s,error:r}=await this.supabase.from("cg_token_price_cache").select("*").eq("id",e).limit(1).single();if(console.log("getTokenPrice",s,r),r)throw new Error(r.message);return s}async saveTokenPrice(e,s){let{error:r,data:o}=await this.supabase.from("cg_token_price_cache").upsert({id:e,price:s,updated_at:new Date().toISOString()});if(console.log("saveTokenPrice",o,r),r)throw new Error(r.message)}};export{n as LocalStorageAdapter,c as SupabaseAdapter};
//# sourceMappingURL=index.mjs.map