@vechain/vechain-kit 2.5.0 → 2.5.1

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 CHANGED
@@ -118,13 +118,13 @@ const e=require(`./assets-DNJsQD7_.cjs`),t=require(`./utils-DeETrpws.cjs`);let n
118
118
  opacity: 0.5 !important;
119
119
  }
120
120
  `),d.length>0&&(u.textContent=d.join(`
121
- `))}let Te=null;function Ee(){return Te||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),Te}const De=({children:e})=>{try{if(r.default.useContext(p.QueryClientContext))return(0,i.jsx)(i.Fragment,{children:e})}catch(e){console.log(e)}return(0,i.jsx)(p.QueryClientProvider,{client:Ee(),children:e})},J=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`Back`,icon:(0,i.jsx)(n.Icon,{as:g.LuChevronLeft,fontSize:`20px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,onClick:e,lineHeight:`0`,...t}),Oe=({wallet:e,label:a,style:o,showHumanAddress:s=!0,setCurrentContent:c,onLogout:u})=>{let{t:d}=(0,l.useTranslation)(),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useColorModeValue)(`#ebebeb`,`#ffffff0a`),b=(0,n.useColorModeValue)(`#ffffff`,`transparent`),x=async(e,n)=>{await t.lt(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))},S=()=>{c&&(e?.domain?c({type:`choose-name-search`,props:{name:``,setCurrentContent:c,initialContentSource:`profile`}}):c({type:`choose-name`,props:{setCurrentContent:c,initialContentSource:`profile`,onBack:()=>c(`profile`)}}))};return(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,...o,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:v,children:a}),(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[e?.domain&&(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:m?d(`Copied!`):e.domain}),(0,i.jsxs)(n.HStack,{spacing:2,children:[c&&(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuPencil,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:S,"aria-label":`Edit domain`}),(0,i.jsx)(n.IconButton,{icon:m?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:()=>x(e.domain||``,h),"aria-label":`Copy domain`})]})]}),(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuWallet,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:f?d(`Copied!`):s?t.W(e?.address??``,8,7):e?.address}),(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuLogOut,{}),onClick:()=>c?.({type:`disconnect-confirm`,props:{onDisconnect:()=>u?.(),onBack:()=>c?.(`profile`)}}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`}),(0,i.jsx)(n.IconButton,{icon:f?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),onClick:()=>x(e?.address??``,p),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`})]})]})]})]})})};var ke=`2.5.0`,Ae={"@adraffy/ens-normalize":`^1.11.0`,"@chakra-ui/react":`^2.8.2`,"@emotion/styled":`^11.14.1`,"@privy-io/cross-app-connect":`0.2.2`,"@privy-io/react-auth":`2.25.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.1.0`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.6.0-rc`,"@wagmi/core":`^2.17.2`,"bignumber.js":`^9.1.2`,"browser-image-compression":`^2.0.2`,dotenv:`^16.4.7`,ethers:`^6.13.5`,"framer-motion":`^11.15.0`,i18next:`^24.2.1`,"i18next-browser-languagedetector":`^8.0.2`,net:`^1.0.2`,process:`^0.11.10`,react:`^18.2.0`,"react-device-detect":`^2.2.3`,"react-hook-form":`^7.54.2`,"react-i18next":`^15.4.0`,"react-icons":`^5.4.0`,"react-qrcode-logo":`^3.0.0`,vaul:`^1.1.2`,viem:`^2.29.3`,wagmi:`^2.15.4`},je={"@chakra-ui/react":`^2.8.2`,"@emotion/react":`^11.0.0`,"@emotion/styled":`^11.0.0`,"@tanstack/react-query":`^5.64.2`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const Me=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.J,{isDark:r,w:`70px`,h:`auto`,opacity:.4,mr:1,ml:`-16px`}),(0,i.jsxs)(n.Link,{fontSize:`11px`,fontWeight:`500`,opacity:.4,textAlign:`left`,href:`https://github.com/vechain/vechain-kit/releases/tag/${ke}`,isExternal:!0,pt:`1px`,children:[`v`,ke]})]})},Ne=(0,r.createContext)({hasContentBelow:!1}),Pe=()=>(0,r.useContext)(Ne),Y=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(null),l=(0,r.useRef)(!0),{tokens:u}=Za(),d=u?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=e=>{if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t);if(e.overflowY===`auto`||e.overflowY===`scroll`||e.overflow===`auto`||e.overflow===`scroll`)return t;t=t.parentElement}return null},t=([e])=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{if(l.current){l.current=!1,a(!1);return}a(!e.isIntersecting)},50)},n=e(s.current),r={threshold:0};n&&(r.root=n,r.rootMargin=`0px`);let i=new IntersectionObserver(t,r),u=setTimeout(()=>{o.current&&i.observe(o.current)},200);return()=>{clearTimeout(u),c.current&&clearTimeout(c.current),i.disconnect()}},[]),(0,i.jsxs)(Ne.Provider,{value:{hasContentBelow:t},children:[(0,i.jsx)(n.Box,{ref:s,position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?d:`none`,style:{WebkitBackdropFilter:t?d:`none`},zIndex:1e3,boxShadow:t?`0px 2px 4px 1px rgb(0 0 0 / 10%)`:`none`,transition:`box-shadow 0.2s ease-in-out`,children:e}),(0,i.jsx)(`div`,{ref:o,style:{height:`1px`,width:`100%`,pointerEvents:`none`,visibility:`hidden`,marginTop:`-1px`}})]})},Fe=({children:e})=>(0,i.jsx)(n.Box,{position:`absolute`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,w:`full`,children:e}),Ie=({scrollableContainerRef:e,observerRef:t})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-border`),{tokens:o}=Za(),s=o?.effects?.backdropFilter?.stickyHeader??`blur(20px)`,[c,l]=(0,r.useState)(!1),u=(0,r.useRef)(null),d=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{let n=([e])=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{if(d.current){d.current=!1,l(!1);return}l(!e.isIntersecting)},50)},r={threshold:0};e.current&&(r.root=e.current,r.rootMargin=`0px`);let i=new IntersectionObserver(n,r),a=setTimeout(()=>{t.current&&i.observe(t.current)},200);return()=>{clearTimeout(a),u.current&&clearTimeout(u.current),i.disconnect()}},[e,t]),(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,w:`full`,backdropFilter:c?s:`none`,style:{WebkitBackdropFilter:c?s:`none`},zIndex:999,transition:`backdrop-filter 0.2s ease-in-out`,children:(0,i.jsx)(n.Box,{mx:`auto`,w:`34px`,h:`5px`,bg:a,mt:4,rounded:`full`})})},Le=({isOpen:e,onClose:t,children:a,ariaTitle:o,ariaDescription:s,isDismissable:c=!0,minHeight:l,maxHeight:u=`68vh`,closeThreshold:d=.5})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-modal`),p=(0,n.useToken)(`colors`,`vechain-kit-overlay`),m=(0,r.useRef)(null),h=(0,r.useRef)(null),{tokens:g}=Za(),v=g?.effects?.backdropFilter?.overlay,y=g?.colors?.border?.modal||`none`;return(0,i.jsx)(_.Drawer.Root,{dismissible:c,shouldScaleBackground:!0,repositionInputs:!1,open:e,closeThreshold:d,onOpenChange:e=>{e||t()},children:(0,i.jsxs)(_.Drawer.Portal,{children:[(0,i.jsx)(_.Drawer.Overlay,{style:{zIndex:100,position:`fixed`,top:0,right:0,bottom:0,left:0,backgroundColor:p,backdropFilter:v,WebkitBackdropFilter:v}}),(0,i.jsxs)(_.Drawer.Content,{"aria-description":s,style:{zIndex:101,backgroundColor:f,borderRadius:`24px 24px 0 0`,border:y,position:`fixed`,bottom:0,left:0,right:0,...l&&{minHeight:l},maxHeight:u,display:`flex`,flexDirection:`column`},children:[(0,i.jsx)(_.Drawer.Title,{style:{position:`absolute`,width:`1px`,height:`1px`,padding:0,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:0},children:o}),(0,i.jsxs)(n.Box,{ref:m,flex:`1`,overflowY:`auto`,children:[(0,i.jsx)(Ie,{scrollableContainerRef:m,observerRef:h}),(0,i.jsx)(`div`,{ref:h,style:{height:`1px`,width:`100%`,visibility:`hidden`,marginTop:`-1px`}}),a]})]})]})})},Re=({isOpen:e,onClose:t,children:r,size:a=`sm`,isCentered:o=!0,motionPreset:s=`slideInBottom`,closeOnOverlayClick:c=!0,blockScrollOnMount:l=!1,allowExternalFocus:u=!1,backdropFilter:d,isCloseable:f=!0,useBottomSheetOnMobile:p,mobileMinHeight:m,mobileMaxHeight:h=`57vh`,desktopMinHeight:g,desktopMaxHeight:_})=>{let[v]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:y,themeConfig:b,tokens:x}=Za(),S=p??b?.modal?.useBottomSheetOnMobile??!1,C=(0,n.useToken)(`colors`,`vechain-kit-modal`),w=(0,n.useToken)(`colors`,`vechain-kit-overlay`),T=x?.effects?.backdropFilter?.overlay,E=x?.effects?.backdropFilter?.modal,D=d??T??`blur(3px)`,O=v?{minHeight:g,maxHeight:_}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`,minHeight:m,maxHeight:h},k=(0,i.jsxs)(n.Modal,{motionPreset:s,isOpen:e,onClose:t,isCentered:o,size:a,returnFocusOnClose:!1,blockScrollOnMount:l,closeOnOverlayClick:c&&f,preserveScrollBarGap:!0,portalProps:{containerRef:y},trapFocus:!u,autoFocus:!u,variant:`vechainKitBase`,children:[(0,i.jsx)(n.ModalOverlay,{bg:w,backdropFilter:D}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:C,sx:{backdropFilter:E,WebkitBackdropFilter:E},...O,children:r})]});return(0,i.jsx)(i.Fragment,{children:!v&&S?(0,i.jsx)(n.Modal,{isOpen:e,onClose:t,size:a,blockScrollOnMount:!1,trapFocus:!1,children:(0,i.jsx)(Le,{isOpen:e,onClose:t,ariaTitle:`Dialog`,ariaDescription:`Dialog content area`,isDismissable:f,minHeight:m,maxHeight:h,children:r})}):k})},ze=async t=>{let n=new URL(`/api/v1/apps/${t}`,e.h),r=await fetch(n,{headers:{"privy-app-id":t}});if(!r.ok)throw Error(`Failed to fetch Privy app info`);return r.json()},Be=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],Ve=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:Be(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>ze(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.Y.find(e=>e.id===i);return[i,{...e,website:a?.website}]}))},enabled:n.length>0,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},He=async()=>{try{let t=new URL(`summary.json`,e.g),n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch Privy status`);return(await n.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},Ue=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:He,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60}),We=e=>[`VECHAIN_KIT_DOMAIN`,e],Ge=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:We(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);let r=await(0,v.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.j(e);if(!r&&!i)throw Error(`Input must be a valid domain or address`);let a=null,o=null,s=!1;return r?(a=await(0,v.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,v.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,v.isPrimaryDomain)(o,e,{networkUrl:n.nodeUrl}))),{address:a||void 0,domain:o||void 0,isValidAddressOrDomain:r||i,isPrimaryDomain:s}},enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address or domain is required`||e===`input must be a valid domain or address`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Ke=async(e,n,r)=>{let i=(0,b.keccak256)((0,b.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,b.keccak256)((0,b.toBytes)(r))])),a=await e.contracts.load(t.bt(n).vetDomainsContractAddress,y.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},qe=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],Je=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:qe(e),queryFn:()=>Ke(t,n.type,e),enabled:!!e,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Ye=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:mt(e??``,r.type)}),n.invalidateQueries({queryKey:vt(e,r.type)}),n.invalidateQueries({queryKey:Ot(t)})])}}},Xe=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:We(t)}),e.invalidateQueries({queryKey:We(n)}),e.invalidateQueries({queryKey:qe(r)}),e.invalidateQueries({queryKey:ft(t,`.vet`)}),e.invalidateQueries({queryKey:ft(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:vt(n)})]),await Promise.all([e.refetchQueries({queryKey:We(t)}),e.refetchQueries({queryKey:We(n)}),e.refetchQueries({queryKey:ft(t,`.vet`)}),e.refetchQueries({queryKey:ft(t,`.veworld.vet`)}),e.refetchQueries({queryKey:mt(r+`.`+i,a)}),e.refetchQueries({queryKey:vt(n)}),e.refetchQueries({queryKey:qe(r)}),e.refetchQueries({queryKey:Ot(t)})])},Ze=y.VeworldSubdomainClaimer__factory.createInterface(),Qe=y.VetDomainsReverseRegistrar__factory.createInterface(),$e=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:Qe.getFunction(`setName`)}),r){s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:Qe.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.bt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.W(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if(tt(n))s.push({to:t.bt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:Ze.encodeFunctionData(`claim`,[e,t.bt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:Ze.getFunction(`claim`)}),s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:Qe.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},et=({subdomain:e,domain:t,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let o=(0,p.useQueryClient)(),{account:s}=X(),{network:c}=$(),{refresh:l}=Ye(e+`.`+t,s?.address??``),u=(0,r.useCallback)(()=>$e(e,t,a,s,c),[e,t,a,s,c]),d=(0,r.useCallback)(async()=>{let r=`${e}.${t}`;await Xe(o,s?.address??``,r,e,t,c.type),l(),n?.()},[n,e,t,o,s,c.type,l]),f=$n({signerAccountAddress:s?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e}.${t} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:d,onTxFailedOrCancelled:()=>{i?.()}});return{...f,clauses:u,sendTransaction:async()=>f.sendTransaction(u())}},tt=e=>e.endsWith(`veworld.vet`),nt=y.VetDomainsReverseRegistrar__factory.createInterface(),rt=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.bt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:nt.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:nt.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.bt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.W(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},it=({domain:e,onSuccess:t,onError:n,alreadyOwned:i=!1})=>{let{network:a}=$(),o=(0,p.useQueryClient)(),{account:s}=X(),{refresh:c}=Ye(e,s?.address??``),l=(0,r.useCallback)(()=>rt(e,i,s,a),[e,i,s,a]),u=(0,r.useCallback)(async()=>{await Xe(o,s?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,a.type),c(),t?.()},[t,e,o,s,a.type,c]),d=$n({signerAccountAddress:s?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:u,onTxFailedOrCancelled:n});return{...d,clauses:l,sendTransaction:async()=>d.sendTransaction(l())}},at=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],ot=s.ABIContract.ofAbi(y.VeworldSubdomainClaimer__factory.abi),st=async(e,n,r)=>{let i=t.bt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,ot.abi).read.isDomainProtected(r))[0]},ct=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:at(e),queryFn:()=>st(n,r.type,e),enabled:!!e&&t&&!!r.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},lt=x.z.object({name:x.z.string()}),ut=x.z.object({domains:x.z.array(lt)}),dt=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.bt(e).graphQlIndexerUrl,a=`query Registrations {
121
+ `))}let Te=null;function Ee(){return Te||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),Te}const De=({children:e})=>{try{if(r.default.useContext(p.QueryClientContext))return(0,i.jsx)(i.Fragment,{children:e})}catch(e){console.log(e)}return(0,i.jsx)(p.QueryClientProvider,{client:Ee(),children:e})},J=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`Back`,icon:(0,i.jsx)(n.Icon,{as:g.LuChevronLeft,fontSize:`20px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,onClick:e,lineHeight:`0`,...t}),Oe=({wallet:e,label:a,style:o,showHumanAddress:s=!0,setCurrentContent:c,onLogout:u})=>{let{t:d}=(0,l.useTranslation)(),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useColorModeValue)(`#ebebeb`,`#ffffff0a`),b=(0,n.useColorModeValue)(`#ffffff`,`transparent`),x=async(e,n)=>{await t.lt(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))},S=()=>{c&&(e?.domain?c({type:`choose-name-search`,props:{name:``,setCurrentContent:c,initialContentSource:`profile`}}):c({type:`choose-name`,props:{setCurrentContent:c,initialContentSource:`profile`,onBack:()=>c(`profile`)}}))};return(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,...o,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:v,children:a}),(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[e?.domain&&(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:m?d(`Copied!`):e.domain}),(0,i.jsxs)(n.HStack,{spacing:2,children:[c&&(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuPencil,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:S,"aria-label":`Edit domain`}),(0,i.jsx)(n.IconButton,{icon:m?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:()=>x(e.domain||``,h),"aria-label":`Copy domain`})]})]}),(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuWallet,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:f?d(`Copied!`):s?t.W(e?.address??``,8,7):e?.address}),(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuLogOut,{}),onClick:()=>c?.({type:`disconnect-confirm`,props:{onDisconnect:()=>u?.(),onBack:()=>c?.(`profile`)}}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`}),(0,i.jsx)(n.IconButton,{icon:f?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),onClick:()=>x(e?.address??``,p),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`})]})]})]})]})})};var ke=`2.5.1`,Ae={"@adraffy/ens-normalize":`^1.11.0`,"@chakra-ui/react":`^2.8.2`,"@emotion/styled":`^11.14.1`,"@privy-io/cross-app-connect":`0.2.2`,"@privy-io/react-auth":`2.25.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.1.0`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.6.0-rc`,"@wagmi/core":`^2.17.2`,"bignumber.js":`^9.1.2`,"browser-image-compression":`^2.0.2`,dotenv:`^16.4.7`,ethers:`^6.13.5`,"framer-motion":`^11.15.0`,i18next:`^24.2.1`,"i18next-browser-languagedetector":`^8.0.2`,net:`^1.0.2`,process:`^0.11.10`,react:`^18.2.0`,"react-device-detect":`^2.2.3`,"react-hook-form":`^7.54.2`,"react-i18next":`^15.4.0`,"react-icons":`^5.4.0`,"react-qrcode-logo":`^3.0.0`,vaul:`^1.1.2`,viem:`^2.29.3`,wagmi:`^2.15.4`},je={"@chakra-ui/react":`^2.8.2`,"@emotion/react":`^11.0.0`,"@emotion/styled":`^11.0.0`,"@tanstack/react-query":`^5.64.2`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const Me=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.J,{isDark:r,w:`70px`,h:`auto`,opacity:.4,mr:1,ml:`-16px`}),(0,i.jsxs)(n.Link,{fontSize:`11px`,fontWeight:`500`,opacity:.4,textAlign:`left`,href:`https://github.com/vechain/vechain-kit/releases/tag/${ke}`,isExternal:!0,pt:`1px`,children:[`v`,ke]})]})},Ne=(0,r.createContext)({hasContentBelow:!1}),Pe=()=>(0,r.useContext)(Ne),Y=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(null),l=(0,r.useRef)(!0),{tokens:u}=Za(),d=u?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=e=>{if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t);if(e.overflowY===`auto`||e.overflowY===`scroll`||e.overflow===`auto`||e.overflow===`scroll`)return t;t=t.parentElement}return null},t=([e])=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{if(l.current){l.current=!1,a(!1);return}a(!e.isIntersecting)},50)},n=e(s.current),r={threshold:0};n&&(r.root=n,r.rootMargin=`0px`);let i=new IntersectionObserver(t,r),u=setTimeout(()=>{o.current&&i.observe(o.current)},200);return()=>{clearTimeout(u),c.current&&clearTimeout(c.current),i.disconnect()}},[]),(0,i.jsxs)(Ne.Provider,{value:{hasContentBelow:t},children:[(0,i.jsx)(n.Box,{ref:s,position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?d:`none`,style:{WebkitBackdropFilter:t?d:`none`},zIndex:1e3,boxShadow:t?`0px 2px 4px 1px rgb(0 0 0 / 10%)`:`none`,transition:`box-shadow 0.2s ease-in-out`,children:e}),(0,i.jsx)(`div`,{ref:o,style:{height:`1px`,width:`100%`,pointerEvents:`none`,visibility:`hidden`,marginTop:`-1px`}})]})},Fe=({children:e})=>(0,i.jsx)(n.Box,{position:`absolute`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,w:`full`,children:e}),Ie=({scrollableContainerRef:e,observerRef:t})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-border`),{tokens:o}=Za(),s=o?.effects?.backdropFilter?.stickyHeader??`blur(20px)`,[c,l]=(0,r.useState)(!1),u=(0,r.useRef)(null),d=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{let n=([e])=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{if(d.current){d.current=!1,l(!1);return}l(!e.isIntersecting)},50)},r={threshold:0};e.current&&(r.root=e.current,r.rootMargin=`0px`);let i=new IntersectionObserver(n,r),a=setTimeout(()=>{t.current&&i.observe(t.current)},200);return()=>{clearTimeout(a),u.current&&clearTimeout(u.current),i.disconnect()}},[e,t]),(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,w:`full`,backdropFilter:c?s:`none`,style:{WebkitBackdropFilter:c?s:`none`},zIndex:999,transition:`backdrop-filter 0.2s ease-in-out`,children:(0,i.jsx)(n.Box,{mx:`auto`,w:`34px`,h:`5px`,bg:a,mt:4,rounded:`full`})})},Le=({isOpen:e,onClose:t,children:a,ariaTitle:o,ariaDescription:s,isDismissable:c=!0,minHeight:l,maxHeight:u=`68vh`,closeThreshold:d=.5})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-modal`),p=(0,n.useToken)(`colors`,`vechain-kit-overlay`),m=(0,r.useRef)(null),h=(0,r.useRef)(null),{tokens:g}=Za(),v=g?.effects?.backdropFilter?.overlay,y=g?.colors?.border?.modal||`none`;return(0,i.jsx)(_.Drawer.Root,{dismissible:c,shouldScaleBackground:!0,repositionInputs:!1,open:e,closeThreshold:d,onOpenChange:e=>{e||t()},children:(0,i.jsxs)(_.Drawer.Portal,{children:[(0,i.jsx)(_.Drawer.Overlay,{style:{zIndex:100,position:`fixed`,top:0,right:0,bottom:0,left:0,backgroundColor:p,backdropFilter:v,WebkitBackdropFilter:v}}),(0,i.jsxs)(_.Drawer.Content,{"aria-description":s,style:{zIndex:101,backgroundColor:f,borderRadius:`24px 24px 0 0`,border:y,position:`fixed`,bottom:0,left:0,right:0,...l&&{minHeight:l},maxHeight:u,display:`flex`,flexDirection:`column`},children:[(0,i.jsx)(_.Drawer.Title,{style:{position:`absolute`,width:`1px`,height:`1px`,padding:0,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:0},children:o}),(0,i.jsxs)(n.Box,{ref:m,flex:`1`,overflowY:`auto`,children:[(0,i.jsx)(Ie,{scrollableContainerRef:m,observerRef:h}),(0,i.jsx)(`div`,{ref:h,style:{height:`1px`,width:`100%`,visibility:`hidden`,marginTop:`-1px`}}),a]})]})]})})},Re=({isOpen:e,onClose:t,children:r,size:a=`sm`,isCentered:o=!0,motionPreset:s=`slideInBottom`,closeOnOverlayClick:c=!0,blockScrollOnMount:l=!1,allowExternalFocus:u=!1,backdropFilter:d,isCloseable:f=!0,useBottomSheetOnMobile:p,mobileMinHeight:m,mobileMaxHeight:h=`57vh`,desktopMinHeight:g,desktopMaxHeight:_})=>{let[v]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:y,themeConfig:b,tokens:x}=Za(),S=p??b?.modal?.useBottomSheetOnMobile??!1,C=(0,n.useToken)(`colors`,`vechain-kit-modal`),w=(0,n.useToken)(`colors`,`vechain-kit-overlay`),T=x?.effects?.backdropFilter?.overlay,E=x?.effects?.backdropFilter?.modal,D=d??T??`blur(3px)`,O=v?{minHeight:g,maxHeight:_}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`,minHeight:m,maxHeight:h},k=(0,i.jsxs)(n.Modal,{motionPreset:s,isOpen:e,onClose:t,isCentered:o,size:a,returnFocusOnClose:!1,blockScrollOnMount:l,closeOnOverlayClick:c&&f,preserveScrollBarGap:!0,portalProps:{containerRef:y},trapFocus:!u,autoFocus:!u,variant:`vechainKitBase`,children:[(0,i.jsx)(n.ModalOverlay,{bg:w,backdropFilter:D}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:C,sx:{backdropFilter:E,WebkitBackdropFilter:E},...O,children:r})]});return(0,i.jsx)(i.Fragment,{children:!v&&S?(0,i.jsx)(n.Modal,{isOpen:e,onClose:t,size:a,blockScrollOnMount:!1,trapFocus:!1,children:(0,i.jsx)(Le,{isOpen:e,onClose:t,ariaTitle:`Dialog`,ariaDescription:`Dialog content area`,isDismissable:f,minHeight:m,maxHeight:h,children:r})}):k})},ze=async t=>{let n=new URL(`/api/v1/apps/${t}`,e.h),r=await fetch(n,{headers:{"privy-app-id":t}});if(!r.ok)throw Error(`Failed to fetch Privy app info`);return r.json()},Be=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],Ve=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:Be(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>ze(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.Y.find(e=>e.id===i);return[i,{...e,website:a?.website}]}))},enabled:n.length>0,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},He=async()=>{try{let t=new URL(`summary.json`,e.g),n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch Privy status`);return(await n.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},Ue=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:He,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60}),We=e=>[`VECHAIN_KIT_DOMAIN`,e],Ge=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:We(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);if(n.type!==`main`&&n.type!==`test`){let n=t.j(e);return{address:n?e:void 0,domain:void 0,isValidAddressOrDomain:n,isPrimaryDomain:!1}}let r=await(0,v.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.j(e);if(!r&&!i)throw Error(`Input must be a valid domain or address`);let a=null,o=null,s=!1;return r?(a=await(0,v.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,v.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,v.isPrimaryDomain)(o,e,{networkUrl:n.nodeUrl}))),{address:a||void 0,domain:o||void 0,isValidAddressOrDomain:r||i,isPrimaryDomain:s}},enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address or domain is required`||e===`input must be a valid domain or address`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Ke=async(e,n,r)=>{let i=(0,b.keccak256)((0,b.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,b.keccak256)((0,b.toBytes)(r))])),a=await e.contracts.load(t.bt(n).vetDomainsContractAddress,y.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},qe=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],Je=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:qe(e),queryFn:()=>Ke(t,n.type,e),enabled:!!e,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Ye=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:mt(e??``,r.type)}),n.invalidateQueries({queryKey:vt(e,r.type)}),n.invalidateQueries({queryKey:Ot(t)})])}}},Xe=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:We(t)}),e.invalidateQueries({queryKey:We(n)}),e.invalidateQueries({queryKey:qe(r)}),e.invalidateQueries({queryKey:ft(t,`.vet`)}),e.invalidateQueries({queryKey:ft(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:vt(n)})]),await Promise.all([e.refetchQueries({queryKey:We(t)}),e.refetchQueries({queryKey:We(n)}),e.refetchQueries({queryKey:ft(t,`.vet`)}),e.refetchQueries({queryKey:ft(t,`.veworld.vet`)}),e.refetchQueries({queryKey:mt(r+`.`+i,a)}),e.refetchQueries({queryKey:vt(n)}),e.refetchQueries({queryKey:qe(r)}),e.refetchQueries({queryKey:Ot(t)})])},Ze=y.VeworldSubdomainClaimer__factory.createInterface(),Qe=y.VetDomainsReverseRegistrar__factory.createInterface(),$e=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:Qe.getFunction(`setName`)}),r){s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:Qe.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.bt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.W(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if(tt(n))s.push({to:t.bt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:Ze.encodeFunctionData(`claim`,[e,t.bt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:Ze.getFunction(`claim`)}),s.push({to:t.bt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Qe.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:Qe.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},et=({subdomain:e,domain:t,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let o=(0,p.useQueryClient)(),{account:s}=X(),{network:c}=$(),{refresh:l}=Ye(e+`.`+t,s?.address??``),u=(0,r.useCallback)(()=>$e(e,t,a,s,c),[e,t,a,s,c]),d=(0,r.useCallback)(async()=>{let r=`${e}.${t}`;await Xe(o,s?.address??``,r,e,t,c.type),l(),n?.()},[n,e,t,o,s,c.type,l]),f=$n({signerAccountAddress:s?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e}.${t} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:d,onTxFailedOrCancelled:()=>{i?.()}});return{...f,clauses:u,sendTransaction:async()=>f.sendTransaction(u())}},tt=e=>e.endsWith(`veworld.vet`),nt=y.VetDomainsReverseRegistrar__factory.createInterface(),rt=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.bt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:nt.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:nt.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.bt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.W(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},it=({domain:e,onSuccess:t,onError:n,alreadyOwned:i=!1})=>{let{network:a}=$(),o=(0,p.useQueryClient)(),{account:s}=X(),{refresh:c}=Ye(e,s?.address??``),l=(0,r.useCallback)(()=>rt(e,i,s,a),[e,i,s,a]),u=(0,r.useCallback)(async()=>{await Xe(o,s?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,a.type),c(),t?.()},[t,e,o,s,a.type,c]),d=$n({signerAccountAddress:s?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:u,onTxFailedOrCancelled:n});return{...d,clauses:l,sendTransaction:async()=>d.sendTransaction(l())}},at=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],ot=s.ABIContract.ofAbi(y.VeworldSubdomainClaimer__factory.abi),st=async(e,n,r)=>{let i=t.bt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,ot.abi).read.isDomainProtected(r))[0]},ct=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:at(e),queryFn:()=>st(n,r.type,e),enabled:!!e&&t&&!!r.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},lt=x.z.object({name:x.z.string()}),ut=x.z.object({domains:x.z.array(lt)}),dt=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.bt(e).graphQlIndexerUrl,a=`query Registrations {
122
122
  domains(
123
123
  where: ${r?`{owner: "${n.toLowerCase()}", parent_: {name: "${r}"}}`:`{owner: "${n.toLowerCase()}"}`}
124
124
  ) {
125
125
  name
126
126
  }
127
- }`,o=await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({operationName:`Registrations`,query:a,extensions:{}})});if(!o.ok)throw Error(`Failed to fetch domains`);let s=await o.json();return s.data&&s.data.domains&&(s.data.domains=s.data.domains.filter(e=>!e.name.endsWith(`addr.reverse`))),ut.parse(s.data)},ft=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,e,t],pt=(e,t)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ft(e,t),queryFn:()=>dt(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},mt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,e,t],ht=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:mt(e??``,t.type),queryFn:async()=>e?(0,v.getAvatar)(e,{networkUrl:t.nodeUrl}):null,enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},gt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) view returns (string)`]),_t=async(e,n,r)=>{if(!r)return{};let i=(0,o.namehash)(r);try{let r=new URL(`accounts/*`,e),[{data:a,reverted:o}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.bt(n).vetDomainsContractAddress,data:gt.encodeFunctionData(`resolver`,[i])}]})})).json();if(o)return{};let{resolverAddress:s}=gt.decodeFunctionResult(`resolver`,a);return(await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:t.S.map(e=>({to:s,data:gt.encodeFunctionData(`text`,[i,e])}))})})).json()).reduce((e,{data:n,reverted:r},i)=>{if(!r&&n&&n!==`0x`)try{let r=gt.decodeFunctionResult(`text`,n)[0];r&&(e[t.S[i]]=r)}catch(e){console.error(`Failed to decode text record for ${t.S[i]}:`,e)}return e},{})}catch(e){throw console.error(`Error fetching text records:`,e),e}},vt=(e,t)=>[`VECHAIN_KIT_TEXT_RECORDS`,e,t],yt=e=>{let{network:n}=$(),r=n.nodeUrl??t.bt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:vt(e,n.type),queryFn:()=>_t(r,n.type,e),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},bt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function setText(bytes32 node, string key, string value) external`]),xt=(e,t)=>{let n=[];for(let{domain:r,key:i,value:a}of t){if(!r)throw Error(`Domain is required`);if(!e)throw Error(`Resolver address is required`);let t=(0,o.namehash)(r);n.push({to:e,data:bt.encodeFunctionData(`setText`,[t,i,a]),value:`0`,comment:`Update ${i} record`})}return n},St=({onSuccess:e,onError:t,signerAccountAddress:n,resolverAddress:i}={})=>{let a=(0,r.useCallback)(e=>{if(!i)throw Error(`Resolver address is required`);return xt(i,e)},[i]),o=$n({signerAccountAddress:n,onTxConfirmed:async()=>{await e?.()},onTxFailedOrCancelled:async()=>{await t?.()},privyUIOptions:{title:`Update Profile Information`,description:`Update the profile information associated with your domain`,buttonText:`Sign to continue`}});return{...o,clauses:a,sendTransaction:async e=>o.sendTransaction(a(e))}},Ct=e=>[`VECHAIN_KIT`,`RESOLVER_ADDRESS`,e],wt=e=>{let{network:n}=$();return Qo({address:t.bt(n.type).vetDomainsContractAddress,abi:y.VetDomainsRegistry__factory.abi,method:`resolver`,args:[e?(0,b.namehash)(e):`0x`],queryOptions:{select:e=>e[0],enabled:!!e}})},Tt={Mugshot:new URL(`mugshot.png`,e.w).toString(),Greencart:new URL(`greencart.png`,e.w).toString(),Cleanify:new URL(`cleanify.png`,e.w).toString(),EVearn:new URL(`evearn.png`,e.w).toString()},Et=`vechain_kit_cross_app_connection`,Dt=()=>{let e=t.dt(`vechain_kit_cross_app_connection`);if(!e)return null;try{let t=JSON.parse(e)?.ecosystemApp?.name;return t?Tt[t]??null:null}catch{return null}},Ot=e=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR_OF_ADDRESS`,e],kt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Ot(e),queryFn:async()=>{if(!e||!n.nodeUrl)return Dt()??t.U(e??``);let r=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl});return r&&await(0,v.getAvatar)(r,{networkUrl:n.nodeUrl})||(Dt()??t.U(e??``))},enabled:!!e&&!!n.nodeUrl,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},At=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) returns (string avatar)`]),jt=new o.Interface([`function tokenURI(uint256 tokenId) view returns (string)`,`function uri(uint256 id) view returns (string)`]),Mt=async(e,n,r)=>{if(!r)throw Error(`Name is required`);let i=(0,o.namehash)(r);try{let r=new URL(`accounts/*`,n),[{data:a,reverted:o}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.bt(e).vetDomainsContractAddress,data:At.encodeFunctionData(`resolver`,[i])}]})})).json();if(o)return null;let{resolverAddress:s}=At.decodeFunctionResult(`resolver`,a),[{data:c,reverted:l}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:s,data:At.encodeFunctionData(`text`,[i,`avatar`])}]})})).json();if(l||c===`0x`)return null;try{let{avatar:t}=At.decodeFunctionResult(`text`,c),r=t===``?null:t;return r?Pt(r,e,n):null}catch(e){return console.error(`Failed to decode avatar data:`,e),null}}catch(e){throw console.error(`Error fetching avatar using legacy API:`,e),e}},Nt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,`LEGACY`,e,t];async function Pt(e,n,r){try{if(e.startsWith(`http`)||e.startsWith(`ipfs://`)||e.startsWith(`ar://`))return t.g(e,n)||null;let i=e.match(/eip155:(\d+)\/(?:erc721|erc1155):([^/]+)\/(\d+)/);if(i){let[,a,s,c]=i,l=e.includes(`erc1155`);if(!a||!s||c===void 0)return null;let u=[{to:s,data:jt.encodeFunctionData(l?`uri`:`tokenURI`,[BigInt(c||0)])}],d=new URL(`accounts/*`,r),[{data:f,reverted:p}]=await fetch(d,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:u})}).then(e=>e.json());if(p)return console.error(`Failed to fetch tokenURI`),null;let m=``;try{m=jt.decodeFunctionResult(l?`uri`:`tokenURI`,f)[0]}catch(e){console.error(`Failed to decode avatar data:`,e),m=(0,o.toUtf8String)(f)}m=t.g(m,n)||m,l&&(m=m.replace(`{id}`,(0,o.zeroPadValue)((0,o.toBeHex)(BigInt(c||0)),32).slice(2)));let h=await fetch(m);if(!h.ok)return console.error(`Failed to fetch metadata`),null;let g=await h.json(),_=g.image||g.image_url||g.image_data;return _?t.g(_,n)||_:(console.error(`No image URL in metadata`),null)}return null}catch(e){return console.error(`Error parsing avatar record:`,e),null}}const Ft=e=>{let{network:n}=$(),r=n.nodeUrl??t.bt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:Nt(e??``,n.type),queryFn:async()=>e?Mt(n.type,r,e):null,enabled:!!e&&!!r&&!!n.type})},It=y.VetDomainsReverseRegistrar__factory.createInterface(),Lt=(e,n)=>{let r=[];return r.push({to:t.bt(n.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:It.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(e?.address??``,4,4)}`,abi:It.getFunction(`setName`)}),r},Rt=({onSuccess:e,onError:t})=>{let n=(0,p.useQueryClient)(),{account:i}=X(),{network:a}=$(),o=(0,r.useCallback)(()=>Lt(i,a),[i,a]),s=(0,r.useCallback)(async()=>{await Xe(n,i?.address??``,``,``,``,a.type),e?.()},[e,n,i,a.type]),c=$n({signerAccountAddress:i?.address??``,privyUIOptions:{title:`Sign to unset your VeChain nickname`,description:`Unset your current VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:s,onTxFailedOrCancelled:t});return{...c,clauses:o,sendTransaction:async()=>c.sendTransaction(o())}},zt=e=>{let{network:n}=$(),i=t.bt(n.type),{data:a,isLoading:o}=cs(e),{data:s,isLoading:c}=ln(e),{data:l,isLoading:u}=hn(e),{data:d,isLoading:f}=pn(i.veDelegateTokenContractAddress,e),{data:p,isLoading:m}=pn(i.gloDollarContractAddress,e),h=dn(e),g=h.map(e=>e.data).filter(Boolean),_=h.some(e=>e.isLoading);return{balances:(0,r.useMemo)(()=>{if(!e)return[];let t={vet:`0x`,vtho:i.vthoContractAddress,b3tr:i.b3trContractAddress,vot3:i.vot3ContractAddress,veDelegate:i.veDelegate,USDGLO:i.gloDollarContractAddress},n=[{address:t.vet,symbol:`VET`,balance:a?.balance||`0`},{address:t.vtho,symbol:`VTHO`,balance:a?.energy||`0`},{address:t.b3tr,symbol:`B3TR`,balance:s?.scaled??`0`},{address:t.vot3,symbol:`VOT3`,balance:l?.scaled??`0`},{address:t.veDelegate,symbol:`veDelegate`,balance:d?.scaled??`0`},{address:t.USDGLO,symbol:`USDGLO`,balance:p?.scaled??`0`}],r=g.map(e=>({address:e?.address||``,symbol:e?.symbol||``,balance:e?.scaled||`0`}));return[...n,...r]},[e,a,s,l,d,p,g,n.type]),isLoading:o||c||u||f||m||_}},Bt={B3TR:`0x623374722d757364000000000000000000000000000000000000000000000000`,VET:`0x7665742d75736400000000000000000000000000000000000000000000000000`,VTHO:`0x7674686f2d757364000000000000000000000000000000000000000000000000`,GBP:`0x6762702d75736400000000000000000000000000000000000000000000000000`,EUR:`0x657572742d757364000000000000000000000000000000000000000000000000`},Vt=async(e,n,r)=>{let i=await e.contracts.load(t.bt(r).oracleContractAddress,y.OracleVechainEnergy__factory.abi).read.getLatestValue(Bt[n]);if(!i)throw Error(`Failed to get price of ${n}`);return new a.BigNumber(i[0].toString()).div(0xe8d4a51000).toNumber()},Ht=e=>[`VECHAIN_KIT_PRICE`,e],Ut=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ht(e),queryFn:async()=>Vt(t,e,n.type),enabled:!!t&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Wt=()=>{let{network:e}=$(),n=t.bt(e.type),{data:i,isLoading:a}=Ut(`VET`),{data:o,isLoading:s}=Ut(`VTHO`),{data:c,isLoading:l}=Ut(`B3TR`),{data:u,isLoading:d}=Ut(`EUR`),{data:f,isLoading:p}=Ut(`GBP`);return{prices:(0,r.useMemo)(()=>{let e={vet:`0x`,vtho:n.vthoContractAddress,b3tr:n.b3trContractAddress,vot3:n.vot3ContractAddress,veDelegate:n.veDelegate,USDGLO:n.gloDollarContractAddress};return{[e.vet]:i||0,[e.vtho]:o||0,[e.b3tr]:c||0,[e.vot3]:c||0,[e.veDelegate]:c||0,[e.USDGLO]:1}},[i,o,c,n.vthoContractAddress,n.b3trContractAddress,n.vot3ContractAddress,n.veDelegate,n.gloDollarContractAddress]),exchangeRates:(0,r.useMemo)(()=>({eurUsdPrice:u||1,gbpUsdPrice:f||1}),[u,f]),isLoading:a||s||l||d||p}},Gt=(e,t,n)=>{switch(t){case`eur`:return e/n.eurUsdPrice;case`gbp`:return e/n.gbpUsdPrice;default:return e}},Kt=(e,t=`en`,n)=>{let r={style:`currency`,minimumFractionDigits:2,maximumFractionDigits:2,currency:n?.currency??`usd`,...n};return new Intl.NumberFormat(U[t],r).format(e)},qt=(e,t)=>Kt(e,W.resolvedLanguage,{notation:`compact`,compactDisplay:`short`,currency:t?.currency??`usd`,...t}),Jt=`vechain_kit_currency`,Yt=[`usd`,`eur`,`gbp`],Xt=()=>{let{currentCurrency:e,setCurrency:n}=$();return(0,r.useEffect)(()=>{t.yt(`vechain_kit_currency`,e)},[e]),{currentCurrency:e,allCurrencies:Yt,changeCurrency:e=>{if(!Yt.includes(e)){console.error(`Invalid currency: ${e}`);return}n(e)}}},Zt=({address:e=``})=>{let{balances:t,isLoading:n}=zt(e),{prices:i,exchangeRates:a,isLoading:o}=Wt(),{currentCurrency:s}=Xt(),c=(0,r.useMemo)(()=>t.map(e=>{let t=i[e.address]||0,n=Number(e.balance)*t,r=Gt(n,s,a);return{...e,priceUsd:t,valueUsd:n,valueInCurrency:r}}),[t,i,s,a]),l=(0,r.useMemo)(()=>[...c].sort((e,t)=>t.valueInCurrency-e.valueInCurrency),[c]);return{tokens:c,sortedTokens:l,tokensWithBalance:(0,r.useMemo)(()=>l.filter(e=>Number(e.balance)>0),[l]),isLoading:n||o}},Qt=({address:e=``})=>{let{tokensWithBalance:t,isLoading:n}=Zt({address:e}),{currentCurrency:i}=Xt(),a=(0,r.useMemo)(()=>t.reduce((e,t)=>e+t.valueInCurrency,0),[t]);return{totalBalanceInCurrency:a,totalBalanceUsd:(0,r.useMemo)(()=>t.reduce((e,t)=>e+t.valueUsd,0),[t]),formattedBalance:(0,r.useMemo)(()=>qt(a,{currency:i}),[a,i]),isLoading:n,hasAnyBalance:t.length>0}},$t=y.XAllocationVoting__factory.abi,en=`currentRoundId`,tn=e=>Yo({abi:$t,address:e,method:en}),nn=()=>{let{network:e}=$(),n=t.bt(e.type).xAllocationVotingContractAddress;return Qo({abi:$t,address:n,method:en,args:[],queryOptions:{select:e=>e[0].toString()}})},rn=async(e,t)=>(0,v.getTokenInfo)(e,{networkUrl:t}),an=e=>[`VECHAIN_KIT_CUSTOM_TOKEN_INFO`,e],on=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:an(e),queryFn:async()=>{if(!e)throw Error(`Token address is required`);if(!t.nodeUrl)throw Error(`Network node URL is required`);return rn(e,t.nodeUrl)},enabled:!!t.type&&!!e,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`token address is required`||e===`network node url is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},sn=()=>{let[e,n]=mc(pc.CUSTOM_TOKENS,[]),{network:r}=$(),i=async t=>{if(!o(t)&&!s(t)){if(!r.nodeUrl)throw Error(`Network node URL is required`);let i={...await rn(t,r.nodeUrl),address:t};n([...e,i])}},a=t=>{n(e.filter(e=>e.address!==t))},o=n=>e.some(e=>t.k(e.address,n)),s=e=>{let n={vet:`0x`,vtho:t.bt(r.type).vthoContractAddress,b3tr:t.bt(r.type).b3trContractAddress,vot3:t.bt(r.type).vot3ContractAddress,veDelegate:t.bt(r.type).veDelegate};return Object.values(n).includes(e)};return{customTokens:e,addToken:i,removeToken:a,isTokenIncluded:o,isDefaultToken:s}},cn=e=>[`VEBETTERDAO_BALANCE`,e,`B3TR`],ln=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:cn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,v.getB3trBalance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get b3tr balance`);let i=r[0];return t.H(i)},enabled:!!e&&!!n.type})},un=(e,t)=>[`VECHAIN_KIT_BALANCE`,t,`CUSTOM_TOKEN`,e],dn=e=>{let{network:n}=$(),{customTokens:r}=sn();return(0,p.useQueries)({queries:r.map(r=>({queryKey:un(r.address,e),queryFn:async()=>{if(!r.address)throw Error(`Token address is required`);if(!e)throw Error(`Address is required`);if(!n.nodeUrl)throw Error(`Network node URL is required`);let i=await(0,v.getErc20Balance)(r.address,e,{networkUrl:n.nodeUrl});if(!i)throw Error(`Failed to get token balance`);let a=t.H(i[0]);return{...r,...a}}}))})},fn=(e,t)=>[`VECHAIN_KIT`,`BALANCE`,`ERC20`,e,t],pn=(e,n)=>{let{network:r}=$();return(0,p.useQuery)({queryKey:fn(e,n),queryFn:async()=>{if(!n)throw Error(`Address is required`);let i=await(0,v.getErc20Balance)(e,n,{networkUrl:r.nodeUrl});if(!i)throw Error(`Failed to get vot3 balance`);let a=i[0];return t.H(a)},enabled:!!n&&!!r.type})},mn=e=>[`VEBETTERDAO_BALANCE`,e,`VOT3`],hn=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:mn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,v.getVot3Balance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get vot3 balance`);let i=r[0];return t.H(i)},enabled:!!e&&!!n.type})},gn=(e,t)=>[`VECHAIN_KIT`,`IS_PERSON`,e,t],_n=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:gn(e??``,t.type),queryFn:async()=>{if(!e)throw Error(`User address is required`);return(0,v.getIsPerson)(e,{networkUrl:t.nodeUrl})},enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`user address is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},vn=y.XAllocationVoting__factory.abi,yn=`getAppsOfRound`,bn=(e,n)=>Zo({abi:vn,address:t.bt(n).xAllocationVotingContractAddress,method:yn,args:[BigInt(e??0)]}),xn=e=>{let{network:n}=$(),r=t.bt(n.type).xAllocationVotingContractAddress;return Qo({abi:vn,address:r,method:yn,args:[BigInt(e??0)],queryOptions:{enabled:!!e,select:e=>e[0].map(e=>({id:e.id.toString(),teamWalletAddress:e.teamWalletAddress,name:e.name,metadataURI:e.metadataURI,createdAtTimestamp:e.createdAtTimestamp.toString()}))}})},Sn=y.XAllocationPool__factory.abi,Cn=`getAppShares`,wn=e=>[`VECHAIN_KIT`,`XApps`,`Shares`,e],Tn=(e,n)=>{let r=(0,f.useThor)(),{network:i}=$(),a=t.bt(i.type).xAllocationPoolContractAddress;return(0,p.useQuery)({queryKey:wn(n),queryFn:async()=>(await t.r({thor:r,calls:e.map(e=>({abi:Sn,functionName:`getAppShares`,address:a,args:[n,e]}))})).map((t,n)=>({app:e[n],share:Number(t[0]||0)/100,unallocatedShare:Number(t[1]||0)/100})),enabled:!!n&&!!e.length})},En=e=>{let{data:t}=xn(e),n=Tn(t?.map(e=>e.id)??[],e);return{data:(0,r.useMemo)(()=>n.data?.map(e=>({percentage:e.share+e.unallocatedShare,id:t?.find(t=>t.id===e.app)?.id??``,app:t?.find(t=>t.id===e.app)??{}})).sort((e,t)=>Number(t.percentage)-Number(e.percentage))??[],[n.data,t]),isLoading:n.isLoading}},Dn=({error:e,mobileBrowserPopupMessage:n=`Mobile browser blocked the window. Please try again.`,rejectedMessage:r=`Request was cancelled.`,defaultMessage:i=`Operation failed`})=>{let a=e?.message;return w.isMobile&&a&&!t.a(a)?Error(n):a&&t.a(a)?Error(r):e instanceof Error?e:Error(i)},On=(0,b.defineChain)({id:`1176455790972829965191905223412607679856028701100105089447013101863`,name:`Vechain`,nativeCurrency:{name:`VeChain`,symbol:`VET`,decimals:18},rpcUrls:{default:{http:[e.E]}},blockExplorers:{default:{name:`Vechain Explorer`,url:e.S},vechainStats:{name:`Vechain Stats`,url:e.b}}}),kn=()=>(0,C.toPrivyWalletConnector)({id:t.at,name:`VeChain`,iconUrl:`https://imagedelivery.net/oHBRUd2clqykxgDWmeAyLg/661dd77c-2f9d-40e7-baa1-f4e24fd7bf00/icon`,smartWalletMode:!1}),An=({privyEcosystemAppIDS:e,children:t})=>(0,i.jsx)(S.WagmiProvider,{config:(0,r.useRef)((0,S.createConfig)({chains:[On],ssr:!0,connectors:[kn(),...e.map(e=>(0,C.toPrivyWalletConnector)({id:e,name:``,iconUrl:``}))],transports:{[On.id]:(0,S.http)()},multiInjectedProviderDiscovery:!1})).current,children:t}),jn=()=>{let{connectAsync:e,connectors:n}=(0,S.useConnect)(),{signTypedDataAsync:i}=(0,S.useSignTypedData)(),{signMessageAsync:a}=(0,S.useSignMessage)(),{disconnectAsync:o}=(0,S.useDisconnect)(),{isConnected:s}=(0,S.useAccount)(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{try{s&&(await o(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`)))}catch(e){throw console.error(`Error during logout:`,e),e}},[o,s]);return{login:(0,r.useCallback)(async r=>{try{l(!0),d(null);let i=n.find(e=>e.id===(r||t.at));if(!i)throw Error(`Connector not found`);return await e({connector:i})}catch(e){throw d(e),e}finally{l(!1)}},[e,n]),logout:f,signMessage:(0,r.useCallback)(async e=>{try{return await a({message:e})}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the signing window. Please click 'Try again' to open the signing window or change your browser settings.`,rejectedMessage:`Signing request was cancelled.`,defaultMessage:`An unexpected issue occurred while signing a message. Please try again or contact support.`})}},[a]),signTypedData:(0,r.useCallback)(async e=>{try{return await i(e)}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the signing window. Please click 'Try again' to open the signing window or change your browser settings.`,rejectedMessage:`Signing request was cancelled.`,defaultMessage:`An unexpected issue occurred while signing typed data. Please try again or contact support.`})}},[i]),isConnecting:c,connectionError:u}},Mn=(e,n)=>{let{data:r,isLoading:i}=Ge(e??``),{data:a,isLoading:o}=kt(e??``),{data:s,isLoading:c}=yt(r?.domain??``),l=s?.header?t.g(s.header,n):null;return{domain:r?.domain,image:a,records:{...s,header:l},isLoading:i||o||c}},Nn=()=>{let{network:e}=$(),n=(0,r.useCallback)(e=>({wallets:`vechain_kit_wallets_${e}`,activeWallet:`vechain_kit_active_wallet_${e}`}),[]),i=(0,r.useCallback)(()=>{if(!t.mt())return[];let r=t.dt(n(e.type).wallets);return r?JSON.parse(r):[]},[e.type,n]),a=(0,r.useCallback)(()=>t.mt()?t.dt(n(e.type).activeWallet):null,[e.type,n]),o=(0,r.useCallback)(r=>{if(!t.mt())return;let a=n(e.type),o=i(),s=o.findIndex(e=>e.address.toLowerCase()===r.toLowerCase()),c={address:r,connectedAt:s>=0?o[s].connectedAt:Date.now(),isActive:!1};s>=0?o[s]=c:o.push(c),t.yt(a.wallets,JSON.stringify(o))},[e.type,n,i]),s=(0,r.useCallback)(r=>{if(!t.mt())return;let a=n(e.type),o=i().map(e=>({...e,isActive:e.address.toLowerCase()===r.toLowerCase()}));t.yt(a.wallets,JSON.stringify(o)),t.yt(a.activeWallet,r)},[e.type,n,i]);return{getStoredWallets:i,getActiveWallet:a,saveWallet:o,setActiveWallet:s,removeWallet:(0,r.useCallback)(r=>{if(!t.mt())return;let o=n(e.type),s=i().filter(e=>e.address.toLowerCase()!==r.toLowerCase());t.yt(o.wallets,JSON.stringify(s));let c=a();c&&c.toLowerCase()===r.toLowerCase()&&t.gt(o.activeWallet),t.mt()&&window.dispatchEvent(new CustomEvent(`wallet_removed`,{detail:{address:r}}))},[e.type,n,i,a]),initializeCurrentWallet:(0,r.useCallback)(e=>{t.mt()&&i().length===0&&(o(e),s(e))},[i,o,s])}},X=()=>{let{address:e,isConnected:n,isConnecting:i,isReconnecting:a}=(0,S.useAccount)(),{logout:o}=jn(),{loading:s}=(0,u.useLoginWithOAuth)({}),{feeDelegation:c,network:l,privy:d}=$(),{user:p,authenticated:m,logout:h,ready:g}=(0,u.usePrivy)(),{data:_}=qs(),{account:v,disconnect:y}=(0,f.useWallet)(),{getConnectionCache:b,clearConnectionCache:x}=Vo(),C=b(),{initializeCurrentWallet:w,getActiveWallet:T,saveWallet:E,getStoredWallets:D}=Nn(),O=rs(),k=(0,r.useMemo)(()=>t.mt()?!!window.vechain?.isInAppBrowser:!1,[]),A=!!v,j=m&&!!p,M=j||n,N=j&&d?.appId===t.at||n&&C?.ecosystemApp?.appId===t.at,P=i||a||s||!g,[F,I]=(0,r.useState)(!1),L=n?{type:`privy-cross-app`,displayName:`Ecosystem`}:A?{type:`wallet`,displayName:`Wallet`}:{type:`privy`,displayName:`Social Login`};(0,r.useEffect)(()=>{let e=A||j||n;F!==e&&(I(e),e||(x(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`))))},[A,j,n,x,F]);let R=p?.linkedAccounts?.find(e=>e.type===`wallet`&&e.connectorType===`embedded`)?.address,z=A?v:n?e:R,[B,ee]=(0,r.useState)(()=>A&&!k?T():null);(0,r.useEffect)(()=>{ee(A&&!k?T():null)},[A,k,T]);let[te,V]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(!t.mt()||!A||k)return;let e=e=>{V(!0),ee(e.detail.address),setTimeout(()=>{V(!1)},1e3)};return window.addEventListener(`wallet_switched`,e),()=>{window.removeEventListener(`wallet_switched`,e)}},[A,k]);let ne=D().some(e=>e.address.toLowerCase()===z?.toLowerCase()),re=A&&!k?T():null,ie=te&&re||re&&ne?re:z,{data:H}=Ns(ie??``),ae=A?ie:H?.address,U=Mn(ae??``,l.type),oe=Mn(ie??``,l.type),W=Mn(H?.address??``,l.type),{setActiveWallet:se}=Nn(),ce=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{if(!t.mt()||!A||k)return;let e=e=>{ce.current.add(e.detail.address.toLowerCase()),setTimeout(()=>{ce.current.delete(e.detail.address.toLowerCase())},5e3)};return window.addEventListener(`wallet_removed`,e),()=>{window.removeEventListener(`wallet_removed`,e)}},[A,k]),(0,r.useEffect)(()=>{if(A&&!k&&z&&U&&!U.isLoading){if(ce.current.has(z.toLowerCase()))return;let e=!D().some(e=>e.address.toLowerCase()===z.toLowerCase());w(z),E(z);let t=!B,n=B&&B.toLowerCase()===z.toLowerCase();(e||t||n)&&!te&&se(z)}},[A,k,z,U?.domain,U?.image,U?.isLoading,w,E,se,B,D]),(0,r.useEffect)(()=>{A&&!k&&B&&B.toLowerCase()===ie?.toLowerCase()&&E(B)},[A,k,B,ie,E]);let G=ae?{address:ae,domain:U.domain,image:U.image,isLoadingMetadata:U.isLoading,metadata:U.records}:null,le=z?{address:z,domain:oe.domain,image:oe.image,isLoadingMetadata:oe.isLoading,metadata:oe.records}:null,{data:ue}=bs(H?.address??``,le?.address??``),de=!!H?.address&&!!G?.address&&t.k(H?.address,G?.address),K=(0,r.useCallback)(async()=>{try{I(!1),A?y():j?await h():n&&await o(),x(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`))}catch(e){console.error(`Error during disconnect:`,e)}},[A,y,j,h,n,o,x]);return{account:G,smartAccount:{address:H?.address??``,domain:W.domain,image:W.image,isDeployed:H?.isDeployed??!1,isActive:de,version:ue?.version??null,isLoadingMetadata:W.isLoading,metadata:W.records},connectedWallet:le,privyUser:p,connection:{isLoading:P,isConnected:F,isConnectedWithSocialLogin:j,isConnectedWithDappKit:A,isConnectedWithCrossApp:n,isConnectedWithPrivy:M,isConnectedWithVeChain:N,source:L,isInAppBrowser:k,nodeUrl:O,delegatorUrl:c?.delegatorUrl,chainId:_,network:l.type},disconnect:K}},Pn=()=>{let e=(0,p.useQueryClient)(),{account:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.invalidateQueries({queryKey:[`VECHAIN_KIT_BALANCE`,n]}),e.invalidateQueries({queryKey:[`VECHAIN_KIT_PRICE`]})])}}},Fn=()=>{let{switchWallet:e}=(0,f.useWallet)(),{connection:n}=X(),[i,a]=(0,r.useState)(!1),{getStoredWallets:o,setActiveWallet:s,removeWallet:c}=Nn(),l=n.isInAppBrowser;return{switchWallet:(0,r.useCallback)(async()=>{if(l){if(!e)return;a(!0);try{await e()}catch{}finally{a(!1)}}else return Promise.resolve()},[e,l]),isSwitching:i,getStoredWallets:o,setActiveWallet:(0,r.useCallback)(e=>{s(e),t.mt()&&window.dispatchEvent(new CustomEvent(`wallet_switched`,{detail:{address:e}}))},[s]),removeWallet:c,isInAppBrowser:l}},In=async(e,n)=>{let r=t.g(e,n)||``,i=await fetch(r,{signal:AbortSignal.timeout(2e4)});if(!i.ok)throw Error(`HTTP error! status: ${i.status}`);return await i.json()},Ln=y.X2EarnApps__factory.abi,Rn=e=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:[`xAppMetaData`,e],queryFn:async()=>{let i=t.bt(r.type).x2EarnAppsContractAddress,a=n.contracts.load(i,Ln),o=(await a.read.app(e))[0][3]?.toString()||``,[s]=await a.read.baseURI();return await In(`${s}${o}`,r.type)},enabled:!!e})},zn=async(e,n,r=!1)=>{if(!n)throw Error(`No URI provided`);let i=t.g(n,e);if(!i)throw Error(`Invalid URI`);let a=await(await fetch(i,{headers:{"X-Project-Id":`vechain-kit`}})).text();return r?JSON.parse(a):a},Bn=(e,t)=>[`VECHAIN_KIT`,`IPFS_METADATA`,e,t],Vn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Bn(n.type,e),queryFn:()=>zn(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`no uri provided`||e===`invalid uri`)return!1}return e<2},staleTime:1/0})},Hn=1024*1024*10,Un=async(e,n)=>{if(!n)throw Error(`IPFS URI is required`);let r=await fetch(t.g(n,e)??``,{headers:{"X-Project-Id":`vechain-kit`}});if(!r.ok)throw Error(`HTTP error! status: ${r.status}`);let i=await r.blob();if(![`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/bmp`,`image/tiff`,`image/webp`,`image/svg+xml`].includes(i.type))throw Error(`Unsupported MIME type: ${i.type}`);if(i.size>Hn)throw Error(`Image size exceeds maximum allowed size`);return new Promise((e,n)=>{let r=new FileReader;r.readAsDataURL(i),r.onloadend=()=>{e({image:r.result,mime:i.type,mediaType:t._(i.type)})},r.onerror=()=>{n(Error(`Error occurred while reading blob.`))}})},Wn=(e,t)=>[`VECHAIN_KIT`,`IPFS_IMAGE`,e,t],Gn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:Wn(t.type,e),queryFn:()=>Un(t.type,e),enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`ipfs uri is required`)return!1}return e<2},staleTime:1/0})},Kn=e=>{let{network:t}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Wn(t.type,e),queryFn:()=>Un(t.type,e),enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`ipfs uri is required`)return!1}return e<2},staleTime:1/0}))})},qn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Bn(n.type,e),queryFn:async()=>zn(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`no uri provided`||e===`invalid uri`)return!1}return e<2},staleTime:1/0}))})},Jn={maxSizeMB:.4,maxWidthOrHeight:1920,useWebWorker:!0},Yn=async e=>{let t=[];try{for(let n of e){let e=await(0,T.default)(n.file,Jn);t.push(e)}return t}catch(e){throw console.error(`compress error`,e),e}},Xn=({compressImages:e,defaultImages:t})=>{let[n,i]=(0,r.useState)(t??[]);(0,r.useEffect)(()=>{t&&i(t)},[t]);let[a,o]=(0,r.useState)([]),s=(0,r.useCallback)(e=>i(t=>t.filter((t,n)=>n!==e)),[]);return{uploadedImages:n,setUploadedImages:i,onUpload:(0,r.useCallback)(async(t,n=!0)=>{o([]);let r=[];for(let n of t){let t=n;e&&(t=await(0,T.default)(n,Jn));let i={file:t,image:URL.createObjectURL(n)};r.push(i)}i(e=>[...r,...n?e.filter(e=>!r.some(t=>t.file.name===e.file.name)):[]])},[e]),onRemove:s,invalidDateError:a}},Zn=({compressImage:e,defaultImage:t})=>{let[n,i]=(0,r.useState)(t);(0,r.useEffect)(()=>{t&&i(t)},[t]);let a=(0,r.useCallback)(()=>i(void 0),[]);return{uploadedImage:n,setUploadedImage:i,onUpload:(0,r.useCallback)(async t=>{let n=t;e&&(n=await(0,T.default)(n,Jn));let r={file:n,image:URL.createObjectURL(n)};return i(r),r},[e]),onRemove:a}},Qn=async(e,t,n,r)=>{let i=await e.transactions.estimateGas(t,n,r);if(i.reverted)throw Error(`Failed to estimate gas`);let a=i?.totalGas??0;return(!a||Number.isNaN(a))&&(a=0),Math.ceil(a)},$n=({signerAccountAddress:e,clauses:t,onTxConfirmed:n,onTxFailedOrCancelled:i,suggestedMaxGas:a,privyUIOptions:o,gasPadding:c,delegationUrl:l})=>{let u=(0,f.useThor)(),{signer:d,requestTransaction:p}=(0,f.useWallet)(),{connection:m}=X(),{feeDelegation:h}=$(),g=rs(),_=rl(),v=(0,r.useCallback)(async(t,n,r)=>{let i=typeof t==`function`?await t():t??[];if(m.isConnectedWithPrivy)return await _.sendTransaction({txClauses:i,...r,delegationUrl:n});if(!e)throw Error(`signerAccountAddress is required`);let o=0;try{o=await Qn(u,[...i],e,{revision:s.Revision.NEXT,...c?{gasPadding:c}:{}})}catch(e){console.error(`Gas estimation failed`,e)}return(await p(i,{signer:m.isConnectedWithDappKit&&!m.isInAppBrowser&&e?e:d.address,gas:a??o,...h?.delegateAllTransactions||n?{delegator:{url:n??h?.delegatorUrl??``,signer:e}}:{}})).txid},[e,a,g,_,o,h,u,d,c,l,p,m.isConnectedWithDappKit,m.isInAppBrowser]),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(null),T=(0,r.useCallback)(async(e,n)=>{if(!e&&!t)throw Error(`clauses are required`);try{b(null),S(!0),w(null),j(void 0),b(await v(e??[],n,{...o}))}catch(e){w(e&&typeof e==`object`&&`message`in e?e.message:String(e)),i?.(e instanceof Error?e:Error(String(e)))}finally{S(!1)}},[v,t,o,l]),{data:E,isLoading:D,error:O}=ac(y??``),k=(0,r.useCallback)(async e=>{if(!(!e.reverted||!e.meta.txID))return await u.transactions.getRevertReason(e.meta.txID)},[u]),[A,j]=(0,r.useState)(),M=(0,r.useMemo)(()=>{if(x)return`pending`;if(C)return`error`;if(y){if(D)return`waitingConfirmation`;if(O)return`error`;if(E)return E.reverted?`error`:`success`}return`ready`},[D,C,x,y,E,O]);(0,r.useEffect)(()=>{if(M===`success`||M===`error`){if(C&&!A){j({type:`UserRejectedError`,reason:C});return}if(E?.reverted&&!A?.type){(async()=>{let e=await k(E);j({type:`RevertReasonError`,reason:e?`Transaction reverted with: `+e:`Transaction reverted`})})();return}E&&!E.reverted&&n?.()}},[M,E,n,k,C]);let N=(0,r.useCallback)(()=>{b(null),S(!1),w(null),j(void 0)},[]);return{sendTransaction:T,isTransactionPending:(0,r.useMemo)(()=>x||D||M===`pending`||M===`waitingConfirmation`,[x,D,M]),isWaitingForWalletConfirmation:(0,r.useMemo)(()=>M===`pending`,[x,M]),txReceipt:E??null,status:M,resetStatus:N,error:A}},er=(e,t)=>{let{account:n}=X(),{t:i}=(0,l.useTranslation)(),{sendTransaction:a,isTransactionPending:o,isWaitingForWalletConfirmation:s,txReceipt:c,status:u,resetStatus:d,error:f}=$n({signerAccountAddress:n?.address??``,privyUIOptions:{title:i(`ConfirmSwapTitle`,{defaultValue:`Confirm Swap`}),description:i(`ConfirmSwapDescription`,{defaultValue:`Please confirm the swap transaction in your wallet`}),buttonText:i(`Confirm`,{defaultValue:`Confirm`})}});return{executeSwap:(0,r.useCallback)(async()=>{if(!e||!t)throw Error(`Missing swap parameters or quote`);if(!t.aggregator)throw Error(`Aggregator not found for quote from ${t.aggregatorName}`);let n=await t.aggregator.buildSwapTransaction(e,t);if(n.length===0)throw Error(`Failed to build swap transaction`);await a(n)},[e,t,a]),isTransactionPending:o,isWaitingForWalletConfirmation:s,txReceipt:c,status:u,resetStatus:d,error:f}},tr=e=>e===`0x`||e===b.zeroAddress,nr=(e,t,n,r)=>{let i={},a=r.toLowerCase();for(let t of e)try{let e=(0,b.decodeEventLog)({abi:s.ERC20_ABI,eventName:`Transfer`,topics:t.topics,data:t.data}),n=e.args.from.toLowerCase(),r=e.args.to.toLowerCase(),o=e.args.value,c=typeof o==`bigint`?o:BigInt(o);if(n!==a&&r!==a)continue;let l=t.address.toLowerCase(),u=i[l]??{inflow:0n,outflow:0n};n===a&&(u.outflow+=c),r===a&&(u.inflow+=c),i[l]=u}catch{continue}if(n!==void 0){let e=BigInt(n);if(e>0n){let t=i[b.zeroAddress]??{inflow:0n,outflow:0n};t.outflow+=e,i[b.zeroAddress]=t}}for(let e of t){if(e.recipient.toLowerCase()!==a)continue;let t=BigInt(e.amount);if(t<=0n)continue;let n=i[b.zeroAddress]??{inflow:0n,outflow:0n};n.inflow+=t,i[b.zeroAddress]=n}return i},rr=async(e,t,n,r)=>{try{if(n.length===0)return{gasCostVTHO:0,success:!1,error:`No clauses found for simulation`};let i=await r.transactions.simulateTransaction(n,{caller:e.userAddress}),a=!1,o,s=2e5,c={};for(let t=0;t<i.length;t++){let r=i[t];r.reverted&&(a=!0,o=r.vmError||`Transaction reverted`),s+=r.gasUsed;let l=n[t],u=nr(r.events,r.transfers,l?.value,e.userAddress);for(let[e,t]of Object.entries(u)){let n=c[e]??{inflow:0n,outflow:0n};c[e]={inflow:n.inflow+t.inflow,outflow:n.outflow+t.outflow}}}if(a)return{gasCostVTHO:0,success:!1,error:o||`Transaction reverted`};let l=s/1e5,u=tr(e.fromTokenAddress),d=tr(e.toTokenAddress),f=BigInt(e.amountIn);if(u){let e=c[b.zeroAddress]??{inflow:0n,outflow:0n};if(e.outflow>f)return{gasCostVTHO:l,success:!1,error:`VET outflow mismatch: expected ${f.toString()}, got ${e.outflow.toString()}`};for(let[e,t]of Object.entries(c))if(e!==b.zeroAddress&&t.outflow>0n)return{gasCostVTHO:l,success:!1,error:`Unexpected token outflow: token ${e} has outflow ${t.outflow.toString()}, expected 0`}}else{let t=e.fromTokenAddress.toLowerCase(),n=c[t]??{inflow:0n,outflow:0n};if(n.outflow>f)return{gasCostVTHO:l,success:!1,error:`Token outflow mismatch: expected ${f.toString()}, got ${n.outflow.toString()}`};for(let[e,n]of Object.entries(c))if(e!==t&&n.outflow>0n)return{gasCostVTHO:l,success:!1,error:`Unexpected token outflow: ${e===b.zeroAddress?`VET`:e} has outflow ${n.outflow.toString()}, expected 0`}}if(t.minimumOutputAmount&&t.minimumOutputAmount>0n)if(d){let e=c[b.zeroAddress]??{inflow:0n,outflow:0n};if(e.inflow<t.minimumOutputAmount)return{gasCostVTHO:l,success:!1,error:`VET inflow mismatch: expected ${t.minimumOutputAmount.toString()}, got ${e.inflow.toString()}`}}else{let n=c[e.toTokenAddress.toLowerCase()]??{inflow:0n,outflow:0n};if(n.inflow<t.minimumOutputAmount)return{gasCostVTHO:l,success:!1,error:`Token inflow mismatch: expected ${t.minimumOutputAmount.toString()}, got ${n.inflow.toString()}`}}return{gasCostVTHO:l,success:!0}}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Simulation failed`}}},ir=e=>e.startsWith(`0x`)?BigInt(e).toString():e,ar=(e,t)=>({name:e,type:`function`,inputs:t.map(e=>({name:e.name,type:e.type,internalType:e.internalType,components:e.components})),outputs:[],stateMutability:`nonpayable`}),or=(e,t)=>{if(Array.isArray(e)&&e.length>0){let n=e[0];if(typeof n==`object`&&`name`in n&&`type`in n&&n.type===`function`)return e;if(typeof n==`object`&&`name`in n&&`type`in n&&!(`stateMutability`in n||`outputs`in n))return[ar(t,e)]}return e},sr=e=>{try{let t=e.functionName||e.name;if(!t)throw Error(`Function name is required (either functionName or name must be provided)`);return(0,b.encodeFunctionData)({abi:or(e.abi,t),functionName:t,args:e.args})}catch(t){console.error(`Failed to encode function call:`,t);let n=e.functionName||e.name||`unknown`;throw Error(`Failed to encode function call ${n}: ${t instanceof Error?t.message:`Unknown error`}`)}},cr=e=>{let t=sr(e.functionCall);return{to:e.to,value:ir(e.value),data:t,comment:e.comment||`Swap on aggregator`}},lr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){try{let r=new URLSearchParams({fromAddress:n.fromTokenAddress,toAddress:n.toTokenAddress,amountIn:n.amountIn,recipient:n.userAddress,slippageBps:String((n.slippageTolerance||1)*100),network:e.network}),i=new URL(e.apiBaseUrl);i.search=r.toString();let a=await fetch(i);if(!a.ok)throw Error(`API request failed: ${a.status} ${a.statusText}`);let o=await a.json(),s=o.clauses.map(cr),c=BigInt(o.amountOut),l=BigInt(o.amountOutMin);return{aggregatorName:e.name,aggregator:t,outputAmount:c,minimumOutputAmount:l,priceImpact:0,data:{clauses:s,path:o.path}}}catch(n){return console.error(`${e.name} getQuote failed:`,n),{aggregatorName:e.name,aggregator:t,outputAmount:0n,priceImpact:0,minimumOutputAmount:0n,data:{clauses:[],path:[]}}}},async simulateSwap(e,t,n){try{return rr(e,t,await this.buildSwapTransaction(e,t),n)}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Failed to build swap transaction for simulation`}}},async buildSwapTransaction(t,n){if(!n.data||typeof n.data!=`object`||!(`clauses`in n.data))throw Error(`Invalid quote data: clauses not found`);let r=n.data.clauses;if(r.length===0)throw Error(`No clauses found in quote`);if(e.supportedAddresses&&e.supportedAddresses.length>0){let t=e.supportedAddresses.map(e=>e.toLowerCase());if(r=r.filter(e=>e.to?t.includes(e.to.toLowerCase()):!1),r.length===0)throw Error(`No clauses found matching supported addresses`)}if(!n.minimumOutputAmount||n.minimumOutputAmount===0n)throw Error(`Invalid quote: minimumOutputAmount is missing or zero`);return r}};return t},ur={main:{supportedAddresses:[`0xE5fA980a6EfE5B79C2150a529da06AeF455963b6`,`0x7C755EC0165fCD926cC6faB10E7BB16a72E9f34A`]},test:{supportedAddresses:[]},solo:{supportedAddresses:[]}},dr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,fr=t=>new URL(`api/quote/vck`,e.O).toString(),pr=t=>{let n=ur[t]??ur.main,i=lr({name:`VeTrade.vet`,apiBaseUrl:fr(t),network:t,getIcon:(t=`20px`)=>r.default.createElement(e.t,{boxSize:t}),supportedAddresses:n.supportedAddresses});return{...i,async simulateSwap(e,t,n){try{return rr(e,t,await this.buildSwapTransaction(e,t),n)}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Simulation failed`}}},async buildSwapTransaction(e,t){let r=[],a=await i.buildSwapTransaction(e,t);if(!a||a.length===0)throw Error(`Failed to build swap transaction`);if(dr(e.fromTokenAddress))a[0].value=e.amountIn;else{if(n.supportedAddresses.length===0)throw Error(`No supported addresses configured for VeTrade on this network`);let i=s.ABIContract.ofAbi(y.IERC20__factory.abi),o=s.Address.of(e.fromTokenAddress),c=BigInt(e.amountIn);r.push(s.Clause.callFunction(o,i.getFunction(`approve`),[a[0].to,c.toString()],s.VET.of(0n,s.Units.wei),{comment:`Approve ${t.aggregatorName} to access ${e.fromTokenAddress}`}))}return r.push(...a),r}}},mr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,hr=()=>BigInt(Math.floor(Date.now()/1e3)+1200),gr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){let i=[mr(n.fromTokenAddress)?e.wrappedVET:n.fromTokenAddress,mr(n.toTokenAddress)?e.wrappedVET:n.toTokenAddress],a=BigInt(n.amountIn);try{let[o]=await r.contracts.load(e.routerAddress,y.UniswapV2Router02__factory.abi).read.getAmountsOut(a,i),s=Array.isArray(o)?o:[o],c=s[s.length-1];if(!c||c===0n)throw Error(`Output amount is zero or invalid`);if(typeof c!=`bigint`)throw Error(`Output amount is not a valid bigint`);let l=n.slippageTolerance||1,u=c*BigInt(1e4-l*100)/BigInt(1e4);return{aggregatorName:e.name,aggregator:t,outputAmount:c,priceImpact:0,minimumOutputAmount:u,data:{path:i,routerAddress:e.routerAddress}}}catch(n){return console.error(`${e.name} getQuote failed:`,n),{aggregatorName:e.name,aggregator:t,outputAmount:0n,priceImpact:0,minimumOutputAmount:0n,data:{path:i,routerAddress:e.routerAddress}}}},async simulateSwap(e,t,n){return rr(e,t,await this.buildSwapTransaction(e,t),n)},async buildSwapTransaction(t,n){if(!n.data||typeof n.data!=`object`||!(`path`in n.data))throw Error(`Invalid quote data`);let r=hr();if(!n.minimumOutputAmount||n.minimumOutputAmount===0n)throw Error(`Invalid quote: minimumOutputAmount is missing or zero`);let i=n.minimumOutputAmount,a=BigInt(t.amountIn);if(i===0n)throw Error(`Invalid quote: minimumOutputAmount is zero`);let o=mr(t.fromTokenAddress),c=mr(t.toTokenAddress),l=s.ABIContract.ofAbi(y.UniswapV2Router02__factory.abi),u=[];if(o)u.push(s.Clause.callFunction(s.Address.of(e.routerAddress),l.getFunction(`swapExactETHForTokens`),[i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(a,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`}));else{let o=s.ABIContract.ofAbi(y.IERC20__factory.abi),d=s.Address.of(t.fromTokenAddress),f=s.Address.of(e.routerAddress);u.push(s.Clause.callFunction(d,o.getFunction(`approve`),[f.toString(),a.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`})),c?u.push(s.Clause.callFunction(f,l.getFunction(`swapExactTokensForETH`),[a.toString(),i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`})):u.push(s.Clause.callFunction(f,l.getFunction(`swapExactTokensForTokens`),[a.toString(),i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`}))}return u}};return t},_r={main:{routerAddress:`0xf21Dd7108D93af56FaB07423EfB90F4a3604DA89`,wrappedVET:`0xf9b02b47694fd635A413F16dC7B38aF06Cc16fe5`},test:{routerAddress:b.zeroAddress,wrappedVET:b.zeroAddress},solo:{routerAddress:b.zeroAddress,wrappedVET:b.zeroAddress}},vr=t=>{let n=_r[t]??_r.main;return gr({name:`BetterSwap.io`,routerAddress:n.routerAddress,wrappedVET:n.wrappedVET,getIcon:(t=`20px`)=>r.default.createElement(e.n,{boxSize:t})})},yr=e=>[pr(e),vr(e)],br=(e,t,n,i,a=1,o=!0)=>{let s=(0,f.useThor)(),{connection:c}=X(),l=e?.address??null,u=t?.address??null,{data:d}=on(l===`0x`||l===b.zeroAddress||!l?``:l),{data:m}=on(u===`0x`||u===b.zeroAddress||!u?``:u),h=(0,r.useMemo)(()=>!l||l===`0x`||l===b.zeroAddress||!d?18:Number(d?.decimals??18),[l,d?.decimals]),g=(0,r.useMemo)(()=>!u||u===`0x`||u===b.zeroAddress||!m?18:Number(m?.decimals??18),[u,m?.decimals]),_=(0,r.useMemo)(()=>{if(!l||!u||!n||!i)return null;let e;try{e=(0,b.parseUnits)(n,h)}catch(e){return console.error(`Failed to parse amount:`,n,e),null}return e<=0n?null:{fromTokenAddress:l,toTokenAddress:u,amountIn:e.toString(),userAddress:i,slippageTolerance:a}},[l,u,n,i,a,h]),{data:v,isLoading:y,error:x}=(0,p.useQuery)({queryKey:[`unified-swap-quotes`,_,c.network],queryFn:async()=>{if(!_||!s||!c.network)return{quotes:[],best:null};let e=yr(c.network).map(async e=>{try{let t=await e.getQuote(_,s);try{let n=await e.simulateSwap(_,t,s);return{...t,aggregator:e,reverted:!n.success,revertReason:n.error,gasCostVTHO:n.gasCostVTHO}}catch(n){return console.error(`Failed to simulate swap for ${e.name}:`,n),{...t,aggregator:e,reverted:!0,revertReason:n instanceof Error?n.message:`Simulation failed`,gasCostVTHO:0}}}catch(t){return console.error(`Failed to get quote from ${e.name}:`,t),null}}),t=(await Promise.all(e)).filter(e=>e!==null&&e.outputAmount!==0n),n=null;if(t.length>0){let e=t.filter(e=>!(e.reverted??!1));n=(e.length>0?e:t).reduce((e,t)=>{let n=BigInt(e.outputAmount||`0`);return BigInt(t.outputAmount||`0`)>n?t:e})}return{quotes:t,best:n}},enabled:o&&_!==null&&s!=null,refetchInterval:1e4});return{bestQuote:v?.best??null,quotes:v?.quotes??[],isLoading:y,error:x,from:e?{...e,address:l??``,decimals:h}:null,to:t?{...t,address:u??``,decimals:g}:null}},xr=({email:e,onResend:t,isLoading:a,isOpen:o,onClose:s})=>{let{t:c}=(0,l.useTranslation)(),{darkMode:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[p,m]=(0,r.useState)(``),[h,_]=(0,r.useState)(null),{createWallet:v}=(0,u.useCreateWallet)(),{loginWithCode:y}=(0,u.useLoginWithEmail)({onComplete:async({isNewUser:e})=>{e&&await v()}});return(0,r.useEffect)(()=>{p.length===6&&y({code:p}).then(()=>{s()}).catch(e=>{_(e.message)})},[p]),(0,i.jsxs)(Re,{isOpen:o,onClose:s,trapFocus:!1,children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{alignItems:`center`,display:`flex`,gap:2,children:c(`Enter confirmation code`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{maxW:`container.lg`,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Icon,{as:g.LuMail,w:`48px`,h:`48px`,color:f}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:f,textAlign:`center`,children:c(`Please check {{email}} for an email from privy.io and enter your code below.`,{email:e})}),(0,i.jsx)(n.HStack,{spacing:2,justify:`center`,mt:4,children:(0,i.jsxs)(n.PinInput,{value:p,onChange:m,otp:!0,size:`lg`,isInvalid:!!h,errorBorderColor:`#ef4444`,children:[(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`})]})}),h&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`xs`,children:h})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.Text,{w:`100%`,textAlign:`center`,fontSize:`14px`,color:d?`whiteAlpha.700`:`gray.600`,children:[c(`Didn't get an email?`),` `,(0,i.jsx)(n.Button,{variant:`link`,color:`blue.500`,fontSize:`14px`,onClick:t,isLoading:a,children:c(`Resend code`)})]})})]})]})},Sr=()=>{let{t:e}=(0,l.useTranslation)(),{darkMode:t}=$(),[a,o]=(0,r.useState)(``),{sendCode:s,state:c}=(0,u.useLoginWithEmail)({}),d=(0,n.useDisclosure)(),f=async()=>{await s({email:a}),d.onOpen()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:4,w:`full`,children:(0,i.jsx)(n.VStack,{spacing:3,w:`full`,children:(0,i.jsxs)(n.InputGroup,{size:`lg`,w:`full`,children:[(0,i.jsx)(n.InputLeftElement,{pointerEvents:`none`,height:`100%`,pl:4,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:t?`whiteAlpha.600`:`blackAlpha.700`,w:`20px`,h:`20px`})}),(0,i.jsx)(n.Input,{placeholder:e(`your@email.com`),value:a,onChange:e=>o(e.target.value),fontSize:`16px`,fontWeight:`400`,backgroundColor:t?`transparent`:`#ffffff`,border:`1px solid ${t?`#ffffff0a`:`#ebebeb`}`,p:6,borderRadius:16,w:`full`,pl:12}),(0,i.jsx)(n.Button,{"aria-label":`Send code`,position:`absolute`,right:2,top:`50%`,transform:`translateY(-50%)`,zIndex:2,variant:`ghost`,size:`sm`,px:6,borderRadius:`full`,isLoading:c.status===`sending-code`,onClick:f,children:e(`Submit`)})]})})}),(0,i.jsx)(xr,{isOpen:d.isOpen,onClose:d.onClose,onResend:()=>s({email:a}),email:a,isLoading:c.status===`sending-code`})]})},Cr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Bo();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:async()=>{await a({provider:`google`})},icon:E.FcGoogle,text:r(`Continue with Google`)})})},wr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Bo();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:async()=>{await a({provider:`github`})},icon:g.LuGithub,text:r(`Continue with Github`)})})},Tr=({isDark:t,gridColumn:r})=>{let{t:a}=(0,l.useTranslation)(),{login:o}=(0,u.usePrivy)();return(0,i.jsx)(n.GridItem,{colSpan:r||4,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:o,icon:t?e.K:e.q,text:a(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(ba,{})})})},Er=({isDark:t,gridColumn:r,setCurrentContent:a})=>{let{t:o}=(0,l.useTranslation)(),{login:s}=Ho(),c=async()=>{a({type:`loading`,props:{title:o(`Connecting to VeChain`),loadingText:o(`Please approve the request in the connection request window...`),onTryAgain:c}});try{await s()}catch(e){console.error(o(`Login failed:`),e),a({type:`error`,props:{error:e instanceof Error?e.message:o(`Failed to connect with VeChain`),onTryAgain:c}})}};return(0,i.jsx)(n.GridItem,{colSpan:r||4,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:c,icon:t?e.K:e.q,text:o(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(ba,{})})})},Dr=({isDark:e,gridColumn:t,setCurrentContent:r})=>{let{t:a}=(0,l.useTranslation)(),{loginWithPasskey:o}=Ro(),s=async()=>{r({type:`loading`,props:{title:a(`Connecting with Passkey`),loadingText:a(`Please complete the passkey authentication...`),onTryAgain:s}});try{await o()}catch(e){(e instanceof Error?e.message.toLowerCase():``).includes(`not found`)&&console.error(e),r({type:`error`,props:{error:e instanceof Error?e.message:a(`Failed to connect with Passkey`),onTryAgain:s}})}};return(0,i.jsx)(n.GridItem,{colSpan:t,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:s,icon:g.LuFingerprint,text:t&&t>=2?a(`Passkey`):void 0})})},Or=({isDark:t,gridColumn:a=2})=>{let{t:o}=(0,l.useTranslation)(),{open:s,onConnectionStatusChange:c}=(0,f.useWalletModal)(),{dappKit:u}=$(),{source:d}=(0,f.useWallet)(),p=u?.allowedWallets?.includes(`sync2`)?o(`Connect wallet`):o(`Connect with VeWorld wallet`);return(0,r.useEffect)(()=>{c((e,t)=>{if(!e)return t?.message&&console.error(t?.message),{...d&&{source:d}}})},[c,d]),(0,i.jsx)(n.GridItem,{colSpan:a||2,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:()=>{s()},icon:u?.allowedWallets?.includes(`sync2`)?g.LuWallet:t?e.M:e.j,iconWidth:`27px`,text:a>=2?p:void 0,rightIcon:u?.allowedWallets?.includes(`sync2`)&&(0,i.jsx)(n.Icon,{as:g.LuArrowRight})||void 0})})},kr=({isDark:e,onViewMoreLogin:t,gridColumn:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsx)(n.GridItem,{colSpan:r,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:t,icon:g.LuEllipsis,text:r&&r>=2?a(`More`):void 0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowRight})})})},Ar=({setCurrentContent:e})=>{let{loginMethods:t,darkMode:r}=$(),{login:a}=(0,u.usePrivy)(),{showGoogleLogin:o,showEmailLogin:s,showPasskey:c,showVeChainLogin:l,showDappKit:d,showMoreLogin:f,showGithubLogin:p,isOfficialVeChainApp:m}=ko();return(0,i.jsx)(n.Stack,{spacing:4,w:`full`,align:`center`,children:(0,i.jsx)(n.Grid,{templateColumns:`repeat(4, 1fr)`,gap:2,w:`full`,children:t?.map(({method:t,gridColumn:n})=>{switch(t){case`email`:return s&&(0,i.jsx)(Sr,{},`email`);case`google`:return o&&(0,i.jsx)(Cr,{isDark:r,gridColumn:n},`google`);case`github`:return p&&(0,i.jsx)(wr,{isDark:r,gridColumn:n},`github`);case`vechain`:return l&&(m?(0,i.jsx)(Tr,{isDark:r,gridColumn:n},`vechain`):(0,i.jsx)(Er,{isDark:r,gridColumn:n,setCurrentContent:e},`vechain`));case`passkey`:return c&&(0,i.jsx)(Dr,{isDark:r,gridColumn:n,setCurrentContent:e},`passkey`);case`dappkit`:return d&&(0,i.jsx)(Or,{isDark:r,gridColumn:n},`dappkit`);case`more`:return f&&(0,i.jsx)(kr,{isDark:r,onViewMoreLogin:a,gridColumn:n},`more`);default:return null}})})})},jr=({appsInfo:e,isLoading:t,setCurrentContent:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsx)(n.Button,{fontSize:`sm`,variant:`link`,onClick:()=>r({type:`ecosystem`,props:{appsInfo:e,isLoading:t}}),children:a(`Already have an x2earn app wallet?`)})},Mr=({setCurrentContent:e,onClose:t,preventAutoClose:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{connection:s}=X(),{loginModalUI:c,darkMode:u}=$(),{loginMethods:d,privyEcosystemAppIDS:f}=$(),{data:p,isLoading:m}=Ve(f),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),g=()=>{e(`faq`)},_=d?.some(({method:e})=>e===`ecosystem`);return(0,r.useEffect)(()=>{s.isConnected&&!a&&t()},[s.isConnected,t,a]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(Ac,{onClick:g}),(0,i.jsx)(n.ModalHeader,{children:o(`Log in or sign up`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),c?.logo&&(0,i.jsx)(n.HStack,{justify:`center`,children:(0,i.jsx)(n.Image,{src:c.logo||`/images/favicon.png`,maxW:`180px`,maxH:`90px`,m:8,alt:`logo`})}),(0,i.jsxs)(n.ModalBody,{children:[c?.description&&(0,i.jsx)(n.HStack,{spacing:4,w:`full`,justify:`center`,mb:`24px`,px:4,children:(0,i.jsx)(n.Text,{color:h,fontSize:`sm`,textAlign:`center`,children:c?.description})}),(0,i.jsx)(Ar,{setCurrentContent:e})]}),_?(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(jr,{isDark:u,appsInfo:Object.values(p||{}),isLoading:m,setCurrentContent:e})})}):(0,i.jsx)(n.ModalFooter,{pt:0,pb:`5px`})]})},Nr=({setCurrentContent:e,wallet:t,onClose:r,switchFeedback:a})=>{let{t:o}=(0,l.useTranslation)(),{network:s}=$(),{isolatedView:c}=Fr();return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[!c&&(0,i.jsx)(J,{onClick:()=>{e(`profile`)}}),(0,i.jsxs)(n.ModalHeader,{children:[o(`Wallet`),s?.type!==`main`&&(0,i.jsx)(n.Tag,{size:`xs`,colorScheme:`orange`,fontSize:`2xs`,p:1,ml:1,textTransform:`uppercase`,children:`${s?.type}`})]}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,overflow:`hidden`,justifyContent:`flex-start`,spacing:8,children:[(0,i.jsx)(Bc,{showFeedback:a?.showFeedback}),(0,i.jsx)(Qr,{style:{justifyContent:`flex-start`},onClick:()=>{e(`profile`)},setCurrentContent:e,onClose:r,wallet:t}),(0,i.jsx)(ei,{onAssetsClick:()=>{e(`assets`)}}),(0,i.jsx)(ri,{setCurrentContent:e})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Pr=({onSelectToken:e,onBack:a,showAllTokens:o=!1,excludedTokenSymbols:s=t.Z})=>{let{t:c}=(0,l.useTranslation)(),{darkMode:u}=$(),{currentCurrency:d}=Xt(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{account:h}=X(),{tokensWithBalance:_,sortedTokens:v}=Zt({address:h?.address??``}),[y,b]=(0,r.useState)(``),x=(0,r.useMemo)(()=>{let e=e=>s.includes(e),t;if(o){let n=v.filter(t=>Number(t.balance)>0&&!e(t.symbol)),r=[...v.filter(t=>Number(t.balance)===0&&!e(t.symbol))].sort((e,t)=>e.symbol.localeCompare(t.symbol));t=[...n,...r]}else t=_.filter(t=>!e(t.symbol));return t},[o,v,_,s]).filter(({symbol:e})=>e.toLowerCase().includes(y.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:c(`Select Token`)}),(0,i.jsx)(J,{onClick:a}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{h:[`540px`,`auto`],p:0,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:`Search token`,bg:u?`vechain-kit-overlay`:`vechain-kit-card`,borderRadius:`xl`,height:`56px`,pl:12,value:y,onChange:e=>b(e.target.value),"data-testid":`search-token-input`}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:m})})]}),(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:f,mt:4,children:c(o?`All tokens`:`Your tokens`)}),x.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,color:m}),(0,i.jsx)(n.Text,{fontSize:`lg`,color:f,children:c(`No tokens found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:p,children:c(`Try searching with a different term`)})]}):(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:x.map(t=>(0,i.jsx)(Oc,{symbol:t.symbol,amount:Number(t.balance),currencyValue:t.valueInCurrency,currentCurrency:d,onClick:()=>e(t)},t.address))})]})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Fr=()=>{let{isolatedView:e,closeAccountModal:t}=Q();return{isolatedView:e,closeAccountModal:t}},Ir=({setCurrentContent:e,preselectedToken:a,initialAmount:s=``,initialToAddressOrDomain:c=``,onBack:u=()=>e(`main`)})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f,feeDelegation:p}=$(),{currentCurrency:m}=Xt(),h=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),y=(0,n.useToken)(`colors`,`vechain-kit-error`),b=(0,n.useToken)(`colors`,`vechain-kit-card`),{exchangeRates:x}=Wt(),{account:S}=X(),{isolatedView:C}=Fr(),{tokensWithBalance:w}=Zt({address:S?.address??``}),T=(0,r.useMemo)(()=>w.filter(e=>!t.Z.includes(e.symbol)),[w]),[E,k]=(0,r.useState)(()=>a&&!t.Z.includes(a.symbol)?a:T[0]??null),[A,j]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!E&&T.length>0&&k(T[0])},[T,E]);let{register:M,watch:N,setValue:P,setError:F,formState:{errors:I,isValid:L},handleSubmit:R}=(0,D.useForm)({defaultValues:{amount:s,toAddressOrDomain:c},mode:`onChange`}),{toAddressOrDomain:z,amount:B}=N(),ee=(0,r.useRef)(E);(0,r.useEffect)(()=>{ee.current&&E&&ee.current.address!==E.address&&P(`amount`,``),ee.current=E},[E,P]);let te=(0,r.useMemo)(()=>E?qt(Gt(Number(B)*E.priceUsd,m,x),{currency:m}):``,[B,E,m,x]),{data:V,isLoading:ne}=Ge(z),re=()=>{E&&P(`amount`,E.balance)},ie=()=>{u()},H=async t=>{if(E){if(!(V?.isValidAddressOrDomain&&(!V?.domain||V?.domain&&V?.isPrimaryDomain))){F(`toAddressOrDomain`,{type:`manual`,message:d(`Invalid address or domain`)});return}if(E){let e=(0,o.parseEther)(t.amount),n=p?.b3trTransfers?.minAmountInEther;if(E.symbol===`B3TR`&&typeof n==`number`&&n>0)try{if(e<(0,o.parseEther)(String(n))){F(`amount`,{type:`manual`,message:d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:E.symbol,min:n})});return}}catch{}if(e>(0,o.parseEther)(E.balance)){F(`amount`,{type:`manual`,message:d(`Insufficient {{symbol}} balance`,{symbol:E.symbol})});return}}e({type:`send-token-summary`,props:{toAddressOrDomain:t.toAddressOrDomain,resolvedDomain:V?.domain,resolvedAddress:V?.address,amount:t.amount,selectedToken:E,formattedTotalAmount:te,setCurrentContent:e}})}};return A?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:e=>{k(e),j(!1)},onBack:()=>{j(!1)}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Send`)}),!C&&(0,i.jsx)(J,{onClick:ie}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,position:`relative`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:h,children:d(`Amount`)}),(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:_,textDecoration:`underline`},onClick:re,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:_,children:[d(`Balance`),`:`,` `,Number(E?.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:4,borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!I.amount,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{...M(`amount`,{required:d(`Amount is required`),pattern:{value:/^\d*\.?\d*$/,message:d(`Please enter a valid number`)},validate:e=>{if(!e)return!0;let t=parseFloat(e);if(isNaN(t))return d(`Please enter a valid number`);let n=p?.b3trTransfers?.minAmountInEther;return E?.symbol===`B3TR`&&typeof n==`number`&&n>0&&t<n?d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:E.symbol,min:n}):!0}}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,P(`amount`,t,{shouldValidate:!0})},placeholder:`0`,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`tx-amount-input`,type:`number`,inputMode:`decimal`,color:h}),E?(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`},onClick:()=>j(!0),leftIcon:t.et[E.symbol]?r.default.cloneElement(t.et[E.symbol],{boxSize:`20px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[E.symbol],alt:`${E.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:h,children:E.symbol.slice(0,3)})})}),children:[E.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]}):(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`,color:v},onClick:()=>j(!0),children:[d(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]})]}),E&&(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:_,children:(0,i.jsxs)(n.Text,{color:_,children:[`≈ `,te]})}),I.amount&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,mt:1,"data-testid":`amount-error-msg`,children:I.amount.message})]})})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:2,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:h,children:d(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,p:4,width:`100%`,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!I.toAddressOrDomain,children:[(0,i.jsx)(n.Input,{...M(`toAddressOrDomain`,{required:d(`Address is required`)}),onChange:e=>{let t=e.target.value.trim(),n=t.includes(`.`)?(0,O.ens_normalize)(t):t;e.target.value=n,P(`toAddressOrDomain`,n,{shouldValidate:!0})},placeholder:d(`Type the receiver address or domain`),_placeholder:{fontSize:`md`,fontWeight:`normal`},fontSize:`lg`,fontWeight:`bold`,color:h,variant:`unstyled`,"data-testid":`tx-address-input`}),I.toAddressOrDomain&&(0,i.jsx)(n.Text,{color:y,fontSize:`sm`,"data-testid":`address-error-msg`,children:I.toAddressOrDomain.message})]})})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!E||!L,isLoading:ne,onClick:R(H),"data-testid":`send-button`,children:d(E?`Send`:`Select Token`)})})]})},Lr=({setCurrentContent:e,toAddressOrDomain:a,resolvedDomain:o,resolvedAddress:s,amount:c,selectedToken:u,formattedTotalAmount:d})=>{let{t:f}=(0,l.useTranslation)(),{account:p,connection:m,connectedWallet:h}=X(),{data:g}=kt(s??``),{network:_,feeDelegation:v}=$(),{preferences:y}=Tc(),{isolatedView:b,closeAccountModal:x}=Fr(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w}=Is(p?.address??``,h?.address??``,3),{open:T}=Ao(),E=(0,r.useMemo)(()=>g||t.U(s||a),[g,_.type,s,a]),D=async()=>{if(w){T();return}try{u.symbol===`VET`?await F():await k()}catch(e){console.error(f(`Transaction failed:`),e)}},O=r.default.useCallback(t=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:f(`Transaction successful`),onDone:()=>{b?x():e(`main`)},showSocialButtons:!0}})},[e,f,b,x]),{sendTransaction:k,txReceipt:A,error:j,isWaitingForWalletConfirmation:M,isTransactionPending:N,clauses:P}=$s({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,tokenAddress:u.address,tokenName:u.symbol,onError:e=>{H(e??``)}}),{sendTransaction:F,txReceipt:I,error:L,isWaitingForWalletConfirmation:R,isTransactionPending:z,clauses:B}=tc({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,onError:e=>{H(e??``)}}),ee=r.default.useCallback(()=>u.symbol===`VET`?I:A,[u.symbol,I,A]),te=M||R,V=te||N||z,[ne,re]=r.default.useState(!1);r.default.useEffect(()=>{let e=ee();if(!e||e.reverted||ne||V)return;let t=e.meta.txID;t&&(re(!0),O(t))},[ee,ne,V,O]),r.default.useEffect(()=>{V&&re(!1)},[V]);let ie=()=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:u,initialAmount:c,initialToAddressOrDomain:a}})},H=e=>{console.error(`Transaction failed:`,e)},[ae,U]=r.default.useState(null),[oe,W]=r.default.useState(null),se=y.availableGasTokens.length>0&&(m.isConnectedWithPrivy||m.isConnectedWithVeChain)&&!v?.delegatorUrl,{data:ce,isLoading:G,error:le,refetch:ue}=Ec({clauses:u.symbol===`VET`?B:P,tokens:ae?[ae]:y.availableGasTokens,sendingAmount:c,sendingTokenSymbol:u.symbol,enabled:se&&!!v?.genericDelegatorUrl}),de=ce?.usedToken,K=(G||!ce)&&m.isConnectedWithPrivy&&!v?.delegatorUrl,q=r.default.useCallback(e=>{U(e),W(e),setTimeout(()=>ue(),100)},[ue]),fe=!!de&&!le;return r.default.useEffect(()=>{le&&ae&&U(null)},[le,ae]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:`Send`}),(0,i.jsx)(J,{isDisabled:V,onClick:ie}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:V})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:4,w:`full`,children:[(0,i.jsxs)(n.Box,{w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,mb:2,color:C,children:f(`From`)}),(0,i.jsx)(kc,{address:p?.address??``,domain:p?.domain,imageSrc:p?.image??``,imageAlt:`From account`,balance:Number(u.balance),tokenAddress:u.address})]}),(0,i.jsxs)(n.Box,{w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,mb:2,color:C,children:f(`To`)}),(0,i.jsx)(kc,{address:s||a,domain:o,imageSrc:E??``,imageAlt:`To account`,tokenAddress:u.address})]}),m.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:ce,isLoading:G,isLoadingTransaction:V,onTokenChange:q,clauses:u.symbol===`VET`?B:P,userSelectedToken:oe}),(0,i.jsxs)(n.VStack,{spacing:0,w:`full`,justifyContent:`flex-start`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`light`,textAlign:`left`,w:`full`,color:C,children:f(`Amount`)}),(0,i.jsxs)(n.HStack,{justifyContent:`flex-start`,w:`full`,children:[(0,i.jsxs)(n.Text,{fontSize:`xl`,fontWeight:`semibold`,textAlign:`left`,"data-testid":`send-summary-amount`,color:S,children:[Number(c).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),` `,u.symbol]}),(0,i.jsxs)(n.Text,{color:C,children:[`≈ `,d]})]})]})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Nc,{transactionError:u.symbol===`VET`?L:j,isSubmitting:V,isTxWaitingConfirmation:te,onConfirm:D,transactionPendingText:f(`Sending...`),txReceipt:ee(),buttonText:f(`Confirm`),isDisabled:V||K,gasEstimationError:le,hasEnoughGasBalance:fe,isLoadingGasEstimation:G,showGasEstimationError:!v?.delegatorUrl&&m.isConnectedWithPrivy,context:`send`})})]})},Rr=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{account:r}=X(),{isolatedView:a}=Fr(),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Receive`)}),!a&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{maxW:`container.lg`,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`center`,w:`full`,children:[(0,i.jsx)(k.QRCode,{value:r?.address??``,size:200,removeQrCodeBehindLogo:!0,eyeRadius:4,logoPaddingStyle:`circle`,style:{borderRadius:`16px`}}),(0,i.jsx)(Oe,{wallet:r,style:{w:`85%`}}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:o,children:t(`Copy your address or scan this QR code`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,textAlign:`center`,color:s,children:t(`This address only supports VeChain assets.`)})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},zr=({quotes:e,selectedQuote:a,toTokenAddress:o,onSelectQuote:s,onBack:c})=>{let{t:u}=(0,l.useTranslation)(),{darkMode:d}=$(),{currentCurrency:f}=Xt(),{account:p}=X(),{exchangeRates:m,prices:h}=Wt(),{tokens:_}=Zt({address:p?.address??``}),[v,y]=(0,r.useState)(!1),x=(0,r.useMemo)(()=>o&&_.find(e=>t.k(e.address,o))||null,[o,_]),S=e.filter(e=>!e.reverted),C=e.filter(e=>e.reverted),w=(0,r.useMemo)(()=>S.length===0?null:S.reduce((e,t)=>{let n=BigInt(e.outputAmount||`0`);return BigInt(t.outputAmount||`0`)>n?t:e}),[S]),T=(0,r.useMemo)(()=>{let e=o&&h[o]||0;return S.map(t=>{let n=(0,b.formatEther)(BigInt(t.outputAmount||`0`)),r=Number(n)*e,i=Gt(r,f,m),a=w&&t.aggregatorName===w.aggregatorName,o=0;if(w&&!a){let e=BigInt(w.outputAmount||`0`),n=BigInt(t.outputAmount||`0`);o=Number(n-e)/Number(e)*100}return{...t,outputAmountFormatted:n,valueUsd:r,valueInCurrency:i,isBest:a,percentageDiff:o}}).sort((e,t)=>{let n=BigInt(e.outputAmount||`0`),r=BigInt(t.outputAmount||`0`);return Number(r-n)})},[S,o,h,f,m,w]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:u(`Found following rates`)}),(0,i.jsx)(J,{onClick:c}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{h:[`540px`,`auto`],p:0,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[T.length>0&&(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:T.map(e=>{let o=a?.aggregatorName===e.aggregatorName;return(0,i.jsxs)(n.Box,{p:2.5,borderRadius:`xl`,bg:d?`#00000038`:`gray.50`,borderWidth:1,borderColor:o?`blue.500`:d?`whiteAlpha.200`:`gray.200`,cursor:`pointer`,onClick:()=>s(e),_hover:{borderColor:o?`blue.500`:d?`whiteAlpha.400`:`gray.300`},position:`relative`,children:[(e.isBest||!e.isBest&&e.percentageDiff<0)&&(0,i.jsx)(n.Box,{position:`absolute`,top:-1,left:0,zIndex:1,children:e.isBest?(0,i.jsx)(n.Badge,{colorScheme:`purple`,borderRadius:`sm`,fontSize:`2xs`,px:1.5,py:.5,borderTopLeftRadius:`xl`,borderBottomRightRadius:`md`,children:u(`Best`)}):(0,i.jsxs)(n.Badge,{colorScheme:`red`,borderRadius:`xs`,fontSize:`2xs`,px:1.5,py:.5,borderTopLeftRadius:`xl`,borderBottomRightRadius:`md`,children:[e.percentageDiff.toFixed(2),`%`]})}),(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:1.5,marginTop:4,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,align:`center`,children:[(0,i.jsxs)(n.HStack,{spacing:1.5,align:`center`,children:[e.aggregator.getIcon(`20px`),(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,children:e.aggregatorName})]}),(0,i.jsx)(n.HStack,{align:`center`,spacing:1.5,children:x&&(0,i.jsxs)(i.Fragment,{children:[t.et[x.symbol]?r.default.cloneElement(t.et[x.symbol],{boxSize:`24px`,borderRadius:`full`}):t.$[x.symbol]?(0,i.jsx)(n.Image,{src:t.$[x.symbol],alt:`${x.symbol} logo`,boxSize:`24px`,borderRadius:`full`}):null,(0,i.jsx)(n.Tooltip,{label:Number(e.outputAmountFormatted).toLocaleString(void 0,{maximumFractionDigits:18}),hasArrow:!0,placement:`top`,children:(0,i.jsxs)(n.Text,{fontSize:`md`,fontWeight:`bold`,textAlign:`right`,whiteSpace:`nowrap`,children:[Number(e.outputAmountFormatted).toLocaleString(void 0,{minimumFractionDigits:4}),` `,x.symbol]})})]})})]}),(0,i.jsxs)(n.HStack,{justify:`space-between`,align:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.500`:`blackAlpha.500`,children:e.gasCostVTHO&&e.gasCostVTHO>0?`Gas: ${e.gasCostVTHO.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:``}),e.valueUsd>0&&(0,i.jsxs)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.600`:`blackAlpha.600`,textAlign:`right`,whiteSpace:`nowrap`,children:[`≈ `,qt(e.valueInCurrency,{currency:f})]})]})]})]},e.aggregatorName)})}),C.length>0&&(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,cursor:`pointer`,onClick:()=>y(!v),py:2,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:d?`whiteAlpha.600`:`blackAlpha.600`,children:[C.length,` `,u(`rate`),C.length===1?``:`s`,` `,u(`unavailable`)]}),(0,i.jsx)(n.Icon,{as:v?g.LuChevronUp:g.LuChevronDown,boxSize:4,color:d?`whiteAlpha.600`:`blackAlpha.600`})]}),(0,i.jsx)(n.Collapse,{in:v,animateOpacity:!0,children:(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,pt:2,children:C.map(e=>(0,i.jsx)(n.Box,{p:2,borderRadius:`xl`,bg:d?`#00000038`:`gray.50`,opacity:.6,children:(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:2,align:`center`,children:[e.aggregator.getIcon(`20px`),(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`medium`,children:e.aggregatorName})]}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.500`:`blackAlpha.500`,children:u(`Unable to fetch the price`)})]})},e.aggregatorName))})})]}),T.length===0&&C.length===0&&(0,i.jsx)(n.VStack,{spacing:2,py:8,color:d?`whiteAlpha.600`:`blackAlpha.600`,children:(0,i.jsx)(n.Text,{fontSize:`lg`,children:u(`No quotes available`)})})]})})}),(0,i.jsx)(n.ModalFooter,{})]})},Br=e=>e===`0x`||e===b.zeroAddress||!e,Vr=(e,t,n,r)=>{if(!e||!t||!n||!r)return null;let i=t.toLowerCase(),a=n.toLowerCase(),o=r.toLowerCase(),s=Br(n),c=Br(r),l=[],u=[];if(e.outputs&&Array.isArray(e.outputs))for(let t of e.outputs)t.events&&Array.isArray(t.events)&&l.push(...t.events),t.transfers&&Array.isArray(t.transfers)&&u.push(...t.transfers);let d=y.IERC20__factory.createInterface().getEvent(`Transfer`),f=d?.topicHash.toLowerCase(),p=l.filter(e=>e.topics&&e.topics.length>0&&e.topics[0]?.toString().toLowerCase()===f),m=null,h=null;if(s){for(let e of u)if(e.sender?.toLowerCase()===i&&e.amount&&e.amount!==`0x0`&&e.amount!==`0x`){let t=BigInt(e.amount);if(t>0n){m=t;break}}}if(c){for(let e of u)if(e.recipient?.toLowerCase()===i&&e.amount&&e.amount!==`0x0`&&e.amount!==`0x`){let t=BigInt(e.amount);if(t>0n){h=t;break}}}if(p.length>0)for(let e of p)try{let t=(0,b.decodeEventLog)({abi:[d],data:e.data.toString(),topics:e.topics.map(e=>e.toString())});if(!t.args||!(`from`in t.args)||!(`to`in t.args)||!(`value`in t.args))continue;let n=t.args.from?.toString().toLowerCase(),r=t.args.to?.toString().toLowerCase(),l=t.args.value,u=e.address.toLowerCase();!s&&n===i&&u&&u===a&&l>0n&&m===null&&(m=l),!c&&r===i&&u&&u===o&&l>0n&&h===null&&(h=l)}catch(e){console.warn(`Failed to decode transfer event:`,e);continue}return{fromAmount:m??0n,toAmount:h??0n}},Hr=({setCurrentContent:e,fromTokenAddress:a,toTokenAddress:o})=>{let{t:s}=(0,l.useTranslation)(),{account:c,connection:u}=X(),{currentCurrency:d}=Xt(),{network:f,feeDelegation:p,darkMode:m}=$(),{isolatedView:h,closeAccountModal:_}=Fr(),v=(0,n.useToken)(`colors`,`vechain-kit-card`),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),x=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),S=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),C=(0,n.useToken)(`colors`,`vechain-kit-button-primary-bg`),w=(0,n.useToken)(`colors`,`vechain-kit-button-primary-color`),{preferences:T}=Tc(),{sortedTokens:E}=Zt({address:c?.address??``}),[D,O]=(0,r.useState)(`main`),[k,A]=(0,r.useState)(null),[j,M]=(0,r.useState)(null),[N,P]=(0,r.useState)(``),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(1),[z,B]=(0,r.useState)(`1`),[ee,te]=(0,r.useState)(null),[V,ne]=r.default.useState(null),[re,ie]=r.default.useState(null),[H,ae]=r.default.useState([]),{prices:U,exchangeRates:oe}=Wt(),W=L===1;r.default.useEffect(()=>{B(L===1?`1`:L===.5?`0.5`:L===3?`3`:L.toString())},[L]),r.default.useEffect(()=>{if(E.length!==0){if((a||o)&&(!k||!j)){if(a&&!k){let e=E.find(e=>t.k(e.address,a));e&&!t.Z.includes(e.symbol)&&A(e)}if(o&&!j){let e=E.find(e=>t.k(e.address,o));e&&!t.Z.includes(e.symbol)&&M(e)}return}if(!k&&!j){let e=E.find(e=>e.symbol===`VET`);e&&A(e);let n=E.find(e=>e.symbol===`B3TR`);if(!n)try{let e=t.bt(f.type).b3trContractAddress;e&&(n=E.find(n=>t.k(n.address,e)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}n&&M(n)}}},[E,k,j,a,o,f.type]),r.default.useEffect(()=>{te(null)},[k?.address,j?.address,N]);let{bestQuote:se,quotes:ce,isLoading:G,from:le,to:ue}=br(k,j,N,c?.address??``,L,!!k&&!!j&&Number(N)>0),de=(0,r.useMemo)(()=>{if(!N||Number(N)<=0||!le)return 0n;try{return(0,b.parseUnits)(N,le.decimals)}catch{return 0n}},[N,le?.decimals]),K=ee||se,q=(0,r.useMemo)(()=>{if(!K?.outputAmount||!ue)return`0`;try{return(0,b.formatUnits)(K.outputAmount,ue.decimals)}catch{return`0`}},[K,ue?.decimals]),fe=(0,r.useMemo)(()=>{if(!k||!N)return 0;let e=U[k.address]||0;return Gt(Number(N)*e,d,oe)},[k?.address,N,U,d,oe]),pe=(0,r.useMemo)(()=>{if(!j||!q)return 0;let e=U[j.address]||0;return Gt(Number(q)*e,d,oe)},[j?.address,q,U,d,oe]),me=(0,r.useMemo)(()=>!k||!j||!c?.address||de===0n?null:{fromTokenAddress:k.address,toTokenAddress:j.address,amountIn:de.toString(),userAddress:c.address,slippageTolerance:L},[k,j,c?.address,de,L]),he=K?.gasCostVTHO??0;r.default.useEffect(()=>{(async()=>{if(!K||!me||!K.aggregator){ae([]);return}try{ae(await K.aggregator.buildSwapTransaction(me,K))}catch(e){console.error(`Failed to build swap clauses for gas estimation:`,e),ae([])}})()},[K,me]);let ge=T.availableGasTokens.length>0&&(u.isConnectedWithPrivy||u.isConnectedWithVeChain)&&!p?.delegatorUrl,{data:_e,isLoading:ve,error:ye,refetch:be}=Ec({clauses:H,tokens:V?[V]:T.availableGasTokens,sendingAmount:N,sendingTokenSymbol:k?.symbol??``,enabled:ge&&!!p?.genericDelegatorUrl&&H.length>0}),xe=_e?.usedToken,Se=(ve||!_e)&&u.isConnectedWithPrivy&&!p?.delegatorUrl,Ce=r.default.useCallback(e=>{ne(e),ie(e),setTimeout(()=>be(),100)},[be]),we=!!xe&&!ye;r.default.useEffect(()=>{ye&&V&&ne(null)},[ye,V]);let{executeSwap:Te,isTransactionPending:Ee,isWaitingForWalletConfirmation:De,txReceipt:Oe,status:ke,error:Ae}=er(me,K),je=(0,r.useCallback)(()=>{let t=Oe?.meta.txID??``,n=s(`Swap successful`,{defaultValue:`Swap successful`}),r;if(Oe&&k&&j&&c?.address){let e=Vr(Oe,c.address,k.address,j.address);if(e&&le&&ue)try{let t=le.decimals,n=ue.decimals,i=(0,b.formatUnits)(e.fromAmount,t),a=(0,b.formatUnits)(e.toAmount,n),o=e=>{let t=Number(e);return t>=1e3?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString(void 0,{maximumFractionDigits:6,minimumFractionDigits:0})};r=s(`You successfully swapped {fromAmount} {fromSymbol} for {toAmount} {toSymbol}`,{fromAmount:o(i),fromSymbol:k.symbol,toAmount:o(a),toSymbol:j.symbol,defaultValue:`You successfully swapped ${o(i)} ${k.symbol} for ${o(a)} ${j.symbol}`})}catch(e){console.warn(`Failed to format swap amounts:`,e)}}!r&&k&&j&&(r=s(`You successfully swapped {fromToken} for {toToken}`,{fromToken:k.symbol,toToken:j.symbol,defaultValue:`You successfully swapped ${k.symbol} for ${j.symbol}`})),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:n,description:r,onDone:()=>{h?_():e(`main`)},showSocialButtons:!0}})},[k,j,N,K,Oe,c?.address,e,s,h,_]),Me=(0,r.useCallback)(e=>{let t=typeof e==`string`?e:e.message;console.error(`Swap failed:`,t)},[k,j,N]),[Ne,Pe]=r.default.useState(!1);r.default.useEffect(()=>{if(ke===`ready`){Pe(!1);return}Ne||(ke===`success`&&Oe&&!Oe.reverted?(Pe(!0),je()):ke===`error`&&Ae?Me(Ae?.reason||Ae?.message||String(Ae)):Oe?.reverted&&Me(`Transaction reverted`))},[ke,Oe,Ae,je,Me,Ne]);let Fe=(0,r.useCallback)(e=>{if(A(e),e.symbol===`VET`&&!j){let e=E.find(e=>e.symbol===`B3TR`);if(!e)try{let n=t.bt(f.type).b3trContractAddress;n&&(e=E.find(e=>t.k(e.address,n)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}e&&M(e)}O(`main`)},[j,E,f.type]),Ie=(0,r.useCallback)(e=>{M(e),O(`main`)},[]),Le=(0,r.useCallback)(e=>{(/^\d*\.?\d*$/.test(e)||e===``)&&P(e)},[]),Re=(0,r.useCallback)(()=>{k&&P(k.balance)},[k]),ze=e=>{if(!e)return null;let n=t.et[e.symbol],r=t.$[e.symbol];return{symbol:e.symbol,logoComponent:n,logoUrl:r,balance:e.balance,value:e.valueInCurrency}},Be=ze(k),Ve=ze(j);return D===`select-from-token`?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:Fe,onBack:()=>O(`main`),showAllTokens:!1}):D===`select-quote`?(0,i.jsx)(zr,{quotes:ce,selectedQuote:K,toTokenAddress:j?.address??null,onSelectQuote:e=>{te(e),O(`main`)},onBack:()=>O(`main`)}):D===`select-to-token`?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:Ie,onBack:()=>O(`main`),showAllTokens:!0}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Swap`)}),!h&&(0,i.jsx)(J,{onClick:()=>e(`main`),isDisabled:Ee||De}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:Ee||De})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,w:`full`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:y,children:s(`From`)}),Be&&(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:x,textDecoration:`underline`},onClick:Re,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Be.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:4,borderRadius:`2xl`,bg:v,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{placeholder:`0`,value:N,onChange:e=>Le(e.target.value),fontSize:`4xl`,fontWeight:`bold`,variant:`unstyled`,"data-testid":`swap-amount-input`,type:`number`,inputMode:`decimal`,color:Be&&N&&Number(N)>Number(Be.balance)?`red.500`:y}),Be?(0,i.jsxs)(n.Button,{onClick:()=>O(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Be.logoComponent?r.default.cloneElement(Be.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Be.logoUrl?(0,i.jsx)(n.Image,{src:Be.logoUrl,alt:`${Be.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:y,children:Be.symbol.slice(0,3)})})}):void 0,children:[Be.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>O(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`,color:S},children:[s(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]})]}),(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:x,children:(0,i.jsx)(n.HStack,{spacing:2,alignItems:`center`,children:(0,i.jsxs)(n.Text,{color:x,children:[`≈`,` `,qt(fe??0,{currency:d})]})})})]})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:4,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:y,children:s(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:v,p:4,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,width:`100%`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{value:Number(q).toLocaleString(void 0,{maximumFractionDigits:Number(q)>1e4?0:2}),readOnly:!0,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`swap-output-amount`,color:y}),Ve?(0,i.jsxs)(n.Button,{onClick:()=>O(`select-to-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Ve.logoComponent?r.default.cloneElement(Ve.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Ve.logoUrl?(0,i.jsx)(n.Image,{src:Ve.logoUrl,alt:`${Ve.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:y,children:Ve.symbol.slice(0,3)})})}):void 0,children:[Ve.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>O(`select-to-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`,color:S},children:[s(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]})]}),(0,i.jsxs)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:x,children:[(0,i.jsx)(n.HStack,{spacing:2,alignItems:`center`,children:(0,i.jsxs)(n.Text,{color:x,children:[`≈`,` `,qt(pe??0,{currency:d})]})}),Ve&&(0,i.jsxs)(n.Text,{noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Ve.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]})]})}),(0,i.jsx)(n.Collapse,{in:F&&!!K,animateOpacity:!0,children:(0,i.jsxs)(n.VStack,{spacing:1,align:`stretch`,p:4,borderRadius:`2xl`,bg:v,children:[K&&(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Source`),`:`]}),(0,i.jsx)(n.Button,{variant:`outline`,size:`xs`,borderRadius:`full`,px:3,h:`auto`,py:1,cursor:`pointer`,onClick:()=>O(`select-quote`),color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:K.aggregator?.getIcon(`12px`),children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:y,children:K.aggregatorName})})]}),(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Slippage tolerance`),`:`]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,fontWeight:`medium`,color:y,children:[L,`%`]})]}),(0,i.jsx)(n.VStack,{spacing:3,align:`stretch`,pt:2,children:(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(1)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:W?C:`transparent`,color:W?w:x,borderColor:W?C:x,_hover:{bg:W?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:W?.8:1},children:`Auto`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(.5)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:L===.5?C:`transparent`,color:L===.5?w:x,borderColor:L===.5?C:x,_hover:{bg:L===.5?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:L===.5?.8:1},children:`0.5%`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(3)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:L===3?C:`transparent`,color:L===3?w:x,borderColor:L===3?C:x,_hover:{bg:L===3?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:L===3?.8:1},children:`3%`}),(0,i.jsxs)(n.InputGroup,{size:`sm`,flex:1,children:[(0,i.jsx)(n.Input,{value:z,onChange:e=>{let t=e.target.value;if(/^\d*\.?\d*$/.test(t)||t===``)if(B(t),t!==``){let e=parseFloat(t);!isNaN(e)&&e>=0&&e<=100&&R(e)}else R(1)},placeholder:`1`,borderRadius:`md`,textAlign:`right`,pr:8,fontSize:`xs`,color:y}),(0,i.jsx)(n.InputRightElement,{width:`2rem`,pointerEvents:`none`,children:(0,i.jsx)(n.Text,{fontSize:`2xs`,color:x,children:`%`})})]})]})})]}),(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Fee`),`:`]}),(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`medium`,color:y,children:he>0?`${he.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:`-`})]})]})}),K&&(0,i.jsx)(n.Box,{minH:`24px`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Button,{variant:`ghost`,size:`xs`,onClick:()=>I(!F),rightIcon:(0,i.jsx)(n.Icon,{color:S,_hover:{color:x},as:F?g.LuArrowUp:g.LuArrowDown}),fontSize:`xs`,fontWeight:`light`,color:S,_hover:{color:x},children:s(F?`Hide`:`Show Advanced Options`)})}),H.length>0&&u.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:_e,isLoading:ve,isLoadingTransaction:Ee,onTokenChange:Ce,clauses:H,userSelectedToken:re})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Nc,{buttonText:s(G?`Loading quote...`:`Swap`),onConfirm:Te,isSubmitting:Ee,isTxWaitingConfirmation:De,transactionPendingText:s(`Swapping...`),txReceipt:Oe,transactionError:Ae,onError:e=>{Me(e)},isDisabled:!k||!j||!N||Number(N)<=0||G||!K||K?.reverted===!0||!!(Be&&N&&Number(N)>Number(Be.balance))||Se,gasEstimationError:ye,hasEnoughGasBalance:we,isLoadingGasEstimation:ve,showGasEstimationError:!p?.delegatorUrl&&u.isConnectedWithPrivy,context:`transaction`})})]})},Ur=({setCurrentContent:e,onBack:t=()=>e(`settings`),initialContentSource:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{isolatedView:o}=Fr(),s=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),c=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),u=()=>{t()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Choose your account name`)}),!o&&(0,i.jsx)(J,{onClick:u}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,boxSize:16,color:c}),(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`500`,textAlign:`center`,color:s,children:a(`Finally say goodbye to 0x addresses`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:c,textAlign:`center`,px:4,children:a(`Name your account to make it easier to exchange assets`)})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:()=>e({type:`choose-name-search`,props:{name:``,setCurrentContent:e,initialContentSource:r}}),"data-testid":`choose-name-button`,children:a(`Choose name`)})})]})},Wr=({domain:e,isCurrentDomain:r,onSelect:a})=>{let{connection:o}=X(),{t:s}=(0,l.useTranslation)(),c=Mn(e.name,o.network),u=(0,n.useToken)(`colors`,`vechain-kit-card`),d=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),f=(0,n.useToken)(`colors`,`vechain-kit-border`),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`);return(0,i.jsx)(n.ListItem,{p:4,bg:u,borderRadius:`xl`,cursor:r?`default`:`pointer`,opacity:r?.7:1,border:`1px solid ${f}`,_hover:{bg:r?d:u,borderColor:f},onClick:()=>!r&&a(e.name),transition:`all 0.2s`,children:(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(Mc,{props:{width:`40px`,height:`40px`,src:c.image??t.U(e.name),alt:e.name}}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,flex:1,children:[(0,i.jsx)(n.Text,{color:p,fontSize:`md`,fontWeight:`500`,children:t.G(e.name,24,0)}),r&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:m,children:s(`Current domain`)})]}),r&&(0,i.jsx)(n.Tag,{size:`sm`,bg:h,color:p,px:3,py:1,borderRadius:`full`,children:s(`Current`)})]})},e.name)},Gr=({onUnset:e})=>{let t=(0,n.useToken)(`colors`,`vechain-kit-card`),r=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),a=(0,n.useToken)(`colors`,`vechain-kit-border`),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),c=(0,n.useToken)(`colors`,`vechain-kit-error`),{t:u}=(0,l.useTranslation)();return(0,i.jsx)(n.ListItem,{p:4,bg:t,borderRadius:`xl`,cursor:`pointer`,opacity:1,border:`1px solid ${a}`,_hover:{bg:r,borderColor:a,color:`red.400`},onClick:e,transition:`all 0.2s`,role:`button`,"aria-label":u(`Unset current domain`),children:(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Box,{width:`40px`,height:`40px`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`,bg:t,children:(0,i.jsx)(n.Icon,{as:g.LuTrash2,fontSize:`18px`,color:c})}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,flex:1,children:[(0,i.jsx)(n.Text,{color:o,fontSize:`md`,fontWeight:`500`,children:u(`Unset current domain`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:s,children:u(`Remove your current domain name`)})]})]})},`unset-domain-list-item`)},Kr=({domains:e,onDomainSelect:t,onUnsetDomain:r,isLoading:a})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),c=(0,n.useToken)(`colors`,`vechain-kit-card`),u=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return e.length===0||a?null:(0,i.jsx)(n.Accordion,{allowToggle:!0,children:(0,i.jsx)(n.AccordionItem,{border:`none`,children:({isExpanded:l})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:c,borderRadius:`xl`,_hover:{bg:u},opacity:a?.7:1,transition:`all 0.2s`,disabled:a,children:[(0,i.jsx)(n.Box,{flex:`1`,textAlign:`left`,py:2,children:(0,i.jsx)(n.Text,{fontWeight:`500`,color:d,children:a?o(`Loading your domains...`):`${o(`Your existing domains`)} (${e.length})`})}),(0,i.jsx)(n.Icon,{as:l?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,color:f})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,pt:2,children:(0,i.jsxs)(n.List,{spacing:2,children:[e.map(e=>(0,i.jsx)(Wr,{domain:e,isCurrentDomain:e.name===s?.domain,onSelect:t},e.name)),s?.domain&&(0,i.jsx)(Gr,{onUnset:r})]})})]})})})},qr=({name:e,setCurrentContent:t,initialContentSource:a=`settings`})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{darkMode:c}=$(),{isolatedView:u}=Fr(),[d,f]=(0,r.useState)((0,O.ens_normalize)(e)),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=(0,n.useToken)(`colors`,`vechain-kit-success`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w,isLoading:T}=Je(d),{data:E,isLoading:D}=Ge(`${d}.veworld.vet`),{data:k,isLoading:A}=ct(d),{data:j,isLoading:M}=pt(s?.address,``),N=T||D||A;(0,r.useEffect)(()=>{if(!y)return;let e=/[^a-zA-Z0-9-]|\s/.test(d);d.length<3?(m(o(`Name must be at least 3 characters long`)),v(!1),g(!1)):e?(m(o(`Only letters, numbers, and hyphens are allowed`)),v(!1),g(!1)):k?(m(o(`This domain is protected`)),v(!1),g(!1)):w?E?.address?.toLowerCase()===s?.address?.toLowerCase()?(m(null),v(!0),g(!0)):(m(o(`This domain is already taken`)),v(!1),g(!1)):T||(m(null),v(!0),g(!1))},[d,y,w,T,E,s?.address,k,_,N]);let P=()=>{_&&!p&&t({type:`choose-name-summary`,props:{fullDomain:d+`.veworld.vet`,isOwnDomain:h,setCurrentContent:t,initialContentSource:a}})},F=e=>{let n=e.split(`.`);t({type:`choose-name-summary`,props:{fullDomain:e,domainType:n.length>2?`${n[1]}.${n[2]}`:`vet`,isOwnDomain:!0,setCurrentContent:t,initialContentSource:a}})},I=()=>{t({type:`choose-name-summary`,props:{fullDomain:``,domainType:``,isOwnDomain:!1,isUnsetting:!0,setCurrentContent:t,initialContentSource:a}})},L=()=>{t(a)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Choose Name`)}),!u&&(0,i.jsx)(J,{onClick:L}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsx)(Kr,{domains:j?.domains||[],onDomainSelect:F,onUnsetDomain:I,isLoading:M}),(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:o(`Enter your name`),value:d,onChange:e=>{f((0,O.ens_normalize)(e.target.value)),y||b(!0)},paddingRight:`120px`,fontSize:`lg`,height:`60px`,bg:c?`#00000038`:`white`,border:`1px solid ${c?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${c?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${c?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},isInvalid:!!p,"data-testid":`domain-input`}),(0,i.jsx)(n.InputRightElement,{width:`auto`,paddingRight:`12px`,h:`full`,children:(0,i.jsx)(n.Box,{mr:4,fontSize:`sm`,color:C,children:`.veworld.vet`})})]}),p&&y&&(0,i.jsx)(n.Text,{color:x,fontSize:`sm`,"data-testid":`domain-availability-status`,children:p}),!p&&y&&d.length>=3&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:_?S:x,fontWeight:`500`,"data-testid":`domain-availability-status`,children:o(h?`YOU OWN THIS`:_?`AVAILABLE`:`UNAVAILABLE`)})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!_||!!p||k||N,isLoading:N,onClick:P,loadingText:o(`Checking...`),"data-testid":`continue-button`,children:o(`Continue`)})})]})},Jr=({setCurrentContent:e,fullDomain:t,domainType:a=`veworld.vet`,isOwnDomain:o,isUnsetting:s=!1,initialContentSource:c=`settings`})=>{let{t:u}=(0,l.useTranslation)(),d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{isolatedView:f,closeAccountModal:p}=Fr(),{account:m,connectedWallet:h,connection:_}=X(),{data:v}=Is(m?.address??``,h?.address??``,3),{open:y}=Ao(),{preferences:b}=Tc(),{feeDelegation:x}=$(),S=e=>{console.error(`Transaction failed:`,e)},C=Rt({onSuccess:()=>N()}),w=a.endsWith(`veworld.vet`),T=et({subdomain:t.split(`.veworld.vet`)[0],domain:a,alreadyOwned:o,onSuccess:()=>N()}),E=it({domain:!s&&!w?t:``,alreadyOwned:o,onSuccess:()=>N()}),{sendTransaction:D,txReceipt:O,error:k,isWaitingForWalletConfirmation:A,isTransactionPending:j,clauses:M}=s?C:w?T:E,N=()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:O?.meta.txID,title:u(s?`Domain unset`:`Domain set`),description:s?u(`Your domain has been unset successfully.`):u(`Your address has been successfully set to {{name}}`,{name:t}),onDone:()=>{f?p():e(c)}}})},P=async()=>{if(v){y();return}try{await D()}catch(e){console.error(`Transaction failed:`,e)}},F=()=>{P()},I=()=>{e({type:`choose-name-search`,props:{setCurrentContent:e,name:t,initialContentSource:c}})},[L,R]=r.default.useState(null),[z,B]=r.default.useState(null),ee=b.availableGasTokens.length>0&&(_.isConnectedWithPrivy||_.isConnectedWithVeChain)&&!x?.delegatorUrl,{data:te,isLoading:V,error:ne,refetch:re}=Ec({clauses:M(),tokens:L?[L]:b.availableGasTokens,enabled:ee&&!!x?.genericDelegatorUrl}),ie=te?.usedToken,H=(V||!te)&&_.isConnectedWithPrivy&&!x?.delegatorUrl,ae=r.default.useCallback(e=>{R(e),B(e),setTimeout(()=>re(),100)},[re]),U=!!ie&&!ne;return r.default.useEffect(()=>{ne&&L&&R(null)},[ne,L]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`confirm-domain`,children:u(s?`Confirm Unset Domain`:`Confirm Name`)}),(0,i.jsx)(J,{onClick:I,isDisabled:j}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:j})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:d,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:d,children:s?u(`By confirming, your current domain will be unset`):u(`By confirming, your address will be set to {{domain}}`,{domain:t})})]}),!s&&(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,mt:6,children:(0,i.jsx)(n.Text,{fontSize:`xl`,fontWeight:`bold`,color:d,textAlign:`center`,"data-testid":`preconfirm-domain-val`,children:t})}),_.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:te,isLoading:V,isLoadingTransaction:j,onTokenChange:ae,clauses:M(),userSelectedToken:z})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Nc,{transactionError:k,isSubmitting:j,isTxWaitingConfirmation:A,onConfirm:P,onRetry:F,transactionPendingText:u(s?`Unsetting current domain...`:`Claiming name...`),txReceipt:O,buttonText:u(`Confirm`),isDisabled:j||H,onError:S,gasEstimationError:ne,hasEnoughGasBalance:U,isLoadingGasEstimation:V,showGasEstimationError:!x?.delegatorUrl&&_.isConnectedWithPrivy,context:`domain`})})]})},Yr=()=>{let{t:e}=(0,l.useTranslation)(),[t,a]=(0,r.useState)(``),o=(0,n.useToken)(`colors`,`vechain-kit-card`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),c=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),u=(0,n.useToken)(`colors`,`vechain-kit-card`),d=(0,n.useToken)(`colors`,`vechain-kit-card-elevated`),f=[{question:e(`What is VeChain?`),answer:e(`VeChain, headquartered in San Marino, Europe, is a pioneering blockchain ecosystem and creator of VeChainThor, a world-class smart contract platform driving real-world blockchain adoption. Founded in 2015 by Sunny Lu, VeChain has consistently worked to deliver a transparent, efficient, scalable, and adaptable blockchain solution.`)},{question:e(`What is a wallet?`),answer:e(`A wallet is your gateway to the VeChain blockchain. It stores your private keys and allows you to securely manage your digital assets, send and receive tokens, and interact with decentralized applications. Think of it as your digital bank account for blockchain transactions.`)},{question:e(`What is a Smart Account?`),answer:e(`A Smart Account is a smart contract wallet that provides enhanced security and functionality. It allows for features like social recovery, transaction batching, and more.`)},{question:e(`How is my wallet secured?`),answer:e(`Your wallet security depends on how you access it. With self-custody options like the VeWorld extension, mobile app, or hardware wallet, you have complete control over your private keys. This extension itself has no access to your private keys. When logging in with social accounts or VeChain, your wallet is created and secured by Privy and managed by VeChain, providing an easier onboarding experience while maintaining security.`)},{question:e(`How do I backup my wallet?`),answer:e(`Backing up your wallet is crucial as you are the only one with access to your private keys. If something goes wrong, having your private key is the only way to recover your assets. How to backup depends on how you access your wallet: If using VeWorld, the backup option is available within the app. For social login users, you can find backup options in the Wallet section. If you're connected through VeChain or another ecosystem app, you'll need to visit the original website, log in, and access the Wallet section from there.`)},{question:e(`What is a network?`),answer:e(`A network in blockchain refers to the environment where transactions take place. VeChain has two main networks: Mainnet (the live network where real transactions occur) and Testnet (a testing environment for developers). The network you're connected to is displayed at the top of this modal.`)},{question:e(`What is a domain name?`),answer:e(`A domain name is a sort of nickname for your wallet address. It allows you to easily identify your wallet and interact with dApps using a human-readable name. For example, if your wallet address is 0x1234567890, your nickname could be "alice.vechain".`)},{question:e(`What is Privy?`),answer:e(`Privy builds user onboarding and embedded wallet infrastructure to enable better products built on crypto rails. This means embedding asset control within applications themselves to enable users, businesses or machines to use digital assets through seamless product experiences.`)},{question:e(`What is VeBetterDAO?`),answer:e(`VeBetterDAO is a decentralized organization on VeChain blockchain focused on sustainability. Members participate in the governance of the DAO using B3TR tokens for rewards and VOT3 for voting in proposals and weekly token allocation rounds.`)},{question:e(`What is an x2earn application?`),answer:e(`An X2Earn application in VeBetterDAO is a sustainable app that rewards users with B3TR tokens for eco-friendly actions. These apps must distribute B3TR, link user wallets, and provide proof of sustainable actions. They join VeBetterDAO through endorsement and participate in weekly token allocation rounds.`)},{question:e(`What is B3TR?`),answer:e(`B3TR is the incentive token of VeBetterDAO, built on VechainThor blockchain. It has a capped supply of 1 billion tokens, emitted weekly over 12 years. B3TR is used for rewards, governance, and backing VOT3 tokens 1:1. It supports sustainability applications and DAO treasury management.`)},{question:e(`What is VET?`),answer:e(`VET is the primary cryptocurrency of the VeChain network. It represents value and ownership in the VeChain ecosystem, similar to how stocks represent ownership in a company. Holding VET automatically generates VTHO, which is needed to pay for transactions on the network.`)},{question:e(`What is VTHO?`),answer:e(`VTHO (VeThor) is the energy or 'gas' token of the VeChain network. It's used to pay for transaction fees when interacting with the blockchain. VTHO is automatically generated by holding VET tokens, creating a two-token system that helps maintain network stability and manage transaction costs.`)},{question:e(`How do I send tokens?`),answer:e(`You can send tokens by clicking the send icon in the Quick Actions section. Enter the recipient's address or VeChain domain name, select the token, and specify the amount you want to send.`)},{question:e(`What is fee delegation?`),answer:e(`Fee delegation is a unique feature of VeChain that allows someone else (a delegator) to pay for your transaction fees. While many dApps and service providers act as delegators to make it easier for new users to get started, some transactions may still require you to pay fees using your own VTHO. Fees are necessary to prevent network spam and compensate the nodes that process and validate transactions on the blockchain. When paying fees yourself, you'll be able to select VTHO from your assets to cover the transaction cost.`)}].filter(e=>e.question.toLowerCase().includes(t.toLowerCase())||typeof e.answer==`string`&&e.answer.toLowerCase().includes(t.toLowerCase()));return(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:e(`Search FAQ`),bg:o,borderRadius:`xl`,height:`56px`,pl:12,value:t,onChange:e=>a(e.target.value)}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:c})})]}),f.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,color:s,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`lg`,children:e(`No questions found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,children:e(`Try searching with a different term`)})]}):(0,i.jsx)(n.Accordion,{allowMultiple:!0,children:f.map((e,t)=>(0,i.jsx)(n.AccordionItem,{border:`none`,mb:2,children:({isExpanded:t})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:u,borderRadius:`xl`,color:s,_hover:{bg:d},children:[(0,i.jsx)(n.Box,{flex:`1`,textAlign:`left`,py:2,children:(0,i.jsx)(n.Text,{fontWeight:`500`,color:s,children:e.question})}),(0,i.jsx)(n.Icon,{as:t?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,opacity:.5})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,children:(0,i.jsx)(n.Text,{fontSize:`sm`,color:s,opacity:.8,children:e.answer})})]})},t))})]})},Xr=({onGoBack:t,showLanguageSelector:r=!0})=>{let{i18n:a,t:o}=(0,l.useTranslation)(),{isolatedView:s}=Fr(),c=(0,n.useToken)(`colors`,`vechain-kit-card`),u=(0,n.useToken)(`colors`,`vechain-kit-border`),d=(0,n.useToken)(`colors`,`vechain-kit-border-hover`);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:o(`Help`)}),!s&&(0,i.jsx)(J,{onClick:t}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[r&&(0,i.jsx)(n.Select,{borderRadius:`md`,size:`sm`,width:`auto`,value:a.language,onChange:e=>{a.changeLanguage(e.target.value)},bg:c,borderColor:u,_hover:{borderColor:d},children:ie.map(e=>(0,i.jsx)(`option`,{value:e,children:ae[e]},e))}),(0,i.jsx)(n.Button,{as:n.Link,href:e.C,isExternal:!0,variant:`vechainKitSecondary`,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuExternalLink}),children:o(`For developers`)}),(0,i.jsx)(Yr,{})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Zr=({leftIcon:e,rightIcon:r,title:a,wallet:o,onClick:s,leftImage:c,isActive:u=!1})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f}=$();return(0,i.jsx)(n.Button,{w:`full`,minH:`70px`,h:`fit-content`,py:4,onClick:s,backgroundColor:`transparent`,border:`1px solid ${f?`#ffffff29`:`#ebebeb`}`,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,children:[(0,i.jsx)(n.Box,{minW:`40px`,justifyContent:`center`,children:c?(0,i.jsx)(n.Image,{justifySelf:`center`,src:c,w:`28px`,alt:`left-image`}):(0,i.jsx)(n.Icon,{as:e,fontSize:`28px`})}),(0,i.jsxs)(n.VStack,{textAlign:`left`,w:`full`,flex:1,children:[(0,i.jsx)(n.HStack,{w:`full`,spacing:2,justifyContent:`flex-start`,children:(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,children:a})}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,opacity:.5,overflowWrap:`break-word`,wordBreak:`break-word`,whiteSpace:`normal`,w:`full`,children:o?.domain?t.G(o?.domain??``,18,0):t.W(o?.address??``,6,4)})]}),(0,i.jsx)(n.VStack,{minW:`40px`,justifyContent:`flex-end`,children:(0,i.jsxs)(n.HStack,{justifyContent:`flex-end`,minW:`40px`,children:[u&&(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`green`,children:d(`Active`)}),(0,i.jsx)(n.Icon,{as:r,fontSize:`20px`,opacity:.5})]})})]})})},Z=({leftIcon:e,rightIcon:t,title:r,onClick:a,leftImage:o,hide:s=!1,showComingSoon:c=!1,backgroundColor:u,_hover:d,isDisabled:f=!1,stacked:p=!1,isLoading:m,loadingText:h,style:g,extraContent:_,dataTestId:v,variant:y=`actionButton`})=>{let{t:b}=(0,l.useTranslation)();return(0,i.jsx)(n.Button,{variant:y===`actionButton`?`vechainKitSecondary`:y,py:p?0:2,minHeight:`50px`,height:`fit-content`,p:0,onClick:a,display:s?`none`:`flex`,isDisabled:c||f,isLoading:m,loadingText:h,bgColor:u,_hover:d,"data-testid":v,...g,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Box,{minW:`40px`,h:`20px`,children:o?(0,i.jsx)(n.Image,{src:o,w:`30px`,h:`30px`,borderRadius:`full`,alt:`left-image`,alignSelf:`end`,objectFit:`cover`}):(0,i.jsx)(n.Icon,{as:e,fontSize:`20px`,h:`full`,alignContent:`center`})}),(0,i.jsx)(n.VStack,{textAlign:`left`,w:`full`,flex:1,justifyContent:`flex-start`,alignItems:`flex-start`,children:(0,i.jsxs)(n.HStack,{justify:`flex-start`,alignItems:`baseline`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,children:r}),c&&(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`red`,children:b(`Coming Soon!`)}),_]})}),t&&(0,i.jsx)(n.VStack,{minW:`40px`,justifyContent:`flex-end`,children:(0,i.jsx)(n.Icon,{as:t,fontSize:`20px`,opacity:.5})})]})})},Qr=({wallet:e,setCurrentContent:a,size:o=`md`,onClick:s,onClose:c,mt:u,style:d})=>{let{t:p}=(0,l.useTranslation)(),{connection:m}=X(),{switchWallet:h,isSwitching:_,isInAppBrowser:v}=Fn(),{isSwitchWalletEnabled:y}=(0,f.useWallet)(),[b,x]=(0,r.useState)(!1),S=async()=>{await t.lt(e?.domain??e?.address??``)&&(x(!0),setTimeout(()=>{x(!1)},2e3))},C=()=>{v?h():a?.({type:`select-wallet`,props:{setCurrentContent:a,onClose:c,returnTo:`main`,onLogoutSuccess:c}})};return(0,i.jsxs)(n.HStack,{mt:u,w:`full`,...d,justifyContent:`flex-start`,alignItems:`center`,children:[(0,i.jsx)(n.Button,{w:`full`,h:12,"aria-label":`Wallet`,onClick:s,variant:`vechainKitSecondary`,p:3,"data-testid":`profile-button`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`center`,justifyContent:`space-between`,w:`full`,children:[(0,i.jsxs)(n.HStack,{spacing:2,justifyContent:`flex-start`,children:[(0,i.jsx)(Mc,{wallet:e,props:{width:7,height:7}}),(0,i.jsx)(n.Text,{fontSize:o,fontWeight:`500`,children:b?p(`Copied!`):t.G(e?.domain??``,22,0)||t.W(e?.address??``,6,4)})]}),(0,i.jsx)(n.Icon,{boxSize:5,as:g.LuChevronRight,cursor:`pointer`,opacity:.5})]})}),m.isInAppBrowser&&y||!m.isInAppBrowser&&m.isConnectedWithDappKit?(0,i.jsx)(n.IconButton,{"aria-label":`Switch wallet`,icon:(0,i.jsx)(n.Icon,{as:g.LuArrowLeftRight}),onClick:C,w:`60px`,h:12,variant:`vechainKitSecondary`,p:3,isLoading:_,isDisabled:_,"data-testid":`switch-wallet-button`}):(0,i.jsx)(n.IconButton,{"aria-label":`Copy address`,icon:(0,i.jsx)(n.Icon,{as:b?g.LuCheck:g.LuCopy}),onClick:S,w:`60px`,h:12,variant:`vechainKitSecondary`,p:3})]})},$r=({address:e,maxIcons:a=3,iconSize:o=20,ml:s=0,style:c,iconsGap:u=0,rightIcon:d,showNoAssetsWarning:f=!1,onClick:p})=>{let{t:m}=(0,l.useTranslation)(),{tokensWithBalance:h}=Zt({address:e}),{darkMode:g}=$(),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=u<1?`-${o/2}px`:`${u}px`,y=h.slice(0,a),b=h.length-a;return!e||h.length===0&&!f?null:(0,i.jsxs)(n.HStack,{spacing:0,ml:s,...c,onClick:p,children:[(0,i.jsxs)(n.HStack,{spacing:0,children:[y.map((e,a)=>(0,i.jsx)(n.Circle,{ml:a>0?v:`0`,zIndex:a,size:`${o}px`,borderRadius:`full`,bg:g?`gray.100`:`gray.600`,border:`2px solid #00000024`,alignItems:`center`,justifyContent:`center`,children:t.et[e.symbol]?r.default.cloneElement(t.et[e.symbol],{width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):t.$[e.symbol]?(0,i.jsx)(n.Image,{src:t.$[e.symbol],alt:`${e.symbol} logo`,width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):(0,i.jsx)(n.Text,{fontSize:`${o*.4}px`,fontWeight:`bold`,color:g?`black`:`white`,children:e.symbol.slice(0,3)})},e.symbol)),b>0&&(0,i.jsx)(n.Circle,{ml:v,zIndex:y.length,size:`${o}px`,borderRadius:`full`,bg:g?`gray.100`:`gray.700`,display:`flex`,alignItems:`center`,justifyContent:`center`,border:`2px solid`,children:(0,i.jsxs)(n.Text,{fontSize:`${o*.4}px`,fontWeight:`bold`,color:g?`black`:`white`,children:[`+`,b]})}),h.length===0&&f&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:_,fontWeight:`700`,children:m(`No assets`)})]}),d]})},ei=({mb:e,mt:t,onAssetsClick:a})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{formattedBalance:c,isLoading:u}=Qt({address:s?.address??``}),{refresh:d}=Pn(),[f,p]=(0,r.useState)(!1),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=async()=>{p(!0),await d(),setTimeout(()=>{p(!1)},1500)},[_,v]=mc(pc.SHOW_ASSETS,!0);return(0,i.jsxs)(n.VStack,{w:`full`,justifyContent:`start`,spacing:1,mt:t,mb:e,children:[(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,alignItems:`center`,spacing:0,role:`group`,children:[(0,i.jsx)(n.Heading,{size:`xs`,fontWeight:`800`,color:m,textTransform:`uppercase`,letterSpacing:1.2,ml:`5px`,children:o(`Assets`)}),(0,i.jsxs)(n.HStack,{spacing:0,alignItems:`center`,children:[(0,i.jsx)(n.IconButton,{"aria-label":`Refresh balances`,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},onClick:h,icon:(0,i.jsx)(n.Icon,{as:g.LuRefreshCw,boxSize:4}),isLoading:u||f,sx:{"& > span.chakra-button__spinner":{width:`16px`,height:`16px`,position:`absolute`}}}),(0,i.jsx)(n.IconButton,{"aria-label":`Show/hide assets`,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},onClick:()=>v(!_),icon:(0,i.jsx)(n.Icon,{as:_?A.GoEye:A.GoEyeClosed,boxSize:4})})]})]}),(0,i.jsx)(n.Button,{onClick:a,h:`fit-content`,variant:`vechainKitSecondary`,children:(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,justifyContent:`flex-start`,alignItems:`flex-start`,mt:4,mb:4,children:[(0,i.jsx)(n.Heading,{size:`2xl`,fontWeight:`700`,children:_?c:`$****`}),(0,i.jsx)(n.HStack,{w:`full`,justifyContent:`flex-start`,"data-testid":`all-assets-button`,mt:2,children:(0,i.jsx)($r,{style:{width:`100%`,justifyContent:`space-between`},maxIcons:10,iconSize:26,iconsGap:3,address:s?.address??``,showNoAssetsWarning:!0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuChevronRight,boxSize:5,opacity:.5,marginLeft:2})})})]})})]})},ti=[{icon:g.LuArrowUpFromLine,label:`Send`,onClick:e=>e({type:`send-token`,props:{setCurrentContent:e}}),isDisabled:e=>!e},{icon:g.LuArrowLeftRight,label:`Swap`,onClick:e=>{e(`swap-token`)},isDisabled:e=>!e},{icon:g.LuArrowDownToLine,label:`Receive`,onClick:e=>{e(`receive-token`)}}],ni=({icon:e,label:t,onClick:r,isDisabled:a,showRedDot:o})=>{let{t:s}=(0,l.useTranslation)();return(0,i.jsx)(n.IconButton,{variant:`vechainKitSecondary`,h:`80px`,w:`full`,"aria-label":t,isDisabled:a,p:3,icon:(0,i.jsxs)(n.VStack,{spacing:4,children:[(0,i.jsx)(n.Icon,{as:e,boxSize:5,opacity:.9}),(0,i.jsxs)(n.HStack,{p:0,alignItems:`baseline`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`600`,"data-testid":`${t.toLowerCase()}-button-label`,children:s(t,t)}),o&&(0,i.jsx)(n.Box,{minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`})]})]}),onClick:r})},ri=({mt:e,setCurrentContent:t})=>{let{account:r,smartAccount:a,connectedWallet:o,connection:s}=X(),{hasAnyBalance:c}=Qt({address:r?.address??``}),{data:l}=Is(a?.address??``,o?.address??``,3),u=s.isConnectedWithPrivy&&l;return(0,i.jsx)(n.Grid,{templateColumns:`repeat(3, 1fr)`,gap:2,w:`full`,mt:e,children:ti.map(e=>(0,i.jsx)(ni,{icon:e.icon,label:e.label,onClick:()=>e.onClick(t),isDisabled:e.isDisabled?.(c),showRedDot:u&&e.label===`Settings`},e.label))})},ii=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),r=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsx)(n.Card,{w:`full`,variant:`featureAnnouncement`,overflow:`hidden`,onClick:()=>{e({type:`choose-name`,props:{setCurrentContent:e,onBack:()=>e(`profile`),initialContentSource:`profile`}})},cursor:`pointer`,_hover:{opacity:.8},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsx)(n.HStack,{justify:`space-between`,align:`flex-start`,spacing:3,children:(0,i.jsxs)(n.VStack,{align:`flex-start`,spacing:1,children:[(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,color:r,children:t(`Claim your vet domain!`)}),(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`red`,children:t(`New`)})]}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:a,children:t(`Say goodbye to 0x addresses, claim your .veworld.vet subdomain now for free!`)})]})})})})},ai=()=>{let{t:e}=(0,l.useTranslation)();return(0,i.jsx)(n.Alert,{status:`warning`,fontSize:`xs`,borderRadius:`xl`,p:2,children:(0,i.jsx)(n.VStack,{spacing:1,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`flex-start`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:4,mt:`10px`}),(0,i.jsx)(n.Text,{w:`full`,children:e(`Sending to OceanX or other exchanges may result in loss of funds.`)})]})})})},oi=()=>{let{t:e}=(0,l.useTranslation)();return(0,i.jsx)(n.Alert,{status:`warning`,fontSize:`xs`,borderRadius:`xl`,p:2,children:(0,i.jsx)(n.VStack,{spacing:1,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`flex-start`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:4,mt:`10px`}),(0,i.jsx)(n.Text,{w:`full`,children:e(`A .vet domain is required to customize your profile. Choose an account name to get started.`)})]})})})},si=()=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Vo(),a=r();return(0,i.jsxs)(n.Card,{variant:`vechainKitBase`,w:`full`,children:[(0,i.jsxs)(n.CardHeader,{p:4,pl:6,borderBottomWidth:`1px`,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,opacity:.8,children:t(`Security preferences`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,mt:1,opacity:.7,children:t(`For security reasons, you can manage your embedded wallet settings only on the {{appName}} platform.`,{appName:a?.ecosystemApp.name??`origin app`})})]}),(0,i.jsx)(n.CardBody,{borderRadius:`none`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`stretch`,children:[(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Center,{w:`fit-content`,h:`fit-content`,p:2,borderRadius:`full`,bg:`blackAlpha.100`,flexShrink:0,children:(0,i.jsx)(n.Icon,{as:g.LuUserCog})}),(0,i.jsxs)(n.Box,{flex:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`shorter`,children:t(`Login methods`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:t(`Manage your login methods and passkeys`)})]})]}),(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Center,{w:`fit-content`,h:`fit-content`,p:2,borderRadius:`full`,bg:`blackAlpha.100`,flexShrink:0,children:(0,i.jsx)(n.Icon,{as:g.LuShieldCheck})}),(0,i.jsxs)(n.Box,{flex:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`shorter`,children:t(`Security settings`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:t(`Backup your wallet, configure MFA and set recovery options`)})]})]})]})}),(0,i.jsx)(n.CardFooter,{children:(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,w:`full`,onClick:()=>{window.open(a?.ecosystemApp.website??e.y,`_blank`)},children:[t(`Manage on {{appName}}`,{appName:a?.ecosystemApp.name??`origin app`}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},ci=({setCurrentContent:e,initialContentSource:a=`profile`})=>{let{t:o}=(0,l.useTranslation)(),{network:s}=$(),{account:c}=X(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-error`),f=(0,n.useToken)(`colors`,`vechain-kit-card`),p=(0,r.useRef)(null),m=(0,r.useRef)(null),[h,_]=(0,r.useState)(!1),{onUpload:v}=Zn({compressImage:!0}),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(null),C=!!c?.domain,[w,T]=(0,r.useState)(null),[E,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(``),{register:j,watch:M,formState:{errors:N,isValid:P}}=(0,D.useForm)({defaultValues:{displayName:c?.metadata?.display||``,description:c?.metadata?.description||``},mode:`onChange`});(0,r.useEffect)(()=>{if(c?.metadata){let e=c.metadata;O(e.display||``),A(e.description||``),T(c.image?c.image.replace(`ipfs://`,``):null),b(e=>e??c.image??null)}},[c,s.type]);let F=M(),I=async e=>{let n=e.target.files?.[0];if(n)try{_(!0),y&&URL.revokeObjectURL(y),b(URL.createObjectURL(n));let e=await v(n);if(!e)throw Error(`Failed to compress image`);S(await t.D(e.file,n.name,s.type))}catch(e){console.error(`Error uploading image:`,e),b(null)}finally{_(!1)}};(0,r.useEffect)(()=>()=>{y&&URL.revokeObjectURL(y)},[y]);let L=()=>{let e={};return x!==w&&x&&(e.avatarIpfsHash=x),F.displayName!==E&&(e.displayName=F.displayName),F.description!==k&&(e.description=F.description),e},R=(0,r.useMemo)(()=>{let e=L();return Object.keys(e).length>0},[L]),z=()=>{e({type:`account-customization-summary`,props:{setCurrentContent:e,changes:L(),onDoneRedirectContent:a}})},B=()=>{e(a)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Customization`)}),(0,i.jsx)(J,{onClick:B}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.Box,{cursor:C?`pointer`:`default`,pt:2,display:`flex`,justifyContent:`center`,position:`relative`,onClick:()=>C&&p.current?.click(),children:[(0,i.jsx)(Mc,{wallet:c,props:{width:`100px`,height:`100px`,boxShadow:`0px 0px 3px 2px #00000024`,src:y??void 0}}),C&&(0,i.jsx)(n.Icon,{as:g.LuCamera,position:`absolute`,top:`80px`,left:`60%`,bg:f,color:u,p:`1`,borderRadius:`full`,boxSize:`6`}),h&&(0,i.jsx)(n.Box,{display:`flex`,alignItems:`center`,justifyContent:`center`,backgroundColor:`rgba(0, 0, 0, 0.5)`,position:`absolute`,transform:`translateX(0%)`,width:`100px`,height:`100px`,borderRadius:`full`,zIndex:10,children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:`white`,children:h?`Uploading...`:`Processing...`})})]}),(0,i.jsxs)(n.VStack,{spacing:6,mt:4,children:[!C&&(0,i.jsx)(oi,{}),(0,i.jsx)(Z,{title:c?.domain??o(`Choose account name`),description:o(`Choose a unique .vet domain name for your account.`),onClick:()=>{c?.domain?e({type:`choose-name-search`,props:{name:``,setCurrentContent:e,initialContentSource:{type:`account-customization`,props:{setCurrentContent:e}}}}):e({type:`choose-name`,props:{setCurrentContent:e,initialContentSource:{type:`account-customization`,props:{setCurrentContent:e}},onBack:()=>e({type:`account-customization`,props:{setCurrentContent:e}})}})},leftIcon:g.LuSquareUser,rightIcon:g.LuChevronRight,dataTestId:`set-domain-name-button`}),(0,i.jsxs)(n.FormControl,{isDisabled:!C,isInvalid:!!N.displayName,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:u,children:o(`Display Name`)}),(0,i.jsx)(n.Input,{...j(`displayName`,{maxLength:{value:25,message:o(`Display name must be less than 25 characters`)}}),placeholder:o(C?`Enter your display name`:`Set a domain first`),fontWeight:`medium`,color:u,"data-testid":`display-name-input`}),N.displayName&&(0,i.jsx)(n.Text,{color:d,fontSize:`sm`,mt:1,fontWeight:`medium`,children:N.displayName.message})]}),(0,i.jsxs)(n.FormControl,{isDisabled:!C,isInvalid:!!N.description,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:u,children:o(`Description`)}),(0,i.jsx)(n.Textarea,{...j(`description`,{maxLength:{value:100,message:o(`Description must be less than 100 characters`)}}),placeholder:o(`Eg: DevRel @ ENS Labs`),fontWeight:`medium`,color:u,"data-testid":`description-input`,minH:`50px`}),N.description&&(0,i.jsx)(n.Text,{color:d,mt:1,fontSize:`sm`,fontWeight:`medium`,children:N.description.message})]})]}),(0,i.jsx)(`input`,{type:`file`,ref:p,hidden:!0,accept:`image/*`,onChange:async e=>await I(e)}),(0,i.jsx)(`input`,{type:`file`,ref:m,hidden:!0,accept:`image/*`,onChange:async e=>{e.preventDefault()}})]}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:z,isDisabled:!C||!R||!P,isLoading:h,loadingText:o(`Preparing changes...`),"data-testid":`save-changes-button`,children:o(`Save Changes`)})})]})},li=({setCurrentContent:e,changes:a,onDoneRedirectContent:o})=>{let{t:s}=(0,l.useTranslation)(),{darkMode:c,network:u,feeDelegation:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{account:m,connectedWallet:h,connection:_}=X(),{preferences:v}=Tc(),{data:y}=Is(m?.address??``,h?.address??``,3),{open:b}=Ao(),{handleSubmit:x}=(0,D.useForm)({defaultValues:{...a,avatarIpfsHash:a.avatarIpfsHash??void 0}}),S=m?.domain??``,{data:C}=wt(S),w=(0,p.useQueryClient)(),{sendTransaction:T,txReceipt:E,error:O,isWaitingForWalletConfirmation:k,isTransactionPending:A,clauses:j}=St({resolverAddress:C,signerAccountAddress:m?.address??``,onSuccess:async()=>{try{await ce()}catch(e){console.error(`Error refreshing data:`,e)}},onError:e=>{console.error(`Error updating text record:`,e)}}),[M,N]=r.default.useState(!1);r.default.useEffect(()=>{if(!E||E.reverted||M||A)return;let t=E.meta.txID;t&&(N(!0),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:s(`Profile Updated`),description:s(`Your changes have been saved successfully.`),onDone:()=>{e(o)}}}))},[E,M,A,e,s,o]),r.default.useEffect(()=>{A&&N(!1)},[A]);let P=(0,r.useMemo)(()=>{let e=m?.domain??``,t={displayName:`display`,description:`description`,twitter:`com.x`,website:`url`,email:`email`,avatarIpfsHash:`avatar`};return Object.entries(a).filter(e=>e[1]!==void 0&&e[1]!==null).map(([n,r])=>({domain:e,key:t[n],value:n===`avatarIpfsHash`?`ipfs://${r}`:r}))},[a,m?.domain]),F=(0,r.useMemo)(()=>{try{return!C||P.length===0||!j?[]:j(P)}catch(e){return console.error(`Error building clauses:`,e),[]}},[P,j,C]),[I,L]=r.default.useState(null),[R,z]=r.default.useState(null),B=v.availableGasTokens.length>0&&(_.isConnectedWithPrivy||_.isConnectedWithVeChain)&&!d?.delegatorUrl,{data:ee,isLoading:te,error:V,refetch:ne}=Ec({clauses:F,tokens:I?[I]:v.availableGasTokens,enabled:B&&!!d?.genericDelegatorUrl}),re=ee?.usedToken,ie=(te||!ee)&&_.isConnectedWithPrivy&&!d?.delegatorUrl,H=r.default.useCallback(e=>{L(e),z(e),setTimeout(()=>ne(),100)},[ne]),ae=!!re&&!V;r.default.useEffect(()=>{V&&I&&L(null)},[V,I]);let U=async()=>{if(y){b();return}try{P.length>0&&await T(P)}catch(e){console.error(`Error saving changes:`,e)}},oe=(e,t)=>t?.trim()?(0,i.jsxs)(n.VStack,{align:`flex-start`,w:`full`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:c?`whiteAlpha.600`:`blackAlpha.600`,children:e}),(0,i.jsx)(n.Text,{fontSize:`md`,children:t})]}):null,W=()=>{x(U)()},se=()=>{e({type:`account-customization`,props:{setCurrentContent:e}})},ce=async()=>{a.avatarIpfsHash&&(w.setQueryData(mt(S,u.type),t.g(`ipfs://`+a.avatarIpfsHash,u.type)),w.setQueryData(Ot(m?.address??``),t.g(`ipfs://`+a.avatarIpfsHash,u.type))),await w.invalidateQueries({queryKey:vt(S,u.type)}),await w.refetchQueries({queryKey:vt(S,u.type)})};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Confirm Changes`)}),(0,i.jsx)(J,{isDisabled:A,onClick:se}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:A})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuFileText,color:f,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:f,children:s(`By confirming, the following details attached to your name ({{domain}}) will be updated`,{domain:S})})]}),(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,mt:6,children:[a.avatarIpfsHash&&(0,i.jsxs)(n.VStack,{align:`flex-start`,w:`full`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:c?`whiteAlpha.600`:`blackAlpha.600`,children:s(`Profile Image`)}),(0,i.jsx)(n.Text,{fontSize:`md`,children:s(`New image selected`)})]}),a.displayName&&oe(s(`Display Name`),a.displayName),a.description&&oe(s(`Description`),a.description),a.twitter&&oe(s(`Twitter`),a.twitter),a.website&&oe(s(`Website`),a.website),a.email&&oe(s(`Email`),a.email)]}),_.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:ee,isLoading:te,isLoadingTransaction:A,onTokenChange:H,clauses:F,userSelectedToken:R})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Nc,{transactionError:O,isSubmitting:A,isTxWaitingConfirmation:k,onConfirm:x(U),onRetry:W,transactionPendingText:s(`Saving changes...`),txReceipt:E,buttonText:s(`Confirm`),isDisabled:A||ie,gasEstimationError:V,hasEnoughGasBalance:ae,isLoadingGasEstimation:te,showGasEstimationError:!d?.delegatorUrl&&_.isConnectedWithPrivy,context:`customization`})})]})},ui=({address:e,showHeader:r=!0,showLinks:a=!0,showDescription:o=!0,showDisplayName:s=!0,reserveNameDescriptionSpace:c=!1,setCurrentContent:l,onLogout:u})=>{let{network:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-card`),h=Mn(e,d.type),_=t.U(e),v=h?.records?.url||h?.records?.[`com.x`]||h?.records?.email,y=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`?t.toString():null}catch{return null}};return(0,i.jsxs)(n.VStack,{spacing:0,w:`full`,children:[(0,i.jsx)(n.Box,{p:0,backgroundSize:`100% !important`,backgroundPosition:`center`,position:`relative`,background:r?`no-repeat url('${_}')`:`none`,w:`100%`,borderRadius:`14px 14px 0 0`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,cursor:l?`pointer`:`default`,onClick:l?()=>{l({type:`account-customization`,props:{setCurrentContent:l,initialContentSource:`profile`}})}:void 0,children:[(0,i.jsx)(Mc,{wallet:{address:e,domain:h?.domain,image:h?.image,isLoadingMetadata:h?.isLoading,metadata:h?.records},props:{width:`120px`,height:`120px`}}),l&&(0,i.jsx)(n.Icon,{as:g.LuPencil,position:`absolute`,bottom:`0`,right:`0`,bg:m,color:f,p:`1`,borderRadius:`full`,boxSize:`6`,border:`2px solid`,borderColor:m})]}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[s&&(h?.records?.display?(0,i.jsx)(n.Text,{fontSize:`xl`,color:f,fontWeight:`bold`,w:`full`,textAlign:`center`,mt:2,"data-testid":`display-name-val`,children:h?.records?.display}):c&&(0,i.jsx)(n.Box,{mt:2,minH:`28px`,"aria-hidden":!0})),o&&(h?.records?.description?(0,i.jsx)(n.Text,{fontSize:`sm`,color:p,w:`full`,textAlign:`center`,"data-testid":`description-val`,children:h?.records?.description}):c&&(0,i.jsx)(n.Box,{minH:`20px`,"aria-hidden":!0})),a&&v&&(0,i.jsxs)(n.HStack,{w:`full`,justify:`center`,spacing:5,mt:4,children:[h?.records?.email&&(0,i.jsx)(n.Link,{href:`mailto:${h?.records?.email}`,target:`_blank`,"data-testid":`mail-link`,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:f})}),h?.records?.url&&(0,i.jsx)(n.Link,{href:y(h.records.url)??void 0,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`website-link`,children:(0,i.jsx)(n.Icon,{as:g.LuGlobe,color:f})}),h?.records?.[`com.x`]&&(0,i.jsx)(n.Link,{href:`https://x.com/${encodeURIComponent(String(h.records[`com.x`]))}`,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`twitter-link`,children:(0,i.jsx)(n.Icon,{as:j.FaXTwitter,color:f})})]}),(0,i.jsx)(Oe,{onLogout:u,wallet:{address:e,domain:h?.domain,image:h?.image,isLoadingMetadata:h?.isLoading,metadata:h?.records},style:{mt:4},setCurrentContent:l})]})]})},di=({onClick:e,...t})=>{let{smartAccount:a,connectedWallet:o,connection:s}=X(),[c,l]=(0,r.useState)(!1);(0,r.useEffect)(()=>{l(!localStorage.getItem(`app-first-visit`))},[]);let{data:u}=Is(a?.address??``,o?.address??``,3),d=s.isConnectedWithPrivy&&u,f=()=>{c&&(localStorage.setItem(`app-first-visit`,`true`),l(!1)),e()};return(0,i.jsx)(n.IconButton,{"aria-label":`Settings`,size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,lineHeight:`0`,onClick:f,icon:(0,i.jsxs)(n.Box,{position:`relative`,children:[(0,i.jsx)(n.Icon,{as:g.LuSettings2,fontSize:`18px`}),d&&(0,i.jsx)(n.Box,{position:`absolute`,top:`-1px`,right:`-1px`,minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`})]}),...t})},fi=({setCurrentContent:e,onLogoutSuccess:t,switchFeedback:r})=>{let{t:a}=(0,l.useTranslation)(),{account:o,disconnect:s,connection:c}=X(),{switchWallet:u,isSwitching:d,isInAppBrowser:p}=Fn(),{isSwitchWalletEnabled:m}=(0,f.useWallet)(),{hasAnyBalance:h,formattedBalance:_}=Qt({address:o?.address}),[v]=mc(pc.SHOW_ASSETS,!0),y=()=>{p?u():e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:`profile`,onLogoutSuccess:t}})};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Profile`)}),(0,i.jsx)(di,{onClick:()=>{e(`settings`)},"data-testid":`settings-button`}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:6,children:[(0,i.jsx)(Bc,{showFeedback:r?.showFeedback}),!o?.domain&&(0,i.jsx)(ii,{setCurrentContent:e}),(0,i.jsx)(ui,{reserveNameDescriptionSpace:!!o?.domain,onEditClick:()=>{e({type:`account-customization`,props:{setCurrentContent:e,initialContentSource:`profile`}})},address:o?.address??``,showHeader:!1,setCurrentContent:e,onLogout:()=>{s(),t?.()}})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,spacing:4,mt:4,children:[(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:h?void 0:(0,i.jsx)(n.Icon,{as:g.LuWalletCards}),onClick:()=>e(`main`),"data-testid":`wallet-button`,children:h?(0,i.jsxs)(n.HStack,{spacing:2,w:`full`,justify:`center`,children:[(0,i.jsx)($r,{address:o?.address??``,maxIcons:2}),(0,i.jsx)(n.Text,{fontWeight:`600`,children:v?_:`$****`})]}):a(`Wallet`)}),c.isInAppBrowser&&m||!c.isInAppBrowser&&c.isConnectedWithDappKit?(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowLeftRight}),colorScheme:`red`,onClick:async()=>{y()},isLoading:d,isDisabled:d,"data-testid":`switch-wallet-button`,children:a(`Switch`)}):(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuLogOut}),colorScheme:`red`,onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:()=>{s(),t?.()},onBack:()=>e?.(`profile`)}}),"data-testid":`logout-button`,children:a(`Logout`)})]})})]})},pi=({setCurrentContent:e,handleClose:t,initialContent:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=Is(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Vs({smartAccountAddress:o?.address??``,targetVersion:3,onSuccess:()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:m?.meta.txID,title:a(`Upgrade Successful!`),description:a(`Your account has been successfully upgraded to the latest version. You can now enjoy a better user experience, lower gas costs, and enhanced security.`),onDone:()=>{t?t():e(r)},showSocialButtons:!1}})},onError:()=>{console.error(`Error upgrading Smart Account`)}});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(J,{onClick:()=>{e(r)}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:10,align:`stretch`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a(c?`Your smart account needs to be upgraded to the latest version (v3).`:`Your smart account is already upgraded to this version.`)}),(0,i.jsxs)(n.HStack,{align:`center`,justifyContent:`space-evenly`,rounded:`md`,children:[(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{borderRadius:`full`,src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#D23F63`,fontSize:`28px`,children:`v1`})]}),(0,i.jsx)(n.Icon,{as:g.LuArrowRight,color:`#3DBA67`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{borderRadius:`full`,src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#3DBA67`,fontSize:`28px`,children:`v3`})]})]}),(0,i.jsxs)(n.Alert,{status:`info`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,children:a(`Benefits of this upgrade:`)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,children:(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,mt:1,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,lineHeight:`1.2`,children:[`• `,a(`Improved security features`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`• `,a(`Better transaction handling`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Enhanced compatibility with dApps`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Reduced gas costs for operations`)]})]})})]})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(Nc,{buttonText:a(c?`Upgrade account`:`Account already upgraded`),onConfirm:async()=>{try{await u()}catch(e){console.error(`Failed to upgrade Smart Account:`,e)}},isTxWaitingConfirmation:f,isSubmitting:d,transactionPendingText:a(`Upgrading...`),txReceipt:m,transactionError:p,isDisabled:!c}),(0,i.jsx)(n.Button,{mt:2,variant:`link`,onClick:()=>{t?t():e(r)},isDisabled:d,children:a(c?`Close and do this later`:`Close`)})]})})]})},mi=({setCurrentContent:e})=>{let{account:a}=X(),{sortedTokens:o}=Zt({address:a?.address}),{allowCustomTokens:s,darkMode:c}=$(),{currentCurrency:u}=Xt(),d=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{t:f}=(0,l.useTranslation)(),{isolatedView:p}=Fr(),[m,h]=(0,r.useState)(``),_=t=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:t,onBack:()=>e(`assets`)}})},v=o.filter(({symbol:e})=>e.toLowerCase().includes(m.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:f(`Assets`)}),!p&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{h:[`540px`,`auto`],p:0,children:[(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:`Search token`,bg:c?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12,value:m,onChange:e=>h(e.target.value),"data-testid":`search-token-input`}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:d})})]}),(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,mt:2,children:v.map(e=>{let n=Number(e.balance)>0,r=t.Z.includes(e.symbol);return(0,i.jsx)(Oc,{symbol:e.symbol,amount:Number(e.balance),currencyValue:e.valueInCurrency,currentCurrency:u,onClick:()=>_(e),isDisabled:!n||r},e.address)})})]}),(0,i.jsx)(n.ModalFooter,{children:s&&(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPencil,boxSize:4}),onClick:()=>e(`add-custom-token`),children:f(`Manage Custom Tokens`)})})]})]})},hi=({setCurrentContent:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),o=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),s=(0,n.useToken)(`colors`,`vechain-kit-card`),c=(0,n.useToken)(`colors`,`vechain-kit-overlay`),{addToken:u,removeToken:d,isTokenIncluded:f,isDefaultToken:p,customTokens:m}=sn(),{register:h,setError:_,setValue:v,formState:{errors:y,isValid:b},handleSubmit:x}=(0,D.useForm)({defaultValues:{newTokenAddress:``},mode:`onChange`}),S=async e=>{if(e.newTokenAddress){if(f(e.newTokenAddress)||p(e.newTokenAddress))return _(`newTokenAddress`,{type:`manual`,message:r(`Token already added`)});try{await u(e.newTokenAddress),v(`newTokenAddress`,``)}catch(e){console.error(`Error adding token 2:`,e),_(`newTokenAddress`,{type:`manual`,message:r(`Invalid token address`)})}}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Manage Custom Tokens`)}),(0,i.jsx)(J,{onClick:()=>e(`assets`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,position:`relative`,children:[(0,i.jsx)(n.Box,{p:6,borderRadius:`xl`,bg:s,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!y.newTokenAddress,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:a,children:r(`Token Contract Address`)}),(0,i.jsx)(n.Input,{...h(`newTokenAddress`,{required:r(`Address is required`),pattern:{value:/^0x[a-fA-F0-9]{40}$/,message:r(`Please enter a valid contract address`)},validate:e=>/^0x[a-fA-F0-9]{40}$/.test(e)||r(`Invalid contract address`)}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,v(`newTokenAddress`,t,{shouldValidate:!0})},placeholder:`0x...`,variant:`outline`,fontSize:`md`,fontWeight:`medium`}),y.newTokenAddress&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,children:y.newTokenAddress.message})]})})}),m.length>0&&(0,i.jsxs)(n.Box,{p:4,borderRadius:`xl`,bg:c,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,mb:2,children:r(`Existing Custom Tokens`)}),(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:m.map(e=>(0,i.jsxs)(n.HStack,{justify:`space-between`,fontSize:`sm`,p:2,borderRadius:`md`,bg:s,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:t.$[e?.symbol],alt:`${e.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:a,children:e.symbol?.slice(0,3)})})}),(0,i.jsx)(n.Text,{fontWeight:`medium`,color:a,children:e.symbol??`Unknown`})]}),(0,i.jsx)(n.Text,{color:o,children:t.W(e.address??``,4,4)}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,color:a,borderRadius:`md`,p:2,onClick:()=>d(e.address),children:(0,i.jsx)(g.LuTrash2,{size:16,color:a})})]},e.address))})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!b,onClick:x(S),children:r(`Add Token`)})})]})},gi=({setCurrentContent:t})=>{let{t:r}=(0,l.useTranslation)(),{darkMode:a}=$(),{isolatedView:o}=Fr();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Bridge`)}),!o&&(0,i.jsx)(J,{onClick:()=>t(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{maxW:`container.lg`,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,w:`full`,children:[(0,i.jsx)(e.r,{isDark:a,borderRadius:`xl`}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:r(`Exchange your digital assets between VeChain and other blockchain networks easily and securely. Swaps are executed through partners that leverage both decentralized and centralized exchanges to convert tokens.`)})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,onClick:()=>{window.open(e.x,`_blank`)},children:[r(`Launch vechain.energy`),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},_i=({setCurrentContent:e})=>{let{t:a}=(0,l.useTranslation)(),{currentCurrency:o,changeCurrency:s,allCurrencies:c}=Xt(),u=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`);(0,r.useEffect)(()=>{t.yt(`settings-currency-visited`,`true`)},[]);let d=e=>{let r=o===e;return(0,i.jsxs)(n.Button,{w:`full`,variant:`ghost`,justifyContent:`space-between`,onClick:()=>s(e),py:6,px:4,bg:r?u:void 0,children:[(0,i.jsxs)(n.HStack,{spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`xl`,children:t.C[e]}),(0,i.jsx)(n.Text,{children:e.toUpperCase()})]}),r&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select currency`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{justify:`center`,spacing:3,align:`flex-start`,w:`full`,children:c.map(e=>d(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},vi=({setCurrentContent:e})=>{let{t,i18n:r}=(0,l.useTranslation)(),a=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`),o=e=>{r.changeLanguage(e)},s=e=>{let t=r.language===e;return(0,i.jsxs)(n.Button,{w:`full`,variant:`ghost`,justifyContent:`space-between`,onClick:()=>o(e),py:6,px:4,bg:t?a:void 0,children:[(0,i.jsx)(n.Text,{children:ae[e]}),t&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Select language`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{justify:`center`,spacing:3,align:`flex-start`,w:`full`,children:ie.map(e=>s(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},yi=({token:e,index:r,isExcluded:a,onToggleExclusion:o,onDragStart:s,onDragOver:c,onDrop:l,onTouchStart:u,onTouchMove:d,onTouchEnd:f,isDragging:p,isDraggedOver:m})=>{let h=t.Q[e],{darkMode:_}=$(),v=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),y=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),b=(0,n.useToken)(`colors`,`vechain-kit-card`);return(0,i.jsx)(n.Box,{bg:_?`#ffffff0a`:`blackAlpha.50`,borderRadius:`md`,border:`1px`,borderColor:p?_?`blue.500`:`blue.300`:m?_?`blue.400`:`blue.200`:b,p:3,mb:2,opacity:p||a?.5:1,cursor:`move`,transition:`background-color 0.2s ease, border-color 0.2s ease`,draggable:!0,onDragStart:()=>s(r),onDragOver:e=>{e.preventDefault(),c(r)},onDrop:()=>l(r),onTouchStart:e=>u(r,e),onTouchMove:d,onTouchEnd:f,_hover:{backgroundColor:_?`#ffffff12`:`blackAlpha.200`},children:(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{opacity:a?.5:1,children:[(0,i.jsx)(n.Box,{cursor:`grab`,_active:{cursor:`grabbing`},pointerEvents:`none`,children:(0,i.jsx)(n.Icon,{as:g.LuGripVertical,color:y})}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:v,children:h.name}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:y,children:h.description})]})]}),(0,i.jsx)(n.Switch,{isChecked:!a,onChange:()=>o(e),colorScheme:`blue`,size:`sm`})]})})},bi=({tokens:e,excludedTokens:t,onReorder:a,onToggleExclusion:o})=>{let[s,c]=(0,r.useState)(null),[l,u]=(0,r.useState)(null),d=(0,r.useRef)([]),f=(0,r.useRef)(0),p=e=>{c(e)},m=e=>{u(e)},h=t=>{if(s===null||s===t){c(null),u(null);return}let n=[...e],r=n[s];n.splice(s,1),n.splice(t,0,r),a(n),c(null),u(null)},g=(e,t)=>{f.current=t.touches[0].clientY,c(e)},_=e=>{if(s===null)return;let t=e.touches[0].clientY;for(let e=0;e<d.current.length;e++){let n=d.current[e];if(!n)continue;let r=n.getBoundingClientRect();if(t>=r.top&&t<=r.bottom){u(e);break}}},v=()=>{if(s!==null&&l!==null&&s!==l){let t=[...e],n=t[s];t.splice(s,1),t.splice(l,0,n),a(t)}c(null),u(null),f.current=0};return(0,i.jsx)(n.Box,{w:`full`,children:e.map((e,r)=>(0,i.jsx)(n.Box,{ref:e=>{d.current[r]=e},children:(0,i.jsx)(yi,{token:e,index:r,isExcluded:t.includes(e),onToggleExclusion:o,onDragStart:p,onDragOver:m,onDrop:h,onTouchStart:g,onTouchMove:_,onTouchEnd:v,isDragging:s===r,isDraggedOver:l===r})},e))})},xi=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{preferences:a,reorderTokenPriority:o,toggleTokenExclusion:s}=Tc(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),u=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),d=(0,r.useCallback)(e=>{o(e)},[o]);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Gas Token Preferences`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{justify:`center`,spacing:6,align:`flex-start`,w:`full`,children:[(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,spacing:3,mb:3,children:(0,i.jsx)(n.Text,{fontSize:`sm`,color:u,textAlign:`center`,children:t(`Choose which tokens to use for transaction fees when the app is not covering them.`)})}),a.availableGasTokens.length===0&&(0,i.jsxs)(n.Alert,{status:`warning`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsx)(n.AlertDescription,{fontSize:`sm`,color:u,children:t(`You must enable at least one token to perform transactions. Without any enabled tokens, you will not be able to pay for gas fees.`)})]}),(0,i.jsxs)(n.VStack,{w:`full`,align:`start`,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`semibold`,color:c,children:t(`Token Priority Order`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:u,children:t(`Drag to reorder. The system will automatically use the highest priority token with sufficient balance.`)}),(0,i.jsx)(bi,{tokens:a.tokenPriority,excludedTokens:a.excludedTokens,onReorder:d,onToggleExclusion:s})]})]})})]})},Si=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=Fr(),{exportWallet:o,linkPasskey:s}=(0,u.usePrivy)(),{showMfaEnrollmentModal:c}=(0,u.useMfaEnrollment)(),{feeDelegation:d}=$(),{connection:f,disconnect:p,smartAccount:m,connectedWallet:h}=X(),{data:_}=Is(m?.address??``,h?.address??``,3),v=()=>{e({type:`upgrade-smart-account`,props:{setCurrentContent:e,initialContent:`settings`}})},y=()=>{e(`connection-details`)},b=()=>{p(),t()},x=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Settings`)}),!a&&(0,i.jsx)(J,{onClick:()=>e(`profile`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`General`)}),(0,i.jsx)(Z,{title:r(`Currency`),onClick:()=>{e(`change-currency`)},leftIcon:g.LuDollarSign,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Language`),onClick:()=>{e(`change-language`)},leftIcon:g.LuLanguages,rightIcon:g.LuChevronRight}),f.isConnectedWithPrivy&&!d?.delegatorUrl&&(0,i.jsx)(Z,{title:r(`Gas Token Preferences`),onClick:()=>{e(`gas-token-settings`)},leftIcon:g.LuFuel,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Terms and Policies`),onClick:()=>{e({type:`terms-and-privacy`,props:{onGoBack:()=>e(`settings`)}})},leftIcon:g.LuShield,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Logout`),onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:b,onBack:()=>e(`settings`)}}),leftIcon:g.LuLogOut})]}),_&&(0,i.jsx)(n.VStack,{w:`full`,spacing:2,mt:4,children:(0,i.jsx)(Z,{title:r(`Upgrade Smart Account to V3`),description:r(`A new version is available for your account`),onClick:v,leftIcon:g.LuSettings2,extraContent:(0,i.jsx)(n.Box,{minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`,ml:2})})}),f.isConnectedWithSocialLogin&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,mt:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`Access and security`)}),(0,i.jsx)(Z,{title:r(`Passkey`),onClick:()=>s(),leftIcon:g.LuFingerprint}),(0,i.jsx)(Z,{title:r(`Backup`),onClick:()=>{o()},leftIcon:g.LuKey}),(0,i.jsx)(Z,{title:r(`Manage MFA`),onClick:()=>{c()},leftIcon:g.LuShieldCheck}),(0,i.jsx)(Z,{title:r(`Login methods`),onClick:()=>{e(`privy-linked-accounts`)},leftIcon:g.LuUserCog,rightIcon:g.LuChevronRight})]}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,mt:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`Help`)}),(0,i.jsx)(Z,{title:r(`Connection details`),onClick:y,leftIcon:g.LuUnlink,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Explore ecosystem`),onClick:()=>e(`ecosystem`),leftIcon:g.LuLayoutGrid,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Frequently asked questions`),onClick:()=>e({type:`faq`,props:{onGoBack:()=>e(`settings`),showLanguageSelector:!1}}),leftIcon:g.LuCircleHelp,rightIcon:g.LuChevronRight})]})]}),(0,i.jsx)(n.ModalFooter,{p:0})]})},Ci=({title:e,description:t,icon:r})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`);return(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,py:8,children:[(0,i.jsx)(n.Icon,{as:r,boxSize:16,color:a}),(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`500`,textAlign:`center`,color:o,children:e}),(0,i.jsx)(n.Text,{fontSize:`md`,color:a,textAlign:`center`,px:4,children:t})]})]})},wi=(e,t=`en-US`)=>new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}).format(new Date(e)),Ti=({document:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=e.documentSource===t.v.VECHAIN_KIT&&e.documentType===t.y.TERMS;return(0,i.jsxs)(n.HStack,{children:[(0,i.jsxs)(n.Tag,{size:`sm`,borderRadius:`full`,color:a,children:[`v`,e.version]}),(0,i.jsx)(n.Text,{fontSize:`xs`,cursor:`pointer`,color:a,onClick:()=>{window.open(e.url,`_blank`)},_hover:{textDecoration:`underline`},children:o?r(`'{{policyName}}' on connect`,{policyName:e.displayName??r(`Vechain Kit Policy`)}):r(`'{{policyName}}' on {{date}}`,{policyName:e.displayName??r(`Policy`),date:wi(e.timestamp)})})]})},Ei=({title:e,description:t,documents:r,bg:a,hoverBg:o,currentPolicy:s})=>{let{t:c}=(0,l.useTranslation)(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),f=r?.length>0,p=r?.find(e=>e.id===s?.id);return f?(0,i.jsx)(n.AccordionItem,{border:`none`,mb:3,children:({isExpanded:l})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:a,borderRadius:`xl`,_hover:{bg:o},children:[(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,textAlign:`left`,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,color:u,children:e}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d,children:t})]}),(0,i.jsx)(n.Icon,{as:l?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,color:d})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,pt:3,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:4,children:[p?.id?(0,i.jsxs)(n.HStack,{w:`full`,children:[(0,i.jsx)(n.Icon,{as:g.LuCheck,color:u}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d,children:c(`You accepted current policy on {{date}}`,{date:wi(p.timestamp)})})]}):null,(0,i.jsx)(n.HStack,{w:`full`,textAlign:`left`,children:(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`bold`,color:d,children:c(`All policies you have accepted`)})}),(0,i.jsx)(n.HStack,{w:`full`,gap:2,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:r.map(e=>(0,i.jsx)(Ti,{document:e},e.id))})}),s&&(0,i.jsx)(n.Button,{variant:`outline`,size:`xs`,alignSelf:`flex-end`,onClick:()=>{window.open(s.url,`_blank`)},children:c(`View Current Policy`)})]})})]})}):null},Di=()=>{let{account:e}=X(),{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),{agreements:s,documents:c}=$c(),u=(0,r.useMemo)(()=>{let n=s?.filter(n=>t.k(n.walletAddress,e?.address));return[{id:`vechain-kit-terms`,...t.it,documentType:t.y.TERMS,documentSource:t.v.VECHAIN_KIT,walletAddress:e?.address??``,timestamp:new Date().getTime()},...n]?.reduce((e,t)=>(e[t.documentType]=[...e[t.documentType]||[],t],e),{})},[s,e?.address]),d=(0,r.useMemo)(()=>c.reduce((e,t)=>{let n=t.documentType;return(!e[n]||t.version>e[n].version)&&(e[n]=t),e},{}),[c]),f=(0,r.useMemo)(()=>Object.values(u).some(e=>e.length>0),[u]),p=o?`whiteAlpha.50`:`blackAlpha.50`,m=o?`whiteAlpha.100`:`blackAlpha.100`,h=(0,r.useMemo)(()=>{let e=[];return u[t.y.TERMS]?.length>0&&e.push(0),u[t.y.PRIVACY]?.length>0&&e.push(1),u[t.y.COOKIES]?.length>0&&e.push(2),e},[u]);return f?(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,children:(0,i.jsxs)(n.Accordion,{allowMultiple:!0,defaultIndex:h,children:[(0,i.jsx)(Ei,{title:a(`Terms and Conditions`),description:a(`Legal agreement between you, Vechain Kit and the current app, outlining the rules for using wallet services.`),documents:u[t.y.TERMS],bg:p,hoverBg:m,currentPolicy:d[t.y.TERMS]}),(0,i.jsx)(Ei,{title:a(`Privacy Policy`),description:a(`Privacy policy outlining the data collection and processing practices.`),documents:u[t.y.PRIVACY],bg:p,hoverBg:m,currentPolicy:d[t.y.PRIVACY]}),(0,i.jsx)(Ei,{title:a(`Cookie Policy`),description:a(`Cookie policy outlining the use of cookies and tracking technologies.`),documents:u[t.y.COOKIES],bg:p,hoverBg:m,currentPolicy:d[t.y.COOKIES]})]})}):(0,i.jsx)(Ci,{title:a(`No policies accepted`),description:a(`When you have accepted a policy, it will appear here`),icon:g.LuGavel})},Oi=({onGoBack:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Terms and Policies`)}),(0,i.jsx)(J,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,children:(0,i.jsx)(Di,{})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},ki=({onDisconnect:e,onBack:t,onClose:r,showCloseButton:a=!0,text:o})=>{let{t:s}=(0,l.useTranslation)(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),u=o??s(`Are you sure you want to disconnect your wallet?`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Logout`)}),(0,i.jsx)(J,{onClick:t}),a?(0,i.jsx)(n.ModalCloseButton,{onClick:r}):null]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuLogOut,color:`#ef4444`,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:c,children:u})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,mt:4,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{onClick:e,"data-testid":`disconnect-button`,variant:`vechainKitLogout`,children:s(`Confirm`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:t,"data-testid":`cancel-logout-button`,children:s(`Cancel`)})]})})]})},Ai=({wallet:e,isActive:r,onSelect:a,onRemove:o,showRemove:s=!0})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),{formattedBalance:d,isLoading:f}=Qt({address:e.address}),{domain:p,image:m,isLoading:h}=Mn(e.address,u.type),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useToken)(`colors`,`vechain-kit-border`),b=f||h;return(0,i.jsx)(n.Card,{variant:`vechainKitWalletCard`,onClick:a,borderWidth:r?`2px`:`1px`,borderColor:r?`vechain-kit-primary`:y,_hover:{borderColor:r?`vechain-kit-primary`:`vechain-kit-text-secondary`},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsxs)(n.HStack,{spacing:3,w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,minW:0,children:[(0,i.jsx)(Mc,{wallet:{address:e.address,domain:p??void 0,image:m??void 0,isLoadingMetadata:h},props:{width:10,height:10}}),(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,flex:1,minW:0,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:_,noOfLines:1,children:p?t.G(p,22,0):t.W(e.address,6,4)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:v,noOfLines:1,children:b?c(`Loading...`):d})]})]}),r&&(0,i.jsx)(n.Box,{children:(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`vechain-kit-primary`})}),s&&!r&&(0,i.jsx)(n.IconButton,{"aria-label":c(`Remove wallet`),icon:(0,i.jsx)(n.Icon,{as:g.LuTrash2}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,onClick:e=>{e.stopPropagation(),o()}})]})})})},ji=e=>t.o(e.map(e=>e.address.toLowerCase()).sort().join(`|`)),Mi=({setCurrentContent:e,returnTo:t=`main`,onLogoutSuccess:a})=>{let{t:o}=(0,l.useTranslation)(),{isolatedView:s}=Fr(),{account:c,disconnect:u}=X(),{disconnect:d}=(0,f.useWallet)(),{open:p}=(0,f.useWalletModal)(),{getStoredWallets:m,setActiveWallet:h,removeWallet:_}=Fn(),{saveWallet:v}=Nn(),{refresh:y}=Pn(),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[x,S]=(0,r.useState)(m()),C=(0,r.useRef)(ji(m())),w=(0,r.useCallback)(()=>{let e=m();S(e),C.current=ji(e)},[m]);(0,r.useEffect)(()=>{w()},[w,c?.address]),(0,r.useEffect)(()=>{let e=()=>{setTimeout(()=>{w()},100)};if(typeof window<`u`)return window.addEventListener(`wallet_switched`,e),()=>{window.removeEventListener(`wallet_switched`,e)}},[w]),(0,r.useEffect)(()=>{let e=setInterval(()=>{ji(m())!==C.current&&w()},200);return()=>clearInterval(e)},[m,w]);let T=(0,r.useMemo)(()=>{let e=x.find(e=>e.isActive);return e?e.address:c?.address??null},[x,c?.address]),E=(0,r.useMemo)(()=>x.find(e=>e.address.toLowerCase()===T?.toLowerCase()),[x,T]),D=(0,r.useMemo)(()=>x.filter(e=>e.address.toLowerCase()!==T?.toLowerCase()),[x,T]),O=(0,r.useCallback)(n=>{n.toLowerCase()!==T?.toLowerCase()&&(E&&v(E.address),h(n),setTimeout(()=>{w()},50),y(),e({type:t,props:{switchFeedback:{showFeedback:!0}}}))},[T,E,c,h,y,e,w,v]),k=(0,r.useCallback)(n=>{let r=n.address.toLowerCase()===T?.toLowerCase(),i=x.filter(e=>e.address.toLowerCase()!==n.address.toLowerCase());e({type:`remove-wallet-confirm`,props:{walletAddress:n.address,walletDomain:null,onConfirm:async()=>{if(r&&i.length>0){let e=i[0];h(e.address)}else if(r&&i.length===0)try{await d()}catch(e){console.error(`Error disconnecting:`,e)}if(_(n.address),setTimeout(()=>{w()},50),i.length===0){a&&a();return}e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})},onBack:()=>{e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})}}})},[_,w,e,t,a,T,x,h,d]),A=(0,r.useCallback)(()=>{p()},[p]),j=()=>{u(),a?.()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[!s&&(0,i.jsx)(J,{onClick:()=>{e(t)}}),(0,i.jsx)(n.ModalHeader,{children:o(`Select Wallet`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[E&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,alignItems:`flex-start`,children:[(0,i.jsx)(n.Heading,{size:`sm`,color:b,children:o(`Active Wallet`)}),(0,i.jsx)(Ai,{wallet:E,isActive:!0,onSelect:()=>{},onRemove:()=>k(E),showRemove:x.length>1})]}),D.length>0&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,alignItems:`flex-start`,children:[(0,i.jsx)(n.Heading,{size:`sm`,color:b,children:o(`Other Wallets`)}),D.map(e=>(0,i.jsx)(Ai,{wallet:e,isActive:!1,onSelect:()=>O(e.address),onRemove:()=>k(e),showRemove:!0},e.address))]})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[(0,i.jsx)(n.Button,{w:`full`,leftIcon:(0,i.jsx)(g.LuPlus,{}),variant:`vechainKitSecondary`,onClick:A,children:o(`Add New Wallet`)}),(0,i.jsx)(n.Button,{w:`full`,leftIcon:(0,i.jsx)(g.LuLogOut,{}),variant:`vechainKitLogout`,onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:j,onBack:()=>e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})}}),children:o(`Logout`)})]})})]})},Ni=({walletAddress:e,walletDomain:r,onConfirm:a,onBack:o,onClose:s})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),{domain:d}=Mn(e,u.type),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=d?t.G(d,20,0):t.W(e,6,4);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:c(`Remove`)}),(0,i.jsx)(J,{onClick:o}),s&&(0,i.jsx)(n.ModalCloseButton,{onClick:s})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuTrash2,color:`#ef4444`,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:f,children:c(`Are you sure you want to remove this wallet?`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:`vechain-kit-text-secondary`,fontWeight:`600`,children:p}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:`vechain-kit-text-secondary`,children:t.W(e,8,7)})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,mt:4,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{onClick:a,"data-testid":`remove-wallet-button`,variant:`vechainKitLogout`,children:c(`Remove`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:o,"data-testid":`cancel-remove-button`,children:c(`Cancel`)})]})})]})},Pi=Ae[`@vechain/dapp-kit-react`]||je[`@vechain/dapp-kit-react`]||`unknown`,Fi=Ae[`@privy-io/react-auth`]||`unknown`,Ii=({connectionCache:e})=>{let{t:r}=(0,l.useTranslation)(),{connection:a,smartAccount:o,connectedWallet:s}=X(),{source:c}=(0,f.useWallet)(),{privy:u,network:d}=$(),p=u?.appId,{data:m,isLoading:h}=Ve(p||[]),{onCopy:_,hasCopied:v}=(0,n.useClipboard)(``),{data:y,isLoading:b}=Ue(),{data:x,isLoading:S}=bs(o.address??``,s?.address??``),C=(0,n.useToken)(`colors`,`vechain-kit-card`),w=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),T=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),E=(()=>a.isConnectedWithCrossApp&&e?.ecosystemApp?e.ecosystemApp.name:a.isConnectedWithSocialLogin&&m?Object.values(m)[0]?.name??null:a.isConnectedWithDappKit&&c?c:null)(),D=a.isConnectedWithSocialLogin&&h,O=({label:e,value:t,isLoading:r=!1,href:a})=>(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:T,children:[e,`:`]}),(0,i.jsx)(n.Text,{fontSize:`sm`,as:a?`a`:void 0,href:a,target:`_blank`,rel:`noopener noreferrer`,style:{textDecoration:a?`underline`:`none`},color:w,children:r?`Loading...`:t})]});return D?(0,i.jsx)(n.VStack,{w:`full`,h:`full`,justify:`center`,align:`center`,minH:`200px`,borderRadius:`xl`,bg:C,children:(0,i.jsx)(n.Spinner,{})}):E?(0,i.jsxs)(n.VStack,{p:4,bg:C,borderRadius:`xl`,spacing:4,w:`full`,justifyContent:`space-between`,children:[(0,i.jsx)(O,{label:r(`Logged in with`),value:E}),a.isConnectedWithCrossApp&&e?.timestamp&&(0,i.jsx)(O,{label:r(`At`),value:new Date(e.timestamp).toLocaleString()}),(0,i.jsx)(O,{label:r(`Connection Type`),value:a.source.type,isLoading:a.isLoading}),(0,i.jsx)(n.Divider,{}),(0,i.jsx)(O,{label:r(`Network`),value:d.type}),(0,i.jsx)(O,{label:r(`Node URL`),value:d.nodeUrl||t.bt(d.type).nodeUrl}),a.isConnectedWithPrivy&&(0,i.jsx)(n.Divider,{}),a.isConnectedWithPrivy&&(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:T,children:[r(`Embedded wallet`),`:`]}),(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:w,children:s?.address?t.W(s.address,8,7):`-`}),(0,i.jsx)(n.Icon,{color:w,onClick:()=>{s?.address&&_(s.address)},opacity:s?.address?1:.4,pointerEvents:s?.address?`auto`:`none`,cursor:`pointer`,as:v?g.LuCheck:g.LuCopy})]})]}),a.isConnectedWithPrivy?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(O,{label:r(`Smart Account`),value:`v${x?.version??``} ${x?.isDeployed?``:`(not deployed)`}`,isLoading:S}),(0,i.jsx)(O,{label:r(`Privy Status`),value:y||``,isLoading:b})]}):o.isDeployed&&(0,i.jsx)(O,{label:r(`Smart Account`),value:`v${x?.version??``}`,isLoading:S}),(0,i.jsx)(n.Divider,{}),(0,i.jsx)(O,{label:r(`VeChain Kit`),value:ke,href:`https://github.com/vechain/vechain-kit/releases/tag/${ke}`}),(0,i.jsx)(O,{label:`DAppKit`,value:Pi}),(0,i.jsx)(O,{label:`Privy`,value:Fi})]}):null},Li=()=>{let{connection:t}=X(),{t:r}=(0,l.useTranslation)(),{privy:a,darkMode:o}=$(),{getConnectionCache:s}=Vo(),c=s(),u=(0,n.useToken)(`colors`,`vechain-kit-card`);return t.isConnectedWithPrivy?(0,i.jsxs)(n.VStack,{w:`full`,align:`stretch`,textAlign:`center`,mt:5,p:3,borderRadius:`lg`,bg:u,shadow:`sm`,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`800`,children:r(`Wallet secured by`)}),(0,i.jsxs)(n.HStack,{justify:`center`,children:[(0,i.jsx)(e.i,{isDark:o,w:`50px`}),(0,i.jsx)(n.Icon,{as:g.LuMinus,ml:3}),t.isConnectedWithVeChain?(0,i.jsx)(e.J,{isDark:o,w:`80px`,h:`auto`,mb:`3px`}):t.isConnectedWithCrossApp&&c&&(0,i.jsx)(n.Image,{src:c.ecosystemApp.logoUrl,alt:c.ecosystemApp.name,maxW:`40px`,borderRadius:`md`}),t.isConnectedWithSocialLogin&&!t.isConnectedWithVeChain&&(0,i.jsx)(n.Image,{src:a?.appearance.logo,alt:a?.appearance.logo,maxW:`40px`,borderRadius:`md`})]})]}):null},Ri=({onGoBack:e})=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Vo(),a=r()??void 0;return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Connection Details`)}),(0,i.jsx)(J,{onClick:()=>{e()}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsx)(Ii,{connectionCache:a}),(0,i.jsx)(Li,{})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},zi=({accountType:e,accountDescription:t,isLoading:r,onConfirm:a,onCancel:o})=>{let{t:s}=(0,l.useTranslation)();return(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:(0,n.useToken)(`colors`,`vechain-kit-text-primary`),children:s(`Are you sure you want to unlink {{accountType}} as a login method linked to {{accountDescription}}?`,{accountType:e,accountDescription:t})}),(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{height:`60px`,colorScheme:`red`,w:`full`,onClick:a,isLoading:r,children:s(`Remove Login Method`)}),(0,i.jsx)(n.Button,{isLoading:r,height:`60px`,w:`full`,onClick:o,children:s(`Cancel`)})]})]})},Bi=({onBack:e})=>{let{t:a}=(0,l.useTranslation)(),{privy:o,dappKit:s}=$(),[c,d]=(0,r.useState)(null),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{user:x,linkEmail:S,linkGoogle:C,linkTwitter:w,linkPhone:T,linkSpotify:D,linkApple:O,linkInstagram:k,linkTiktok:A,linkGithub:P,linkLinkedIn:F,linkTelegram:I,linkFarcaster:L,linkPasskey:R,linkDiscord:z,unlinkEmail:B,unlinkGoogle:ee,unlinkApple:te,unlinkSpotify:V,unlinkInstagram:ne,unlinkTiktok:re,unlinkGithub:ie,unlinkLinkedIn:H,unlinkTelegram:ae,unlinkFarcaster:U,unlinkPhone:oe,unlinkPasskey:W,unlinkDiscord:se,linkWallet:ce}=(0,u.usePrivy)(),G=(0,r.useMemo)(()=>{let e=o?.loginMethods?.filter(e=>[`rabby_wallet`,`coinbase_wallet`,`rainbow`,`phantom`,`metamask`].includes(e))??[],t=s?.allowedWallets??[];return e.length>0||t.length>0},[o?.loginMethods,s?.allowedWallets]),le=e=>{switch(e){case`google_oauth`:return E.FcGoogle;case`email`:return g.LuMail;case`passkey`:return g.LuFingerprint;case`wallet`:return g.LuWallet;case`twitter_oauth`:return j.FaXTwitter;case`phone`:return g.LuPhone;case`spotify_oauth`:return N.FaSpotify;case`apple_oauth`:return N.FaApple;case`instagram_oauth`:return N.FaInstagram;case`tiktok_oauth`:return N.FaTiktok;case`github_oauth`:return g.LuGithub;case`linkedin_oauth`:return N.FaLinkedin;case`telegram`:return N.FaTelegram;case`farcaster`:return M.SiFarcaster;case`discord_oauth`:return N.FaDiscord;default:return}},ue=()=>{let e=x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`);return e&&e?.length>1},de=async e=>{if(ue()){v(!0);try{switch(e.type){case`google_oauth`:await ee(e.subject);break;case`email`:await B(e.address);break;case`passkey`:await W(e.subject);break;case`phone`:await oe(e.number);break;case`spotify_oauth`:await V(e.subject);break;case`apple_oauth`:await te(e.subject);break;case`instagram_oauth`:await ne(e.subject);break;case`tiktok_oauth`:await re(e.subject);break;case`github_oauth`:await ie(e.subject);break;case`linkedin_oauth`:await H(e.subject);break;case`telegram`:await ae(e.subject);break;case`farcaster`:await U(e.subject);break;case`discord_oauth`:await se(e.subject);break;default:break}}catch(e){console.error(e)}finally{v(!1),d(null)}}},K=e=>{switch(e.type){case`google_oauth`:return e.email;case`email`:return e.address;case`passkey`:return`${e.authenticatorName} - ${e.createdWithBrowser}`;case`phone`:return e.number;case`wallet`:return`${t.W(e.address)} - ${e.walletClientType}`;default:return``}},q=x?.linkedAccounts?.map(e=>e.type)||[],fe=o?.loginMethods||[],pe=!q.includes(`google_oauth`)&&fe.includes(`google`),me=!q.includes(`email`)&&fe.includes(`email`),he=!q.includes(`twitter_oauth`)&&fe.includes(`twitter`),ge=!q.includes(`phone`)&&fe.includes(`sms`),_e=!q.includes(`spotify_oauth`)&&fe.includes(`spotify`),ve=!q.includes(`apple_oauth`)&&fe.includes(`apple`),ye=!q.includes(`instagram_oauth`)&&fe.includes(`instagram`),be=!q.includes(`tiktok_oauth`)&&fe.includes(`tiktok`),xe=!q.includes(`github_oauth`)&&fe.includes(`github`),Se=!q.includes(`linkedin_oauth`)&&fe.includes(`linkedin`),Ce=!q.includes(`telegram`)&&fe.includes(`telegram`),we=!q.includes(`farcaster`)&&fe.includes(`farcaster`),Te=!q.includes(`discord_oauth`)&&fe.includes(`discord`);return f?(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select Additional Login Method`)}),(0,i.jsx)(J,{onClick:()=>p(!1)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`stretch`,w:`full`,children:[(0,i.jsx)(Z,{title:a(`Set up Passkey`),description:a(`Set up a passkey for easier access`),onClick:()=>R(),leftIcon:g.LuFingerprint}),pe&&(0,i.jsx)(Z,{title:a(`Link Google Account`),description:a(`Connect your Google account for easier access`),onClick:()=>C(),leftIcon:E.FcGoogle}),me&&(0,i.jsx)(Z,{title:a(`Link Email Account`),description:a(`Connect your email for easier access`),onClick:()=>S(),leftIcon:g.LuMail,stacked:!0}),he&&(0,i.jsx)(Z,{title:a(`Link Twitter Account`),description:a(`Connect your Twitter account for easier access`),onClick:()=>w(),leftIcon:j.FaXTwitter}),ge&&(0,i.jsx)(Z,{title:a(`Link Phone Number`),description:a(`Connect your phone number for easier access`),onClick:()=>T(),leftIcon:g.LuPhone}),_e&&(0,i.jsx)(Z,{title:a(`Link Spotify Account`),description:a(`Connect your Spotify account for easier access`),onClick:()=>D(),leftIcon:N.FaSpotify}),ve&&(0,i.jsx)(Z,{title:a(`Link Apple Account`),description:a(`Connect your Apple account for easier access`),onClick:()=>O(),leftIcon:N.FaApple}),ye&&(0,i.jsx)(Z,{title:a(`Link Instagram Account`),description:a(`Connect your Instagram account for easier access`),onClick:()=>k(),leftIcon:N.FaInstagram}),be&&(0,i.jsx)(Z,{title:a(`Link Tiktok Account`),description:a(`Connect your Tiktok account for easier access`),onClick:()=>A(),leftIcon:N.FaTiktok}),xe&&(0,i.jsx)(Z,{title:a(`Link Github Account`),description:a(`Connect your Github account for easier access`),onClick:()=>P(),leftIcon:g.LuGithub}),Se&&(0,i.jsx)(Z,{title:a(`Link LinkedIn Account`),description:a(`Connect your LinkedIn account for easier access`),onClick:()=>F(),leftIcon:N.FaLinkedin}),Ce&&(0,i.jsx)(Z,{title:a(`Link Telegram Account`),description:a(`Connect your Telegram account for easier access`),onClick:()=>I(),leftIcon:N.FaTelegram}),we&&(0,i.jsx)(Z,{title:a(`Link Farcaster Account`),description:a(`Connect your Farcaster account for easier access`),onClick:()=>L(),leftIcon:M.SiFarcaster}),Te&&(0,i.jsx)(Z,{title:a(`Link Discord Account`),description:a(`Connect your Discord account for easier access`),onClick:()=>z(),leftIcon:N.FaDiscord}),G&&(0,i.jsx)(Z,{title:a(`Link External Wallet`),description:a(`Connect an external wallet for easier access`),onClick:()=>ce(),leftIcon:g.LuWallet}),!pe&&!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,opacity:.7,children:a(`No additional accounts available to link`)})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):c?(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Remove Login Method`)}),(0,i.jsx)(J,{onClick:()=>d(null)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(zi,{accountType:c.type,accountDescription:K(c),isLoading:_,onConfirm:()=>de(c),onCancel:()=>d(null)})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Login methods`)}),(0,i.jsx)(J,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`center`,w:`full`,justify:`center`,children:[(0,i.jsxs)(n.VStack,{spacing:1,justify:`flex-start`,alignItems:`flex-start`,mb:5,textAlign:`left`,w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:a(`These accounts are linked to your embedded wallet and can be used to login to your wallet and access your private key.`)}),m&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:a(`Adding more linked accounts increases security against loss of access, but also introduces additional potential attack vectors. For enhanced security, we recommend enabling MFA.`)}),(0,i.jsx)(n.Button,{variant:`link`,mt:0,size:`sm`,onClick:()=>h(!m),color:y,children:a(m?`Show Less`:`Read More`)})]}),x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`).map(e=>(0,i.jsxs)(n.Flex,{p:4,borderWidth:`1px`,borderRadius:`md`,align:`center`,justify:`space-between`,w:`full`,children:[(0,i.jsxs)(n.Flex,{align:`center`,gap:3,children:[(0,i.jsx)(n.Icon,{as:le(e.type),color:y}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`500`,color:y,children:e.type===`google_oauth`?a(`Google`):e.type===`email`?a(`Email`):e.type===`passkey`?a(`Passkey`):e.type===`twitter_oauth`?a(`Twitter`):e.type===`phone`?a(`Phone Number`):e.type===`spotify_oauth`?a(`Spotify`):e.type===`apple_oauth`?a(`Apple`):e.type===`instagram_oauth`?a(`Instagram`):e.type===`tiktok_oauth`?a(`Tiktok`):e.type===`github_oauth`?a(`Github`):e.type===`linkedin_oauth`?a(`LinkedIn`):e.type===`telegram`?a(`Telegram`):e.type===`farcaster`?a(`Farcaster`):e.type===`discord_oauth`?a(`Discord`):a(`Wallet`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:K(e)})]})]}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,colorScheme:`red`,isDisabled:!ue(),onClick:()=>{e.type===`passkey`?R():d(e)},children:a(`Remove`)})]},e.type))]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsx)(n.Button,{w:`full`,variant:`vechainKitPrimary`,onClick:()=>p(!0),leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPlus}),isDisabled:!pe&&!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te,children:a(`Add Login Method`)})})]})},Vi=[{id:`welcome`,title:`Welcome to the VeChain`,description:`Welcome! Here you can manage your wallet, send tokens, and interact with the VeChain blockchain and its applications.`,timestamp:Date.now(),status:`success`,isRead:!1}],Hi=()=>{let{t:e}=(0,l.useTranslation)(),{account:t,connection:n,smartAccount:i}=X(),{addNotification:a,getNotifications:o}=Ui(),{data:s}=zs(i?.address??``,3);(0,r.useEffect)(()=>{if(!n.isConnectedWithPrivy||!t?.address)return;let r=o(),i=`smart_account_upgrade_${t.address.toLowerCase()}`;!r.some(e=>e.id===i)&&s&&a({id:i,title:e(`Account Upgrade Required`),description:e(`A new upgrade is available for your smart account. Please head over to the 'Access and Security' section to upgrade it.`),status:`warning`})},[n.isConnectedWithPrivy,t?.address,s]),(0,r.useEffect)(()=>{!n.isConnectedWithPrivy||!t?.address||o().some(e=>e.id===`smart_account_${t.address.toLowerCase()}`)||a({id:`smart_account_${t.address.toLowerCase()}`,title:e(`Smart Account detected`),description:e(`You have an active smart account associated to this wallet. It has been set as your main identity.`),status:`info`})},[n.isConnectedWithPrivy,t?.address]),(0,r.useEffect)(()=>{if(!n.isConnectedWithPrivy||!t?.address)return;let r=o(),i=r.some(e=>e.id===`multiclause_warning_${t.address.toLowerCase()}`),s=r.some(e=>e.id===`multiclause_support_${t.address.toLowerCase()}`);i&&!s&&a({id:`multiclause_support_${t.address.toLowerCase()}`,title:e(`Multiclause Transactions Are Now Supported`),description:e(`Good news! Multiclause transactions are now fully supported for smart accounts. You can now enjoy a better user experience, lower gas costs, and enchanced security.`),status:`info`})},[n.isConnectedWithPrivy,t?.address])},Ui=()=>{let{account:e}=X(),n=(0,r.useCallback)(e=>{let t=e?.toLowerCase();return{notifications:`vechain_kit_notifications_${t}`,archived:`vechain_kit_archived_notifications_${t}`,initialized:`vechain_kit_notifications_initialized_${t}`}},[]),i=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return;let r=n(e.address);t.dt(r.initialized)||(t.yt(r.notifications,JSON.stringify(Vi)),t.yt(r.initialized,`true`))},[e?.address,n]);(0,r.useEffect)(()=>{i()},[i]);let a=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return[];let r=t.dt(n(e.address).notifications);return r?JSON.parse(r):[]},[e?.address,n]),o=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return[];let r=t.dt(n(e.address).archived);return r?JSON.parse(r):[]},[e?.address,n]),s=(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),o=a(),s=t.dt(i.archived),c=s?JSON.parse(s):[];if([...o,...c].some(e=>e.title===r.title))return;let l={...r,id:r.id||Math.random().toString(36).substring(7),timestamp:Date.now(),isRead:!1};t.yt(i.notifications,JSON.stringify([l,...o]))},[e?.address,a,n]),c=(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),o=a().filter(e=>e.id!==r);t.yt(i.notifications,JSON.stringify(o))},[e?.address,a,n]);return{getNotifications:a,getArchivedNotifications:o,addNotification:s,clearAllNotifications:(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return;let r=n(e.address),i=a();t.yt(r.archived,JSON.stringify([...o(),...i])),t.yt(r.notifications,JSON.stringify([]))},[e?.address,a,o,n]),markAsRead:(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),s=a(),c=o(),l=s.find(e=>e.id===r),u=s.filter(e=>e.id!==r);if(l){let e=[{...l,isRead:!0},...c];t.yt(i.notifications,JSON.stringify(u)),t.yt(i.archived,JSON.stringify(e))}},[e?.address,a,o,n]),deleteNotification:c}},Wi=({showArchived:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsx)(Ci,{title:t(e?`No archived notifications`:`No notifications`),description:t(e?`Cleared notifications will appear here`:`When you have notifications, they will appear here`),icon:e?g.LuArchive:g.LuBell})},Gi=({notification:e,isArchiveView:t,onMarkAsRead:r})=>{let{t:a}=(0,l.useTranslation)(),o=()=>{r(e.id)};return e.isRead&&!t?null:(0,i.jsxs)(n.Alert,{status:e.status,variant:`subtle`,borderRadius:`lg`,pr:8,position:`relative`,opacity:e.isRead?.7:1,cursor:`pointer`,_hover:{opacity:.8},"data-testid":`notification-item`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:`16px`}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,"data-testid":`notification-title`,children:a(e.title)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,lineHeight:`1.2`,"data-testid":`notification-text`,children:a(e.description)})]}),!t&&!e.isRead&&(0,i.jsx)(n.IconButton,{position:`absolute`,right:1,top:1,size:`sm`,variant:`ghost`,icon:(0,i.jsx)(g.LuCircleX,{}),onClick:e=>{e.stopPropagation(),o()},"aria-label":`Mark as read and archive`,"data-testid":`remove-notification-button`})]},e.id)},Ki=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isolatedView:a}=Fr(),{getNotifications:o,getArchivedNotifications:s,clearAllNotifications:c,markAsRead:u}=Ui(),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(o()),[h,_]=(0,r.useState)(s()),v=()=>{c(),_([...h,...p]),m([])},y=e=>{u(e);let t=p.find(t=>t.id===e);m(p.filter(t=>t.id!==e)),t&&_([{...t,isRead:!0},...h])},b=()=>{f(!d)},x=d?h:p,S=[...x].sort((e,t)=>e.id===`welcome`?-1:t.id===`welcome`?1:e.id===`smart-account`?-1:t.id===`smart-account`?1:e.id===`multiclause`?-1:t.id===`multiclause`?1:t.timestamp-e.timestamp);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[!a&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:t(d?`Archived Notifications`:`Notifications`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{h:[`540px`,`auto`],p:0,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,w:`full`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Button,{variant:`ghost`,leftIcon:(0,i.jsx)(n.Icon,{as:d?g.LuBell:g.LuArchive}),size:`sm`,onClick:b,"data-testid":`toggle-view-button`,children:t(d?`Current`:`Archived`)}),!d&&p.length>0&&(0,i.jsx)(n.Button,{variant:`ghost`,size:`sm`,onClick:v,"data-testid":`clear-all-button`,children:t(`Clear all`)})]}),x.length===0?(0,i.jsx)(Wi,{showArchived:d}):(0,i.jsx)(n.VStack,{spacing:3,children:S.map(e=>(0,i.jsx)(Gi,{notification:e,isArchiveView:d,onMarkAsRead:y},e.id))})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},qi=e=>{switch(e){case`defi`:return`blue`;case`games`:return`green`;case`collectibles`:return`purple`;case`marketplaces`:return`orange`;case`utilities`:return`cyan`;default:return`gray`}},Ji=({category:e,...t})=>{let{t:r}=(0,l.useTranslation)(),a=e.toLowerCase();return(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:qi(a),borderRadius:`full`,px:2,...t,children:r(a)})},Yi=({name:e,imageUrl:r,logoComponent:a,category:o,onClick:s,size:c=`md`})=>(0,i.jsxs)(n.Card,{variant:`vechainKitAppCard`,_hover:{opacity:.8},cursor:`pointer`,onClick:s,position:`relative`,children:[o&&(0,i.jsx)(n.Box,{position:`absolute`,top:`2`,right:`2`,zIndex:`1`,children:(0,i.jsx)(Ji,{category:o})}),(0,i.jsx)(n.CardBody,{p:c===`sm`?2:4,alignItems:`center`,children:(0,i.jsxs)(n.VStack,{spacing:2,h:`100%`,justifyContent:`space-between`,children:[a||r&&(0,i.jsx)(n.Image,{src:r,fallbackSrc:t.ct,alt:e,height:`90px`,objectFit:`contain`,rounded:`full`}),e&&(0,i.jsx)(n.Text,{fontWeight:`medium`,wordBreak:`break-word`,noOfLines:1,textAlign:`center`,w:`full`,children:e})]})})]}),Xi=({xApp:e,setCurrentContent:t,selectedCategory:r})=>{let{data:a,isLoading:o}=Rn(e.id),{data:s,isLoading:c}=Gn(a?.logo);return(0,i.jsx)(n.Skeleton,{isLoaded:!o&&!c,borderRadius:`md`,height:`100%`,children:(0,i.jsx)(Yi,{name:a?.name??``,imageUrl:s?.image??``,linkUrl:a?.external_url??``,category:`vebetter`,onClick:()=>{a?.name&&t({type:`app-overview`,props:{name:a.name,image:s?.image??``,url:a?.external_url??``,description:a?.description??``,category:`vebetter`,selectedCategory:r,setCurrentContent:t}})}})})},Zi=({name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c})=>(0,i.jsx)(Yi,{name:e,imageUrl:t,linkUrl:n,category:a,onClick:()=>{c({type:`app-overview`,props:{name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c}})},...o&&{logoComponent:o}}),Qi=({})=>{let{t:e}=(0,l.useTranslation)(),{shortcuts:r}=_c();return r.length===0?null:(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,children:e(`Shortcuts`)}),(0,i.jsx)(n.Grid,{templateColumns:`repeat(4, 1fr)`,gap:2,w:`full`,children:r.map(e=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(n.Card,{_hover:{opacity:.8},cursor:`pointer`,onClick:()=>window.open(e.url,`_blank`),children:(0,i.jsx)(n.CardBody,{p:2,alignItems:`center`,children:(0,i.jsx)(n.Image,{src:e.image,fallbackSrc:t.ct,alt:e.name,objectFit:`contain`,rounded:`full`})})})},e.url))})]})},$i=({selectedCategory:e,onCategoryChange:t,categories:r,darkMode:a})=>{let{t:o}=(0,l.useTranslation)();return(0,i.jsxs)(n.Box,{width:`full`,mb:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,mb:2,children:o(`Filter by category`)}),(0,i.jsxs)(n.Wrap,{spacing:2,children:[(0,i.jsx)(n.WrapItem,{children:(0,i.jsx)(n.Tag,{size:`md`,borderRadius:`full`,variant:e===null?`solid`:`outline`,colorScheme:a?`gray`:`blackAlpha`,cursor:`pointer`,onClick:()=>t(null),children:o(`All`)})}),r.map(r=>(0,i.jsx)(n.WrapItem,{children:(0,i.jsx)(Ji,{category:r,size:`md`,variant:e===r?`solid`:`outline`,cursor:`pointer`,onClick:()=>t(r)})},r))]})]})},ea=[{name:`VeBetterDAO`,description:`Engage, earn and prosper by doing sustainable actions.`,external_url:e.y,logo:new URL(`/static/img/coins/64x64/33509.png`,e.c).toString(),banner:new URL(`/static/img/icons/vbd.png`,e.c).toString(),screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:new URL(`/static/img/icons/vbd.png`,e.c).toString()},categories:[]},{name:`vet.domains`,description:`.vet.domains provides a unique and unchangeable identity for Vechain users by linking information to their wallet addresses. It becomes easier for people to use the blockchain by replacing complicated wallet addresses with easy-to-remember names.`,external_url:e.k,logo:new URL(`/assets/walletconnect.png`,e.k).toString(),banner:new URL(`/assets/walletconnect.png`,e.k).toString(),screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:new URL(`/assets/walletconnect.png`,e.k).toString()},categories:[]}],ta=({setCurrentContent:e,selectedCategory:t})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o,network:s}=$(),{isolatedView:c}=Fr(),u=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(t||null);(0,r.useEffect)(()=>{t!==void 0&&m(t)},[t]);let{data:h}=nn(),{data:_}=En(h?(parseInt(h)-1).toString():`1`),{data:v,isLoading:y,error:b}=Jo(),x=(0,r.useMemo)(()=>{let e=new Set;return s.type===`main`&&_&&_.length>0&&e.add(`vebetter`),v&&v.forEach(t=>{t.category&&e.add(t.category)}),Array.from(e).sort()},[v,_,s.type]),S=s.type===`main`?_.filter(e=>e.app.name.toLowerCase().includes(d.toLowerCase())):[],C=ea.filter(e=>e.name.toLowerCase().includes(d.toLowerCase())),w=v?.filter(e=>(e.name.toLowerCase().includes(d.toLowerCase())||e.description.toLowerCase().includes(d.toLowerCase())||e.tags.some(e=>e.toLowerCase().includes(d.toLowerCase())))&&(p===null||e.category===p))||[],T=p===null,E=p===null||p===`vebetter`,{shortcuts:D}=_c();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Ecosystem`)}),!c&&(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{overflowY:`auto`,minH:`300px`,children:(0,i.jsxs)(n.VStack,{spacing:6,w:`full`,children:[(0,i.jsx)(Qi,{setCurrentContent:e}),D.length>0&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,w:`full`,textAlign:`left`,children:a(`All apps`)}),(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:a(`Search Apps`),value:d,onChange:e=>{f(e.target.value)},bg:o?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:u})})]}),x.length>0&&(0,i.jsx)($i,{selectedCategory:p,onCategoryChange:e=>{m(e)},categories:x,darkMode:o}),(0,i.jsxs)(n.Grid,{templateColumns:`repeat(2, 1fr)`,gap:4,w:`full`,children:[T&&C.length>0&&(0,i.jsx)(i.Fragment,{children:C.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Zi,{name:t.name,image:t.logo,url:t.external_url,setCurrentContent:e,description:t.description,selectedCategory:p})},t.name))}),E&&S.length>0&&(0,i.jsx)(i.Fragment,{children:S.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Xi,{xApp:t.app,setCurrentContent:e,selectedCategory:p})},t.id))}),y?(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Center,{py:4,children:(0,i.jsx)(n.Spinner,{})})}):b?(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Text,{color:`red.500`,textAlign:`center`,children:a(`Failed to load App Hub apps`)})}):w.length>0?w.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Zi,{name:t.name,image:t.logo,url:t.url,setCurrentContent:e,description:t.description,category:t.category,selectedCategory:p})},t.id)):p&&!E&&(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Center,{py:4,children:(0,i.jsx)(n.Text,{children:a(`No apps found in this category`)})})})]})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},na=({name:e,image:t,url:r,description:a})=>{let{t:o}=(0,l.useTranslation)(),{isShortcut:s,addShortcut:c,removeShortcut:u}=_c(),d=s(r);return(0,i.jsx)(n.Button,{px:4,width:`full`,height:`45px`,variant:`vechainKitSecondary`,borderRadius:`xl`,onClick:()=>{d?u(r):c({name:e,image:t,url:r,description:a})},leftIcon:(0,i.jsx)(n.Icon,{as:d?g.LuBookmarkCheck:g.LuBookmark}),children:o(d?`Remove from shortcuts`:`Add to shortcuts`)})},ra=({setCurrentContent:e,name:t,image:r,url:a,description:o,category:s,selectedCategory:c,logoComponent:u})=>{let{t:d}=(0,l.useTranslation)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t}),(0,i.jsx)(J,{onClick:()=>{e(c?{type:`ecosystem-with-category`,props:{selectedCategory:c,setCurrentContent:e}}:`ecosystem`)}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,w:`full`,children:[(0,i.jsxs)(n.Flex,{direction:`column`,align:`center`,children:[u||(0,i.jsx)(n.Image,{src:r,alt:t,w:`200px`,h:`200px`,objectFit:`contain`,borderRadius:`xl`}),s&&(0,i.jsx)(n.HStack,{mt:2,children:(0,i.jsx)(Ji,{category:s})})]}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:o}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:d(`Click below to access {{ name }} and explore its features.`,{name:t})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,onClick:()=>{window.open(a,`_blank`)},children:[d(`Launch {{name}}`,{name:t}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]}),(0,i.jsx)(na,{name:t,image:r,url:a,description:o})]})})]})},ia=({children:e})=>(0,i.jsx)(h.motion.div,{whileHover:{scale:1.1},transition:{duration:.5,ease:`easeInOut`,repeat:1/0,repeatDelay:crypto.getRandomValues(new Uint32Array(1))[0]/2**32*5},animate:{y:[0,-2,0],rotate:[0,10,-10,0]},children:e}),aa=({description:t})=>{let{darkMode:r}=$(),a=new URL(`intent/tweet`,e.v);a.searchParams.set(`text`,t);let o=new URL(`share/url`,e._);o.searchParams.set(`url`,t);let s=new URL(``,e.A);return s.searchParams.set(`text`,t),(0,i.jsxs)(n.HStack,{gap:2,children:[(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:a.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:r?`blackAlpha.700`:`lightgrey`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaXTwitter,{size:22})})})}),(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:o.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#30abec`,p:2,borderRadius:`full`,children:(0,i.jsx)(N.FaTelegramPlane,{color:`white`,size:22})})})}),(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:s.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#01cb37`,p:2,borderRadius:`full`,children:(0,i.jsx)(N.FaWhatsapp,{size:22,color:`white`})})})})]})},oa=({status:e,uiConfig:a,onTryAgain:o,txReceipt:s,txError:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=(0,n.useToken)(`colors`,`vechain-kit-error`),m=(0,n.useToken)(`colors`,`vechain-kit-success`),h=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=(0,r.useMemo)(()=>c?c.reason||d(`Something went wrong. Please try again.`):null,[c,d]),y=(()=>{let t=e===`waitingConfirmation`;switch(t&&(e=`pending`),e){case`pending`:return{title:a?.title??d(t?`Sending Transaction...`:`Waiting for confirmation`),icon:a?.loadingIcon??(0,i.jsx)(n.Spinner,{size:`xl`,"data-testid":`pending-spinner-modal`}),description:t?d(`Transaction is being processed, it can take up to 15 seconds.`):a?.description??d(`Please confirm the transaction in your wallet.`)};case`error`:return{title:d(`Something went wrong`),icon:a?.errorIcon??(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:p,fontSize:`100px`,"data-testid":`error-icon-modal`}),description:v??d(`An unexpected error occurred.`)};case`success`:return{title:d(`Transaction successful!`),icon:a?.successIcon??(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,color:m,fontSize:`100px`,"data-testid":`success-icon-modal`}),description:``};case`ready`:return{title:a?.title??d(`Confirm transaction`),icon:null,description:a?.description??d(`Confirm the transaction in your wallet to complete it.`)};default:return{title:``,icon:null,description:``}}})(),b=`${t.bt(f.type).explorerUrl}/${s?.meta.txID}`;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:y.title}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:e===`pending`&&!a?.isClosable})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[y.icon,e===`success`&&a?.showShareOnSocials&&(0,i.jsxs)(n.VStack,{mt:2,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:_,children:d(`Share on`)}),(0,i.jsx)(aa,{description:b})]}),y.description&&(0,i.jsx)(n.Text,{fontSize:e===`ready`?`md`:`sm`,textAlign:`center`,color:e===`error`?p:h,mt:5,style:{lineBreak:`anywhere`},children:y.description})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[e===`error`&&!!o&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:o,width:`full`,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),d(`Try again`)]}),e===`ready`&&(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitPrimary`,width:`full`,children:d(`Confirm`)}),(e===`success`||e===`error`||e===`ready`)&&(0,i.jsx)(n.Button,{onClick:u,variant:`ghost`,width:`full`,children:d(`Close`)}),a?.showExplorerButton&&s?.meta.txID&&(0,i.jsx)(n.Link,{href:`${t.bt(f.type).explorerUrl}/${s?.meta.txID}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{color:_,children:d(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:`sm`,as:g.LuExternalLink,color:_})]})})]})})]})},sa=({isOpen:e,onClose:t,status:n,uiConfig:r,txReceipt:a,txError:o,onTryAgain:s})=>{let{darkMode:c,theme:l}=$();return e?(0,i.jsx)($a,{darkMode:c,theme:l,children:(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,closeOnOverlayClick:n!==`pending`&&r?.isClosable,children:(0,i.jsx)(oa,{status:n,onTryAgain:s,uiConfig:r,txReceipt:a,onClose:t,txError:o})})}):null},ca=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.bt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`),m=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,fontSize:`100px`,color:p,"data-testid":`success-icon`}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:m,children:a}),s&&e&&(0,i.jsxs)(n.VStack,{mt:2,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:h,children:c(`Share on`)}),(0,i.jsx)(aa,{description:f})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:c(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{color:h,children:c(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},la=({txId:e,title:r,description:a,onDone:o})=>{let{t:s}=(0,l.useTranslation)(),{network:c,darkMode:u}=$(),d=t.bt(c.type).explorerUrl;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,fontSize:`100px`,color:u?`red.400`:`red.500`,"data-testid":`error-icon`}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:s(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{children:s(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},ua=({isOpen:e,onClose:t,initialContent:n=`profile`})=>{let{account:a}=X(),{themeConfig:o}=Za(),{accountModalContent:s,setAccountModalContent:c}=Q();return(0,r.useEffect)(()=>{e&&c(n)},[e,n,c]),(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:o?.modal?.useBottomSheetOnMobile?`520px`:`510px`,mobileMaxHeight:o?.modal?.useBottomSheetOnMobile?`520px`:`510px`,desktopMinHeight:`485px`,desktopMaxHeight:`485px`,children:(()=>{if(typeof s==`object`)switch(s.type){case`send-token`:return(0,i.jsx)(Ir,{...s.props});case`send-token-summary`:return(0,i.jsx)(Lr,{...s.props});case`swap-token`:return(0,i.jsx)(Hr,{...s.props});case`choose-name`:return(0,i.jsx)(Ur,{...s.props});case`choose-name-search`:return(0,i.jsx)(qr,{...s.props});case`choose-name-summary`:return(0,i.jsx)(Jr,{...s.props});case`app-overview`:return(0,i.jsx)(ra,{...s.props,setCurrentContent:c});case`disconnect-confirm`:return(0,i.jsx)(ki,{...s.props});case`remove-wallet-confirm`:return(0,i.jsx)(Ni,{...s.props});case`account-customization`:return(0,i.jsx)(ci,{...s.props});case`account-customization-summary`:return(0,i.jsx)(li,{...s.props});case`successful-operation`:return(0,i.jsx)(ca,{...s.props});case`failed-operation`:return(0,i.jsx)(la,{...s.props});case`upgrade-smart-account`:return(0,i.jsx)(pi,{...s.props});case`faq`:return(0,i.jsx)(Xr,{...s.props});case`terms-and-privacy`:return(0,i.jsx)(Oi,{...s.props});case`ecosystem-with-category`:return(0,i.jsx)(ta,{setCurrentContent:c,selectedCategory:s.props.selectedCategory});case`select-wallet`:return(0,i.jsx)(Mi,{setCurrentContent:c,onClose:t,returnTo:s.props.returnTo,onLogoutSuccess:s.props.onLogoutSuccess});case`main`:return(0,i.jsx)(Nr,{setCurrentContent:c,onClose:t,wallet:a,switchFeedback:s.props?.switchFeedback});case`profile`:return(0,i.jsx)(fi,{setCurrentContent:c,onLogoutSuccess:()=>{t()},switchFeedback:s.props?.switchFeedback})}switch(s){case`main`:return(0,i.jsx)(Nr,{setCurrentContent:c,onClose:t,wallet:a});case`settings`:return(0,i.jsx)(Si,{setCurrentContent:c,onLogoutSuccess:()=>{t()}});case`profile`:return(0,i.jsx)(fi,{setCurrentContent:c,onLogoutSuccess:()=>{t()}});case`assets`:return(0,i.jsx)(mi,{setCurrentContent:c});case`notifications`:return(0,i.jsx)(Ki,{setCurrentContent:c});case`receive-token`:return(0,i.jsx)(Rr,{setCurrentContent:c});case`swap-token`:return(0,i.jsx)(Hr,{setCurrentContent:c});case`connection-details`:return(0,i.jsx)(Ri,{onGoBack:()=>c(`settings`)});case`privy-linked-accounts`:return(0,i.jsx)(Bi,{onBack:()=>c(`settings`)});case`ecosystem`:return(0,i.jsx)(ta,{setCurrentContent:c});case`add-custom-token`:return(0,i.jsx)(hi,{setCurrentContent:c});case`change-currency`:return(0,i.jsx)(_i,{setCurrentContent:c});case`change-language`:return(0,i.jsx)(vi,{setCurrentContent:c});case`gas-token-settings`:return(0,i.jsx)(xi,{setCurrentContent:c});default:return null}})()})},da=({loadingText:e,title:t,onTryAgain:a,onClose:o,onGoBack:s,showBackButton:c=!0})=>{let{t:u}=(0,l.useTranslation)(),[d,f]=r.default.useState(!1);return r.default.useEffect(()=>{let e=setTimeout(()=>{f(!0)},7e3);return()=>clearTimeout(e)},[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[c&&(0,i.jsx)(J,{onClick:s}),t??u(`Connecting...`),(0,i.jsx)(n.ModalCloseButton,{onClick:o})]})}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsx)(n.VStack,{align:`center`,p:6,gap:0,w:`full`,justifyContent:`center`,minH:`150px`,children:(0,i.jsx)(n.Spinner,{size:`xl`})}),e&&!d&&(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:e}),d&&(0,i.jsxs)(n.VStack,{mt:4,spacing:2,children:[(0,i.jsx)(n.Text,{color:`orange.300`,size:`sm`,textAlign:`center`,children:u(`This is taking longer than expected.`)}),(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:u(`You may want to try establishing the connection again.`)})]})]}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:d&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:a,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),u(`Try again`)]})})]})},fa=({error:e,onClose:t,onTryAgain:r,onGoBack:a})=>{let{t:o}=(0,l.useTranslation)(),s=(0,h.useReducedMotion)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(J,{onClick:a}),o(`Connection Failed`),(0,i.jsx)(n.ModalCloseButton,{onClick:t})]})}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,w:`full`,justifyContent:`center`,minH:`100px`,gap:4,children:[(0,i.jsx)(h.motion.div,{transition:{duration:4,ease:`easeInOut`,repeat:s?0:1/0},animate:{scale:s?[1]:[1,1.1,1]},children:(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:`#ef4444`,fontSize:`60px`,opacity:.5})}),(0,i.jsx)(n.Text,{w:`full`,size:`sm`,textAlign:`center`,children:e})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:r,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),o(`Try again`)]})})]})},pa=({onClose:e,appsInfo:r,isLoading:a,setCurrentContent:o,showBackButton:s=!0})=>{let{t:c}=(0,l.useTranslation)(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{setConnectionCache:d}=Vo(),{login:f}=jn(),p=async(n,i)=>{o({type:`loading`,props:{title:`${c(`Connecting with`)} ${i}`,loadingText:c(`Please approve the request in the connection request window...`),onTryAgain:()=>{p(n,i)}}});try{await f(n),d({name:i,logoUrl:r.find(e=>e.id===n)?.logo_url,appId:n,website:r.find(e=>e.id===n)?.website}),e()}catch(e){let a=e?.message;if(a&&t.a(a)){o({type:`ecosystem`,props:{appsInfo:r,isLoading:!1}});return}o({type:`error`,props:{error:(e instanceof Error?e:Error(`An unexpected issue occurred while logging in with this app. Please try again or contact support.`)).message,onTryAgain:()=>{p(n,i)}}})}};return(0,i.jsx)(n.Box,{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[s&&(0,i.jsx)(J,{onClick:()=>o(`main`)}),c(`Already have an x2earn app wallet?`),(0,i.jsx)(n.ModalCloseButton,{onClick:e})]})}),(0,i.jsxs)(n.ModalBody,{children:[a&&(0,i.jsx)(n.VStack,{minH:`200px`,w:`full`,justifyContent:`center`,children:(0,i.jsx)(n.Spinner,{})}),!a&&r&&(0,i.jsx)(n.VStack,{spacing:4,w:`full`,pb:6,children:r.map(e=>(0,i.jsxs)(n.Button,{variant:`loginIn`,fontSize:`14px`,fontWeight:`400`,p:6,borderRadius:16,w:`full`,onClick:()=>{p(e.id,e.name)},justifyContent:`flex-start`,children:[(0,i.jsx)(n.Image,{src:e.logo_url,alt:e.name,w:`30px`}),(0,i.jsx)(n.Text,{ml:5,children:e.name})]},e.id))}),!a&&!r&&(0,i.jsx)(n.Text,{textAlign:`center`,color:u,children:c(`No application from VeChain ecosystem is available to login.`)})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})})},ma=({isOpen:e,onClose:t,initialContent:n=`main`,preventAutoClose:a=!1})=>{let[o,s]=(0,r.useState)(n);(0,r.useEffect)(()=>{e&&s(n)},[e,n,s]);let c=(()=>{if(!o)return(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t,preventAutoClose:a});switch(o){case`main`:return(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t,preventAutoClose:a});case`faq`:return(0,i.jsx)(Xr,{onGoBack:()=>s(`main`)})}if(typeof o==`object`&&`type`in o)switch(o.type){case`ecosystem`:return(0,i.jsx)(pa,{onClose:t,appsInfo:o.props.appsInfo,isLoading:o.props.isLoading,setCurrentContent:s,showBackButton:o.props.showBackButton});case`loading`:return(0,i.jsx)(da,{title:o.props.title,loadingText:o.props.loadingText,onTryAgain:o.props.onTryAgain,onClose:t,onGoBack:()=>s(`main`),showBackButton:o.props.showBackButton});case`error`:return(0,i.jsx)(fa,{error:o.props.error,onClose:t,onTryAgain:o.props.onTryAgain,onGoBack:()=>s(`main`)})}return null})();return c?(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:`260px`,mobileMaxHeight:`400px`,desktopMinHeight:`250px`,desktopMaxHeight:`400px`,children:c}):(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:`260px`,mobileMaxHeight:`400px`,desktopMinHeight:`250px`,desktopMaxHeight:`400px`,children:(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t})})},ha=({onClick:e,text:t,icon:r,customIcon:a,rightIcon:o,style:s,variant:c=`loginIn`,iconWidth:l=`25px`})=>t?t?(0,i.jsxs)(n.Button,{...s,variant:c,w:`full`,onClick:e,children:[(0,i.jsxs)(n.HStack,{w:`full`,justify:`flex-start`,gap:2,children:[a||(0,i.jsx)(n.Icon,{as:r,w:l,h:l}),(0,i.jsx)(n.Text,{opacity:.9,children:t})]}),o]}):null:(0,i.jsx)(n.Button,{...s,variant:c,w:`full`,onClick:e,children:a||(0,i.jsx)(n.Icon,{as:r,w:`20px`,h:`20px`})}),ga=({isLoading:e,buttonStyle:t})=>{let{t:a}=(0,l.useTranslation)(),{loginMethods:o,darkMode:s,privyEcosystemAppIDS:c}=$(),u=o?.some(({method:e})=>e===`ecosystem`),{open:d}=no(),{data:f,isLoading:p}=Ve(c),m=(0,r.useCallback)(e=>{let t=typeof e==`function`?e(`main`):e;typeof t==`object`&&`type`in t?t.type===`ecosystem`?d({type:`ecosystem`,props:{...t.props,showBackButton:!1}}):t.type===`loading`?d({type:`loading`,props:{...t.props,showBackButton:!1}}):d(t):d(t)},[d]);return(0,i.jsx)(n.Popover,{placement:`bottom-start`,size:`xl`,closeOnBlur:!1,variant:`vechainKitBase`,children:({isOpen:r})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.PopoverTrigger,{children:(0,i.jsxs)(n.Button,{isLoading:e,...t,isActive:r,children:[a(`Login`),(0,i.jsx)(n.Icon,{ml:2,as:g.LuChevronDown,transform:r?`rotate(180deg)`:`rotate(0deg)`,transition:`transform 0.2s`})]})}),(0,i.jsxs)(n.PopoverContent,{children:[(0,i.jsx)(n.PopoverBody,{children:(0,i.jsx)(Ar,{setCurrentContent:m})}),(0,i.jsx)(n.PopoverFooter,{borderTop:`none`,pb:`15px`,children:u&&(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(jr,{isDark:s,appsInfo:Object.values(f||{}),isLoading:p,setCurrentContent:m})})})]})]})})},_a=({variant:e})=>{let{account:r}=X();return r?e===`icon`?null:e===`iconAndDomain`?r.domain?(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.G(r?.domain??``,16,0)}):(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.W(r.address??``,6,4)}):e===`iconDomainAndAssets`?(0,i.jsxs)(n.HStack,{spacing:4,children:[(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,children:[r.domain&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,children:t.G(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,"data-testid":`trimmed-address`,children:t.W(r.address??``,4,4)})]}),(0,i.jsx)($r,{address:r.address??``,maxIcons:3})]}):(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,children:[r.domain&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,children:t.G(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,children:t.W(r.address??``,4,4)})]}):(0,i.jsx)(n.Spinner,{})},va=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconAndDomain`,onOpen:r,buttonStyle:a={}})=>{let{account:o}=X(),[s]=(0,n.useMediaQuery)(`(min-width: 768px)`);return(0,i.jsx)(n.Button,{...a,onClick:r,w:`full`,minH:`45px`,maxW:`fit-content`,"data-testid":`wallet-button`,children:(0,i.jsxs)(n.HStack,{w:`full`,minW:`fit-content`,children:[(0,i.jsx)(Mc,{wallet:o,props:{width:30,height:30,minWidth:30,minHeight:30}}),(0,i.jsx)(_a,{variant:s?t:e})]})})},ya=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconDomainAndAddress`,buttonStyle:r,connectionVariant:a=`modal`,label:o=`Login`})=>{let{darkMode:s,loginMethods:c,theme:l}=$(),u=c?.length===1&&c[0].method===`dappkit`,{connection:d,account:p}=X(),{setSource:m,connectV2:h}=(0,f.useWallet)(),[g]=(0,n.useMediaQuery)(`(max-width: 768px)`),_=(0,n.useDisclosure)(),v=(0,n.useDisclosure)(),{open:y}=(0,f.useWalletModal)();return(0,i.jsxs)($a,{darkMode:s,theme:l,children:[d.isConnected&&p?(0,i.jsx)(va,{mobileVariant:e,desktopVariant:t,onOpen:v.onOpen,buttonStyle:r}):a===`popover`&&!g?(0,i.jsx)(ga,{isLoading:d.isLoading,buttonStyle:r}):(0,i.jsx)(n.Button,{isLoading:d.isLoading,onClick:()=>{d.isInAppBrowser?(m(`veworld`),h(null)):u?y():_.onOpen()},...r,children:o}),(0,i.jsx)(ma,{isOpen:_.isOpen,onClose:_.onClose}),(0,i.jsx)(ua,{isOpen:v.isOpen,onClose:v.onClose})]})},ba=()=>{let{darkMode:e}=$(),t=25/2,[r]=(0,n.useMediaQuery)(`(max-width: 280px)`),[a]=(0,n.useMediaQuery)(`(max-width: 380px)`);return(0,i.jsxs)(n.HStack,{spacing:0,ml:0,children:[(0,i.jsx)(n.Circle,{size:`25px`,borderRadius:`full`,bg:`#F8F8F8`,p:2,alignItems:`center`,justifyContent:`center`,zIndex:3,children:(0,i.jsx)(n.Icon,{as:E.FcGoogle,fontSize:`20px`})}),!r&&(0,i.jsx)(n.Circle,{ml:`-${t}px`,size:`25px`,borderRadius:`full`,bg:`black`,p:2,alignItems:`center`,justifyContent:`center`,zIndex:2,children:(0,i.jsx)(n.Icon,{as:j.FaXTwitter,color:`white`,fontSize:`20px`})}),!r&&!a&&(0,i.jsx)(n.Circle,{ml:`-${t}px`,zIndex:1,size:`25px`,borderRadius:`full`,bg:`#5865F2`,p:2,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Icon,{as:j.FaDiscord,color:`white`,fontSize:`20px`})}),(0,i.jsx)(n.Icon,{zIndex:1,as:g.LuPlus,color:e?`black`:`white`,fontSize:`15px`})]})},xa=({status:e,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=t.bt(f.type).explorerUrl,m=(0,r.useMemo)(()=>o?o.reason||d(`Something went wrong. Please try again.`):null,[o,d]),h=(()=>{let t=e===`waitingConfirmation`;switch(t&&(e=`pending`),e){case`pending`:return{icon:(0,i.jsx)(n.Spinner,{size:`md`,"data-testid":`pending-spinner-toast`}),title:d(t?`Processing transaction...`:`Waiting for confirmation...`),closeDisabled:!0,description:t?d(`Transaction is being processed, it can take up to 15 seconds.`):c??d(`Please confirm the transaction in your wallet.`)};case`error`:return{icon:(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:`red.500`,fontSize:`40px`,"data-testid":`error-icon-toast`}),title:d(`Transaction failed`),closeDisabled:!1,description:m};case`success`:return{icon:(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,color:`green.500`,fontSize:`40px`,"data-testid":`success-icon-toast`}),title:d(`Transaction successful!`),closeDisabled:!1,description:void 0};case`ready`:return{icon:null,title:d(`Confirm transaction`),closeDisabled:!1,description:c??d(`Confirm the transaction in your wallet to complete it.`)};default:return{icon:null,title:``,closeDisabled:!1,description:``}}})();return h?(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`flex-start`,w:`full`,children:[(0,i.jsx)(n.VStack,{spacing:4,children:(0,i.jsxs)(n.HStack,{spacing:4,w:`full`,justifyContent:`flex-start`,alignItems:`flex-start`,children:[h.icon,(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,spacing:2,children:[(0,i.jsxs)(n.VStack,{spacing:1,w:`full`,children:[(0,i.jsx)(n.Heading,{w:`full`,size:`xs`,children:h.title}),h.description&&(0,i.jsx)(n.Text,{fontSize:`xs`,children:h.description})]}),(e===`error`||e===`ready`)&&(0,i.jsx)(n.Button,{size:`xs`,onClick:s,children:e===`error`?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),d(`Try again`)]}):d(`Confirm`)}),a&&e!==`pending`&&(0,i.jsxs)(n.Link,{fontSize:`xs`,isExternal:!0,href:`${p}/${a.meta.txID}`,children:[d(`View on explorer`),` `,(0,i.jsx)(n.Icon,{as:g.LuExternalLink})]})]})]})}),!h.closeDisabled&&(0,i.jsx)(n.IconButton,{onClick:u,size:`sm`,borderRadius:`full`,"aria-label":`Close`,icon:(0,i.jsx)(n.Icon,{as:g.LuX,boxSize:4})})]}):null},Sa=({isOpen:e,onClose:t,status:r,txReceipt:a,txError:o,onTryAgain:s,description:c})=>{let{darkMode:l}=$();return e?(0,i.jsx)(n.Box,{position:`fixed`,bottom:`5`,left:`5`,zIndex:`11111`,bg:l?`#1f1f1e`:`white`,borderRadius:`md`,p:5,boxShadow:`lg`,maxW:`sm`,minW:`300px`,children:(0,i.jsx)(xa,{status:r,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:t})}):null},Ca=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.bt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(h.motion.div,{transition:{duration:4,ease:`easeInOut`,repeat:1/0},animate:{scale:[1,1.1,1]},children:(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,fontSize:`100px`,color:p})}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a}),s&&e&&(0,i.jsxs)(n.VStack,{mt:2,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,children:c(`Share on`)}),(0,i.jsx)(aa,{description:f})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:c(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{children:c(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},wa=({setCurrentContent:e,handleClose:t,style:r})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=Is(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Vs({smartAccountAddress:o?.address??``,targetVersion:3,onSuccess:()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:m?.meta.txID,title:a(`Upgrade Successful!`),description:a(`Your account has been successfully upgraded to the latest version. You can now enjoy a better user experience, lower gas costs, and enhanced security.`),onDone:()=>{t()},showSocialButtons:!1}})},onError:()=>{console.error(`Error upgrading Smart Account`)}});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:10,align:`stretch`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a(`To continue interacting with VeChain blockchain and complete your operation, your smart account needs to be upgraded to the latest version (v3).`)}),(0,i.jsxs)(n.HStack,{align:`center`,justifyContent:`space-evenly`,rounded:`md`,children:[(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,borderRadius:`full`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#D23F63`,fontSize:`28px`,children:`v1`})]}),(0,i.jsx)(n.Icon,{as:g.LuArrowRight,color:`#3DBA67`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,borderRadius:`full`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#3DBA67`,fontSize:`28px`,children:`v3`})]})]}),(0,i.jsxs)(n.Alert,{status:`info`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,children:a(`Benefits of this upgrade:`)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,children:(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,mt:1,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,lineHeight:`1.2`,children:[`• `,a(`Improved security features`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`• `,a(`Better transaction handling`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Enhanced compatibility with dApps`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Reduced gas costs for operations`)]})]})})]})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsx)(n.VStack,{spacing:3,w:`full`,children:(0,i.jsx)(Nc,{style:r,buttonText:a(c?`Upgrade account`:`Account already upgraded`),onConfirm:async()=>{try{await u()}catch(e){console.error(`Failed to upgrade Smart Account:`,e)}},isTxWaitingConfirmation:f,isSubmitting:d,transactionPendingText:a(`Upgrading...`),txReceipt:m,transactionError:p,isDisabled:!c})})})]})},Ta=({isOpen:e,onClose:t,style:n})=>{let[a,o]=(0,r.useState)(`upgrade-smart-account`);return(0,r.useEffect)(()=>{e&&o(`upgrade-smart-account`)},[e]),(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,size:n?.modalSize,children:(()=>{if(typeof a==`object`)switch(a.type){case`successful-operation`:return(0,i.jsx)(Ca,{...a.props})}else if(a===`upgrade-smart-account`)return(0,i.jsx)(wa,{setCurrentContent:o,handleClose:t,style:n})})()})},{definePartsStyle:Ea,defineMultiStyleConfig:Da}=(0,n.createMultiStyleConfigHelpers)(I.modalAnatomy.keys),Oa=e=>({vechainKitBase:Ea({dialog:{scrollbarWidth:`none`,overflow:`scroll`,overflowX:`hidden`,rounded:e.modal.rounded??e.borders.radius.modal,backgroundColor:e.colors.background.modal,backdropFilter:e.effects.backdropFilter.modal,border:e.colors.border.modal},overlay:{backgroundColor:e.colors.background.overlay,backdropFilter:e.effects.backdropFilter.overlay},closeButton:{borderRadius:e.borders.radius.full,color:e.colors.text.primary,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8}},_active:{bg:e.buttons.button.bg,opacity:.8}},header:{w:`full`,color:e.colors.text.primary,fontSize:e.fonts.sizes.large,fontWeight:e.fonts.weights.bold,textAlign:`center`,paddingBottom:5,paddingTop:5}})}),ka=e=>Da({variants:Oa(e),defaultProps:{variant:`vechainKitBase`}}),{definePartsStyle:Aa,defineMultiStyleConfig:ja}=(0,n.createMultiStyleConfigHelpers)(I.cardAnatomy.keys),Ma=e=>({vechainKitBase:Aa({container:{backgroundColor:e.colors.background.card,borderRadius:e.borders.radius.medium,width:`full`,border:`none`},body:{p:5,width:`full`},header:{p:5,width:`full`,borderRadius:`${e.borders.radius.medium} ${e.borders.radius.medium} 0 0`},footer:{width:`full`,borderRadius:`0 0 ${e.borders.radius.medium} ${e.borders.radius.medium}`}}),vechainKitWalletCard:Aa({container:{backgroundColor:e.colors.background.card,borderRadius:e.borders.radius.medium,width:`full`,cursor:`pointer`,position:`relative`}}),featureAnnouncement:Aa({body:{backgroundColor:e.buttons.button.bg,borderRadius:e.borders.radius.medium,color:e.colors.text.secondary},container:{borderRadius:e.borders.radius.medium,backgroundColor:`transparent`}}),vechainKitAppCard:Aa({body:{height:`full`,borderRadius:e.borders.radius.medium,backgroundColor:e.colors.background.cardElevated,border:`1px solid ${e.colors.border.default}`},container:{height:`150px`,borderRadius:e.borders.radius.medium,backgroundColor:`transparent`}})}),Na=e=>ja({variants:Ma(e),defaultProps:{variant:`vechainKitBase`}}),Pa=(0,n.defineStyle)({borderRadius:`12px`}),Fa=e=>({loginIn:(0,n.defineStyle)(()=>({bg:e.buttons.loginButton.bg,color:e.buttons.loginButton.color,border:e.buttons.loginButton.border,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.normal,py:6,px:3,rounded:e.buttons.loginButton.rounded??e.borders.radius.large,backdropFilter:e.buttons.loginButton.backdropFilter,_hover:{opacity:.5,_disabled:{opacity:.5,bg:e.buttons.loginButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.loginButton.bg},transition:`all 0.2s`})),loginWithVechain:(0,n.defineStyle)(()=>({color:`white`,bg:`#1a1a1a`,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.normal,py:6,px:3,borderRadius:e.borders.radius.large,border:`1px solid ${e.colors.border.button}`,_hover:{opacity:.5,_disabled:{opacity:.5,bg:`#1a1a1a`}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:`#1a1a1a`},_dark:{color:`#1a1a1a`,bg:`white`,_hover:{_disabled:{bg:`white`}},_disabled:{bg:`white`}},transition:`all 0.2s`})),vechainKitPrimary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.primaryButton.rounded??e.borders.radius.large,bg:e.buttons.primaryButton.bg,color:e.buttons.primaryButton.color,border:e.buttons.primaryButton.border,backdropFilter:e.buttons.primaryButton.backdropFilter,_hover:{...e.buttons.primaryButton.hoverBg?{bg:e.buttons.primaryButton.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.primaryButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.primaryButton.bg},transition:`all 0.2s`})),vechainKitSecondary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.button.rounded??e.borders.radius.large,bg:e.buttons.button.bg,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`})),vechainKitTertiary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.tertiaryButton.rounded??e.borders.radius.large,bg:e.buttons.tertiaryButton.bg,color:e.buttons.tertiaryButton.color,border:e.buttons.tertiaryButton.border===`none`?`none`:e.buttons.tertiaryButton.border,backdropFilter:e.buttons.tertiaryButton.backdropFilter,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.buttons.tertiaryButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.tertiaryButton.bg},transition:`all 0.2s`})),vechainKitLogout:(0,n.defineStyle)(()=>({px:4,width:`full`,height:`60px`,rounded:e.buttons.button.rounded??e.borders.radius.large,bg:e.colors.error+`1f`,color:e.colors.error,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.colors.error+`1f`}},_disabled:{opacity:.5,cursor:`not-allowed`},transition:`all 0.2s`})),vechainKitHeaderIconButtons:(0,n.defineStyle)(()=>({bg:e.buttons.button.bg,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`,rounded:`full`,mt:`8px`})),actionButton:(0,n.defineStyle)(()=>({width:`full`,minHeight:`50px`,height:`fit-content`,bg:e.buttons.button.bg,borderRadius:e.borders.radius.xl,p:0,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`1px solid ${e.colors.border.button}`:e.buttons.button.border,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`})),ghost:(0,n.defineStyle)(()=>({bg:`transparent`,color:e.colors.text.primary,border:`none`,_hover:{bg:e.buttons.button.bg},_active:{bg:e.buttons.button.bg,opacity:.8},transition:`all 0.2s`})),link:(0,n.defineStyle)(()=>({color:e.colors.text.primary,_hover:{color:e.colors.text.secondary,textDecoration:`underline`},_active:{color:e.colors.text.primary},transition:`all 0.2s`}))}),Ia=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e)}),La=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e)}),Ra=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e),defaultProps:{variant:`vechainKitHeaderIconButtons`}}),{definePartsStyle:za,defineMultiStyleConfig:Ba}=(0,n.createMultiStyleConfigHelpers)(I.popoverAnatomy.keys),Va=e=>({vechainKitBase:za({popper:{zIndex:1e3},content:{borderRadius:e.borders.radius.xl,border:e.colors.border.modal,backgroundColor:e.colors.background.modal,backdropFilter:e.effects.backdropFilter.modal,boxShadow:`0px 4px 16px rgba(0, 0, 0, 0.12)`,minWidth:`380px`},body:{padding:`16px`}})}),Ha=e=>Ba({variants:Va(e),defaultProps:{variant:`vechainKitBase`}}),Ua=(e,t)=>({useSystemColorMode:!1,disableTransitionOnChange:!1,components:{Modal:ka(t),Card:Na(t),Button:Ia(t),IconButton:La(t),CloseButton:Ra(t),Popover:Ha(t)},styles:{global:()=>({})},semanticTokens:{colors:{"chakra-placeholder-color":t.colors.text.tertiary,"vechain-kit-modal":t.colors.background.modal,"vechain-kit-overlay":t.colors.background.overlay,"vechain-kit-card":e?`rgba(0, 0, 0, 0.3)`:`rgba(0, 0, 0, 0.05)`,"vechain-kit-card-elevated":e?`rgba(0, 0, 0, 0.4)`:`rgba(0, 0, 0, 0.08)`,"vechain-kit-sticky-header":t.colors.background.stickyHeader,"vechain-kit-text-primary":t.colors.text.primary,"vechain-kit-text-secondary":t.colors.text.secondary,"vechain-kit-text-tertiary":t.colors.text.tertiary,"vechain-kit-border":t.colors.border.default,"vechain-kit-border-hover":t.colors.border.hover,"vechain-kit-border-focus":t.colors.border.focus,"vechain-kit-success":t.colors.success,"vechain-kit-error":t.colors.error,"vechain-kit-warning":t.colors.warning,"vechain-kit-button-primary-bg":t.buttons.primaryButton.bg,"vechain-kit-button-primary-color":t.buttons.primaryButton.color},effects:{"vechain-kit-backdrop-filter-modal":t.effects.backdropFilter.modal,"vechain-kit-backdrop-filter-overlay":t.effects.backdropFilter.overlay,"vechain-kit-backdrop-filter-sticky-header":t.effects.backdropFilter.stickyHeader},config:{cssVarPrefix:`vechain-kit`}},fonts:n.theme.fonts,fontSizes:{...n.theme.fontSizes,sm:t.fonts.sizes.small,md:t.fonts.sizes.medium,lg:t.fonts.sizes.large},fontWeights:{...n.theme.fontWeights,normal:t.fonts.weights.normal,medium:t.fonts.weights.medium,bold:t.fonts.weights.bold},colors:n.theme.colors,space:n.theme.space}),Wa=(e,t)=>{let r=(0,n.extendTheme)(Ua(e,ve(_e(e),ye(t,e))));return r.styles.global=()=>({}),r.__cssVars&&(r.__cssVars.global=()=>({})),r},{ToastContainer:Ga}=(0,n.createStandaloneToast)(),Ka=()=>(0,F.default)({key:`vechain-kit`,prepend:!0}),qa=({bodyFont:e,headingFont:t})=>(0,i.jsx)(P.Global,{styles:P.css`
127
+ }`,o=await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({operationName:`Registrations`,query:a,extensions:{}})});if(!o.ok)throw Error(`Failed to fetch domains`);let s=await o.json();return s.data&&s.data.domains&&(s.data.domains=s.data.domains.filter(e=>!e.name.endsWith(`addr.reverse`))),ut.parse(s.data)},ft=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,e,t],pt=(e,t)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ft(e,t),queryFn:()=>dt(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},mt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,e,t],ht=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:mt(e??``,t.type),queryFn:async()=>e?(0,v.getAvatar)(e,{networkUrl:t.nodeUrl}):null,enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},gt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) view returns (string)`]),_t=async(e,n,r)=>{if(!r)return{};let i=(0,o.namehash)(r);try{let r=new URL(`accounts/*`,e),[{data:a,reverted:o}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.bt(n).vetDomainsContractAddress,data:gt.encodeFunctionData(`resolver`,[i])}]})})).json();if(o)return{};let{resolverAddress:s}=gt.decodeFunctionResult(`resolver`,a);return(await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:t.S.map(e=>({to:s,data:gt.encodeFunctionData(`text`,[i,e])}))})})).json()).reduce((e,{data:n,reverted:r},i)=>{if(!r&&n&&n!==`0x`)try{let r=gt.decodeFunctionResult(`text`,n)[0];r&&(e[t.S[i]]=r)}catch(e){console.error(`Failed to decode text record for ${t.S[i]}:`,e)}return e},{})}catch(e){throw console.error(`Error fetching text records:`,e),e}},vt=(e,t)=>[`VECHAIN_KIT_TEXT_RECORDS`,e,t],yt=e=>{let{network:n}=$(),r=n.nodeUrl??t.bt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:vt(e,n.type),queryFn:()=>_t(r,n.type,e),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},bt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function setText(bytes32 node, string key, string value) external`]),xt=(e,t)=>{let n=[];for(let{domain:r,key:i,value:a}of t){if(!r)throw Error(`Domain is required`);if(!e)throw Error(`Resolver address is required`);let t=(0,o.namehash)(r);n.push({to:e,data:bt.encodeFunctionData(`setText`,[t,i,a]),value:`0`,comment:`Update ${i} record`})}return n},St=({onSuccess:e,onError:t,signerAccountAddress:n,resolverAddress:i}={})=>{let a=(0,r.useCallback)(e=>{if(!i)throw Error(`Resolver address is required`);return xt(i,e)},[i]),o=$n({signerAccountAddress:n,onTxConfirmed:async()=>{await e?.()},onTxFailedOrCancelled:async()=>{await t?.()},privyUIOptions:{title:`Update Profile Information`,description:`Update the profile information associated with your domain`,buttonText:`Sign to continue`}});return{...o,clauses:a,sendTransaction:async e=>o.sendTransaction(a(e))}},Ct=e=>[`VECHAIN_KIT`,`RESOLVER_ADDRESS`,e],wt=e=>{let{network:n}=$();return Qo({address:t.bt(n.type).vetDomainsContractAddress,abi:y.VetDomainsRegistry__factory.abi,method:`resolver`,args:[e?(0,b.namehash)(e):`0x`],queryOptions:{select:e=>e[0],enabled:!!e}})},Tt={Mugshot:new URL(`mugshot.png`,e.w).toString(),Greencart:new URL(`greencart.png`,e.w).toString(),Cleanify:new URL(`cleanify.png`,e.w).toString(),EVearn:new URL(`evearn.png`,e.w).toString()},Et=`vechain_kit_cross_app_connection`,Dt=()=>{let e=t.dt(`vechain_kit_cross_app_connection`);if(!e)return null;try{let t=JSON.parse(e)?.ecosystemApp?.name;return t?Tt[t]??null:null}catch{return null}},Ot=e=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR_OF_ADDRESS`,e],kt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Ot(e),queryFn:async()=>{if(!e||!n.nodeUrl)return Dt()??t.U(e??``);if(n.type!==`main`&&n.type!==`test`)return Dt()??t.U(e);let r=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl});return r&&await(0,v.getAvatar)(r,{networkUrl:n.nodeUrl})||(Dt()??t.U(e??``))},enabled:!!e&&!!n.nodeUrl,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},At=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) returns (string avatar)`]),jt=new o.Interface([`function tokenURI(uint256 tokenId) view returns (string)`,`function uri(uint256 id) view returns (string)`]),Mt=async(e,n,r)=>{if(!r)throw Error(`Name is required`);let i=(0,o.namehash)(r);try{let r=new URL(`accounts/*`,n),[{data:a,reverted:o}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.bt(e).vetDomainsContractAddress,data:At.encodeFunctionData(`resolver`,[i])}]})})).json();if(o)return null;let{resolverAddress:s}=At.decodeFunctionResult(`resolver`,a),[{data:c,reverted:l}]=await(await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:s,data:At.encodeFunctionData(`text`,[i,`avatar`])}]})})).json();if(l||c===`0x`)return null;try{let{avatar:t}=At.decodeFunctionResult(`text`,c),r=t===``?null:t;return r?Pt(r,e,n):null}catch(e){return console.error(`Failed to decode avatar data:`,e),null}}catch(e){throw console.error(`Error fetching avatar using legacy API:`,e),e}},Nt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,`LEGACY`,e,t];async function Pt(e,n,r){try{if(e.startsWith(`http`)||e.startsWith(`ipfs://`)||e.startsWith(`ar://`))return t.g(e,n)||null;let i=e.match(/eip155:(\d+)\/(?:erc721|erc1155):([^/]+)\/(\d+)/);if(i){let[,a,s,c]=i,l=e.includes(`erc1155`);if(!a||!s||c===void 0)return null;let u=[{to:s,data:jt.encodeFunctionData(l?`uri`:`tokenURI`,[BigInt(c||0)])}],d=new URL(`accounts/*`,r),[{data:f,reverted:p}]=await fetch(d,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:u})}).then(e=>e.json());if(p)return console.error(`Failed to fetch tokenURI`),null;let m=``;try{m=jt.decodeFunctionResult(l?`uri`:`tokenURI`,f)[0]}catch(e){console.error(`Failed to decode avatar data:`,e),m=(0,o.toUtf8String)(f)}m=t.g(m,n)||m,l&&(m=m.replace(`{id}`,(0,o.zeroPadValue)((0,o.toBeHex)(BigInt(c||0)),32).slice(2)));let h=await fetch(m);if(!h.ok)return console.error(`Failed to fetch metadata`),null;let g=await h.json(),_=g.image||g.image_url||g.image_data;return _?t.g(_,n)||_:(console.error(`No image URL in metadata`),null)}return null}catch(e){return console.error(`Error parsing avatar record:`,e),null}}const Ft=e=>{let{network:n}=$(),r=n.nodeUrl??t.bt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:Nt(e??``,n.type),queryFn:async()=>e?Mt(n.type,r,e):null,enabled:!!e&&!!r&&!!n.type})},It=y.VetDomainsReverseRegistrar__factory.createInterface(),Lt=(e,n)=>{let r=[];return r.push({to:t.bt(n.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:It.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(e?.address??``,4,4)}`,abi:It.getFunction(`setName`)}),r},Rt=({onSuccess:e,onError:t})=>{let n=(0,p.useQueryClient)(),{account:i}=X(),{network:a}=$(),o=(0,r.useCallback)(()=>Lt(i,a),[i,a]),s=(0,r.useCallback)(async()=>{await Xe(n,i?.address??``,``,``,``,a.type),e?.()},[e,n,i,a.type]),c=$n({signerAccountAddress:i?.address??``,privyUIOptions:{title:`Sign to unset your VeChain nickname`,description:`Unset your current VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:s,onTxFailedOrCancelled:t});return{...c,clauses:o,sendTransaction:async()=>c.sendTransaction(o())}},zt=e=>{let{network:n}=$(),i=t.bt(n.type),{data:a,isLoading:o}=cs(e),{data:s,isLoading:c}=ln(e),{data:l,isLoading:u}=hn(e),{data:d,isLoading:f}=pn(i.veDelegateTokenContractAddress,e),{data:p,isLoading:m}=pn(i.gloDollarContractAddress,e),h=dn(e),g=h.map(e=>e.data).filter(Boolean),_=h.some(e=>e.isLoading);return{balances:(0,r.useMemo)(()=>{if(!e)return[];let t={vet:`0x`,vtho:i.vthoContractAddress,b3tr:i.b3trContractAddress,vot3:i.vot3ContractAddress,veDelegate:i.veDelegate,USDGLO:i.gloDollarContractAddress},n=[{address:t.vet,symbol:`VET`,balance:a?.balance||`0`},{address:t.vtho,symbol:`VTHO`,balance:a?.energy||`0`},{address:t.b3tr,symbol:`B3TR`,balance:s?.scaled??`0`},{address:t.vot3,symbol:`VOT3`,balance:l?.scaled??`0`},{address:t.veDelegate,symbol:`veDelegate`,balance:d?.scaled??`0`},{address:t.USDGLO,symbol:`USDGLO`,balance:p?.scaled??`0`}],r=g.map(e=>({address:e?.address||``,symbol:e?.symbol||``,balance:e?.scaled||`0`}));return[...n,...r]},[e,a,s,l,d,p,g,n.type]),isLoading:o||c||u||f||m||_}},Bt={B3TR:`0x623374722d757364000000000000000000000000000000000000000000000000`,VET:`0x7665742d75736400000000000000000000000000000000000000000000000000`,VTHO:`0x7674686f2d757364000000000000000000000000000000000000000000000000`,GBP:`0x6762702d75736400000000000000000000000000000000000000000000000000`,EUR:`0x657572742d757364000000000000000000000000000000000000000000000000`},Vt=async(e,n,r)=>{let i=await e.contracts.load(t.bt(r).oracleContractAddress,y.OracleVechainEnergy__factory.abi).read.getLatestValue(Bt[n]);if(!i)throw Error(`Failed to get price of ${n}`);return new a.BigNumber(i[0].toString()).div(0xe8d4a51000).toNumber()},Ht=e=>[`VECHAIN_KIT_PRICE`,e],Ut=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ht(e),queryFn:async()=>Vt(t,e,n.type),enabled:!!t&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},Wt=()=>{let{network:e}=$(),n=t.bt(e.type),{data:i,isLoading:a}=Ut(`VET`),{data:o,isLoading:s}=Ut(`VTHO`),{data:c,isLoading:l}=Ut(`B3TR`),{data:u,isLoading:d}=Ut(`EUR`),{data:f,isLoading:p}=Ut(`GBP`);return{prices:(0,r.useMemo)(()=>{let e={vet:`0x`,vtho:n.vthoContractAddress,b3tr:n.b3trContractAddress,vot3:n.vot3ContractAddress,veDelegate:n.veDelegate,USDGLO:n.gloDollarContractAddress};return{[e.vet]:i||0,[e.vtho]:o||0,[e.b3tr]:c||0,[e.vot3]:c||0,[e.veDelegate]:c||0,[e.USDGLO]:1}},[i,o,c,n.vthoContractAddress,n.b3trContractAddress,n.vot3ContractAddress,n.veDelegate,n.gloDollarContractAddress]),exchangeRates:(0,r.useMemo)(()=>({eurUsdPrice:u||1,gbpUsdPrice:f||1}),[u,f]),isLoading:a||s||l||d||p}},Gt=(e,t,n)=>{switch(t){case`eur`:return e/n.eurUsdPrice;case`gbp`:return e/n.gbpUsdPrice;default:return e}},Kt=(e,t=`en`,n)=>{let r={style:`currency`,minimumFractionDigits:2,maximumFractionDigits:2,currency:n?.currency??`usd`,...n};return new Intl.NumberFormat(U[t],r).format(e)},qt=(e,t)=>Kt(e,W.resolvedLanguage,{notation:`compact`,compactDisplay:`short`,currency:t?.currency??`usd`,...t}),Jt=`vechain_kit_currency`,Yt=[`usd`,`eur`,`gbp`],Xt=()=>{let{currentCurrency:e,setCurrency:n}=$();return(0,r.useEffect)(()=>{t.yt(`vechain_kit_currency`,e)},[e]),{currentCurrency:e,allCurrencies:Yt,changeCurrency:e=>{if(!Yt.includes(e)){console.error(`Invalid currency: ${e}`);return}n(e)}}},Zt=({address:e=``})=>{let{balances:t,isLoading:n}=zt(e),{prices:i,exchangeRates:a,isLoading:o}=Wt(),{currentCurrency:s}=Xt(),c=(0,r.useMemo)(()=>t.map(e=>{let t=i[e.address]||0,n=Number(e.balance)*t,r=Gt(n,s,a);return{...e,priceUsd:t,valueUsd:n,valueInCurrency:r}}),[t,i,s,a]),l=(0,r.useMemo)(()=>[...c].sort((e,t)=>t.valueInCurrency-e.valueInCurrency),[c]);return{tokens:c,sortedTokens:l,tokensWithBalance:(0,r.useMemo)(()=>l.filter(e=>Number(e.balance)>0),[l]),isLoading:n||o}},Qt=({address:e=``})=>{let{tokensWithBalance:t,isLoading:n}=Zt({address:e}),{currentCurrency:i}=Xt(),a=(0,r.useMemo)(()=>t.reduce((e,t)=>e+t.valueInCurrency,0),[t]);return{totalBalanceInCurrency:a,totalBalanceUsd:(0,r.useMemo)(()=>t.reduce((e,t)=>e+t.valueUsd,0),[t]),formattedBalance:(0,r.useMemo)(()=>qt(a,{currency:i}),[a,i]),isLoading:n,hasAnyBalance:t.length>0}},$t=y.XAllocationVoting__factory.abi,en=`currentRoundId`,tn=e=>Yo({abi:$t,address:e,method:en}),nn=()=>{let{network:e}=$(),n=t.bt(e.type).xAllocationVotingContractAddress;return Qo({abi:$t,address:n,method:en,args:[],queryOptions:{select:e=>e[0].toString()}})},rn=async(e,t)=>(0,v.getTokenInfo)(e,{networkUrl:t}),an=e=>[`VECHAIN_KIT_CUSTOM_TOKEN_INFO`,e],on=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:an(e),queryFn:async()=>{if(!e)throw Error(`Token address is required`);if(!t.nodeUrl)throw Error(`Network node URL is required`);return rn(e,t.nodeUrl)},enabled:!!t.type&&!!e,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`token address is required`||e===`network node url is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},sn=()=>{let[e,n]=mc(pc.CUSTOM_TOKENS,[]),{network:r}=$(),i=async t=>{if(!o(t)&&!s(t)){if(!r.nodeUrl)throw Error(`Network node URL is required`);let i={...await rn(t,r.nodeUrl),address:t};n([...e,i])}},a=t=>{n(e.filter(e=>e.address!==t))},o=n=>e.some(e=>t.k(e.address,n)),s=e=>{let n={vet:`0x`,vtho:t.bt(r.type).vthoContractAddress,b3tr:t.bt(r.type).b3trContractAddress,vot3:t.bt(r.type).vot3ContractAddress,veDelegate:t.bt(r.type).veDelegate};return Object.values(n).includes(e)};return{customTokens:e,addToken:i,removeToken:a,isTokenIncluded:o,isDefaultToken:s}},cn=e=>[`VEBETTERDAO_BALANCE`,e,`B3TR`],ln=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:cn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,v.getB3trBalance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get b3tr balance`);let i=r[0];return t.H(i)},enabled:!!e&&!!n.type})},un=(e,t)=>[`VECHAIN_KIT_BALANCE`,t,`CUSTOM_TOKEN`,e],dn=e=>{let{network:n}=$(),{customTokens:r}=sn();return(0,p.useQueries)({queries:r.map(r=>({queryKey:un(r.address,e),queryFn:async()=>{if(!r.address)throw Error(`Token address is required`);if(!e)throw Error(`Address is required`);if(!n.nodeUrl)throw Error(`Network node URL is required`);let i=await(0,v.getErc20Balance)(r.address,e,{networkUrl:n.nodeUrl});if(!i)throw Error(`Failed to get token balance`);let a=t.H(i[0]);return{...r,...a}}}))})},fn=(e,t)=>[`VECHAIN_KIT`,`BALANCE`,`ERC20`,e,t],pn=(e,n)=>{let{network:r}=$();return(0,p.useQuery)({queryKey:fn(e,n),queryFn:async()=>{if(!n)throw Error(`Address is required`);let i=await(0,v.getErc20Balance)(e,n,{networkUrl:r.nodeUrl});if(!i)throw Error(`Failed to get vot3 balance`);let a=i[0];return t.H(a)},enabled:!!n&&!!r.type})},mn=e=>[`VEBETTERDAO_BALANCE`,e,`VOT3`],hn=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:mn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,v.getVot3Balance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get vot3 balance`);let i=r[0];return t.H(i)},enabled:!!e&&!!n.type})},gn=(e,t)=>[`VECHAIN_KIT`,`IS_PERSON`,e,t],_n=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:gn(e??``,t.type),queryFn:async()=>{if(!e)throw Error(`User address is required`);return(0,v.getIsPerson)(e,{networkUrl:t.nodeUrl})},enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`user address is required`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},vn=y.XAllocationVoting__factory.abi,yn=`getAppsOfRound`,bn=(e,n)=>Zo({abi:vn,address:t.bt(n).xAllocationVotingContractAddress,method:yn,args:[BigInt(e??0)]}),xn=e=>{let{network:n}=$(),r=t.bt(n.type).xAllocationVotingContractAddress;return Qo({abi:vn,address:r,method:yn,args:[BigInt(e??0)],queryOptions:{enabled:!!e,select:e=>e[0].map(e=>({id:e.id.toString(),teamWalletAddress:e.teamWalletAddress,name:e.name,metadataURI:e.metadataURI,createdAtTimestamp:e.createdAtTimestamp.toString()}))}})},Sn=y.XAllocationPool__factory.abi,Cn=`getAppShares`,wn=e=>[`VECHAIN_KIT`,`XApps`,`Shares`,e],Tn=(e,n)=>{let r=(0,f.useThor)(),{network:i}=$(),a=t.bt(i.type).xAllocationPoolContractAddress;return(0,p.useQuery)({queryKey:wn(n),queryFn:async()=>(await t.r({thor:r,calls:e.map(e=>({abi:Sn,functionName:`getAppShares`,address:a,args:[n,e]}))})).map((t,n)=>({app:e[n],share:Number(t[0]||0)/100,unallocatedShare:Number(t[1]||0)/100})),enabled:!!n&&!!e.length})},En=e=>{let{data:t}=xn(e),n=Tn(t?.map(e=>e.id)??[],e);return{data:(0,r.useMemo)(()=>n.data?.map(e=>({percentage:e.share+e.unallocatedShare,id:t?.find(t=>t.id===e.app)?.id??``,app:t?.find(t=>t.id===e.app)??{}})).sort((e,t)=>Number(t.percentage)-Number(e.percentage))??[],[n.data,t]),isLoading:n.isLoading}},Dn=({error:e,mobileBrowserPopupMessage:n=`Mobile browser blocked the window. Please try again.`,rejectedMessage:r=`Request was cancelled.`,defaultMessage:i=`Operation failed`})=>{let a=e?.message;return w.isMobile&&a&&!t.a(a)?Error(n):a&&t.a(a)?Error(r):e instanceof Error?e:Error(i)},On=(0,b.defineChain)({id:`1176455790972829965191905223412607679856028701100105089447013101863`,name:`Vechain`,nativeCurrency:{name:`VeChain`,symbol:`VET`,decimals:18},rpcUrls:{default:{http:[e.E]}},blockExplorers:{default:{name:`Vechain Explorer`,url:e.S},vechainStats:{name:`Vechain Stats`,url:e.b}}}),kn=()=>(0,C.toPrivyWalletConnector)({id:t.at,name:`VeChain`,iconUrl:`https://imagedelivery.net/oHBRUd2clqykxgDWmeAyLg/661dd77c-2f9d-40e7-baa1-f4e24fd7bf00/icon`,smartWalletMode:!1}),An=({privyEcosystemAppIDS:e,children:t})=>(0,i.jsx)(S.WagmiProvider,{config:(0,r.useRef)((0,S.createConfig)({chains:[On],ssr:!0,connectors:[kn(),...e.map(e=>(0,C.toPrivyWalletConnector)({id:e,name:``,iconUrl:``}))],transports:{[On.id]:(0,S.http)()},multiInjectedProviderDiscovery:!1})).current,children:t}),jn=()=>{let{connectAsync:e,connectors:n}=(0,S.useConnect)(),{signTypedDataAsync:i}=(0,S.useSignTypedData)(),{signMessageAsync:a}=(0,S.useSignMessage)(),{disconnectAsync:o}=(0,S.useDisconnect)(),{isConnected:s}=(0,S.useAccount)(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{try{s&&(await o(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`)))}catch(e){throw console.error(`Error during logout:`,e),e}},[o,s]);return{login:(0,r.useCallback)(async r=>{try{l(!0),d(null);let i=n.find(e=>e.id===(r||t.at));if(!i)throw Error(`Connector not found`);return await e({connector:i})}catch(e){throw d(e),e}finally{l(!1)}},[e,n]),logout:f,signMessage:(0,r.useCallback)(async e=>{try{return await a({message:e})}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the signing window. Please click 'Try again' to open the signing window or change your browser settings.`,rejectedMessage:`Signing request was cancelled.`,defaultMessage:`An unexpected issue occurred while signing a message. Please try again or contact support.`})}},[a]),signTypedData:(0,r.useCallback)(async e=>{try{return await i(e)}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the signing window. Please click 'Try again' to open the signing window or change your browser settings.`,rejectedMessage:`Signing request was cancelled.`,defaultMessage:`An unexpected issue occurred while signing typed data. Please try again or contact support.`})}},[i]),isConnecting:c,connectionError:u}},Mn=(e,n)=>{let{data:r,isLoading:i}=Ge(e??``),{data:a,isLoading:o}=kt(e??``),{data:s,isLoading:c}=yt(r?.domain??``),l=s?.header?t.g(s.header,n):null;return{domain:r?.domain,image:a,records:{...s,header:l},isLoading:i||o||c}},Nn=()=>{let{network:e}=$(),n=(0,r.useCallback)(e=>({wallets:`vechain_kit_wallets_${e}`,activeWallet:`vechain_kit_active_wallet_${e}`}),[]),i=(0,r.useCallback)(()=>{if(!t.mt())return[];let r=t.dt(n(e.type).wallets);return r?JSON.parse(r):[]},[e.type,n]),a=(0,r.useCallback)(()=>t.mt()?t.dt(n(e.type).activeWallet):null,[e.type,n]),o=(0,r.useCallback)(r=>{if(!t.mt())return;let a=n(e.type),o=i(),s=o.findIndex(e=>e.address.toLowerCase()===r.toLowerCase()),c={address:r,connectedAt:s>=0?o[s].connectedAt:Date.now(),isActive:!1};s>=0?o[s]=c:o.push(c),t.yt(a.wallets,JSON.stringify(o))},[e.type,n,i]),s=(0,r.useCallback)(r=>{if(!t.mt())return;let a=n(e.type),o=i().map(e=>({...e,isActive:e.address.toLowerCase()===r.toLowerCase()}));t.yt(a.wallets,JSON.stringify(o)),t.yt(a.activeWallet,r)},[e.type,n,i]);return{getStoredWallets:i,getActiveWallet:a,saveWallet:o,setActiveWallet:s,removeWallet:(0,r.useCallback)(r=>{if(!t.mt())return;let o=n(e.type),s=i().filter(e=>e.address.toLowerCase()!==r.toLowerCase());t.yt(o.wallets,JSON.stringify(s));let c=a();c&&c.toLowerCase()===r.toLowerCase()&&t.gt(o.activeWallet),t.mt()&&window.dispatchEvent(new CustomEvent(`wallet_removed`,{detail:{address:r}}))},[e.type,n,i,a]),initializeCurrentWallet:(0,r.useCallback)(e=>{t.mt()&&i().length===0&&(o(e),s(e))},[i,o,s])}},X=()=>{let{address:e,isConnected:n,isConnecting:i,isReconnecting:a}=(0,S.useAccount)(),{logout:o}=jn(),{loading:s}=(0,u.useLoginWithOAuth)({}),{feeDelegation:c,network:l,privy:d}=$(),{user:p,authenticated:m,logout:h,ready:g}=(0,u.usePrivy)(),{data:_}=qs(),{account:v,disconnect:y}=(0,f.useWallet)(),{getConnectionCache:b,clearConnectionCache:x}=Vo(),C=b(),{initializeCurrentWallet:w,getActiveWallet:T,saveWallet:E,getStoredWallets:D}=Nn(),O=rs(),k=(0,r.useMemo)(()=>t.mt()?!!window.vechain?.isInAppBrowser:!1,[]),A=!!v,j=m&&!!p,M=j||n,N=j&&d?.appId===t.at||n&&C?.ecosystemApp?.appId===t.at,P=i||a||s||!g,[F,I]=(0,r.useState)(!1),L=n?{type:`privy-cross-app`,displayName:`Ecosystem`}:A?{type:`wallet`,displayName:`Wallet`}:{type:`privy`,displayName:`Social Login`};(0,r.useEffect)(()=>{let e=A||j||n;F!==e&&(I(e),e||(x(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`))))},[A,j,n,x,F]);let R=p?.linkedAccounts?.find(e=>e.type===`wallet`&&e.connectorType===`embedded`)?.address,z=A?v:n?e:R,[B,ee]=(0,r.useState)(()=>A&&!k?T():null);(0,r.useEffect)(()=>{ee(A&&!k?T():null)},[A,k,T]);let[te,V]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(!t.mt()||!A||k)return;let e=e=>{V(!0),ee(e.detail.address),setTimeout(()=>{V(!1)},1e3)};return window.addEventListener(`wallet_switched`,e),()=>{window.removeEventListener(`wallet_switched`,e)}},[A,k]);let ne=D().some(e=>e.address.toLowerCase()===z?.toLowerCase()),re=A&&!k?T():null,ie=te&&re||re&&ne?re:z,{data:H}=Ns(ie??``),ae=A?ie:H?.address,U=Mn(ae??``,l.type),oe=Mn(ie??``,l.type),W=Mn(H?.address??``,l.type),{setActiveWallet:se}=Nn(),ce=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{if(!t.mt()||!A||k)return;let e=e=>{ce.current.add(e.detail.address.toLowerCase()),setTimeout(()=>{ce.current.delete(e.detail.address.toLowerCase())},5e3)};return window.addEventListener(`wallet_removed`,e),()=>{window.removeEventListener(`wallet_removed`,e)}},[A,k]),(0,r.useEffect)(()=>{if(A&&!k&&z&&U&&!U.isLoading){if(ce.current.has(z.toLowerCase()))return;let e=!D().some(e=>e.address.toLowerCase()===z.toLowerCase());w(z),E(z);let t=!B,n=B&&B.toLowerCase()===z.toLowerCase();(e||t||n)&&!te&&se(z)}},[A,k,z,U?.domain,U?.image,U?.isLoading,w,E,se,B,D]),(0,r.useEffect)(()=>{A&&!k&&B&&B.toLowerCase()===ie?.toLowerCase()&&E(B)},[A,k,B,ie,E]);let G=ae?{address:ae,domain:U.domain,image:U.image,isLoadingMetadata:U.isLoading,metadata:U.records}:null,le=z?{address:z,domain:oe.domain,image:oe.image,isLoadingMetadata:oe.isLoading,metadata:oe.records}:null,{data:ue}=bs(H?.address??``,le?.address??``),de=!!H?.address&&!!G?.address&&t.k(H?.address,G?.address),K=(0,r.useCallback)(async()=>{try{I(!1),A?y():j?await h():n&&await o(),x(),t.mt()&&window.dispatchEvent(new Event(`wallet_disconnected`))}catch(e){console.error(`Error during disconnect:`,e)}},[A,y,j,h,n,o,x]);return{account:G,smartAccount:{address:H?.address??``,domain:W.domain,image:W.image,isDeployed:H?.isDeployed??!1,isActive:de,version:ue?.version??null,isLoadingMetadata:W.isLoading,metadata:W.records},connectedWallet:le,privyUser:p,connection:{isLoading:P,isConnected:F,isConnectedWithSocialLogin:j,isConnectedWithDappKit:A,isConnectedWithCrossApp:n,isConnectedWithPrivy:M,isConnectedWithVeChain:N,source:L,isInAppBrowser:k,nodeUrl:O,delegatorUrl:c?.delegatorUrl,chainId:_,network:l.type},disconnect:K}},Pn=()=>{let e=(0,p.useQueryClient)(),{account:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.invalidateQueries({queryKey:[`VECHAIN_KIT_BALANCE`,n]}),e.invalidateQueries({queryKey:[`VECHAIN_KIT_PRICE`]})])}}},Fn=()=>{let{switchWallet:e}=(0,f.useWallet)(),{connection:n}=X(),[i,a]=(0,r.useState)(!1),{getStoredWallets:o,setActiveWallet:s,removeWallet:c}=Nn(),l=n.isInAppBrowser;return{switchWallet:(0,r.useCallback)(async()=>{if(l){if(!e)return;a(!0);try{await e()}catch{}finally{a(!1)}}else return Promise.resolve()},[e,l]),isSwitching:i,getStoredWallets:o,setActiveWallet:(0,r.useCallback)(e=>{s(e),t.mt()&&window.dispatchEvent(new CustomEvent(`wallet_switched`,{detail:{address:e}}))},[s]),removeWallet:c,isInAppBrowser:l}},In=async(e,n)=>{let r=t.g(e,n)||``,i=await fetch(r,{signal:AbortSignal.timeout(2e4)});if(!i.ok)throw Error(`HTTP error! status: ${i.status}`);return await i.json()},Ln=y.X2EarnApps__factory.abi,Rn=e=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:[`xAppMetaData`,e],queryFn:async()=>{let i=t.bt(r.type).x2EarnAppsContractAddress,a=n.contracts.load(i,Ln),o=(await a.read.app(e))[0][3]?.toString()||``,[s]=await a.read.baseURI();return await In(`${s}${o}`,r.type)},enabled:!!e})},zn=async(e,n,r=!1)=>{if(!n)throw Error(`No URI provided`);let i=t.g(n,e);if(!i)throw Error(`Invalid URI`);let a=await(await fetch(i,{headers:{"X-Project-Id":`vechain-kit`}})).text();return r?JSON.parse(a):a},Bn=(e,t)=>[`VECHAIN_KIT`,`IPFS_METADATA`,e,t],Vn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Bn(n.type,e),queryFn:()=>zn(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`no uri provided`||e===`invalid uri`)return!1}return e<2},staleTime:1/0})},Hn=1024*1024*10,Un=async(e,n)=>{if(!n)throw Error(`IPFS URI is required`);let r=await fetch(t.g(n,e)??``,{headers:{"X-Project-Id":`vechain-kit`}});if(!r.ok)throw Error(`HTTP error! status: ${r.status}`);let i=await r.blob();if(![`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/bmp`,`image/tiff`,`image/webp`,`image/svg+xml`].includes(i.type))throw Error(`Unsupported MIME type: ${i.type}`);if(i.size>Hn)throw Error(`Image size exceeds maximum allowed size`);return new Promise((e,n)=>{let r=new FileReader;r.readAsDataURL(i),r.onloadend=()=>{e({image:r.result,mime:i.type,mediaType:t._(i.type)})},r.onerror=()=>{n(Error(`Error occurred while reading blob.`))}})},Wn=(e,t)=>[`VECHAIN_KIT`,`IPFS_IMAGE`,e,t],Gn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:Wn(t.type,e),queryFn:()=>Un(t.type,e),enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`ipfs uri is required`)return!1}return e<2},staleTime:1/0})},Kn=e=>{let{network:t}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Wn(t.type,e),queryFn:()=>Un(t.type,e),enabled:!!e&&!!t.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`ipfs uri is required`)return!1}return e<2},staleTime:1/0}))})},qn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Bn(n.type,e),queryFn:async()=>zn(n.type,e,t),enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`no uri provided`||e===`invalid uri`)return!1}return e<2},staleTime:1/0}))})},Jn={maxSizeMB:.4,maxWidthOrHeight:1920,useWebWorker:!0},Yn=async e=>{let t=[];try{for(let n of e){let e=await(0,T.default)(n.file,Jn);t.push(e)}return t}catch(e){throw console.error(`compress error`,e),e}},Xn=({compressImages:e,defaultImages:t})=>{let[n,i]=(0,r.useState)(t??[]);(0,r.useEffect)(()=>{t&&i(t)},[t]);let[a,o]=(0,r.useState)([]),s=(0,r.useCallback)(e=>i(t=>t.filter((t,n)=>n!==e)),[]);return{uploadedImages:n,setUploadedImages:i,onUpload:(0,r.useCallback)(async(t,n=!0)=>{o([]);let r=[];for(let n of t){let t=n;e&&(t=await(0,T.default)(n,Jn));let i={file:t,image:URL.createObjectURL(n)};r.push(i)}i(e=>[...r,...n?e.filter(e=>!r.some(t=>t.file.name===e.file.name)):[]])},[e]),onRemove:s,invalidDateError:a}},Zn=({compressImage:e,defaultImage:t})=>{let[n,i]=(0,r.useState)(t);(0,r.useEffect)(()=>{t&&i(t)},[t]);let a=(0,r.useCallback)(()=>i(void 0),[]);return{uploadedImage:n,setUploadedImage:i,onUpload:(0,r.useCallback)(async t=>{let n=t;e&&(n=await(0,T.default)(n,Jn));let r={file:n,image:URL.createObjectURL(n)};return i(r),r},[e]),onRemove:a}},Qn=async(e,t,n,r)=>{let i=await e.transactions.estimateGas(t,n,r);if(i.reverted)throw Error(`Failed to estimate gas`);let a=i?.totalGas??0;return(!a||Number.isNaN(a))&&(a=0),Math.ceil(a)},$n=({signerAccountAddress:e,clauses:t,onTxConfirmed:n,onTxFailedOrCancelled:i,suggestedMaxGas:a,privyUIOptions:o,gasPadding:c,delegationUrl:l})=>{let u=(0,f.useThor)(),{signer:d,requestTransaction:p}=(0,f.useWallet)(),{connection:m}=X(),{feeDelegation:h}=$(),g=rs(),_=rl(),v=(0,r.useCallback)(async(t,n,r)=>{let i=typeof t==`function`?await t():t??[];if(m.isConnectedWithPrivy)return await _.sendTransaction({txClauses:i,...r,delegationUrl:n});if(!e)throw Error(`signerAccountAddress is required`);let o=0;try{o=await Qn(u,[...i],e,{revision:s.Revision.NEXT,...c?{gasPadding:c}:{}})}catch(e){console.error(`Gas estimation failed`,e)}return(await p(i,{signer:m.isConnectedWithDappKit&&!m.isInAppBrowser&&e?e:d.address,gas:a??o,...h?.delegateAllTransactions||n?{delegator:{url:n??h?.delegatorUrl??``,signer:e}}:{}})).txid},[e,a,g,_,o,h,u,d,c,l,p,m.isConnectedWithDappKit,m.isInAppBrowser]),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(null),T=(0,r.useCallback)(async(e,n)=>{if(!e&&!t)throw Error(`clauses are required`);try{b(null),S(!0),w(null),j(void 0),b(await v(e??[],n,{...o}))}catch(e){w(e&&typeof e==`object`&&`message`in e?e.message:String(e)),i?.(e instanceof Error?e:Error(String(e)))}finally{S(!1)}},[v,t,o,l]),{data:E,isLoading:D,error:O}=ac(y??``),k=(0,r.useCallback)(async e=>{if(!(!e.reverted||!e.meta.txID))return await u.transactions.getRevertReason(e.meta.txID)},[u]),[A,j]=(0,r.useState)(),M=(0,r.useMemo)(()=>{if(x)return`pending`;if(C)return`error`;if(y){if(D)return`waitingConfirmation`;if(O)return`error`;if(E)return E.reverted?`error`:`success`}return`ready`},[D,C,x,y,E,O]);(0,r.useEffect)(()=>{if(M===`success`||M===`error`){if(C&&!A){j({type:`UserRejectedError`,reason:C});return}if(E?.reverted&&!A?.type){(async()=>{let e=await k(E);j({type:`RevertReasonError`,reason:e?`Transaction reverted with: `+e:`Transaction reverted`})})();return}E&&!E.reverted&&n?.()}},[M,E,n,k,C]);let N=(0,r.useCallback)(()=>{b(null),S(!1),w(null),j(void 0)},[]);return{sendTransaction:T,isTransactionPending:(0,r.useMemo)(()=>x||D||M===`pending`||M===`waitingConfirmation`,[x,D,M]),isWaitingForWalletConfirmation:(0,r.useMemo)(()=>M===`pending`,[x,M]),txReceipt:E??null,status:M,resetStatus:N,error:A}},er=(e,t)=>{let{account:n}=X(),{t:i}=(0,l.useTranslation)(),{sendTransaction:a,isTransactionPending:o,isWaitingForWalletConfirmation:s,txReceipt:c,status:u,resetStatus:d,error:f}=$n({signerAccountAddress:n?.address??``,privyUIOptions:{title:i(`ConfirmSwapTitle`,{defaultValue:`Confirm Swap`}),description:i(`ConfirmSwapDescription`,{defaultValue:`Please confirm the swap transaction in your wallet`}),buttonText:i(`Confirm`,{defaultValue:`Confirm`})}});return{executeSwap:(0,r.useCallback)(async()=>{if(!e||!t)throw Error(`Missing swap parameters or quote`);if(!t.aggregator)throw Error(`Aggregator not found for quote from ${t.aggregatorName}`);let n=await t.aggregator.buildSwapTransaction(e,t);if(n.length===0)throw Error(`Failed to build swap transaction`);await a(n)},[e,t,a]),isTransactionPending:o,isWaitingForWalletConfirmation:s,txReceipt:c,status:u,resetStatus:d,error:f}},tr=e=>e===`0x`||e===b.zeroAddress,nr=(e,t,n,r)=>{let i={},a=r.toLowerCase();for(let t of e)try{let e=(0,b.decodeEventLog)({abi:s.ERC20_ABI,eventName:`Transfer`,topics:t.topics,data:t.data}),n=e.args.from.toLowerCase(),r=e.args.to.toLowerCase(),o=e.args.value,c=typeof o==`bigint`?o:BigInt(o);if(n!==a&&r!==a)continue;let l=t.address.toLowerCase(),u=i[l]??{inflow:0n,outflow:0n};n===a&&(u.outflow+=c),r===a&&(u.inflow+=c),i[l]=u}catch{continue}if(n!==void 0){let e=BigInt(n);if(e>0n){let t=i[b.zeroAddress]??{inflow:0n,outflow:0n};t.outflow+=e,i[b.zeroAddress]=t}}for(let e of t){if(e.recipient.toLowerCase()!==a)continue;let t=BigInt(e.amount);if(t<=0n)continue;let n=i[b.zeroAddress]??{inflow:0n,outflow:0n};n.inflow+=t,i[b.zeroAddress]=n}return i},rr=async(e,t,n,r)=>{try{if(n.length===0)return{gasCostVTHO:0,success:!1,error:`No clauses found for simulation`};let i=await r.transactions.simulateTransaction(n,{caller:e.userAddress}),a=!1,o,s=2e5,c={};for(let t=0;t<i.length;t++){let r=i[t];r.reverted&&(a=!0,o=r.vmError||`Transaction reverted`),s+=r.gasUsed;let l=n[t],u=nr(r.events,r.transfers,l?.value,e.userAddress);for(let[e,t]of Object.entries(u)){let n=c[e]??{inflow:0n,outflow:0n};c[e]={inflow:n.inflow+t.inflow,outflow:n.outflow+t.outflow}}}if(a)return{gasCostVTHO:0,success:!1,error:o||`Transaction reverted`};let l=s/1e5,u=tr(e.fromTokenAddress),d=tr(e.toTokenAddress),f=BigInt(e.amountIn);if(u){let e=c[b.zeroAddress]??{inflow:0n,outflow:0n};if(e.outflow>f)return{gasCostVTHO:l,success:!1,error:`VET outflow mismatch: expected ${f.toString()}, got ${e.outflow.toString()}`};for(let[e,t]of Object.entries(c))if(e!==b.zeroAddress&&t.outflow>0n)return{gasCostVTHO:l,success:!1,error:`Unexpected token outflow: token ${e} has outflow ${t.outflow.toString()}, expected 0`}}else{let t=e.fromTokenAddress.toLowerCase(),n=c[t]??{inflow:0n,outflow:0n};if(n.outflow>f)return{gasCostVTHO:l,success:!1,error:`Token outflow mismatch: expected ${f.toString()}, got ${n.outflow.toString()}`};for(let[e,n]of Object.entries(c))if(e!==t&&n.outflow>0n)return{gasCostVTHO:l,success:!1,error:`Unexpected token outflow: ${e===b.zeroAddress?`VET`:e} has outflow ${n.outflow.toString()}, expected 0`}}if(t.minimumOutputAmount&&t.minimumOutputAmount>0n)if(d){let e=c[b.zeroAddress]??{inflow:0n,outflow:0n};if(e.inflow<t.minimumOutputAmount)return{gasCostVTHO:l,success:!1,error:`VET inflow mismatch: expected ${t.minimumOutputAmount.toString()}, got ${e.inflow.toString()}`}}else{let n=c[e.toTokenAddress.toLowerCase()]??{inflow:0n,outflow:0n};if(n.inflow<t.minimumOutputAmount)return{gasCostVTHO:l,success:!1,error:`Token inflow mismatch: expected ${t.minimumOutputAmount.toString()}, got ${n.inflow.toString()}`}}return{gasCostVTHO:l,success:!0}}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Simulation failed`}}},ir=e=>e.startsWith(`0x`)?BigInt(e).toString():e,ar=(e,t)=>({name:e,type:`function`,inputs:t.map(e=>({name:e.name,type:e.type,internalType:e.internalType,components:e.components})),outputs:[],stateMutability:`nonpayable`}),or=(e,t)=>{if(Array.isArray(e)&&e.length>0){let n=e[0];if(typeof n==`object`&&`name`in n&&`type`in n&&n.type===`function`)return e;if(typeof n==`object`&&`name`in n&&`type`in n&&!(`stateMutability`in n||`outputs`in n))return[ar(t,e)]}return e},sr=e=>{try{let t=e.functionName||e.name;if(!t)throw Error(`Function name is required (either functionName or name must be provided)`);return(0,b.encodeFunctionData)({abi:or(e.abi,t),functionName:t,args:e.args})}catch(t){console.error(`Failed to encode function call:`,t);let n=e.functionName||e.name||`unknown`;throw Error(`Failed to encode function call ${n}: ${t instanceof Error?t.message:`Unknown error`}`)}},cr=e=>{let t=sr(e.functionCall);return{to:e.to,value:ir(e.value),data:t,comment:e.comment||`Swap on aggregator`}},lr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){try{let r=new URLSearchParams({fromAddress:n.fromTokenAddress,toAddress:n.toTokenAddress,amountIn:n.amountIn,recipient:n.userAddress,slippageBps:String((n.slippageTolerance||1)*100),network:e.network}),i=new URL(e.apiBaseUrl);i.search=r.toString();let a=await fetch(i);if(!a.ok)throw Error(`API request failed: ${a.status} ${a.statusText}`);let o=await a.json(),s=o.clauses.map(cr),c=BigInt(o.amountOut),l=BigInt(o.amountOutMin);return{aggregatorName:e.name,aggregator:t,outputAmount:c,minimumOutputAmount:l,priceImpact:0,data:{clauses:s,path:o.path}}}catch(n){return console.error(`${e.name} getQuote failed:`,n),{aggregatorName:e.name,aggregator:t,outputAmount:0n,priceImpact:0,minimumOutputAmount:0n,data:{clauses:[],path:[]}}}},async simulateSwap(e,t,n){try{return rr(e,t,await this.buildSwapTransaction(e,t),n)}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Failed to build swap transaction for simulation`}}},async buildSwapTransaction(t,n){if(!n.data||typeof n.data!=`object`||!(`clauses`in n.data))throw Error(`Invalid quote data: clauses not found`);let r=n.data.clauses;if(r.length===0)throw Error(`No clauses found in quote`);if(e.supportedAddresses&&e.supportedAddresses.length>0){let t=e.supportedAddresses.map(e=>e.toLowerCase());if(r=r.filter(e=>e.to?t.includes(e.to.toLowerCase()):!1),r.length===0)throw Error(`No clauses found matching supported addresses`)}if(!n.minimumOutputAmount||n.minimumOutputAmount===0n)throw Error(`Invalid quote: minimumOutputAmount is missing or zero`);return r}};return t},ur={main:{supportedAddresses:[`0xE5fA980a6EfE5B79C2150a529da06AeF455963b6`,`0x7C755EC0165fCD926cC6faB10E7BB16a72E9f34A`]},test:{supportedAddresses:[]},solo:{supportedAddresses:[]}},dr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,fr=t=>new URL(`api/quote/vck`,e.O).toString(),pr=t=>{let n=ur[t]??ur.main,i=lr({name:`VeTrade.vet`,apiBaseUrl:fr(t),network:t,getIcon:(t=`20px`)=>r.default.createElement(e.t,{boxSize:t}),supportedAddresses:n.supportedAddresses});return{...i,async simulateSwap(e,t,n){try{return rr(e,t,await this.buildSwapTransaction(e,t),n)}catch(e){return{gasCostVTHO:0,success:!1,error:e instanceof Error?e.message:`Simulation failed`}}},async buildSwapTransaction(e,t){let r=[],a=await i.buildSwapTransaction(e,t);if(!a||a.length===0)throw Error(`Failed to build swap transaction`);if(dr(e.fromTokenAddress))a[0].value=e.amountIn;else{if(n.supportedAddresses.length===0)throw Error(`No supported addresses configured for VeTrade on this network`);let i=s.ABIContract.ofAbi(y.IERC20__factory.abi),o=s.Address.of(e.fromTokenAddress),c=BigInt(e.amountIn);r.push(s.Clause.callFunction(o,i.getFunction(`approve`),[a[0].to,c.toString()],s.VET.of(0n,s.Units.wei),{comment:`Approve ${t.aggregatorName} to access ${e.fromTokenAddress}`}))}return r.push(...a),r}}},mr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,hr=()=>BigInt(Math.floor(Date.now()/1e3)+1200),gr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){let i=[mr(n.fromTokenAddress)?e.wrappedVET:n.fromTokenAddress,mr(n.toTokenAddress)?e.wrappedVET:n.toTokenAddress],a=BigInt(n.amountIn);try{let[o]=await r.contracts.load(e.routerAddress,y.UniswapV2Router02__factory.abi).read.getAmountsOut(a,i),s=Array.isArray(o)?o:[o],c=s[s.length-1];if(!c||c===0n)throw Error(`Output amount is zero or invalid`);if(typeof c!=`bigint`)throw Error(`Output amount is not a valid bigint`);let l=n.slippageTolerance||1,u=c*BigInt(1e4-l*100)/BigInt(1e4);return{aggregatorName:e.name,aggregator:t,outputAmount:c,priceImpact:0,minimumOutputAmount:u,data:{path:i,routerAddress:e.routerAddress}}}catch(n){return console.error(`${e.name} getQuote failed:`,n),{aggregatorName:e.name,aggregator:t,outputAmount:0n,priceImpact:0,minimumOutputAmount:0n,data:{path:i,routerAddress:e.routerAddress}}}},async simulateSwap(e,t,n){return rr(e,t,await this.buildSwapTransaction(e,t),n)},async buildSwapTransaction(t,n){if(!n.data||typeof n.data!=`object`||!(`path`in n.data))throw Error(`Invalid quote data`);let r=hr();if(!n.minimumOutputAmount||n.minimumOutputAmount===0n)throw Error(`Invalid quote: minimumOutputAmount is missing or zero`);let i=n.minimumOutputAmount,a=BigInt(t.amountIn);if(i===0n)throw Error(`Invalid quote: minimumOutputAmount is zero`);let o=mr(t.fromTokenAddress),c=mr(t.toTokenAddress),l=s.ABIContract.ofAbi(y.UniswapV2Router02__factory.abi),u=[];if(o)u.push(s.Clause.callFunction(s.Address.of(e.routerAddress),l.getFunction(`swapExactETHForTokens`),[i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(a,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`}));else{let o=s.ABIContract.ofAbi(y.IERC20__factory.abi),d=s.Address.of(t.fromTokenAddress),f=s.Address.of(e.routerAddress);u.push(s.Clause.callFunction(d,o.getFunction(`approve`),[f.toString(),a.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`})),c?u.push(s.Clause.callFunction(f,l.getFunction(`swapExactTokensForETH`),[a.toString(),i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`})):u.push(s.Clause.callFunction(f,l.getFunction(`swapExactTokensForTokens`),[a.toString(),i.toString(),n.data.path,t.userAddress,r.toString()],s.VET.of(0n,s.Units.wei),{comment:`Swap on ${n.aggregatorName}`}))}return u}};return t},_r={main:{routerAddress:`0xf21Dd7108D93af56FaB07423EfB90F4a3604DA89`,wrappedVET:`0xf9b02b47694fd635A413F16dC7B38aF06Cc16fe5`},test:{routerAddress:b.zeroAddress,wrappedVET:b.zeroAddress},solo:{routerAddress:b.zeroAddress,wrappedVET:b.zeroAddress}},vr=t=>{let n=_r[t]??_r.main;return gr({name:`BetterSwap.io`,routerAddress:n.routerAddress,wrappedVET:n.wrappedVET,getIcon:(t=`20px`)=>r.default.createElement(e.n,{boxSize:t})})},yr=e=>[pr(e),vr(e)],br=(e,t,n,i,a=1,o=!0)=>{let s=(0,f.useThor)(),{connection:c}=X(),l=e?.address??null,u=t?.address??null,{data:d}=on(l===`0x`||l===b.zeroAddress||!l?``:l),{data:m}=on(u===`0x`||u===b.zeroAddress||!u?``:u),h=(0,r.useMemo)(()=>!l||l===`0x`||l===b.zeroAddress||!d?18:Number(d?.decimals??18),[l,d?.decimals]),g=(0,r.useMemo)(()=>!u||u===`0x`||u===b.zeroAddress||!m?18:Number(m?.decimals??18),[u,m?.decimals]),_=(0,r.useMemo)(()=>{if(!l||!u||!n||!i)return null;let e;try{e=(0,b.parseUnits)(n,h)}catch(e){return console.error(`Failed to parse amount:`,n,e),null}return e<=0n?null:{fromTokenAddress:l,toTokenAddress:u,amountIn:e.toString(),userAddress:i,slippageTolerance:a}},[l,u,n,i,a,h]),{data:v,isLoading:y,error:x}=(0,p.useQuery)({queryKey:[`unified-swap-quotes`,_,c.network],queryFn:async()=>{if(!_||!s||!c.network)return{quotes:[],best:null};let e=yr(c.network).map(async e=>{try{let t=await e.getQuote(_,s);try{let n=await e.simulateSwap(_,t,s);return{...t,aggregator:e,reverted:!n.success,revertReason:n.error,gasCostVTHO:n.gasCostVTHO}}catch(n){return console.error(`Failed to simulate swap for ${e.name}:`,n),{...t,aggregator:e,reverted:!0,revertReason:n instanceof Error?n.message:`Simulation failed`,gasCostVTHO:0}}}catch(t){return console.error(`Failed to get quote from ${e.name}:`,t),null}}),t=(await Promise.all(e)).filter(e=>e!==null&&e.outputAmount!==0n),n=null;if(t.length>0){let e=t.filter(e=>!(e.reverted??!1));n=(e.length>0?e:t).reduce((e,t)=>{let n=BigInt(e.outputAmount||`0`);return BigInt(t.outputAmount||`0`)>n?t:e})}return{quotes:t,best:n}},enabled:o&&_!==null&&s!=null,refetchInterval:1e4});return{bestQuote:v?.best??null,quotes:v?.quotes??[],isLoading:y,error:x,from:e?{...e,address:l??``,decimals:h}:null,to:t?{...t,address:u??``,decimals:g}:null}},xr=({email:e,onResend:t,isLoading:a,isOpen:o,onClose:s})=>{let{t:c}=(0,l.useTranslation)(),{darkMode:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[p,m]=(0,r.useState)(``),[h,_]=(0,r.useState)(null),{createWallet:v}=(0,u.useCreateWallet)(),{loginWithCode:y}=(0,u.useLoginWithEmail)({onComplete:async({isNewUser:e})=>{e&&await v()}});return(0,r.useEffect)(()=>{p.length===6&&y({code:p}).then(()=>{s()}).catch(e=>{_(e.message)})},[p]),(0,i.jsxs)(Re,{isOpen:o,onClose:s,trapFocus:!1,children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{alignItems:`center`,display:`flex`,gap:2,children:c(`Enter confirmation code`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{maxW:`container.lg`,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Icon,{as:g.LuMail,w:`48px`,h:`48px`,color:f}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:f,textAlign:`center`,children:c(`Please check {{email}} for an email from privy.io and enter your code below.`,{email:e})}),(0,i.jsx)(n.HStack,{spacing:2,justify:`center`,mt:4,children:(0,i.jsxs)(n.PinInput,{value:p,onChange:m,otp:!0,size:`lg`,isInvalid:!!h,errorBorderColor:`#ef4444`,children:[(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`}),(0,i.jsx)(n.PinInputField,{borderRadius:`12px`,border:`1px solid ${d?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${d?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${d?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},backgroundColor:d?`transparent`:`#ffffff`})]})}),h&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`xs`,children:h})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.Text,{w:`100%`,textAlign:`center`,fontSize:`14px`,color:d?`whiteAlpha.700`:`gray.600`,children:[c(`Didn't get an email?`),` `,(0,i.jsx)(n.Button,{variant:`link`,color:`blue.500`,fontSize:`14px`,onClick:t,isLoading:a,children:c(`Resend code`)})]})})]})]})},Sr=()=>{let{t:e}=(0,l.useTranslation)(),{darkMode:t}=$(),[a,o]=(0,r.useState)(``),{sendCode:s,state:c}=(0,u.useLoginWithEmail)({}),d=(0,n.useDisclosure)(),f=async()=>{await s({email:a}),d.onOpen()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:4,w:`full`,children:(0,i.jsx)(n.VStack,{spacing:3,w:`full`,children:(0,i.jsxs)(n.InputGroup,{size:`lg`,w:`full`,children:[(0,i.jsx)(n.InputLeftElement,{pointerEvents:`none`,height:`100%`,pl:4,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:t?`whiteAlpha.600`:`blackAlpha.700`,w:`20px`,h:`20px`})}),(0,i.jsx)(n.Input,{placeholder:e(`your@email.com`),value:a,onChange:e=>o(e.target.value),fontSize:`16px`,fontWeight:`400`,backgroundColor:t?`transparent`:`#ffffff`,border:`1px solid ${t?`#ffffff0a`:`#ebebeb`}`,p:6,borderRadius:16,w:`full`,pl:12}),(0,i.jsx)(n.Button,{"aria-label":`Send code`,position:`absolute`,right:2,top:`50%`,transform:`translateY(-50%)`,zIndex:2,variant:`ghost`,size:`sm`,px:6,borderRadius:`full`,isLoading:c.status===`sending-code`,onClick:f,children:e(`Submit`)})]})})}),(0,i.jsx)(xr,{isOpen:d.isOpen,onClose:d.onClose,onResend:()=>s({email:a}),email:a,isLoading:c.status===`sending-code`})]})},Cr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Bo();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:async()=>{await a({provider:`google`})},icon:E.FcGoogle,text:r(`Continue with Google`)})})},wr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Bo();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:async()=>{await a({provider:`github`})},icon:g.LuGithub,text:r(`Continue with Github`)})})},Tr=({isDark:t,gridColumn:r})=>{let{t:a}=(0,l.useTranslation)(),{login:o}=(0,u.usePrivy)();return(0,i.jsx)(n.GridItem,{colSpan:r||4,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:o,icon:t?e.K:e.q,text:a(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(ba,{})})})},Er=({isDark:t,gridColumn:r,setCurrentContent:a})=>{let{t:o}=(0,l.useTranslation)(),{login:s}=Ho(),c=async()=>{a({type:`loading`,props:{title:o(`Connecting to VeChain`),loadingText:o(`Please approve the request in the connection request window...`),onTryAgain:c}});try{await s()}catch(e){console.error(o(`Login failed:`),e),a({type:`error`,props:{error:e instanceof Error?e.message:o(`Failed to connect with VeChain`),onTryAgain:c}})}};return(0,i.jsx)(n.GridItem,{colSpan:r||4,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:c,icon:t?e.K:e.q,text:o(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(ba,{})})})},Dr=({isDark:e,gridColumn:t,setCurrentContent:r})=>{let{t:a}=(0,l.useTranslation)(),{loginWithPasskey:o}=Ro(),s=async()=>{r({type:`loading`,props:{title:a(`Connecting with Passkey`),loadingText:a(`Please complete the passkey authentication...`),onTryAgain:s}});try{await o()}catch(e){(e instanceof Error?e.message.toLowerCase():``).includes(`not found`)&&console.error(e),r({type:`error`,props:{error:e instanceof Error?e.message:a(`Failed to connect with Passkey`),onTryAgain:s}})}};return(0,i.jsx)(n.GridItem,{colSpan:t,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:s,icon:g.LuFingerprint,text:t&&t>=2?a(`Passkey`):void 0})})},Or=({isDark:t,gridColumn:a=2})=>{let{t:o}=(0,l.useTranslation)(),{open:s,onConnectionStatusChange:c}=(0,f.useWalletModal)(),{dappKit:u}=$(),{source:d}=(0,f.useWallet)(),p=u?.allowedWallets?.includes(`sync2`)?o(`Connect wallet`):o(`Connect with VeWorld wallet`);return(0,r.useEffect)(()=>{c((e,t)=>{if(!e)return t?.message&&console.error(t?.message),{...d&&{source:d}}})},[c,d]),(0,i.jsx)(n.GridItem,{colSpan:a||2,w:`full`,children:(0,i.jsx)(ha,{isDark:t,onClick:()=>{s()},icon:u?.allowedWallets?.includes(`sync2`)?g.LuWallet:t?e.M:e.j,iconWidth:`27px`,text:a>=2?p:void 0,rightIcon:u?.allowedWallets?.includes(`sync2`)&&(0,i.jsx)(n.Icon,{as:g.LuArrowRight})||void 0})})},kr=({isDark:e,onViewMoreLogin:t,gridColumn:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsx)(n.GridItem,{colSpan:r,w:`full`,children:(0,i.jsx)(ha,{isDark:e,onClick:t,icon:g.LuEllipsis,text:r&&r>=2?a(`More`):void 0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowRight})})})},Ar=({setCurrentContent:e})=>{let{loginMethods:t,darkMode:r}=$(),{login:a}=(0,u.usePrivy)(),{showGoogleLogin:o,showEmailLogin:s,showPasskey:c,showVeChainLogin:l,showDappKit:d,showMoreLogin:f,showGithubLogin:p,isOfficialVeChainApp:m}=ko();return(0,i.jsx)(n.Stack,{spacing:4,w:`full`,align:`center`,children:(0,i.jsx)(n.Grid,{templateColumns:`repeat(4, 1fr)`,gap:2,w:`full`,children:t?.map(({method:t,gridColumn:n})=>{switch(t){case`email`:return s&&(0,i.jsx)(Sr,{},`email`);case`google`:return o&&(0,i.jsx)(Cr,{isDark:r,gridColumn:n},`google`);case`github`:return p&&(0,i.jsx)(wr,{isDark:r,gridColumn:n},`github`);case`vechain`:return l&&(m?(0,i.jsx)(Tr,{isDark:r,gridColumn:n},`vechain`):(0,i.jsx)(Er,{isDark:r,gridColumn:n,setCurrentContent:e},`vechain`));case`passkey`:return c&&(0,i.jsx)(Dr,{isDark:r,gridColumn:n,setCurrentContent:e},`passkey`);case`dappkit`:return d&&(0,i.jsx)(Or,{isDark:r,gridColumn:n},`dappkit`);case`more`:return f&&(0,i.jsx)(kr,{isDark:r,onViewMoreLogin:a,gridColumn:n},`more`);default:return null}})})})},jr=({appsInfo:e,isLoading:t,setCurrentContent:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsx)(n.Button,{fontSize:`sm`,variant:`link`,onClick:()=>r({type:`ecosystem`,props:{appsInfo:e,isLoading:t}}),children:a(`Already have an x2earn app wallet?`)})},Mr=({setCurrentContent:e,onClose:t,preventAutoClose:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{connection:s}=X(),{loginModalUI:c,darkMode:u}=$(),{loginMethods:d,privyEcosystemAppIDS:f}=$(),{data:p,isLoading:m}=Ve(f),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),g=()=>{e(`faq`)},_=d?.some(({method:e})=>e===`ecosystem`);return(0,r.useEffect)(()=>{s.isConnected&&!a&&t()},[s.isConnected,t,a]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(Ac,{onClick:g}),(0,i.jsx)(n.ModalHeader,{children:o(`Log in or sign up`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),c?.logo&&(0,i.jsx)(n.HStack,{justify:`center`,children:(0,i.jsx)(n.Image,{src:c.logo||`/images/favicon.png`,maxW:`180px`,maxH:`90px`,m:8,alt:`logo`})}),(0,i.jsxs)(n.ModalBody,{children:[c?.description&&(0,i.jsx)(n.HStack,{spacing:4,w:`full`,justify:`center`,mb:`24px`,px:4,children:(0,i.jsx)(n.Text,{color:h,fontSize:`sm`,textAlign:`center`,children:c?.description})}),(0,i.jsx)(Ar,{setCurrentContent:e})]}),_?(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(jr,{isDark:u,appsInfo:Object.values(p||{}),isLoading:m,setCurrentContent:e})})}):(0,i.jsx)(n.ModalFooter,{pt:0,pb:`5px`})]})},Nr=({setCurrentContent:e,wallet:t,onClose:r,switchFeedback:a})=>{let{t:o}=(0,l.useTranslation)(),{network:s}=$(),{isolatedView:c}=Fr();return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[!c&&(0,i.jsx)(J,{onClick:()=>{e(`profile`)}}),(0,i.jsxs)(n.ModalHeader,{children:[o(`Wallet`),s?.type!==`main`&&(0,i.jsx)(n.Tag,{size:`xs`,colorScheme:`orange`,fontSize:`2xs`,p:1,ml:1,textTransform:`uppercase`,children:`${s?.type}`})]}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,overflow:`hidden`,justifyContent:`flex-start`,spacing:8,children:[(0,i.jsx)(Bc,{showFeedback:a?.showFeedback}),(0,i.jsx)(Qr,{style:{justifyContent:`flex-start`},onClick:()=>{e(`profile`)},setCurrentContent:e,onClose:r,wallet:t}),(0,i.jsx)(ei,{onAssetsClick:()=>{e(`assets`)}}),(0,i.jsx)(ri,{setCurrentContent:e})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Pr=({onSelectToken:e,onBack:a,showAllTokens:o=!1,excludedTokenSymbols:s=t.Z})=>{let{t:c}=(0,l.useTranslation)(),{darkMode:u}=$(),{currentCurrency:d}=Xt(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{account:h}=X(),{tokensWithBalance:_,sortedTokens:v}=Zt({address:h?.address??``}),[y,b]=(0,r.useState)(``),x=(0,r.useMemo)(()=>{let e=e=>s.includes(e),t;if(o){let n=v.filter(t=>Number(t.balance)>0&&!e(t.symbol)),r=[...v.filter(t=>Number(t.balance)===0&&!e(t.symbol))].sort((e,t)=>e.symbol.localeCompare(t.symbol));t=[...n,...r]}else t=_.filter(t=>!e(t.symbol));return t},[o,v,_,s]).filter(({symbol:e})=>e.toLowerCase().includes(y.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:c(`Select Token`)}),(0,i.jsx)(J,{onClick:a}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{h:[`540px`,`auto`],p:0,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:`Search token`,bg:u?`vechain-kit-overlay`:`vechain-kit-card`,borderRadius:`xl`,height:`56px`,pl:12,value:y,onChange:e=>b(e.target.value),"data-testid":`search-token-input`}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:m})})]}),(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:f,mt:4,children:c(o?`All tokens`:`Your tokens`)}),x.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,color:m}),(0,i.jsx)(n.Text,{fontSize:`lg`,color:f,children:c(`No tokens found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:p,children:c(`Try searching with a different term`)})]}):(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:x.map(t=>(0,i.jsx)(Oc,{symbol:t.symbol,amount:Number(t.balance),currencyValue:t.valueInCurrency,currentCurrency:d,onClick:()=>e(t)},t.address))})]})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Fr=()=>{let{isolatedView:e,closeAccountModal:t}=Q();return{isolatedView:e,closeAccountModal:t}},Ir=({setCurrentContent:e,preselectedToken:a,initialAmount:s=``,initialToAddressOrDomain:c=``,onBack:u=()=>e(`main`)})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f,feeDelegation:p}=$(),{currentCurrency:m}=Xt(),h=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),y=(0,n.useToken)(`colors`,`vechain-kit-error`),b=(0,n.useToken)(`colors`,`vechain-kit-card`),{exchangeRates:x}=Wt(),{account:S}=X(),{isolatedView:C}=Fr(),{tokensWithBalance:w}=Zt({address:S?.address??``}),T=(0,r.useMemo)(()=>w.filter(e=>!t.Z.includes(e.symbol)),[w]),[E,k]=(0,r.useState)(()=>a&&!t.Z.includes(a.symbol)?a:T[0]??null),[A,j]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!E&&T.length>0&&k(T[0])},[T,E]);let{register:M,watch:N,setValue:P,setError:F,formState:{errors:I,isValid:L},handleSubmit:R}=(0,D.useForm)({defaultValues:{amount:s,toAddressOrDomain:c},mode:`onChange`}),{toAddressOrDomain:z,amount:B}=N(),ee=(0,r.useRef)(E);(0,r.useEffect)(()=>{ee.current&&E&&ee.current.address!==E.address&&P(`amount`,``),ee.current=E},[E,P]);let te=(0,r.useMemo)(()=>E?qt(Gt(Number(B)*E.priceUsd,m,x),{currency:m}):``,[B,E,m,x]),{data:V,isLoading:ne}=Ge(z),re=()=>{E&&P(`amount`,E.balance)},ie=()=>{u()},H=async t=>{if(E){if(!(V?.isValidAddressOrDomain&&(!V?.domain||V?.domain&&V?.isPrimaryDomain))){F(`toAddressOrDomain`,{type:`manual`,message:d(`Invalid address or domain`)});return}if(E){let e=(0,o.parseEther)(t.amount),n=p?.b3trTransfers?.minAmountInEther;if(E.symbol===`B3TR`&&typeof n==`number`&&n>0)try{if(e<(0,o.parseEther)(String(n))){F(`amount`,{type:`manual`,message:d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:E.symbol,min:n})});return}}catch{}if(e>(0,o.parseEther)(E.balance)){F(`amount`,{type:`manual`,message:d(`Insufficient {{symbol}} balance`,{symbol:E.symbol})});return}}e({type:`send-token-summary`,props:{toAddressOrDomain:t.toAddressOrDomain,resolvedDomain:V?.domain,resolvedAddress:V?.address,amount:t.amount,selectedToken:E,formattedTotalAmount:te,setCurrentContent:e}})}};return A?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:e=>{k(e),j(!1)},onBack:()=>{j(!1)}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Send`)}),!C&&(0,i.jsx)(J,{onClick:ie}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,position:`relative`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:h,children:d(`Amount`)}),(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:_,textDecoration:`underline`},onClick:re,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:_,children:[d(`Balance`),`:`,` `,Number(E?.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:4,borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!I.amount,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{...M(`amount`,{required:d(`Amount is required`),pattern:{value:/^\d*\.?\d*$/,message:d(`Please enter a valid number`)},validate:e=>{if(!e)return!0;let t=parseFloat(e);if(isNaN(t))return d(`Please enter a valid number`);let n=p?.b3trTransfers?.minAmountInEther;return E?.symbol===`B3TR`&&typeof n==`number`&&n>0&&t<n?d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:E.symbol,min:n}):!0}}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,P(`amount`,t,{shouldValidate:!0})},placeholder:`0`,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`tx-amount-input`,type:`number`,inputMode:`decimal`,color:h}),E?(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`},onClick:()=>j(!0),leftIcon:t.et[E.symbol]?r.default.cloneElement(t.et[E.symbol],{boxSize:`20px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[E.symbol],alt:`${E.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:h,children:E.symbol.slice(0,3)})})}),children:[E.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]}):(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`,color:v},onClick:()=>j(!0),children:[d(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]})]}),E&&(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:_,children:(0,i.jsxs)(n.Text,{color:_,children:[`≈ `,te]})}),I.amount&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,mt:1,"data-testid":`amount-error-msg`,children:I.amount.message})]})})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:2,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:h,children:d(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,p:4,width:`100%`,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!I.toAddressOrDomain,children:[(0,i.jsx)(n.Input,{...M(`toAddressOrDomain`,{required:d(`Address is required`)}),onChange:e=>{let t=e.target.value.trim(),n=t.includes(`.`)?(0,O.ens_normalize)(t):t;e.target.value=n,P(`toAddressOrDomain`,n,{shouldValidate:!0})},placeholder:d(`Type the receiver address or domain`),_placeholder:{fontSize:`md`,fontWeight:`normal`},fontSize:`lg`,fontWeight:`bold`,color:h,variant:`unstyled`,"data-testid":`tx-address-input`}),I.toAddressOrDomain&&(0,i.jsx)(n.Text,{color:y,fontSize:`sm`,"data-testid":`address-error-msg`,children:I.toAddressOrDomain.message})]})})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!E||!L,isLoading:ne,onClick:R(H),"data-testid":`send-button`,children:d(E?`Send`:`Select Token`)})})]})},Lr=({setCurrentContent:e,toAddressOrDomain:a,resolvedDomain:o,resolvedAddress:s,amount:c,selectedToken:u,formattedTotalAmount:d})=>{let{t:f}=(0,l.useTranslation)(),{account:p,connection:m,connectedWallet:h}=X(),{data:g}=kt(s??``),{network:_,feeDelegation:v}=$(),{preferences:y}=Tc(),{isolatedView:b,closeAccountModal:x}=Fr(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w}=Is(p?.address??``,h?.address??``,3),{open:T}=Ao(),E=(0,r.useMemo)(()=>g||t.U(s||a),[g,_.type,s,a]),D=async()=>{if(w){T();return}try{u.symbol===`VET`?await F():await k()}catch(e){console.error(f(`Transaction failed:`),e)}},O=r.default.useCallback(t=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:f(`Transaction successful`),onDone:()=>{b?x():e(`main`)},showSocialButtons:!0}})},[e,f,b,x]),{sendTransaction:k,txReceipt:A,error:j,isWaitingForWalletConfirmation:M,isTransactionPending:N,clauses:P}=$s({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,tokenAddress:u.address,tokenName:u.symbol,onError:e=>{H(e??``)}}),{sendTransaction:F,txReceipt:I,error:L,isWaitingForWalletConfirmation:R,isTransactionPending:z,clauses:B}=tc({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,onError:e=>{H(e??``)}}),ee=r.default.useCallback(()=>u.symbol===`VET`?I:A,[u.symbol,I,A]),te=M||R,V=te||N||z,[ne,re]=r.default.useState(!1);r.default.useEffect(()=>{let e=ee();if(!e||e.reverted||ne||V)return;let t=e.meta.txID;t&&(re(!0),O(t))},[ee,ne,V,O]),r.default.useEffect(()=>{V&&re(!1)},[V]);let ie=()=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:u,initialAmount:c,initialToAddressOrDomain:a}})},H=e=>{console.error(`Transaction failed:`,e)},[ae,U]=r.default.useState(null),[oe,W]=r.default.useState(null),se=y.availableGasTokens.length>0&&(m.isConnectedWithPrivy||m.isConnectedWithVeChain)&&!v?.delegatorUrl,{data:ce,isLoading:G,error:le,refetch:ue}=Ec({clauses:u.symbol===`VET`?B:P,tokens:ae?[ae]:y.availableGasTokens,sendingAmount:c,sendingTokenSymbol:u.symbol,enabled:se&&!!v?.genericDelegatorUrl}),de=ce?.usedToken,K=(G||!ce)&&m.isConnectedWithPrivy&&!v?.delegatorUrl,q=r.default.useCallback(e=>{U(e),W(e),setTimeout(()=>ue(),100)},[ue]),fe=!!de&&!le;return r.default.useEffect(()=>{le&&ae&&U(null)},[le,ae]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:`Send`}),(0,i.jsx)(J,{isDisabled:V,onClick:ie}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:V})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:4,w:`full`,children:[(0,i.jsxs)(n.Box,{w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,mb:2,color:C,children:f(`From`)}),(0,i.jsx)(kc,{address:p?.address??``,domain:p?.domain,imageSrc:p?.image??``,imageAlt:`From account`,balance:Number(u.balance),tokenAddress:u.address})]}),(0,i.jsxs)(n.Box,{w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,mb:2,color:C,children:f(`To`)}),(0,i.jsx)(kc,{address:s||a,domain:o,imageSrc:E??``,imageAlt:`To account`,tokenAddress:u.address})]}),m.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:ce,isLoading:G,isLoadingTransaction:V,onTokenChange:q,clauses:u.symbol===`VET`?B:P,userSelectedToken:oe}),(0,i.jsxs)(n.VStack,{spacing:0,w:`full`,justifyContent:`flex-start`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`light`,textAlign:`left`,w:`full`,color:C,children:f(`Amount`)}),(0,i.jsxs)(n.HStack,{justifyContent:`flex-start`,w:`full`,children:[(0,i.jsxs)(n.Text,{fontSize:`xl`,fontWeight:`semibold`,textAlign:`left`,"data-testid":`send-summary-amount`,color:S,children:[Number(c).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),` `,u.symbol]}),(0,i.jsxs)(n.Text,{color:C,children:[`≈ `,d]})]})]})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Nc,{transactionError:u.symbol===`VET`?L:j,isSubmitting:V,isTxWaitingConfirmation:te,onConfirm:D,transactionPendingText:f(`Sending...`),txReceipt:ee(),buttonText:f(`Confirm`),isDisabled:V||K,gasEstimationError:le,hasEnoughGasBalance:fe,isLoadingGasEstimation:G,showGasEstimationError:!v?.delegatorUrl&&m.isConnectedWithPrivy,context:`send`})})]})},Rr=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{account:r}=X(),{isolatedView:a}=Fr(),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Receive`)}),!a&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{maxW:`container.lg`,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`center`,w:`full`,children:[(0,i.jsx)(k.QRCode,{value:r?.address??``,size:200,removeQrCodeBehindLogo:!0,eyeRadius:4,logoPaddingStyle:`circle`,style:{borderRadius:`16px`}}),(0,i.jsx)(Oe,{wallet:r,style:{w:`85%`}}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:o,children:t(`Copy your address or scan this QR code`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,textAlign:`center`,color:s,children:t(`This address only supports VeChain assets.`)})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},zr=({quotes:e,selectedQuote:a,toTokenAddress:o,onSelectQuote:s,onBack:c})=>{let{t:u}=(0,l.useTranslation)(),{darkMode:d}=$(),{currentCurrency:f}=Xt(),{account:p}=X(),{exchangeRates:m,prices:h}=Wt(),{tokens:_}=Zt({address:p?.address??``}),[v,y]=(0,r.useState)(!1),x=(0,r.useMemo)(()=>o&&_.find(e=>t.k(e.address,o))||null,[o,_]),S=e.filter(e=>!e.reverted),C=e.filter(e=>e.reverted),w=(0,r.useMemo)(()=>S.length===0?null:S.reduce((e,t)=>{let n=BigInt(e.outputAmount||`0`);return BigInt(t.outputAmount||`0`)>n?t:e}),[S]),T=(0,r.useMemo)(()=>{let e=o&&h[o]||0;return S.map(t=>{let n=(0,b.formatEther)(BigInt(t.outputAmount||`0`)),r=Number(n)*e,i=Gt(r,f,m),a=w&&t.aggregatorName===w.aggregatorName,o=0;if(w&&!a){let e=BigInt(w.outputAmount||`0`),n=BigInt(t.outputAmount||`0`);o=Number(n-e)/Number(e)*100}return{...t,outputAmountFormatted:n,valueUsd:r,valueInCurrency:i,isBest:a,percentageDiff:o}}).sort((e,t)=>{let n=BigInt(e.outputAmount||`0`),r=BigInt(t.outputAmount||`0`);return Number(r-n)})},[S,o,h,f,m,w]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:u(`Found following rates`)}),(0,i.jsx)(J,{onClick:c}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{h:[`540px`,`auto`],p:0,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[T.length>0&&(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:T.map(e=>{let o=a?.aggregatorName===e.aggregatorName;return(0,i.jsxs)(n.Box,{p:2.5,borderRadius:`xl`,bg:d?`#00000038`:`gray.50`,borderWidth:1,borderColor:o?`blue.500`:d?`whiteAlpha.200`:`gray.200`,cursor:`pointer`,onClick:()=>s(e),_hover:{borderColor:o?`blue.500`:d?`whiteAlpha.400`:`gray.300`},position:`relative`,children:[(e.isBest||!e.isBest&&e.percentageDiff<0)&&(0,i.jsx)(n.Box,{position:`absolute`,top:-1,left:0,zIndex:1,children:e.isBest?(0,i.jsx)(n.Badge,{colorScheme:`purple`,borderRadius:`sm`,fontSize:`2xs`,px:1.5,py:.5,borderTopLeftRadius:`xl`,borderBottomRightRadius:`md`,children:u(`Best`)}):(0,i.jsxs)(n.Badge,{colorScheme:`red`,borderRadius:`xs`,fontSize:`2xs`,px:1.5,py:.5,borderTopLeftRadius:`xl`,borderBottomRightRadius:`md`,children:[e.percentageDiff.toFixed(2),`%`]})}),(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:1.5,marginTop:4,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,align:`center`,children:[(0,i.jsxs)(n.HStack,{spacing:1.5,align:`center`,children:[e.aggregator.getIcon(`20px`),(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,children:e.aggregatorName})]}),(0,i.jsx)(n.HStack,{align:`center`,spacing:1.5,children:x&&(0,i.jsxs)(i.Fragment,{children:[t.et[x.symbol]?r.default.cloneElement(t.et[x.symbol],{boxSize:`24px`,borderRadius:`full`}):t.$[x.symbol]?(0,i.jsx)(n.Image,{src:t.$[x.symbol],alt:`${x.symbol} logo`,boxSize:`24px`,borderRadius:`full`}):null,(0,i.jsx)(n.Tooltip,{label:Number(e.outputAmountFormatted).toLocaleString(void 0,{maximumFractionDigits:18}),hasArrow:!0,placement:`top`,children:(0,i.jsxs)(n.Text,{fontSize:`md`,fontWeight:`bold`,textAlign:`right`,whiteSpace:`nowrap`,children:[Number(e.outputAmountFormatted).toLocaleString(void 0,{minimumFractionDigits:4}),` `,x.symbol]})})]})})]}),(0,i.jsxs)(n.HStack,{justify:`space-between`,align:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.500`:`blackAlpha.500`,children:e.gasCostVTHO&&e.gasCostVTHO>0?`Gas: ${e.gasCostVTHO.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:``}),e.valueUsd>0&&(0,i.jsxs)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.600`:`blackAlpha.600`,textAlign:`right`,whiteSpace:`nowrap`,children:[`≈ `,qt(e.valueInCurrency,{currency:f})]})]})]})]},e.aggregatorName)})}),C.length>0&&(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,cursor:`pointer`,onClick:()=>y(!v),py:2,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:d?`whiteAlpha.600`:`blackAlpha.600`,children:[C.length,` `,u(`rate`),C.length===1?``:`s`,` `,u(`unavailable`)]}),(0,i.jsx)(n.Icon,{as:v?g.LuChevronUp:g.LuChevronDown,boxSize:4,color:d?`whiteAlpha.600`:`blackAlpha.600`})]}),(0,i.jsx)(n.Collapse,{in:v,animateOpacity:!0,children:(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,pt:2,children:C.map(e=>(0,i.jsx)(n.Box,{p:2,borderRadius:`xl`,bg:d?`#00000038`:`gray.50`,opacity:.6,children:(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:2,align:`center`,children:[e.aggregator.getIcon(`20px`),(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`medium`,children:e.aggregatorName})]}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d?`whiteAlpha.500`:`blackAlpha.500`,children:u(`Unable to fetch the price`)})]})},e.aggregatorName))})})]}),T.length===0&&C.length===0&&(0,i.jsx)(n.VStack,{spacing:2,py:8,color:d?`whiteAlpha.600`:`blackAlpha.600`,children:(0,i.jsx)(n.Text,{fontSize:`lg`,children:u(`No quotes available`)})})]})})}),(0,i.jsx)(n.ModalFooter,{})]})},Br=e=>e===`0x`||e===b.zeroAddress||!e,Vr=(e,t,n,r)=>{if(!e||!t||!n||!r)return null;let i=t.toLowerCase(),a=n.toLowerCase(),o=r.toLowerCase(),s=Br(n),c=Br(r),l=[],u=[];if(e.outputs&&Array.isArray(e.outputs))for(let t of e.outputs)t.events&&Array.isArray(t.events)&&l.push(...t.events),t.transfers&&Array.isArray(t.transfers)&&u.push(...t.transfers);let d=y.IERC20__factory.createInterface().getEvent(`Transfer`),f=d?.topicHash.toLowerCase(),p=l.filter(e=>e.topics&&e.topics.length>0&&e.topics[0]?.toString().toLowerCase()===f),m=null,h=null;if(s){for(let e of u)if(e.sender?.toLowerCase()===i&&e.amount&&e.amount!==`0x0`&&e.amount!==`0x`){let t=BigInt(e.amount);if(t>0n){m=t;break}}}if(c){for(let e of u)if(e.recipient?.toLowerCase()===i&&e.amount&&e.amount!==`0x0`&&e.amount!==`0x`){let t=BigInt(e.amount);if(t>0n){h=t;break}}}if(p.length>0)for(let e of p)try{let t=(0,b.decodeEventLog)({abi:[d],data:e.data.toString(),topics:e.topics.map(e=>e.toString())});if(!t.args||!(`from`in t.args)||!(`to`in t.args)||!(`value`in t.args))continue;let n=t.args.from?.toString().toLowerCase(),r=t.args.to?.toString().toLowerCase(),l=t.args.value,u=e.address.toLowerCase();!s&&n===i&&u&&u===a&&l>0n&&m===null&&(m=l),!c&&r===i&&u&&u===o&&l>0n&&h===null&&(h=l)}catch(e){console.warn(`Failed to decode transfer event:`,e);continue}return{fromAmount:m??0n,toAmount:h??0n}},Hr=({setCurrentContent:e,fromTokenAddress:a,toTokenAddress:o})=>{let{t:s}=(0,l.useTranslation)(),{account:c,connection:u}=X(),{currentCurrency:d}=Xt(),{network:f,feeDelegation:p,darkMode:m}=$(),{isolatedView:h,closeAccountModal:_}=Fr(),v=(0,n.useToken)(`colors`,`vechain-kit-card`),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),x=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),S=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),C=(0,n.useToken)(`colors`,`vechain-kit-button-primary-bg`),w=(0,n.useToken)(`colors`,`vechain-kit-button-primary-color`),{preferences:T}=Tc(),{sortedTokens:E}=Zt({address:c?.address??``}),[D,O]=(0,r.useState)(`main`),[k,A]=(0,r.useState)(null),[j,M]=(0,r.useState)(null),[N,P]=(0,r.useState)(``),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(1),[z,B]=(0,r.useState)(`1`),[ee,te]=(0,r.useState)(null),[V,ne]=r.default.useState(null),[re,ie]=r.default.useState(null),[H,ae]=r.default.useState([]),{prices:U,exchangeRates:oe}=Wt(),W=L===1;r.default.useEffect(()=>{B(L===1?`1`:L===.5?`0.5`:L===3?`3`:L.toString())},[L]),r.default.useEffect(()=>{if(E.length!==0){if((a||o)&&(!k||!j)){if(a&&!k){let e=E.find(e=>t.k(e.address,a));e&&!t.Z.includes(e.symbol)&&A(e)}if(o&&!j){let e=E.find(e=>t.k(e.address,o));e&&!t.Z.includes(e.symbol)&&M(e)}return}if(!k&&!j){let e=E.find(e=>e.symbol===`VET`);e&&A(e);let n=E.find(e=>e.symbol===`B3TR`);if(!n)try{let e=t.bt(f.type).b3trContractAddress;e&&(n=E.find(n=>t.k(n.address,e)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}n&&M(n)}}},[E,k,j,a,o,f.type]),r.default.useEffect(()=>{te(null)},[k?.address,j?.address,N]);let{bestQuote:se,quotes:ce,isLoading:G,from:le,to:ue}=br(k,j,N,c?.address??``,L,!!k&&!!j&&Number(N)>0),de=(0,r.useMemo)(()=>{if(!N||Number(N)<=0||!le)return 0n;try{return(0,b.parseUnits)(N,le.decimals)}catch{return 0n}},[N,le?.decimals]),K=ee||se,q=(0,r.useMemo)(()=>{if(!K?.outputAmount||!ue)return`0`;try{return(0,b.formatUnits)(K.outputAmount,ue.decimals)}catch{return`0`}},[K,ue?.decimals]),fe=(0,r.useMemo)(()=>{if(!k||!N)return 0;let e=U[k.address]||0;return Gt(Number(N)*e,d,oe)},[k?.address,N,U,d,oe]),pe=(0,r.useMemo)(()=>{if(!j||!q)return 0;let e=U[j.address]||0;return Gt(Number(q)*e,d,oe)},[j?.address,q,U,d,oe]),me=(0,r.useMemo)(()=>!k||!j||!c?.address||de===0n?null:{fromTokenAddress:k.address,toTokenAddress:j.address,amountIn:de.toString(),userAddress:c.address,slippageTolerance:L},[k,j,c?.address,de,L]),he=K?.gasCostVTHO??0;r.default.useEffect(()=>{(async()=>{if(!K||!me||!K.aggregator){ae([]);return}try{ae(await K.aggregator.buildSwapTransaction(me,K))}catch(e){console.error(`Failed to build swap clauses for gas estimation:`,e),ae([])}})()},[K,me]);let ge=T.availableGasTokens.length>0&&(u.isConnectedWithPrivy||u.isConnectedWithVeChain)&&!p?.delegatorUrl,{data:_e,isLoading:ve,error:ye,refetch:be}=Ec({clauses:H,tokens:V?[V]:T.availableGasTokens,sendingAmount:N,sendingTokenSymbol:k?.symbol??``,enabled:ge&&!!p?.genericDelegatorUrl&&H.length>0}),xe=_e?.usedToken,Se=(ve||!_e)&&u.isConnectedWithPrivy&&!p?.delegatorUrl,Ce=r.default.useCallback(e=>{ne(e),ie(e),setTimeout(()=>be(),100)},[be]),we=!!xe&&!ye;r.default.useEffect(()=>{ye&&V&&ne(null)},[ye,V]);let{executeSwap:Te,isTransactionPending:Ee,isWaitingForWalletConfirmation:De,txReceipt:Oe,status:ke,error:Ae}=er(me,K),je=(0,r.useCallback)(()=>{let t=Oe?.meta.txID??``,n=s(`Swap successful`,{defaultValue:`Swap successful`}),r;if(Oe&&k&&j&&c?.address){let e=Vr(Oe,c.address,k.address,j.address);if(e&&le&&ue)try{let t=le.decimals,n=ue.decimals,i=(0,b.formatUnits)(e.fromAmount,t),a=(0,b.formatUnits)(e.toAmount,n),o=e=>{let t=Number(e);return t>=1e3?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString(void 0,{maximumFractionDigits:6,minimumFractionDigits:0})};r=s(`You successfully swapped {fromAmount} {fromSymbol} for {toAmount} {toSymbol}`,{fromAmount:o(i),fromSymbol:k.symbol,toAmount:o(a),toSymbol:j.symbol,defaultValue:`You successfully swapped ${o(i)} ${k.symbol} for ${o(a)} ${j.symbol}`})}catch(e){console.warn(`Failed to format swap amounts:`,e)}}!r&&k&&j&&(r=s(`You successfully swapped {fromToken} for {toToken}`,{fromToken:k.symbol,toToken:j.symbol,defaultValue:`You successfully swapped ${k.symbol} for ${j.symbol}`})),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:n,description:r,onDone:()=>{h?_():e(`main`)},showSocialButtons:!0}})},[k,j,N,K,Oe,c?.address,e,s,h,_]),Me=(0,r.useCallback)(e=>{let t=typeof e==`string`?e:e.message;console.error(`Swap failed:`,t)},[k,j,N]),[Ne,Pe]=r.default.useState(!1);r.default.useEffect(()=>{if(ke===`ready`){Pe(!1);return}Ne||(ke===`success`&&Oe&&!Oe.reverted?(Pe(!0),je()):ke===`error`&&Ae?Me(Ae?.reason||Ae?.message||String(Ae)):Oe?.reverted&&Me(`Transaction reverted`))},[ke,Oe,Ae,je,Me,Ne]);let Fe=(0,r.useCallback)(e=>{if(A(e),e.symbol===`VET`&&!j){let e=E.find(e=>e.symbol===`B3TR`);if(!e)try{let n=t.bt(f.type).b3trContractAddress;n&&(e=E.find(e=>t.k(e.address,n)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}e&&M(e)}O(`main`)},[j,E,f.type]),Ie=(0,r.useCallback)(e=>{M(e),O(`main`)},[]),Le=(0,r.useCallback)(e=>{(/^\d*\.?\d*$/.test(e)||e===``)&&P(e)},[]),Re=(0,r.useCallback)(()=>{k&&P(k.balance)},[k]),ze=e=>{if(!e)return null;let n=t.et[e.symbol],r=t.$[e.symbol];return{symbol:e.symbol,logoComponent:n,logoUrl:r,balance:e.balance,value:e.valueInCurrency}},Be=ze(k),Ve=ze(j);return D===`select-from-token`?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:Fe,onBack:()=>O(`main`),showAllTokens:!1}):D===`select-quote`?(0,i.jsx)(zr,{quotes:ce,selectedQuote:K,toTokenAddress:j?.address??null,onSelectQuote:e=>{te(e),O(`main`)},onBack:()=>O(`main`)}):D===`select-to-token`?(0,i.jsx)(Pr,{setCurrentContent:e,onSelectToken:Ie,onBack:()=>O(`main`),showAllTokens:!0}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Swap`)}),!h&&(0,i.jsx)(J,{onClick:()=>e(`main`),isDisabled:Ee||De}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:Ee||De})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,w:`full`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:y,children:s(`From`)}),Be&&(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:x,textDecoration:`underline`},onClick:Re,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Be.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:4,borderRadius:`2xl`,bg:v,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{placeholder:`0`,value:N,onChange:e=>Le(e.target.value),fontSize:`4xl`,fontWeight:`bold`,variant:`unstyled`,"data-testid":`swap-amount-input`,type:`number`,inputMode:`decimal`,color:Be&&N&&Number(N)>Number(Be.balance)?`red.500`:y}),Be?(0,i.jsxs)(n.Button,{onClick:()=>O(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Be.logoComponent?r.default.cloneElement(Be.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Be.logoUrl?(0,i.jsx)(n.Image,{src:Be.logoUrl,alt:`${Be.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:y,children:Be.symbol.slice(0,3)})})}):void 0,children:[Be.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>O(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`,color:S},children:[s(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]})]}),(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:x,children:(0,i.jsx)(n.HStack,{spacing:2,alignItems:`center`,children:(0,i.jsxs)(n.Text,{color:x,children:[`≈`,` `,qt(fe??0,{currency:d})]})})})]})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:4,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:y,children:s(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:v,p:4,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,width:`100%`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{value:Number(q).toLocaleString(void 0,{maximumFractionDigits:Number(q)>1e4?0:2}),readOnly:!0,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`swap-output-amount`,color:y}),Ve?(0,i.jsxs)(n.Button,{onClick:()=>O(`select-to-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Ve.logoComponent?r.default.cloneElement(Ve.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Ve.logoUrl?(0,i.jsx)(n.Image,{src:Ve.logoUrl,alt:`${Ve.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:y,children:Ve.symbol.slice(0,3)})})}):void 0,children:[Ve.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>O(`select-to-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`,color:S},children:[s(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]})]}),(0,i.jsxs)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:x,children:[(0,i.jsx)(n.HStack,{spacing:2,alignItems:`center`,children:(0,i.jsxs)(n.Text,{color:x,children:[`≈`,` `,qt(pe??0,{currency:d})]})}),Ve&&(0,i.jsxs)(n.Text,{noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Ve.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]})]})}),(0,i.jsx)(n.Collapse,{in:F&&!!K,animateOpacity:!0,children:(0,i.jsxs)(n.VStack,{spacing:1,align:`stretch`,p:4,borderRadius:`2xl`,bg:v,children:[K&&(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Source`),`:`]}),(0,i.jsx)(n.Button,{variant:`outline`,size:`xs`,borderRadius:`full`,px:3,h:`auto`,py:1,cursor:`pointer`,onClick:()=>O(`select-quote`),color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:K.aggregator?.getIcon(`12px`),children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:y,children:K.aggregatorName})})]}),(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Slippage tolerance`),`:`]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,fontWeight:`medium`,color:y,children:[L,`%`]})]}),(0,i.jsx)(n.VStack,{spacing:3,align:`stretch`,pt:2,children:(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(1)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:W?C:`transparent`,color:W?w:x,borderColor:W?C:x,_hover:{bg:W?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:W?.8:1},children:`Auto`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(.5)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:L===.5?C:`transparent`,color:L===.5?w:x,borderColor:L===.5?C:x,_hover:{bg:L===.5?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:L===.5?.8:1},children:`0.5%`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{R(3)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:L===3?C:`transparent`,color:L===3?w:x,borderColor:L===3?C:x,_hover:{bg:L===3?C:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:L===3?.8:1},children:`3%`}),(0,i.jsxs)(n.InputGroup,{size:`sm`,flex:1,children:[(0,i.jsx)(n.Input,{value:z,onChange:e=>{let t=e.target.value;if(/^\d*\.?\d*$/.test(t)||t===``)if(B(t),t!==``){let e=parseFloat(t);!isNaN(e)&&e>=0&&e<=100&&R(e)}else R(1)},placeholder:`1`,borderRadius:`md`,textAlign:`right`,pr:8,fontSize:`xs`,color:y}),(0,i.jsx)(n.InputRightElement,{width:`2rem`,pointerEvents:`none`,children:(0,i.jsx)(n.Text,{fontSize:`2xs`,color:x,children:`%`})})]})]})})]}),(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,color:x,children:[s(`Fee`),`:`]}),(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`medium`,color:y,children:he>0?`${he.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:`-`})]})]})}),K&&(0,i.jsx)(n.Box,{minH:`24px`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Button,{variant:`ghost`,size:`xs`,onClick:()=>I(!F),rightIcon:(0,i.jsx)(n.Icon,{color:S,_hover:{color:x},as:F?g.LuArrowUp:g.LuArrowDown}),fontSize:`xs`,fontWeight:`light`,color:S,_hover:{color:x},children:s(F?`Hide`:`Show Advanced Options`)})}),H.length>0&&u.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:_e,isLoading:ve,isLoadingTransaction:Ee,onTokenChange:Ce,clauses:H,userSelectedToken:re})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Nc,{buttonText:s(G?`Loading quote...`:`Swap`),onConfirm:Te,isSubmitting:Ee,isTxWaitingConfirmation:De,transactionPendingText:s(`Swapping...`),txReceipt:Oe,transactionError:Ae,onError:e=>{Me(e)},isDisabled:!k||!j||!N||Number(N)<=0||G||!K||K?.reverted===!0||!!(Be&&N&&Number(N)>Number(Be.balance))||Se,gasEstimationError:ye,hasEnoughGasBalance:we,isLoadingGasEstimation:ve,showGasEstimationError:!p?.delegatorUrl&&u.isConnectedWithPrivy,context:`transaction`})})]})},Ur=({setCurrentContent:e,onBack:t=()=>e(`settings`),initialContentSource:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{isolatedView:o}=Fr(),s=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),c=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),u=()=>{t()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Choose your account name`)}),!o&&(0,i.jsx)(J,{onClick:u}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,boxSize:16,color:c}),(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`500`,textAlign:`center`,color:s,children:a(`Finally say goodbye to 0x addresses`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:c,textAlign:`center`,px:4,children:a(`Name your account to make it easier to exchange assets`)})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:()=>e({type:`choose-name-search`,props:{name:``,setCurrentContent:e,initialContentSource:r}}),"data-testid":`choose-name-button`,children:a(`Choose name`)})})]})},Wr=({domain:e,isCurrentDomain:r,onSelect:a})=>{let{connection:o}=X(),{t:s}=(0,l.useTranslation)(),c=Mn(e.name,o.network),u=(0,n.useToken)(`colors`,`vechain-kit-card`),d=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),f=(0,n.useToken)(`colors`,`vechain-kit-border`),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`);return(0,i.jsx)(n.ListItem,{p:4,bg:u,borderRadius:`xl`,cursor:r?`default`:`pointer`,opacity:r?.7:1,border:`1px solid ${f}`,_hover:{bg:r?d:u,borderColor:f},onClick:()=>!r&&a(e.name),transition:`all 0.2s`,children:(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(Mc,{props:{width:`40px`,height:`40px`,src:c.image??t.U(e.name),alt:e.name}}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,flex:1,children:[(0,i.jsx)(n.Text,{color:p,fontSize:`md`,fontWeight:`500`,children:t.G(e.name,24,0)}),r&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:m,children:s(`Current domain`)})]}),r&&(0,i.jsx)(n.Tag,{size:`sm`,bg:h,color:p,px:3,py:1,borderRadius:`full`,children:s(`Current`)})]})},e.name)},Gr=({onUnset:e})=>{let t=(0,n.useToken)(`colors`,`vechain-kit-card`),r=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),a=(0,n.useToken)(`colors`,`vechain-kit-border`),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),c=(0,n.useToken)(`colors`,`vechain-kit-error`),{t:u}=(0,l.useTranslation)();return(0,i.jsx)(n.ListItem,{p:4,bg:t,borderRadius:`xl`,cursor:`pointer`,opacity:1,border:`1px solid ${a}`,_hover:{bg:r,borderColor:a,color:`red.400`},onClick:e,transition:`all 0.2s`,role:`button`,"aria-label":u(`Unset current domain`),children:(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Box,{width:`40px`,height:`40px`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`,bg:t,children:(0,i.jsx)(n.Icon,{as:g.LuTrash2,fontSize:`18px`,color:c})}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,flex:1,children:[(0,i.jsx)(n.Text,{color:o,fontSize:`md`,fontWeight:`500`,children:u(`Unset current domain`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:s,children:u(`Remove your current domain name`)})]})]})},`unset-domain-list-item`)},Kr=({domains:e,onDomainSelect:t,onUnsetDomain:r,isLoading:a})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),c=(0,n.useToken)(`colors`,`vechain-kit-card`),u=(0,n.useToken)(`colors`,`vechain-kit-card-hover`),d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return e.length===0||a?null:(0,i.jsx)(n.Accordion,{allowToggle:!0,children:(0,i.jsx)(n.AccordionItem,{border:`none`,children:({isExpanded:l})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:c,borderRadius:`xl`,_hover:{bg:u},opacity:a?.7:1,transition:`all 0.2s`,disabled:a,children:[(0,i.jsx)(n.Box,{flex:`1`,textAlign:`left`,py:2,children:(0,i.jsx)(n.Text,{fontWeight:`500`,color:d,children:a?o(`Loading your domains...`):`${o(`Your existing domains`)} (${e.length})`})}),(0,i.jsx)(n.Icon,{as:l?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,color:f})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,pt:2,children:(0,i.jsxs)(n.List,{spacing:2,children:[e.map(e=>(0,i.jsx)(Wr,{domain:e,isCurrentDomain:e.name===s?.domain,onSelect:t},e.name)),s?.domain&&(0,i.jsx)(Gr,{onUnset:r})]})})]})})})},qr=({name:e,setCurrentContent:t,initialContentSource:a=`settings`})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{darkMode:c}=$(),{isolatedView:u}=Fr(),[d,f]=(0,r.useState)((0,O.ens_normalize)(e)),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=(0,n.useToken)(`colors`,`vechain-kit-success`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w,isLoading:T}=Je(d),{data:E,isLoading:D}=Ge(`${d}.veworld.vet`),{data:k,isLoading:A}=ct(d),{data:j,isLoading:M}=pt(s?.address,``),N=T||D||A;(0,r.useEffect)(()=>{if(!y)return;let e=/[^a-zA-Z0-9-]|\s/.test(d);d.length<3?(m(o(`Name must be at least 3 characters long`)),v(!1),g(!1)):e?(m(o(`Only letters, numbers, and hyphens are allowed`)),v(!1),g(!1)):k?(m(o(`This domain is protected`)),v(!1),g(!1)):w?E?.address?.toLowerCase()===s?.address?.toLowerCase()?(m(null),v(!0),g(!0)):(m(o(`This domain is already taken`)),v(!1),g(!1)):T||(m(null),v(!0),g(!1))},[d,y,w,T,E,s?.address,k,_,N]);let P=()=>{_&&!p&&t({type:`choose-name-summary`,props:{fullDomain:d+`.veworld.vet`,isOwnDomain:h,setCurrentContent:t,initialContentSource:a}})},F=e=>{let n=e.split(`.`);t({type:`choose-name-summary`,props:{fullDomain:e,domainType:n.length>2?`${n[1]}.${n[2]}`:`vet`,isOwnDomain:!0,setCurrentContent:t,initialContentSource:a}})},I=()=>{t({type:`choose-name-summary`,props:{fullDomain:``,domainType:``,isOwnDomain:!1,isUnsetting:!0,setCurrentContent:t,initialContentSource:a}})},L=()=>{t(a)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Choose Name`)}),!u&&(0,i.jsx)(J,{onClick:L}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsx)(Kr,{domains:j?.domains||[],onDomainSelect:F,onUnsetDomain:I,isLoading:M}),(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:o(`Enter your name`),value:d,onChange:e=>{f((0,O.ens_normalize)(e.target.value)),y||b(!0)},paddingRight:`120px`,fontSize:`lg`,height:`60px`,bg:c?`#00000038`:`white`,border:`1px solid ${c?`#ffffff29`:`#ebebeb`}`,_hover:{border:`1px solid ${c?`#ffffff40`:`#e0e0e0`}`},_focus:{border:`1px solid ${c?`#ffffff60`:`#d0d0d0`}`,boxShadow:`none`},isInvalid:!!p,"data-testid":`domain-input`}),(0,i.jsx)(n.InputRightElement,{width:`auto`,paddingRight:`12px`,h:`full`,children:(0,i.jsx)(n.Box,{mr:4,fontSize:`sm`,color:C,children:`.veworld.vet`})})]}),p&&y&&(0,i.jsx)(n.Text,{color:x,fontSize:`sm`,"data-testid":`domain-availability-status`,children:p}),!p&&y&&d.length>=3&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:_?S:x,fontWeight:`500`,"data-testid":`domain-availability-status`,children:o(h?`YOU OWN THIS`:_?`AVAILABLE`:`UNAVAILABLE`)})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!_||!!p||k||N,isLoading:N,onClick:P,loadingText:o(`Checking...`),"data-testid":`continue-button`,children:o(`Continue`)})})]})},Jr=({setCurrentContent:e,fullDomain:t,domainType:a=`veworld.vet`,isOwnDomain:o,isUnsetting:s=!1,initialContentSource:c=`settings`})=>{let{t:u}=(0,l.useTranslation)(),d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{isolatedView:f,closeAccountModal:p}=Fr(),{account:m,connectedWallet:h,connection:_}=X(),{data:v}=Is(m?.address??``,h?.address??``,3),{open:y}=Ao(),{preferences:b}=Tc(),{feeDelegation:x}=$(),S=e=>{console.error(`Transaction failed:`,e)},C=Rt({onSuccess:()=>N()}),w=a.endsWith(`veworld.vet`),T=et({subdomain:t.split(`.veworld.vet`)[0],domain:a,alreadyOwned:o,onSuccess:()=>N()}),E=it({domain:!s&&!w?t:``,alreadyOwned:o,onSuccess:()=>N()}),{sendTransaction:D,txReceipt:O,error:k,isWaitingForWalletConfirmation:A,isTransactionPending:j,clauses:M}=s?C:w?T:E,N=()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:O?.meta.txID,title:u(s?`Domain unset`:`Domain set`),description:s?u(`Your domain has been unset successfully.`):u(`Your address has been successfully set to {{name}}`,{name:t}),onDone:()=>{f?p():e(c)}}})},P=async()=>{if(v){y();return}try{await D()}catch(e){console.error(`Transaction failed:`,e)}},F=()=>{P()},I=()=>{e({type:`choose-name-search`,props:{setCurrentContent:e,name:t,initialContentSource:c}})},[L,R]=r.default.useState(null),[z,B]=r.default.useState(null),ee=b.availableGasTokens.length>0&&(_.isConnectedWithPrivy||_.isConnectedWithVeChain)&&!x?.delegatorUrl,{data:te,isLoading:V,error:ne,refetch:re}=Ec({clauses:M(),tokens:L?[L]:b.availableGasTokens,enabled:ee&&!!x?.genericDelegatorUrl}),ie=te?.usedToken,H=(V||!te)&&_.isConnectedWithPrivy&&!x?.delegatorUrl,ae=r.default.useCallback(e=>{R(e),B(e),setTimeout(()=>re(),100)},[re]),U=!!ie&&!ne;return r.default.useEffect(()=>{ne&&L&&R(null)},[ne,L]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`confirm-domain`,children:u(s?`Confirm Unset Domain`:`Confirm Name`)}),(0,i.jsx)(J,{onClick:I,isDisabled:j}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:j})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:d,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:d,children:s?u(`By confirming, your current domain will be unset`):u(`By confirming, your address will be set to {{domain}}`,{domain:t})})]}),!s&&(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,mt:6,children:(0,i.jsx)(n.Text,{fontSize:`xl`,fontWeight:`bold`,color:d,textAlign:`center`,"data-testid":`preconfirm-domain-val`,children:t})}),_.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:te,isLoading:V,isLoadingTransaction:j,onTokenChange:ae,clauses:M(),userSelectedToken:z})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Nc,{transactionError:k,isSubmitting:j,isTxWaitingConfirmation:A,onConfirm:P,onRetry:F,transactionPendingText:u(s?`Unsetting current domain...`:`Claiming name...`),txReceipt:O,buttonText:u(`Confirm`),isDisabled:j||H,onError:S,gasEstimationError:ne,hasEnoughGasBalance:U,isLoadingGasEstimation:V,showGasEstimationError:!x?.delegatorUrl&&_.isConnectedWithPrivy,context:`domain`})})]})},Yr=()=>{let{t:e}=(0,l.useTranslation)(),[t,a]=(0,r.useState)(``),o=(0,n.useToken)(`colors`,`vechain-kit-card`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),c=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),u=(0,n.useToken)(`colors`,`vechain-kit-card`),d=(0,n.useToken)(`colors`,`vechain-kit-card-elevated`),f=[{question:e(`What is VeChain?`),answer:e(`VeChain, headquartered in San Marino, Europe, is a pioneering blockchain ecosystem and creator of VeChainThor, a world-class smart contract platform driving real-world blockchain adoption. Founded in 2015 by Sunny Lu, VeChain has consistently worked to deliver a transparent, efficient, scalable, and adaptable blockchain solution.`)},{question:e(`What is a wallet?`),answer:e(`A wallet is your gateway to the VeChain blockchain. It stores your private keys and allows you to securely manage your digital assets, send and receive tokens, and interact with decentralized applications. Think of it as your digital bank account for blockchain transactions.`)},{question:e(`What is a Smart Account?`),answer:e(`A Smart Account is a smart contract wallet that provides enhanced security and functionality. It allows for features like social recovery, transaction batching, and more.`)},{question:e(`How is my wallet secured?`),answer:e(`Your wallet security depends on how you access it. With self-custody options like the VeWorld extension, mobile app, or hardware wallet, you have complete control over your private keys. This extension itself has no access to your private keys. When logging in with social accounts or VeChain, your wallet is created and secured by Privy and managed by VeChain, providing an easier onboarding experience while maintaining security.`)},{question:e(`How do I backup my wallet?`),answer:e(`Backing up your wallet is crucial as you are the only one with access to your private keys. If something goes wrong, having your private key is the only way to recover your assets. How to backup depends on how you access your wallet: If using VeWorld, the backup option is available within the app. For social login users, you can find backup options in the Wallet section. If you're connected through VeChain or another ecosystem app, you'll need to visit the original website, log in, and access the Wallet section from there.`)},{question:e(`What is a network?`),answer:e(`A network in blockchain refers to the environment where transactions take place. VeChain has two main networks: Mainnet (the live network where real transactions occur) and Testnet (a testing environment for developers). The network you're connected to is displayed at the top of this modal.`)},{question:e(`What is a domain name?`),answer:e(`A domain name is a sort of nickname for your wallet address. It allows you to easily identify your wallet and interact with dApps using a human-readable name. For example, if your wallet address is 0x1234567890, your nickname could be "alice.vechain".`)},{question:e(`What is Privy?`),answer:e(`Privy builds user onboarding and embedded wallet infrastructure to enable better products built on crypto rails. This means embedding asset control within applications themselves to enable users, businesses or machines to use digital assets through seamless product experiences.`)},{question:e(`What is VeBetterDAO?`),answer:e(`VeBetterDAO is a decentralized organization on VeChain blockchain focused on sustainability. Members participate in the governance of the DAO using B3TR tokens for rewards and VOT3 for voting in proposals and weekly token allocation rounds.`)},{question:e(`What is an x2earn application?`),answer:e(`An X2Earn application in VeBetterDAO is a sustainable app that rewards users with B3TR tokens for eco-friendly actions. These apps must distribute B3TR, link user wallets, and provide proof of sustainable actions. They join VeBetterDAO through endorsement and participate in weekly token allocation rounds.`)},{question:e(`What is B3TR?`),answer:e(`B3TR is the incentive token of VeBetterDAO, built on VechainThor blockchain. It has a capped supply of 1 billion tokens, emitted weekly over 12 years. B3TR is used for rewards, governance, and backing VOT3 tokens 1:1. It supports sustainability applications and DAO treasury management.`)},{question:e(`What is VET?`),answer:e(`VET is the primary cryptocurrency of the VeChain network. It represents value and ownership in the VeChain ecosystem, similar to how stocks represent ownership in a company. Holding VET automatically generates VTHO, which is needed to pay for transactions on the network.`)},{question:e(`What is VTHO?`),answer:e(`VTHO (VeThor) is the energy or 'gas' token of the VeChain network. It's used to pay for transaction fees when interacting with the blockchain. VTHO is automatically generated by holding VET tokens, creating a two-token system that helps maintain network stability and manage transaction costs.`)},{question:e(`How do I send tokens?`),answer:e(`You can send tokens by clicking the send icon in the Quick Actions section. Enter the recipient's address or VeChain domain name, select the token, and specify the amount you want to send.`)},{question:e(`What is fee delegation?`),answer:e(`Fee delegation is a unique feature of VeChain that allows someone else (a delegator) to pay for your transaction fees. While many dApps and service providers act as delegators to make it easier for new users to get started, some transactions may still require you to pay fees using your own VTHO. Fees are necessary to prevent network spam and compensate the nodes that process and validate transactions on the blockchain. When paying fees yourself, you'll be able to select VTHO from your assets to cover the transaction cost.`)}].filter(e=>e.question.toLowerCase().includes(t.toLowerCase())||typeof e.answer==`string`&&e.answer.toLowerCase().includes(t.toLowerCase()));return(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:e(`Search FAQ`),bg:o,borderRadius:`xl`,height:`56px`,pl:12,value:t,onChange:e=>a(e.target.value)}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:c})})]}),f.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,color:s,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`lg`,children:e(`No questions found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,children:e(`Try searching with a different term`)})]}):(0,i.jsx)(n.Accordion,{allowMultiple:!0,children:f.map((e,t)=>(0,i.jsx)(n.AccordionItem,{border:`none`,mb:2,children:({isExpanded:t})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:u,borderRadius:`xl`,color:s,_hover:{bg:d},children:[(0,i.jsx)(n.Box,{flex:`1`,textAlign:`left`,py:2,children:(0,i.jsx)(n.Text,{fontWeight:`500`,color:s,children:e.question})}),(0,i.jsx)(n.Icon,{as:t?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,opacity:.5})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,children:(0,i.jsx)(n.Text,{fontSize:`sm`,color:s,opacity:.8,children:e.answer})})]})},t))})]})},Xr=({onGoBack:t,showLanguageSelector:r=!0})=>{let{i18n:a,t:o}=(0,l.useTranslation)(),{isolatedView:s}=Fr(),c=(0,n.useToken)(`colors`,`vechain-kit-card`),u=(0,n.useToken)(`colors`,`vechain-kit-border`),d=(0,n.useToken)(`colors`,`vechain-kit-border-hover`);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:o(`Help`)}),!s&&(0,i.jsx)(J,{onClick:t}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[r&&(0,i.jsx)(n.Select,{borderRadius:`md`,size:`sm`,width:`auto`,value:a.language,onChange:e=>{a.changeLanguage(e.target.value)},bg:c,borderColor:u,_hover:{borderColor:d},children:ie.map(e=>(0,i.jsx)(`option`,{value:e,children:ae[e]},e))}),(0,i.jsx)(n.Button,{as:n.Link,href:e.C,isExternal:!0,variant:`vechainKitSecondary`,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuExternalLink}),children:o(`For developers`)}),(0,i.jsx)(Yr,{})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Zr=({leftIcon:e,rightIcon:r,title:a,wallet:o,onClick:s,leftImage:c,isActive:u=!1})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f}=$();return(0,i.jsx)(n.Button,{w:`full`,minH:`70px`,h:`fit-content`,py:4,onClick:s,backgroundColor:`transparent`,border:`1px solid ${f?`#ffffff29`:`#ebebeb`}`,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,children:[(0,i.jsx)(n.Box,{minW:`40px`,justifyContent:`center`,children:c?(0,i.jsx)(n.Image,{justifySelf:`center`,src:c,w:`28px`,alt:`left-image`}):(0,i.jsx)(n.Icon,{as:e,fontSize:`28px`})}),(0,i.jsxs)(n.VStack,{textAlign:`left`,w:`full`,flex:1,children:[(0,i.jsx)(n.HStack,{w:`full`,spacing:2,justifyContent:`flex-start`,children:(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,children:a})}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,opacity:.5,overflowWrap:`break-word`,wordBreak:`break-word`,whiteSpace:`normal`,w:`full`,children:o?.domain?t.G(o?.domain??``,18,0):t.W(o?.address??``,6,4)})]}),(0,i.jsx)(n.VStack,{minW:`40px`,justifyContent:`flex-end`,children:(0,i.jsxs)(n.HStack,{justifyContent:`flex-end`,minW:`40px`,children:[u&&(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`green`,children:d(`Active`)}),(0,i.jsx)(n.Icon,{as:r,fontSize:`20px`,opacity:.5})]})})]})})},Z=({leftIcon:e,rightIcon:t,title:r,onClick:a,leftImage:o,hide:s=!1,showComingSoon:c=!1,backgroundColor:u,_hover:d,isDisabled:f=!1,stacked:p=!1,isLoading:m,loadingText:h,style:g,extraContent:_,dataTestId:v,variant:y=`actionButton`})=>{let{t:b}=(0,l.useTranslation)();return(0,i.jsx)(n.Button,{variant:y===`actionButton`?`vechainKitSecondary`:y,py:p?0:2,minHeight:`50px`,height:`fit-content`,p:0,onClick:a,display:s?`none`:`flex`,isDisabled:c||f,isLoading:m,loadingText:h,bgColor:u,_hover:d,"data-testid":v,...g,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Box,{minW:`40px`,h:`20px`,children:o?(0,i.jsx)(n.Image,{src:o,w:`30px`,h:`30px`,borderRadius:`full`,alt:`left-image`,alignSelf:`end`,objectFit:`cover`}):(0,i.jsx)(n.Icon,{as:e,fontSize:`20px`,h:`full`,alignContent:`center`})}),(0,i.jsx)(n.VStack,{textAlign:`left`,w:`full`,flex:1,justifyContent:`flex-start`,alignItems:`flex-start`,children:(0,i.jsxs)(n.HStack,{justify:`flex-start`,alignItems:`baseline`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,children:r}),c&&(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`red`,children:b(`Coming Soon!`)}),_]})}),t&&(0,i.jsx)(n.VStack,{minW:`40px`,justifyContent:`flex-end`,children:(0,i.jsx)(n.Icon,{as:t,fontSize:`20px`,opacity:.5})})]})})},Qr=({wallet:e,setCurrentContent:a,size:o=`md`,onClick:s,onClose:c,mt:u,style:d})=>{let{t:p}=(0,l.useTranslation)(),{connection:m}=X(),{switchWallet:h,isSwitching:_,isInAppBrowser:v}=Fn(),{isSwitchWalletEnabled:y}=(0,f.useWallet)(),[b,x]=(0,r.useState)(!1),S=async()=>{await t.lt(e?.domain??e?.address??``)&&(x(!0),setTimeout(()=>{x(!1)},2e3))},C=()=>{v?h():a?.({type:`select-wallet`,props:{setCurrentContent:a,onClose:c,returnTo:`main`,onLogoutSuccess:c}})};return(0,i.jsxs)(n.HStack,{mt:u,w:`full`,...d,justifyContent:`flex-start`,alignItems:`center`,children:[(0,i.jsx)(n.Button,{w:`full`,h:12,"aria-label":`Wallet`,onClick:s,variant:`vechainKitSecondary`,p:3,"data-testid":`profile-button`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`center`,justifyContent:`space-between`,w:`full`,children:[(0,i.jsxs)(n.HStack,{spacing:2,justifyContent:`flex-start`,children:[(0,i.jsx)(Mc,{wallet:e,props:{width:7,height:7}}),(0,i.jsx)(n.Text,{fontSize:o,fontWeight:`500`,children:b?p(`Copied!`):t.G(e?.domain??``,22,0)||t.W(e?.address??``,6,4)})]}),(0,i.jsx)(n.Icon,{boxSize:5,as:g.LuChevronRight,cursor:`pointer`,opacity:.5})]})}),m.isInAppBrowser&&y||!m.isInAppBrowser&&m.isConnectedWithDappKit?(0,i.jsx)(n.IconButton,{"aria-label":`Switch wallet`,icon:(0,i.jsx)(n.Icon,{as:g.LuArrowLeftRight}),onClick:C,w:`60px`,h:12,variant:`vechainKitSecondary`,p:3,isLoading:_,isDisabled:_,"data-testid":`switch-wallet-button`}):(0,i.jsx)(n.IconButton,{"aria-label":`Copy address`,icon:(0,i.jsx)(n.Icon,{as:b?g.LuCheck:g.LuCopy}),onClick:S,w:`60px`,h:12,variant:`vechainKitSecondary`,p:3})]})},$r=({address:e,maxIcons:a=3,iconSize:o=20,ml:s=0,style:c,iconsGap:u=0,rightIcon:d,showNoAssetsWarning:f=!1,onClick:p})=>{let{t:m}=(0,l.useTranslation)(),{tokensWithBalance:h}=Zt({address:e}),{darkMode:g}=$(),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=u<1?`-${o/2}px`:`${u}px`,y=h.slice(0,a),b=h.length-a;return!e||h.length===0&&!f?null:(0,i.jsxs)(n.HStack,{spacing:0,ml:s,...c,onClick:p,children:[(0,i.jsxs)(n.HStack,{spacing:0,children:[y.map((e,a)=>(0,i.jsx)(n.Circle,{ml:a>0?v:`0`,zIndex:a,size:`${o}px`,borderRadius:`full`,bg:g?`gray.100`:`gray.600`,border:`2px solid #00000024`,alignItems:`center`,justifyContent:`center`,children:t.et[e.symbol]?r.default.cloneElement(t.et[e.symbol],{width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):t.$[e.symbol]?(0,i.jsx)(n.Image,{src:t.$[e.symbol],alt:`${e.symbol} logo`,width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):(0,i.jsx)(n.Text,{fontSize:`${o*.4}px`,fontWeight:`bold`,color:g?`black`:`white`,children:e.symbol.slice(0,3)})},e.symbol)),b>0&&(0,i.jsx)(n.Circle,{ml:v,zIndex:y.length,size:`${o}px`,borderRadius:`full`,bg:g?`gray.100`:`gray.700`,display:`flex`,alignItems:`center`,justifyContent:`center`,border:`2px solid`,children:(0,i.jsxs)(n.Text,{fontSize:`${o*.4}px`,fontWeight:`bold`,color:g?`black`:`white`,children:[`+`,b]})}),h.length===0&&f&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:_,fontWeight:`700`,children:m(`No assets`)})]}),d]})},ei=({mb:e,mt:t,onAssetsClick:a})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{formattedBalance:c,isLoading:u}=Qt({address:s?.address??``}),{refresh:d}=Pn(),[f,p]=(0,r.useState)(!1),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=async()=>{p(!0),await d(),setTimeout(()=>{p(!1)},1500)},[_,v]=mc(pc.SHOW_ASSETS,!0);return(0,i.jsxs)(n.VStack,{w:`full`,justifyContent:`start`,spacing:1,mt:t,mb:e,children:[(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,alignItems:`center`,spacing:0,role:`group`,children:[(0,i.jsx)(n.Heading,{size:`xs`,fontWeight:`800`,color:m,textTransform:`uppercase`,letterSpacing:1.2,ml:`5px`,children:o(`Assets`)}),(0,i.jsxs)(n.HStack,{spacing:0,alignItems:`center`,children:[(0,i.jsx)(n.IconButton,{"aria-label":`Refresh balances`,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},onClick:h,icon:(0,i.jsx)(n.Icon,{as:g.LuRefreshCw,boxSize:4}),isLoading:u||f,sx:{"& > span.chakra-button__spinner":{width:`16px`,height:`16px`,position:`absolute`}}}),(0,i.jsx)(n.IconButton,{"aria-label":`Show/hide assets`,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},onClick:()=>v(!_),icon:(0,i.jsx)(n.Icon,{as:_?A.GoEye:A.GoEyeClosed,boxSize:4})})]})]}),(0,i.jsx)(n.Button,{onClick:a,h:`fit-content`,variant:`vechainKitSecondary`,children:(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,justifyContent:`flex-start`,alignItems:`flex-start`,mt:4,mb:4,children:[(0,i.jsx)(n.Heading,{size:`2xl`,fontWeight:`700`,children:_?c:`$****`}),(0,i.jsx)(n.HStack,{w:`full`,justifyContent:`flex-start`,"data-testid":`all-assets-button`,mt:2,children:(0,i.jsx)($r,{style:{width:`100%`,justifyContent:`space-between`},maxIcons:10,iconSize:26,iconsGap:3,address:s?.address??``,showNoAssetsWarning:!0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuChevronRight,boxSize:5,opacity:.5,marginLeft:2})})})]})})]})},ti=[{icon:g.LuArrowUpFromLine,label:`Send`,onClick:e=>e({type:`send-token`,props:{setCurrentContent:e}}),isDisabled:e=>!e},{icon:g.LuArrowLeftRight,label:`Swap`,onClick:e=>{e(`swap-token`)},isDisabled:e=>!e},{icon:g.LuArrowDownToLine,label:`Receive`,onClick:e=>{e(`receive-token`)}}],ni=({icon:e,label:t,onClick:r,isDisabled:a,showRedDot:o})=>{let{t:s}=(0,l.useTranslation)();return(0,i.jsx)(n.IconButton,{variant:`vechainKitSecondary`,h:`80px`,w:`full`,"aria-label":t,isDisabled:a,p:3,icon:(0,i.jsxs)(n.VStack,{spacing:4,children:[(0,i.jsx)(n.Icon,{as:e,boxSize:5,opacity:.9}),(0,i.jsxs)(n.HStack,{p:0,alignItems:`baseline`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`600`,"data-testid":`${t.toLowerCase()}-button-label`,children:s(t,t)}),o&&(0,i.jsx)(n.Box,{minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`})]})]}),onClick:r})},ri=({mt:e,setCurrentContent:t})=>{let{account:r,smartAccount:a,connectedWallet:o,connection:s}=X(),{hasAnyBalance:c}=Qt({address:r?.address??``}),{data:l}=Is(a?.address??``,o?.address??``,3),u=s.isConnectedWithPrivy&&l;return(0,i.jsx)(n.Grid,{templateColumns:`repeat(3, 1fr)`,gap:2,w:`full`,mt:e,children:ti.map(e=>(0,i.jsx)(ni,{icon:e.icon,label:e.label,onClick:()=>e.onClick(t),isDisabled:e.isDisabled?.(c),showRedDot:u&&e.label===`Settings`},e.label))})},ii=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),r=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsx)(n.Card,{w:`full`,variant:`featureAnnouncement`,overflow:`hidden`,onClick:()=>{e({type:`choose-name`,props:{setCurrentContent:e,onBack:()=>e(`profile`),initialContentSource:`profile`}})},cursor:`pointer`,_hover:{opacity:.8},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsx)(n.HStack,{justify:`space-between`,align:`flex-start`,spacing:3,children:(0,i.jsxs)(n.VStack,{align:`flex-start`,spacing:1,children:[(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`400`,color:r,children:t(`Claim your vet domain!`)}),(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:`red`,children:t(`New`)})]}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:a,children:t(`Say goodbye to 0x addresses, claim your .veworld.vet subdomain now for free!`)})]})})})})},ai=()=>{let{t:e}=(0,l.useTranslation)();return(0,i.jsx)(n.Alert,{status:`warning`,fontSize:`xs`,borderRadius:`xl`,p:2,children:(0,i.jsx)(n.VStack,{spacing:1,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`flex-start`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:4,mt:`10px`}),(0,i.jsx)(n.Text,{w:`full`,children:e(`Sending to OceanX or other exchanges may result in loss of funds.`)})]})})})},oi=()=>{let{t:e}=(0,l.useTranslation)();return(0,i.jsx)(n.Alert,{status:`warning`,fontSize:`xs`,borderRadius:`xl`,p:2,children:(0,i.jsx)(n.VStack,{spacing:1,align:`stretch`,w:`full`,children:(0,i.jsxs)(n.HStack,{spacing:2,align:`flex-start`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:4,mt:`10px`}),(0,i.jsx)(n.Text,{w:`full`,children:e(`A .vet domain is required to customize your profile. Choose an account name to get started.`)})]})})})},si=()=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Vo(),a=r();return(0,i.jsxs)(n.Card,{variant:`vechainKitBase`,w:`full`,children:[(0,i.jsxs)(n.CardHeader,{p:4,pl:6,borderBottomWidth:`1px`,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,opacity:.8,children:t(`Security preferences`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,mt:1,opacity:.7,children:t(`For security reasons, you can manage your embedded wallet settings only on the {{appName}} platform.`,{appName:a?.ecosystemApp.name??`origin app`})})]}),(0,i.jsx)(n.CardBody,{borderRadius:`none`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`stretch`,children:[(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Center,{w:`fit-content`,h:`fit-content`,p:2,borderRadius:`full`,bg:`blackAlpha.100`,flexShrink:0,children:(0,i.jsx)(n.Icon,{as:g.LuUserCog})}),(0,i.jsxs)(n.Box,{flex:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`shorter`,children:t(`Login methods`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:t(`Manage your login methods and passkeys`)})]})]}),(0,i.jsxs)(n.HStack,{spacing:3,align:`center`,children:[(0,i.jsx)(n.Center,{w:`fit-content`,h:`fit-content`,p:2,borderRadius:`full`,bg:`blackAlpha.100`,flexShrink:0,children:(0,i.jsx)(n.Icon,{as:g.LuShieldCheck})}),(0,i.jsxs)(n.Box,{flex:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`shorter`,children:t(`Security settings`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:t(`Backup your wallet, configure MFA and set recovery options`)})]})]})]})}),(0,i.jsx)(n.CardFooter,{children:(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,w:`full`,onClick:()=>{window.open(a?.ecosystemApp.website??e.y,`_blank`)},children:[t(`Manage on {{appName}}`,{appName:a?.ecosystemApp.name??`origin app`}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},ci=({setCurrentContent:e,initialContentSource:a=`profile`})=>{let{t:o}=(0,l.useTranslation)(),{network:s}=$(),{account:c}=X(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-error`),f=(0,n.useToken)(`colors`,`vechain-kit-card`),p=(0,r.useRef)(null),m=(0,r.useRef)(null),[h,_]=(0,r.useState)(!1),{onUpload:v}=Zn({compressImage:!0}),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(null),C=!!c?.domain,[w,T]=(0,r.useState)(null),[E,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(``),{register:j,watch:M,formState:{errors:N,isValid:P}}=(0,D.useForm)({defaultValues:{displayName:c?.metadata?.display||``,description:c?.metadata?.description||``},mode:`onChange`});(0,r.useEffect)(()=>{if(c?.metadata){let e=c.metadata;O(e.display||``),A(e.description||``),T(c.image?c.image.replace(`ipfs://`,``):null),b(e=>e??c.image??null)}},[c,s.type]);let F=M(),I=async e=>{let n=e.target.files?.[0];if(n)try{_(!0),y&&URL.revokeObjectURL(y),b(URL.createObjectURL(n));let e=await v(n);if(!e)throw Error(`Failed to compress image`);S(await t.D(e.file,n.name,s.type))}catch(e){console.error(`Error uploading image:`,e),b(null)}finally{_(!1)}};(0,r.useEffect)(()=>()=>{y&&URL.revokeObjectURL(y)},[y]);let L=()=>{let e={};return x!==w&&x&&(e.avatarIpfsHash=x),F.displayName!==E&&(e.displayName=F.displayName),F.description!==k&&(e.description=F.description),e},R=(0,r.useMemo)(()=>{let e=L();return Object.keys(e).length>0},[L]),z=()=>{e({type:`account-customization-summary`,props:{setCurrentContent:e,changes:L(),onDoneRedirectContent:a}})},B=()=>{e(a)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Customization`)}),(0,i.jsx)(J,{onClick:B}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.Box,{cursor:C?`pointer`:`default`,pt:2,display:`flex`,justifyContent:`center`,position:`relative`,onClick:()=>C&&p.current?.click(),children:[(0,i.jsx)(Mc,{wallet:c,props:{width:`100px`,height:`100px`,boxShadow:`0px 0px 3px 2px #00000024`,src:y??void 0}}),C&&(0,i.jsx)(n.Icon,{as:g.LuCamera,position:`absolute`,top:`80px`,left:`60%`,bg:f,color:u,p:`1`,borderRadius:`full`,boxSize:`6`}),h&&(0,i.jsx)(n.Box,{display:`flex`,alignItems:`center`,justifyContent:`center`,backgroundColor:`rgba(0, 0, 0, 0.5)`,position:`absolute`,transform:`translateX(0%)`,width:`100px`,height:`100px`,borderRadius:`full`,zIndex:10,children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:`white`,children:h?`Uploading...`:`Processing...`})})]}),(0,i.jsxs)(n.VStack,{spacing:6,mt:4,children:[!C&&(0,i.jsx)(oi,{}),(0,i.jsx)(Z,{title:c?.domain??o(`Choose account name`),description:o(`Choose a unique .vet domain name for your account.`),onClick:()=>{c?.domain?e({type:`choose-name-search`,props:{name:``,setCurrentContent:e,initialContentSource:{type:`account-customization`,props:{setCurrentContent:e}}}}):e({type:`choose-name`,props:{setCurrentContent:e,initialContentSource:{type:`account-customization`,props:{setCurrentContent:e}},onBack:()=>e({type:`account-customization`,props:{setCurrentContent:e}})}})},leftIcon:g.LuSquareUser,rightIcon:g.LuChevronRight,dataTestId:`set-domain-name-button`}),(0,i.jsxs)(n.FormControl,{isDisabled:!C,isInvalid:!!N.displayName,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:u,children:o(`Display Name`)}),(0,i.jsx)(n.Input,{...j(`displayName`,{maxLength:{value:25,message:o(`Display name must be less than 25 characters`)}}),placeholder:o(C?`Enter your display name`:`Set a domain first`),fontWeight:`medium`,color:u,"data-testid":`display-name-input`}),N.displayName&&(0,i.jsx)(n.Text,{color:d,fontSize:`sm`,mt:1,fontWeight:`medium`,children:N.displayName.message})]}),(0,i.jsxs)(n.FormControl,{isDisabled:!C,isInvalid:!!N.description,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:u,children:o(`Description`)}),(0,i.jsx)(n.Textarea,{...j(`description`,{maxLength:{value:100,message:o(`Description must be less than 100 characters`)}}),placeholder:o(`Eg: DevRel @ ENS Labs`),fontWeight:`medium`,color:u,"data-testid":`description-input`,minH:`50px`}),N.description&&(0,i.jsx)(n.Text,{color:d,mt:1,fontSize:`sm`,fontWeight:`medium`,children:N.description.message})]})]}),(0,i.jsx)(`input`,{type:`file`,ref:p,hidden:!0,accept:`image/*`,onChange:async e=>await I(e)}),(0,i.jsx)(`input`,{type:`file`,ref:m,hidden:!0,accept:`image/*`,onChange:async e=>{e.preventDefault()}})]}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:z,isDisabled:!C||!R||!P,isLoading:h,loadingText:o(`Preparing changes...`),"data-testid":`save-changes-button`,children:o(`Save Changes`)})})]})},li=({setCurrentContent:e,changes:a,onDoneRedirectContent:o})=>{let{t:s}=(0,l.useTranslation)(),{darkMode:c,network:u,feeDelegation:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{account:m,connectedWallet:h,connection:_}=X(),{preferences:v}=Tc(),{data:y}=Is(m?.address??``,h?.address??``,3),{open:b}=Ao(),{handleSubmit:x}=(0,D.useForm)({defaultValues:{...a,avatarIpfsHash:a.avatarIpfsHash??void 0}}),S=m?.domain??``,{data:C}=wt(S),w=(0,p.useQueryClient)(),{sendTransaction:T,txReceipt:E,error:O,isWaitingForWalletConfirmation:k,isTransactionPending:A,clauses:j}=St({resolverAddress:C,signerAccountAddress:m?.address??``,onSuccess:async()=>{try{await ce()}catch(e){console.error(`Error refreshing data:`,e)}},onError:e=>{console.error(`Error updating text record:`,e)}}),[M,N]=r.default.useState(!1);r.default.useEffect(()=>{if(!E||E.reverted||M||A)return;let t=E.meta.txID;t&&(N(!0),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:s(`Profile Updated`),description:s(`Your changes have been saved successfully.`),onDone:()=>{e(o)}}}))},[E,M,A,e,s,o]),r.default.useEffect(()=>{A&&N(!1)},[A]);let P=(0,r.useMemo)(()=>{let e=m?.domain??``,t={displayName:`display`,description:`description`,twitter:`com.x`,website:`url`,email:`email`,avatarIpfsHash:`avatar`};return Object.entries(a).filter(e=>e[1]!==void 0&&e[1]!==null).map(([n,r])=>({domain:e,key:t[n],value:n===`avatarIpfsHash`?`ipfs://${r}`:r}))},[a,m?.domain]),F=(0,r.useMemo)(()=>{try{return!C||P.length===0||!j?[]:j(P)}catch(e){return console.error(`Error building clauses:`,e),[]}},[P,j,C]),[I,L]=r.default.useState(null),[R,z]=r.default.useState(null),B=v.availableGasTokens.length>0&&(_.isConnectedWithPrivy||_.isConnectedWithVeChain)&&!d?.delegatorUrl,{data:ee,isLoading:te,error:V,refetch:ne}=Ec({clauses:F,tokens:I?[I]:v.availableGasTokens,enabled:B&&!!d?.genericDelegatorUrl}),re=ee?.usedToken,ie=(te||!ee)&&_.isConnectedWithPrivy&&!d?.delegatorUrl,H=r.default.useCallback(e=>{L(e),z(e),setTimeout(()=>ne(),100)},[ne]),ae=!!re&&!V;r.default.useEffect(()=>{V&&I&&L(null)},[V,I]);let U=async()=>{if(y){b();return}try{P.length>0&&await T(P)}catch(e){console.error(`Error saving changes:`,e)}},oe=(e,t)=>t?.trim()?(0,i.jsxs)(n.VStack,{align:`flex-start`,w:`full`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:c?`whiteAlpha.600`:`blackAlpha.600`,children:e}),(0,i.jsx)(n.Text,{fontSize:`md`,children:t})]}):null,W=()=>{x(U)()},se=()=>{e({type:`account-customization`,props:{setCurrentContent:e}})},ce=async()=>{a.avatarIpfsHash&&(w.setQueryData(mt(S,u.type),t.g(`ipfs://`+a.avatarIpfsHash,u.type)),w.setQueryData(Ot(m?.address??``),t.g(`ipfs://`+a.avatarIpfsHash,u.type))),await w.invalidateQueries({queryKey:vt(S,u.type)}),await w.refetchQueries({queryKey:vt(S,u.type)})};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Confirm Changes`)}),(0,i.jsx)(J,{isDisabled:A,onClick:se}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:A})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuFileText,color:f,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:f,children:s(`By confirming, the following details attached to your name ({{domain}}) will be updated`,{domain:S})})]}),(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,mt:6,children:[a.avatarIpfsHash&&(0,i.jsxs)(n.VStack,{align:`flex-start`,w:`full`,spacing:1,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:c?`whiteAlpha.600`:`blackAlpha.600`,children:s(`Profile Image`)}),(0,i.jsx)(n.Text,{fontSize:`md`,children:s(`New image selected`)})]}),a.displayName&&oe(s(`Display Name`),a.displayName),a.description&&oe(s(`Description`),a.description),a.twitter&&oe(s(`Twitter`),a.twitter),a.website&&oe(s(`Website`),a.website),a.email&&oe(s(`Email`),a.email)]}),_.isConnectedWithPrivy&&(0,i.jsx)(Ic,{estimation:ee,isLoading:te,isLoadingTransaction:A,onTokenChange:H,clauses:F,userSelectedToken:R})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Nc,{transactionError:O,isSubmitting:A,isTxWaitingConfirmation:k,onConfirm:x(U),onRetry:W,transactionPendingText:s(`Saving changes...`),txReceipt:E,buttonText:s(`Confirm`),isDisabled:A||ie,gasEstimationError:V,hasEnoughGasBalance:ae,isLoadingGasEstimation:te,showGasEstimationError:!d?.delegatorUrl&&_.isConnectedWithPrivy,context:`customization`})})]})},ui=({address:e,showHeader:r=!0,showLinks:a=!0,showDescription:o=!0,showDisplayName:s=!0,reserveNameDescriptionSpace:c=!1,setCurrentContent:l,onLogout:u})=>{let{network:d}=$(),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-card`),h=Mn(e,d.type),_=t.U(e),v=h?.records?.url||h?.records?.[`com.x`]||h?.records?.email,y=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`?t.toString():null}catch{return null}};return(0,i.jsxs)(n.VStack,{spacing:0,w:`full`,children:[(0,i.jsx)(n.Box,{p:0,backgroundSize:`100% !important`,backgroundPosition:`center`,position:`relative`,background:r?`no-repeat url('${_}')`:`none`,w:`100%`,borderRadius:`14px 14px 0 0`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,cursor:l?`pointer`:`default`,onClick:l?()=>{l({type:`account-customization`,props:{setCurrentContent:l,initialContentSource:`profile`}})}:void 0,children:[(0,i.jsx)(Mc,{wallet:{address:e,domain:h?.domain,image:h?.image,isLoadingMetadata:h?.isLoading,metadata:h?.records},props:{width:`120px`,height:`120px`}}),l&&(0,i.jsx)(n.Icon,{as:g.LuPencil,position:`absolute`,bottom:`0`,right:`0`,bg:m,color:f,p:`1`,borderRadius:`full`,boxSize:`6`,border:`2px solid`,borderColor:m})]}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[s&&(h?.records?.display?(0,i.jsx)(n.Text,{fontSize:`xl`,color:f,fontWeight:`bold`,w:`full`,textAlign:`center`,mt:2,"data-testid":`display-name-val`,children:h?.records?.display}):c&&(0,i.jsx)(n.Box,{mt:2,minH:`28px`,"aria-hidden":!0})),o&&(h?.records?.description?(0,i.jsx)(n.Text,{fontSize:`sm`,color:p,w:`full`,textAlign:`center`,"data-testid":`description-val`,children:h?.records?.description}):c&&(0,i.jsx)(n.Box,{minH:`20px`,"aria-hidden":!0})),a&&v&&(0,i.jsxs)(n.HStack,{w:`full`,justify:`center`,spacing:5,mt:4,children:[h?.records?.email&&(0,i.jsx)(n.Link,{href:`mailto:${h?.records?.email}`,target:`_blank`,"data-testid":`mail-link`,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:f})}),h?.records?.url&&(0,i.jsx)(n.Link,{href:y(h.records.url)??void 0,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`website-link`,children:(0,i.jsx)(n.Icon,{as:g.LuGlobe,color:f})}),h?.records?.[`com.x`]&&(0,i.jsx)(n.Link,{href:`https://x.com/${encodeURIComponent(String(h.records[`com.x`]))}`,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`twitter-link`,children:(0,i.jsx)(n.Icon,{as:j.FaXTwitter,color:f})})]}),(0,i.jsx)(Oe,{onLogout:u,wallet:{address:e,domain:h?.domain,image:h?.image,isLoadingMetadata:h?.isLoading,metadata:h?.records},style:{mt:4},setCurrentContent:l})]})]})},di=({onClick:e,...t})=>{let{smartAccount:a,connectedWallet:o,connection:s}=X(),[c,l]=(0,r.useState)(!1);(0,r.useEffect)(()=>{l(!localStorage.getItem(`app-first-visit`))},[]);let{data:u}=Is(a?.address??``,o?.address??``,3),d=s.isConnectedWithPrivy&&u,f=()=>{c&&(localStorage.setItem(`app-first-visit`,`true`),l(!1)),e()};return(0,i.jsx)(n.IconButton,{"aria-label":`Settings`,size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,lineHeight:`0`,onClick:f,icon:(0,i.jsxs)(n.Box,{position:`relative`,children:[(0,i.jsx)(n.Icon,{as:g.LuSettings2,fontSize:`18px`}),d&&(0,i.jsx)(n.Box,{position:`absolute`,top:`-1px`,right:`-1px`,minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`})]}),...t})},fi=({setCurrentContent:e,onLogoutSuccess:t,switchFeedback:r})=>{let{t:a}=(0,l.useTranslation)(),{account:o,disconnect:s,connection:c}=X(),{switchWallet:u,isSwitching:d,isInAppBrowser:p}=Fn(),{isSwitchWalletEnabled:m}=(0,f.useWallet)(),{hasAnyBalance:h,formattedBalance:_}=Qt({address:o?.address}),[v]=mc(pc.SHOW_ASSETS,!0),y=()=>{p?u():e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:`profile`,onLogoutSuccess:t}})};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Profile`)}),(0,i.jsx)(di,{onClick:()=>{e(`settings`)},"data-testid":`settings-button`}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:6,children:[(0,i.jsx)(Bc,{showFeedback:r?.showFeedback}),!o?.domain&&(0,i.jsx)(ii,{setCurrentContent:e}),(0,i.jsx)(ui,{reserveNameDescriptionSpace:!!o?.domain,onEditClick:()=>{e({type:`account-customization`,props:{setCurrentContent:e,initialContentSource:`profile`}})},address:o?.address??``,showHeader:!1,setCurrentContent:e,onLogout:()=>{s(),t?.()}})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.HStack,{w:`full`,justify:`space-between`,spacing:4,mt:4,children:[(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:h?void 0:(0,i.jsx)(n.Icon,{as:g.LuWalletCards}),onClick:()=>e(`main`),"data-testid":`wallet-button`,children:h?(0,i.jsxs)(n.HStack,{spacing:2,w:`full`,justify:`center`,children:[(0,i.jsx)($r,{address:o?.address??``,maxIcons:2}),(0,i.jsx)(n.Text,{fontWeight:`600`,children:v?_:`$****`})]}):a(`Wallet`)}),c.isInAppBrowser&&m||!c.isInAppBrowser&&c.isConnectedWithDappKit?(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowLeftRight}),colorScheme:`red`,onClick:async()=>{y()},isLoading:d,isDisabled:d,"data-testid":`switch-wallet-button`,children:a(`Switch`)}):(0,i.jsx)(n.Button,{size:`md`,width:`full`,height:`40px`,variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuLogOut}),colorScheme:`red`,onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:()=>{s(),t?.()},onBack:()=>e?.(`profile`)}}),"data-testid":`logout-button`,children:a(`Logout`)})]})})]})},pi=({setCurrentContent:e,handleClose:t,initialContent:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=Is(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Vs({smartAccountAddress:o?.address??``,targetVersion:3,onSuccess:()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:m?.meta.txID,title:a(`Upgrade Successful!`),description:a(`Your account has been successfully upgraded to the latest version. You can now enjoy a better user experience, lower gas costs, and enhanced security.`),onDone:()=>{t?t():e(r)},showSocialButtons:!1}})},onError:()=>{console.error(`Error upgrading Smart Account`)}});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(J,{onClick:()=>{e(r)}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:10,align:`stretch`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a(c?`Your smart account needs to be upgraded to the latest version (v3).`:`Your smart account is already upgraded to this version.`)}),(0,i.jsxs)(n.HStack,{align:`center`,justifyContent:`space-evenly`,rounded:`md`,children:[(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{borderRadius:`full`,src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#D23F63`,fontSize:`28px`,children:`v1`})]}),(0,i.jsx)(n.Icon,{as:g.LuArrowRight,color:`#3DBA67`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{borderRadius:`full`,src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#3DBA67`,fontSize:`28px`,children:`v3`})]})]}),(0,i.jsxs)(n.Alert,{status:`info`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,children:a(`Benefits of this upgrade:`)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,children:(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,mt:1,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,lineHeight:`1.2`,children:[`• `,a(`Improved security features`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`• `,a(`Better transaction handling`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Enhanced compatibility with dApps`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Reduced gas costs for operations`)]})]})})]})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(Nc,{buttonText:a(c?`Upgrade account`:`Account already upgraded`),onConfirm:async()=>{try{await u()}catch(e){console.error(`Failed to upgrade Smart Account:`,e)}},isTxWaitingConfirmation:f,isSubmitting:d,transactionPendingText:a(`Upgrading...`),txReceipt:m,transactionError:p,isDisabled:!c}),(0,i.jsx)(n.Button,{mt:2,variant:`link`,onClick:()=>{t?t():e(r)},isDisabled:d,children:a(c?`Close and do this later`:`Close`)})]})})]})},mi=({setCurrentContent:e})=>{let{account:a}=X(),{sortedTokens:o}=Zt({address:a?.address}),{allowCustomTokens:s,darkMode:c}=$(),{currentCurrency:u}=Xt(),d=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{t:f}=(0,l.useTranslation)(),{isolatedView:p}=Fr(),[m,h]=(0,r.useState)(``),_=t=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:t,onBack:()=>e(`assets`)}})},v=o.filter(({symbol:e})=>e.toLowerCase().includes(m.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:f(`Assets`)}),!p&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{h:[`540px`,`auto`],p:0,children:[(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:`Search token`,bg:c?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12,value:m,onChange:e=>h(e.target.value),"data-testid":`search-token-input`}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:d})})]}),(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,mt:2,children:v.map(e=>{let n=Number(e.balance)>0,r=t.Z.includes(e.symbol);return(0,i.jsx)(Oc,{symbol:e.symbol,amount:Number(e.balance),currencyValue:e.valueInCurrency,currentCurrency:u,onClick:()=>_(e),isDisabled:!n||r},e.address)})})]}),(0,i.jsx)(n.ModalFooter,{children:s&&(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPencil,boxSize:4}),onClick:()=>e(`add-custom-token`),children:f(`Manage Custom Tokens`)})})]})]})},hi=({setCurrentContent:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),o=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),s=(0,n.useToken)(`colors`,`vechain-kit-card`),c=(0,n.useToken)(`colors`,`vechain-kit-overlay`),{addToken:u,removeToken:d,isTokenIncluded:f,isDefaultToken:p,customTokens:m}=sn(),{register:h,setError:_,setValue:v,formState:{errors:y,isValid:b},handleSubmit:x}=(0,D.useForm)({defaultValues:{newTokenAddress:``},mode:`onChange`}),S=async e=>{if(e.newTokenAddress){if(f(e.newTokenAddress)||p(e.newTokenAddress))return _(`newTokenAddress`,{type:`manual`,message:r(`Token already added`)});try{await u(e.newTokenAddress),v(`newTokenAddress`,``)}catch(e){console.error(`Error adding token 2:`,e),_(`newTokenAddress`,{type:`manual`,message:r(`Invalid token address`)})}}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Manage Custom Tokens`)}),(0,i.jsx)(J,{onClick:()=>e(`assets`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,position:`relative`,children:[(0,i.jsx)(n.Box,{p:6,borderRadius:`xl`,bg:s,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!y.newTokenAddress,children:[(0,i.jsx)(n.FormLabel,{fontSize:`sm`,fontWeight:`medium`,color:a,children:r(`Token Contract Address`)}),(0,i.jsx)(n.Input,{...h(`newTokenAddress`,{required:r(`Address is required`),pattern:{value:/^0x[a-fA-F0-9]{40}$/,message:r(`Please enter a valid contract address`)},validate:e=>/^0x[a-fA-F0-9]{40}$/.test(e)||r(`Invalid contract address`)}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,v(`newTokenAddress`,t,{shouldValidate:!0})},placeholder:`0x...`,variant:`outline`,fontSize:`md`,fontWeight:`medium`}),y.newTokenAddress&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,children:y.newTokenAddress.message})]})})}),m.length>0&&(0,i.jsxs)(n.Box,{p:4,borderRadius:`xl`,bg:c,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,mb:2,children:r(`Existing Custom Tokens`)}),(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:m.map(e=>(0,i.jsxs)(n.HStack,{justify:`space-between`,fontSize:`sm`,p:2,borderRadius:`md`,bg:s,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:t.$[e?.symbol],alt:`${e.symbol} logo`,boxSize:`20px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`20px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`8px`,fontWeight:`bold`,color:a,children:e.symbol?.slice(0,3)})})}),(0,i.jsx)(n.Text,{fontWeight:`medium`,color:a,children:e.symbol??`Unknown`})]}),(0,i.jsx)(n.Text,{color:o,children:t.W(e.address??``,4,4)}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,color:a,borderRadius:`md`,p:2,onClick:()=>d(e.address),children:(0,i.jsx)(g.LuTrash2,{size:16,color:a})})]},e.address))})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!b,onClick:x(S),children:r(`Add Token`)})})]})},gi=({setCurrentContent:t})=>{let{t:r}=(0,l.useTranslation)(),{darkMode:a}=$(),{isolatedView:o}=Fr();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Bridge`)}),!o&&(0,i.jsx)(J,{onClick:()=>t(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.Container,{maxW:`container.lg`,children:(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,w:`full`,children:[(0,i.jsx)(e.r,{isDark:a,borderRadius:`xl`}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:r(`Exchange your digital assets between VeChain and other blockchain networks easily and securely. Swaps are executed through partners that leverage both decentralized and centralized exchanges to convert tokens.`)})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,onClick:()=>{window.open(e.x,`_blank`)},children:[r(`Launch vechain.energy`),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},_i=({setCurrentContent:e})=>{let{t:a}=(0,l.useTranslation)(),{currentCurrency:o,changeCurrency:s,allCurrencies:c}=Xt(),u=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`);(0,r.useEffect)(()=>{t.yt(`settings-currency-visited`,`true`)},[]);let d=e=>{let r=o===e;return(0,i.jsxs)(n.Button,{w:`full`,variant:`ghost`,justifyContent:`space-between`,onClick:()=>s(e),py:6,px:4,bg:r?u:void 0,children:[(0,i.jsxs)(n.HStack,{spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`xl`,children:t.C[e]}),(0,i.jsx)(n.Text,{children:e.toUpperCase()})]}),r&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select currency`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{justify:`center`,spacing:3,align:`flex-start`,w:`full`,children:c.map(e=>d(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},vi=({setCurrentContent:e})=>{let{t,i18n:r}=(0,l.useTranslation)(),a=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`),o=e=>{r.changeLanguage(e)},s=e=>{let t=r.language===e;return(0,i.jsxs)(n.Button,{w:`full`,variant:`ghost`,justifyContent:`space-between`,onClick:()=>o(e),py:6,px:4,bg:t?a:void 0,children:[(0,i.jsx)(n.Text,{children:ae[e]}),t&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Select language`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{justify:`center`,spacing:3,align:`flex-start`,w:`full`,children:ie.map(e=>s(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},yi=({token:e,index:r,isExcluded:a,onToggleExclusion:o,onDragStart:s,onDragOver:c,onDrop:l,onTouchStart:u,onTouchMove:d,onTouchEnd:f,isDragging:p,isDraggedOver:m})=>{let h=t.Q[e],{darkMode:_}=$(),v=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),y=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),b=(0,n.useToken)(`colors`,`vechain-kit-card`);return(0,i.jsx)(n.Box,{bg:_?`#ffffff0a`:`blackAlpha.50`,borderRadius:`md`,border:`1px`,borderColor:p?_?`blue.500`:`blue.300`:m?_?`blue.400`:`blue.200`:b,p:3,mb:2,opacity:p||a?.5:1,cursor:`move`,transition:`background-color 0.2s ease, border-color 0.2s ease`,draggable:!0,onDragStart:()=>s(r),onDragOver:e=>{e.preventDefault(),c(r)},onDrop:()=>l(r),onTouchStart:e=>u(r,e),onTouchMove:d,onTouchEnd:f,_hover:{backgroundColor:_?`#ffffff12`:`blackAlpha.200`},children:(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{opacity:a?.5:1,children:[(0,i.jsx)(n.Box,{cursor:`grab`,_active:{cursor:`grabbing`},pointerEvents:`none`,children:(0,i.jsx)(n.Icon,{as:g.LuGripVertical,color:y})}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:v,children:h.name}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:y,children:h.description})]})]}),(0,i.jsx)(n.Switch,{isChecked:!a,onChange:()=>o(e),colorScheme:`blue`,size:`sm`})]})})},bi=({tokens:e,excludedTokens:t,onReorder:a,onToggleExclusion:o})=>{let[s,c]=(0,r.useState)(null),[l,u]=(0,r.useState)(null),d=(0,r.useRef)([]),f=(0,r.useRef)(0),p=e=>{c(e)},m=e=>{u(e)},h=t=>{if(s===null||s===t){c(null),u(null);return}let n=[...e],r=n[s];n.splice(s,1),n.splice(t,0,r),a(n),c(null),u(null)},g=(e,t)=>{f.current=t.touches[0].clientY,c(e)},_=e=>{if(s===null)return;let t=e.touches[0].clientY;for(let e=0;e<d.current.length;e++){let n=d.current[e];if(!n)continue;let r=n.getBoundingClientRect();if(t>=r.top&&t<=r.bottom){u(e);break}}},v=()=>{if(s!==null&&l!==null&&s!==l){let t=[...e],n=t[s];t.splice(s,1),t.splice(l,0,n),a(t)}c(null),u(null),f.current=0};return(0,i.jsx)(n.Box,{w:`full`,children:e.map((e,r)=>(0,i.jsx)(n.Box,{ref:e=>{d.current[r]=e},children:(0,i.jsx)(yi,{token:e,index:r,isExcluded:t.includes(e),onToggleExclusion:o,onDragStart:p,onDragOver:m,onDrop:h,onTouchStart:g,onTouchMove:_,onTouchEnd:v,isDragging:s===r,isDraggedOver:l===r})},e))})},xi=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{preferences:a,reorderTokenPriority:o,toggleTokenExclusion:s}=Tc(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),u=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),d=(0,r.useCallback)(e=>{o(e)},[o]);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Gas Token Preferences`)}),(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{justify:`center`,spacing:6,align:`flex-start`,w:`full`,children:[(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,spacing:3,mb:3,children:(0,i.jsx)(n.Text,{fontSize:`sm`,color:u,textAlign:`center`,children:t(`Choose which tokens to use for transaction fees when the app is not covering them.`)})}),a.availableGasTokens.length===0&&(0,i.jsxs)(n.Alert,{status:`warning`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsx)(n.AlertDescription,{fontSize:`sm`,color:u,children:t(`You must enable at least one token to perform transactions. Without any enabled tokens, you will not be able to pay for gas fees.`)})]}),(0,i.jsxs)(n.VStack,{w:`full`,align:`start`,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`semibold`,color:c,children:t(`Token Priority Order`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:u,children:t(`Drag to reorder. The system will automatically use the highest priority token with sufficient balance.`)}),(0,i.jsx)(bi,{tokens:a.tokenPriority,excludedTokens:a.excludedTokens,onReorder:d,onToggleExclusion:s})]})]})})]})},Si=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=Fr(),{exportWallet:o,linkPasskey:s}=(0,u.usePrivy)(),{showMfaEnrollmentModal:c}=(0,u.useMfaEnrollment)(),{feeDelegation:d}=$(),{connection:f,disconnect:p,smartAccount:m,connectedWallet:h}=X(),{data:_}=Is(m?.address??``,h?.address??``,3),v=()=>{e({type:`upgrade-smart-account`,props:{setCurrentContent:e,initialContent:`settings`}})},y=()=>{e(`connection-details`)},b=()=>{p(),t()},x=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Settings`)}),!a&&(0,i.jsx)(J,{onClick:()=>e(`profile`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`General`)}),(0,i.jsx)(Z,{title:r(`Currency`),onClick:()=>{e(`change-currency`)},leftIcon:g.LuDollarSign,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Language`),onClick:()=>{e(`change-language`)},leftIcon:g.LuLanguages,rightIcon:g.LuChevronRight}),f.isConnectedWithPrivy&&!d?.delegatorUrl&&(0,i.jsx)(Z,{title:r(`Gas Token Preferences`),onClick:()=>{e(`gas-token-settings`)},leftIcon:g.LuFuel,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Terms and Policies`),onClick:()=>{e({type:`terms-and-privacy`,props:{onGoBack:()=>e(`settings`)}})},leftIcon:g.LuShield,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Logout`),onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:b,onBack:()=>e(`settings`)}}),leftIcon:g.LuLogOut})]}),_&&(0,i.jsx)(n.VStack,{w:`full`,spacing:2,mt:4,children:(0,i.jsx)(Z,{title:r(`Upgrade Smart Account to V3`),description:r(`A new version is available for your account`),onClick:v,leftIcon:g.LuSettings2,extraContent:(0,i.jsx)(n.Box,{minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`,display:`flex`,alignItems:`center`,justifyContent:`center`,ml:2})})}),f.isConnectedWithSocialLogin&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,mt:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`Access and security`)}),(0,i.jsx)(Z,{title:r(`Passkey`),onClick:()=>s(),leftIcon:g.LuFingerprint}),(0,i.jsx)(Z,{title:r(`Backup`),onClick:()=>{o()},leftIcon:g.LuKey}),(0,i.jsx)(Z,{title:r(`Manage MFA`),onClick:()=>{c()},leftIcon:g.LuShieldCheck}),(0,i.jsx)(Z,{title:r(`Login methods`),onClick:()=>{e(`privy-linked-accounts`)},leftIcon:g.LuUserCog,rightIcon:g.LuChevronRight})]}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,mt:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:x,textAlign:`left`,w:`full`,children:r(`Help`)}),(0,i.jsx)(Z,{title:r(`Connection details`),onClick:y,leftIcon:g.LuUnlink,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Explore ecosystem`),onClick:()=>e(`ecosystem`),leftIcon:g.LuLayoutGrid,rightIcon:g.LuChevronRight}),(0,i.jsx)(Z,{title:r(`Frequently asked questions`),onClick:()=>e({type:`faq`,props:{onGoBack:()=>e(`settings`),showLanguageSelector:!1}}),leftIcon:g.LuCircleHelp,rightIcon:g.LuChevronRight})]})]}),(0,i.jsx)(n.ModalFooter,{p:0})]})},Ci=({title:e,description:t,icon:r})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`);return(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,py:8,children:[(0,i.jsx)(n.Icon,{as:r,boxSize:16,color:a}),(0,i.jsxs)(n.VStack,{spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`500`,textAlign:`center`,color:o,children:e}),(0,i.jsx)(n.Text,{fontSize:`md`,color:a,textAlign:`center`,px:4,children:t})]})]})},wi=(e,t=`en-US`)=>new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}).format(new Date(e)),Ti=({document:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=e.documentSource===t.v.VECHAIN_KIT&&e.documentType===t.y.TERMS;return(0,i.jsxs)(n.HStack,{children:[(0,i.jsxs)(n.Tag,{size:`sm`,borderRadius:`full`,color:a,children:[`v`,e.version]}),(0,i.jsx)(n.Text,{fontSize:`xs`,cursor:`pointer`,color:a,onClick:()=>{window.open(e.url,`_blank`)},_hover:{textDecoration:`underline`},children:o?r(`'{{policyName}}' on connect`,{policyName:e.displayName??r(`Vechain Kit Policy`)}):r(`'{{policyName}}' on {{date}}`,{policyName:e.displayName??r(`Policy`),date:wi(e.timestamp)})})]})},Ei=({title:e,description:t,documents:r,bg:a,hoverBg:o,currentPolicy:s})=>{let{t:c}=(0,l.useTranslation)(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),f=r?.length>0,p=r?.find(e=>e.id===s?.id);return f?(0,i.jsx)(n.AccordionItem,{border:`none`,mb:3,children:({isExpanded:l})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.AccordionButton,{bg:a,borderRadius:`xl`,_hover:{bg:o},children:[(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,textAlign:`left`,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,color:u,children:e}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d,children:t})]}),(0,i.jsx)(n.Icon,{as:l?g.LuChevronUp:g.LuChevronDown,fontSize:`20px`,color:d})]}),(0,i.jsx)(n.AccordionPanel,{pb:4,pt:3,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:4,children:[p?.id?(0,i.jsxs)(n.HStack,{w:`full`,children:[(0,i.jsx)(n.Icon,{as:g.LuCheck,color:u}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:d,children:c(`You accepted current policy on {{date}}`,{date:wi(p.timestamp)})})]}):null,(0,i.jsx)(n.HStack,{w:`full`,textAlign:`left`,children:(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`bold`,color:d,children:c(`All policies you have accepted`)})}),(0,i.jsx)(n.HStack,{w:`full`,gap:2,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:r.map(e=>(0,i.jsx)(Ti,{document:e},e.id))})}),s&&(0,i.jsx)(n.Button,{variant:`outline`,size:`xs`,alignSelf:`flex-end`,onClick:()=>{window.open(s.url,`_blank`)},children:c(`View Current Policy`)})]})})]})}):null},Di=()=>{let{account:e}=X(),{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),{agreements:s,documents:c}=$c(),u=(0,r.useMemo)(()=>{let n=s?.filter(n=>t.k(n.walletAddress,e?.address));return[{id:`vechain-kit-terms`,...t.it,documentType:t.y.TERMS,documentSource:t.v.VECHAIN_KIT,walletAddress:e?.address??``,timestamp:new Date().getTime()},...n]?.reduce((e,t)=>(e[t.documentType]=[...e[t.documentType]||[],t],e),{})},[s,e?.address]),d=(0,r.useMemo)(()=>c.reduce((e,t)=>{let n=t.documentType;return(!e[n]||t.version>e[n].version)&&(e[n]=t),e},{}),[c]),f=(0,r.useMemo)(()=>Object.values(u).some(e=>e.length>0),[u]),p=o?`whiteAlpha.50`:`blackAlpha.50`,m=o?`whiteAlpha.100`:`blackAlpha.100`,h=(0,r.useMemo)(()=>{let e=[];return u[t.y.TERMS]?.length>0&&e.push(0),u[t.y.PRIVACY]?.length>0&&e.push(1),u[t.y.COOKIES]?.length>0&&e.push(2),e},[u]);return f?(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,children:(0,i.jsxs)(n.Accordion,{allowMultiple:!0,defaultIndex:h,children:[(0,i.jsx)(Ei,{title:a(`Terms and Conditions`),description:a(`Legal agreement between you, Vechain Kit and the current app, outlining the rules for using wallet services.`),documents:u[t.y.TERMS],bg:p,hoverBg:m,currentPolicy:d[t.y.TERMS]}),(0,i.jsx)(Ei,{title:a(`Privacy Policy`),description:a(`Privacy policy outlining the data collection and processing practices.`),documents:u[t.y.PRIVACY],bg:p,hoverBg:m,currentPolicy:d[t.y.PRIVACY]}),(0,i.jsx)(Ei,{title:a(`Cookie Policy`),description:a(`Cookie policy outlining the use of cookies and tracking technologies.`),documents:u[t.y.COOKIES],bg:p,hoverBg:m,currentPolicy:d[t.y.COOKIES]})]})}):(0,i.jsx)(Ci,{title:a(`No policies accepted`),description:a(`When you have accepted a policy, it will appear here`),icon:g.LuGavel})},Oi=({onGoBack:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Terms and Policies`)}),(0,i.jsx)(J,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,children:(0,i.jsx)(Di,{})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},ki=({onDisconnect:e,onBack:t,onClose:r,showCloseButton:a=!0,text:o})=>{let{t:s}=(0,l.useTranslation)(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),u=o??s(`Are you sure you want to disconnect your wallet?`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Logout`)}),(0,i.jsx)(J,{onClick:t}),a?(0,i.jsx)(n.ModalCloseButton,{onClick:r}):null]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuLogOut,color:`#ef4444`,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:c,children:u})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,mt:4,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{onClick:e,"data-testid":`disconnect-button`,variant:`vechainKitLogout`,children:s(`Confirm`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:t,"data-testid":`cancel-logout-button`,children:s(`Cancel`)})]})})]})},Ai=({wallet:e,isActive:r,onSelect:a,onRemove:o,showRemove:s=!0})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),{formattedBalance:d,isLoading:f}=Qt({address:e.address}),{domain:p,image:m,isLoading:h}=Mn(e.address,u.type),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useToken)(`colors`,`vechain-kit-border`),b=f||h;return(0,i.jsx)(n.Card,{variant:`vechainKitWalletCard`,onClick:a,borderWidth:r?`2px`:`1px`,borderColor:r?`vechain-kit-primary`:y,_hover:{borderColor:r?`vechain-kit-primary`:`vechain-kit-text-secondary`},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsxs)(n.HStack,{spacing:3,w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,minW:0,children:[(0,i.jsx)(Mc,{wallet:{address:e.address,domain:p??void 0,image:m??void 0,isLoadingMetadata:h},props:{width:10,height:10}}),(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,flex:1,minW:0,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:_,noOfLines:1,children:p?t.G(p,22,0):t.W(e.address,6,4)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:v,noOfLines:1,children:b?c(`Loading...`):d})]})]}),r&&(0,i.jsx)(n.Box,{children:(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`vechain-kit-primary`})}),s&&!r&&(0,i.jsx)(n.IconButton,{"aria-label":c(`Remove wallet`),icon:(0,i.jsx)(n.Icon,{as:g.LuTrash2}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,onClick:e=>{e.stopPropagation(),o()}})]})})})},ji=e=>t.o(e.map(e=>e.address.toLowerCase()).sort().join(`|`)),Mi=({setCurrentContent:e,returnTo:t=`main`,onLogoutSuccess:a})=>{let{t:o}=(0,l.useTranslation)(),{isolatedView:s}=Fr(),{account:c,disconnect:u}=X(),{disconnect:d}=(0,f.useWallet)(),{open:p}=(0,f.useWalletModal)(),{getStoredWallets:m,setActiveWallet:h,removeWallet:_}=Fn(),{saveWallet:v}=Nn(),{refresh:y}=Pn(),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[x,S]=(0,r.useState)(m()),C=(0,r.useRef)(ji(m())),w=(0,r.useCallback)(()=>{let e=m();S(e),C.current=ji(e)},[m]);(0,r.useEffect)(()=>{w()},[w,c?.address]),(0,r.useEffect)(()=>{let e=()=>{setTimeout(()=>{w()},100)};if(typeof window<`u`)return window.addEventListener(`wallet_switched`,e),()=>{window.removeEventListener(`wallet_switched`,e)}},[w]),(0,r.useEffect)(()=>{let e=setInterval(()=>{ji(m())!==C.current&&w()},200);return()=>clearInterval(e)},[m,w]);let T=(0,r.useMemo)(()=>{let e=x.find(e=>e.isActive);return e?e.address:c?.address??null},[x,c?.address]),E=(0,r.useMemo)(()=>x.find(e=>e.address.toLowerCase()===T?.toLowerCase()),[x,T]),D=(0,r.useMemo)(()=>x.filter(e=>e.address.toLowerCase()!==T?.toLowerCase()),[x,T]),O=(0,r.useCallback)(n=>{n.toLowerCase()!==T?.toLowerCase()&&(E&&v(E.address),h(n),setTimeout(()=>{w()},50),y(),e({type:t,props:{switchFeedback:{showFeedback:!0}}}))},[T,E,c,h,y,e,w,v]),k=(0,r.useCallback)(n=>{let r=n.address.toLowerCase()===T?.toLowerCase(),i=x.filter(e=>e.address.toLowerCase()!==n.address.toLowerCase());e({type:`remove-wallet-confirm`,props:{walletAddress:n.address,walletDomain:null,onConfirm:async()=>{if(r&&i.length>0){let e=i[0];h(e.address)}else if(r&&i.length===0)try{await d()}catch(e){console.error(`Error disconnecting:`,e)}if(_(n.address),setTimeout(()=>{w()},50),i.length===0){a&&a();return}e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})},onBack:()=>{e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})}}})},[_,w,e,t,a,T,x,h,d]),A=(0,r.useCallback)(()=>{p()},[p]),j=()=>{u(),a?.()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[!s&&(0,i.jsx)(J,{onClick:()=>{e(t)}}),(0,i.jsx)(n.ModalHeader,{children:o(`Select Wallet`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[E&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,alignItems:`flex-start`,children:[(0,i.jsx)(n.Heading,{size:`sm`,color:b,children:o(`Active Wallet`)}),(0,i.jsx)(Ai,{wallet:E,isActive:!0,onSelect:()=>{},onRemove:()=>k(E),showRemove:x.length>1})]}),D.length>0&&(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,alignItems:`flex-start`,children:[(0,i.jsx)(n.Heading,{size:`sm`,color:b,children:o(`Other Wallets`)}),D.map(e=>(0,i.jsx)(Ai,{wallet:e,isActive:!1,onSelect:()=>O(e.address),onRemove:()=>k(e),showRemove:!0},e.address))]})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[(0,i.jsx)(n.Button,{w:`full`,leftIcon:(0,i.jsx)(g.LuPlus,{}),variant:`vechainKitSecondary`,onClick:A,children:o(`Add New Wallet`)}),(0,i.jsx)(n.Button,{w:`full`,leftIcon:(0,i.jsx)(g.LuLogOut,{}),variant:`vechainKitLogout`,onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:j,onBack:()=>e({type:`select-wallet`,props:{setCurrentContent:e,onClose:()=>{},returnTo:t,onLogoutSuccess:a}})}}),children:o(`Logout`)})]})})]})},Ni=({walletAddress:e,walletDomain:r,onConfirm:a,onBack:o,onClose:s})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),{domain:d}=Mn(e,u.type),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=d?t.G(d,20,0):t.W(e,6,4);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:c(`Remove`)}),(0,i.jsx)(J,{onClick:o}),s&&(0,i.jsx)(n.ModalCloseButton,{onClick:s})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,mt:10,children:[(0,i.jsx)(n.Icon,{as:g.LuTrash2,color:`#ef4444`,fontSize:`60px`,opacity:.5}),(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:f,children:c(`Are you sure you want to remove this wallet?`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:`vechain-kit-text-secondary`,fontWeight:`600`,children:p}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:`vechain-kit-text-secondary`,children:t.W(e,8,7)})]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,mt:4,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{onClick:a,"data-testid":`remove-wallet-button`,variant:`vechainKitLogout`,children:c(`Remove`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:o,"data-testid":`cancel-remove-button`,children:c(`Cancel`)})]})})]})},Pi=Ae[`@vechain/dapp-kit-react`]||je[`@vechain/dapp-kit-react`]||`unknown`,Fi=Ae[`@privy-io/react-auth`]||`unknown`,Ii=({connectionCache:e})=>{let{t:r}=(0,l.useTranslation)(),{connection:a,smartAccount:o,connectedWallet:s}=X(),{source:c}=(0,f.useWallet)(),{privy:u,network:d}=$(),p=u?.appId,{data:m,isLoading:h}=Ve(p||[]),{onCopy:_,hasCopied:v}=(0,n.useClipboard)(``),{data:y,isLoading:b}=Ue(),{data:x,isLoading:S}=bs(o.address??``,s?.address??``),C=(0,n.useToken)(`colors`,`vechain-kit-card`),w=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),T=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),E=(()=>a.isConnectedWithCrossApp&&e?.ecosystemApp?e.ecosystemApp.name:a.isConnectedWithSocialLogin&&m?Object.values(m)[0]?.name??null:a.isConnectedWithDappKit&&c?c:null)(),D=a.isConnectedWithSocialLogin&&h,O=({label:e,value:t,isLoading:r=!1,href:a})=>(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:T,children:[e,`:`]}),(0,i.jsx)(n.Text,{fontSize:`sm`,as:a?`a`:void 0,href:a,target:`_blank`,rel:`noopener noreferrer`,style:{textDecoration:a?`underline`:`none`},color:w,children:r?`Loading...`:t})]});return D?(0,i.jsx)(n.VStack,{w:`full`,h:`full`,justify:`center`,align:`center`,minH:`200px`,borderRadius:`xl`,bg:C,children:(0,i.jsx)(n.Spinner,{})}):E?(0,i.jsxs)(n.VStack,{p:4,bg:C,borderRadius:`xl`,spacing:4,w:`full`,justifyContent:`space-between`,children:[(0,i.jsx)(O,{label:r(`Logged in with`),value:E}),a.isConnectedWithCrossApp&&e?.timestamp&&(0,i.jsx)(O,{label:r(`At`),value:new Date(e.timestamp).toLocaleString()}),(0,i.jsx)(O,{label:r(`Connection Type`),value:a.source.type,isLoading:a.isLoading}),(0,i.jsx)(n.Divider,{}),(0,i.jsx)(O,{label:r(`Network`),value:d.type}),(0,i.jsx)(O,{label:r(`Node URL`),value:d.nodeUrl||t.bt(d.type).nodeUrl}),a.isConnectedWithPrivy&&(0,i.jsx)(n.Divider,{}),a.isConnectedWithPrivy&&(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`space-between`,children:[(0,i.jsxs)(n.Text,{fontSize:`sm`,color:T,children:[r(`Embedded wallet`),`:`]}),(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:w,children:s?.address?t.W(s.address,8,7):`-`}),(0,i.jsx)(n.Icon,{color:w,onClick:()=>{s?.address&&_(s.address)},opacity:s?.address?1:.4,pointerEvents:s?.address?`auto`:`none`,cursor:`pointer`,as:v?g.LuCheck:g.LuCopy})]})]}),a.isConnectedWithPrivy?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(O,{label:r(`Smart Account`),value:`v${x?.version??``} ${x?.isDeployed?``:`(not deployed)`}`,isLoading:S}),(0,i.jsx)(O,{label:r(`Privy Status`),value:y||``,isLoading:b})]}):o.isDeployed&&(0,i.jsx)(O,{label:r(`Smart Account`),value:`v${x?.version??``}`,isLoading:S}),(0,i.jsx)(n.Divider,{}),(0,i.jsx)(O,{label:r(`VeChain Kit`),value:ke,href:`https://github.com/vechain/vechain-kit/releases/tag/${ke}`}),(0,i.jsx)(O,{label:`DAppKit`,value:Pi}),(0,i.jsx)(O,{label:`Privy`,value:Fi})]}):null},Li=()=>{let{connection:t}=X(),{t:r}=(0,l.useTranslation)(),{privy:a,darkMode:o}=$(),{getConnectionCache:s}=Vo(),c=s(),u=(0,n.useToken)(`colors`,`vechain-kit-card`);return t.isConnectedWithPrivy?(0,i.jsxs)(n.VStack,{w:`full`,align:`stretch`,textAlign:`center`,mt:5,p:3,borderRadius:`lg`,bg:u,shadow:`sm`,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`800`,children:r(`Wallet secured by`)}),(0,i.jsxs)(n.HStack,{justify:`center`,children:[(0,i.jsx)(e.i,{isDark:o,w:`50px`}),(0,i.jsx)(n.Icon,{as:g.LuMinus,ml:3}),t.isConnectedWithVeChain?(0,i.jsx)(e.J,{isDark:o,w:`80px`,h:`auto`,mb:`3px`}):t.isConnectedWithCrossApp&&c&&(0,i.jsx)(n.Image,{src:c.ecosystemApp.logoUrl,alt:c.ecosystemApp.name,maxW:`40px`,borderRadius:`md`}),t.isConnectedWithSocialLogin&&!t.isConnectedWithVeChain&&(0,i.jsx)(n.Image,{src:a?.appearance.logo,alt:a?.appearance.logo,maxW:`40px`,borderRadius:`md`})]})]}):null},Ri=({onGoBack:e})=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Vo(),a=r()??void 0;return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Connection Details`)}),(0,i.jsx)(J,{onClick:()=>{e()}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsx)(Ii,{connectionCache:a}),(0,i.jsx)(Li,{})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},zi=({accountType:e,accountDescription:t,isLoading:r,onConfirm:a,onCancel:o})=>{let{t:s}=(0,l.useTranslation)();return(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:(0,n.useToken)(`colors`,`vechain-kit-text-primary`),children:s(`Are you sure you want to unlink {{accountType}} as a login method linked to {{accountDescription}}?`,{accountType:e,accountDescription:t})}),(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{height:`60px`,colorScheme:`red`,w:`full`,onClick:a,isLoading:r,children:s(`Remove Login Method`)}),(0,i.jsx)(n.Button,{isLoading:r,height:`60px`,w:`full`,onClick:o,children:s(`Cancel`)})]})]})},Bi=({onBack:e})=>{let{t:a}=(0,l.useTranslation)(),{privy:o,dappKit:s}=$(),[c,d]=(0,r.useState)(null),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{user:x,linkEmail:S,linkGoogle:C,linkTwitter:w,linkPhone:T,linkSpotify:D,linkApple:O,linkInstagram:k,linkTiktok:A,linkGithub:P,linkLinkedIn:F,linkTelegram:I,linkFarcaster:L,linkPasskey:R,linkDiscord:z,unlinkEmail:B,unlinkGoogle:ee,unlinkApple:te,unlinkSpotify:V,unlinkInstagram:ne,unlinkTiktok:re,unlinkGithub:ie,unlinkLinkedIn:H,unlinkTelegram:ae,unlinkFarcaster:U,unlinkPhone:oe,unlinkPasskey:W,unlinkDiscord:se,linkWallet:ce}=(0,u.usePrivy)(),G=(0,r.useMemo)(()=>{let e=o?.loginMethods?.filter(e=>[`rabby_wallet`,`coinbase_wallet`,`rainbow`,`phantom`,`metamask`].includes(e))??[],t=s?.allowedWallets??[];return e.length>0||t.length>0},[o?.loginMethods,s?.allowedWallets]),le=e=>{switch(e){case`google_oauth`:return E.FcGoogle;case`email`:return g.LuMail;case`passkey`:return g.LuFingerprint;case`wallet`:return g.LuWallet;case`twitter_oauth`:return j.FaXTwitter;case`phone`:return g.LuPhone;case`spotify_oauth`:return N.FaSpotify;case`apple_oauth`:return N.FaApple;case`instagram_oauth`:return N.FaInstagram;case`tiktok_oauth`:return N.FaTiktok;case`github_oauth`:return g.LuGithub;case`linkedin_oauth`:return N.FaLinkedin;case`telegram`:return N.FaTelegram;case`farcaster`:return M.SiFarcaster;case`discord_oauth`:return N.FaDiscord;default:return}},ue=()=>{let e=x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`);return e&&e?.length>1},de=async e=>{if(ue()){v(!0);try{switch(e.type){case`google_oauth`:await ee(e.subject);break;case`email`:await B(e.address);break;case`passkey`:await W(e.subject);break;case`phone`:await oe(e.number);break;case`spotify_oauth`:await V(e.subject);break;case`apple_oauth`:await te(e.subject);break;case`instagram_oauth`:await ne(e.subject);break;case`tiktok_oauth`:await re(e.subject);break;case`github_oauth`:await ie(e.subject);break;case`linkedin_oauth`:await H(e.subject);break;case`telegram`:await ae(e.subject);break;case`farcaster`:await U(e.subject);break;case`discord_oauth`:await se(e.subject);break;default:break}}catch(e){console.error(e)}finally{v(!1),d(null)}}},K=e=>{switch(e.type){case`google_oauth`:return e.email;case`email`:return e.address;case`passkey`:return`${e.authenticatorName} - ${e.createdWithBrowser}`;case`phone`:return e.number;case`wallet`:return`${t.W(e.address)} - ${e.walletClientType}`;default:return``}},q=x?.linkedAccounts?.map(e=>e.type)||[],fe=o?.loginMethods||[],pe=!q.includes(`google_oauth`)&&fe.includes(`google`),me=!q.includes(`email`)&&fe.includes(`email`),he=!q.includes(`twitter_oauth`)&&fe.includes(`twitter`),ge=!q.includes(`phone`)&&fe.includes(`sms`),_e=!q.includes(`spotify_oauth`)&&fe.includes(`spotify`),ve=!q.includes(`apple_oauth`)&&fe.includes(`apple`),ye=!q.includes(`instagram_oauth`)&&fe.includes(`instagram`),be=!q.includes(`tiktok_oauth`)&&fe.includes(`tiktok`),xe=!q.includes(`github_oauth`)&&fe.includes(`github`),Se=!q.includes(`linkedin_oauth`)&&fe.includes(`linkedin`),Ce=!q.includes(`telegram`)&&fe.includes(`telegram`),we=!q.includes(`farcaster`)&&fe.includes(`farcaster`),Te=!q.includes(`discord_oauth`)&&fe.includes(`discord`);return f?(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select Additional Login Method`)}),(0,i.jsx)(J,{onClick:()=>p(!1)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`stretch`,w:`full`,children:[(0,i.jsx)(Z,{title:a(`Set up Passkey`),description:a(`Set up a passkey for easier access`),onClick:()=>R(),leftIcon:g.LuFingerprint}),pe&&(0,i.jsx)(Z,{title:a(`Link Google Account`),description:a(`Connect your Google account for easier access`),onClick:()=>C(),leftIcon:E.FcGoogle}),me&&(0,i.jsx)(Z,{title:a(`Link Email Account`),description:a(`Connect your email for easier access`),onClick:()=>S(),leftIcon:g.LuMail,stacked:!0}),he&&(0,i.jsx)(Z,{title:a(`Link Twitter Account`),description:a(`Connect your Twitter account for easier access`),onClick:()=>w(),leftIcon:j.FaXTwitter}),ge&&(0,i.jsx)(Z,{title:a(`Link Phone Number`),description:a(`Connect your phone number for easier access`),onClick:()=>T(),leftIcon:g.LuPhone}),_e&&(0,i.jsx)(Z,{title:a(`Link Spotify Account`),description:a(`Connect your Spotify account for easier access`),onClick:()=>D(),leftIcon:N.FaSpotify}),ve&&(0,i.jsx)(Z,{title:a(`Link Apple Account`),description:a(`Connect your Apple account for easier access`),onClick:()=>O(),leftIcon:N.FaApple}),ye&&(0,i.jsx)(Z,{title:a(`Link Instagram Account`),description:a(`Connect your Instagram account for easier access`),onClick:()=>k(),leftIcon:N.FaInstagram}),be&&(0,i.jsx)(Z,{title:a(`Link Tiktok Account`),description:a(`Connect your Tiktok account for easier access`),onClick:()=>A(),leftIcon:N.FaTiktok}),xe&&(0,i.jsx)(Z,{title:a(`Link Github Account`),description:a(`Connect your Github account for easier access`),onClick:()=>P(),leftIcon:g.LuGithub}),Se&&(0,i.jsx)(Z,{title:a(`Link LinkedIn Account`),description:a(`Connect your LinkedIn account for easier access`),onClick:()=>F(),leftIcon:N.FaLinkedin}),Ce&&(0,i.jsx)(Z,{title:a(`Link Telegram Account`),description:a(`Connect your Telegram account for easier access`),onClick:()=>I(),leftIcon:N.FaTelegram}),we&&(0,i.jsx)(Z,{title:a(`Link Farcaster Account`),description:a(`Connect your Farcaster account for easier access`),onClick:()=>L(),leftIcon:M.SiFarcaster}),Te&&(0,i.jsx)(Z,{title:a(`Link Discord Account`),description:a(`Connect your Discord account for easier access`),onClick:()=>z(),leftIcon:N.FaDiscord}),G&&(0,i.jsx)(Z,{title:a(`Link External Wallet`),description:a(`Connect an external wallet for easier access`),onClick:()=>ce(),leftIcon:g.LuWallet}),!pe&&!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,opacity:.7,children:a(`No additional accounts available to link`)})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):c?(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Remove Login Method`)}),(0,i.jsx)(J,{onClick:()=>d(null)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(zi,{accountType:c.type,accountDescription:K(c),isLoading:_,onConfirm:()=>de(c),onCancel:()=>d(null)})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Login methods`)}),(0,i.jsx)(J,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,align:`center`,w:`full`,justify:`center`,children:[(0,i.jsxs)(n.VStack,{spacing:1,justify:`flex-start`,alignItems:`flex-start`,mb:5,textAlign:`left`,w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:a(`These accounts are linked to your embedded wallet and can be used to login to your wallet and access your private key.`)}),m&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:a(`Adding more linked accounts increases security against loss of access, but also introduces additional potential attack vectors. For enhanced security, we recommend enabling MFA.`)}),(0,i.jsx)(n.Button,{variant:`link`,mt:0,size:`sm`,onClick:()=>h(!m),color:y,children:a(m?`Show Less`:`Read More`)})]}),x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`).map(e=>(0,i.jsxs)(n.Flex,{p:4,borderWidth:`1px`,borderRadius:`md`,align:`center`,justify:`space-between`,w:`full`,children:[(0,i.jsxs)(n.Flex,{align:`center`,gap:3,children:[(0,i.jsx)(n.Icon,{as:le(e.type),color:y}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`500`,color:y,children:e.type===`google_oauth`?a(`Google`):e.type===`email`?a(`Email`):e.type===`passkey`?a(`Passkey`):e.type===`twitter_oauth`?a(`Twitter`):e.type===`phone`?a(`Phone Number`):e.type===`spotify_oauth`?a(`Spotify`):e.type===`apple_oauth`?a(`Apple`):e.type===`instagram_oauth`?a(`Instagram`):e.type===`tiktok_oauth`?a(`Tiktok`):e.type===`github_oauth`?a(`Github`):e.type===`linkedin_oauth`?a(`LinkedIn`):e.type===`telegram`?a(`Telegram`):e.type===`farcaster`?a(`Farcaster`):e.type===`discord_oauth`?a(`Discord`):a(`Wallet`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,children:K(e)})]})]}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,colorScheme:`red`,isDisabled:!ue(),onClick:()=>{e.type===`passkey`?R():d(e)},children:a(`Remove`)})]},e.type))]})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsx)(n.Button,{w:`full`,variant:`vechainKitPrimary`,onClick:()=>p(!0),leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPlus}),isDisabled:!pe&&!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te,children:a(`Add Login Method`)})})]})},Vi=[{id:`welcome`,title:`Welcome to the VeChain`,description:`Welcome! Here you can manage your wallet, send tokens, and interact with the VeChain blockchain and its applications.`,timestamp:Date.now(),status:`success`,isRead:!1}],Hi=()=>{let{t:e}=(0,l.useTranslation)(),{account:t,connection:n,smartAccount:i}=X(),{addNotification:a,getNotifications:o}=Ui(),{data:s}=zs(i?.address??``,3);(0,r.useEffect)(()=>{if(!n.isConnectedWithPrivy||!t?.address)return;let r=o(),i=`smart_account_upgrade_${t.address.toLowerCase()}`;!r.some(e=>e.id===i)&&s&&a({id:i,title:e(`Account Upgrade Required`),description:e(`A new upgrade is available for your smart account. Please head over to the 'Access and Security' section to upgrade it.`),status:`warning`})},[n.isConnectedWithPrivy,t?.address,s]),(0,r.useEffect)(()=>{!n.isConnectedWithPrivy||!t?.address||o().some(e=>e.id===`smart_account_${t.address.toLowerCase()}`)||a({id:`smart_account_${t.address.toLowerCase()}`,title:e(`Smart Account detected`),description:e(`You have an active smart account associated to this wallet. It has been set as your main identity.`),status:`info`})},[n.isConnectedWithPrivy,t?.address]),(0,r.useEffect)(()=>{if(!n.isConnectedWithPrivy||!t?.address)return;let r=o(),i=r.some(e=>e.id===`multiclause_warning_${t.address.toLowerCase()}`),s=r.some(e=>e.id===`multiclause_support_${t.address.toLowerCase()}`);i&&!s&&a({id:`multiclause_support_${t.address.toLowerCase()}`,title:e(`Multiclause Transactions Are Now Supported`),description:e(`Good news! Multiclause transactions are now fully supported for smart accounts. You can now enjoy a better user experience, lower gas costs, and enchanced security.`),status:`info`})},[n.isConnectedWithPrivy,t?.address])},Ui=()=>{let{account:e}=X(),n=(0,r.useCallback)(e=>{let t=e?.toLowerCase();return{notifications:`vechain_kit_notifications_${t}`,archived:`vechain_kit_archived_notifications_${t}`,initialized:`vechain_kit_notifications_initialized_${t}`}},[]),i=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return;let r=n(e.address);t.dt(r.initialized)||(t.yt(r.notifications,JSON.stringify(Vi)),t.yt(r.initialized,`true`))},[e?.address,n]);(0,r.useEffect)(()=>{i()},[i]);let a=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return[];let r=t.dt(n(e.address).notifications);return r?JSON.parse(r):[]},[e?.address,n]),o=(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return[];let r=t.dt(n(e.address).archived);return r?JSON.parse(r):[]},[e?.address,n]),s=(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),o=a(),s=t.dt(i.archived),c=s?JSON.parse(s):[];if([...o,...c].some(e=>e.title===r.title))return;let l={...r,id:r.id||Math.random().toString(36).substring(7),timestamp:Date.now(),isRead:!1};t.yt(i.notifications,JSON.stringify([l,...o]))},[e?.address,a,n]),c=(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),o=a().filter(e=>e.id!==r);t.yt(i.notifications,JSON.stringify(o))},[e?.address,a,n]);return{getNotifications:a,getArchivedNotifications:o,addNotification:s,clearAllNotifications:(0,r.useCallback)(()=>{if(!e?.address||!t.mt())return;let r=n(e.address),i=a();t.yt(r.archived,JSON.stringify([...o(),...i])),t.yt(r.notifications,JSON.stringify([]))},[e?.address,a,o,n]),markAsRead:(0,r.useCallback)(r=>{if(!e?.address||!t.mt())return;let i=n(e.address),s=a(),c=o(),l=s.find(e=>e.id===r),u=s.filter(e=>e.id!==r);if(l){let e=[{...l,isRead:!0},...c];t.yt(i.notifications,JSON.stringify(u)),t.yt(i.archived,JSON.stringify(e))}},[e?.address,a,o,n]),deleteNotification:c}},Wi=({showArchived:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsx)(Ci,{title:t(e?`No archived notifications`:`No notifications`),description:t(e?`Cleared notifications will appear here`:`When you have notifications, they will appear here`),icon:e?g.LuArchive:g.LuBell})},Gi=({notification:e,isArchiveView:t,onMarkAsRead:r})=>{let{t:a}=(0,l.useTranslation)(),o=()=>{r(e.id)};return e.isRead&&!t?null:(0,i.jsxs)(n.Alert,{status:e.status,variant:`subtle`,borderRadius:`lg`,pr:8,position:`relative`,opacity:e.isRead?.7:1,cursor:`pointer`,_hover:{opacity:.8},"data-testid":`notification-item`,children:[(0,i.jsx)(n.AlertIcon,{boxSize:`16px`}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,"data-testid":`notification-title`,children:a(e.title)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,lineHeight:`1.2`,"data-testid":`notification-text`,children:a(e.description)})]}),!t&&!e.isRead&&(0,i.jsx)(n.IconButton,{position:`absolute`,right:1,top:1,size:`sm`,variant:`ghost`,icon:(0,i.jsx)(g.LuCircleX,{}),onClick:e=>{e.stopPropagation(),o()},"aria-label":`Mark as read and archive`,"data-testid":`remove-notification-button`})]},e.id)},Ki=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isolatedView:a}=Fr(),{getNotifications:o,getArchivedNotifications:s,clearAllNotifications:c,markAsRead:u}=Ui(),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(o()),[h,_]=(0,r.useState)(s()),v=()=>{c(),_([...h,...p]),m([])},y=e=>{u(e);let t=p.find(t=>t.id===e);m(p.filter(t=>t.id!==e)),t&&_([{...t,isRead:!0},...h])},b=()=>{f(!d)},x=d?h:p,S=[...x].sort((e,t)=>e.id===`welcome`?-1:t.id===`welcome`?1:e.id===`smart-account`?-1:t.id===`smart-account`?1:e.id===`multiclause`?-1:t.id===`multiclause`?1:t.timestamp-e.timestamp);return(0,i.jsxs)(jc,{children:[(0,i.jsxs)(Y,{children:[!a&&(0,i.jsx)(J,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:t(d?`Archived Notifications`:`Notifications`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.Container,{h:[`540px`,`auto`],p:0,children:[(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,w:`full`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Button,{variant:`ghost`,leftIcon:(0,i.jsx)(n.Icon,{as:d?g.LuBell:g.LuArchive}),size:`sm`,onClick:b,"data-testid":`toggle-view-button`,children:t(d?`Current`:`Archived`)}),!d&&p.length>0&&(0,i.jsx)(n.Button,{variant:`ghost`,size:`sm`,onClick:v,"data-testid":`clear-all-button`,children:t(`Clear all`)})]}),x.length===0?(0,i.jsx)(Wi,{showArchived:d}):(0,i.jsx)(n.VStack,{spacing:3,children:S.map(e=>(0,i.jsx)(Gi,{notification:e,isArchiveView:d,onMarkAsRead:y},e.id))})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},qi=e=>{switch(e){case`defi`:return`blue`;case`games`:return`green`;case`collectibles`:return`purple`;case`marketplaces`:return`orange`;case`utilities`:return`cyan`;default:return`gray`}},Ji=({category:e,...t})=>{let{t:r}=(0,l.useTranslation)(),a=e.toLowerCase();return(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:qi(a),borderRadius:`full`,px:2,...t,children:r(a)})},Yi=({name:e,imageUrl:r,logoComponent:a,category:o,onClick:s,size:c=`md`})=>(0,i.jsxs)(n.Card,{variant:`vechainKitAppCard`,_hover:{opacity:.8},cursor:`pointer`,onClick:s,position:`relative`,children:[o&&(0,i.jsx)(n.Box,{position:`absolute`,top:`2`,right:`2`,zIndex:`1`,children:(0,i.jsx)(Ji,{category:o})}),(0,i.jsx)(n.CardBody,{p:c===`sm`?2:4,alignItems:`center`,children:(0,i.jsxs)(n.VStack,{spacing:2,h:`100%`,justifyContent:`space-between`,children:[a||r&&(0,i.jsx)(n.Image,{src:r,fallbackSrc:t.ct,alt:e,height:`90px`,objectFit:`contain`,rounded:`full`}),e&&(0,i.jsx)(n.Text,{fontWeight:`medium`,wordBreak:`break-word`,noOfLines:1,textAlign:`center`,w:`full`,children:e})]})})]}),Xi=({xApp:e,setCurrentContent:t,selectedCategory:r})=>{let{data:a,isLoading:o}=Rn(e.id),{data:s,isLoading:c}=Gn(a?.logo);return(0,i.jsx)(n.Skeleton,{isLoaded:!o&&!c,borderRadius:`md`,height:`100%`,children:(0,i.jsx)(Yi,{name:a?.name??``,imageUrl:s?.image??``,linkUrl:a?.external_url??``,category:`vebetter`,onClick:()=>{a?.name&&t({type:`app-overview`,props:{name:a.name,image:s?.image??``,url:a?.external_url??``,description:a?.description??``,category:`vebetter`,selectedCategory:r,setCurrentContent:t}})}})})},Zi=({name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c})=>(0,i.jsx)(Yi,{name:e,imageUrl:t,linkUrl:n,category:a,onClick:()=>{c({type:`app-overview`,props:{name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c}})},...o&&{logoComponent:o}}),Qi=({})=>{let{t:e}=(0,l.useTranslation)(),{shortcuts:r}=_c();return r.length===0?null:(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,spacing:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,children:e(`Shortcuts`)}),(0,i.jsx)(n.Grid,{templateColumns:`repeat(4, 1fr)`,gap:2,w:`full`,children:r.map(e=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(n.Card,{_hover:{opacity:.8},cursor:`pointer`,onClick:()=>window.open(e.url,`_blank`),children:(0,i.jsx)(n.CardBody,{p:2,alignItems:`center`,children:(0,i.jsx)(n.Image,{src:e.image,fallbackSrc:t.ct,alt:e.name,objectFit:`contain`,rounded:`full`})})})},e.url))})]})},$i=({selectedCategory:e,onCategoryChange:t,categories:r,darkMode:a})=>{let{t:o}=(0,l.useTranslation)();return(0,i.jsxs)(n.Box,{width:`full`,mb:4,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,mb:2,children:o(`Filter by category`)}),(0,i.jsxs)(n.Wrap,{spacing:2,children:[(0,i.jsx)(n.WrapItem,{children:(0,i.jsx)(n.Tag,{size:`md`,borderRadius:`full`,variant:e===null?`solid`:`outline`,colorScheme:a?`gray`:`blackAlpha`,cursor:`pointer`,onClick:()=>t(null),children:o(`All`)})}),r.map(r=>(0,i.jsx)(n.WrapItem,{children:(0,i.jsx)(Ji,{category:r,size:`md`,variant:e===r?`solid`:`outline`,cursor:`pointer`,onClick:()=>t(r)})},r))]})]})},ea=[{name:`VeBetterDAO`,description:`Engage, earn and prosper by doing sustainable actions.`,external_url:e.y,logo:new URL(`/static/img/coins/64x64/33509.png`,e.c).toString(),banner:new URL(`/static/img/icons/vbd.png`,e.c).toString(),screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:new URL(`/static/img/icons/vbd.png`,e.c).toString()},categories:[]},{name:`vet.domains`,description:`.vet.domains provides a unique and unchangeable identity for Vechain users by linking information to their wallet addresses. It becomes easier for people to use the blockchain by replacing complicated wallet addresses with easy-to-remember names.`,external_url:e.k,logo:new URL(`/assets/walletconnect.png`,e.k).toString(),banner:new URL(`/assets/walletconnect.png`,e.k).toString(),screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:new URL(`/assets/walletconnect.png`,e.k).toString()},categories:[]}],ta=({setCurrentContent:e,selectedCategory:t})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o,network:s}=$(),{isolatedView:c}=Fr(),u=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(t||null);(0,r.useEffect)(()=>{t!==void 0&&m(t)},[t]);let{data:h}=nn(),{data:_}=En(h?(parseInt(h)-1).toString():`1`),{data:v,isLoading:y,error:b}=Jo(),x=(0,r.useMemo)(()=>{let e=new Set;return s.type===`main`&&_&&_.length>0&&e.add(`vebetter`),v&&v.forEach(t=>{t.category&&e.add(t.category)}),Array.from(e).sort()},[v,_,s.type]),S=s.type===`main`?_.filter(e=>e.app.name.toLowerCase().includes(d.toLowerCase())):[],C=ea.filter(e=>e.name.toLowerCase().includes(d.toLowerCase())),w=v?.filter(e=>(e.name.toLowerCase().includes(d.toLowerCase())||e.description.toLowerCase().includes(d.toLowerCase())||e.tags.some(e=>e.toLowerCase().includes(d.toLowerCase())))&&(p===null||e.category===p))||[],T=p===null,E=p===null||p===`vebetter`,{shortcuts:D}=_c();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Ecosystem`)}),!c&&(0,i.jsx)(J,{onClick:()=>e(`settings`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{overflowY:`auto`,minH:`300px`,children:(0,i.jsxs)(n.VStack,{spacing:6,w:`full`,children:[(0,i.jsx)(Qi,{setCurrentContent:e}),D.length>0&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`500`,w:`full`,textAlign:`left`,children:a(`All apps`)}),(0,i.jsxs)(n.InputGroup,{size:`lg`,children:[(0,i.jsx)(n.Input,{placeholder:a(`Search Apps`),value:d,onChange:e=>{f(e.target.value)},bg:o?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12}),(0,i.jsx)(n.InputLeftElement,{h:`56px`,w:`56px`,pl:4,children:(0,i.jsx)(g.LuSearch,{color:u})})]}),x.length>0&&(0,i.jsx)($i,{selectedCategory:p,onCategoryChange:e=>{m(e)},categories:x,darkMode:o}),(0,i.jsxs)(n.Grid,{templateColumns:`repeat(2, 1fr)`,gap:4,w:`full`,children:[T&&C.length>0&&(0,i.jsx)(i.Fragment,{children:C.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Zi,{name:t.name,image:t.logo,url:t.external_url,setCurrentContent:e,description:t.description,selectedCategory:p})},t.name))}),E&&S.length>0&&(0,i.jsx)(i.Fragment,{children:S.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Xi,{xApp:t.app,setCurrentContent:e,selectedCategory:p})},t.id))}),y?(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Center,{py:4,children:(0,i.jsx)(n.Spinner,{})})}):b?(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Text,{color:`red.500`,textAlign:`center`,children:a(`Failed to load App Hub apps`)})}):w.length>0?w.map(t=>(0,i.jsx)(n.GridItem,{children:(0,i.jsx)(Zi,{name:t.name,image:t.logo,url:t.url,setCurrentContent:e,description:t.description,category:t.category,selectedCategory:p})},t.id)):p&&!E&&(0,i.jsx)(n.GridItem,{colSpan:2,children:(0,i.jsx)(n.Center,{py:4,children:(0,i.jsx)(n.Text,{children:a(`No apps found in this category`)})})})]})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},na=({name:e,image:t,url:r,description:a})=>{let{t:o}=(0,l.useTranslation)(),{isShortcut:s,addShortcut:c,removeShortcut:u}=_c(),d=s(r);return(0,i.jsx)(n.Button,{px:4,width:`full`,height:`45px`,variant:`vechainKitSecondary`,borderRadius:`xl`,onClick:()=>{d?u(r):c({name:e,image:t,url:r,description:a})},leftIcon:(0,i.jsx)(n.Icon,{as:d?g.LuBookmarkCheck:g.LuBookmark}),children:o(d?`Remove from shortcuts`:`Add to shortcuts`)})},ra=({setCurrentContent:e,name:t,image:r,url:a,description:o,category:s,selectedCategory:c,logoComponent:u})=>{let{t:d}=(0,l.useTranslation)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:t}),(0,i.jsx)(J,{onClick:()=>{e(c?{type:`ecosystem-with-category`,props:{selectedCategory:c,setCurrentContent:e}}:`ecosystem`)}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:6,align:`center`,w:`full`,children:[(0,i.jsxs)(n.Flex,{direction:`column`,align:`center`,children:[u||(0,i.jsx)(n.Image,{src:r,alt:t,w:`200px`,h:`200px`,objectFit:`contain`,borderRadius:`xl`}),s&&(0,i.jsx)(n.HStack,{mt:2,children:(0,i.jsx)(Ji,{category:s})})]}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:o}),(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:d(`Click below to access {{ name }} and explore its features.`,{name:t})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[(0,i.jsxs)(n.Button,{variant:`vechainKitSecondary`,onClick:()=>{window.open(a,`_blank`)},children:[d(`Launch {{name}}`,{name:t}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]}),(0,i.jsx)(na,{name:t,image:r,url:a,description:o})]})})]})},ia=({children:e})=>(0,i.jsx)(h.motion.div,{whileHover:{scale:1.1},transition:{duration:.5,ease:`easeInOut`,repeat:1/0,repeatDelay:crypto.getRandomValues(new Uint32Array(1))[0]/2**32*5},animate:{y:[0,-2,0],rotate:[0,10,-10,0]},children:e}),aa=({description:t})=>{let{darkMode:r}=$(),a=new URL(`intent/tweet`,e.v);a.searchParams.set(`text`,t);let o=new URL(`share/url`,e._);o.searchParams.set(`url`,t);let s=new URL(``,e.A);return s.searchParams.set(`text`,t),(0,i.jsxs)(n.HStack,{gap:2,children:[(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:a.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:r?`blackAlpha.700`:`lightgrey`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaXTwitter,{size:22})})})}),(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:o.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#30abec`,p:2,borderRadius:`full`,children:(0,i.jsx)(N.FaTelegramPlane,{color:`white`,size:22})})})}),(0,i.jsx)(ia,{children:(0,i.jsx)(n.Link,{href:s.toString(),isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#01cb37`,p:2,borderRadius:`full`,children:(0,i.jsx)(N.FaWhatsapp,{size:22,color:`white`})})})})]})},oa=({status:e,uiConfig:a,onTryAgain:o,txReceipt:s,txError:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=(0,n.useToken)(`colors`,`vechain-kit-error`),m=(0,n.useToken)(`colors`,`vechain-kit-success`),h=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),_=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),v=(0,r.useMemo)(()=>c?c.reason||d(`Something went wrong. Please try again.`):null,[c,d]),y=(()=>{let t=e===`waitingConfirmation`;switch(t&&(e=`pending`),e){case`pending`:return{title:a?.title??d(t?`Sending Transaction...`:`Waiting for confirmation`),icon:a?.loadingIcon??(0,i.jsx)(n.Spinner,{size:`xl`,"data-testid":`pending-spinner-modal`}),description:t?d(`Transaction is being processed, it can take up to 15 seconds.`):a?.description??d(`Please confirm the transaction in your wallet.`)};case`error`:return{title:d(`Something went wrong`),icon:a?.errorIcon??(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:p,fontSize:`100px`,"data-testid":`error-icon-modal`}),description:v??d(`An unexpected error occurred.`)};case`success`:return{title:d(`Transaction successful!`),icon:a?.successIcon??(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,color:m,fontSize:`100px`,"data-testid":`success-icon-modal`}),description:``};case`ready`:return{title:a?.title??d(`Confirm transaction`),icon:null,description:a?.description??d(`Confirm the transaction in your wallet to complete it.`)};default:return{title:``,icon:null,description:``}}})(),b=`${t.bt(f.type).explorerUrl}/${s?.meta.txID}`;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:y.title}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:e===`pending`&&!a?.isClosable})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[y.icon,e===`success`&&a?.showShareOnSocials&&(0,i.jsxs)(n.VStack,{mt:2,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:_,children:d(`Share on`)}),(0,i.jsx)(aa,{description:b})]}),y.description&&(0,i.jsx)(n.Text,{fontSize:e===`ready`?`md`:`sm`,textAlign:`center`,color:e===`error`?p:h,mt:5,style:{lineBreak:`anywhere`},children:y.description})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[e===`error`&&!!o&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:o,width:`full`,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),d(`Try again`)]}),e===`ready`&&(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitPrimary`,width:`full`,children:d(`Confirm`)}),(e===`success`||e===`error`||e===`ready`)&&(0,i.jsx)(n.Button,{onClick:u,variant:`ghost`,width:`full`,children:d(`Close`)}),a?.showExplorerButton&&s?.meta.txID&&(0,i.jsx)(n.Link,{href:`${t.bt(f.type).explorerUrl}/${s?.meta.txID}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{color:_,children:d(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:`sm`,as:g.LuExternalLink,color:_})]})})]})})]})},sa=({isOpen:e,onClose:t,status:n,uiConfig:r,txReceipt:a,txError:o,onTryAgain:s})=>{let{darkMode:c,theme:l}=$();return e?(0,i.jsx)($a,{darkMode:c,theme:l,children:(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,closeOnOverlayClick:n!==`pending`&&r?.isClosable,children:(0,i.jsx)(oa,{status:n,onTryAgain:s,uiConfig:r,txReceipt:a,onClose:t,txError:o})})}):null},ca=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.bt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`),m=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,fontSize:`100px`,color:p,"data-testid":`success-icon`}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,color:m,children:a}),s&&e&&(0,i.jsxs)(n.VStack,{mt:2,spacing:3,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,color:h,children:c(`Share on`)}),(0,i.jsx)(aa,{description:f})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:c(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{color:h,children:c(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},la=({txId:e,title:r,description:a,onDone:o})=>{let{t:s}=(0,l.useTranslation)(),{network:c,darkMode:u}=$(),d=t.bt(c.type).explorerUrl;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,fontSize:`100px`,color:u?`red.400`:`red.500`,"data-testid":`error-icon`}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:s(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{children:s(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},ua=({isOpen:e,onClose:t,initialContent:n=`profile`})=>{let{account:a}=X(),{themeConfig:o}=Za(),{accountModalContent:s,setAccountModalContent:c}=Q();return(0,r.useEffect)(()=>{e&&c(n)},[e,n,c]),(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:o?.modal?.useBottomSheetOnMobile?`520px`:`510px`,mobileMaxHeight:o?.modal?.useBottomSheetOnMobile?`520px`:`510px`,desktopMinHeight:`485px`,desktopMaxHeight:`485px`,children:(()=>{if(typeof s==`object`)switch(s.type){case`send-token`:return(0,i.jsx)(Ir,{...s.props});case`send-token-summary`:return(0,i.jsx)(Lr,{...s.props});case`swap-token`:return(0,i.jsx)(Hr,{...s.props});case`choose-name`:return(0,i.jsx)(Ur,{...s.props});case`choose-name-search`:return(0,i.jsx)(qr,{...s.props});case`choose-name-summary`:return(0,i.jsx)(Jr,{...s.props});case`app-overview`:return(0,i.jsx)(ra,{...s.props,setCurrentContent:c});case`disconnect-confirm`:return(0,i.jsx)(ki,{...s.props});case`remove-wallet-confirm`:return(0,i.jsx)(Ni,{...s.props});case`account-customization`:return(0,i.jsx)(ci,{...s.props});case`account-customization-summary`:return(0,i.jsx)(li,{...s.props});case`successful-operation`:return(0,i.jsx)(ca,{...s.props});case`failed-operation`:return(0,i.jsx)(la,{...s.props});case`upgrade-smart-account`:return(0,i.jsx)(pi,{...s.props});case`faq`:return(0,i.jsx)(Xr,{...s.props});case`terms-and-privacy`:return(0,i.jsx)(Oi,{...s.props});case`ecosystem-with-category`:return(0,i.jsx)(ta,{setCurrentContent:c,selectedCategory:s.props.selectedCategory});case`select-wallet`:return(0,i.jsx)(Mi,{setCurrentContent:c,onClose:t,returnTo:s.props.returnTo,onLogoutSuccess:s.props.onLogoutSuccess});case`main`:return(0,i.jsx)(Nr,{setCurrentContent:c,onClose:t,wallet:a,switchFeedback:s.props?.switchFeedback});case`profile`:return(0,i.jsx)(fi,{setCurrentContent:c,onLogoutSuccess:()=>{t()},switchFeedback:s.props?.switchFeedback})}switch(s){case`main`:return(0,i.jsx)(Nr,{setCurrentContent:c,onClose:t,wallet:a});case`settings`:return(0,i.jsx)(Si,{setCurrentContent:c,onLogoutSuccess:()=>{t()}});case`profile`:return(0,i.jsx)(fi,{setCurrentContent:c,onLogoutSuccess:()=>{t()}});case`assets`:return(0,i.jsx)(mi,{setCurrentContent:c});case`notifications`:return(0,i.jsx)(Ki,{setCurrentContent:c});case`receive-token`:return(0,i.jsx)(Rr,{setCurrentContent:c});case`swap-token`:return(0,i.jsx)(Hr,{setCurrentContent:c});case`connection-details`:return(0,i.jsx)(Ri,{onGoBack:()=>c(`settings`)});case`privy-linked-accounts`:return(0,i.jsx)(Bi,{onBack:()=>c(`settings`)});case`ecosystem`:return(0,i.jsx)(ta,{setCurrentContent:c});case`add-custom-token`:return(0,i.jsx)(hi,{setCurrentContent:c});case`change-currency`:return(0,i.jsx)(_i,{setCurrentContent:c});case`change-language`:return(0,i.jsx)(vi,{setCurrentContent:c});case`gas-token-settings`:return(0,i.jsx)(xi,{setCurrentContent:c});default:return null}})()})},da=({loadingText:e,title:t,onTryAgain:a,onClose:o,onGoBack:s,showBackButton:c=!0})=>{let{t:u}=(0,l.useTranslation)(),[d,f]=r.default.useState(!1);return r.default.useEffect(()=>{let e=setTimeout(()=>{f(!0)},7e3);return()=>clearTimeout(e)},[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[c&&(0,i.jsx)(J,{onClick:s}),t??u(`Connecting...`),(0,i.jsx)(n.ModalCloseButton,{onClick:o})]})}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsx)(n.VStack,{align:`center`,p:6,gap:0,w:`full`,justifyContent:`center`,minH:`150px`,children:(0,i.jsx)(n.Spinner,{size:`xl`})}),e&&!d&&(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:e}),d&&(0,i.jsxs)(n.VStack,{mt:4,spacing:2,children:[(0,i.jsx)(n.Text,{color:`orange.300`,size:`sm`,textAlign:`center`,children:u(`This is taking longer than expected.`)}),(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:u(`You may want to try establishing the connection again.`)})]})]}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:d&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:a,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),u(`Try again`)]})})]})},fa=({error:e,onClose:t,onTryAgain:r,onGoBack:a})=>{let{t:o}=(0,l.useTranslation)(),s=(0,h.useReducedMotion)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(J,{onClick:a}),o(`Connection Failed`),(0,i.jsx)(n.ModalCloseButton,{onClick:t})]})}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,w:`full`,justifyContent:`center`,minH:`100px`,gap:4,children:[(0,i.jsx)(h.motion.div,{transition:{duration:4,ease:`easeInOut`,repeat:s?0:1/0},animate:{scale:s?[1]:[1,1.1,1]},children:(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:`#ef4444`,fontSize:`60px`,opacity:.5})}),(0,i.jsx)(n.Text,{w:`full`,size:`sm`,textAlign:`center`,children:e})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:r,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),o(`Try again`)]})})]})},pa=({onClose:e,appsInfo:r,isLoading:a,setCurrentContent:o,showBackButton:s=!0})=>{let{t:c}=(0,l.useTranslation)(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),{setConnectionCache:d}=Vo(),{login:f}=jn(),p=async(n,i)=>{o({type:`loading`,props:{title:`${c(`Connecting with`)} ${i}`,loadingText:c(`Please approve the request in the connection request window...`),onTryAgain:()=>{p(n,i)}}});try{await f(n),d({name:i,logoUrl:r.find(e=>e.id===n)?.logo_url,appId:n,website:r.find(e=>e.id===n)?.website}),e()}catch(e){let a=e?.message;if(a&&t.a(a)){o({type:`ecosystem`,props:{appsInfo:r,isLoading:!1}});return}o({type:`error`,props:{error:(e instanceof Error?e:Error(`An unexpected issue occurred while logging in with this app. Please try again or contact support.`)).message,onTryAgain:()=>{p(n,i)}}})}};return(0,i.jsx)(n.Box,{children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(Y,{children:(0,i.jsxs)(n.ModalHeader,{children:[s&&(0,i.jsx)(J,{onClick:()=>o(`main`)}),c(`Already have an x2earn app wallet?`),(0,i.jsx)(n.ModalCloseButton,{onClick:e})]})}),(0,i.jsxs)(n.ModalBody,{children:[a&&(0,i.jsx)(n.VStack,{minH:`200px`,w:`full`,justifyContent:`center`,children:(0,i.jsx)(n.Spinner,{})}),!a&&r&&(0,i.jsx)(n.VStack,{spacing:4,w:`full`,pb:6,children:r.map(e=>(0,i.jsxs)(n.Button,{variant:`loginIn`,fontSize:`14px`,fontWeight:`400`,p:6,borderRadius:16,w:`full`,onClick:()=>{p(e.id,e.name)},justifyContent:`flex-start`,children:[(0,i.jsx)(n.Image,{src:e.logo_url,alt:e.name,w:`30px`}),(0,i.jsx)(n.Text,{ml:5,children:e.name})]},e.id))}),!a&&!r&&(0,i.jsx)(n.Text,{textAlign:`center`,color:u,children:c(`No application from VeChain ecosystem is available to login.`)})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})})},ma=({isOpen:e,onClose:t,initialContent:n=`main`,preventAutoClose:a=!1})=>{let[o,s]=(0,r.useState)(n);(0,r.useEffect)(()=>{e&&s(n)},[e,n,s]);let c=(()=>{if(!o)return(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t,preventAutoClose:a});switch(o){case`main`:return(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t,preventAutoClose:a});case`faq`:return(0,i.jsx)(Xr,{onGoBack:()=>s(`main`)})}if(typeof o==`object`&&`type`in o)switch(o.type){case`ecosystem`:return(0,i.jsx)(pa,{onClose:t,appsInfo:o.props.appsInfo,isLoading:o.props.isLoading,setCurrentContent:s,showBackButton:o.props.showBackButton});case`loading`:return(0,i.jsx)(da,{title:o.props.title,loadingText:o.props.loadingText,onTryAgain:o.props.onTryAgain,onClose:t,onGoBack:()=>s(`main`),showBackButton:o.props.showBackButton});case`error`:return(0,i.jsx)(fa,{error:o.props.error,onClose:t,onTryAgain:o.props.onTryAgain,onGoBack:()=>s(`main`)})}return null})();return c?(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:`260px`,mobileMaxHeight:`400px`,desktopMinHeight:`250px`,desktopMaxHeight:`400px`,children:c}):(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,mobileMinHeight:`260px`,mobileMaxHeight:`400px`,desktopMinHeight:`250px`,desktopMaxHeight:`400px`,children:(0,i.jsx)(Mr,{setCurrentContent:s,onClose:t})})},ha=({onClick:e,text:t,icon:r,customIcon:a,rightIcon:o,style:s,variant:c=`loginIn`,iconWidth:l=`25px`})=>t?t?(0,i.jsxs)(n.Button,{...s,variant:c,w:`full`,onClick:e,children:[(0,i.jsxs)(n.HStack,{w:`full`,justify:`flex-start`,gap:2,children:[a||(0,i.jsx)(n.Icon,{as:r,w:l,h:l}),(0,i.jsx)(n.Text,{opacity:.9,children:t})]}),o]}):null:(0,i.jsx)(n.Button,{...s,variant:c,w:`full`,onClick:e,children:a||(0,i.jsx)(n.Icon,{as:r,w:`20px`,h:`20px`})}),ga=({isLoading:e,buttonStyle:t})=>{let{t:a}=(0,l.useTranslation)(),{loginMethods:o,darkMode:s,privyEcosystemAppIDS:c}=$(),u=o?.some(({method:e})=>e===`ecosystem`),{open:d}=no(),{data:f,isLoading:p}=Ve(c),m=(0,r.useCallback)(e=>{let t=typeof e==`function`?e(`main`):e;typeof t==`object`&&`type`in t?t.type===`ecosystem`?d({type:`ecosystem`,props:{...t.props,showBackButton:!1}}):t.type===`loading`?d({type:`loading`,props:{...t.props,showBackButton:!1}}):d(t):d(t)},[d]);return(0,i.jsx)(n.Popover,{placement:`bottom-start`,size:`xl`,closeOnBlur:!1,variant:`vechainKitBase`,children:({isOpen:r})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.PopoverTrigger,{children:(0,i.jsxs)(n.Button,{isLoading:e,...t,isActive:r,children:[a(`Login`),(0,i.jsx)(n.Icon,{ml:2,as:g.LuChevronDown,transform:r?`rotate(180deg)`:`rotate(0deg)`,transition:`transform 0.2s`})]})}),(0,i.jsxs)(n.PopoverContent,{children:[(0,i.jsx)(n.PopoverBody,{children:(0,i.jsx)(Ar,{setCurrentContent:m})}),(0,i.jsx)(n.PopoverFooter,{borderTop:`none`,pb:`15px`,children:u&&(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(jr,{isDark:s,appsInfo:Object.values(f||{}),isLoading:p,setCurrentContent:m})})})]})]})})},_a=({variant:e})=>{let{account:r}=X();return r?e===`icon`?null:e===`iconAndDomain`?r.domain?(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.G(r?.domain??``,16,0)}):(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.W(r.address??``,6,4)}):e===`iconDomainAndAssets`?(0,i.jsxs)(n.HStack,{spacing:4,children:[(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,children:[r.domain&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,children:t.G(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,"data-testid":`trimmed-address`,children:t.W(r.address??``,4,4)})]}),(0,i.jsx)($r,{address:r.address??``,maxIcons:3})]}):(0,i.jsxs)(n.VStack,{spacing:0,alignItems:`flex-start`,children:[r.domain&&(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,children:t.G(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,children:t.W(r.address??``,4,4)})]}):(0,i.jsx)(n.Spinner,{})},va=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconAndDomain`,onOpen:r,buttonStyle:a={}})=>{let{account:o}=X(),[s]=(0,n.useMediaQuery)(`(min-width: 768px)`);return(0,i.jsx)(n.Button,{...a,onClick:r,w:`full`,minH:`45px`,maxW:`fit-content`,"data-testid":`wallet-button`,children:(0,i.jsxs)(n.HStack,{w:`full`,minW:`fit-content`,children:[(0,i.jsx)(Mc,{wallet:o,props:{width:30,height:30,minWidth:30,minHeight:30}}),(0,i.jsx)(_a,{variant:s?t:e})]})})},ya=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconDomainAndAddress`,buttonStyle:r,connectionVariant:a=`modal`,label:o=`Login`})=>{let{darkMode:s,loginMethods:c,theme:l}=$(),u=c?.length===1&&c[0].method===`dappkit`,{connection:d,account:p}=X(),{setSource:m,connectV2:h}=(0,f.useWallet)(),[g]=(0,n.useMediaQuery)(`(max-width: 768px)`),_=(0,n.useDisclosure)(),v=(0,n.useDisclosure)(),{open:y}=(0,f.useWalletModal)();return(0,i.jsxs)($a,{darkMode:s,theme:l,children:[d.isConnected&&p?(0,i.jsx)(va,{mobileVariant:e,desktopVariant:t,onOpen:v.onOpen,buttonStyle:r}):a===`popover`&&!g?(0,i.jsx)(ga,{isLoading:d.isLoading,buttonStyle:r}):(0,i.jsx)(n.Button,{isLoading:d.isLoading,onClick:()=>{d.isInAppBrowser?(m(`veworld`),h(null)):u?y():_.onOpen()},...r,children:o}),(0,i.jsx)(ma,{isOpen:_.isOpen,onClose:_.onClose}),(0,i.jsx)(ua,{isOpen:v.isOpen,onClose:v.onClose})]})},ba=()=>{let{darkMode:e}=$(),t=25/2,[r]=(0,n.useMediaQuery)(`(max-width: 280px)`),[a]=(0,n.useMediaQuery)(`(max-width: 380px)`);return(0,i.jsxs)(n.HStack,{spacing:0,ml:0,children:[(0,i.jsx)(n.Circle,{size:`25px`,borderRadius:`full`,bg:`#F8F8F8`,p:2,alignItems:`center`,justifyContent:`center`,zIndex:3,children:(0,i.jsx)(n.Icon,{as:E.FcGoogle,fontSize:`20px`})}),!r&&(0,i.jsx)(n.Circle,{ml:`-${t}px`,size:`25px`,borderRadius:`full`,bg:`black`,p:2,alignItems:`center`,justifyContent:`center`,zIndex:2,children:(0,i.jsx)(n.Icon,{as:j.FaXTwitter,color:`white`,fontSize:`20px`})}),!r&&!a&&(0,i.jsx)(n.Circle,{ml:`-${t}px`,zIndex:1,size:`25px`,borderRadius:`full`,bg:`#5865F2`,p:2,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Icon,{as:j.FaDiscord,color:`white`,fontSize:`20px`})}),(0,i.jsx)(n.Icon,{zIndex:1,as:g.LuPlus,color:e?`black`:`white`,fontSize:`15px`})]})},xa=({status:e,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=t.bt(f.type).explorerUrl,m=(0,r.useMemo)(()=>o?o.reason||d(`Something went wrong. Please try again.`):null,[o,d]),h=(()=>{let t=e===`waitingConfirmation`;switch(t&&(e=`pending`),e){case`pending`:return{icon:(0,i.jsx)(n.Spinner,{size:`md`,"data-testid":`pending-spinner-toast`}),title:d(t?`Processing transaction...`:`Waiting for confirmation...`),closeDisabled:!0,description:t?d(`Transaction is being processed, it can take up to 15 seconds.`):c??d(`Please confirm the transaction in your wallet.`)};case`error`:return{icon:(0,i.jsx)(n.Icon,{as:g.LuCircleAlert,color:`red.500`,fontSize:`40px`,"data-testid":`error-icon-toast`}),title:d(`Transaction failed`),closeDisabled:!1,description:m};case`success`:return{icon:(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,color:`green.500`,fontSize:`40px`,"data-testid":`success-icon-toast`}),title:d(`Transaction successful!`),closeDisabled:!1,description:void 0};case`ready`:return{icon:null,title:d(`Confirm transaction`),closeDisabled:!1,description:c??d(`Confirm the transaction in your wallet to complete it.`)};default:return{icon:null,title:``,closeDisabled:!1,description:``}}})();return h?(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`flex-start`,w:`full`,children:[(0,i.jsx)(n.VStack,{spacing:4,children:(0,i.jsxs)(n.HStack,{spacing:4,w:`full`,justifyContent:`flex-start`,alignItems:`flex-start`,children:[h.icon,(0,i.jsxs)(n.VStack,{w:`full`,align:`flex-start`,spacing:2,children:[(0,i.jsxs)(n.VStack,{spacing:1,w:`full`,children:[(0,i.jsx)(n.Heading,{w:`full`,size:`xs`,children:h.title}),h.description&&(0,i.jsx)(n.Text,{fontSize:`xs`,children:h.description})]}),(e===`error`||e===`ready`)&&(0,i.jsx)(n.Button,{size:`xs`,onClick:s,children:e===`error`?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),d(`Try again`)]}):d(`Confirm`)}),a&&e!==`pending`&&(0,i.jsxs)(n.Link,{fontSize:`xs`,isExternal:!0,href:`${p}/${a.meta.txID}`,children:[d(`View on explorer`),` `,(0,i.jsx)(n.Icon,{as:g.LuExternalLink})]})]})]})}),!h.closeDisabled&&(0,i.jsx)(n.IconButton,{onClick:u,size:`sm`,borderRadius:`full`,"aria-label":`Close`,icon:(0,i.jsx)(n.Icon,{as:g.LuX,boxSize:4})})]}):null},Sa=({isOpen:e,onClose:t,status:r,txReceipt:a,txError:o,onTryAgain:s,description:c})=>{let{darkMode:l}=$();return e?(0,i.jsx)(n.Box,{position:`fixed`,bottom:`5`,left:`5`,zIndex:`11111`,bg:l?`#1f1f1e`:`white`,borderRadius:`md`,p:5,boxShadow:`lg`,maxW:`sm`,minW:`300px`,children:(0,i.jsx)(xa,{status:r,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:t})}):null},Ca=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.bt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:r}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`center`,p:6,spacing:3,children:[(0,i.jsx)(h.motion.div,{transition:{duration:4,ease:`easeInOut`,repeat:1/0},animate:{scale:[1,1.1,1]},children:(0,i.jsx)(n.Icon,{as:g.LuCircleCheck,fontSize:`100px`,color:p})}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a}),s&&e&&(0,i.jsxs)(n.VStack,{mt:2,children:[(0,i.jsx)(n.Text,{fontSize:`xs`,children:c(`Share on`)}),(0,i.jsx)(aa,{description:f})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[(0,i.jsx)(n.Button,{onClick:o,variant:`vechainKitSecondary`,width:`full`,children:c(`Done`)}),e&&(0,i.jsx)(n.Link,{href:`${d}/${e}`,isExternal:!0,opacity:.5,fontSize:`14px`,textDecoration:`underline`,children:(0,i.jsxs)(n.HStack,{spacing:1,alignItems:`center`,w:`full`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{children:c(`View transaction on the explorer`)}),(0,i.jsx)(n.Icon,{size:16,as:g.LuExternalLink})]})})]})})]})},wa=({setCurrentContent:e,handleClose:t,style:r})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=Is(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Vs({smartAccountAddress:o?.address??``,targetVersion:3,onSuccess:()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:m?.meta.txID,title:a(`Upgrade Successful!`),description:a(`Your account has been successfully upgraded to the latest version. You can now enjoy a better user experience, lower gas costs, and enhanced security.`),onDone:()=>{t()},showSocialButtons:!1}})},onError:()=>{console.error(`Error upgrading Smart Account`)}});return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Y,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:10,align:`stretch`,justifyContent:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,textAlign:`center`,children:a(`To continue interacting with VeChain blockchain and complete your operation, your smart account needs to be upgraded to the latest version (v3).`)}),(0,i.jsxs)(n.HStack,{align:`center`,justifyContent:`space-evenly`,rounded:`md`,children:[(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,borderRadius:`full`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#D23F63`,fontSize:`28px`,children:`v1`})]}),(0,i.jsx)(n.Icon,{as:g.LuArrowRight,color:`#3DBA67`}),(0,i.jsxs)(n.Box,{position:`relative`,display:`inline-block`,children:[(0,i.jsx)(n.Circle,{size:`60px`,bg:`gray.200`,children:(0,i.jsx)(n.Image,{src:o?.image,alt:a(`Profile Picture`),w:`100%`,h:`100%`,borderRadius:`full`,objectFit:`cover`})}),(0,i.jsx)(n.Heading,{position:`absolute`,top:`-5`,right:`-5`,color:`#3DBA67`,fontSize:`28px`,children:`v3`})]})]}),(0,i.jsxs)(n.Alert,{status:`info`,borderRadius:`md`,children:[(0,i.jsx)(n.AlertIcon,{}),(0,i.jsxs)(n.Box,{children:[(0,i.jsx)(n.AlertTitle,{fontSize:`sm`,children:a(`Benefits of this upgrade:`)}),(0,i.jsx)(n.AlertDescription,{fontSize:`xs`,children:(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,mt:1,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,lineHeight:`1.2`,children:[`• `,a(`Improved security features`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`• `,a(`Better transaction handling`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Enhanced compatibility with dApps`)]}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[`•`,` `,a(`Reduced gas costs for operations`)]})]})})]})]})]})}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:(0,i.jsx)(n.VStack,{spacing:3,w:`full`,children:(0,i.jsx)(Nc,{style:r,buttonText:a(c?`Upgrade account`:`Account already upgraded`),onConfirm:async()=>{try{await u()}catch(e){console.error(`Failed to upgrade Smart Account:`,e)}},isTxWaitingConfirmation:f,isSubmitting:d,transactionPendingText:a(`Upgrading...`),txReceipt:m,transactionError:p,isDisabled:!c})})})]})},Ta=({isOpen:e,onClose:t,style:n})=>{let[a,o]=(0,r.useState)(`upgrade-smart-account`);return(0,r.useEffect)(()=>{e&&o(`upgrade-smart-account`)},[e]),(0,i.jsx)(Re,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,size:n?.modalSize,children:(()=>{if(typeof a==`object`)switch(a.type){case`successful-operation`:return(0,i.jsx)(Ca,{...a.props})}else if(a===`upgrade-smart-account`)return(0,i.jsx)(wa,{setCurrentContent:o,handleClose:t,style:n})})()})},{definePartsStyle:Ea,defineMultiStyleConfig:Da}=(0,n.createMultiStyleConfigHelpers)(I.modalAnatomy.keys),Oa=e=>({vechainKitBase:Ea({dialog:{scrollbarWidth:`none`,overflow:`scroll`,overflowX:`hidden`,rounded:e.modal.rounded??e.borders.radius.modal,backgroundColor:e.colors.background.modal,backdropFilter:e.effects.backdropFilter.modal,border:e.colors.border.modal},overlay:{backgroundColor:e.colors.background.overlay,backdropFilter:e.effects.backdropFilter.overlay},closeButton:{borderRadius:e.borders.radius.full,color:e.colors.text.primary,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8}},_active:{bg:e.buttons.button.bg,opacity:.8}},header:{w:`full`,color:e.colors.text.primary,fontSize:e.fonts.sizes.large,fontWeight:e.fonts.weights.bold,textAlign:`center`,paddingBottom:5,paddingTop:5}})}),ka=e=>Da({variants:Oa(e),defaultProps:{variant:`vechainKitBase`}}),{definePartsStyle:Aa,defineMultiStyleConfig:ja}=(0,n.createMultiStyleConfigHelpers)(I.cardAnatomy.keys),Ma=e=>({vechainKitBase:Aa({container:{backgroundColor:e.colors.background.card,borderRadius:e.borders.radius.medium,width:`full`,border:`none`},body:{p:5,width:`full`},header:{p:5,width:`full`,borderRadius:`${e.borders.radius.medium} ${e.borders.radius.medium} 0 0`},footer:{width:`full`,borderRadius:`0 0 ${e.borders.radius.medium} ${e.borders.radius.medium}`}}),vechainKitWalletCard:Aa({container:{backgroundColor:e.colors.background.card,borderRadius:e.borders.radius.medium,width:`full`,cursor:`pointer`,position:`relative`}}),featureAnnouncement:Aa({body:{backgroundColor:e.buttons.button.bg,borderRadius:e.borders.radius.medium,color:e.colors.text.secondary},container:{borderRadius:e.borders.radius.medium,backgroundColor:`transparent`}}),vechainKitAppCard:Aa({body:{height:`full`,borderRadius:e.borders.radius.medium,backgroundColor:e.colors.background.cardElevated,border:`1px solid ${e.colors.border.default}`},container:{height:`150px`,borderRadius:e.borders.radius.medium,backgroundColor:`transparent`}})}),Na=e=>ja({variants:Ma(e),defaultProps:{variant:`vechainKitBase`}}),Pa=(0,n.defineStyle)({borderRadius:`12px`}),Fa=e=>({loginIn:(0,n.defineStyle)(()=>({bg:e.buttons.loginButton.bg,color:e.buttons.loginButton.color,border:e.buttons.loginButton.border,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.normal,py:6,px:3,rounded:e.buttons.loginButton.rounded??e.borders.radius.large,backdropFilter:e.buttons.loginButton.backdropFilter,_hover:{opacity:.5,_disabled:{opacity:.5,bg:e.buttons.loginButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.loginButton.bg},transition:`all 0.2s`})),loginWithVechain:(0,n.defineStyle)(()=>({color:`white`,bg:`#1a1a1a`,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.normal,py:6,px:3,borderRadius:e.borders.radius.large,border:`1px solid ${e.colors.border.button}`,_hover:{opacity:.5,_disabled:{opacity:.5,bg:`#1a1a1a`}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:`#1a1a1a`},_dark:{color:`#1a1a1a`,bg:`white`,_hover:{_disabled:{bg:`white`}},_disabled:{bg:`white`}},transition:`all 0.2s`})),vechainKitPrimary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.primaryButton.rounded??e.borders.radius.large,bg:e.buttons.primaryButton.bg,color:e.buttons.primaryButton.color,border:e.buttons.primaryButton.border,backdropFilter:e.buttons.primaryButton.backdropFilter,_hover:{...e.buttons.primaryButton.hoverBg?{bg:e.buttons.primaryButton.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.primaryButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.primaryButton.bg},transition:`all 0.2s`})),vechainKitSecondary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.button.rounded??e.borders.radius.large,bg:e.buttons.button.bg,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`})),vechainKitTertiary:(0,n.defineStyle)(()=>({fontSize:e.fonts.sizes.medium,px:4,width:`full`,height:`60px`,rounded:e.buttons.tertiaryButton.rounded??e.borders.radius.large,bg:e.buttons.tertiaryButton.bg,color:e.buttons.tertiaryButton.color,border:e.buttons.tertiaryButton.border===`none`?`none`:e.buttons.tertiaryButton.border,backdropFilter:e.buttons.tertiaryButton.backdropFilter,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.buttons.tertiaryButton.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.tertiaryButton.bg},transition:`all 0.2s`})),vechainKitLogout:(0,n.defineStyle)(()=>({px:4,width:`full`,height:`60px`,rounded:e.buttons.button.rounded??e.borders.radius.large,bg:e.colors.error+`1f`,color:e.colors.error,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.colors.error+`1f`}},_disabled:{opacity:.5,cursor:`not-allowed`},transition:`all 0.2s`})),vechainKitHeaderIconButtons:(0,n.defineStyle)(()=>({bg:e.buttons.button.bg,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`none`:e.buttons.button.border,backdropFilter:e.buttons.button.backdropFilter,_hover:{...e.buttons.button.hoverBg?{bg:e.buttons.button.hoverBg}:{opacity:.8},_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`,rounded:`full`,mt:`8px`})),actionButton:(0,n.defineStyle)(()=>({width:`full`,minHeight:`50px`,height:`fit-content`,bg:e.buttons.button.bg,borderRadius:e.borders.radius.xl,p:0,color:e.buttons.button.color,border:e.buttons.button.border===`none`?`1px solid ${e.colors.border.button}`:e.buttons.button.border,_hover:{opacity:.8,_disabled:{opacity:.5,bg:e.buttons.button.bg}},_disabled:{opacity:.5,cursor:`not-allowed`,bg:e.buttons.button.bg},transition:`all 0.2s`})),ghost:(0,n.defineStyle)(()=>({bg:`transparent`,color:e.colors.text.primary,border:`none`,_hover:{bg:e.buttons.button.bg},_active:{bg:e.buttons.button.bg,opacity:.8},transition:`all 0.2s`})),link:(0,n.defineStyle)(()=>({color:e.colors.text.primary,_hover:{color:e.colors.text.secondary,textDecoration:`underline`},_active:{color:e.colors.text.primary},transition:`all 0.2s`}))}),Ia=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e)}),La=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e)}),Ra=e=>(0,n.defineStyleConfig)({baseStyle:Pa,variants:Fa(e),defaultProps:{variant:`vechainKitHeaderIconButtons`}}),{definePartsStyle:za,defineMultiStyleConfig:Ba}=(0,n.createMultiStyleConfigHelpers)(I.popoverAnatomy.keys),Va=e=>({vechainKitBase:za({popper:{zIndex:1e3},content:{borderRadius:e.borders.radius.xl,border:e.colors.border.modal,backgroundColor:e.colors.background.modal,backdropFilter:e.effects.backdropFilter.modal,boxShadow:`0px 4px 16px rgba(0, 0, 0, 0.12)`,minWidth:`380px`},body:{padding:`16px`}})}),Ha=e=>Ba({variants:Va(e),defaultProps:{variant:`vechainKitBase`}}),Ua=(e,t)=>({useSystemColorMode:!1,disableTransitionOnChange:!1,components:{Modal:ka(t),Card:Na(t),Button:Ia(t),IconButton:La(t),CloseButton:Ra(t),Popover:Ha(t)},styles:{global:()=>({})},semanticTokens:{colors:{"chakra-placeholder-color":t.colors.text.tertiary,"vechain-kit-modal":t.colors.background.modal,"vechain-kit-overlay":t.colors.background.overlay,"vechain-kit-card":e?`rgba(0, 0, 0, 0.3)`:`rgba(0, 0, 0, 0.05)`,"vechain-kit-card-elevated":e?`rgba(0, 0, 0, 0.4)`:`rgba(0, 0, 0, 0.08)`,"vechain-kit-sticky-header":t.colors.background.stickyHeader,"vechain-kit-text-primary":t.colors.text.primary,"vechain-kit-text-secondary":t.colors.text.secondary,"vechain-kit-text-tertiary":t.colors.text.tertiary,"vechain-kit-border":t.colors.border.default,"vechain-kit-border-hover":t.colors.border.hover,"vechain-kit-border-focus":t.colors.border.focus,"vechain-kit-success":t.colors.success,"vechain-kit-error":t.colors.error,"vechain-kit-warning":t.colors.warning,"vechain-kit-button-primary-bg":t.buttons.primaryButton.bg,"vechain-kit-button-primary-color":t.buttons.primaryButton.color},effects:{"vechain-kit-backdrop-filter-modal":t.effects.backdropFilter.modal,"vechain-kit-backdrop-filter-overlay":t.effects.backdropFilter.overlay,"vechain-kit-backdrop-filter-sticky-header":t.effects.backdropFilter.stickyHeader},config:{cssVarPrefix:`vechain-kit`}},fonts:n.theme.fonts,fontSizes:{...n.theme.fontSizes,sm:t.fonts.sizes.small,md:t.fonts.sizes.medium,lg:t.fonts.sizes.large},fontWeights:{...n.theme.fontWeights,normal:t.fonts.weights.normal,medium:t.fonts.weights.medium,bold:t.fonts.weights.bold},colors:n.theme.colors,space:n.theme.space}),Wa=(e,t)=>{let r=(0,n.extendTheme)(Ua(e,ve(_e(e),ye(t,e))));return r.styles.global=()=>({}),r.__cssVars&&(r.__cssVars.global=()=>({})),r},{ToastContainer:Ga}=(0,n.createStandaloneToast)(),Ka=()=>(0,F.default)({key:`vechain-kit`,prepend:!0}),qa=({bodyFont:e,headingFont:t})=>(0,i.jsx)(P.Global,{styles:P.css`
128
128
  /* define CSS layers with proper priority order */
129
129
  @layer vechain-kit, host-app;
130
130
 
@@ -197,7 +197,7 @@ const e=require(`./assets-DNJsQD7_.cjs`),t=require(`./utils-DeETrpws.cjs`);let n
197
197
  font-family: ${t} !important;
198
198
  }
199
199
  }
200
- `}),Ja=({children:e,theme:t,bodyFont:a,headingFont:o})=>(0,i.jsxs)(P.CacheProvider,{value:(0,r.useMemo)(()=>Ka(),[]),children:[(0,i.jsx)(qa,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,children:e})]}),Ya=({darkMode:e})=>{try{if(t._t(`[data-chakra-color-mode]`))return null}catch(e){console.error(e)}return(0,i.jsx)(n.ColorModeScript,{initialColorMode:e?`dark`:`light`})},Xa=(0,r.createContext)({portalRootRef:void 0,tokens:void 0,themeConfig:void 0}),Za=()=>{let e=(0,r.useContext)(Xa);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},Qa=({darkMode:e=!1})=>{let{setColorMode:t,colorMode:a}=(0,n.useColorMode)();return(0,r.useEffect)(()=>{let n=e?`dark`:`light`;a!==n&&t(n)},[e]),(0,i.jsx)(i.Fragment,{})},$a=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(il),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>ve(_e(t),ye(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...Wa(t,l),config:{...Wa(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]);return(0,i.jsxs)(Xa.Provider,{value:{portalRootRef:o,tokens:u,themeConfig:l},children:[(0,i.jsx)(Ya,{darkMode:t}),(0,i.jsxs)(Ja,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,children:[(0,i.jsx)(Qa,{darkMode:t}),(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})]}),(0,i.jsx)(Ga,{})]})},eo=(0,r.createContext)(null),Q=()=>{let e=(0,r.useContext)(eo);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},to=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),[c,l]=(0,r.useState)(`main`),[u,d]=(0,r.useState)(!1),{setSource:p,connectV2:m}=(0,f.useWallet)(),h=(0,r.useCallback)((e,n)=>{t.mt()&&window.vechain&&window.vechain.isInAppBrowser?(p(`veworld`),m(null)):(l(e??`main`),d(n??!1),s(!0))},[]),g=(0,r.useCallback)(()=>{s(!1),l(`main`),d(!1)},[]),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(`main`),C=(0,r.useCallback)((e,t)=>{S(e??`main`),b(t?.isolatedView??!1),v(!0)},[]),w=(0,r.useCallback)(()=>{v(!1),S(`main`),setTimeout(()=>{b(!1)},300)},[]),[T,E]=(0,r.useState)(!1),D=(0,r.useCallback)(()=>E(!0),[]),O=(0,r.useCallback)(()=>E(!1),[]),[k,A]=(0,r.useState)(!1),j=(0,r.useCallback)(()=>A(!0),[]),M=(0,r.useCallback)(()=>A(!1),[]),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(void 0),L=(0,r.useCallback)(e=>{I(e),P(!0)},[]),R=(0,r.useCallback)(()=>P(!1),[]);return(0,i.jsxs)(eo.Provider,{value:{openConnectModal:h,closeConnectModal:g,isConnectModalOpen:o,connectModalContent:c,setConnectModalContent:l,connectModalPreventAutoClose:u,setConnectModalPreventAutoClose:d,openAccountModal:C,closeAccountModal:w,isAccountModalOpen:_,setAccountModalContent:S,accountModalContent:x,isolatedView:y,openTransactionModal:D,closeTransactionModal:O,isTransactionModalOpen:T,openTransactionToast:j,closeTransactionToast:M,isTransactionToastOpen:k,openUpgradeSmartAccountModal:L,closeUpgradeSmartAccountModal:R,isUpgradeSmartAccountModalOpen:N},children:[e,(0,i.jsxs)($a,{darkMode:n,theme:a,children:[(0,i.jsx)(ma,{isOpen:o,onClose:g,initialContent:c,preventAutoClose:u}),(0,i.jsx)(ua,{isOpen:_,onClose:w,initialContent:x}),(0,i.jsx)(Ta,{isOpen:N,onClose:R,style:F})]})]})},no=()=>{let{loginMethods:e}=$(),t=e?.length===1&&e[0].method===`dappkit`,{openConnectModal:n,closeConnectModal:r,isConnectModalOpen:i}=Q(),{open:a,close:o}=(0,f.useWalletModal)();return{open:t?a:e=>n(e),close:t?o:r,isOpen:t?!1:i}},ro=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),io=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:()=>e(),close:t,isOpen:n}},ao=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),oo=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=Q();return{open:e,close:t,isOpen:n}},so=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),co=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=Q();return{open:e,close:t,isOpen:n}},lo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),uo=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=Q();return{open:n=>{e.isConnected?i(void 0,n):t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},fo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),po=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},mo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ho=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`send-token`,props:{setCurrentContent:r}},t)},close:()=>{t()},isOpen:n}},go=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),_o=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},vo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),yo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},bo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},So=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Co=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`faq`,props:{onGoBack:()=>r(`main`),showLanguageSelector:!1}},t)},close:()=>{t()},isOpen:n}},wo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),To=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:()=>{e({type:`account-customization`,props:{setCurrentContent:r}})},close:()=>{t()},isOpen:n}},Eo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Do=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},Oo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ko=()=>{let{privy:e,loginMethods:n}=$(),i=e?.appId===t.at,a=e=>n?Array.isArray(e)?e.some(e=>n.some(t=>t.method===e)):n.some(t=>t.method===e):!0,o=(0,r.useMemo)(()=>n?n.length===0||a(`ecosystem`):!0,[n]),s=(0,r.useMemo)(()=>a(`vechain`),[n]),c=(0,r.useMemo)(()=>a(`dappkit`),[n]),l=(0,r.useMemo)(()=>a(`passkey`),[n]),u=(0,r.useMemo)(()=>a(`email`),[n]),d={showGoogleLogin:(0,r.useMemo)(()=>a(`google`),[n]),showEmailLogin:u,showPasskey:l,showVeChainLogin:s,showDappKit:c,showEcosystem:o,showMoreLogin:(0,r.useMemo)(()=>a(`more`),[n]),showGithubLogin:(0,r.useMemo)(()=>a(`github`),[n]),isOfficialVeChainApp:!1};return e?i?{...d,isOfficialVeChainApp:!0}:{...d}:{...d,showGoogleLogin:!1,showEmailLogin:!1,showPasskey:!1,showMoreLogin:!1}},Ao=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=Q();return{open:()=>t(e),close:n,isOpen:r}},jo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Mo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},No=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Po=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`settings`,t)},close:()=>{t()},isOpen:n}},Fo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Io=()=>{let[e,t]=(0,r.useState)(!1),[n,i]=(0,r.useState)(null),[a,o]=(0,r.useState)(null),{connection:s,account:c}=X(),{requestCertificate:l}=(0,f.useWallet)(),u=rl();return{signMessage:(0,r.useCallback)(async e=>{if(!c)throw Error(`Account not found`);t(!0),o(null),i(null);try{let t=null;return t=s.isConnectedWithDappKit?(await l({purpose:`agreement`,payload:{type:`text`,content:e}},{signer:c.address})).signature:await u.signMessage(e),i(t),t}catch(e){let t=e instanceof Error?e:Error(String(e));throw o(t),t}finally{t(!1)}},[s,u,c?.address]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},Lo=()=>{let[e,t]=(0,r.useState)(!1),[n,i]=(0,r.useState)(null),[a,o]=(0,r.useState)(null),{signer:s}=(0,f.useWallet)(),{connection:c}=X(),l=rl();return{signTypedData:(0,r.useCallback)(async(e,n)=>{t(!0),o(null),i(null);try{let t;if(c.isConnectedWithDappKit){let r={...e.domain,salt:e.domain?.salt?Buffer.from(e.domain.salt).toString(`hex`):void 0};t=await s.signTypedData(r,e.types,e.message,void 0,n)}else t=await l.signTypedData(e);return i(t),t}catch(e){if(e&&typeof e==`object`&&`statusCode`in e&&e.statusCode===4001){let e=Error(`User denied signature request`);throw o(e),e}let t=e instanceof Error?e:Error(typeof e==`object`?JSON.stringify(e):String(e));throw console.error(t),o(t),t}finally{t(!1)}},[c,l]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},Ro=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}};let zo=!1;const Bo=()=>{let{createWallet:e}=(0,u.useCreateWallet)(),{initOAuth:t}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:t})=>{if(t&&!zo){zo=!0;try{await e()}catch(e){throw zo=!1,console.error(`Failed to create wallet:`,e),e}}},[e])});return{initOAuth:async({provider:e})=>{try{await t({provider:e})}catch(e){throw e}}}},Vo=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t.yt(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.dt(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t.gt(e)},[])}},Ho=()=>{let{login:n}=jn(),{setConnectionCache:r}=Vo(),{data:i}=Ve([t.at]);return{login:async()=>{try{await n(t.at),r({name:`VeChain`,logoUrl:i?.[t.at]?.logo_url,appId:t.at,website:e.y})}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the login window. Please click 'Try again' to open the login window or change your browser settings.`,rejectedMessage:`Login request was cancelled.`,defaultMessage:`There was an unexpected issue logging in with VeChain. Please try again or contact support.`})}}}},Uo=`vechain-kit-app-hub-apps`,Wo=`vechain-kit-app-hub-apps-expiry`,Go=1440*60*1e3,Ko=()=>[`VECHAIN_KIT`,`appHub`,`apps`],qo=async()=>{if(typeof window<`u`)try{let e=t.dt(Uo),n=t.dt(Wo);if(e&&n){let t=parseInt(n,10);if(Date.now()<t)return JSON.parse(e)}}catch{console.warn(`Invalid app-hub cache, fetching fresh data`)}let n=new URL(`contents/apps`,e.a),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch app directories`);let i=(await r.json()).map(async t=>{if(t.type!==`dir`)return null;let n=new URL(`master/apps/${t.name}/manifest.json`,e.o),r=await fetch(n);if(!r.ok)return console.warn(`Failed to fetch manifest for ${t.name}`),null;try{let n=await r.json(),i=new URL(`master/apps/${t.name}/logo.png`,e.o);return{id:t.name,name:n.name,description:n.desc,url:n.href,logo:i.toString(),category:n.category,tags:n.tags||[],isVeWorldSupported:n.isVeWorldSupported||!1,repo:n.repo,contracts:n.contracts,veBetterDaoId:n.veBetterDaoId}}catch(e){return console.warn(`Error parsing manifest for ${t.name}:`,e),null}}),a=(await Promise.all(i)).filter(e=>e!==null);if(typeof window<`u`)try{t.yt(Uo,JSON.stringify(a)),t.yt(Wo,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return a},Jo=()=>(0,p.useQuery)({queryKey:Ko(),queryFn:async()=>{try{return await qo()}catch(e){let t=localStorage.getItem(Uo);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),Yo=({abi:e,address:t,method:n})=>[`callClause`,t,n],Xo=e=>e.map(e=>typeof e==`bigint`?e.toString():Array.isArray(e)?Xo(e):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,typeof t==`bigint`?t.toString():t])):e),Zo=({abi:e,address:t,method:n,args:r})=>[`callClause`,t,n,...r?.length?Xo(r):[]],Qo=({address:e,abi:n,method:r,args:i,queryOptions:a})=>{let o=(0,f.useThor)();return(0,p.useQuery)({queryKey:Zo({abi:n,address:e,method:r,args:i}),queryFn:async()=>t.n({thor:o,contractAddress:e,abi:n,method:r,args:i}),...a})},$o=({thor:e,calls:n,queryKey:r,enabled:i=!0})=>(0,p.useQuery)({queryKey:r,queryFn:()=>t.r({thor:e,calls:n}),enabled:i}),es=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},ts=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},ns=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.dt(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t.yt(i,`true`),n(!1)}}},rs=()=>{let{network:e}=$();return e.nodeUrl??t.bt(e.type).nodeUrl},is=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.mt()){n(!1);return}let e=()=>{n(window.matchMedia(`(display-mode: standalone)`).matches||window.standalone||document.referrer.includes(`android-app://`))};return e(),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[]),e},as=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},os=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,b.formatEther)(BigInt(n.balance)).toString(),energy:(0,b.formatEther)(BigInt(n.energy)).toString()}},ss=e=>[`VECHAIN_KIT_BALANCE`,e],cs=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:ss(e),queryFn:()=>os(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},ls=async(e,n,r)=>{if(!r)throw Error(`Network type is required`);if(!n)throw Error(`Version is required`);let i=e.contracts.load(t.bt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi),a;switch(n){case 1:case 2:a=i.read.accountImplementationV1();break;case 3:a=i.read.accountImplementationV3();break;default:throw Error(`Invalid version, must be between 1 and 3`)}let o=await a;if(!o)throw Error(`Failed to get account implementation address`);return o[0].toString()},us=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],ds=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:us(e,n.type),queryFn:async()=>ls(t,e,n.type),enabled:!!t&&!!e&&!!n})},fs=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.bt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},ps=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],ms=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:ps(t.type),queryFn:async()=>fs(e,t.type),enabled:!!e&&!!t})},hs=async(e,n,r)=>{if(!n)throw Error(`Owner address is required`);if(!r)throw Error(`Network type is required`);let i=await e.contracts.load(t.bt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},gs=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],_s=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:gs(e,n.type),queryFn:async()=>hs(t,e,n.type),enabled:!!t&&!!e&&!!n})},vs=y.SocialLoginSmartAccountFactory__factory.abi,ys=(e,n,r)=>Zo({abi:vs,address:t.bt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),bs=(e,n)=>{let{network:r}=$();return Qo({address:t.bt(r.type).accountFactoryAddress,abi:vs,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]})}})},xs=y.SocialLoginSmartAccountFactory__factory.abi,Ss=`hasLegacyAccount`,Cs=async(e,n,r)=>{if(!n)throw Error(`Owner address is required`);if(!r)throw Error(`Network type is required`);let[i]=await t.n({thor:e,abi:xs,contractAddress:t.bt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},ws=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],Ts=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ws(e,n.type),queryFn:async()=>Cs(t,e,n.type),enabled:!!t&&!!e&&!!n})},Es=async(e,t)=>{if(!t)throw Error(`Account address is required`);let n=await e.accounts.getAccount(s.Address.of(String(t)));if(!n)throw Error(`Account not found`);return n.hasCode},Ds=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Os=e=>{let t=rs(),n=L.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ds(e),queryFn:async()=>Es(n,e),enabled:!!n&&!!e})},ks=()=>{let e=(0,p.useQueryClient)(),{connectedWallet:t,smartAccount:n}=X(),{network:r}=$();return{refresh:async()=>{let i=t?.address??``,a=n?.address??``;await Promise.all([e.cancelQueries({queryKey:gs(i,r.type)}),e.cancelQueries({queryKey:ys(a,i,r.type)}),e.cancelQueries({queryKey:ws(i,r.type)}),e.cancelQueries({queryKey:ps(r.type)}),e.cancelQueries({queryKey:Fs(a,i,3,r.type)}),e.cancelQueries({queryKey:Rs(a,3,r.type)}),e.cancelQueries({queryKey:us(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:gs(i,r.type)}),e.refetchQueries({queryKey:ys(a,i,r.type)}),e.refetchQueries({queryKey:ws(i,r.type)}),e.refetchQueries({queryKey:ps(r.type)}),e.refetchQueries({queryKey:Fs(a,i,3,r.type)}),e.refetchQueries({queryKey:Rs(a,3,r.type)}),e.refetchQueries({queryKey:us(3,r.type)})])}}},As=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Ms(n)}),e.cancelQueries({queryKey:Ds(n)})]),await Promise.all([e.refetchQueries({queryKey:Ms(n)}),e.refetchQueries({queryKey:Ds(n)})])}}},js=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.bt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(r);if(!i)throw Error(`Failed to get account address of ${r}`);let a=s.Address.of(i[0].toString()),o=await e.accounts.getAccount(a);if(!o)throw Error(`Failed to get account detail of ${a}`);return{address:a.toString(),isDeployed:o.hasCode}},Ms=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Ns=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ms(e),queryFn:()=>js(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},Ps=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.bt(a).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.bt(a).accountFactoryAddress}`);return o[0]},Fs=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],Is=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:Fs(e,t,n,i.type),queryFn:async()=>Ps(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},Ls=async(e,n,r,i)=>{let a=await e.contracts.load(t.bt(i).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},Rs=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],zs=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:Rs(e,t,r.type),queryFn:async()=>Ls(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},Bs=y.SocialLoginSmartAccount__factory.createInterface(),Vs=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=ks(),{refresh:s}=As(),{data:c}=ds(n),l=(0,r.useCallback)(async()=>{if(!e||!t.j(e))throw Error(`Invalid smart account address`);if(!c)throw Error(`Unable to fetch implementation address for version ${n}`);return[{to:e,value:`0x0`,data:Bs.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:Bs.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=$n({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.W(e)} to version ${n}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{await Promise.all([o(),s()]),i?.()},onTxFailedOrCancelled:async()=>{a?.()}});return{...u,sendTransaction:async()=>u.sendTransaction(await l())}},Hs=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],Us=10*t.s.SECOND,Ws=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Hs(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:Us})},Gs=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},Ks=()=>[`VECHAIN_KIT_CHAIN_ID`],qs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ks(),queryFn:()=>Gs(e),enabled:!!e})},Js=1e3,Ys=async({thor:e,order:t=`asc`,offset:n=0,limit:r=Js,from:i=0,to:a=e.blocks.getHeadBlock()?.number,filterCriteria:o})=>{let s=await e.logs.filterEventLogs({range:{from:i,to:a,unit:`block`},options:{offset:n,limit:r},order:t,criteriaSet:o});if(!s)throw Error(`Failed to fetch events`);return s},Xs=async({nodeUrl:e,thor:t,order:n=`asc`,from:r=0,to:i,filterCriteria:a})=>{let o=[],s=0;for(;;){let c=await Ys({nodeUrl:e,thor:t,filterCriteria:a,from:r,to:i??2**53-1,limit:Js,order:n,offset:s});if(o.push(...c),c.length<Js)return o;s+=Js}},Zs=y.IERC20__factory.createInterface(),Qs=(e,n,r,i)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);let a=[];return a.push({to:r,value:`0x0`,data:Zs.encodeFunctionData(`transfer`,[e,(0,b.parseEther)(n)]),comment:`Transfer ${n} ${i} to ${e}`,abi:Zs.getFunction(`transfer`)}),a},$s=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,onSuccess:s,onError:c})=>{let{refresh:l}=Pn(),u=(0,r.useMemo)(()=>Qs(n,i,a,o),[n,i,a,o]),d=$n({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{l(),s?.()},onTxFailedOrCancelled:async e=>{c?.(e instanceof Error?e.message:String(e))}});return{...d,clauses:u,sendTransaction:async()=>d.sendTransaction(u)}},ec=(e,n)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);if(isNaN(Number(n)))throw Error(`Invalid amount`);let r=[];try{r.push({to:e,value:(0,b.parseEther)(n).toString(),data:`0x`,comment:`Transfer ${n} VET to ${e}`})}catch(e){throw console.error(`Error building clauses:`,e),Error(`Invalid amount format`)}return r},tc=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=Pn(),c=(0,r.useMemo)(()=>ec(n,i),[n,i]),l=$n({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{s(),a?.()},onTxFailedOrCancelled:async e=>{o?.(e instanceof Error?e.message:String(e))}});return{...l,clauses:c,sendTransaction:async()=>l.sendTransaction(c)}},nc=({clauseBuilder:e,refetchQueryKeys:t,invalidateCache:n=!0,onSuccess:i,onFailure:a,suggestedMaxGas:o,gasPadding:s,delegationUrl:c})=>{let{account:l}=X(),u=(0,p.useQueryClient)(),d=(0,r.useCallback)(async()=>{n&&t?.forEach(async e=>{await u.cancelQueries({queryKey:e}),await u.refetchQueries({queryKey:e})}),i?.()},[n,i,u,t]),f=$n({signerAccountAddress:l?.address,onTxConfirmed:d,suggestedMaxGas:o,onTxFailedOrCancelled:a,gasPadding:s,delegationUrl:c}),m=(0,r.useCallback)(async t=>{f.sendTransaction(e(t),c)},[e,f,c]);return{...f,sendTransaction:m}},rc=10*t.s.SECOND,ic=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],ac=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:ic(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*rc,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},oc=(e,t)=>{let n=(0,b.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},sc=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],cc=({abi:e,contractAddress:t,eventName:n,filterParams:i,mapResponse:a,nodeUrl:o})=>{let s=(0,f.useThor)();return(0,p.useQuery)({queryFn:(0,r.useCallback)(async()=>{if(!s)return[];let r=s.contracts.load(t,e).getEventAbi(n),c=r.encodeFilterTopicsNoNull(i??{}),l=(await Xs({thor:s,nodeUrl:o,filterCriteria:[{criteria:{address:t,topic0:c[0]??void 0,topic1:c[1]??void 0,topic2:c[2]??void 0,topic3:c[3]??void 0,topic4:c[4]??void 0},eventAbi:r}]})).map(t=>oc(t,e));if(l.some(({decodedData:e})=>e.eventName!==n))throw Error(`Unknown event`);return l.map(e=>a({meta:e.meta,decodedData:e.decodedData}))},[s,t,e,n,i,a,o]),queryKey:(0,r.useMemo)(()=>sc({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function lc({clauses:e,chainId:t,verifyingContract:n}){let r=[],i=[],a=[];return e.forEach(e=>{r.push(e.to??``),i.push(String(e.value)),typeof e.data==`object`&&`abi`in e.data?a.push((0,b.encodeFunctionData)(e.data)):a.push(e.data||`0x`)}),{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n},types:{ExecuteBatchWithAuthorization:[{name:`to`,type:`address[]`},{name:`value`,type:`uint256[]`},{name:`data`,type:`bytes[]`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`},{name:`nonce`,type:`bytes32`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteBatchWithAuthorization`,message:{to:r,value:i,data:a,validAfter:0,validBefore:Math.floor(Date.now()/1e3)+300,nonce:o.ethers.hexlify(o.ethers.randomBytes(32))}}}function uc({clause:e,chainId:t,smartAccount:n}){return{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n.address??``},types:{ExecuteWithAuthorization:[{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`data`,type:`bytes`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteWithAuthorization`,message:{validAfter:0,validBefore:Math.floor(Date.now()/1e3)+60,to:e.to,value:String(e.value),data:(typeof e.data==`object`&&`abi`in e.data?(0,b.encodeFunctionData)(e.data):e.data)||`0x`}}}function dc(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=jn(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=qs();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const fc=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=dc(),c=async e=>{let{version:t}=e;return t&&t<3?await l(e):await u(e)};async function l(c){let{clauses:l,smartAccount:u,title:d=`Sign Transaction`,description:f,buttonText:p=`Sign`}=c,m=[],h=l.map(e=>uc({clause:e,chainId:o,smartAccount:u})),g=[];for(let t=0;t<h.length;t++){let a=h[t],o=l[t];if(!o)throw Error(`Transaction clause at index ${t} is undefined`);if(e.isConnectedWithCrossApp){let e=await r({...a,address:n?.address,types:Object.fromEntries(Object.entries(a.types).map(([e,t])=>[e,[...t]]))});g.push(e);continue}let s=o.data,c=(await i(a,{uiOptions:{title:d,description:f??(l[t].comment||(typeof s==`object`&&s&&`functionName`in s?s.functionName:` `)),buttonText:p}})).signature;g.push(c)}return u.isDeployed||m.push(s.Clause.callFunction(s.Address.of(t.bt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeWithAuthorization`),[e.message.to,BigInt(e.message.value),e.message.data,BigInt(e.message.validAfter),BigInt(e.message.validBefore),g[t]]))}),m}async function u(c){let{clauses:l,smartAccount:u,title:d,description:f,buttonText:p=`Sign`}=c,m=[],h=lc({clauses:l,chainId:o,verifyingContract:u.address??``}),g;return g=e.isConnectedWithCrossApp?await r({...h,address:n?.address}):(await i(h,{uiOptions:{title:d,description:f,buttonText:p}})).signature,u.isDeployed||m.push(s.Clause.callFunction(s.Address.of(t.bt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeBatchWithAuthorization`),[h.message.to,h.message.value?.map(e=>BigInt(e))??0,h.message.data,BigInt(h.message.validAfter),BigInt(h.message.validBefore),h.message.nonce,g])),m}return{buildClausesWithAuth:c}};let pc=function(e){return e.CUSTOM_TOKENS=`vechain_kit_custom_tokens`,e.ECOSYSTEM_SHORTCUTS=`vechain-kit-ecosystem-shortcuts`,e.CURRENCY=`vechain_kit_currency`,e.NODE_URL=`vechain_kit_node_url`,e.NETWORK=`vechain_kit_network`,e.GAS_TOKEN_PREFERENCES=`vechain_kit_gas_token_preferences`,e.SHOW_ASSETS=`vechain_kit_show_assets`,e}({});const mc=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.dt(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t.yt(e,JSON.stringify(i))},[e,i]),[i,a]},hc=`vechain-kit-storage-change`,gc=(e,t)=>{let[n,i]=(0,r.useState)(()=>{if(typeof window>`u`)return t;try{let n=window.localStorage.getItem(e);return n?JSON.parse(n):t}catch(e){return console.error(`Error loading from localStorage:`,e),t}}),a=(0,r.useRef)(!1);return(0,r.useEffect)(()=>{if(!(typeof window>`u`)){if(a.current){a.current=!1;return}try{window.localStorage.setItem(e,JSON.stringify(n)),window.dispatchEvent(new CustomEvent(hc,{detail:{key:e,value:n}}))}catch(e){console.error(`Error writing to localStorage:`,e)}}},[e,n]),(0,r.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(t.key===e&&t.newValue)try{let e=JSON.parse(t.newValue);JSON.stringify(e)!==JSON.stringify(n)&&(a.current=!0,i(e))}catch(e){console.error(`Error parsing storage value:`,e)}},r=(t=>{if(t.detail.key===e)try{let t=window.localStorage.getItem(e);if(t){let e=JSON.parse(t);JSON.stringify(e)!==JSON.stringify(n)&&(a.current=!0,i(e))}}catch(e){console.error(`Error parsing storage value:`,e)}});return window.addEventListener(`storage`,t),window.addEventListener(hc,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(hc,r)}},[e,n]),[n,i,(0,r.useCallback)(()=>{if(!(typeof window>`u`))try{let r=window.localStorage.getItem(e),a=r?JSON.parse(r):t;JSON.stringify(a)!==JSON.stringify(n)&&i(a)}catch(e){console.error(`Error syncing localStorage:`,e)}},[e,t,n]),(0,r.useCallback)(()=>{if(typeof window>`u`)return t;let n=window.localStorage.getItem(e);return n?JSON.parse(n):t},[e,t])]},_c=()=>{let[e,t]=mc(pc.ECOSYSTEM_SHORTCUTS,[]);return{shortcuts:e,addShortcut:n=>{e.some(e=>e.url===n.url)||t([...e,n])},removeShortcut:n=>{t(e.filter(e=>e.url!==n))},isShortcut:t=>e.some(e=>e.url===t)}},vc=async(e,t,n,r,i)=>{let a=new URL(`estimate/clauses/${r.toLowerCase()}`,t);return a.searchParams.set(`type`,`smartaccount`),a.searchParams.set(`speed`,i),await(await fetch(a,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json()},yc=async e=>{let t=new URL(`deposit/account`,e);return await(await fetch(t,{method:`GET`,headers:{"Content-Type":`application/json`}})).json()},bc=async(e,t,n,r)=>{let i=new URL(`sign/transaction/authorized/${n.toLowerCase()}`,r);return await(await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json()},xc=async(e,t,n,r)=>{let i=await t.gas.estimateGas(e,n?.address??``),a=Math.max(i.totalGas,0);return await t.transactions.buildTransactionBody(e,a,{isDelegated:r})};function Sc(e,t){return s.Transaction.of(e.body,R.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function Cc(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const wc=()=>{let{connectedWallet:e}=X(),{data:n}=Ns(e?.address??``),{data:i}=bs(n?.address??``,e?.address??``),{preferences:a}=Tc(),o=y.IERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=fc(),u=L.ThorClient.at(t.bt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await vc(n?.address??``,r,e,c,`medium`),f=await yc(r),p={to:c===`VET`?f.depositAccount:t.Q[c].address,value:c===`VET`?(0,b.parseEther)(d.transactionCost?.toString()??`0`).toString():`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,(0,b.parseEther)(d.transactionCost?.toString()??`0`)]),comment:`Transfer ${d.transactionCost} ${c} to ${f.depositAccount}`,abi:c===`VET`?void 0:o.getFunction(`transfer`)},m=await l({clauses:[...e,p],smartAccount:n,version:i?.version??0}),h=await xc(m,u,t.V,!0),g=await s.Transaction.of(h).signAsSender(s.HexUInt.of(t.V.privateKey).bytes),_=await bc(s.HexUInt.of(g.encoded).toString(),t.V.address,c,r),v=Sc(g,_.signature),y={clauses:m,simulateTransactionOptions:{caller:t.V.address??``,gasPayer:_.address}},x=await u.transactions.simulateTransaction(y.clauses,{...y.simulateTransactionOptions});for(let e=0;e<x.length;e++)if(x[e].reverted)throw Error(x[e].vmError);return(await u.transactions.sendTransaction(v)).id}catch(e){console.error(`Error sending transaction using generic delegator`,e)}throw Error(`Failed to send transaction using generic delegator, no gas tokens have sufficient balance or are enabled in Gas Token Preferences`)},[a,n,i,l,u,t.V])}},Tc=()=>{let[e,n]=gc(pc.GAS_TOKEN_PREFERENCES,t.J);return{preferences:e,supportedTokens:t.Q,updatePreferences:(0,r.useCallback)(e=>{n(t=>({...t,...e}))},[n]),reorderTokenPriority:(0,r.useCallback)(e=>{n(t=>{let n=e.filter(e=>t.availableGasTokens.includes(e)&&!t.excludedTokens.includes(e));return{...t,tokenPriority:e,availableGasTokens:n,gasTokenToUse:n[0]??t.gasTokenToUse}})},[n]),toggleTokenExclusion:(0,r.useCallback)(e=>{n(t=>{let n=t.excludedTokens.includes(e),r=n?t.excludedTokens.filter(t=>t!==e):[...t.excludedTokens,e],i=t.tokenPriority.indexOf(e),a=n?[...t.availableGasTokens.slice(0,i),e,...t.availableGasTokens.slice(i)]:t.availableGasTokens.filter(t=>t!==e);return{...t,excludedTokens:r,availableGasTokens:a,gasTokenToUse:a[0]??t.gasTokenToUse}})},[n])}},Ec=({clauses:e,enabled:t=!0,tokens:n,sendingAmount:r,sendingTokenSymbol:i})=>{let{connectedWallet:a,account:o}=X(),{data:s}=Ns(a?.address??``),{feeDelegation:c}=$(),{balances:l}=zt(o?.address??``),{updatePreferences:u}=Tc();return(0,p.useQuery)({queryKey:[`gas-estimation`,JSON.stringify(e),JSON.stringify(n),r,i],queryFn:async()=>{let t=null;for(let a of n)try{let n=await vc(s?.address??``,c?.genericDelegatorUrl??``,e,a,`medium`),o=n.transactionCost,d=Number(l.find(e=>e.symbol===a)?.balance||0),f=o+(r&&i&&a===i?Number(r):0);if(d>=f)return u({gasTokenToUse:a}),{...n,usedToken:a};t=Error(`Insufficient ${a} balance: has ${d}, needs ${f}`)}catch(e){t=e}throw t||Error(`All gas tokens failed estimation or have insufficient balance`)},enabled:t&&e.length>0&&!!s?.address&&!!c?.genericDelegatorUrl&&n.length>0&&l.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1,retry:!1,retryDelay:1e3})},Dc=({clauses:e,tokens:t,enabled:n=!0})=>{let{connectedWallet:r}=X(),{data:i}=Ns(r?.address??``),{feeDelegation:a}=$();return(0,p.useQuery)({queryKey:[`gas-estimation-all-tokens`,JSON.stringify(e),JSON.stringify(t)],queryFn:async()=>{let n={};return await Promise.all(t.map(async t=>{try{n[t]={cost:(await vc(i?.address??``,a?.genericDelegatorUrl??``,e,t,`medium`)).transactionCost||0,loading:!1}}catch(e){n[t]={cost:0,loading:!1,error:e instanceof Error?e.message:`Unknown error`}}})),n},enabled:n&&e.length>0&&!!i?.address&&!!a?.genericDelegatorUrl&&t.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},Oc=({symbol:e,amount:a,currencyValue:o,currentCurrency:s,isDisabled:c,onClick:l,...u})=>{let d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[p]=mc(pc.SHOW_ASSETS,!0);return(0,i.jsxs)(n.Button,{height:`72px`,variant:`ghost`,justifyContent:`space-between`,isDisabled:c,p:4,w:`100%`,_disabled:{cursor:`not-allowed`,opacity:.5},onClick:l,"data-testid":`asset-${e}`,...u,children:[(0,i.jsxs)(n.HStack,{children:[t.et[e]?r.default.cloneElement(t.et[e],{boxSize:`24px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[e],alt:`${e} logo`,boxSize:`24px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`24px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`10px`,fontWeight:`bold`,color:d,children:e.slice(0,3)})})}),(0,i.jsx)(n.Text,{color:d,children:e})]}),(0,i.jsxs)(n.VStack,{align:`flex-end`,spacing:0,children:[(0,i.jsxs)(n.Text,{color:d,children:[p?a.toLocaleString(void 0,{maximumFractionDigits:2}):`*`.repeat(4),` `]}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:f,"data-testid":`${e}-balance`,children:p?qt(o,{currency:s}):`*`.repeat(4)})]})]})},kc=({address:e,domain:a,imageSrc:o,imageAlt:s=`Account`,hideAddress:c=!1,balance:u,tokenAddress:d})=>{let{t:f}=(0,l.useTranslation)(),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:g}=Qt({address:e}),{tokens:_,isLoading:v}=Zt({address:e}),y=(0,r.useMemo)(()=>d?_.find(e=>e.address===d):null,[_,d]),b=(0,r.useMemo)(()=>u===void 0?y?Number(y.balance):0:u,[u,y]),x=y?.symbol||``;return g||v?(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!c&&(0,i.jsx)(n.Skeleton,{mt:2,height:`12px`,width:`100px`,borderRadius:`md`})]})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]}):(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:o,alt:s,boxSize:`40px`,borderRadius:`full`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:a?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:a}),!c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:m,children:t.W(e,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:t.W(e,6,4)})})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:m,children:[b.toLocaleString(void 0,{maximumFractionDigits:2}),x&&` ${x}`]})]})]})},Ac=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`FAQ`,icon:(0,i.jsx)(n.Icon,{as:g.LuCircleHelp,fontSize:`17px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,lineHeight:`normal`,left:`10px`,top:`8px`,onClick:e,...t}),jc=({children:e,...t})=>(as(),(0,i.jsx)(n.VStack,{...t,children:e})),Mc=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image),o=(0,r.useRef)(e?.address);return(0,r.useEffect)(()=>{o.current!==e?.address&&(a.current=e?.image,o.current=e?.address)},[e?.address]),(0,r.useEffect)(()=>{e?.image&&!e.isLoadingMetadata&&(a.current=e.image)},[e?.image,e?.isLoadingMetadata]),!t?.src&&!e?.image&&!a.current||e?.isLoadingMetadata?(0,i.jsx)(n.Skeleton,{rounded:`full`,width:t?.width,height:t?.height}):(0,i.jsx)(n.Image,{src:t?.src||e?.image||a.current,alt:t?.alt||e?.domain,objectFit:`cover`,rounded:`full`,...t})},Nc=({transactionError:e,isSubmitting:a,isTxWaitingConfirmation:o,onConfirm:s,onRetry:c,transactionPendingText:u,txReceipt:d,isSubmitForm:f=!1,buttonText:p,isDisabled:m=!1,style:h,onError:g,gasEstimationError:_,hasEnoughGasBalance:v=!0,isLoadingGasEstimation:y=!1,showGasEstimationError:b=!1,context:x=`transaction`})=>{let{t:S}=(0,l.useTranslation)(),{darkMode:C}=$(),{network:w}=$(),T=(0,r.useMemo)(()=>e?e.reason||S(`Something went wrong. Please try again.`):null,[e,S]);(0,r.useEffect)(()=>{T&&g?.(T)},[T,g]);let E=(0,r.useMemo)(()=>{if(h?.accentColor)return`${h.accentColor} !important`},[h?.accentColor]),D=(0,r.useMemo)(()=>{if(!b||y||!(_||v))return null;if(!v&&!_)return{message:S(`You don't have any gas tokens enabled. Please enable at least one gas token in Gas Token Preferences.`)};if(_){let e=``;switch(x){case`send`:e=S(`Insufficient balance to complete this transfer and cover gas fees.`);break;case`customization`:e=S(`Insufficient balance to update your profile and cover gas fees.`);break;case`domain`:e=S(`Insufficient balance to claim this domain and cover gas fees.`);break;default:e=S(`Insufficient balance to complete this transaction and cover gas fees.`)}return{message:e}}return null},[_,v,y,b,x,S]);return(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[T&&(0,i.jsx)(n.Box,{p:3,borderRadius:`md`,bg:C?`rgba(218, 90, 90, 0.1)`:`rgba(218, 90, 90, 0.05)`,borderWidth:`1px`,borderColor:C?`rgba(218, 90, 90, 0.3)`:`rgba(218, 90, 90, 0.2)`,w:`full`,children:(0,i.jsx)(n.Text,{color:`#da5a5a`,fontSize:`sm`,fontWeight:`medium`,"data-testid":`tx-send-error-msg`,children:T})}),D&&!T&&(0,i.jsx)(n.Box,{p:3,borderRadius:`md`,bg:C?`rgba(218, 90, 90, 0.1)`:`rgba(218, 90, 90, 0.05)`,borderWidth:`1px`,borderColor:C?`rgba(218, 90, 90, 0.3)`:`rgba(218, 90, 90, 0.2)`,w:`full`,children:(0,i.jsx)(n.Text,{color:`#da5a5a`,fontSize:`sm`,fontWeight:`medium`,"data-testid":`gas-estimation-error`,children:D.message})}),(0,i.jsx)(n.Button,{px:4,variant:T?`vechainKitSecondary`:`vechainKitPrimary`,bg:E,onClick:()=>T&&c?c():s(),type:f?`submit`:`button`,isLoading:a,isDisabled:m,loadingText:o?S(`Waiting wallet confirmation...`):u,"data-testid":`confirm-button`,children:T?S(`Retry`):p||S(`Confirm`)}),T&&d?.meta.txID&&(0,i.jsx)(n.Link,{isExternal:!0,fontSize:`sm`,color:C?`whiteAlpha.600`:`blackAlpha.600`,textAlign:`center`,width:`full`,href:`${t.bt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},Pc=({onClick:e,hasUnreadNotifications:t,...r})=>(0,i.jsx)(n.IconButton,{"aria-label":`Notifications`,size:`sm`,variant:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,icon:(0,i.jsxs)(n.Box,{position:`relative`,children:[(0,i.jsx)(g.LuBell,{fontSize:`20px`}),t&&(0,i.jsx)(n.Box,{position:`absolute`,top:`-1px`,right:`-1px`,minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`})]}),...r}),Fc=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{balances:p}=zt(d),[m,h]=r.default.useState(o),[g,_]=r.default.useState(!1),v=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),y=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=e=>e?b:`transparent`,C=e=>e?v:`transparent`;r.default.useEffect(()=>{e&&(h(o),_(!1))},[e,o]);let w=()=>{s(m,g),a()},T=e=>{let t=p.find(t=>t.symbol===e);return t?Number(t.balance).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):`0.00`},E=e=>{let t=p.find(t=>t.symbol===e),n=u[e];return!t||!n?!1:Number(t.balance)<n.cost};return(0,i.jsxs)(Re,{isOpen:e,onClose:a,size:`sm`,children:[(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:v,children:f(`Fee token`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`normal`,color:y,mt:1,children:f(`Select the token to pay the fee with`)})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,children:[c.map(e=>{let a=t.Q[e],o=m===e,s=u[e]||{cost:0,loading:!0},c=E(e);return(0,i.jsx)(n.Box,{cursor:c?`not-allowed`:`pointer`,bg:S(o),border:`1px`,borderColor:C(o),borderRadius:`md`,p:3,transition:`all 0.2s ease`,_hover:{backgroundColor:c?S(o):y&&`#ffffff12`,borderColor:c?C(o):y},opacity:c?.5:1,onClick:()=>!c&&h(e),children:(0,i.jsxs)(n.HStack,{spacing:3,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,children:[r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:v,children:a.symbol}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:y,children:[f(`Balance`),`:`,` `,T(e)]}),c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:x,children:f(`Insufficient balance`)})]})]}),(0,i.jsx)(n.VStack,{align:`end`,spacing:0,children:s.loading?(0,i.jsx)(n.Skeleton,{height:`16px`,width:`60px`}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,color:v,children:t.x(s.cost,2)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:y,children:a.symbol})]})})]})},e)}),m!==o&&(0,i.jsxs)(n.FormControl,{display:`flex`,alignItems:`center`,justifyContent:`space-between`,children:[(0,i.jsx)(n.FormLabel,{htmlFor:`remember-choice`,mb:`0`,fontSize:`sm`,color:v,children:f(`Use this token for future transactions`)}),(0,i.jsx)(n.Switch,{id:`remember-choice`,isChecked:g,onChange:e=>_(e.target.checked),color:v})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:w,isDisabled:E(m),children:f(`Apply`)}),(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:a,children:f(`Cancel`)})]})})]})},Ic=({estimation:e,isLoading:a,isLoadingTransaction:o,onTokenChange:s,clauses:c=[],userSelectedToken:u})=>{let{t:d}=(0,l.useTranslation)(),{feeDelegation:f}=$(),{connection:p,account:m}=X(),{preferences:h,reorderTokenPriority:_}=Tc(),{isOpen:v,onOpen:y,onClose:b}=(0,n.useDisclosure)(),x=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),S=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[C,w]=(0,r.useState)(()=>{let e={};return h.availableGasTokens.forEach(t=>{e[t]={cost:0,loading:!0}}),e}),{data:T,isLoading:E}=Dc({clauses:c,tokens:h.availableGasTokens,enabled:c.length>0});(0,r.useEffect)(()=>{!E&&T&&w(T)},[T,E]),(0,r.useEffect)(()=>{e&&w(t=>({...t,[e.usedToken]:{cost:e.transactionCost||0,loading:!1}}))},[e]),(0,r.useEffect)(()=>{E&&w(h.availableGasTokens.reduce((e,t)=>(e[t]={cost:0,loading:!0},e),{}))},[E,h.availableGasTokens]);let D=(0,r.useCallback)((t,n)=>{n&&_([t,...h.tokenPriority.filter(e=>e!==t)]),s&&t!==e?.usedToken&&s(t)},[e,s,_,h.tokenPriority]);if(f?.delegatorUrl||p.isConnectedWithDappKit||h.availableGasTokens.length===0)return null;let{balances:O}=zt(m?.address??``),k=e=>{let t=O.find(t=>t.symbol===e),n=C[e];return!t||!n||n.loading?!0:Number(t.balance)<n.cost},A=e?.usedToken,j=h.availableGasTokens,M;A?M=A:u&&j.includes(u)?M=u:(M=j.find(e=>C[e]&&!C[e].loading&&!k(e)),M||=j.find(e=>C[e]&&!C[e].loading),M||=j[0]);let N=M?C[M]:void 0,P=A&&e?.transactionCost?e.transactionCost:N?.cost||0,F=M?t.Q[M]:void 0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Divider,{mt:3}),(0,i.jsxs)(n.HStack,{mt:3,w:`full`,justifyContent:`start`,alignItems:`center`,children:[(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`light`,textAlign:`left`,w:`full`,color:S,children:d(`Fee`)}),(0,i.jsx)(n.HStack,{align:`start`,justifyContent:`space-between`,spacing:0,w:`full`,children:(0,i.jsx)(n.HStack,{justifyContent:`flex-start`,w:`full`,children:a||!A&&(!N||N.loading)||!F?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),(0,i.jsx)(n.Skeleton,{height:`16px`,width:`60px`,borderRadius:`md`})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.Text,{color:x,fontSize:`sm`,fontWeight:`semibold`,children:[t.x(P,2),` `,F.symbol]}),(0,i.jsxs)(n.Text,{color:S,fontSize:`xs`,children:[`≈`,` $`,(P*.01).toFixed(2)]})]})})})]}),(0,i.jsxs)(n.Button,{onClick:y,variant:`outline`,size:`sm`,borderRadius:`full`,px:6,disabled:o,color:S,borderColor:S,_hover:{bg:S},leftIcon:r.default.cloneElement(t.et[M||h.availableGasTokens[0]],{boxSize:`20px`,borderRadius:`full`}),children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,children:M||h.availableGasTokens[0]}),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:S})]})]}),(0,i.jsx)(Fc,{isOpen:v,onClose:b,selectedToken:M||h.availableGasTokens[0],onTokenSelect:D,availableTokens:h.availableGasTokens,tokenEstimations:C,walletAddress:m?.address??``})]})},Lc=P.keyframes`
200
+ `}),Ja=({children:e,theme:t,bodyFont:a,headingFont:o})=>(0,i.jsxs)(P.CacheProvider,{value:(0,r.useMemo)(()=>Ka(),[]),children:[(0,i.jsx)(qa,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,children:e})]}),Ya=({darkMode:e})=>{try{if(t._t(`[data-chakra-color-mode]`))return null}catch(e){console.error(e)}return(0,i.jsx)(n.ColorModeScript,{initialColorMode:e?`dark`:`light`})},Xa=(0,r.createContext)({portalRootRef:void 0,tokens:void 0,themeConfig:void 0}),Za=()=>{let e=(0,r.useContext)(Xa);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},Qa=({darkMode:e=!1})=>{let{setColorMode:t,colorMode:a}=(0,n.useColorMode)();return(0,r.useEffect)(()=>{let n=e?`dark`:`light`;a!==n&&t(n)},[e]),(0,i.jsx)(i.Fragment,{})},$a=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(il),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>ve(_e(t),ye(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...Wa(t,l),config:{...Wa(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]);return(0,i.jsxs)(Xa.Provider,{value:{portalRootRef:o,tokens:u,themeConfig:l},children:[(0,i.jsx)(Ya,{darkMode:t}),(0,i.jsxs)(Ja,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,children:[(0,i.jsx)(Qa,{darkMode:t}),(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})]}),(0,i.jsx)(Ga,{})]})},eo=(0,r.createContext)(null),Q=()=>{let e=(0,r.useContext)(eo);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},to=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),[c,l]=(0,r.useState)(`main`),[u,d]=(0,r.useState)(!1),{setSource:p,connectV2:m}=(0,f.useWallet)(),h=(0,r.useCallback)((e,n)=>{t.mt()&&window.vechain&&window.vechain.isInAppBrowser?(p(`veworld`),m(null)):(l(e??`main`),d(n??!1),s(!0))},[]),g=(0,r.useCallback)(()=>{s(!1),l(`main`),d(!1)},[]),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(`main`),C=(0,r.useCallback)((e,t)=>{S(e??`main`),b(t?.isolatedView??!1),v(!0)},[]),w=(0,r.useCallback)(()=>{v(!1),S(`main`),setTimeout(()=>{b(!1)},300)},[]),[T,E]=(0,r.useState)(!1),D=(0,r.useCallback)(()=>E(!0),[]),O=(0,r.useCallback)(()=>E(!1),[]),[k,A]=(0,r.useState)(!1),j=(0,r.useCallback)(()=>A(!0),[]),M=(0,r.useCallback)(()=>A(!1),[]),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(void 0),L=(0,r.useCallback)(e=>{I(e),P(!0)},[]),R=(0,r.useCallback)(()=>P(!1),[]);return(0,i.jsxs)(eo.Provider,{value:{openConnectModal:h,closeConnectModal:g,isConnectModalOpen:o,connectModalContent:c,setConnectModalContent:l,connectModalPreventAutoClose:u,setConnectModalPreventAutoClose:d,openAccountModal:C,closeAccountModal:w,isAccountModalOpen:_,setAccountModalContent:S,accountModalContent:x,isolatedView:y,openTransactionModal:D,closeTransactionModal:O,isTransactionModalOpen:T,openTransactionToast:j,closeTransactionToast:M,isTransactionToastOpen:k,openUpgradeSmartAccountModal:L,closeUpgradeSmartAccountModal:R,isUpgradeSmartAccountModalOpen:N},children:[e,(0,i.jsxs)($a,{darkMode:n,theme:a,children:[(0,i.jsx)(ma,{isOpen:o,onClose:g,initialContent:c,preventAutoClose:u}),(0,i.jsx)(ua,{isOpen:_,onClose:w,initialContent:x}),(0,i.jsx)(Ta,{isOpen:N,onClose:R,style:F})]})]})},no=()=>{let{loginMethods:e}=$(),t=e?.length===1&&e[0].method===`dappkit`,{openConnectModal:n,closeConnectModal:r,isConnectModalOpen:i}=Q(),{open:a,close:o}=(0,f.useWalletModal)();return{open:t?a:e=>n(e),close:t?o:r,isOpen:t?!1:i}},ro=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),io=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:()=>e(),close:t,isOpen:n}},ao=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),oo=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=Q();return{open:e,close:t,isOpen:n}},so=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),co=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=Q();return{open:e,close:t,isOpen:n}},lo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),uo=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=Q();return{open:n=>{e.isConnected?i(void 0,n):t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},fo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),po=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},mo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ho=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`send-token`,props:{setCurrentContent:r}},t)},close:()=>{t()},isOpen:n}},go=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),_o=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},vo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),yo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},bo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},So=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Co=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:t=>{e({type:`faq`,props:{onGoBack:()=>r(`main`),showLanguageSelector:!1}},t)},close:()=>{t()},isOpen:n}},wo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),To=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:()=>{e({type:`account-customization`,props:{setCurrentContent:r}})},close:()=>{t()},isOpen:n}},Eo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Do=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},Oo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ko=()=>{let{privy:e,loginMethods:n}=$(),i=e?.appId===t.at,a=e=>n?Array.isArray(e)?e.some(e=>n.some(t=>t.method===e)):n.some(t=>t.method===e):!0,o=(0,r.useMemo)(()=>n?n.length===0||a(`ecosystem`):!0,[n]),s=(0,r.useMemo)(()=>a(`vechain`),[n]),c=(0,r.useMemo)(()=>a(`dappkit`),[n]),l=(0,r.useMemo)(()=>a(`passkey`),[n]),u=(0,r.useMemo)(()=>a(`email`),[n]),d={showGoogleLogin:(0,r.useMemo)(()=>a(`google`),[n]),showEmailLogin:u,showPasskey:l,showVeChainLogin:s,showDappKit:c,showEcosystem:o,showMoreLogin:(0,r.useMemo)(()=>a(`more`),[n]),showGithubLogin:(0,r.useMemo)(()=>a(`github`),[n]),isOfficialVeChainApp:!1};return e?i?{...d,isOfficialVeChainApp:!0}:{...d}:{...d,showGoogleLogin:!1,showEmailLogin:!1,showPasskey:!1,showMoreLogin:!1}},Ao=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=Q();return{open:()=>t(e),close:n,isOpen:r}},jo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Mo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},No=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Po=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`settings`,t)},close:()=>{t()},isOpen:n}},Fo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Io=()=>{let[e,t]=(0,r.useState)(!1),[n,i]=(0,r.useState)(null),[a,o]=(0,r.useState)(null),{connection:s,account:c}=X(),{requestCertificate:l}=(0,f.useWallet)(),u=rl();return{signMessage:(0,r.useCallback)(async e=>{if(!c)throw Error(`Account not found`);t(!0),o(null),i(null);try{let t=null;return t=s.isConnectedWithDappKit?(await l({purpose:`agreement`,payload:{type:`text`,content:e}},{signer:c.address})).signature:await u.signMessage(e),i(t),t}catch(e){let t=e instanceof Error?e:Error(String(e));throw o(t),t}finally{t(!1)}},[s,u,c?.address]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},Lo=()=>{let[e,t]=(0,r.useState)(!1),[n,i]=(0,r.useState)(null),[a,o]=(0,r.useState)(null),{signer:s}=(0,f.useWallet)(),{connection:c}=X(),l=rl();return{signTypedData:(0,r.useCallback)(async(e,n)=>{t(!0),o(null),i(null);try{let t;if(c.isConnectedWithDappKit){let r={...e.domain,salt:e.domain?.salt?Buffer.from(e.domain.salt).toString(`hex`):void 0};t=await s.signTypedData(r,e.types,e.message,void 0,n)}else t=await l.signTypedData(e);return i(t),t}catch(e){if(e&&typeof e==`object`&&`statusCode`in e&&e.statusCode===4001){let e=Error(`User denied signature request`);throw o(e),e}let t=e instanceof Error?e:Error(typeof e==`object`?JSON.stringify(e):String(e));throw console.error(t),o(t),t}finally{t(!1)}},[c,l]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},Ro=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}};let zo=!1;const Bo=()=>{let{createWallet:e}=(0,u.useCreateWallet)(),{initOAuth:t}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:t})=>{if(t&&!zo){zo=!0;try{await e()}catch(e){throw zo=!1,console.error(`Failed to create wallet:`,e),e}}},[e])});return{initOAuth:async({provider:e})=>{try{await t({provider:e})}catch(e){throw e}}}},Vo=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t.yt(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.dt(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t.gt(e)},[])}},Ho=()=>{let{login:n}=jn(),{setConnectionCache:r}=Vo(),{data:i}=Ve([t.at]);return{login:async()=>{try{await n(t.at),r({name:`VeChain`,logoUrl:i?.[t.at]?.logo_url,appId:t.at,website:e.y})}catch(e){throw Dn({error:e,mobileBrowserPopupMessage:`Your mobile browser blocked the login window. Please click 'Try again' to open the login window or change your browser settings.`,rejectedMessage:`Login request was cancelled.`,defaultMessage:`There was an unexpected issue logging in with VeChain. Please try again or contact support.`})}}}},Uo=`vechain-kit-app-hub-apps`,Wo=`vechain-kit-app-hub-apps-expiry`,Go=1440*60*1e3,Ko=()=>[`VECHAIN_KIT`,`appHub`,`apps`],qo=async()=>{if(typeof window<`u`)try{let e=t.dt(Uo),n=t.dt(Wo);if(e&&n){let t=parseInt(n,10);if(Date.now()<t)return JSON.parse(e)}}catch{console.warn(`Invalid app-hub cache, fetching fresh data`)}let n=new URL(`contents/apps`,e.a),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch app directories`);let i=(await r.json()).map(async t=>{if(t.type!==`dir`)return null;let n=new URL(`master/apps/${t.name}/manifest.json`,e.o),r=await fetch(n);if(!r.ok)return console.warn(`Failed to fetch manifest for ${t.name}`),null;try{let n=await r.json(),i=new URL(`master/apps/${t.name}/logo.png`,e.o);return{id:t.name,name:n.name,description:n.desc,url:n.href,logo:i.toString(),category:n.category,tags:n.tags||[],isVeWorldSupported:n.isVeWorldSupported||!1,repo:n.repo,contracts:n.contracts,veBetterDaoId:n.veBetterDaoId}}catch(e){return console.warn(`Error parsing manifest for ${t.name}:`,e),null}}),a=(await Promise.all(i)).filter(e=>e!==null);if(typeof window<`u`)try{t.yt(Uo,JSON.stringify(a)),t.yt(Wo,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return a},Jo=()=>(0,p.useQuery)({queryKey:Ko(),queryFn:async()=>{try{return await qo()}catch(e){let t=localStorage.getItem(Uo);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),Yo=({abi:e,address:t,method:n})=>[`callClause`,t,n],Xo=e=>e.map(e=>typeof e==`bigint`?e.toString():Array.isArray(e)?Xo(e):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,typeof t==`bigint`?t.toString():t])):e),Zo=({abi:e,address:t,method:n,args:r})=>[`callClause`,t,n,...r?.length?Xo(r):[]],Qo=({address:e,abi:n,method:r,args:i,queryOptions:a})=>{let o=(0,f.useThor)();return(0,p.useQuery)({queryKey:Zo({abi:n,address:e,method:r,args:i}),queryFn:async()=>t.n({thor:o,contractAddress:e,abi:n,method:r,args:i}),...a})},$o=({thor:e,calls:n,queryKey:r,enabled:i=!0})=>(0,p.useQuery)({queryKey:r,queryFn:()=>t.r({thor:e,calls:n}),enabled:i}),es=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},ts=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},ns=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.dt(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t.yt(i,`true`),n(!1)}}},rs=()=>{let{network:e}=$();return e.nodeUrl??t.bt(e.type).nodeUrl},is=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.mt()){n(!1);return}let e=()=>{n(window.matchMedia(`(display-mode: standalone)`).matches||window.standalone||document.referrer.includes(`android-app://`))};return e(),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[]),e},as=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},os=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,b.formatEther)(BigInt(n.balance)).toString(),energy:(0,b.formatEther)(BigInt(n.energy)).toString()}},ss=e=>[`VECHAIN_KIT_BALANCE`,e],cs=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:ss(e),queryFn:()=>os(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},ls=async(e,n,r)=>{if(!r)throw Error(`Network type is required`);if(!n)throw Error(`Version is required`);let i=e.contracts.load(t.bt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi),a;switch(n){case 1:case 2:a=i.read.accountImplementationV1();break;case 3:a=i.read.accountImplementationV3();break;default:throw Error(`Invalid version, must be between 1 and 3`)}let o=await a;if(!o)throw Error(`Failed to get account implementation address`);return o[0].toString()},us=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],ds=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:us(e,n.type),queryFn:async()=>ls(t,e,n.type),enabled:!!t&&!!e&&!!n})},fs=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.bt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},ps=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],ms=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:ps(t.type),queryFn:async()=>fs(e,t.type),enabled:!!e&&!!t})},hs=async(e,n,r)=>{if(!n)throw Error(`Owner address is required`);if(!r)throw Error(`Network type is required`);let i=await e.contracts.load(t.bt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},gs=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],_s=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:gs(e,n.type),queryFn:async()=>hs(t,e,n.type),enabled:!!t&&!!e&&!!n})},vs=y.SocialLoginSmartAccountFactory__factory.abi,ys=(e,n,r)=>Zo({abi:vs,address:t.bt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),bs=(e,n)=>{let{network:r}=$();return Qo({address:t.bt(r.type).accountFactoryAddress,abi:vs,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]}),enabled:!!e&&!!n}})},xs=y.SocialLoginSmartAccountFactory__factory.abi,Ss=`hasLegacyAccount`,Cs=async(e,n,r)=>{if(!n)throw Error(`Owner address is required`);if(!r)throw Error(`Network type is required`);let[i]=await t.n({thor:e,abi:xs,contractAddress:t.bt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},ws=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],Ts=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ws(e,n.type),queryFn:async()=>Cs(t,e,n.type),enabled:!!t&&!!e&&!!n})},Es=async(e,t)=>{if(!t)throw Error(`Account address is required`);let n=await e.accounts.getAccount(s.Address.of(String(t)));if(!n)throw Error(`Account not found`);return n.hasCode},Ds=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Os=e=>{let t=rs(),n=L.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ds(e),queryFn:async()=>Es(n,e),enabled:!!n&&!!e})},ks=()=>{let e=(0,p.useQueryClient)(),{connectedWallet:t,smartAccount:n}=X(),{network:r}=$();return{refresh:async()=>{let i=t?.address??``,a=n?.address??``;await Promise.all([e.cancelQueries({queryKey:gs(i,r.type)}),e.cancelQueries({queryKey:ys(a,i,r.type)}),e.cancelQueries({queryKey:ws(i,r.type)}),e.cancelQueries({queryKey:ps(r.type)}),e.cancelQueries({queryKey:Fs(a,i,3,r.type)}),e.cancelQueries({queryKey:Rs(a,3,r.type)}),e.cancelQueries({queryKey:us(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:gs(i,r.type)}),e.refetchQueries({queryKey:ys(a,i,r.type)}),e.refetchQueries({queryKey:ws(i,r.type)}),e.refetchQueries({queryKey:ps(r.type)}),e.refetchQueries({queryKey:Fs(a,i,3,r.type)}),e.refetchQueries({queryKey:Rs(a,3,r.type)}),e.refetchQueries({queryKey:us(3,r.type)})])}}},As=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Ms(n)}),e.cancelQueries({queryKey:Ds(n)})]),await Promise.all([e.refetchQueries({queryKey:Ms(n)}),e.refetchQueries({queryKey:Ds(n)})])}}},js=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.bt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(r);if(!i)throw Error(`Failed to get account address of ${r}`);let a=s.Address.of(i[0].toString()),o=await e.accounts.getAccount(a);if(!o)throw Error(`Failed to get account detail of ${a}`);return{address:a.toString(),isDeployed:o.hasCode}},Ms=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Ns=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ms(e),queryFn:()=>js(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},Ps=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.bt(a).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.bt(a).accountFactoryAddress}`);return o[0]},Fs=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],Is=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:Fs(e,t,n,i.type),queryFn:async()=>Ps(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},Ls=async(e,n,r,i)=>{let a=await e.contracts.load(t.bt(i).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},Rs=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],zs=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:Rs(e,t,r.type),queryFn:async()=>Ls(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},Bs=y.SocialLoginSmartAccount__factory.createInterface(),Vs=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=ks(),{refresh:s}=As(),{data:c}=ds(n),l=(0,r.useCallback)(async()=>{if(!e||!t.j(e))throw Error(`Invalid smart account address`);if(!c)throw Error(`Unable to fetch implementation address for version ${n}`);return[{to:e,value:`0x0`,data:Bs.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:Bs.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=$n({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.W(e)} to version ${n}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{await Promise.all([o(),s()]),i?.()},onTxFailedOrCancelled:async()=>{a?.()}});return{...u,sendTransaction:async()=>u.sendTransaction(await l())}},Hs=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],Us=10*t.s.SECOND,Ws=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Hs(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:Us})},Gs=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},Ks=()=>[`VECHAIN_KIT_CHAIN_ID`],qs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ks(),queryFn:()=>Gs(e),enabled:!!e})},Js=1e3,Ys=async({thor:e,order:t=`asc`,offset:n=0,limit:r=Js,from:i=0,to:a=e.blocks.getHeadBlock()?.number,filterCriteria:o})=>{let s=await e.logs.filterEventLogs({range:{from:i,to:a,unit:`block`},options:{offset:n,limit:r},order:t,criteriaSet:o});if(!s)throw Error(`Failed to fetch events`);return s},Xs=async({nodeUrl:e,thor:t,order:n=`asc`,from:r=0,to:i,filterCriteria:a})=>{let o=[],s=0;for(;;){let c=await Ys({nodeUrl:e,thor:t,filterCriteria:a,from:r,to:i??2**53-1,limit:Js,order:n,offset:s});if(o.push(...c),c.length<Js)return o;s+=Js}},Zs=y.IERC20__factory.createInterface(),Qs=(e,n,r,i)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);let a=[];return a.push({to:r,value:`0x0`,data:Zs.encodeFunctionData(`transfer`,[e,(0,b.parseEther)(n)]),comment:`Transfer ${n} ${i} to ${e}`,abi:Zs.getFunction(`transfer`)}),a},$s=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,onSuccess:s,onError:c})=>{let{refresh:l}=Pn(),u=(0,r.useMemo)(()=>Qs(n,i,a,o),[n,i,a,o]),d=$n({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{l(),s?.()},onTxFailedOrCancelled:async e=>{c?.(e instanceof Error?e.message:String(e))}});return{...d,clauses:u,sendTransaction:async()=>d.sendTransaction(u)}},ec=(e,n)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);if(isNaN(Number(n)))throw Error(`Invalid amount`);let r=[];try{r.push({to:e,value:(0,b.parseEther)(n).toString(),data:`0x`,comment:`Transfer ${n} VET to ${e}`})}catch(e){throw console.error(`Error building clauses:`,e),Error(`Invalid amount format`)}return r},tc=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=Pn(),c=(0,r.useMemo)(()=>ec(n,i),[n,i]),l=$n({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{s(),a?.()},onTxFailedOrCancelled:async e=>{o?.(e instanceof Error?e.message:String(e))}});return{...l,clauses:c,sendTransaction:async()=>l.sendTransaction(c)}},nc=({clauseBuilder:e,refetchQueryKeys:t,invalidateCache:n=!0,onSuccess:i,onFailure:a,suggestedMaxGas:o,gasPadding:s,delegationUrl:c})=>{let{account:l}=X(),u=(0,p.useQueryClient)(),d=(0,r.useCallback)(async()=>{n&&t?.forEach(async e=>{await u.cancelQueries({queryKey:e}),await u.refetchQueries({queryKey:e})}),i?.()},[n,i,u,t]),f=$n({signerAccountAddress:l?.address,onTxConfirmed:d,suggestedMaxGas:o,onTxFailedOrCancelled:a,gasPadding:s,delegationUrl:c}),m=(0,r.useCallback)(async t=>{f.sendTransaction(e(t),c)},[e,f,c]);return{...f,sendTransaction:m}},rc=10*t.s.SECOND,ic=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],ac=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:ic(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*rc,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},oc=(e,t)=>{let n=(0,b.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},sc=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],cc=({abi:e,contractAddress:t,eventName:n,filterParams:i,mapResponse:a,nodeUrl:o})=>{let s=(0,f.useThor)();return(0,p.useQuery)({queryFn:(0,r.useCallback)(async()=>{if(!s)return[];let r=s.contracts.load(t,e).getEventAbi(n),c=r.encodeFilterTopicsNoNull(i??{}),l=(await Xs({thor:s,nodeUrl:o,filterCriteria:[{criteria:{address:t,topic0:c[0]??void 0,topic1:c[1]??void 0,topic2:c[2]??void 0,topic3:c[3]??void 0,topic4:c[4]??void 0},eventAbi:r}]})).map(t=>oc(t,e));if(l.some(({decodedData:e})=>e.eventName!==n))throw Error(`Unknown event`);return l.map(e=>a({meta:e.meta,decodedData:e.decodedData}))},[s,t,e,n,i,a,o]),queryKey:(0,r.useMemo)(()=>sc({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function lc({clauses:e,chainId:t,verifyingContract:n}){let r=[],i=[],a=[];return e.forEach(e=>{r.push(e.to??``),i.push(String(e.value)),typeof e.data==`object`&&`abi`in e.data?a.push((0,b.encodeFunctionData)(e.data)):a.push(e.data||`0x`)}),{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n},types:{ExecuteBatchWithAuthorization:[{name:`to`,type:`address[]`},{name:`value`,type:`uint256[]`},{name:`data`,type:`bytes[]`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`},{name:`nonce`,type:`bytes32`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteBatchWithAuthorization`,message:{to:r,value:i,data:a,validAfter:0,validBefore:Math.floor(Date.now()/1e3)+300,nonce:o.ethers.hexlify(o.ethers.randomBytes(32))}}}function uc({clause:e,chainId:t,smartAccount:n}){return{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n.address??``},types:{ExecuteWithAuthorization:[{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`data`,type:`bytes`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteWithAuthorization`,message:{validAfter:0,validBefore:Math.floor(Date.now()/1e3)+60,to:e.to,value:String(e.value),data:(typeof e.data==`object`&&`abi`in e.data?(0,b.encodeFunctionData)(e.data):e.data)||`0x`}}}function dc(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=jn(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=qs();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const fc=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=dc(),c=async e=>{let{version:t}=e;return t&&t<3?await l(e):await u(e)};async function l(c){let{clauses:l,smartAccount:u,title:d=`Sign Transaction`,description:f,buttonText:p=`Sign`}=c,m=[],h=l.map(e=>uc({clause:e,chainId:o,smartAccount:u})),g=[];for(let t=0;t<h.length;t++){let a=h[t],o=l[t];if(!o)throw Error(`Transaction clause at index ${t} is undefined`);if(e.isConnectedWithCrossApp){let e=await r({...a,address:n?.address,types:Object.fromEntries(Object.entries(a.types).map(([e,t])=>[e,[...t]]))});g.push(e);continue}let s=o.data,c=(await i(a,{uiOptions:{title:d,description:f??(l[t].comment||(typeof s==`object`&&s&&`functionName`in s?s.functionName:` `)),buttonText:p}})).signature;g.push(c)}return u.isDeployed||m.push(s.Clause.callFunction(s.Address.of(t.bt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeWithAuthorization`),[e.message.to,BigInt(e.message.value),e.message.data,BigInt(e.message.validAfter),BigInt(e.message.validBefore),g[t]]))}),m}async function u(c){let{clauses:l,smartAccount:u,title:d,description:f,buttonText:p=`Sign`}=c,m=[],h=lc({clauses:l,chainId:o,verifyingContract:u.address??``}),g;return g=e.isConnectedWithCrossApp?await r({...h,address:n?.address}):(await i(h,{uiOptions:{title:d,description:f,buttonText:p}})).signature,u.isDeployed||m.push(s.Clause.callFunction(s.Address.of(t.bt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeBatchWithAuthorization`),[h.message.to,h.message.value?.map(e=>BigInt(e))??0,h.message.data,BigInt(h.message.validAfter),BigInt(h.message.validBefore),h.message.nonce,g])),m}return{buildClausesWithAuth:c}};let pc=function(e){return e.CUSTOM_TOKENS=`vechain_kit_custom_tokens`,e.ECOSYSTEM_SHORTCUTS=`vechain-kit-ecosystem-shortcuts`,e.CURRENCY=`vechain_kit_currency`,e.NODE_URL=`vechain_kit_node_url`,e.NETWORK=`vechain_kit_network`,e.GAS_TOKEN_PREFERENCES=`vechain_kit_gas_token_preferences`,e.SHOW_ASSETS=`vechain_kit_show_assets`,e}({});const mc=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.dt(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t.yt(e,JSON.stringify(i))},[e,i]),[i,a]},hc=`vechain-kit-storage-change`,gc=(e,t)=>{let[n,i]=(0,r.useState)(()=>{if(typeof window>`u`)return t;try{let n=window.localStorage.getItem(e);return n?JSON.parse(n):t}catch(e){return console.error(`Error loading from localStorage:`,e),t}}),a=(0,r.useRef)(!1);return(0,r.useEffect)(()=>{if(!(typeof window>`u`)){if(a.current){a.current=!1;return}try{window.localStorage.setItem(e,JSON.stringify(n)),window.dispatchEvent(new CustomEvent(hc,{detail:{key:e,value:n}}))}catch(e){console.error(`Error writing to localStorage:`,e)}}},[e,n]),(0,r.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(t.key===e&&t.newValue)try{let e=JSON.parse(t.newValue);JSON.stringify(e)!==JSON.stringify(n)&&(a.current=!0,i(e))}catch(e){console.error(`Error parsing storage value:`,e)}},r=(t=>{if(t.detail.key===e)try{let t=window.localStorage.getItem(e);if(t){let e=JSON.parse(t);JSON.stringify(e)!==JSON.stringify(n)&&(a.current=!0,i(e))}}catch(e){console.error(`Error parsing storage value:`,e)}});return window.addEventListener(`storage`,t),window.addEventListener(hc,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(hc,r)}},[e,n]),[n,i,(0,r.useCallback)(()=>{if(!(typeof window>`u`))try{let r=window.localStorage.getItem(e),a=r?JSON.parse(r):t;JSON.stringify(a)!==JSON.stringify(n)&&i(a)}catch(e){console.error(`Error syncing localStorage:`,e)}},[e,t,n]),(0,r.useCallback)(()=>{if(typeof window>`u`)return t;let n=window.localStorage.getItem(e);return n?JSON.parse(n):t},[e,t])]},_c=()=>{let[e,t]=mc(pc.ECOSYSTEM_SHORTCUTS,[]);return{shortcuts:e,addShortcut:n=>{e.some(e=>e.url===n.url)||t([...e,n])},removeShortcut:n=>{t(e.filter(e=>e.url!==n))},isShortcut:t=>e.some(e=>e.url===t)}},vc=async(e,t,n,r,i)=>{let a=new URL(`estimate/clauses/${r.toLowerCase()}`,t);return a.searchParams.set(`type`,`smartaccount`),a.searchParams.set(`speed`,i),await(await fetch(a,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json()},yc=async e=>{let t=new URL(`deposit/account`,e);return await(await fetch(t,{method:`GET`,headers:{"Content-Type":`application/json`}})).json()},bc=async(e,t,n,r)=>{let i=new URL(`sign/transaction/authorized/${n.toLowerCase()}`,r);return await(await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json()},xc=async(e,t,n,r)=>{let i=await t.gas.estimateGas(e,n?.address??``),a=Math.max(i.totalGas,0);return await t.transactions.buildTransactionBody(e,a,{isDelegated:r})};function Sc(e,t){return s.Transaction.of(e.body,R.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function Cc(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const wc=()=>{let{connectedWallet:e}=X(),{data:n}=Ns(e?.address??``),{data:i}=bs(n?.address??``,e?.address??``),{preferences:a}=Tc(),o=y.IERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=fc(),u=L.ThorClient.at(t.bt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await vc(n?.address??``,r,e,c,`medium`),f=await yc(r),p={to:c===`VET`?f.depositAccount:t.Q[c].address,value:c===`VET`?(0,b.parseEther)(d.transactionCost?.toString()??`0`).toString():`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,(0,b.parseEther)(d.transactionCost?.toString()??`0`)]),comment:`Transfer ${d.transactionCost} ${c} to ${f.depositAccount}`,abi:c===`VET`?void 0:o.getFunction(`transfer`)},m=await l({clauses:[...e,p],smartAccount:n,version:i?.version??0}),h=await xc(m,u,t.V,!0),g=await s.Transaction.of(h).signAsSender(s.HexUInt.of(t.V.privateKey).bytes),_=await bc(s.HexUInt.of(g.encoded).toString(),t.V.address,c,r),v=Sc(g,_.signature),y={clauses:m,simulateTransactionOptions:{caller:t.V.address??``,gasPayer:_.address}},x=await u.transactions.simulateTransaction(y.clauses,{...y.simulateTransactionOptions});for(let e=0;e<x.length;e++)if(x[e].reverted)throw Error(x[e].vmError);return(await u.transactions.sendTransaction(v)).id}catch(e){console.error(`Error sending transaction using generic delegator`,e)}throw Error(`Failed to send transaction using generic delegator, no gas tokens have sufficient balance or are enabled in Gas Token Preferences`)},[a,n,i,l,u,t.V])}},Tc=()=>{let[e,n]=gc(pc.GAS_TOKEN_PREFERENCES,t.J);return{preferences:e,supportedTokens:t.Q,updatePreferences:(0,r.useCallback)(e=>{n(t=>({...t,...e}))},[n]),reorderTokenPriority:(0,r.useCallback)(e=>{n(t=>{let n=e.filter(e=>t.availableGasTokens.includes(e)&&!t.excludedTokens.includes(e));return{...t,tokenPriority:e,availableGasTokens:n,gasTokenToUse:n[0]??t.gasTokenToUse}})},[n]),toggleTokenExclusion:(0,r.useCallback)(e=>{n(t=>{let n=t.excludedTokens.includes(e),r=n?t.excludedTokens.filter(t=>t!==e):[...t.excludedTokens,e],i=t.tokenPriority.indexOf(e),a=n?[...t.availableGasTokens.slice(0,i),e,...t.availableGasTokens.slice(i)]:t.availableGasTokens.filter(t=>t!==e);return{...t,excludedTokens:r,availableGasTokens:a,gasTokenToUse:a[0]??t.gasTokenToUse}})},[n])}},Ec=({clauses:e,enabled:t=!0,tokens:n,sendingAmount:r,sendingTokenSymbol:i})=>{let{connectedWallet:a,account:o}=X(),{data:s}=Ns(a?.address??``),{feeDelegation:c}=$(),{balances:l}=zt(o?.address??``),{updatePreferences:u}=Tc();return(0,p.useQuery)({queryKey:[`gas-estimation`,JSON.stringify(e),JSON.stringify(n),r,i],queryFn:async()=>{let t=null;for(let a of n)try{let n=await vc(s?.address??``,c?.genericDelegatorUrl??``,e,a,`medium`),o=n.transactionCost,d=Number(l.find(e=>e.symbol===a)?.balance||0),f=o+(r&&i&&a===i?Number(r):0);if(d>=f)return u({gasTokenToUse:a}),{...n,usedToken:a};t=Error(`Insufficient ${a} balance: has ${d}, needs ${f}`)}catch(e){t=e}throw t||Error(`All gas tokens failed estimation or have insufficient balance`)},enabled:t&&e.length>0&&!!s?.address&&!!c?.genericDelegatorUrl&&n.length>0&&l.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1,retry:!1,retryDelay:1e3})},Dc=({clauses:e,tokens:t,enabled:n=!0})=>{let{connectedWallet:r}=X(),{data:i}=Ns(r?.address??``),{feeDelegation:a}=$();return(0,p.useQuery)({queryKey:[`gas-estimation-all-tokens`,JSON.stringify(e),JSON.stringify(t)],queryFn:async()=>{let n={};return await Promise.all(t.map(async t=>{try{n[t]={cost:(await vc(i?.address??``,a?.genericDelegatorUrl??``,e,t,`medium`)).transactionCost||0,loading:!1}}catch(e){n[t]={cost:0,loading:!1,error:e instanceof Error?e.message:`Unknown error`}}})),n},enabled:n&&e.length>0&&!!i?.address&&!!a?.genericDelegatorUrl&&t.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},Oc=({symbol:e,amount:a,currencyValue:o,currentCurrency:s,isDisabled:c,onClick:l,...u})=>{let d=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[p]=mc(pc.SHOW_ASSETS,!0);return(0,i.jsxs)(n.Button,{height:`72px`,variant:`ghost`,justifyContent:`space-between`,isDisabled:c,p:4,w:`100%`,_disabled:{cursor:`not-allowed`,opacity:.5},onClick:l,"data-testid":`asset-${e}`,...u,children:[(0,i.jsxs)(n.HStack,{children:[t.et[e]?r.default.cloneElement(t.et[e],{boxSize:`24px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[e],alt:`${e} logo`,boxSize:`24px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`24px`,borderRadius:`full`,bg:`whiteAlpha.200`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`10px`,fontWeight:`bold`,color:d,children:e.slice(0,3)})})}),(0,i.jsx)(n.Text,{color:d,children:e})]}),(0,i.jsxs)(n.VStack,{align:`flex-end`,spacing:0,children:[(0,i.jsxs)(n.Text,{color:d,children:[p?a.toLocaleString(void 0,{maximumFractionDigits:2}):`*`.repeat(4),` `]}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:f,"data-testid":`${e}-balance`,children:p?qt(o,{currency:s}):`*`.repeat(4)})]})]})},kc=({address:e,domain:a,imageSrc:o,imageAlt:s=`Account`,hideAddress:c=!1,balance:u,tokenAddress:d})=>{let{t:f}=(0,l.useTranslation)(),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:g}=Qt({address:e}),{tokens:_,isLoading:v}=Zt({address:e}),y=(0,r.useMemo)(()=>d?_.find(e=>e.address===d):null,[_,d]),b=(0,r.useMemo)(()=>u===void 0?y?Number(y.balance):0:u,[u,y]),x=y?.symbol||``;return g||v?(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!c&&(0,i.jsx)(n.Skeleton,{mt:2,height:`12px`,width:`100px`,borderRadius:`md`})]})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]}):(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:o,alt:s,boxSize:`40px`,borderRadius:`full`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:a?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:a}),!c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:m,children:t.W(e,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:t.W(e,6,4)})})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:m,children:[b.toLocaleString(void 0,{maximumFractionDigits:2}),x&&` ${x}`]})]})]})},Ac=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`FAQ`,icon:(0,i.jsx)(n.Icon,{as:g.LuCircleHelp,fontSize:`17px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,lineHeight:`normal`,left:`10px`,top:`8px`,onClick:e,...t}),jc=({children:e,...t})=>(as(),(0,i.jsx)(n.VStack,{...t,children:e})),Mc=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image),o=(0,r.useRef)(e?.address);return(0,r.useEffect)(()=>{o.current!==e?.address&&(a.current=e?.image,o.current=e?.address)},[e?.address]),(0,r.useEffect)(()=>{e?.image&&!e.isLoadingMetadata&&(a.current=e.image)},[e?.image,e?.isLoadingMetadata]),!t?.src&&!e?.image&&!a.current||e?.isLoadingMetadata?(0,i.jsx)(n.Skeleton,{rounded:`full`,width:t?.width,height:t?.height}):(0,i.jsx)(n.Image,{src:t?.src||e?.image||a.current,alt:t?.alt||e?.domain,objectFit:`cover`,rounded:`full`,...t})},Nc=({transactionError:e,isSubmitting:a,isTxWaitingConfirmation:o,onConfirm:s,onRetry:c,transactionPendingText:u,txReceipt:d,isSubmitForm:f=!1,buttonText:p,isDisabled:m=!1,style:h,onError:g,gasEstimationError:_,hasEnoughGasBalance:v=!0,isLoadingGasEstimation:y=!1,showGasEstimationError:b=!1,context:x=`transaction`})=>{let{t:S}=(0,l.useTranslation)(),{darkMode:C}=$(),{network:w}=$(),T=(0,r.useMemo)(()=>e?e.reason||S(`Something went wrong. Please try again.`):null,[e,S]);(0,r.useEffect)(()=>{T&&g?.(T)},[T,g]);let E=(0,r.useMemo)(()=>{if(h?.accentColor)return`${h.accentColor} !important`},[h?.accentColor]),D=(0,r.useMemo)(()=>{if(!b||y||!(_||v))return null;if(!v&&!_)return{message:S(`You don't have any gas tokens enabled. Please enable at least one gas token in Gas Token Preferences.`)};if(_){let e=``;switch(x){case`send`:e=S(`Insufficient balance to complete this transfer and cover gas fees.`);break;case`customization`:e=S(`Insufficient balance to update your profile and cover gas fees.`);break;case`domain`:e=S(`Insufficient balance to claim this domain and cover gas fees.`);break;default:e=S(`Insufficient balance to complete this transaction and cover gas fees.`)}return{message:e}}return null},[_,v,y,b,x,S]);return(0,i.jsxs)(n.VStack,{width:`full`,spacing:4,children:[T&&(0,i.jsx)(n.Box,{p:3,borderRadius:`md`,bg:C?`rgba(218, 90, 90, 0.1)`:`rgba(218, 90, 90, 0.05)`,borderWidth:`1px`,borderColor:C?`rgba(218, 90, 90, 0.3)`:`rgba(218, 90, 90, 0.2)`,w:`full`,children:(0,i.jsx)(n.Text,{color:`#da5a5a`,fontSize:`sm`,fontWeight:`medium`,"data-testid":`tx-send-error-msg`,children:T})}),D&&!T&&(0,i.jsx)(n.Box,{p:3,borderRadius:`md`,bg:C?`rgba(218, 90, 90, 0.1)`:`rgba(218, 90, 90, 0.05)`,borderWidth:`1px`,borderColor:C?`rgba(218, 90, 90, 0.3)`:`rgba(218, 90, 90, 0.2)`,w:`full`,children:(0,i.jsx)(n.Text,{color:`#da5a5a`,fontSize:`sm`,fontWeight:`medium`,"data-testid":`gas-estimation-error`,children:D.message})}),(0,i.jsx)(n.Button,{px:4,variant:T?`vechainKitSecondary`:`vechainKitPrimary`,bg:E,onClick:()=>T&&c?c():s(),type:f?`submit`:`button`,isLoading:a,isDisabled:m,loadingText:o?S(`Waiting wallet confirmation...`):u,"data-testid":`confirm-button`,children:T?S(`Retry`):p||S(`Confirm`)}),T&&d?.meta.txID&&(0,i.jsx)(n.Link,{isExternal:!0,fontSize:`sm`,color:C?`whiteAlpha.600`:`blackAlpha.600`,textAlign:`center`,width:`full`,href:`${t.bt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},Pc=({onClick:e,hasUnreadNotifications:t,...r})=>(0,i.jsx)(n.IconButton,{"aria-label":`Notifications`,size:`sm`,variant:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,icon:(0,i.jsxs)(n.Box,{position:`relative`,children:[(0,i.jsx)(g.LuBell,{fontSize:`20px`}),t&&(0,i.jsx)(n.Box,{position:`absolute`,top:`-1px`,right:`-1px`,minWidth:`8px`,height:`8px`,bg:`red.500`,borderRadius:`full`})]}),...r}),Fc=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{balances:p}=zt(d),[m,h]=r.default.useState(o),[g,_]=r.default.useState(!1),v=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),y=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=e=>e?b:`transparent`,C=e=>e?v:`transparent`;r.default.useEffect(()=>{e&&(h(o),_(!1))},[e,o]);let w=()=>{s(m,g),a()},T=e=>{let t=p.find(t=>t.symbol===e);return t?Number(t.balance).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):`0.00`},E=e=>{let t=p.find(t=>t.symbol===e),n=u[e];return!t||!n?!1:Number(t.balance)<n.cost};return(0,i.jsxs)(Re,{isOpen:e,onClose:a,size:`sm`,children:[(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:v,children:f(`Fee token`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`normal`,color:y,mt:1,children:f(`Select the token to pay the fee with`)})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,children:[c.map(e=>{let a=t.Q[e],o=m===e,s=u[e]||{cost:0,loading:!0},c=E(e);return(0,i.jsx)(n.Box,{cursor:c?`not-allowed`:`pointer`,bg:S(o),border:`1px`,borderColor:C(o),borderRadius:`md`,p:3,transition:`all 0.2s ease`,_hover:{backgroundColor:c?S(o):y&&`#ffffff12`,borderColor:c?C(o):y},opacity:c?.5:1,onClick:()=>!c&&h(e),children:(0,i.jsxs)(n.HStack,{spacing:3,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,children:[r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:v,children:a.symbol}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:y,children:[f(`Balance`),`:`,` `,T(e)]}),c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:x,children:f(`Insufficient balance`)})]})]}),(0,i.jsx)(n.VStack,{align:`end`,spacing:0,children:s.loading?(0,i.jsx)(n.Skeleton,{height:`16px`,width:`60px`}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,color:v,children:t.x(s.cost,2)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:y,children:a.symbol})]})})]})},e)}),m!==o&&(0,i.jsxs)(n.FormControl,{display:`flex`,alignItems:`center`,justifyContent:`space-between`,children:[(0,i.jsx)(n.FormLabel,{htmlFor:`remember-choice`,mb:`0`,fontSize:`sm`,color:v,children:f(`Use this token for future transactions`)}),(0,i.jsx)(n.Switch,{id:`remember-choice`,isChecked:g,onChange:e=>_(e.target.checked),color:v})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:w,isDisabled:E(m),children:f(`Apply`)}),(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:a,children:f(`Cancel`)})]})})]})},Ic=({estimation:e,isLoading:a,isLoadingTransaction:o,onTokenChange:s,clauses:c=[],userSelectedToken:u})=>{let{t:d}=(0,l.useTranslation)(),{feeDelegation:f}=$(),{connection:p,account:m}=X(),{preferences:h,reorderTokenPriority:_}=Tc(),{isOpen:v,onOpen:y,onClose:b}=(0,n.useDisclosure)(),x=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),S=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),[C,w]=(0,r.useState)(()=>{let e={};return h.availableGasTokens.forEach(t=>{e[t]={cost:0,loading:!0}}),e}),{data:T,isLoading:E}=Dc({clauses:c,tokens:h.availableGasTokens,enabled:c.length>0});(0,r.useEffect)(()=>{!E&&T&&w(T)},[T,E]),(0,r.useEffect)(()=>{e&&w(t=>({...t,[e.usedToken]:{cost:e.transactionCost||0,loading:!1}}))},[e]),(0,r.useEffect)(()=>{E&&w(h.availableGasTokens.reduce((e,t)=>(e[t]={cost:0,loading:!0},e),{}))},[E,h.availableGasTokens]);let D=(0,r.useCallback)((t,n)=>{n&&_([t,...h.tokenPriority.filter(e=>e!==t)]),s&&t!==e?.usedToken&&s(t)},[e,s,_,h.tokenPriority]);if(f?.delegatorUrl||p.isConnectedWithDappKit||h.availableGasTokens.length===0)return null;let{balances:O}=zt(m?.address??``),k=e=>{let t=O.find(t=>t.symbol===e),n=C[e];return!t||!n||n.loading?!0:Number(t.balance)<n.cost},A=e?.usedToken,j=h.availableGasTokens,M;A?M=A:u&&j.includes(u)?M=u:(M=j.find(e=>C[e]&&!C[e].loading&&!k(e)),M||=j.find(e=>C[e]&&!C[e].loading),M||=j[0]);let N=M?C[M]:void 0,P=A&&e?.transactionCost?e.transactionCost:N?.cost||0,F=M?t.Q[M]:void 0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Divider,{mt:3}),(0,i.jsxs)(n.HStack,{mt:3,w:`full`,justifyContent:`start`,alignItems:`center`,children:[(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,w:`full`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`light`,textAlign:`left`,w:`full`,color:S,children:d(`Fee`)}),(0,i.jsx)(n.HStack,{align:`start`,justifyContent:`space-between`,spacing:0,w:`full`,children:(0,i.jsx)(n.HStack,{justifyContent:`flex-start`,w:`full`,children:a||!A&&(!N||N.loading)||!F?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),(0,i.jsx)(n.Skeleton,{height:`16px`,width:`60px`,borderRadius:`md`})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.Text,{color:x,fontSize:`sm`,fontWeight:`semibold`,children:[t.x(P,2),` `,F.symbol]}),(0,i.jsxs)(n.Text,{color:S,fontSize:`xs`,children:[`≈`,` $`,(P*.01).toFixed(2)]})]})})})]}),(0,i.jsxs)(n.Button,{onClick:y,variant:`outline`,size:`sm`,borderRadius:`full`,px:6,disabled:o,color:S,borderColor:S,_hover:{bg:S},leftIcon:r.default.cloneElement(t.et[M||h.availableGasTokens[0]],{boxSize:`20px`,borderRadius:`full`}),children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,children:M||h.availableGasTokens[0]}),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:S})]})]}),(0,i.jsx)(Fc,{isOpen:v,onClose:b,selectedToken:M||h.availableGasTokens[0],onTokenSelect:D,availableTokens:h.availableGasTokens,tokenEstimations:C,walletAddress:m?.address??``})]})},Lc=P.keyframes`
201
201
  from {
202
202
  transform: translateY(-100%);
203
203
  opacity: 0;