@surf_liquid/surf-widget 0.1.5

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.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),f=require("react"),z=f.createContext(null);function fe(s,i){const t=i.colors??{},n={"--surf-primary":t.primary,"--surf-primary-text":t.primaryText,"--surf-background":t.background,"--surf-card-background":t.cardBackground,"--surf-text":t.text,"--surf-text-secondary":t.textSecondary,"--surf-apy":t.apy,"--surf-border":t.border,"--surf-success":t.success,"--surf-border-radius":i.borderRadius,"--surf-font-family":i.fontFamily};for(const[a,r]of Object.entries(n))r!=null&&s.style.setProperty(a,r)}function ne({config:s,containerRef:i,children:t}){const{client:n,walletAddress:a,chainId:r=8453,theme:o={},onSuccess:l,onError:h}=s;f.useEffect(()=>{i.current&&fe(i.current,o)},[o,i]);const u=f.useMemo(()=>({walletAddress:a,chainId:r,surfClient:n,theme:o,onSuccess:l,onError:h}),[a,r,n,o,l,h]);return e.jsx(z.Provider,{value:u,children:t})}function S(){const s=f.useContext(z);if(!s)throw new Error("useSurf must be used within a SurfProvider");return s}const pe={8453:"Base",137:"Polygon",84532:"Base Sepolia"};function xe(s,i){var u;const t=i||s.homeChainId||8453,n={name:pe[t]??`Chain ${t}`,id:t};if(!s.exists||s.assets.length===0)return{token:{symbol:"USDC",name:"USD Coin",decimals:6,address:""},chain:n,balance:"0.00",earnings:"0.00",apy:((u=s.apyBreakdown)==null?void 0:u.currentAPY)??0,withdrawalType:"instant",availableBalance:"0.00",userVaultAddress:s.userVaultAddress??void 0,assets:[]};const a=s.assets.filter(d=>d.chainId===t),r=a.length>0?a:s.assets,o=r.reduce((d,c)=>c.currentValueUSD>d.currentValueUSD?c:d,r[0]),l=r.reduce((d,c)=>d+c.currentValueUSD,0),h=r.reduce((d,c)=>d+c.totalEarningsUSD,0);return{token:{symbol:o.assetSymbol,name:o.assetSymbol==="USDC"?"USD Coin":o.assetSymbol,decimals:o.assetDecimals??6,address:o.assetAddress},chain:n,balance:l.toFixed(2),earnings:h.toFixed(2),apy:s.apyBreakdown.currentAPY,withdrawalType:"instant",availableBalance:l.toFixed(2),userVaultAddress:s.userVaultAddress??void 0,assets:a.length>0?a:s.assets}}function ie(){const{walletAddress:s,surfClient:i,chainId:t}=S(),[n,a]=f.useState(null),[r,o]=f.useState(!0),[l,h]=f.useState(null),[u,d]=f.useState(0);f.useEffect(()=>{let p=!1;async function m(){o(!0),h(null);try{const x=await i.getVault(s);p||a(xe(x,t))}catch(x){p||h(x instanceof Error?x:new Error(String(x)))}finally{p||o(!1)}}return m(),()=>{p=!0}},[s,i,t,u]);const c=f.useCallback(()=>d(p=>p+1),[]);return{vault:n,isLoading:r,error:l,refetch:c}}const _="https://cdn.jsdelivr.net/npm/@aanchal16/surf-widget-sdk/dist",w={USDC:`${_}/USDC.svg`,BASE_CHAIN:`${_}/Base.svg`,POLYGON:`${_}/Polygon.png`,SURF_TOKEN:`${_}/SurfToken.png`};function me(s){const i=["#3B82F6","#8B5CF6","#10B981","#F59E0B","#EF4444","#06B6D4","#EC4899","#6366F1"];let t=0;for(let n=0;n<s.length;n++)t=s.charCodeAt(n)+((t<<5)-t);return i[Math.abs(t)%i.length]}function T({symbol:s,icon:i,size:t=32,className:n}){const a=["surf-token-icon",n].filter(Boolean).join(" ");if(i)return e.jsx("img",{src:i,alt:s,className:a,style:{width:t,height:t}});if(s.toUpperCase()==="USDC")return e.jsx("img",{src:w.USDC,alt:"USDC",className:a,style:{width:t,height:t}});const r=me(s),o=s.slice(0,2).toUpperCase(),l=Math.floor(t*.38);return e.jsx("div",{className:a,style:{width:t,height:t,backgroundColor:r,fontSize:l},"aria-label":s,children:o})}function y({variant:s="primary",size:i="md",isLoading:t=!1,leftIcon:n,rightIcon:a,fullWidth:r=!1,children:o,className:l,disabled:h,style:u,...d}){const c=["surf-btn",`surf-btn--${s}`,`surf-btn--${i}`,r?"surf-btn--full":"",l??""].filter(Boolean).join(" ");return e.jsxs("button",{className:c,disabled:h||t,style:u,...d,children:[t?e.jsx("span",{className:"surf-btn-spinner"}):n&&e.jsx("span",{style:{flexShrink:0,display:"flex"},children:n}),o,!t&&a&&e.jsx("span",{style:{flexShrink:0,display:"flex"},children:a})]})}function re({isOpen:s,onClose:i,onWithdraw:t,onViewDeposits:n,onViewActivities:a}){const r=f.useRef(null);return f.useEffect(()=>{if(!s)return;const o=l=>{r.current&&!r.current.contains(l.target)&&i()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[s,i]),s?e.jsxs("div",{ref:r,className:"surf-dropdown surf-fade-in",children:[e.jsx("button",{className:"surf-dropdown-item",onClick:()=>{t(),i()},children:"Withdraw"}),e.jsx("button",{className:"surf-dropdown-item",onClick:()=>{n(),i()},children:"View Deposits"}),e.jsx("button",{className:"surf-dropdown-item",onClick:()=>{a(),i()},children:"Vault Activities"})]}):null}function ge({chainId:s}){const i=s===137?w.POLYGON:w.BASE_CHAIN;return e.jsx("img",{src:i,alt:`chain-${s}`,width:14,height:14,className:"surf-chain-icon"})}function P({label:s,value:i,apy:t=!1}){return e.jsxs("div",{className:"surf-stat",children:[e.jsx("span",{className:"surf-stat-label",children:s}),e.jsx("span",{className:["surf-stat-value",t?"surf-stat-value--apy":""].filter(Boolean).join(" "),children:i})]})}function ae({vault:s,onDeposit:i,onWithdraw:t,onViewDeposits:n,onViewActivities:a,isSelected:r=!1,isLoading:o=!1,className:l}){const[h,u]=f.useState(!1);if(o)return e.jsxs("div",{className:["surf-skeleton-card",l].filter(Boolean).join(" "),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:18},children:[e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[e.jsx("div",{className:"surf-skeleton",style:{width:44,height:44,borderRadius:"50%"}}),e.jsxs("div",{children:[e.jsx("div",{className:"surf-skeleton",style:{height:14,width:120,marginBottom:6}}),e.jsx("div",{className:"surf-skeleton",style:{height:11,width:60}})]})]}),e.jsx("div",{className:"surf-skeleton",style:{height:26,width:110,borderRadius:6}})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"center"},children:[e.jsx("div",{className:"surf-skeleton",style:{height:32,width:80}}),e.jsx("div",{className:"surf-skeleton",style:{height:32,width:60}}),e.jsx("div",{className:"surf-skeleton",style:{height:32,width:80}})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("div",{className:"surf-skeleton",style:{height:34,width:80,borderRadius:22}}),e.jsx("div",{className:"surf-skeleton",style:{height:34,width:100,borderRadius:22}})]})]})]});const d=parseFloat(s.balance).toLocaleString("en-US",{style:"currency",currency:"USD"}),c=parseFloat(s.earnings).toLocaleString("en-US",{style:"currency",currency:"USD"});return e.jsxs("div",{className:["surf-card",r?"surf-card--selected":"",l].filter(Boolean).join(" "),children:[e.jsxs("div",{className:"surf-card-header",children:[e.jsxs("div",{className:"surf-token-meta",children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:44}),e.jsxs("div",{children:[e.jsxs("p",{className:"surf-token-name",children:[s.token.name," ",e.jsx("span",{className:"surf-token-symbol",children:s.token.symbol})]}),e.jsxs("div",{className:"surf-chain-badge",children:[e.jsx(ge,{chainId:s.chain.id}),e.jsx("span",{className:"surf-chain-name",children:s.chain.name})]})]})]}),e.jsx("p",{className:"surf-balance-amount",children:d})]}),e.jsxs("div",{className:"surf-card-bottom",children:[e.jsxs("div",{className:"surf-stats-row",children:[e.jsx(P,{label:"Earnings",value:c}),e.jsx("div",{className:"surf-stat-divider"}),e.jsx(P,{label:"APY",value:s.apy.toFixed(2)+"%",apy:!0}),e.jsx("div",{className:"surf-stat-divider"}),e.jsx(P,{label:"Withdrawal",value:s.withdrawalType==="instant"?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},children:["Instant ",e.jsx("span",{style:{fontSize:13},children:"⚡"})]}):"Standard"})]}),e.jsxs("div",{className:"surf-actions",children:[e.jsx(y,{variant:"outline",size:"md",onClick:i,children:"Deposit"}),e.jsxs("div",{className:"surf-dropdown-wrap",children:[e.jsx(y,{variant:"primary",size:"md",onClick:()=>u(p=>!p),rightIcon:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",style:{transition:"transform 0.2s",transform:h?"rotate(180deg)":"none"},children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),children:"Manage"}),e.jsx(re,{isOpen:h,onClose:()=>u(!1),onWithdraw:t,onViewDeposits:n,onViewActivities:a})]})]})]})]})}function ye(s){var a,r;const i=((a=s.transactionType)==null?void 0:a.toUpperCase().includes("WITHDRAWAL"))||((r=s.transactionType)==null?void 0:r.toUpperCase().includes("WITHDRAW")),t=s.vaultVersion?` ${s.vaultVersion.toUpperCase()}`:"",n=s.executedBy==="AGENT"?`Surf Agent${t}`:`Surf${t}`;return{id:s.txHash,type:i?"withdraw":"deposit",description:s.message,protocol:n,timestamp:new Date(s.timestamp).getTime(),txHash:s.txHash}}function oe(){const{surfClient:s,walletAddress:i}=S(),[t,n]=f.useState([]),[a,r]=f.useState(!1),[o,l]=f.useState(0);f.useEffect(()=>{let u=!1;return r(!0),s.getAgentMessages(i).then(d=>{if(u)return;const c=Array.isArray(d)?d:d.messages??[];n(c.map(ye))}).catch(()=>{u||n([])}).finally(()=>{u||r(!1)}),()=>{u=!0}},[s,i,o]);const h=f.useCallback(()=>l(u=>u+1),[]);return{activities:t,isLoading:a,refetch:h}}function F({isOpen:s,onClose:i,children:t,className:n}){const a=f.useRef(null);return f.useEffect(()=>{if(!s)return;const r=o=>{o.key==="Escape"&&i()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[s,i]),s?e.jsx("div",{ref:a,className:"surf-modal-overlay surf-fade-in",onClick:r=>{r.target===a.current&&i()},children:e.jsx("div",{role:"dialog","aria-modal":"true",className:["surf-modal",n].filter(Boolean).join(" "),children:t})}):null}function N({tabs:s,activeTab:i,onChange:t,className:n,variant:a="underline"}){const r=["surf-tabs",a==="pill"?"surf-tabs--pill":"surf-tabs--underline",n].filter(Boolean).join(" ");return e.jsx("div",{className:r,children:s.map(o=>e.jsx("button",{onClick:()=>t(o.id),className:["surf-tab",o.id===i?"surf-tab--active":""].filter(Boolean).join(" "),children:o.label},o.id))})}const je={8453:"Base",137:"Polygon",84532:"Base Sepolia"};function be({timestamp:s}){const i=Date.now()-s,t=Math.floor(i/864e5),n=Math.floor(i/36e5),a=Math.floor(i/6e4);return t>=1?e.jsxs("span",{children:[t," day",t===1?"":"s"," ago"]}):n>=1?e.jsxs("span",{children:[n," hour",n===1?"":"s"," ago"]}):e.jsxs("span",{children:[Math.max(a,1)," min ago"]})}function ve({chainId:s,size:i=16}){return e.jsx("img",{src:s===137?w.POLYGON:w.BASE_CHAIN,alt:je[s??8453]??"Base",width:i,height:i})}function we({activity:s}){const i=s.type==="deposit";return e.jsxs("div",{className:"surf-activity-item",children:[e.jsx("div",{className:["surf-activity-icon",i?"surf-activity-icon--in":"surf-activity-icon--out"].join(" "),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:i?"#10B981":"#EF4444",strokeWidth:"2.5",children:i?e.jsx(e.Fragment,{children:e.jsx("path",{d:"M7 7l10 10M17 7v10H7"})}):e.jsx(e.Fragment,{children:e.jsx("path",{d:"M17 17L7 7M7 17V7h10"})})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{className:"surf-activity-desc",children:s.description}),e.jsxs("div",{className:"surf-activity-meta",children:[e.jsxs("span",{className:"surf-activity-protocol",children:[e.jsx("img",{src:w.SURF_TOKEN,alt:"Surf",width:16,height:16})," ",s.protocol," · ",e.jsx(be,{timestamp:s.timestamp})]}),s.txHash&&e.jsxs("a",{href:`https://basescan.org/tx/${s.txHash}`,target:"_blank",rel:"noopener noreferrer",className:"surf-activity-link",children:["View Transaction",e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})]})]})]})}function ke({deposit:s,onWithdraw:i,onDeposit:t}){return e.jsxs("tr",{className:"surf-deposits-tr",children:[e.jsx("td",{className:"surf-deposits-td",children:e.jsxs("div",{className:"surf-deposits-token",children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:22}),s.token.symbol]})}),e.jsx("td",{className:"surf-deposits-td",children:e.jsxs("div",{className:"surf-deposits-chain",children:[e.jsx(ve,{chainId:s.chain.id,size:16}),s.chain.name]})}),e.jsx("td",{className:"surf-deposits-td",children:s.amount}),e.jsx("td",{className:"surf-deposits-td",children:s.earned}),e.jsx("td",{className:"surf-deposits-td",children:e.jsxs("div",{className:"surf-deposits-actions",children:[e.jsx("button",{className:"surf-link-btn",onClick:i,children:"Withdraw"}),e.jsx(y,{variant:"primary",size:"sm",onClick:t,style:{borderRadius:50},children:"Deposit"}),s.vaultUrl&&e.jsxs("a",{href:s.vaultUrl,target:"_blank",rel:"noopener noreferrer",className:"surf-ext-link",children:["Vault",e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14 21 3"})})]})]})})]})}const Se=[{id:"activities",label:"Activities"},{id:"deposits",label:"Deposits"}];function le({isOpen:s,onClose:i,initialTab:t="activities",vault:n,onWithdraw:a,onDeposit:r}){const[o,l]=f.useState(t),{activities:h,isLoading:u}=oe(),d=n&&parseFloat(n.balance)>0?[{id:n.token.address||n.token.symbol,token:{symbol:n.token.symbol,icon:n.token.icon},chain:{name:n.chain.name,id:n.chain.id},amount:`${parseFloat(n.balance).toLocaleString("en-US",{minimumFractionDigits:2})} ${n.token.symbol}`,earned:`${parseFloat(n.earnings).toLocaleString("en-US",{minimumFractionDigits:2})} ${n.token.symbol}`}]:[];return f.useEffect(()=>{l(t)},[t]),e.jsxs(F,{isOpen:s,onClose:i,className:"surf-modal--wide",children:[e.jsx("button",{className:"surf-modal-close",onClick:i,"aria-label":"Close",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}),e.jsx("div",{style:{padding:"20px 20px 0"},children:e.jsx(N,{tabs:Se,activeTab:o,onChange:l,variant:"pill"})}),o==="activities"&&e.jsx("div",{className:"surf-modal-body",children:u?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[1,2,3].map(c=>e.jsx("div",{className:"surf-skeleton",style:{height:72,borderRadius:12}},c))}):h.length===0?e.jsx("div",{className:"surf-empty",children:"No activities yet"}):e.jsx("div",{className:"surf-activity-list",children:h.map(c=>e.jsx(we,{activity:c},c.id))})}),o==="deposits"&&e.jsx("div",{className:"surf-modal-body",style:{overflowX:"auto"},children:d.length===0?e.jsx("div",{className:"surf-empty",children:"No open deposits"}):e.jsxs("table",{className:"surf-deposits-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"surf-deposits-th",children:"Token"}),e.jsx("th",{className:"surf-deposits-th",children:"Blockchain"}),e.jsx("th",{className:"surf-deposits-th",children:"Amount"}),e.jsx("th",{className:"surf-deposits-th",children:"Earned"}),e.jsx("th",{className:"surf-deposits-th",style:{textAlign:"right"},children:"Actions"})]})}),e.jsx("tbody",{children:d.map(c=>e.jsx(ke,{deposit:c,onWithdraw:()=>{i(),a==null||a()},onDeposit:()=>{i(),r==null||r()}},c.id))})]})})]})}const X={id:"idle"};function O(){const{surfClient:s,walletAddress:i,onSuccess:t,onError:n}=S(),[a,r]=f.useState(X),o=f.useRef(a);o.current=a;const l=a.id!=="idle"&&a.id!=="success"&&a.id!=="error";f.useEffect(()=>{const d=({txHash:c})=>{r({id:"approving",txHash:c})};return s.on("deposit:approved",d),()=>s.off("deposit:approved",d)},[s]);const h=f.useCallback(async(d,c)=>{try{if(!c.userVaultAddress){r({id:"creating_contract"});const x=await s.deployVault();r({id:"creating_contract",txHash:x.transactionHash})}r({id:"approving"});const p=c.token.address,m=await s.deposit({asset:p,amount:d});r({id:"depositing",txHash:m.hash}),await m.wait(),r({id:"success",txHash:m.hash,amount:d}),t&&t("deposit",m.hash)}catch(p){const m=p instanceof Error?p:new Error(String(p));r({id:"error",error:m}),n&&n("deposit",m)}},[s,i,t,n]),u=f.useCallback(()=>r(X),[]);return{step:a,isProcessing:l,execute:h,reset:u}}const Q={id:"idle"};function Y(){const{surfClient:s,onSuccess:i,onError:t}=S(),[n,a]=f.useState(Q),r=n.id!=="idle"&&n.id!=="success"&&n.id!=="error",o=f.useCallback(async(h,u)=>{try{a({id:"closing_position"});const d=await s.withdraw({asset:u.token.address,amount:h||void 0});a({id:"closing_position",txHash:d.hash}),a({id:"redeeming_reward"}),await d.wait(),a({id:"redeeming_reward",txHash:d.hash}),a({id:"success",txHash:d.hash,amount:h}),i&&i("withdraw",d.hash)}catch(d){const c=d instanceof Error?d:new Error(String(d));a({id:"error",error:c}),t&&t("withdraw",c)}},[s,i,t]),l=f.useCallback(()=>a(Q),[]);return{step:n,isProcessing:r,execute:o,reset:l}}function ce(s,i=6){const t=i||6,n=typeof s=="bigint"?s:BigInt(Math.round(parseFloat(String(s)))),a=BigInt(10**t),r=n/a,o=n%a;if(o===0n)return r.toString();const l=o.toString().padStart(t,"0").replace(/0+$/,"");return`${r}.${l}`}function q(s,i=6){const{surfClient:t,walletAddress:n}=S(),[a,r]=f.useState("0"),[o,l]=f.useState(!1),[h,u]=f.useState(0);f.useEffect(()=>{if(!s)return;let c=!1;return l(!0),t.getTokenBalance(s,n).then(p=>{console.log("[useDepositBalance] raw:",p,"| type:",typeof p,"| token:",s),c||r(ce(p,i))}).catch(p=>{console.error("[useDepositBalance] error:",p),c||r("0")}).finally(()=>{c||l(!1)}),()=>{c=!0}},[t,n,s,i,h]);const d=f.useCallback(()=>u(c=>c+1),[]);return{balance:a,isLoading:o,refetch:d}}function G(s,i,t=6){const{surfClient:n}=S(),[a,r]=f.useState("0"),[o,l]=f.useState(!1),[h,u]=f.useState(0);f.useEffect(()=>{if(!s)return;let c=!1;return l(!0),n.getWithdrawableAmount(s,i).then(p=>{console.log("[useWithdrawableBalance] raw:",p,"| type:",typeof p,"| asset:",s),c||r(ce(p,t))}).catch(p=>{console.error("[useWithdrawableBalance] error:",p),c||r("0")}).finally(()=>{c||l(!1)}),()=>{c=!0}},[n,s,i,t,h]);const d=f.useCallback(()=>u(c=>c+1),[]);return{balance:a,isLoading:o,refetch:d}}function Ne({status:s}){return s==="completed"?e.jsx("div",{className:"surf-step-icon surf-step-icon--completed",children:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}):s==="active"?e.jsx("div",{className:"surf-step-icon surf-step-icon--active",children:e.jsx("span",{className:"surf-step-active-dot"})}):s==="error"?e.jsx("div",{className:"surf-step-icon surf-step-icon--error",children:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#ef4444",strokeWidth:"3",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}):e.jsx("div",{className:"surf-step-icon surf-step-icon--pending"})}const Z=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14 21 3"})});function I({steps:s,className:i,baseExplorerUrl:t="https://basescan.org/tx/"}){return e.jsx("div",{className:["surf-steps",i].filter(Boolean).join(" "),children:s.map((n,a)=>e.jsxs("div",{className:["surf-step",`surf-step--${n.status}`].join(" "),children:[e.jsxs("div",{className:"surf-step-icon-col",children:[e.jsx(Ne,{status:n.status}),a<s.length-1&&e.jsx("div",{className:["surf-step-line",n.status==="completed"?"surf-step-line--done":"",n.status==="active"?"surf-step-line--active":""].filter(Boolean).join(" ")})]}),e.jsxs("div",{className:"surf-step-body",children:[e.jsx("p",{className:"surf-step-title",children:n.title}),e.jsx("p",{className:"surf-step-desc",children:n.description})]}),e.jsx("div",{className:"surf-step-explore",children:n.txHash?e.jsxs("a",{href:`${t}${n.txHash}`,target:"_blank",rel:"noopener noreferrer",className:"surf-step-link",children:["Explore ",e.jsx(Z,{})]}):e.jsxs("span",{className:"surf-step-link surf-step-link--ghost",children:["Explore ",e.jsx(Z,{})]})})]},n.id))})}const de=[10,25,50,100];function K(s){return s.length<10?s:`${s.slice(0,6)}...${s.slice(-4)}`}function Ce(s){return(Math.floor(s*100)/100).toFixed(2)}function ue(s){const i=typeof s=="string"?s:(s==null?void 0:s.message)??"";if(!i)return"Transaction failed. Please try again.";const t=i.toLowerCase();if(t.includes("user rejected")||t.includes("user denied"))return"Transaction rejected by wallet.";if(t.includes("insufficient funds"))return"Insufficient funds for transaction.";if(t.includes("execution reverted"))return"Transaction reverted by contract.";if(t.includes("nonce"))return"Nonce error — please reset your wallet and retry.";if(t.includes("network")||t.includes("disconnected"))return"Network error. Check your connection.";const n=i.split(/[.(]/)[0].trim();return n.length>0&&n.length<=100?n:"Transaction failed. Please try again."}const Be=()=>e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),Ae=()=>e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14 21 3"})}),he=()=>e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:[e.jsx("path",{d:"M1 4v6h6M23 20v-6h-6"}),e.jsx("path",{d:"M20.49 9A9 9 0 005.64 5.64L1 10M23 14l-4.64 4.36A9 9 0 013.51 15"})]});function Te({vault:s,amount:i,availableBalance:t,isBalanceLoading:n,onAmountChange:a,onSubmit:r,onRefreshBalance:o,onSwitchTab:l}){const h=parseFloat(t)||0,u=parseFloat(i)||0,d=u>0&&u<=h;return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"deposit",onChange:l,variant:"pill"}),e.jsx("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:"Your surf is ready! Enter your deposit to activate"}),e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Token"}),e.jsxs("div",{className:"surf-select-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:26}),e.jsx("span",{style:{fontSize:14,fontWeight:600},children:s.token.symbol})]}),e.jsxs("span",{className:"surf-select-box--apy",children:[s.apy.toFixed(2),"% APY"]})]})]}),e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Blockchain"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[e.jsx("img",{src:s.chain.id===137?w.POLYGON:w.BASE_CHAIN,alt:s.chain.name,width:18,height:18}),e.jsx("span",{style:{fontSize:13,fontWeight:500},children:s.chain.name})]})})]})]}),e.jsxs("div",{className:"surf-amount-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{className:"surf-label",style:{margin:0},children:"Enter Amount"}),e.jsx("div",{style:{display:"flex",gap:10},children:de.map(c=>e.jsxs("button",{className:"surf-pct-link",onClick:()=>a((h*c/100).toFixed(2)),children:[c,"%"]},c))})]}),e.jsx("input",{type:"number",value:i,onChange:c=>a(c.target.value),placeholder:"0",min:"0",step:"any",className:"surf-amount-input"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:8},children:[e.jsxs("span",{className:"surf-amount-hint",children:["Min 100 ",s.token.symbol]}),e.jsxs("span",{className:"surf-amount-hint",children:["Available: ",n?"...":h.toLocaleString("en-US",{minimumFractionDigits:2})," ",s.token.symbol,e.jsx("button",{className:"surf-refresh-btn",onClick:o,title:"Refresh balance",children:e.jsx(he,{})})]})]})]}),e.jsxs(y,{variant:"primary",size:"lg",fullWidth:!0,disabled:!d,onClick:r,style:{borderRadius:50,marginTop:16},children:["Deposit ",s.token.symbol]}),e.jsxs("p",{className:"surf-disclaimer",style:{marginTop:10},children:["You'll need Base-bridged ETH to deposit. After activation, all agent fees are covered. By activating Surf, you agree to the"," ",e.jsx("a",{href:"https://surfliquid.com/terms",target:"_blank",rel:"noopener noreferrer",children:"platform terms"})," ","and ",e.jsx("a",{href:"https://surfliquid.com/privacy",target:"_blank",rel:"noopener noreferrer",children:"privacy policy"}),", and acknowledge that returns may vary according to market conditions and selected strategy"]})]})}function De({vault:s,amount:i,walletAddress:t,withdrawableBalance:n,isBalanceLoading:a,onAmountChange:r,onSubmit:o,onRefreshBalance:l,onSwitchTab:h}){const u=parseFloat(n)>0?parseFloat(n):parseFloat(s.availableBalance)||parseFloat(s.balance)||0,d=parseFloat(i)||0,c=d>0&&d<=u;return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"withdraw",onChange:h,variant:"pill"}),e.jsxs("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:["Surf will withdraw to your connected wallet"," ",e.jsx("span",{style:{fontWeight:600,color:"var(--surf-text)"},children:K(t)})]}),e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Token"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:26}),e.jsx("span",{style:{fontSize:14,fontWeight:600},children:s.token.symbol})]})})]}),e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Blockchain"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[e.jsx("img",{src:s.chain.id===137?w.POLYGON:w.BASE_CHAIN,alt:s.chain.name,width:18,height:18}),e.jsx("span",{style:{fontSize:13,fontWeight:500},children:s.chain.name})]})})]})]}),e.jsxs("div",{className:"surf-amount-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{className:"surf-label",style:{margin:0},children:"Enter Amount"}),e.jsx("div",{style:{display:"flex",gap:10},children:de.map(p=>e.jsxs("button",{className:"surf-pct-link",onClick:()=>r(Ce(u*p/100)),children:[p,"%"]},p))})]}),e.jsx("input",{type:"number",value:i,onChange:p=>r(p.target.value),placeholder:"0",min:"0",step:"any",className:"surf-amount-input"}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"flex-end",marginTop:8},children:e.jsxs("span",{className:"surf-amount-hint",children:["Available: ",a?"...":u.toLocaleString("en-US",{minimumFractionDigits:2})," ",s.token.symbol,e.jsx("button",{className:"surf-refresh-btn",onClick:l,title:"Refresh balance",children:e.jsx(he,{})})]})})]}),e.jsx(y,{variant:"primary",size:"lg",fullWidth:!0,disabled:!c,onClick:o,style:{borderRadius:50,marginTop:16},children:"Withdraw funds"}),e.jsx("p",{className:"surf-disclaimer",style:{marginTop:10},children:"Rewards will also be withdrawn by default"})]})}function Ee(s,i){const t=["creating_contract","approving","depositing"];function n(r){if(r==="creating_contract"&&i)return"completed";const o=t.indexOf(s.id),l=t.indexOf(r);return s.id==="success"?"completed":o===-1?"pending":l<o?"completed":l===o?"active":"pending"}function a(r){return s.id===r&&"txHash"in s?s.txHash:void 0}return[{id:"creating_contract",title:"Surf Account Creation",description:"Deploy your self-custodial smart contract",status:n("creating_contract"),txHash:a("creating_contract")},{id:"approving",title:"Approve USDC",description:"Grant access for automated strategies",status:n("approving"),txHash:a("approving")},{id:"depositing",title:"Deposit USDC",description:"Fund your Surf Account by depositing",status:n("depositing"),txHash:a("depositing")}]}function We({step:s,vaultExists:i,onDashboard:t,onSwitchTab:n}){const a=s.id==="depositing"&&"txHash"in s&&!!s.txHash,r=!a&&s.id!=="success"&&s.id!=="error"&&s.id!=="idle",o=s.id==="creating_contract"?"Creating contract":s.id==="approving"?"Approve USDC":s.id==="depositing"?"Access Dashboard":"Processing...";return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"deposit",onChange:n,variant:"pill"}),e.jsx("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:"Confirm wallet requests to finish agent activation"}),e.jsx(I,{steps:Ee(s,i)}),e.jsx("div",{style:{marginTop:20},children:e.jsx(y,{variant:a?"primary":"soft",size:"lg",fullWidth:!0,isLoading:r,disabled:!a&&s.id!=="error",onClick:a?t:void 0,style:{borderRadius:50},children:o})}),s.id==="error"&&e.jsxs("div",{className:"surf-error-box",children:["⚠ ",ue(s.error)]})]})}function Me(s,i,t){const n=["closing_position","redeeming_reward"];function a(o){const l=n.indexOf(s.id),h=n.indexOf(o);return s.id==="success"?"completed":l===-1?"pending":h<l?"completed":h===l?"active":"pending"}function r(o){return s.id===o&&"txHash"in s?s.txHash:void 0}return[{id:"closing_position",title:"Close current position",description:`Withdraw ${parseFloat(i||"0").toFixed(2)} ${t} from Vault`,status:a("closing_position"),txHash:r("closing_position")},{id:"redeeming_reward",title:"Redeem Reward",description:"Transferring to your wallet",status:a("redeeming_reward"),txHash:r("redeeming_reward")}]}function Fe({step:s,amount:i,tokenSymbol:t,walletAddress:n,onSwitchTab:a}){const r=s.id!=="success"&&s.id!=="error"&&s.id!=="idle",o=s.id==="closing_position"?"Withdrawing Funds...":s.id==="redeeming_reward"?"Redeeming Reward...":"Processing...";return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"withdraw",onChange:a,variant:"pill"}),e.jsxs("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:["Surf is resolving all your positions and withdrawing to your connected wallet ",e.jsx("strong",{children:K(n)})]}),e.jsx(I,{steps:Me(s,i,t)}),e.jsx("div",{style:{marginTop:20},children:e.jsx(y,{variant:"soft",size:"lg",fullWidth:!0,isLoading:r,disabled:s.id!=="error",style:{borderRadius:50},children:o})}),s.id==="error"&&e.jsxs("div",{className:"surf-error-box",children:["⚠ ",ue(s.error)]})]})}function ee({action:s,amount:i,tokenSymbol:t,walletAddress:n,txHash:a,onExplore:r,onBack:o}){return e.jsxs("div",{className:"surf-success",children:[e.jsx("div",{className:"surf-success-icon",children:e.jsx("div",{className:"surf-success-icon-inner",children:e.jsx(Be,{})})}),e.jsx("p",{className:"surf-success-title",children:"You're all done!"}),e.jsxs("p",{className:"surf-success-desc",children:["Successfully ",s==="deposit"?"deposited":"withdrew"," ",e.jsxs("strong",{children:[parseFloat(i).toLocaleString("en-US",{minimumFractionDigits:2})," ",t]})," ","to your wallet ",e.jsx("strong",{children:K(n)})]}),e.jsxs("div",{className:"surf-success-actions",children:[e.jsx(y,{variant:"outline",size:"md",style:{flex:1},onClick:r,rightIcon:e.jsx(Ae,{}),children:"Explore"}),e.jsx(y,{variant:"primary",size:"md",style:{flex:1},onClick:o,children:"Back to dashboard"})]})]})}const Ie={token:{symbol:"USDC",name:"USD Coin",decimals:6,address:""},chain:{name:"Base",id:8453},balance:"0.00",earnings:"0.00",apy:0,withdrawalType:"instant",availableBalance:"0.00"};function He({isOpen:s,initialTab:i,onClose:t,vault:n}){const{walletAddress:a}=S(),r=n??Ie,[o,l]=f.useState(i),[h,u]=f.useState(""),[d,c]=f.useState(""),{step:p,execute:m,reset:x}=O(),{step:g,execute:v,reset:B}=Y(),{balance:R,isLoading:V,refetch:$}=q(r.token.address,r.token.decimals??6),{balance:D,isLoading:E,refetch:W}=G(r.token.address,r.userVaultAddress,r.token.decimals??6),M=f.useState(i)[0];s&&i!==M&&l(i);function C(U){U!==o&&(U==="deposit"?(B(),c("")):(x(),u("")),l(U))}function A(){x(),B(),u(""),c(""),t()}const H=p.id==="idle",j=p.id==="success",b=g.id==="idle",k=g.id==="success";function L(){return o==="deposit"?j&&p.id==="success"?e.jsx(ee,{action:"deposit",amount:p.amount,tokenSymbol:r.token.symbol,walletAddress:a,txHash:p.txHash,onExplore:()=>window.open(`https://basescan.org/tx/${p.txHash}`,"_blank"),onBack:A}):H?e.jsx(Te,{vault:r,amount:h,availableBalance:R,isBalanceLoading:V,onAmountChange:u,onSubmit:()=>h&&m(h,r),onRefreshBalance:$,onSwitchTab:C}):e.jsx(We,{step:p,vaultExists:!!r.userVaultAddress,onDashboard:A,onSwitchTab:C}):k&&g.id==="success"?e.jsx(ee,{action:"withdraw",amount:g.amount,tokenSymbol:r.token.symbol,walletAddress:a,txHash:g.txHash,onExplore:()=>window.open(`https://basescan.org/tx/${g.txHash}`,"_blank"),onBack:A}):b?e.jsx(De,{vault:r,amount:d,walletAddress:a,withdrawableBalance:D,isBalanceLoading:E,onAmountChange:c,onSubmit:()=>d&&v(d,r),onRefreshBalance:W,onSwitchTab:C}):e.jsx(Fe,{step:g,amount:d,tokenSymbol:r.token.symbol,walletAddress:a,onSwitchTab:C})}return e.jsxs(F,{isOpen:s,onClose:A,children:[e.jsx("button",{className:"surf-modal-close",onClick:A,"aria-label":"Close",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}),L()]})}function Le(){const{vault:s,isLoading:i,refetch:t}=ie(),{chainId:n}=S(),a=f.useRef(null);s&&(a.current=s);const r=s??a.current,[o,l]=f.useState(null),[h,u]=f.useState(!1),[d,c]=f.useState("activities");function p(){u(!1),l("deposit")}function m(){u(!1),l("withdraw")}function x(B="activities"){l(null),c(B),u(!0)}const v={token:{symbol:"USDC",name:"USD Coin",decimals:6,address:""},chain:{name:{8453:"Base",137:"Polygon"}[n]??"Base",id:n},balance:"0.00",earnings:"0.00",apy:0,withdrawalType:"instant",availableBalance:"0.00"};return e.jsxs(e.Fragment,{children:[e.jsx(ae,{vault:r??v,isLoading:i&&!r,onDeposit:p,onWithdraw:m,onViewDeposits:()=>x("deposits"),onViewActivities:()=>x("activities")}),e.jsx(He,{isOpen:o!==null,initialTab:o??"deposit",onClose:()=>{l(null),t()},vault:r}),e.jsx(le,{isOpen:h,onClose:()=>u(!1),initialTab:d,vault:r,onWithdraw:m,onDeposit:p})]})}function _e({client:s,walletAddress:i,chainId:t,theme:n,onSuccess:a,onError:r,className:o}){const l=f.useRef(null);return e.jsx("div",{ref:l,className:["surf-widget-root",o].filter(Boolean).join(" "),"data-surf-widget":!0,children:e.jsx("div",{className:"surf-widget-shell",children:e.jsx(ne,{config:{client:s,walletAddress:i,chainId:t,theme:n,onSuccess:a,onError:r},containerRef:l,children:e.jsx(Le,{})})})})}const se="https://e609-106-219-158-226.ngrok-free.app";function Re({value:s}){const[i,t]=f.useState(!1);function n(){navigator.clipboard.writeText(s).then(()=>{t(!0),setTimeout(()=>t(!1),2e3)})}return e.jsx("button",{onClick:n,title:"Copy to clipboard",style:{background:"none",border:"none",cursor:"pointer",padding:"2px 6px",borderRadius:4,color:i?"#22c55e":"#6b7280",fontSize:12,fontWeight:600,flexShrink:0},children:i?"✓ Copied":"Copy"})}function te({label:s,value:i,masked:t}){const[n,a]=f.useState(!1),r=t&&!n?"•".repeat(Math.min(i.length,36)):i;return e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#6b7280",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:s}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:8,padding:"8px 12px"},children:[e.jsx("span",{style:{fontFamily:"monospace",fontSize:13,color:"#1a2540",flex:1,wordBreak:"break-all"},children:r}),t&&e.jsx("button",{onClick:()=>a(o=>!o),style:{background:"none",border:"none",cursor:"pointer",fontSize:11,color:"#6b7280",flexShrink:0,padding:"2px 4px"},children:n?"Hide":"Show"}),e.jsx(Re,{value:i})]})]})}function Ve({walletAddress:s="",onSuccess:i}){const[t,n]=f.useState("register"),[a,r]=f.useState(!1),[o,l]=f.useState(""),[h,u]=f.useState(s),[d,c]=f.useState(""),[p,m]=f.useState(""),[x,g]=f.useState(""),[v,B]=f.useState(null);async function R(j){j.preventDefault(),l(""),r(!0);try{const b=await fetch(`${se}/api/sdk/register`,{method:"POST",headers:{"Content-Type":"application/json","ngrok-skip-browser-warning":"1"},body:JSON.stringify({walletAddress:h,email:d,appName:p})}),k=await b.json();if(!b.ok)throw new Error((k==null?void 0:k.message)||`Error ${b.status}`);n("verify")}catch(b){l(b.message??"Registration failed")}finally{r(!1)}}async function V(j){j.preventDefault(),l(""),r(!0);try{const b=await fetch(`${se}/api/sdk/verify-email`,{method:"POST",headers:{"Content-Type":"application/json","ngrok-skip-browser-warning":"1"},body:JSON.stringify({email:d,otp:x})}),k=await b.json();if(!b.ok)throw new Error((k==null?void 0:k.message)||`Error ${b.status}`);const L={appId:k.appId,apiSecret:k.apiSecret};B(L),n("done"),i==null||i(L)}catch(b){l(b.message??"Verification failed")}finally{r(!1)}}const $={background:"white",border:"1px solid #e5e7eb",borderRadius:16,padding:28,maxWidth:420,width:"100%",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},D={display:"block",fontSize:13,fontWeight:600,color:"#374151",marginBottom:6},E={width:"100%",padding:"10px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:14,color:"#1a2540",outline:"none",boxSizing:"border-box",fontFamily:"inherit",transition:"border-color 0.15s"},W={width:"100%",padding:"11px 16px",borderRadius:10,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:14,cursor:a?"not-allowed":"pointer",opacity:a?.7:1,marginTop:4},M={fontWeight:700,fontSize:18,color:"#1a2540",marginBottom:4},C={fontSize:13,color:"#6b7280",marginBottom:20},A=["Register","Verify OTP","Done"],H=t==="register"?0:t==="verify"?1:2;return e.jsxs("div",{style:$,children:[e.jsx("div",{style:{display:"flex",gap:6,marginBottom:24},children:A.map((j,b)=>e.jsx("div",{style:{flex:1,textAlign:"center",fontSize:11,fontWeight:600,padding:"4px 0",borderRadius:20,background:b<=H?"#2563eb":"#f3f4f6",color:b<=H?"white":"#9ca3af",transition:"all 0.2s"},children:j},j))}),t==="register"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:M,children:"Register your app"}),e.jsxs("div",{style:C,children:["Get an ",e.jsx("code",{children:"appId"})," and ",e.jsx("code",{children:"apiSecret"})," to start integrating SurfLiquid SDK."]}),e.jsxs("form",{onSubmit:R,style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:D,children:"Wallet address"}),e.jsx("input",{style:E,type:"text",placeholder:"0x...",value:h,onChange:j=>u(j.target.value),required:!0,spellCheck:!1})]}),e.jsxs("div",{children:[e.jsx("label",{style:D,children:"Email"}),e.jsx("input",{style:E,type:"email",placeholder:"you@yourplatform.com",value:d,onChange:j=>c(j.target.value),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{style:D,children:"App name"}),e.jsx("input",{style:E,type:"text",placeholder:"My DeFi App",value:p,onChange:j=>m(j.target.value),required:!0})]}),o&&e.jsx("p",{style:{margin:0,color:"#ef4444",fontSize:13},children:o}),e.jsx("button",{type:"submit",style:W,disabled:a,children:a?"Sending OTP…":"Register →"})]})]}),t==="verify"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:M,children:"Check your email"}),e.jsxs("div",{style:C,children:["We sent a 6-digit OTP to ",e.jsx("strong",{children:d}),". Enter it below to complete registration."]}),e.jsxs("form",{onSubmit:V,style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:D,children:"OTP code"}),e.jsx("input",{style:{...E,fontSize:22,letterSpacing:"0.3em",textAlign:"center",fontFamily:"monospace"},type:"text",inputMode:"numeric",placeholder:"------",maxLength:6,value:x,onChange:j=>g(j.target.value.replace(/\D/g,"")),required:!0,autoFocus:!0})]}),o&&e.jsx("p",{style:{margin:0,color:"#ef4444",fontSize:13},children:o}),e.jsx("button",{type:"submit",style:W,disabled:a||x.length<6,children:a?"Verifying…":"Verify →"}),e.jsx("button",{type:"button",style:{...W,background:"transparent",color:"#6b7280",border:"1px solid #e5e7eb",marginTop:0},onClick:()=>{n("register"),l(""),g("")},disabled:a,children:"← Back"})]})]}),t==="done"&&v&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:22},children:"🎉"}),e.jsx("div",{style:M,children:"App registered!"})]}),e.jsxs("div",{style:C,children:["Save your credentials below. ",e.jsx("strong",{children:"apiSecret is shown only once"})," and cannot be recovered."]}),e.jsx(te,{label:"App ID (public)",value:v.appId}),e.jsx(te,{label:"API Secret (keep secret!)",value:v.apiSecret,masked:!0}),e.jsxs("div",{style:{marginTop:16,padding:"10px 14px",background:"#fefce8",border:"1px solid #fde68a",borderRadius:8,fontSize:12,color:"#92400e",lineHeight:1.5},children:["Store ",e.jsx("strong",{children:"apiSecret"})," securely (env var, secret manager). Embed ",e.jsx("strong",{children:"appId"})," freely in your frontend."]}),e.jsx("button",{style:{...W,marginTop:16,background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"},onClick:()=>{n("register"),u(s),c(""),m(""),g(""),B(null),l("")},children:"Register another app"})]})]})}const $e=[10,25,50,100];function Ue(s){return s.length<10?s:`${s.slice(0,6)}...${s.slice(-4)}`}function Pe(s){const i=typeof s=="string"?s:(s==null?void 0:s.message)??"";if(!i)return"Transaction failed. Please try again.";const t=i.toLowerCase();if(t.includes("user rejected")||t.includes("user denied"))return"Transaction rejected by wallet.";if(t.includes("insufficient funds"))return"Insufficient funds for transaction.";if(t.includes("execution reverted"))return"Transaction reverted by contract.";if(t.includes("nonce"))return"Nonce error — please reset your wallet and retry.";if(t.includes("network")||t.includes("disconnected"))return"Network error. Check your connection.";const n=i.split(/[.(]/)[0].trim();return n.length>0&&n.length<=100?n:"Transaction failed. Please try again."}function ze({vault:s,amount:i,availableBalance:t,isBalanceLoading:n,onAmountChange:a,onSubmit:r,onRefreshBalance:o,onSwitchToWithdraw:l}){const h=parseFloat(t)||0,u=parseFloat(i)||0,d=u>0&&u<=h;return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"deposit",onChange:c=>{c==="withdraw"&&l()},variant:"pill"}),e.jsx("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:"Your surf is ready! Enter your deposit to activate"}),e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Token"}),e.jsxs("div",{className:"surf-select-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:26}),e.jsx("span",{style:{fontSize:14,fontWeight:600},children:s.token.symbol})]}),e.jsxs("span",{className:"surf-select-box--apy",children:[s.apy.toFixed(2),"% APY"]})]})]}),e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Blockchain"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[e.jsx("img",{src:s.chain.id===137?w.POLYGON:w.BASE_CHAIN,alt:s.chain.name,width:18,height:18}),e.jsx("span",{style:{fontSize:13,fontWeight:500},children:s.chain.name})]})})]})]}),e.jsxs("div",{className:"surf-amount-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{className:"surf-label",style:{margin:0},children:"Enter Amount"}),e.jsx("div",{style:{display:"flex",gap:10},children:$e.map(c=>e.jsxs("button",{className:"surf-pct-link",onClick:()=>a((h*c/100).toFixed(2)),children:[c,"%"]},c))})]}),e.jsx("input",{type:"number",value:i,onChange:c=>a(c.target.value),placeholder:"0",min:"0",step:"any",className:"surf-amount-input"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:8},children:[e.jsxs("span",{className:"surf-amount-hint",children:["Min 100 ",s.token.symbol]}),e.jsxs("span",{className:"surf-amount-hint",children:["Available:"," ",n?"...":h.toLocaleString("en-US",{minimumFractionDigits:2})," ",s.token.symbol,e.jsx("button",{className:"surf-refresh-btn",onClick:o,title:"Refresh balance",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:[e.jsx("path",{d:"M1 4v6h6M23 20v-6h-6"}),e.jsx("path",{d:"M20.49 9A9 9 0 005.64 5.64L1 10M23 14l-4.64 4.36A9 9 0 013.51 15"})]})})]})]})]}),e.jsxs(y,{variant:"primary",size:"lg",fullWidth:!0,disabled:!d,onClick:r,style:{borderRadius:50,marginTop:16},children:["Deposit ",s.token.symbol]}),e.jsxs("p",{className:"surf-disclaimer",style:{marginTop:10},children:["You'll need Base-bridged ETH to deposit. After activation, all agent fees are covered. By activating Surf, you agree to the"," ",e.jsx("a",{href:"https://surfliquid.com/terms",target:"_blank",rel:"noopener noreferrer",children:"platform terms"})," ","and"," ",e.jsx("a",{href:"https://surfliquid.com/privacy",target:"_blank",rel:"noopener noreferrer",children:"privacy policy"}),", and acknowledge that returns may vary according to market conditions and selected strategy"]})]})}function Oe(s,i){const t=["creating_contract","approving","depositing"];function n(r){if(r==="creating_contract"&&i)return"completed";const o=t.indexOf(s.id),l=t.indexOf(r);return s.id==="success"?"completed":o===-1?"pending":l<o?"completed":l===o?"active":"pending"}function a(r){return s.id===r&&"txHash"in s?s.txHash:void 0}return[{id:"creating_contract",title:"Surf Account Creation",description:"Deploy your self-custodial smart contract",status:n("creating_contract"),txHash:a("creating_contract")},{id:"approving",title:"Approve USDC",description:"Grant access for automated strategies",status:n("approving"),txHash:a("approving")},{id:"depositing",title:"Deposit USDC",description:"Fund your Surf Account by depositing",status:n("depositing"),txHash:a("depositing")}]}function Ye(s){switch(s.id){case"creating_contract":return"Creating contract";case"approving":return"Approve USDC";case"depositing":return"Access Dashboard";default:return"Processing..."}}function qe(s){return s.id==="depositing"&&"txHash"in s&&!!s.txHash}function Ge({step:s,tokenSymbol:i,vaultExists:t,onDashboard:n,onSwitchToWithdraw:a}){const r=qe(s),o=!r&&s.id!=="success"&&s.id!=="error"&&s.id!=="idle";return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"deposit",onChange:l=>{l==="withdraw"&&a()},variant:"pill"}),e.jsx("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:"Confirm wallet requests to finish agent activation"}),e.jsx(I,{steps:Oe(s,t)}),e.jsx("div",{style:{marginTop:20},children:e.jsx(y,{variant:r?"primary":"soft",size:"lg",fullWidth:!0,isLoading:o,disabled:!r&&s.id!=="error",onClick:r?n:void 0,style:{borderRadius:50},children:Ye(s)})}),s.id==="error"&&e.jsxs("div",{className:"surf-error-box",children:["⚠ ",Pe(s.error)]})]})}function Ke({txHash:s,amount:i,tokenSymbol:t,walletAddress:n,onExplore:a,onBack:r}){return e.jsxs("div",{className:"surf-success",children:[e.jsx("div",{className:"surf-success-icon",children:e.jsx("div",{className:"surf-success-icon-inner",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})})}),e.jsx("p",{className:"surf-success-title",children:"You're all done!"}),e.jsxs("p",{className:"surf-success-desc",children:["Successfully deposited"," ",e.jsxs("strong",{children:[parseFloat(i).toLocaleString("en-US",{minimumFractionDigits:2})," ",t]})," ","to your wallet ",e.jsx("strong",{children:Ue(n)})]}),e.jsxs("div",{className:"surf-success-actions",children:[e.jsx(y,{variant:"outline",size:"md",style:{flex:1},onClick:a,rightIcon:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14 21 3"})}),children:"Explore"}),e.jsx(y,{variant:"primary",size:"md",style:{flex:1},onClick:r,children:"Back to dashboard"})]})]})}const Je={token:{symbol:"USDC",name:"USD Coin",decimals:6,address:""},chain:{name:"Base",id:8453},balance:"0.00",earnings:"0.00",apy:0,withdrawalType:"instant",availableBalance:"0.00"};function Xe({isOpen:s,onClose:i,vault:t,onSwitchToWithdraw:n}){const{walletAddress:a}=S(),{step:r,execute:o,reset:l}=O(),[h,u]=f.useState(""),d=t??Je,{balance:c,isLoading:p,refetch:m}=q(d.token.address,d.token.decimals??6),x=r.id==="idle",g=r.id==="success";function v(){l(),u(""),i()}return e.jsxs(F,{isOpen:s,onClose:v,children:[e.jsx("button",{className:"surf-modal-close",onClick:v,"aria-label":"Close",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}),x&&e.jsx(ze,{vault:d,amount:h,availableBalance:c,isBalanceLoading:p,onAmountChange:u,onSubmit:()=>h&&o(h,d),onRefreshBalance:m,onSwitchToWithdraw:()=>{l(),u(""),n==null||n()}}),!x&&!g&&e.jsx(Ge,{step:r,tokenSymbol:d.token.symbol,vaultExists:!!d.userVaultAddress,onDashboard:v,onSwitchToWithdraw:()=>{l(),u(""),n==null||n()}}),g&&r.id==="success"&&e.jsx(Ke,{txHash:r.txHash,amount:r.amount,tokenSymbol:d.token.symbol,walletAddress:a,onExplore:()=>window.open(`https://basescan.org/tx/${r.txHash}`,"_blank"),onBack:v})]})}const Qe=[10,25,50,100];function J(s){return s.length<10?s:`${s.slice(0,6)}...${s.slice(-4)}`}function Ze(s){return(Math.floor(s*100)/100).toFixed(2)}function es(s){const i=typeof s=="string"?s:(s==null?void 0:s.message)??"";if(!i)return"Transaction failed. Please try again.";const t=i.toLowerCase();if(t.includes("user rejected")||t.includes("user denied"))return"Transaction rejected by wallet.";if(t.includes("insufficient funds"))return"Insufficient funds for transaction.";if(t.includes("execution reverted"))return"Transaction reverted by contract.";if(t.includes("nonce"))return"Nonce error — please reset your wallet and retry.";if(t.includes("network")||t.includes("disconnected"))return"Network error. Check your connection.";const n=i.split(/[.(]/)[0].trim();return n.length>0&&n.length<=100?n:"Transaction failed. Please try again."}function ss({vault:s,amount:i,walletAddress:t,withdrawableBalance:n,isBalanceLoading:a,onAmountChange:r,onSubmit:o,onRefreshBalance:l,onSwitchToDeposit:h}){const u=parseFloat(n)>0?parseFloat(n):parseFloat(s.availableBalance)||parseFloat(s.balance)||0,d=parseFloat(i)||0,c=d>0&&d<=u;return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"withdraw",onChange:p=>{p==="deposit"&&h()},variant:"pill"}),e.jsxs("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:["Surf will withdraw to your connected wallet"," ",e.jsx("span",{style:{fontWeight:600,color:"#111827"},children:J(t)})]}),e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Token"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(T,{symbol:s.token.symbol,icon:s.token.icon,size:26}),e.jsx("span",{style:{fontSize:14,fontWeight:600},children:s.token.symbol})]})})]}),e.jsxs("div",{className:"surf-field",style:{flex:1,marginBottom:0},children:[e.jsx("span",{className:"surf-label",children:"Blockchain"}),e.jsx("div",{className:"surf-select-box",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[e.jsx("img",{src:s.chain.id===137?w.POLYGON:w.BASE_CHAIN,alt:s.chain.name,width:18,height:18}),e.jsx("span",{style:{fontSize:13,fontWeight:500},children:s.chain.name})]})})]})]}),e.jsxs("div",{className:"surf-amount-box",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{className:"surf-label",style:{margin:0},children:"Enter Amount"}),e.jsx("div",{style:{display:"flex",gap:10},children:Qe.map(p=>e.jsxs("button",{className:"surf-pct-link",onClick:()=>r(Ze(u*p/100)),children:[p,"%"]},p))})]}),e.jsx("input",{type:"number",value:i,onChange:p=>r(p.target.value),placeholder:"0",min:"0",step:"any",className:"surf-amount-input"}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"flex-end",marginTop:8},children:e.jsxs("span",{className:"surf-amount-hint",children:["Available:"," ",a?"...":u.toLocaleString("en-US",{minimumFractionDigits:2})," ",s.token.symbol,e.jsx("button",{className:"surf-refresh-btn",onClick:l,title:"Refresh balance",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:[e.jsx("path",{d:"M1 4v6h6M23 20v-6h-6"}),e.jsx("path",{d:"M20.49 9A9 9 0 005.64 5.64L1 10M23 14l-4.64 4.36A9 9 0 013.51 15"})]})})]})})]}),e.jsx(y,{variant:"primary",size:"lg",fullWidth:!0,disabled:!c,onClick:o,style:{borderRadius:50,marginTop:16},children:"Withdraw funds"}),e.jsx("p",{className:"surf-disclaimer",style:{marginTop:10},children:"Rewards will also be withdrawn by default"})]})}function ts(s,i,t){const n=["closing_position","redeeming_reward"];function a(o){const l=n.indexOf(s.id),h=n.indexOf(o);return s.id==="success"?"completed":l===-1?"pending":h<l?"completed":h===l?"active":"pending"}function r(o){return s.id===o&&"txHash"in s?s.txHash:void 0}return[{id:"closing_position",title:"Close current position",description:`Withdraw ${parseFloat(i||"0").toFixed(2)} ${t} from Vault`,status:a("closing_position"),txHash:r("closing_position")},{id:"redeeming_reward",title:"Redeem Reward",description:"Transferring to your wallet",status:a("redeeming_reward"),txHash:r("redeeming_reward")}]}function ns(s){switch(s.id){case"closing_position":return"Withdrawing Funds...";case"redeeming_reward":return"Redeeming Reward...";default:return"Processing..."}}function is({step:s,amount:i,tokenSymbol:t,walletAddress:n,onSwitchToDeposit:a}){const r=s.id!=="success"&&s.id!=="error"&&s.id!=="idle";return e.jsxs("div",{className:"surf-modal-body",children:[e.jsx(N,{tabs:[{id:"deposit",label:"Deposit"},{id:"withdraw",label:"Withdraw"}],activeTab:"withdraw",onChange:o=>{o==="deposit"&&a()},variant:"pill"}),e.jsxs("p",{className:"surf-modal-subtitle",style:{marginTop:14,textAlign:"center"},children:["Surf is resolving all your positions and withdrawing to your connected wallet ",e.jsx("strong",{children:J(n)})]}),e.jsx(I,{steps:ts(s,i,t)}),e.jsx("div",{style:{marginTop:20},children:e.jsx(y,{variant:"soft",size:"lg",fullWidth:!0,isLoading:r,disabled:s.id!=="error",style:{borderRadius:50},children:ns(s)})}),s.id==="error"&&e.jsxs("div",{className:"surf-error-box",children:["⚠ ",es(s.error)]})]})}function rs({amount:s,tokenSymbol:i,walletAddress:t,onExplore:n,onBack:a}){return e.jsxs("div",{className:"surf-success",children:[e.jsx("div",{className:"surf-success-icon",children:e.jsx("div",{className:"surf-success-icon-inner",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})})}),e.jsx("p",{className:"surf-success-title",children:"You're all done!"}),e.jsxs("p",{className:"surf-success-desc",children:["Successfully withdrew"," ",e.jsxs("strong",{children:[parseFloat(s).toLocaleString("en-US",{minimumFractionDigits:2})," ",i]})," ","to your wallet ",e.jsx("strong",{children:J(t)})]}),e.jsxs("div",{className:"surf-success-actions",children:[e.jsx(y,{variant:"outline",size:"md",style:{flex:1},onClick:n,rightIcon:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14 21 3"})}),children:"Explore"}),e.jsx(y,{variant:"primary",size:"md",style:{flex:1},onClick:a,children:"Back to dashboard"})]})]})}function as({isOpen:s,onClose:i,vault:t,onSwitchToDeposit:n}){const{walletAddress:a}=S(),{step:r,execute:o,reset:l}=Y(),[h,u]=f.useState(""),{balance:d,isLoading:c,refetch:p}=G((t==null?void 0:t.token.address)??"",t==null?void 0:t.userVaultAddress,(t==null?void 0:t.token.decimals)??6),m=r.id==="idle",x=r.id==="success";function g(){l(),u(""),i()}const v=x&&r.id==="success"?r.amount:h;return e.jsxs(F,{isOpen:s,onClose:g,children:[e.jsx("button",{className:"surf-modal-close",onClick:g,"aria-label":"Close",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}),t&&m&&e.jsx(ss,{vault:t,amount:h,walletAddress:a,withdrawableBalance:d,isBalanceLoading:c,onAmountChange:u,onSubmit:()=>t&&h&&o(h,t),onRefreshBalance:p,onSwitchToDeposit:()=>{l(),u(""),n==null||n()}}),!m&&!x&&t&&e.jsx(is,{step:r,amount:h,tokenSymbol:t.token.symbol,walletAddress:a,onSwitchToDeposit:()=>{l(),u(""),n==null||n()}}),x&&r.id==="success"&&e.jsx(rs,{amount:v,tokenSymbol:(t==null?void 0:t.token.symbol)??"USDC",walletAddress:a,onExplore:()=>window.open(`https://basescan.org/tx/${r.txHash}`,"_blank"),onBack:g}),!t&&e.jsx("div",{className:"surf-empty",children:"Loading vault information..."})]})}exports.Button=y;exports.DepositModal=Xe;exports.ManageDropdown=re;exports.Modal=F;exports.RegistrationForm=Ve;exports.StepProgress=I;exports.SurfContext=z;exports.SurfProvider=ne;exports.SurfWidget=_e;exports.Tabs=N;exports.TokenIcon=T;exports.VaultActivityModal=le;exports.VaultCard=ae;exports.WithdrawModal=as;exports.useAgentMessages=oe;exports.useDeposit=O;exports.useDepositBalance=q;exports.useSurf=S;exports.useVault=ie;exports.useWithdraw=Y;exports.useWithdrawableBalance=G;
2
+ //# sourceMappingURL=index.js.map