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