"use strict";var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(t,e,s)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var h=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},w=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!u.call(t,o)&&o!==s&&i(t,o,{get:()=>e[o],enumerable:!(r=m(e,o))||r.enumerable});return t};var T=t=>w(i({},"__esModule",{value:!0}),t);var n=(t,e,s)=>(p(t,typeof e!="symbol"?e+"":e,s),s);var k={};h(k,{LocalStorageAdapter:()=>c,SupabaseAdapter:()=>d});module.exports=T(k);var c=class{constructor(){n(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.")}};var l=require("uuid");var d=class{constructor(e){n(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:a}=await this.supabase.from("wallet_alias").upsert({...r,user_id:o});if(a)throw new Error(a.message);console.log("upsertWalletAlias",r)}async getOneUserDbToken(e,s,r){let{data:o,error:a}=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,a),a)throw new Error(a.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(a=>({name:a.name,symbol:a.symbol,coinGeckoId:a.coin_gecko_id,decimals:a.decimals,address:a.address,chainId:a.chain_id,icon:a.logo_uri,type:a.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:(0,l.v4)(),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)}};0&&(module.exports={LocalStorageAdapter,SupabaseAdapter});
//# sourceMappingURL=index.js.map