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