PageSourceSearch

https://porto-pocs.vercel.app/assets/earn-Db80WrgB.js

js porto-pocs.vercel.app collected 2026-10-03 07:31:38 UTC 14,942 bytes, 1 lines download raw bytes

1import{r as p,j as e,g as T,h as se,i as re,C as ne,H as ae,T as x,c as ie,d as te,f,F as d,I as W,S as _,P as M,u as U,e as $,p as z,s as Y,a as A,w as q,m as le,b as R}from"./index-CcWIe3Ny.js";import{u as oe}from"./useWalletConnection-TGCGoSkZ.js";import{n as F,b as de}from"./numberFormatter-BINWGwh-.js";import{T as ce,E as V,U as K,A as k}from"./porto-BDhCh_fV.js";import"./v-stack-D_MTImIs.js";const ue=p.forwardRef(function(o,r){const{size:a,...s}=o;return e.jsx(T,{...s,ref:r,boxSize:a,css:{display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,flexGrow:0,...o.css}})}),pe=p.forwardRef(function(o,r){const{size:a,...s}=o;return e.jsx(ue,{size:a,ref:r,borderRadius:"9999px",...s})}),{withContext:he}=se({key:"skeleton"}),D=he("div");p.forwardRef(function(o,r){const{size:a,...s}=o;return e.jsx(pe,{size:a,asChild:!0,ref:r,children:e.jsx(D,{...s})})});const xe=p.forwardRef(function(o,r){const{noOfLines:a=3,gap:s,rootProps:i,...n}=o;return e.jsx(re,{gap:s,width:"full",ref:r,...i,children:Array.from({length:a}).map((g,m)=>e.jsx(D,{height:"4",_last:{maxW:a===1?"100%":"80%"},...n},m))})}),me={"html.light &":{"--background-color":"#fff","--border-color":"#fff","--box-shadow":"0 9.6px 13px 0 rgb(0 0 0 / 8%)","--title-color":"#2e3048","--text-color":"#4b4d60"},"html.dark &":{"--background-color":"#2E3048","--border-color":"#292B43","--box-shadow":"0 9.6px 13px 0 rgb(0 0 0 / 8%)","--title-color":"#fff","--text-color":"#fff"}},fe=({...t})=>e.jsxs("svg",{fill:"none",height:"21",viewBox:"0 0 21 21",width:"21",xmlns:"http://www.w3.org/2000/svg",...t,children:[e.jsx("title",{children:"Close"}),e.jsx("path",{d:"M20.3111 18.4444C20.404 18.5373 20.4777 18.6476 20.528 18.769C20.5783 18.8904 20.6041 19.0205 20.6041 19.1519C20.6041 19.2833 20.5783 19.4134 20.528 19.5348C20.4777 19.6562 20.404 19.7665 20.3111 19.8594C20.2182 19.9523 20.1079 20.026 19.9865 20.0763C19.8651 20.1266 19.735 20.1525 19.6036 20.1525C19.4722 20.1525 19.3421 20.1266 19.2207 20.0763C19.0993 20.026 18.989 19.9523 18.8961 19.8594L10.6036 11.5657L2.31108 19.8594C2.12344 20.0471 1.86895 20.1525 1.60358 20.1525C1.33822 20.1525 1.08372 20.0471 0.896083 19.8594C0.708443 19.6718 0.603027 19.4173 0.603027 19.1519C0.603027 18.8866 0.708443 18.6321 0.896083 18.4444L9.18983 10.1519L0.896083 1.85942C0.708443 1.67178 0.603027 1.41729 0.603027 1.15192C0.603027 0.886559 0.708443 0.632064 0.896083 0.444423C1.08372 0.256783 1.33822 0.151367 1.60358 0.151367C1.86895 0.151367 2.12344 0.256783 2.31108 0.444423L10.6036 8.73817L18.8961 0.444423C19.0837 0.256783 19.3382 0.151367 19.6036 0.151367C19.8689 0.151367 20.1234 0.256783 20.3111 0.444423C20.4987 0.632064 20.6041 0.886559 20.6041 1.15192C20.6041 1.41729 20.4987 1.67178 20.3111 1.85942L12.0173 10.1519L20.3111 18.4444Z",fill:"currentColor"})]}),ge=({children:t,...o})=>e.jsx(ie.button,{background:"none",border:"none",color:"var(--title-color)",cursor:"pointer",position:"absolute",right:4,top:4,_active:{opacity:.7},...o,children:e.jsx(fe,{width:"12px",height:"12px"})}),be=({css:t,children:o,title:r,onClose:a,text:s,...i})=>e.jsxs(e.Fragment,{children:[a&&e.jsx(T,{position:"fixed",h:"100vh",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"modal",onClick:()=>a()}),e.jsxs(ne,{backgroundColor:"bg.default",borderColor:"var(--border-color)",borderRadius:"8px",boxShadow:"var(--box-sha
1dow)",css:{...t,...me},display:"flex",flexDirection:"column",margin:"auto",maxWidth:"calc(100vw - 16px)",pt:8,rowGap:6,whiteSpace:"normal",...i,children:[e.jsx(ae,{as:"h1",color:"var(--title-color)",fontSize:"xl",fontWeight:"semibold",lineHeight:"1.2",mb:0,ml:6,mr:6,mt:0,textAlign:"left",children:r}),a&&e.jsx(ge,{onClick:()=>a()}),e.jsx(x,{borderRadius:"md",color:"var(--text-color)",flexDirection:"column",fontSize:"sm",lineHeight:"1.6",maxHeight:"250px",overflow:"auto",position:"relative",wordBreak:"break-word",pl:6,pr:6,pt:4,borderTop:"1px solid",borderColor:"bg.emphasized/4",children:s}),o||"No contents"]})]}),we=({token:t,tokenIcon:o,chainIcon:r,tvl:a,APY:s,userBalance:i,lendingProtocol:n,walletBalance:g,onDeposit:m,onWithdraw:h,isLoadingProtocolData:w,isLoadingUserData:S,address:v})=>{const[B,b]=p.useState(!1),[j,E]=p.useState("deposit"),[C,I]=p.useState(!1),{connect:O}=oe(te),L=()=>{E("deposit"),b(!0)},P=()=>{E("withdraw"),b(!0)},N=()=>{b(!1)},l=async()=>{I(!0);try{j==="deposit"?(await m(),console.log(`Deposit confirmed for ${t.symbol}`)):(await h(),console.log(`Withdraw confirmed for ${t.symbol}`)),b(!1)}catch(y){console.error(`${j} error:`,y)}finally{I(!1)}},c=j==="deposit"?`Deposit ${t.symbol}`:`Withdraw ${t.symbol}`,u=j==="deposit"?`Deposit your ${t.symbol} tokens to earn ${s} APY on ${n}. Current wallet balance: ${S?"Loading...":F.format(Number(f(g,t.decimals)))} ${t.symbol}.`:`Withdraw your ${t.symbol} tokens from ${n}. Current deposited balance: ${S?"Loading...":F.format(Number(f(i,t.decimals)))} ${t.symbol}.`;return e.jsxs(e.Fragment,{children:[e.jsxs(d,{bg:"primary.default/4",borderRadius:"lg",pt:8,gap:6,flexDirection:"column",border:"1px solid",borderColor:"bg.emphasized/10",width:"100%",children:[e.jsxs(d,{justifyContent:"space-between",alignItems:"flex-start",width:"100%",px:{base:4,md:6},children:[e.jsxs(d,{gap:4,alignItems:"center",children:[e.jsxs(T,{position:"relative",children:[e.jsx(T,{borderRadius:"full",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",children:e.jsx(W,{htmlWidth:"52px",htmlHeight:"52px",src:o,alt:`${t.symbol} icon`})}),e.jsx(T,{position:"absolute",bottom:"-4px",right:"-4px",borderRadius:"full",width:"20px",height:"20px",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid",borderColor:"#11406E",children:e.jsx(W,{htmlWidth:"24px",htmlHeight:"24px",src:r,alt:"chain icon"})})]}),e.jsxs(d,{flexDirection:"column",gap:.5,children:[e.jsx(x,{fontSize:"xl",fontWeight:"bold",color:"text.default",lineHeight:1,children:t.symbol}),e.jsxs(x,{fontSize:"sm",color:"text.default/60",lineHeight:1,children:["on ",n]})]})]}),e.jsxs(d,{flexDirection:"column",alignItems:"flex-end",gap:.5,children:[e.jsx(x,{fontSize:"xs",color:"text.default/80",textTransform:"uppercase",lineHeight:1.2,children:"TVL"}),w?e.jsx(D,{background:"bg.emphasized/6",width:"80px",height:"24px"}):e.jsx(x,{fontSize:"xl",fontWeight:"bold",color:"text.default",lineHeight:1.2,children:de.format(a)})]})]}),e.jsxs(d,{justifyContent:"space-between",alignItems:"flex-end",width:"100%",px:{base:4,md:6},pt:4,borderTop:"1px solid",borderColor:"bg.emphasized/4",children:[e.jsxs(d,{flexDirection:"column",gap:.5,children:[e.jsx(x,{fontSize:"sm",color:"text.default/80",lineHeight:1.2,children:i===0n?"Earn":"Earning"}),e.jsx(x,{fontSize:"lg",fontWeight:"bold",color:i===0n?"text.default":"#71DABE",lineHeight:1.2,children:w?e.jsx(D,{background:"bg.emphasized/6",width:"80px",height:"28px"}):`+ ${s} APY`})]}),e.jsxs(d,{flexDirection:"column",alignItems:"flex-end",gap:.5,children:[e.jsx(x,{fontSize:"sm",color:"text.default/80",lineHeight:1.2,children:"Your balance"}),v?e.jsx(x,{fontSize:"2xl",fontWeight:"bold",color:"text.default",lineHeight:1.2,children:F.format(Number(f(i,t.decimals)))}):e.jsx(D,{background:"bg.emphasized/6",width:"70px",height:"28px"})]})]}),e.jsx(d,{gap:4,width:"100%",justifyContent:"space-between",p:{base:4,md:6},bg:"bg.emphasized/4",borderTop:"1px solid",borderColor:"bg.emphasized/4",children:v?e.jsxs(e.Fragment,{children:[e.jsx(_,{disabled:i===0n||w,onClick:P,fontSize:"md",children:"Withdraw"}),e.jsx(M,{disabled:i===g||w,onClick:L,fontSize:"md",children:"Deposit"})]}):e.jsx(_,{w:"full",onClick:O,children:"Sign in"})})]}),B&&e.jsx(be,{title:c,text:u,onClose:N,position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",zIndex:"modal",width:"400px",children:e.jsxs(d,{gap:3,justifyContent:"space-between",width:"100%",borderTop:"1px solid",borderColor:"bg.emphasized/4",bg:"bg.emphasized/4",py:6,pl:6,pr:6,children:[e.jsx(_,{onClick:N,fontSize:"md",disabled:C,children:"Cancel"}),e.jsx(M,{onClick:l,fontSize:"md",disabled:C,children:C?"Processing...":j==="deposit"?"Deposit":"Withdraw"})]})})]})},je=({tokenSymbol:t,balance:o,supplied:r,decimals:a,isLoading:s})=>{const n=r<=0?"none":r>=0&&o===0n?"full":"partial",g=()=>{if(n==="none")return"You haven’t supplied any funds yet. Supply now to start earning.";if(n==="full")return"You've supplied your full balance. You're earning at full capacity.";if(n==="partial"){const m=f(r,a),h=f(o,a);return`You've supplied ${m} ${t}. You can supply ${h} more to maximize earnings.`}return"You have tokens available to supply and start earning."};return e.jsxs(d,{borderRadius:"lg",p:{base:4,md:6},gap:{base:2,md:4},alignItems:"flex-start",border:"1px solid",borderWidth:"1px",borderStyle:"solid",borderColor:"bg.emphasized/10",width:"100%",flexDirection:{base:"column",sm:"row"},children:[e.jsx(T,{bg:"bg.emphasized/4",borderRadius:"full",p:1,flexShrink:0,mt:1,children:n==="full"?e.jsx(W,{htmlWidth:"26px",htmlHeight:"26px",src:"/images/Check.svg"}):n==="partial"?e.jsx(W,{htmlWidth:"26px",htmlHeight:"26px",src:"/images/ChartPieSlice.svg"}):e.jsx(W,{htmlWidth:"26px",htmlHeight:"26px",src:"/images/Empty.svg"})}),e.jsxs(d,{flexDirection:"column",gap:"2px",flex:1,minW:0,maxW:"full",children:[e.jsxs(d,{flexDirection:"column",minW:0,children:[e.jsx(x,{fontSize:"xs",fontWeight:"400",color:"text.default",children:"Balance:"}),e.jsxs(d,{alignItems:"center",gap:1,minW:0,children:[e.jsx(x,{fontSize:"lg",fontWeight:"semibold",color:"text.default",truncate:!0,children:s?e.jsx(D,{background:"bg.emphasized/6",width:"50px",height:"25px"}):f(o,a)}),e.jsx(x,{fontSize:"lg",fontWeight:"semibold",color:"text.default",children:t})]})]}),e.jsx(x,{fontSize:"xs",color:"text.default/80",lineHeight:"1.5",children:s?e.jsx(xe,{background:"bg.emphasized/6",noOfLines:2,gap:"1"}):g()})]})]})},G=({token:t,supplied:o,tokenIcon:r,chainIcon:a,tvl:s,APY:i,walletBalance:n,lendingProtocol:g,onDeposit:m,onWithdraw:h,isLoadingProtocolData:w,isLoadingUserData:S,address:v})=>e.jsxs(d,{flexDirection:"column",gap:4,flex:1,minW:0,children:[v&&e.jsx(je,{tokenSymbol:t.symbol,balance:n,supplied:o,decimals:t.decimals,isLoading:S}),e.jsx(we,{token:t,tokenIcon:r,chainIcon:a,tvl:s,APY:i,walletBalance:n,userBalance:o,lendingProtocol:g,onDeposit:m,onWithdraw:h,isLoadingProtocolData:w,isLoadingUserData:S,address:v})]}),Ce=z(["function balanceOf(address) view returns (uint256)"]),ye=z(["function approve(address,uint256) returns (bool)"]),Ae=z(["function balanceOf(address) view returns (uint256)"]),Q=z(["function supply(address asset,uint256 amount,address onBehalfOf,uint16 referralCode)","function withdraw(address asset,uint256 amount,address to) returns (uint256)"]),Z=z(["function getReserveData(address asset) view returns (uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)","function getReserveTokensAddresses(address asset) view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress)"]),Se=z(["function getAssetPrice(address asset) view returns (uint256)"]),J=31536e3,X=(t,o=2)=>`${Number.isFinite(t)?(t*100).toFixed(o):"0.00"}%`;function ee(t,o){const{pool:r,dataProvider:a,asset:s,oracleAddress:i}=o,{data:n,refetch:g}=U({queryKey:["aaveReserveData",a,s.address,i],enabled:!!(a&&s.address&&i),queryFn:async()=>{const l=await R(A,{address:a,abi:Z,functionName:"getReserveData",args:[s.address]}),c=l[2],u=l[5],[y]=await R(A,{address:a,abi:Z,functionName:"getReserveTokensAddresses",args:[s.address]}),H=await R(A,{address:i,abi:Se,functionName:"getAssetPrice",args:[s.address]});
1return{totalAToken:c,currentLiquidityRate:u,aTokenAddress:y,priceUSD:H}},staleTime:15e3}),m=n==null?void 0:n.aTokenAddress,{data:h,refetch:w}=U({queryKey:["aaveBalances",t,s.address,m],enabled:!!(t&&m),queryFn:async()=>{if(!t||!m)return null;const[l,c]=await Promise.all([R(A,{address:s.address,abi:Ce,functionName:"balanceOf",args:[t]}),R(A,{address:m,abi:Ae,functionName:"balanceOf",args:[t]})]);return{walletAsset:l,walletAToken:c}},staleTime:15e3}),S=p.useMemo(()=>{if(!n)return{raw:0,pct:"0.00%"};const l=Number(f(n.currentLiquidityRate,27));return{raw:l,pct:X(l)}},[n]),v=p.useMemo(()=>{if(!n)return{raw:0,pct:"0.00%"};const l=Number(f(n.currentLiquidityRate,27)),c=Math.expm1(Math.log1p(l/J)*J);return{raw:c,pct:X(c)}},[n]),B=p.useMemo(()=>{if(!n)return 0;const l=Number(f(n.totalAToken,s.decimals)),c=Number(f(n.priceUSD,8));return l*c},[n,s.decimals]),b=(h==null?void 0:h.walletAsset)??0n,j=(h==null?void 0:h.walletAToken)??0n,E=p.useMemo(()=>({asset:f(b,s.decimals),aToken:f(j,s.decimals)}),[b,j,s.decimals]),C=p.useCallback(async()=>{await Promise.all([w(),g()])},[w,g]),I=p.useCallback(async l=>{if(!t)return;const c=l??b;if(!(c<=0n))try{const u=[{to:s.address,data:$({abi:ye,functionName:"approve",args:[r,c]})},{to:r,data:$({abi:Q,functionName:"supply",args:[s.address,c,t,0]})}],y=await Y(A,{account:t,calls:u}),H=await q(A,{id:y==null?void 0:y.id});return await C(),H}catch(u){throw console.error("Aave deposit error:",u),u}},[t,b,s.address,r,C]),O=p.useCallback(async l=>{if(!t)return;const c=l??le;try{const u=await Y(A,{account:t,calls:[{to:r,data:$({abi:Q,functionName:"withdraw",args:[s.address,c,t]})}]}),y=await q(A,{id:u==null?void 0:u.id});return await C(),y}catch(u){throw console.error("Aave withdraw error:",u),u}},[t,s.address,r,C]),L=!n,P=!!t&&!h,N=L||P;return{walletAsset:b,walletAToken:j,formattedAsset:E.asset,formattedAToken:E.aToken,apr:S,apy:v,totalSupplied:n==null?void 0:n.totalAToken,totalSuppliedUSD:B,deposit:I,withdraw:O,refresh:C,isLoading:N,isLoadingProtocolData:L,isLoadingUserData:P}}const ve=()=>{const{address:t}=oe(te),o=ee(t,{pool:k.pool,dataProvider:k.dataProvider,oracleAddress:k.priceOracle,asset:K}),r=ee(t,{pool:k.pool,dataProvider:k.dataProvider,oracleAddress:k.priceOracle,asset:V});return e.jsxs(d,{flexDirection:"column",rowGap:8,bg:"bg.emphasized/4",borderRadius:"md",p:4,sm:{p:10},borderColor:"bg.emphasized/4",borderWidth:"1px",borderStyle:"solid",width:"100%",children:[e.jsx(ce,{title:"Start earning with Porto",subtitle:"Deposit assets to generate yields"}),e.jsxs(d,{flexDirection:{base:"column",md:"row"},gap:4,children:[e.jsx(G,{token:V,tokenIcon:"/images/tokens/eth.svg",chainIcon:"/images/chains/base.svg",tvl:r.totalSuppliedUSD,APY:r.apy.pct,supplied:r.walletAToken,walletBalance:r.walletAsset,lendingProtocol:"Aave",onDeposit:r.deposit,onWithdraw:r.withdraw,isLoadingProtocolData:r.isLoadingProtocolData,isLoadingUserData:r.isLoadingUserData,address:t}),e.jsx(G,{token:K,tokenIcon:"/images/tokens/usdc.svg",chainIcon:"/images/chains/base.svg",tvl:o.totalSuppliedUSD,APY:o.apy.pct,supplied:o.walletAToken,walletBalance:o.walletAsset,lendingProtocol:"Aave",onDeposit:o.deposit,onWithdraw:o.withdraw,isLoadingProtocolData:o.isLoadingProtocolData,isLoadingUserData:o.isLoadingUserData,address:t})]})]})},Re=ve;export{Re as component};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.