@turtleclub/earn-widget 0.4.0-beta.7 → 0.4.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {clsx}from'clsx';import {createContext,useMemo,useRef,useEffect,useCallback,useContext,useState,useReducer}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Card,cn,BaseSelector,iconUrlToImg,OpportunityRateEstimator,Button,AssetList,Skeleton,TurtleTooltip,SwapInput,SwapDetails,RouteDetails,DataTable,APIStatus,DropdownMenu,DropdownMenuTrigger,DropdownMenuContent,DropdownMenuItem,TxStatus}from'@turtleclub/ui';import {cva}from'class-variance-authority';import {useCheckMembership,useCreateMembershipAgreement,useCreateMembership,useMultiChainBalances,useWidgetOpportunities,useTokenBalance,useEarnRoute}from'@turtleclub/hooks';import {atom,useAtom,useAtomValue}from'jotai';import {InfoIcon,ChevronLeft,Wallet2Icon,LogOutIcon}from'lucide-react';import {formatNumber,formatToken,formatCurrency,getNetworkByChainId,formatCurrencyWithCommas,getNetworkById,getNetworkBackgroundColor}from'@turtleclub/utils';import {parseUnits}from'viem';import {mainnet}from'viem/chains';function q(...e){return clsx(e)}var Pe=createContext(null);function De({config:e,children:t}){return jsx(Pe.Provider,{value:e,children:t})}function M(){let e=useContext(Pe);if(!e)throw new Error("useWidgetConfig must be used within WidgetConfigProvider");return e}function X(e){return `rgb(from ${e} calc(255 - r) calc(255 - g) calc(255 - b))`}function Gt(e,t=10){return `color-mix(in srgb, ${e} ${100-t}%, black)`}function _e(e,t){let r=t==="dark",o={"--color-brand-black":r?e.background_dark:X(e.background_dark),"--color-brand-white":r?e.foreground_dark:X(e.foreground_dark),"--color-brand-green":r?e.primary_dark:Gt(e.primary_dark)};return (e.card!==void 0||e.card_dark!==void 0)&&(o["--color-surface-primary"]=r?e.card_dark??e.card??e.background_dark:X(e.card_dark??e.background_dark)),(e.muted_foreground!==void 0||e.muted_foreground_dark!==void 0)&&(o["--muted-foreground"]=r?e.muted_foreground_dark??e.muted_foreground??e.foreground_dark:X(e.muted_foreground_dark??e.muted_foreground_dark??e.foreground_dark)),o}var Le={background:"#F9F9F9",background_dark:"#141514",foreground:"#141514",foreground_dark:"#F9F9F9",primary:"#73F36C",primary_dark:"#73F36C",card:"#F9F9F9",card_dark:"#141514",muted_foreground:"#14151480",muted_foreground_dark:"#FFFFFF80"},Fe="dark",Me="Montserrat, sans-serif",Ue="DM Sans, sans-serif";function A(){let e=M(),t=e?.theme??Fe,r=e?.fontFamily??Me,o=e?.fontSecondary??Ue,n=e?.widgetWidth??"default",i=e?.customWidth??"100%",u=e?.showNavigation??true,s=e?.padding??"default",a=e?.rounding??"default",l=e?.styles??Le,c=_e(l,t==="auto"?"dark":t);return {theme:t,coreTokenCSS:c,fontPrimary:r,fontSecondary:o,widgetWidth:n,customWidth:i,showNavigation:u,padding:s,rounding:a,config:e,widgetStyles:l}}var Be={xxs:"h-4 text-xs",xs:"h-6 text-sm",sm:"h-8 text-2xl",md:"h-12 text-4xl",lg:"h-16 text-6xl"};function Qe({light:e,dark:t,fallback:r="Turtle Club",className:o,size:n="lg"}){let[i,u]=useState(false),{theme:s}=A(),l=s==="dark"?t||e:e||t;return l&&!i?jsx("div",{className:cn("flex justify-center items-center",o),children:jsx("img",{src:l,alt:r,className:cn("object-contain",Be[n]),onError:()=>u(true),onLoad:()=>u(false)})}):jsx("div",{className:cn("flex justify-center items-center",o),children:jsx("span",{className:cn("font-bold text-primary",Be[n]),children:r})})}function ze(){let e=M();return {light:e?.logo?.light,dark:e?.logo?.dark,fallback:e?.logo?.fallback||"Turtle Club"}}var Kt=cva("p-0",{variants:{padding:{none:"p-0",sm:"p-3",default:"p-4",md:"p-6",lg:"p-7"}},defaultVariants:{padding:"default"}});function ue({children:e,className:t,variant:r,padding:o,rounding:n,showLogo:i=true,logoSize:u="xs",...s}){let{padding:a}=A(),{light:l,dark:m,fallback:c}=ze(),d=Kt({padding:o??a});return jsxs(Card,{className:q(t,d),...s,variant:r,gradient:"white",children:[i&&jsx("div",{className:"flex-shrink-0 py-2",children:jsx(Qe,{light:l,dark:m,fallback:c,size:u})}),e]})}var Ve=createContext(null),Ge=createContext(""),Xe=({adapter:e,distributorId:t,children:r})=>jsx(Ve.Provider,{value:e,children:jsx(Ge.Provider,{value:t,children:r})}),W=()=>{let e=useContext(Ve);if(!e)throw new Error("useAdapter must be used within an AdapterProvider");return e},U=()=>useContext(Ge);function Ze({children:e}){let t=M(),{theme:r,coreTokenCSS:o,fontPrimary:n,fontSecondary:i,widgetWidth:u}=A();return jsx("div",{className:q("turtle-widget-root text-foreground","antialiased transition-all duration-700 ease-linear w-full overflow-hidden","h-full flex items-center justify-center",r==="dark"?"dark":""),style:{...o,"--font-primary":n,"--font-secondary":i,fontFamily:n,backgroundColor:"transparent",maxHeight:"90vh"},children:jsx("div",{className:q("flex flex-col gap-2 h-full overflow-hidden",u==="full"?"w-full items-center":u==="custom"?"items-stretch":"items-center"),style:{...u==="custom"&&t.customWidth?{width:t.customWidth}:u==="default"?{width:"620px"}:{}},children:jsx("div",{className:"w-full max-w-md h-full flex flex-col gap-2 overflow-hidden",children:e})})})}var R=()=>{let e=W(),t=useRef(void 0),r=useRef(false),{data:o,isLoading:n,refetch:i}=useCheckMembership({params:{address:e.user||"",walletEcosystem:"evm"},enabled:!!e.user}),{mutateAsync:u,isPending:s,error:a}=useCreateMembershipAgreement(),{mutateAsync:l,isPending:m,error:c}=useCreateMembership();useEffect(()=>{let k=e.user;if(!k){t.current!==void 0&&(t.current=void 0);return}k!==t.current&&(t.current=k,d(k));},[e.user]);let d=async k=>{if(!r.current){r.current=true;try{let{data:w}=await i();if(w?.isMember){console.log("[useWidgetAuth] User is already a member");return}console.log("[useWidgetAuth] User is not a member, starting membership flow..."),console.log("[useWidgetAuth] Creating membership agreement...");let S=await u({address:k,walletEcosystem:"evm",url:window.location.href,chainId:String(e.network||1)});console.log("[useWidgetAuth] Requesting signature from wallet...");let H=await e.signMessage(S.message);console.log("[useWidgetAuth] Creating membership with signature...");let E=await l({address:k,walletEcosystem:"evm",signature:H,nonce:S.nonce});E.isMember?console.log("[useWidgetAuth] Membership created successfully!"):console.error("[useWidgetAuth] Failed to create membership:",E.error);}catch(w){console.error("[useWidgetAuth] Membership flow error:",w);}finally{r.current=false;}}},p=n||s||m,b=a?.message||c?.message||null;return {address:e.user,isConnected:!!e.user,isMember:o?.isMember,currentChain:e.network,connect:e.openConnectionModal,disconnect:e.disconnect,changeNetwork:e.changeNetwork,isLoading:p,error:b}};function Ke(e){let[t,r]=useState(e),o=useCallback(n=>{r(n);},[]);return {currentTab:t,setTab:o}}var ur=atom({id:"none"});function y(){let[e,t]=useAtom(ur),r=useCallback((n,i)=>{t({id:n,data:i});},[t]),o=useCallback(()=>{t({id:"none"});},[t]);return {currentOverlay:e.id,overlayData:e.data,isOverlayOpen:e.id!=="none",openOverlay:r,closeOverlay:o}}function de({tabs:e,overlays:t,defaultTab:r}){let {showNavigation:o}=A(),{currentTab:n}=Ke(r),{currentOverlay:u,overlayData:s}=y();useMemo(()=>Object.entries(e).filter(([p,b])=>b.visible!==false).map(([p,b])=>({value:p,label:b.label})),[e]);let m=useMemo(()=>e[n].component,[n,e]),c=useMemo(()=>u==="none"?null:t[u].component,[u,t]);return jsxs(Fragment,{children:[o&&false,jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col gap-2 bg-transparent",children:jsx(ue,{variant:"border",className:"flex-1 min-h-0 w-full flex flex-col overflow-hidden",children:jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:c?jsx(c,{data:s}):jsx(m,{})})})})]})}function Y({onBack:e,children:t,className:r}){let{closeOverlay:o}=y();return jsxs("div",{className:`flex flex-col h-full ${r||""}`,children:[jsx("div",{className:"flex items-center gap-2 pb-3",children:jsx(Button,{variant:"green",border:"interactive",size:"icon",onClick:e??o,className:"h-8 w-8 shrink-0","aria-label":"Go back",children:jsx(ChevronLeft,{className:"h-5 w-5"})})}),jsx("div",{className:"flex-1 min-h-0 overflow-auto pt-4",children:t})]})}var J=e=>e.filter(t=>t.rewardType!=="points").reduce((t,r)=>t+(r.yield??0),0),et=e=>({totalYield:useMemo(()=>J(e),[e])});function ee({incentives:e,isPill:t,className:r}){let{totalYield:o}=et(e),n=useMemo(()=>e.filter(i=>i.rewardType!=="points"&&i.yield!==null&&i.yield!==void 0).sort((i,u)=>u.yield-i.yield),[e]);return jsx(TurtleTooltip,{trigger:jsxs("div",{className:cn("group flex items-center gap-1",r,t&&"hover:bg-neutral-alpha-5 border-border bg-neutral-alpha-2 hover:border-gradient-white rounded-full border px-3 py-1.5 text-xs"),children:[formatNumber(o,1,false,false),"%"," ",jsx(InfoIcon,{className:"text-primary/70 group-hover:text-primary size-2.5"})]}),content:jsxs("div",{children:[jsx("div",{className:"text-sm",children:"APR Breakdown"}),jsx("div",{children:n.map(i=>jsxs("div",{className:"my-1 flex justify-between gap-2 text-xs",children:[jsxs("div",{className:"flex items-center gap-1",children:[i.iconUrl&&jsx("img",{src:i.iconUrl,alt:i.name||i.id,className:"size-4 rounded-full",loading:"lazy"}),jsx("div",{children:i.name})]}),jsxs("div",{children:[formatNumber(i.yield,1,false,false),"%"]})]},i.id))}),jsxs("div",{className:"text-primary flex justify-between gap-2 text-sm",children:[jsx("span",{children:"Total"}),jsxs("span",{children:[formatNumber(o,1,false,false),"%"]})]})]}),side:"bottom",contentClassName:"p-5 backdrop-blur-xl"})}function rt({chain:e,triggerClassName:t}){let r=getNetworkById(e.slug);return jsx("div",{className:cn("bg-foreground -mr-1 flex size-5 items-center justify-center overflow-hidden rounded-full ring-1 ring-white last:mr-0 lg:-mr-4 lg:size-6",getNetworkBackgroundColor(r),t),children:jsx("img",{src:e.logoUrl,className:"size-5 rounded-full object-contain lg:size-6",alt:e.name})})}var pe=atom(null),fe=atom(null),ge=atom(.001),be=atom(null),nt=atom(e=>{let t=e(pe),r=e(be),o=e(fe),n=e(ge),i=!!(o&&Number.parseFloat(o)>0),u=!!t&&!!r&&i&&!!n,s=u?{chain:Number(t?.receiptToken?.chain.chainId)??1,token_in:r?.address??"",token_out:t?.receiptToken?.address??"",amount:parseUnits(o??"0",r?.decimals??18).toString(),slippage:n}:void 0;return {opportunity:t,token:r,amount:o,options:s,isValid:u}});function C(){let[e,t]=useAtom(pe),[r,o]=useAtom(be),[n,i]=useAtom(fe),[u,s]=useAtom(ge),a=useAtomValue(nt),l=useCallback(()=>{t(null),o(null),i(null),s(.001);},[t,o,i]);return useEffect(()=>{i(""),s(.001);},[r]),{opportunity:e,token:r,amount:n,slippage:u,isValid:a.isValid,options:a.options,selectOpportunity:t,selectToken:o,setAmount:i,setSlippage:s,reset:l}}function re({opportunities:e}){let{changeNetwork:t,network:r}=W(),{selectOpportunity:o,selectToken:n}=C(),{closeOverlay:i}=y();return jsx(DataTable,{columns:[{accessorKey:"name",header:()=>jsx("div",{children:"Opportunity"}),cell:({row:a})=>jsxs("div",{className:"flex items-center gap-2 px-1",children:[jsx(APIStatus,{warning:false}),jsx("img",{src:a.original.token.logoUrl,className:"size-6 rounded-full",loading:"lazy"}),a.original.name||a.original.token.name]}),enableSorting:true},{accessorKey:"chain",header:()=>jsx("div",{className:"flex w-full justify-end",children:"Chain"}),cell:({row:a})=>jsx(rt,{chain:a.original.token.chain})},{id:"organization",accessorFn:a=>a.products.length?a.products[0].organization.name:"-",header:()=>jsx("div",{children:"Partner"}),cell:({row:a})=>a.original.products.length?jsxs("div",{className:"flex items-center gap-2",children:[jsx("img",{src:a.original.products[0].organization.iconUrl||"",className:"size-6 rounded-full",loading:"lazy"}),a.original.products[0].organization.name]}):"-",enableSorting:true},{accessorKey:"tvl",header:()=>jsx("div",{className:"flex w-full justify-end",children:"TVL"}),cell:({row:a})=>jsx("div",{className:"text-end",children:formatCurrency(a.original.tvl,0,true)}),enableSorting:true},{accessorKey:"totalYield",header:()=>jsx("div",{className:"flex w-full justify-end",children:"Estimated APR"}),cell:({row:a})=>jsx("div",{className:"flex flex-row-reverse",children:jsx(ee,{incentives:a.original.incentives})}),enableSorting:true,sortingFn:(a,l)=>{let m=J(a.original.incentives),c=J(l.original.incentives);return m-c}}],onRowClick:a=>{o(a);let l=Number(a.token.chain.chainId);l!==r&&(t(l),n(null)),i();},data:e,enableSearch:true,grid:{displayAsGrid:true,headerSlot:"name",rightSlot:"totalYield",excludeColumns:[],className:"grid-cols-1 gap-2.5"}})}function at(){let e=U(),{data:t,isLoading:r,error:o}=useWidgetOpportunities(e);return r?jsx("div",{children:"Loading..."}):o?jsxs("div",{children:["Error: ",o.message]}):t===void 0?jsx("div",{children:"No data"}):t.opportunities&&t.opportunities.length===0?jsx("div",{children:"No opportunities"}):jsx(Y,{children:jsx(re,{opportunities:t.opportunities||[]})})}var ut=()=>{let{openOverlay:e}=y();return jsx("button",{onClick:()=>{e("balances"),console.log("Positions Content Click");},children:"Positions Content Click"})};var lt=()=>jsx("div",{children:"Discover Content"});function ye({steps:e,currentStep:t,allCompleted:r,cancelled:o,tokenSymbol:n,amount:i,resetQueue:u,resetForm:s}){let a=e.filter(d=>d.status==="completed"&&d.txHash).pop(),l=t?.txHash?t:null,m=r?a?.txHash:l?.txHash||a?.txHash,c=useMemo(()=>({title:o?"Transaction Cancelled":r?"Transaction Completed!":"Processing Transaction",description:o?"Transaction was cancelled by user":r?"Your deposit has been successfully processed.":"Please wait while your transaction is being confirmed...",txHash:m,explorerUrl:"https://etherscan.io",estimatedTime:void 0,amount:`${i?formatNumber(i,5,false,false):"0"}`,token:n,protocol:"Turtle Protocol",completed:r,cancelled:o,onViewDetails:void 0,onClose:()=>{u(),s();},steps:e.map(d=>({label:d.label,completed:d.status==="completed",current:d.status==="executing",txHash:d.txHash}))}),[e,r,o,n,i,u,s,m]);return jsx("div",{className:"h-full overflow-hidden",children:jsx(TxStatus,{...c,className:"bg-background border-border text-foreground h-full"})})}function dt(e){return e.kind==="approve"&&e.token?`Approve ${e.token.symbol}`:e.kind==="enso"?"Execute Deposit":`Execute ${e.kind}`}function mt(e,t){return e.kind==="approve"&&e.token?`Allow contract to spend ${e.token.symbol}`:`Transaction step ${t+1}`}function pt(e){let t=e instanceof Error?e.message:String(e);return ["user rejected","user denied","user cancelled","cancelled by user","transaction rejected","4001"].some(o=>t.toLowerCase().includes(o.toLowerCase()))}function ft(e){if(e.steps.length<=1||e.queueStatus!=="idle")return false;let t=e.steps[e.currentIndex-1],r=e.steps[e.currentIndex];return e.currentIndex>0&&e.currentIndex<e.steps.length&&t?.status==="completed"&&r?.status==="pending"}var Br=1e3;function yt(e,t){return e.tx?{id:t,label:dt(e),description:mt(e,t),txData:e.tx,status:"pending"}:null}function Qr(e,t){switch(t.type){case "INITIALIZE_QUEUE":return {steps:t.steps,currentIndex:0,queueStatus:"idle",lastError:void 0};case "START_EXECUTION":return {...e,steps:e.steps.map((r,o)=>o===t.index?{...r,status:"executing"}:r),queueStatus:"executing",lastError:void 0};case "COMPLETE_STEP":{let r=e.steps.map((i,u)=>u===t.index?{...i,status:"completed",txHash:t.txHash}:i),o=t.index+1,n=o>=r.length;return {...e,steps:r,currentIndex:n?e.currentIndex:o,queueStatus:n?"completed":"idle"}}case "FAIL_STEP":return {...e,steps:e.steps.map((r,o)=>o===t.index?{...r,status:"failed",error:t.error}:r),queueStatus:t.isCancellation?"cancelled":"error",lastError:t.error};case "RESET_QUEUE":return {steps:t.steps,currentIndex:0,queueStatus:"idle",lastError:void 0};default:return e}}function ve({earnRoute:e,userAddress:t,chainId:r,sendTransaction:o,onError:n=()=>{},onSuccess:i=()=>{}}){let u={steps:[],currentIndex:0,queueStatus:"idle"},[s,a]=useReducer(Qr,u);useEffect(()=>{if(!e?.steps?.length){a({type:"INITIALIZE_QUEUE",steps:[]});return}let f=e.steps.map((v,g)=>yt(v,g)).filter(v=>v!==null);a({type:"INITIALIZE_QUEUE",steps:f});},[e]);let l=useCallback(async()=>{if(!t||!r||!o||s.queueStatus==="executing")return;let f=s.steps[s.currentIndex];if(!f||f.status!=="pending"&&f.status!=="failed")return;if(f.txData.from.toLowerCase()!==t.toLowerCase()){let g=new Error("Transaction 'from' address doesn't match connected wallet");a({type:"FAIL_STEP",index:s.currentIndex,error:g.message,isCancellation:false}),n&&n(g);return}a({type:"START_EXECUTION",index:s.currentIndex});try{let g=await o({...f.txData,chainId:r});a({type:"COMPLETE_STEP",index:s.currentIndex,txHash:g??""}),s.currentIndex+1>=s.steps.length&&i&&i();}catch(g){let L=g instanceof Error?g.message:"Transaction failed",$=pt(g);a({type:"FAIL_STEP",index:s.currentIndex,error:$?"Transaction cancelled by user":L,isCancellation:$}),!$&&n&&n(g instanceof Error?g:new Error(L));}},[t,r,o,s.queueStatus,s.steps,s.currentIndex,i,n]),m=useCallback(()=>{if(!e?.steps?.length)return;let f=e.steps.map((v,g)=>yt(v,g)).filter(v=>v!==null);a({type:"RESET_QUEUE",steps:f});},[e]),c=s.steps[s.currentIndex]||null,d=s.queueStatus==="executing",p=s.queueStatus==="completed",b=s.queueStatus==="error",k=s.queueStatus==="cancelled",w=s.steps.filter(f=>f.status==="completed").length,S=s.steps.length,H=S>0?w/S*100:0,E=useMemo(()=>c?!!(p||d&&c.id===0||c.id>0):false,[c,p,d]),ne=!!(t&&r&&s.steps.length>0&&s.queueStatus!=="executing"&&s.queueStatus!=="completed");return useEffect(()=>{if(ft(s)){let f=setTimeout(()=>{l();},Br);return ()=>clearTimeout(f)}},[s,l]),{steps:s.steps.map((f,v)=>({...f,completed:f.status==="completed",current:v===s.currentIndex})),currentIndex:s.currentIndex,isExecuting:d,allCompleted:p,hasError:b,cancelled:k,error:s.lastError,currentStep:c?{...c,completed:c.status==="completed",current:true}:null,canExecute:ne,executeCurrentTransaction:l,resetQueue:m,totalSteps:S,completedSteps:w,progress:H,showTxStatus:E}}var $r=(e,t,r)=>({in:{icon:t.logos[0],symbol:t.symbol},out:{icon:r.logos[0],symbol:r.symbol},amount:void 0,type:e}),qr=(e,t)=>({in:{icon:e.logos[0],symbol:e.symbol},out:null,amount:formatToken(t,{decimals:e.decimals},true,false,4),type:"approve"});function vt(e){if(!e)return [];let t=[];return e.steps.forEach(r=>{if(r.kind==="approve"&&r.token){let o=qr(r.token,r.amount);t.push(o);}r.kind==="enso"&&r.substeps&&r.substeps.forEach(o=>{let n=o.from[0],i=o.to[0],u=$r(o.kind,n,i);t.push(u);});}),t}function ht(e){return {chainId:Number(e.receiptToken?.chain.chainId)??mainnet.id,address:e.receiptToken?.address??"",symbol:e.receiptToken?.symbol??"",decimals:e.receiptToken?.decimals??18}}function xt(e,t,r,o,n){let i=useMemo(()=>{if(!(!o||!e))return {...o,user:t,distributor_id:r,referral_code:n}},[o,t,r,n]),u=useMemo(()=>!!(t&&i?.token_in&&i?.token_out&&i?.amount&&i?.chain&&i?.slippage&&i?.distributor_id),[o]),{data:s,isLoading:a,error:l}=useEarnRoute({params:i,enabled:u&&e}),m=useMemo(()=>vt(s??null),[s]);return {fetchedRoute:s??null,outputAmount:s?.amount_out??void 0,isReady:u&&s&&!a,hasRequiredParams:u,routeDetails:m,routeError:l,isLoadingRoute:a}}function xe({fetchedRoute:e,routeError:t,isLoadingRoute:r,canExecute:o,isExecuting:n,hasError:i,cancelled:u,executeCurrentTransaction:s,totalSteps:a,completedSteps:l,showingTransactionStatus:m,hasInsufficientBalance:c}){let d=useCallback(async()=>{o&&await s();},[o,s]),p=useMemo(()=>m?null:r?{text:"Loading route...",disabled:true,className:"cursor-not-allowed"}:t?{text:"Route Error",disabled:true,className:"cursor-not-allowed"}:!e||!e.steps||e.steps.length===0?{text:"Enter amount to continue",disabled:true,className:"cursor-not-allowed"}:c?{text:"Insufficient Balance",disabled:true,className:"cursor-not-allowed"}:n?{text:"Executing...",disabled:true,className:"cursor-not-allowed"}:i?{text:"Retry Transaction",disabled:!o,onClick:d,className:"cursor-pointer"}:u?{text:"Try Again",disabled:!o,onClick:d,className:"cursor-pointer"}:{text:a>1&&l!==a?`Confirm Transaction (${l}/${a})`:"Confirm Transaction",disabled:false,onClick:d,className:"cursor-pointer"},[m,r,t,e,c,n,i,u,o,a,l,d]);return p?jsx(Button,{border:"plain",onClick:()=>p.onClick?.(),disabled:p.disabled,className:p.className+" w-full",children:p.text}):null}function Et({opportunity:e,address:t,distributorId:r,executeTransaction:o,stickyButton:n=false}){let{openOverlay:i}=y(),{chainId:u,symbol:s,decimals:a}=useMemo(()=>ht(e),[e]),{setAmount:l,setSlippage:m,token:c,amount:d,slippage:p,options:b,isValid:k}=C(),{usdValue:w,hasInsufficientBalance:S,handleMaxClick:H}=useTokenBalance({token:c,amount:d??void 0,setAmount:O=>l(O??null)}),{routeDetails:E,isReady:ne,outputAmount:f,fetchedRoute:v,routeError:g,isLoadingRoute:L}=xt(k,t,r,b),$=useCallback(async O=>{let ie={from:O.from,to:O.to,data:O.data,value:BigInt(O.value),chainId:u??1};return await o(ie)},[o,u]),{steps:Qt,currentStep:Ne,canExecute:we,isExecuting:F,allCompleted:se,hasError:Oe,cancelled:ae,executeCurrentTransaction:Ae,resetQueue:We,totalSteps:Re,completedSteps:Ie,showTxStatus:zt}=ve({earnRoute:v,userAddress:t,chainId:u,sendTransaction:$}),Ht=useMemo(()=>{let O=d?formatNumber(d,6,true,false):"0",ie=f&&a?formatToken(f,{decimals:a},true,false,6):"0";return {deposit:d?`${O} ${c?.symbol||"ETH"}`:"0 ETH",receive:f&&a?`${ie} ${s||"ETH"}`:"0 ETH",equivalentInUsd:d&&c?.price?(Number.parseFloat(d)*c.price).toFixed(2):"0.00",defaultOpen:true,slippage:p,setSlippage:m}},[d,f,a,s,c,p]);return jsxs("div",{className:cn("grid gap-3 flex-1 min-h-0",n?"grid-rows-[auto_1fr_auto] pb-6":"grid-rows-[auto_1fr]"),children:[jsx(SwapInput,{tokens:[],useCustomTokenSelector:true,selectedTokenData:c,onCustomTokenSelectorClick:()=>i("balances"),value:d??void 0,onChange:l,usdValue:S?void 0:w,balance:c?formatToken(c.balance,c,true,false,5):"0",onMaxClick:H,className:cn("p-5",S?"border-destructive/50 border":"border-border border")}),jsxs("div",{className:"overflow-auto min-h-0 space-y-3",children:[ne&&E&&jsx(SwapDetails,{details:Ht}),E&&E.length>0&&jsx(RouteDetails,{value:{steps:E}}),Ne&&d&&zt&&jsx(ye,{steps:Qt,currentStep:Ne,allCompleted:se,cancelled:ae,tokenSymbol:c?.symbol||"",amount:d,resetQueue:We,resetForm:We}),!n&&(!F||se)&&jsx("div",{className:"pt-3",children:jsx(xe,{fetchedRoute:v,routeError:g,isLoadingRoute:L,canExecute:we,isExecuting:F,hasError:Oe,cancelled:ae,executeCurrentTransaction:Ae,totalSteps:Re,completedSteps:Ie,showingTransactionStatus:F,hasInsufficientBalance:S})})]}),n&&(!F||se)&&jsx("div",{className:"w-full",children:jsx(xe,{fetchedRoute:v,routeError:g,isLoadingRoute:L,canExecute:we,isExecuting:F,hasError:Oe,cancelled:ae,executeCurrentTransaction:Ae,totalSteps:Re,completedSteps:Ie,showingTransactionStatus:F,hasInsufficientBalance:S})})]})}function co(e,t){let r={address:e.token.address,name:e.token.name,symbol:e.token.symbol,decimals:e.token.decimals,balance:e.amount,price:e.token.price??void 0,chainId:e.token.chain,logo:e.token.logos?.[0]},o=getNetworkByChainId(Number(t));return {id:`${t}-${r.address}`,symbol:r.symbol,name:r.name,icon:r.logo?jsx("img",{src:r.logo,alt:r.symbol,className:"h-8 w-8 rounded-full"}):jsx("div",{className:"bg-muted flex h-8 w-8 items-center justify-center rounded-full text-xs",children:r.symbol?.charAt(0)||"?"}),balance:formatToken(r.balance,r),balanceUSD:formatCurrencyWithCommas(Number.parseFloat(formatToken(r.balance,r))*(r.price||0),2),chainId:String(t),chainName:o?.name||"Unknown",address:r.address,decimals:r.decimals}}function Te(e){let t=[];return Object.entries(e).forEach(([r,o])=>{o.forEach(n=>{t.push(co(n,r));});}),t}function ke(e,t,r){let n=e[Number(t)]?.find(i=>i.token.address===r);return n?{address:n.token.address,name:n.token.name,symbol:n.token.symbol,decimals:n.token.decimals,logo:n.token.logos?.[0],icon:jsx("img",{src:n.token.logos?.[0],alt:n.token.symbol,className:"size-4 rounded-full"}),balance:n.amount,price:n.token.price??void 0,chainId:n.token.chain}:null}function wt(){let{selectToken:e,opportunity:t}=C(),{closeOverlay:r}=y(),{user:o}=W(),{balances:n,isLoading:i,error:u}=useMultiChainBalances({chainIds:[Number(t?.receiptToken?.chain.chainId)??mainnet.id],address:o||""}),s=useCallback(l=>{let m=ke(n,l.chainId,l.address);e(m),r();},[e,r,n]),a=useMemo(()=>Te(n),[n]);return i?jsx("div",{children:"Loading..."}):u?jsxs("div",{children:["Error: ",u.message]}):jsx(Y,{children:jsx(AssetList,{assets:a,onAssetClick:s,groupByChain:true,showChainIcon:true,filterVariant:"navigation",className:"h-full",itemClassName:"!rounded-full"})})}var yo=e=>{let r=Te(e)[0];return r?ke(e,r.chainId,r.address):null};function At(){let{user:e,network:t,sendTransaction:r}=W(),o=U(),{openOverlay:n}=y(),{token:i,selectOpportunity:u,selectToken:s,opportunity:a}=C(),{balances:l,isLoading:m}=useMultiChainBalances({chainIds:[Number(a?.receiptToken?.chain.chainId)??mainnet.id],address:e}),{data:c,isLoading:d}=useWidgetOpportunities(o);useEffect(()=>{if(c&&c.opportunities&&c.opportunities.length>0&&!a){let b=c.opportunities[0];u(b);}},[c,a]),useEffect(()=>{if(!i&&Object.keys(l).length>0){let b=yo(l);b&&s(b);}},[l,i]);let p=useMemo(()=>m||d,[m,d]);return {address:e,network:t,distributorId:o,openOverlay:n,sendTransaction:r,isLoading:p}}function To(e,t=4){return e?`${e.slice(0,t+2)}...${e.slice(-t)}`:""}function Wt(){let{isMember:e,isLoading:t,address:r,isConnected:o,disconnect:n}=R();if(t)return jsx("div",{className:"h-10 w-[133px] animate-pulse rounded-full bg-neutral-alpha-10"});if(!o)return null;if(o&&e)return jsx(Button,{variant:"ghost",border:"bordered",onClick:n,className:"group min-w-[140px] transition-colors",children:jsxs("div",{className:"gap-2 flex text-md items-center justify-between",children:[jsx(Wallet2Icon,{className:"size-6 stroke-accent group-hover:hidden"}),jsx(LogOutIcon,{className:"hidden size-6 stroke-destructive group-hover:block"}),jsx("span",{className:"group-hover:hidden",children:To(r)}),jsx("span",{className:"hidden group-hover:block text-foreground",children:"Disconnect"})]})})}function It(){let e=U(),{data:t}=useWidgetOpportunities(e),r=t?.chains||[],{changeNetwork:o,currentChain:n,isConnected:i}=R(),u=useMemo(()=>r.find(a=>Number(a.chainId)===n)||r[0],[r,n]),s=async a=>{try{await o(a);}catch(l){console.error("Failed to change network:",l);}};return i?jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{src:u?.logoUrl,children:u?.name}),jsx(DropdownMenuContent,{children:r.map(a=>jsxs(DropdownMenuItem,{onClick:()=>s(Number(a.chainId)),children:[jsx("img",{src:a.logoUrl,alt:a.name,className:"size-6 rounded-full"}),a.name]},a.id))})]}):null}function Ce(){return jsxs("div",{className:"flex justify-between items-center gap-2",children:[jsx(Wt,{}),jsx(It,{})]})}var _t=()=>jsx("div",{className:"mt-5 flex flex-col gap-4 h-full",children:jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex gap-3",children:[jsx(Skeleton,{className:"h-12 flex-1 rounded-turtle"}),jsx(Skeleton,{className:"h-12 w-48 rounded-turtle"})]}),jsxs(Card,{variant:"shadow",gradient:"white",className:"rounded-turtle space-y-2",children:[jsxs("div",{className:"flex justify-between p-4",children:[jsx(Skeleton,{className:"h-8 w-24"}),jsx(Skeleton,{className:"h-8 w-56 rounded-full"})]}),jsxs("div",{className:"mx-4 mb-4 space-y-1",children:[jsxs("div",{className:"flex justify-between",children:[jsx(Skeleton,{className:"h-4 w-16"}),jsx(Skeleton,{className:"h-4 w-40"})]}),jsxs("div",{className:"flex justify-between",children:[jsx(Skeleton,{className:"h-4 w-16"}),jsx(Skeleton,{className:"h-4 w-40"})]})]})]}),jsxs(Card,{variant:"shadow",className:"rounded-turtle p-4",children:[jsx("div",{className:"mb-4",children:jsx(Skeleton,{className:"h-20 w-full rounded-turtle"})}),jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsx(Skeleton,{className:"h-10 w-40 rounded-full"}),jsx(Skeleton,{className:"h-5 w-32"})]})]}),jsx(Skeleton,{className:"h-14 w-full rounded-turtle"})]})});var Lt=()=>{let{isConnected:e,connect:t}=R(),{address:r,distributorId:o,openOverlay:n,sendTransaction:i,isLoading:u}=At(),{opportunity:s,amount:a,token:l}=C(),m=c=>c.filter(d=>d.rewardType!=="points").reduce((d,p)=>d+(p.yield??0),0);return u?jsx(_t,{}):jsxs("div",{className:"mt-5 flex flex-col gap-4 h-full",children:[jsxs("div",{className:"text-foreground space-y-3",children:[jsx(Ce,{}),jsxs(Card,{variant:"shadow",gradient:"white",className:cn("rounded-turtle space-y-2"),children:[jsxs("div",{className:"flex justify-between p-4",children:[jsx(ee,{incentives:s?.incentives||[],className:"text-xl text-primary"}),jsx(BaseSelector,{icon:iconUrlToImg(s?.receiptToken?.logoUrl||"",s?.receiptToken?.symbol||""),text:s?.name||"",onClick:()=>n("opportunities"),size:"sm"})]}),jsx(OpportunityRateEstimator,{value:{symbol:s?.baseTokens?.symbol||"",price:s?.baseTokens?.priceUsd||0,depositedAmountUsd:Number(Number(a??0)*Number(l?.price??0))||0,apr:m(s?.incentives||[])}})]})]}),s&&r&&o&&jsx(Et,{opportunity:s,address:r,distributorId:o,stickyButton:true,executeTransaction:async c=>await i(c)}),!e&&jsx("div",{className:"mt-auto sticky bottom-0",children:jsx(Button,{variant:"green",border:"interactive",size:"lg",onClick:t,className:"w-full",children:"Connect Wallet"})})]})};function Ut(){let{isMember:e}=R(),t=useMemo(()=>({positions:{label:"Your Positions",component:ut,visible:e},earn:{label:"Earn",component:Lt},discover:{label:"Discover",component:lt}}),[e]),r=useMemo(()=>({opportunities:{component:at},balances:{component:wt}}),[]);return jsx(Ze,{children:jsx(de,{tabs:t,overlays:r,defaultTab:"earn"})})}function Bt({adapter:e,config:t,distributorId:r}){return jsx(De,{config:t,children:jsx(Xe,{adapter:e,distributorId:r,children:jsx(Ut,{})})})}var Lo={theme:"dark",widgetWidth:"default",customWidth:"100%",padding:"default",rounding:"default",fontFamily:"Montserrat",fontSecondary:"DM Sans",deals:[],campaigns:[],styles:{background:"#141514",background_dark:"#F9F9F9",foreground:"#F9F9F9",foreground_dark:"#141514",card:"#141514",card_dark:"#F9F9F9",muted_foreground:"#FFFFFF80",muted_foreground_dark:"#14151480",primary:"#73F36C",primary_dark:"#73F36C"}};//! Will be deprecated when just use distributorId to fetch everything from the API
|
|
2
|
-
export{
|
|
1
|
+
import {clsx}from'clsx';import {createContext,useMemo,useRef,useEffect,useCallback,useContext,useState,useReducer}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Card,cn,BaseSelector,iconUrlToImg,OpportunityRateEstimator,Button,AssetList,Skeleton,TurtleTooltip,SwapInput,SwapDetails,RouteDetails,DataTable,APIStatus,DropdownMenu,DropdownMenuTrigger,DropdownMenuContent,DropdownMenuItem,TxStatus}from'@turtleclub/ui';import {cva}from'class-variance-authority';import {useCheckMembership,useCreateMembershipAgreement,useCreateMembership,useMultiChainBalances,useWidgetOpportunities,useTokenBalance,useEarnRoute}from'@turtleclub/hooks';import {atom,useAtom,useAtomValue}from'jotai';import {InfoIcon,ChevronLeft,Wallet2Icon,LogOutIcon}from'lucide-react';import {formatNumber,formatToken,formatCurrency,getNetworkByChainId,formatCurrencyWithCommas,getNetworkById,getNetworkBackgroundColor}from'@turtleclub/utils';import {parseUnits}from'viem';import {mainnet}from'viem/chains';function $(...e){return clsx(e)}var Pe=createContext(null);function De({config:e,children:t}){return jsx(Pe.Provider,{value:e,children:t})}function U(){let e=useContext(Pe);if(!e)throw new Error("useWidgetConfig must be used within WidgetConfigProvider");return e}function X(e){return `rgb(from ${e} calc(255 - r) calc(255 - g) calc(255 - b))`}function jt(e,t=10){return `color-mix(in srgb, ${e} ${100-t}%, black)`}function _e(e,t){let r=t==="dark",o={"--color-brand-black":r?e.background_dark:X(e.background_dark),"--color-brand-white":r?e.foreground_dark:X(e.foreground_dark),"--color-brand-green":r?e.primary_dark:jt(e.primary_dark)};return (e.card!==void 0||e.card_dark!==void 0)&&(o["--color-surface-primary"]=r?e.card_dark??e.card??e.background_dark:X(e.card_dark??e.background_dark)),(e.muted_foreground!==void 0||e.muted_foreground_dark!==void 0)&&(o["--muted-foreground"]=r?e.muted_foreground_dark??e.muted_foreground??e.foreground_dark:X(e.muted_foreground_dark??e.muted_foreground_dark??e.foreground_dark)),o}var Le={background:"#F9F9F9",background_dark:"#141514",foreground:"#141514",foreground_dark:"#F9F9F9",primary:"#73F36C",primary_dark:"#73F36C",card:"#F9F9F9",card_dark:"#141514",muted_foreground:"#14151480",muted_foreground_dark:"#FFFFFF80"},Fe="dark",Me="Montserrat, sans-serif",Ue="DM Sans, sans-serif";function W(){let e=U(),t=e?.theme??Fe,r=e?.fontFamily??Me,o=e?.fontSecondary??Ue,s=e?.widgetWidth??"default",a=e?.customWidth??"100%",u=e?.showNavigation??true,i=e?.padding??"default",n=e?.rounding??"default",l=e?.styles??Le,m=_e(l,t==="auto"?"dark":t);return {theme:t,coreTokenCSS:m,fontPrimary:r,fontSecondary:o,widgetWidth:s,customWidth:a,showNavigation:u,padding:i,rounding:n,config:e,widgetStyles:l}}var Be={xxs:"h-4 text-xs",xs:"h-6 text-sm",sm:"h-8 text-2xl",md:"h-12 text-4xl",lg:"h-16 text-6xl"};function Qe({light:e,dark:t,fallback:r="Turtle Club",className:o,size:s="lg"}){let[a,u]=useState(false),{theme:i}=W(),l=i==="dark"?t||e:e||t;return l&&!a?jsx("div",{className:cn("flex justify-center items-center",o),children:jsx("img",{src:l,alt:r,className:cn("object-contain",Be[s]),onError:()=>u(true),onLoad:()=>u(false)})}):jsx("div",{className:cn("flex justify-center items-center",o),children:jsx("span",{className:cn("font-bold text-primary",Be[s]),children:r})})}function ze(){let e=U();return {light:e?.logo?.light,dark:e?.logo?.dark,fallback:e?.logo?.fallback||"Turtle Club"}}var tr=cva("p-0",{variants:{padding:{none:"p-0",sm:"p-3",default:"p-4",md:"p-6",lg:"p-7"}},defaultVariants:{padding:"default"}});function ue({children:e,className:t,variant:r,padding:o,rounding:s,showLogo:a=true,logoSize:u="xs",...i}){let{padding:n}=W(),{light:l,dark:p,fallback:m}=ze(),d=tr({padding:o??n});return jsxs(Card,{className:$(t,d),...i,variant:r,gradient:"white",children:[a&&jsx("div",{className:"flex-shrink-0 py-2",children:jsx(Qe,{light:l,dark:p,fallback:m,size:u})}),e]})}var Ve=createContext(null),Ge=createContext(""),Xe=({adapter:e,distributorId:t,children:r})=>jsx(Ve.Provider,{value:e,children:jsx(Ge.Provider,{value:t,children:r})}),I=()=>{let e=useContext(Ve);if(!e)throw new Error("useAdapter must be used within an AdapterProvider");return e},B=()=>useContext(Ge);function Ze({children:e}){let t=U(),{theme:r,coreTokenCSS:o,fontPrimary:s,fontSecondary:a,widgetWidth:u}=W();return jsx("div",{className:$("turtle-widget-root text-foreground","antialiased transition-all duration-700 ease-linear w-full overflow-hidden","h-full flex items-center justify-center",r==="dark"?"dark":""),style:{...o,"--font-primary":s,"--font-secondary":a,fontFamily:s,backgroundColor:"transparent",maxHeight:"90vh"},children:jsx("div",{className:$("flex flex-col gap-2 h-full overflow-hidden",u==="full"?"w-full items-center":u==="custom"?"items-stretch":"items-center"),style:{...u==="custom"&&t.customWidth?{width:t.customWidth}:u==="default"?{width:"620px"}:{}},children:jsx("div",{className:"w-full max-w-md h-full flex flex-col gap-2 overflow-hidden",children:e})})})}var R=()=>{let e=I(),t=useRef(void 0),r=useRef(false),{data:o,isLoading:s,refetch:a}=useCheckMembership({params:{address:e.user||"",walletEcosystem:"evm"},enabled:!!e.user}),{mutateAsync:u,isPending:i,error:n}=useCreateMembershipAgreement(),{mutateAsync:l,isPending:p,error:m}=useCreateMembership();useEffect(()=>{let h=e.user;if(!h){t.current!==void 0&&(t.current=void 0);return}h!==t.current&&(t.current=h,d(h));},[e.user]);let d=async h=>{if(!r.current){r.current=true;try{let{data:S}=await a();if(S?.isMember){console.log("[useWidgetAuth] User is already a member");return}console.log("[useWidgetAuth] User is not a member, starting membership flow..."),console.log("[useWidgetAuth] Creating membership agreement...");let N=await u({address:h,walletEcosystem:"evm",url:window.location.href,chainId:String(e.network||1)});console.log("[useWidgetAuth] Requesting signature from wallet...");let O=await e.signMessage(N.message);console.log("[useWidgetAuth] Creating membership with signature...");let E=await l({address:h,walletEcosystem:"evm",signature:O,nonce:N.nonce});E.isMember?console.log("[useWidgetAuth] Membership created successfully!"):console.error("[useWidgetAuth] Failed to create membership:",E.error);}catch(S){console.error("[useWidgetAuth] Membership flow error:",S);}finally{r.current=false;}}},c=s||i||p,b=n?.message||m?.message||null;return {address:e.user,isConnected:!!e.user,isMember:o?.isMember,currentChain:e.network,connect:e.openConnectionModal,disconnect:e.disconnect,changeNetwork:e.changeNetwork,isLoading:c,error:b}};function Ke(e){let[t,r]=useState(e),o=useCallback(s=>{r(s);},[]);return {currentTab:t,setTab:o}}var dr=atom({id:"none"});function y(){let[e,t]=useAtom(dr),r=useCallback((s,a)=>{t({id:s,data:a});},[t]),o=useCallback(()=>{t({id:"none"});},[t]);return {currentOverlay:e.id,overlayData:e.data,isOverlayOpen:e.id!=="none",openOverlay:r,closeOverlay:o}}function de({tabs:e,overlays:t,defaultTab:r}){let {showNavigation:o}=W(),{currentTab:s}=Ke(r),{currentOverlay:u,overlayData:i}=y();useMemo(()=>Object.entries(e).filter(([c,b])=>b.visible!==false).map(([c,b])=>({value:c,label:b.label})),[e]);let p=useMemo(()=>e[s].component,[s,e]),m=useMemo(()=>u==="none"?null:t[u].component,[u,t]);return jsxs(Fragment,{children:[o&&false,jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col gap-2 bg-transparent",children:jsx(ue,{variant:"border",className:"flex-1 min-h-0 w-full flex flex-col overflow-hidden",children:jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:m?jsx(m,{data:i}):jsx(p,{})})})})]})}function q({onBack:e,children:t,className:r}){let{closeOverlay:o}=y();return jsxs("div",{className:`flex flex-col h-full ${r||""}`,children:[jsx("div",{className:"flex items-center gap-2 pb-3",children:jsx(Button,{variant:"green",border:"interactive",size:"icon",onClick:e??o,className:"h-8 w-8 shrink-0","aria-label":"Go back",children:jsx(ChevronLeft,{className:"h-5 w-5"})})}),jsx("div",{className:"flex-1 min-h-0 overflow-auto pt-4",children:t})]})}var J=e=>e.filter(t=>t.rewardType!=="points").reduce((t,r)=>t+(r.yield??0),0),et=e=>({totalYield:useMemo(()=>J(e),[e])});function ee({incentives:e,isPill:t,className:r}){let{totalYield:o}=et(e),s=useMemo(()=>e.filter(a=>a.rewardType!=="points"&&a.yield!==null&&a.yield!==void 0).sort((a,u)=>u.yield-a.yield),[e]);return jsx(TurtleTooltip,{trigger:jsxs("div",{className:cn("group flex items-center gap-1",r,t&&"hover:bg-neutral-alpha-5 border-border bg-neutral-alpha-2 hover:border-gradient-white rounded-full border px-3 py-1.5 text-xs"),children:[formatNumber(o,1,false,false),"%"," ",jsx(InfoIcon,{className:"text-primary/70 group-hover:text-primary size-2.5"})]}),content:jsxs("div",{children:[jsx("div",{className:"text-sm",children:"APR Breakdown"}),jsx("div",{children:s.map(a=>jsxs("div",{className:"my-1 flex justify-between gap-2 text-xs",children:[jsxs("div",{className:"flex items-center gap-1",children:[a.iconUrl&&jsx("img",{src:a.iconUrl,alt:a.name||a.id,className:"size-4 rounded-full",loading:"lazy"}),jsx("div",{children:a.name})]}),jsxs("div",{children:[formatNumber(a.yield,1,false,false),"%"]})]},a.id))}),jsxs("div",{className:"text-primary flex justify-between gap-2 text-sm",children:[jsx("span",{children:"Total"}),jsxs("span",{children:[formatNumber(o,1,false,false),"%"]})]})]}),side:"bottom",contentClassName:"p-5 backdrop-blur-xl"})}function rt({chain:e,triggerClassName:t}){let r=getNetworkById(e.slug);return jsx("div",{className:cn("bg-foreground -mr-1 flex size-5 items-center justify-center overflow-hidden rounded-full ring-1 ring-white last:mr-0 lg:-mr-4 lg:size-6",getNetworkBackgroundColor(r),t),children:jsx("img",{src:e.logoUrl,className:"size-5 rounded-full object-contain lg:size-6",alt:e.name})})}var pe=atom(null),fe=atom(null),ge=atom(.001),be=atom(null),nt=atom(e=>{let t=e(pe),r=e(be),o=e(fe),s=e(ge),a=!!(o&&Number.parseFloat(o)>0),u=!!t&&!!r&&a&&!!s,i=u?{chain:Number(t?.receiptToken?.chain.chainId)??1,token_in:r?.address??"",token_out:t?.receiptToken?.address??"",amount:parseUnits(o??"0",r?.decimals??18).toString(),slippage:s}:void 0;return {opportunity:t,token:r,amount:o,options:i,isValid:u}});function C(){let[e,t]=useAtom(pe),[r,o]=useAtom(be),[s,a]=useAtom(fe),[u,i]=useAtom(ge),n=useAtomValue(nt),l=useCallback(()=>{o(null),a(""),i(.001);},[o,a,i]);return useEffect(()=>{r&&(a(""),i(.001));},[r,a,i]),{opportunity:e,token:r,amount:s,slippage:u,isValid:n.isValid,options:n.options,selectOpportunity:t,selectToken:o,setAmount:a,setSlippage:i,reset:l}}function re({opportunities:e}){let{changeNetwork:t,network:r}=I(),{selectOpportunity:o,selectToken:s}=C(),{closeOverlay:a}=y();return jsx(DataTable,{columns:[{accessorKey:"name",header:()=>jsx("div",{children:"Opportunity"}),cell:({row:n})=>jsxs("div",{className:"flex items-center gap-2 px-1",children:[jsx(APIStatus,{warning:false}),jsx("img",{src:n.original.token.logoUrl,className:"size-6 rounded-full",loading:"lazy"}),n.original.name||n.original.token.name]}),enableSorting:true},{accessorKey:"chain",header:()=>jsx("div",{className:"flex w-full justify-end",children:"Chain"}),cell:({row:n})=>jsx(rt,{chain:n.original.token.chain})},{id:"organization",accessorFn:n=>n.products.length?n.products[0].organization.name:"-",header:()=>jsx("div",{children:"Partner"}),cell:({row:n})=>n.original.products.length?jsxs("div",{className:"flex items-center gap-2",children:[jsx("img",{src:n.original.products[0].organization.iconUrl||"",className:"size-6 rounded-full",loading:"lazy"}),n.original.products[0].organization.name]}):"-",enableSorting:true},{accessorKey:"tvl",header:()=>jsx("div",{className:"flex w-full justify-end",children:"TVL"}),cell:({row:n})=>jsx("div",{className:"text-end",children:formatCurrency(n.original.tvl,0,true)}),enableSorting:true},{accessorKey:"totalYield",header:()=>jsx("div",{className:"flex w-full justify-end",children:"Estimated APR"}),cell:({row:n})=>jsx("div",{className:"flex flex-row-reverse",children:jsx(ee,{incentives:n.original.incentives})}),enableSorting:true,sortingFn:(n,l)=>{let p=J(n.original.incentives),m=J(l.original.incentives);return p-m}}],onRowClick:n=>{o(n);let l=Number(n.token.chain.chainId);l!==r&&(t(l),s(null)),a();},data:e,enableSearch:true,grid:{displayAsGrid:true,headerSlot:"name",rightSlot:"totalYield",excludeColumns:[],className:"grid-cols-1 gap-2.5"}})}function at(){let e=B(),{data:t,isLoading:r,error:o}=useWidgetOpportunities(e);return r?jsx("div",{children:"Loading..."}):o?jsxs("div",{children:["Error: ",o.message]}):t===void 0?jsx("div",{children:"No data"}):t.opportunities&&t.opportunities.length===0?jsx("div",{children:"No opportunities"}):jsx(q,{children:jsx(re,{opportunities:t.opportunities||[]})})}var ut=()=>{let{openOverlay:e}=y();return jsx("button",{onClick:()=>{e("balances"),console.log("Positions Content Click");},children:"Positions Content Click"})};var lt=()=>jsx("div",{children:"Discover Content"});function he({steps:e,currentStep:t,allCompleted:r,cancelled:o,tokenSymbol:s,amount:a,resetQueue:u,resetForm:i,refetchBalances:n}){let l=e.filter(c=>c.status==="completed"&&c.txHash).pop(),p=t?.txHash?t:null,m=r?l?.txHash:p?.txHash||l?.txHash,d=useMemo(()=>({title:o?"Transaction Cancelled":r?"Transaction Completed!":"Processing Transaction",description:o?"Transaction was cancelled by user":r?"Your deposit has been successfully processed.":"Please wait while your transaction is being confirmed...",txHash:m,explorerUrl:"https://etherscan.io",estimatedTime:void 0,amount:`${a?formatNumber(a,5,false,false):"0"}`,token:s,protocol:"Turtle Protocol",completed:r,cancelled:o,onViewDetails:void 0,onClose:()=>{u(),i(),n?.();},steps:e.map(c=>({label:c.label,completed:c.status==="completed",current:c.status==="executing",txHash:c.txHash}))}),[e,r,o,s,a,u,i,n,m]);return jsx("div",{className:"h-full overflow-hidden",children:jsx(TxStatus,{...d,className:"bg-background border-border text-foreground h-full"})})}function dt(e){return e.kind==="approve"&&e.token?`Approve ${e.token.symbol}`:e.kind==="enso"?"Execute Deposit":`Execute ${e.kind}`}function mt(e,t){return e.kind==="approve"&&e.token?`Allow contract to spend ${e.token.symbol}`:`Transaction step ${t+1}`}function pt(e){let t=e instanceof Error?e.message:String(e);return ["user rejected","user denied","user cancelled","cancelled by user","transaction rejected","4001"].some(o=>t.toLowerCase().includes(o.toLowerCase()))}function ft(e){if(e.steps.length<=1||e.queueStatus!=="idle")return false;let t=e.steps[e.currentIndex-1],r=e.steps[e.currentIndex];return e.currentIndex>0&&e.currentIndex<e.steps.length&&t?.status==="completed"&&r?.status==="pending"}var Hr=1e3;function ht(e,t){return e.tx?{id:t,label:dt(e),description:mt(e,t),txData:e.tx,status:"pending"}:null}function $r(e,t){switch(t.type){case "INITIALIZE_QUEUE":return {steps:t.steps,currentIndex:0,queueStatus:"idle",lastError:void 0};case "START_EXECUTION":return {...e,steps:e.steps.map((r,o)=>o===t.index?{...r,status:"executing"}:r),queueStatus:"executing",lastError:void 0};case "COMPLETE_STEP":{let r=e.steps.map((a,u)=>u===t.index?{...a,status:"completed",txHash:t.txHash}:a),o=t.index+1,s=o>=r.length;return {...e,steps:r,currentIndex:s?e.currentIndex:o,queueStatus:s?"completed":"idle"}}case "FAIL_STEP":return {...e,steps:e.steps.map((r,o)=>o===t.index?{...r,status:"failed",error:t.error}:r),queueStatus:t.isCancellation?"cancelled":"error",lastError:t.error};case "RESET_QUEUE":return {steps:t.steps,currentIndex:0,queueStatus:"idle",lastError:void 0};default:return e}}function ye({earnRoute:e,userAddress:t,chainId:r,sendTransaction:o,onError:s=()=>{},onSuccess:a=()=>{}}){let u={steps:[],currentIndex:0,queueStatus:"idle"},[i,n]=useReducer($r,u);useEffect(()=>{if(!e?.steps?.length){n({type:"INITIALIZE_QUEUE",steps:[]});return}let f=e.steps.map((T,g)=>ht(T,g)).filter(T=>T!==null);n({type:"INITIALIZE_QUEUE",steps:f});},[e]);let l=useCallback(async()=>{if(!t||!r||!o||i.queueStatus==="executing")return;let f=i.steps[i.currentIndex];if(!f||f.status!=="pending"&&f.status!=="failed")return;if(f.txData.from.toLowerCase()!==t.toLowerCase()){let g=new Error("Transaction 'from' address doesn't match connected wallet");n({type:"FAIL_STEP",index:i.currentIndex,error:g.message,isCancellation:false}),s&&s(g);return}n({type:"START_EXECUTION",index:i.currentIndex});try{let g=await o({...f.txData,chainId:r});n({type:"COMPLETE_STEP",index:i.currentIndex,txHash:g??""}),i.currentIndex+1>=i.steps.length&&a&&a();}catch(g){let _=g instanceof Error?g.message:"Transaction failed",M=pt(g);n({type:"FAIL_STEP",index:i.currentIndex,error:M?"Transaction cancelled by user":_,isCancellation:M}),!M&&s&&s(g instanceof Error?g:new Error(_));}},[t,r,o,i.queueStatus,i.steps,i.currentIndex,a,s]),p=useCallback(()=>{if(!e?.steps?.length)return;let f=e.steps.map((T,g)=>ht(T,g)).filter(T=>T!==null);n({type:"RESET_QUEUE",steps:f});},[e]),m=i.steps[i.currentIndex]||null,d=i.queueStatus==="executing",c=i.queueStatus==="completed",b=i.queueStatus==="error",h=i.queueStatus==="cancelled",S=i.steps.filter(f=>f.status==="completed").length,N=i.steps.length,O=N>0?S/N*100:0,E=useMemo(()=>m?!!(c||d&&m.id===0||m.id>0):false,[m,c,d]),ne=!!(t&&r&&i.steps.length>0&&i.queueStatus!=="executing"&&i.queueStatus!=="completed");return useEffect(()=>{if(ft(i)){let f=setTimeout(()=>{l();},Hr);return ()=>clearTimeout(f)}},[i,l]),{steps:i.steps.map((f,T)=>({...f,completed:f.status==="completed",current:T===i.currentIndex})),currentIndex:i.currentIndex,isExecuting:d,allCompleted:c,hasError:b,cancelled:h,error:i.lastError,currentStep:m?{...m,completed:m.status==="completed",current:true}:null,canExecute:ne,executeCurrentTransaction:l,resetQueue:p,totalSteps:N,completedSteps:S,progress:O,showTxStatus:E}}var Vr=(e,t,r)=>({in:{icon:t.logos[0],symbol:t.symbol},out:{icon:r.logos[0],symbol:r.symbol},amount:void 0,type:e}),Gr=(e,t)=>({in:{icon:e.logos[0],symbol:e.symbol},out:null,amount:formatToken(t,{decimals:e.decimals},true,false,4),type:"approve"});function yt(e){if(!e)return [];let t=[];return e.steps.forEach(r=>{if(r.kind==="approve"&&r.token){let o=Gr(r.token,r.amount);t.push(o);}r.kind==="enso"&&r.substeps&&r.substeps.forEach(o=>{let s=o.from[0],a=o.to[0],u=Vr(o.kind,s,a);t.push(u);});}),t}function vt(e){return {chainId:Number(e.receiptToken?.chain.chainId)??mainnet.id,address:e.receiptToken?.address??"",symbol:e.receiptToken?.symbol??"",decimals:e.receiptToken?.decimals??18}}function xt(e,t,r,o,s){let a=useMemo(()=>{if(!(!o||!e))return {...o,user:t,distributor_id:r,referral_code:s}},[o,t,r,s]),u=useMemo(()=>!!(t&&a?.token_in&&a?.token_out&&a?.amount&&a?.chain&&a?.slippage&&a?.distributor_id),[o]),{data:i,isLoading:n,error:l}=useEarnRoute({params:a,enabled:u&&e}),p=useMemo(()=>yt(i??null),[i]);return {fetchedRoute:i??null,outputAmount:i?.amount_out??void 0,isReady:u&&i&&!n,hasRequiredParams:u,routeDetails:p,routeError:l,isLoadingRoute:n}}function xe({fetchedRoute:e,routeError:t,isLoadingRoute:r,canExecute:o,isExecuting:s,hasError:a,cancelled:u,executeCurrentTransaction:i,totalSteps:n,completedSteps:l,showingTransactionStatus:p,hasInsufficientBalance:m}){let d=useCallback(async()=>{o&&await i();},[o,i]),c=useMemo(()=>p?null:r?{text:"Loading route...",disabled:true,className:"cursor-not-allowed"}:t?{text:"Route Error",disabled:true,className:"cursor-not-allowed"}:!e||!e.steps||e.steps.length===0?{text:"Enter amount to continue",disabled:true,className:"cursor-not-allowed"}:m?{text:"Insufficient Balance",disabled:true,className:"cursor-not-allowed"}:s?{text:"Executing...",disabled:true,className:"cursor-not-allowed"}:a?{text:"Retry Transaction",disabled:!o,onClick:d,className:"cursor-pointer"}:u?{text:"Try Again",disabled:!o,onClick:d,className:"cursor-pointer"}:{text:n>1&&l!==n?`Confirm Transaction (${l}/${n})`:"Confirm Transaction",disabled:false,onClick:d,className:"cursor-pointer"},[p,r,t,e,m,s,a,u,o,n,l,d]);return c?jsx(Button,{border:"plain",onClick:()=>c.onClick?.(),disabled:c.disabled,className:c.className+" w-full",children:c.text}):null}function Nt({opportunity:e,address:t,distributorId:r,executeTransaction:o,refetchBalances:s,stickyButton:a=false}){let{openOverlay:u}=y(),{chainId:i,symbol:n,decimals:l}=useMemo(()=>vt(e),[e]),{setAmount:p,setSlippage:m,token:d,amount:c,slippage:b,options:h,isValid:S,reset:N}=C(),{usdValue:O,hasInsufficientBalance:E,handleMaxClick:ne}=useTokenBalance({token:d,amount:c??void 0,setAmount:A=>p(A??null)}),{routeDetails:f,isReady:T,outputAmount:g,fetchedRoute:_,routeError:M,isLoadingRoute:Ee}=xt(S,t,r,h),zt=useCallback(async A=>{let ie={from:A.from,to:A.to,data:A.data,value:BigInt(A.value),chainId:i??1};return await o(ie)},[o,i]),{steps:Ht,currentStep:we,canExecute:Oe,isExecuting:G,allCompleted:$t,hasError:Ae,cancelled:se,executeCurrentTransaction:We,resetQueue:qt,totalSteps:Ie,completedSteps:Re,showTxStatus:ae}=ye({earnRoute:_,userAddress:t,chainId:i,sendTransaction:zt,onSuccess:()=>{s();}}),Yt=useMemo(()=>{let A=c?formatNumber(c,6,true,false):"0",ie=g&&l?formatToken(g,{decimals:l},true,false,6):"0";return {deposit:c?`${A} ${d?.symbol||"ETH"}`:"0 ETH",receive:g&&l?`${ie} ${n||"ETH"}`:"0 ETH",equivalentInUsd:c&&d?.price?(Number.parseFloat(c)*d.price).toFixed(2):"0.00",defaultOpen:true,slippage:b,setSlippage:m}},[c,g,l,n,d,b]);return jsxs("div",{className:cn("grid gap-3 flex-1 min-h-0",a?"grid-rows-[auto_1fr_auto] pb-6":"grid-rows-[auto_1fr]"),children:[jsx(SwapInput,{tokens:[],useCustomTokenSelector:true,selectedTokenData:d,onCustomTokenSelectorClick:()=>u("balances"),value:c??void 0,onChange:p,usdValue:E?void 0:O,balance:d?formatToken(d.balance,d,true,false,5):"0",onMaxClick:ne,className:cn("p-5",E?"border-destructive/50 border":"border-border border")}),jsxs("div",{className:"overflow-auto min-h-0 space-y-3",children:[T&&f&&jsx(SwapDetails,{details:Yt}),f&&f.length>0&&jsx(RouteDetails,{value:{steps:f}}),we&&c&&ae&&jsx(he,{steps:Ht,currentStep:we,allCompleted:$t,cancelled:se,tokenSymbol:d?.symbol||"",amount:c,resetQueue:qt,resetForm:N,refetchBalances:s}),!a&&!ae&&jsx("div",{className:"pt-3",children:jsx(xe,{fetchedRoute:_,routeError:M,isLoadingRoute:Ee,canExecute:Oe,isExecuting:G,hasError:Ae,cancelled:se,executeCurrentTransaction:We,totalSteps:Ie,completedSteps:Re,showingTransactionStatus:G,hasInsufficientBalance:E})})]}),a&&!ae&&jsx("div",{className:"w-full",children:jsx(xe,{fetchedRoute:_,routeError:M,isLoadingRoute:Ee,canExecute:Oe,isExecuting:G,hasError:Ae,cancelled:se,executeCurrentTransaction:We,totalSteps:Ie,completedSteps:Re,showingTransactionStatus:G,hasInsufficientBalance:E})})]})}function fo(e,t){let r={address:e.token.address,name:e.token.name,symbol:e.token.symbol,decimals:e.token.decimals,balance:e.amount,price:e.token.price??void 0,chainId:e.token.chain,logo:e.token.logos?.[0]},o=getNetworkByChainId(Number(t));return {id:`${t}-${r.address}`,symbol:r.symbol,name:r.name,icon:r.logo?jsx("img",{src:r.logo,alt:r.symbol,className:"h-8 w-8 rounded-full"}):jsx("div",{className:"bg-muted flex h-8 w-8 items-center justify-center rounded-full text-xs",children:r.symbol?.charAt(0)||"?"}),balance:formatToken(r.balance,r),balanceUSD:formatCurrencyWithCommas(Number.parseFloat(formatToken(r.balance,r))*(r.price||0),2),chainId:String(t),chainName:o?.name||"Unknown",address:r.address,decimals:r.decimals}}function Te(e){let t=[];return Object.entries(e).forEach(([r,o])=>{o.forEach(s=>{t.push(fo(s,r));});}),t}function ke(e,t,r){let s=e[Number(t)]?.find(a=>a.token.address===r);return s?{address:s.token.address,name:s.token.name,symbol:s.token.symbol,decimals:s.token.decimals,logo:s.token.logos?.[0],icon:jsx("img",{src:s.token.logos?.[0],alt:s.token.symbol,className:"size-4 rounded-full"}),balance:s.amount,price:s.token.price??void 0,chainId:s.token.chain}:null}function wt(){let{selectToken:e,opportunity:t}=C(),{closeOverlay:r}=y(),{user:o}=I(),{balances:s,isLoading:a,error:u}=useMultiChainBalances({chainIds:[Number(t?.receiptToken?.chain.chainId)??mainnet.id],address:o||""}),i=useCallback(l=>{let p=ke(s,l.chainId,l.address);e(p),r();},[e,r,s]),n=useMemo(()=>Te(s),[s]);return a?jsx("div",{children:"Loading..."}):u?jsxs("div",{children:["Error: ",u.message]}):jsx(q,{children:jsx(AssetList,{assets:n,onAssetClick:i,groupByChain:true,showChainIcon:true,filterVariant:"navigation",className:"h-full",itemClassName:"!rounded-full"})})}var vo=e=>{let r=Te(e)[0];return r?ke(e,r.chainId,r.address):null};function Wt(){let{user:e,network:t,sendTransaction:r}=I(),o=B(),{openOverlay:s}=y(),{token:a,selectOpportunity:u,selectToken:i,opportunity:n}=C(),{balances:l,isLoading:p,refetchAll:m}=useMultiChainBalances({chainIds:[Number(n?.receiptToken?.chain.chainId)??mainnet.id],address:e}),{data:d,isLoading:c}=useWidgetOpportunities(o);useEffect(()=>{if(d&&d.opportunities&&d.opportunities.length>0&&!n){let h=d.opportunities[0];u(h);}},[d,n]),useEffect(()=>{let h=Number(n?.receiptToken?.chain.chainId)??mainnet.id,S=a?.chainId;if((!a||S!==h)&&Object.keys(l).length>0){let O=vo(l);O&&i(O);}},[l,a,n]);let b=useMemo(()=>p||c,[p,c]);return {address:e,network:t,distributorId:o,openOverlay:s,sendTransaction:r,isLoading:b,refetchBalances:m}}function So(e,t=4){return e?`${e.slice(0,t+2)}...${e.slice(-t)}`:""}function It(){let{isMember:e,isLoading:t,address:r,isConnected:o,disconnect:s}=R();if(t)return jsx("div",{className:"h-10 w-[133px] animate-pulse rounded-full bg-neutral-alpha-10"});if(!o)return null;if(o&&e)return jsx(Button,{variant:"ghost",border:"bordered",onClick:s,className:"group min-w-[140px] transition-colors",children:jsxs("div",{className:"gap-2 flex text-md items-center justify-between",children:[jsx(Wallet2Icon,{className:"size-6 stroke-accent group-hover:hidden"}),jsx(LogOutIcon,{className:"hidden size-6 stroke-destructive group-hover:block"}),jsx("span",{className:"group-hover:hidden",children:So(r)}),jsx("span",{className:"hidden group-hover:block text-foreground",children:"Disconnect"})]})})}function Pt(){let e=B(),{data:t}=useWidgetOpportunities(e),r=t?.chains||[],{changeNetwork:o,currentChain:s,isConnected:a}=R(),u=useMemo(()=>r.find(n=>Number(n.chainId)===s)||r[0],[r,s]),i=async n=>{try{await o(n);}catch(l){console.error("Failed to change network:",l);}};return a?jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{src:u?.logoUrl,children:u?.name}),jsx(DropdownMenuContent,{children:r.map(n=>jsxs(DropdownMenuItem,{onClick:()=>i(Number(n.chainId)),children:[jsx("img",{src:n.logoUrl,alt:n.name,className:"size-6 rounded-full"}),n.name]},n.id))})]}):null}function Ce(){return jsxs("div",{className:"flex justify-between items-center gap-2",children:[jsx(It,{}),jsx(Pt,{})]})}var Lt=()=>jsx("div",{className:"mt-5 flex flex-col gap-4 h-full",children:jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex gap-3",children:[jsx(Skeleton,{className:"h-12 flex-1 rounded-turtle"}),jsx(Skeleton,{className:"h-12 w-48 rounded-turtle"})]}),jsxs(Card,{variant:"shadow",gradient:"white",className:"rounded-turtle space-y-2",children:[jsxs("div",{className:"flex justify-between p-4",children:[jsx(Skeleton,{className:"h-8 w-24"}),jsx(Skeleton,{className:"h-8 w-56 rounded-full"})]}),jsxs("div",{className:"mx-4 mb-4 space-y-1",children:[jsxs("div",{className:"flex justify-between",children:[jsx(Skeleton,{className:"h-4 w-16"}),jsx(Skeleton,{className:"h-4 w-40"})]}),jsxs("div",{className:"flex justify-between",children:[jsx(Skeleton,{className:"h-4 w-16"}),jsx(Skeleton,{className:"h-4 w-40"})]})]})]}),jsxs(Card,{variant:"shadow",className:"rounded-turtle p-4",children:[jsx("div",{className:"mb-4",children:jsx(Skeleton,{className:"h-20 w-full rounded-turtle"})}),jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsx(Skeleton,{className:"h-10 w-40 rounded-full"}),jsx(Skeleton,{className:"h-5 w-32"})]})]}),jsx(Skeleton,{className:"h-14 w-full rounded-turtle"})]})});var Ft=()=>{let{isConnected:e,connect:t}=R(),{address:r,distributorId:o,openOverlay:s,sendTransaction:a,isLoading:u,refetchBalances:i}=Wt(),{opportunity:n,amount:l,token:p}=C(),m=d=>d.filter(c=>c.rewardType!=="points").reduce((c,b)=>c+(b.yield??0),0);return u?jsx(Lt,{}):jsxs("div",{className:"mt-5 flex flex-col gap-4 h-full",children:[jsxs("div",{className:"text-foreground space-y-3",children:[jsx(Ce,{}),jsxs(Card,{variant:"shadow",gradient:"white",className:cn("rounded-turtle space-y-2"),children:[jsxs("div",{className:"flex justify-between p-4",children:[jsx(ee,{incentives:n?.incentives||[],className:"text-xl text-primary"}),jsx(BaseSelector,{icon:iconUrlToImg(n?.receiptToken?.logoUrl||"",n?.receiptToken?.symbol||""),text:n?.name||"",onClick:()=>s("opportunities"),size:"sm"})]}),jsx(OpportunityRateEstimator,{value:{symbol:n?.baseTokens?.symbol||"",price:n?.baseTokens?.priceUsd||0,depositedAmountUsd:Number(Number(l??0)*Number(p?.price??0))||0,apr:m(n?.incentives||[])}})]})]}),n&&r&&o&&jsx(Nt,{opportunity:n,address:r,distributorId:o,stickyButton:true,refetchBalances:i,executeTransaction:async d=>await a(d)}),!e&&jsx("div",{className:"mt-auto sticky bottom-0",children:jsx(Button,{variant:"green",border:"interactive",size:"lg",onClick:t,className:"w-full",children:"Connect Wallet"})})]})};function Bt(){let{isMember:e}=R(),t=useMemo(()=>({positions:{label:"Your Positions",component:ut,visible:e},earn:{label:"Earn",component:Ft},discover:{label:"Discover",component:lt}}),[e]),r=useMemo(()=>({opportunities:{component:at},balances:{component:wt}}),[]);return jsx(Ze,{children:jsx(de,{tabs:t,overlays:r,defaultTab:"earn"})})}function Qt({adapter:e,config:t,distributorId:r}){return jsx(De,{config:t,children:jsx(Xe,{adapter:e,distributorId:r,children:jsx(Bt,{})})})}var Mo={theme:"dark",widgetWidth:"default",customWidth:"100%",padding:"default",rounding:"default",fontFamily:"Montserrat",fontSecondary:"DM Sans",deals:[],campaigns:[],styles:{background:"#141514",background_dark:"#F9F9F9",foreground:"#F9F9F9",foreground_dark:"#141514",card:"#141514",card_dark:"#F9F9F9",muted_foreground:"#FFFFFF80",muted_foreground_dark:"#14151480",primary:"#73F36C",primary_dark:"#73F36C"}};//! Will be deprecated when just use distributorId to fetch everything from the API
|
|
2
|
+
export{Qt as EarnWidget,Mo as defaultWidgetStyleConfig};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|