@vechain/vechain-kit 2.2.1 → 2.2.3

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
@@ -110,13 +110,13 @@ const e=require(`./assets-DXVXPy3w.cjs`),t=require(`./utils-Bl-JeVTg.cjs`);let n
110
110
  opacity: 0.5 !important;
111
111
  }
112
112
  `),d.length>0&&(u.textContent=d.join(`
113
- `))}let we=null;function Te(){return we||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),we}const Ee=({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:Te(),children:e})},q=({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:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,...t}),De=({wallet:e,label:a,style:o,showHumanAddress:s=!0})=>{let[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=async(e,n)=>{await t.st(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))};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:p,children:a}),e?.domain?(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:e.domain,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e.domain||``,d)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,onClick:()=>m(e.domain||``,d),cursor:`pointer`,as:u?g.LuCheck:g.LuCopy})})]}),(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuWallet,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:s?t.U(e.address??``,8,7):e.address,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e.address??``,l)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,cursor:`pointer`,onClick:()=>m(e.address??``,l),as:c?g.LuCheck:g.LuCopy})})]})]}):(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuWallet,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:s?t.U(e?.address??``,6,4):e?.address,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e?.address??``,l)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,onClick:()=>m(e?.address??``,l),cursor:`pointer`,as:c?g.LuCheck:g.LuCopy})})]})]})})};var Oe=`2.2.1`,ke={"@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.24.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.0.3`,"@vechain/dapp-kit-react":`2.1.0-rc.2`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.4.1`,"@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`,viem:`^2.29.3`,wagmi:`^2.15.4`},Ae={"@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.2`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const je=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.S,{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/${Oe}`,isExternal:!0,pt:`1px`,children:[`v`,Oe]})]})},J=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(!0),{tokens:l}=qa(),u=l?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=new IntersectionObserver(([e])=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{if(c.current){c.current=!1,a(!1);return}a(!e.isIntersecting)},50)},{threshold:0}),t=setTimeout(()=>{o.current&&e.observe(o.current)},200);return()=>{clearTimeout(t),s.current&&clearTimeout(s.current),e.disconnect()}},[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?u:`none`,style:{WebkitBackdropFilter:t?u:`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:{position:`absolute`,top:`25px`}})]})},Me=({children:e})=>(0,i.jsx)(n.Box,{position:`sticky`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,boxShadow:`0px -1px 6px -3px rgb(0 0 0 / 56%)`,transition:`box-shadow 0.2s ease-in-out`,children:e}),Ne=({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})=>{let[p]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:m}=qa(),h=(0,n.useToken)(`colors`,`vechain-kit-modal`),g=(0,n.useToken)(`colors`,`vechain-kit-overlay`),{tokens:_}=qa(),v=_?.effects?.backdropFilter?.overlay,y=_?.effects?.backdropFilter?.modal,b=d??v??`blur(3px)`,x=p?{}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`};return(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:m},trapFocus:!u,autoFocus:!u,children:[(0,i.jsx)(n.ModalOverlay,{bg:g,backdropFilter:b}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:h,variant:`vechainKitBase`,sx:{backdropFilter:y,WebkitBackdropFilter:y},...x,children:r})]})},Pe=(e,t,n)=>{switch(t){case`eur`:return e/n.eurUsdPrice;case`gbp`:return e/n.gbpUsdPrice;default:return e}},Fe=(e,t=`en`,n)=>{let r={style:`currency`,minimumFractionDigits:2,maximumFractionDigits:2,currency:n?.currency??`usd`,...n};return new Intl.NumberFormat(ie[t],r).format(e)},Ie=(e,t)=>Fe(e,U.resolvedLanguage,{notation:`compact`,compactDisplay:`short`,currency:t?.currency??`usd`,...t}),Le=({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`);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.Q[e]?r.default.cloneElement(t.Q[e],{boxSize:`24px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.Z[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:[a.toLocaleString(void 0,{maximumFractionDigits:2}),` `]}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:f,"data-testid":`${e}-balance`,children:Ie(o,{currency:s})})]})]})},Re=async e=>{let t=await fetch(`https://auth.privy.io/api/v1/apps/${e}`,{headers:{"privy-app-id":e}});if(!t.ok)throw Error(`Failed to fetch Privy app info`);return t.json()},ze=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],Be=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:ze(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>Re(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.J.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})},Y=async()=>{try{let e=await fetch(`https://status.privy.io/summary.json`);if(!e.ok)throw Error(`Failed to fetch Privy status`);return(await e.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},Ve=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:Y,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=e=>[`VECHAIN_KIT_DOMAIN`,e],Ue=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:He(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);let r=await(0,_.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.A(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,_.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,_.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,_.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,_.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})},We=async(e,n,r)=>{let i=(0,y.keccak256)((0,y.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,y.keccak256)((0,y.toBytes)(r))])),a=await e.contracts.load(t.vt(n).vetDomainsContractAddress,v.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},Ge=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],Ke=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ge(e),queryFn:()=>We(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})},qe=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:ft(e??``,r.type)}),n.invalidateQueries({queryKey:gt(e,r.type)}),n.invalidateQueries({queryKey:Et(t)})])}}},Je=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:He(t)}),e.invalidateQueries({queryKey:He(n)}),e.invalidateQueries({queryKey:Ge(r)}),e.invalidateQueries({queryKey:ut(t,`.vet`)}),e.invalidateQueries({queryKey:ut(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:gt(n)})]),await Promise.all([e.refetchQueries({queryKey:He(t)}),e.refetchQueries({queryKey:He(n)}),e.refetchQueries({queryKey:ut(t,`.vet`)}),e.refetchQueries({queryKey:ut(t,`.veworld.vet`)}),e.refetchQueries({queryKey:ft(r+`.`+i,a)}),e.refetchQueries({queryKey:gt(n)}),e.refetchQueries({queryKey:Ge(r)}),e.refetchQueries({queryKey:Et(t)})])},Ye=v.VeworldSubdomainClaimer__factory.createInterface(),Xe=v.VetDomainsReverseRegistrar__factory.createInterface(),Ze=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.U(i?.address??``,4,4)}`,abi:Xe.getFunction(`setName`)}),r){s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:Xe.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.vt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.U(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if($e(n))s.push({to:t.vt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:Ye.encodeFunctionData(`claim`,[e,t.vt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:Ye.getFunction(`claim`)}),s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.U(i?.address??``,4,4)}`,abi:Xe.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},Qe=({subdomain:e,domain:t,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let o=(0,p.useQueryClient)(),{account:s}=X(),{network:c}=$(),{refresh:l}=qe(e+`.`+t,s?.address??``),u=(0,r.useCallback)(()=>Ze(e,t,a,s,c),[e,t,a,s,c]),d=(0,r.useCallback)(async()=>{let r=`${e}.${t}`;await Je(o,s?.address??``,r,e,t,c.type),l(),n?.()},[n,e,t,o,s,c.type,l]),f=Kn({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())}},$e=e=>e.endsWith(`veworld.vet`),et=v.VetDomainsReverseRegistrar__factory.createInterface(),tt=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.vt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:et.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:et.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.vt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.U(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},nt=({domain:e,onSuccess:t,onError:n,alreadyOwned:i=!1})=>{let{network:a}=$(),o=(0,p.useQueryClient)(),{account:s}=X(),{refresh:c}=qe(e,s?.address??``),l=(0,r.useCallback)(()=>tt(e,i,s,a),[e,i,s,a]),u=(0,r.useCallback)(async()=>{await Je(o,s?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,a.type),c(),t?.()},[t,e,o,s,a.type,c]),d=Kn({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())}},rt=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],it=s.ABIContract.ofAbi(v.VeworldSubdomainClaimer__factory.abi),at=async(e,n,r)=>{let i=t.vt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,it.abi).read.isDomainProtected(r))[0]},ot=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:rt(e),queryFn:()=>at(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})},st=b.z.object({name:b.z.string()}),ct=b.z.object({domains:b.z.array(st)}),lt=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.vt(e).graphQlIndexerUrl,a=`query Registrations {
113
+ `))}let we=null;function Te(){return we||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),we}const Ee=({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:Te(),children:e})},q=({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:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,...t}),De=({wallet:e,label:a,style:o,showHumanAddress:s=!0})=>{let[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=async(e,n)=>{await t.st(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))};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:p,children:a}),e?.domain?(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:e.domain,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e.domain||``,d)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,onClick:()=>m(e.domain||``,d),cursor:`pointer`,as:u?g.LuCheck:g.LuCopy})})]}),(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuWallet,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:s?t.U(e.address??``,8,7):e.address,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e.address??``,l)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,cursor:`pointer`,onClick:()=>m(e.address??``,l),as:c?g.LuCheck:g.LuCopy})})]})]}):(0,i.jsxs)(n.InputGroup,{children:[(0,i.jsx)(n.InputLeftElement,{children:(0,i.jsx)(n.Icon,{as:g.LuWallet,color:p})}),(0,i.jsx)(n.Input,{cursor:`pointer`,value:s?t.U(e?.address??``,6,4):e?.address,readOnly:!0,fontSize:`sm`,fontWeight:`700`,color:f,onClick:()=>m(e?.address??``,l)}),(0,i.jsx)(n.InputRightElement,{children:(0,i.jsx)(n.Icon,{color:p,onClick:()=>m(e?.address??``,l),cursor:`pointer`,as:c?g.LuCheck:g.LuCopy})})]})]})})};var Oe=`2.2.3`,ke={"@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.24.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.0.3`,"@vechain/dapp-kit-react":`2.1.0-rc.2`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.4.1`,"@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`,viem:`^2.29.3`,wagmi:`^2.15.4`},Ae={"@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.2`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const je=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.S,{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/${Oe}`,isExternal:!0,pt:`1px`,children:[`v`,Oe]})]})},J=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(!0),{tokens:l}=qa(),u=l?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=new IntersectionObserver(([e])=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{if(c.current){c.current=!1,a(!1);return}a(!e.isIntersecting)},50)},{threshold:0}),t=setTimeout(()=>{o.current&&e.observe(o.current)},200);return()=>{clearTimeout(t),s.current&&clearTimeout(s.current),e.disconnect()}},[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?u:`none`,style:{WebkitBackdropFilter:t?u:`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:{position:`absolute`,top:`25px`}})]})},Me=({children:e})=>(0,i.jsx)(n.Box,{position:`sticky`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,boxShadow:`0px -1px 6px -3px rgb(0 0 0 / 56%)`,transition:`box-shadow 0.2s ease-in-out`,children:e}),Ne=({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})=>{let[p]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:m}=qa(),h=(0,n.useToken)(`colors`,`vechain-kit-modal`),g=(0,n.useToken)(`colors`,`vechain-kit-overlay`),{tokens:_}=qa(),v=_?.effects?.backdropFilter?.overlay,y=_?.effects?.backdropFilter?.modal,b=d??v??`blur(3px)`,x=p?{}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`};return(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:m},trapFocus:!u,autoFocus:!u,children:[(0,i.jsx)(n.ModalOverlay,{bg:g,backdropFilter:b}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:h,variant:`vechainKitBase`,sx:{backdropFilter:y,WebkitBackdropFilter:y},...x,children:r})]})},Pe=(e,t,n)=>{switch(t){case`eur`:return e/n.eurUsdPrice;case`gbp`:return e/n.gbpUsdPrice;default:return e}},Fe=(e,t=`en`,n)=>{let r={style:`currency`,minimumFractionDigits:2,maximumFractionDigits:2,currency:n?.currency??`usd`,...n};return new Intl.NumberFormat(ie[t],r).format(e)},Ie=(e,t)=>Fe(e,U.resolvedLanguage,{notation:`compact`,compactDisplay:`short`,currency:t?.currency??`usd`,...t}),Le=({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`);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.Q[e]?r.default.cloneElement(t.Q[e],{boxSize:`24px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.Z[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:[a.toLocaleString(void 0,{maximumFractionDigits:2}),` `]}),(0,i.jsx)(n.Text,{fontSize:`sm`,color:f,"data-testid":`${e}-balance`,children:Ie(o,{currency:s})})]})]})},Re=async e=>{let t=await fetch(`https://auth.privy.io/api/v1/apps/${e}`,{headers:{"privy-app-id":e}});if(!t.ok)throw Error(`Failed to fetch Privy app info`);return t.json()},ze=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],Be=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:ze(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>Re(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.J.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})},Y=async()=>{try{let e=await fetch(`https://status.privy.io/summary.json`);if(!e.ok)throw Error(`Failed to fetch Privy status`);return(await e.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},Ve=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:Y,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=e=>[`VECHAIN_KIT_DOMAIN`,e],Ue=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:He(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);let r=await(0,_.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.A(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,_.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,_.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,_.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,_.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})},We=async(e,n,r)=>{let i=(0,y.keccak256)((0,y.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,y.keccak256)((0,y.toBytes)(r))])),a=await e.contracts.load(t.vt(n).vetDomainsContractAddress,v.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},Ge=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],Ke=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ge(e),queryFn:()=>We(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})},qe=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:ft(e??``,r.type)}),n.invalidateQueries({queryKey:gt(e,r.type)}),n.invalidateQueries({queryKey:Et(t)})])}}},Je=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:He(t)}),e.invalidateQueries({queryKey:He(n)}),e.invalidateQueries({queryKey:Ge(r)}),e.invalidateQueries({queryKey:ut(t,`.vet`)}),e.invalidateQueries({queryKey:ut(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:gt(n)})]),await Promise.all([e.refetchQueries({queryKey:He(t)}),e.refetchQueries({queryKey:He(n)}),e.refetchQueries({queryKey:ut(t,`.vet`)}),e.refetchQueries({queryKey:ut(t,`.veworld.vet`)}),e.refetchQueries({queryKey:ft(r+`.`+i,a)}),e.refetchQueries({queryKey:gt(n)}),e.refetchQueries({queryKey:Ge(r)}),e.refetchQueries({queryKey:Et(t)})])},Ye=v.VeworldSubdomainClaimer__factory.createInterface(),Xe=v.VetDomainsReverseRegistrar__factory.createInterface(),Ze=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.U(i?.address??``,4,4)}`,abi:Xe.getFunction(`setName`)}),r){s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:Xe.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.vt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.U(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if($e(n))s.push({to:t.vt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:Ye.encodeFunctionData(`claim`,[e,t.vt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:Ye.getFunction(`claim`)}),s.push({to:t.vt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Xe.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.U(i?.address??``,4,4)}`,abi:Xe.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},Qe=({subdomain:e,domain:t,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let o=(0,p.useQueryClient)(),{account:s}=X(),{network:c}=$(),{refresh:l}=qe(e+`.`+t,s?.address??``),u=(0,r.useCallback)(()=>Ze(e,t,a,s,c),[e,t,a,s,c]),d=(0,r.useCallback)(async()=>{let r=`${e}.${t}`;await Je(o,s?.address??``,r,e,t,c.type),l(),n?.()},[n,e,t,o,s,c.type,l]),f=Kn({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())}},$e=e=>e.endsWith(`veworld.vet`),et=v.VetDomainsReverseRegistrar__factory.createInterface(),tt=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.vt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:et.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:et.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.vt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.U(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},nt=({domain:e,onSuccess:t,onError:n,alreadyOwned:i=!1})=>{let{network:a}=$(),o=(0,p.useQueryClient)(),{account:s}=X(),{refresh:c}=qe(e,s?.address??``),l=(0,r.useCallback)(()=>tt(e,i,s,a),[e,i,s,a]),u=(0,r.useCallback)(async()=>{await Je(o,s?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,a.type),c(),t?.()},[t,e,o,s,a.type,c]),d=Kn({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())}},rt=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],it=s.ABIContract.ofAbi(v.VeworldSubdomainClaimer__factory.abi),at=async(e,n,r)=>{let i=t.vt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,it.abi).read.isDomainProtected(r))[0]},ot=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:rt(e),queryFn:()=>at(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})},st=b.z.object({name:b.z.string()}),ct=b.z.object({domains:b.z.array(st)}),lt=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.vt(e).graphQlIndexerUrl,a=`query Registrations {
114
114
  domains(
115
115
  where: ${r?`{owner: "${n.toLowerCase()}", parent_: {name: "${r}"}}`:`{owner: "${n.toLowerCase()}"}`}
116
116
  ) {
117
117
  name
118
118
  }
119
- }`,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`))),ct.parse(s.data)},ut=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,e,t],dt=(e,t)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ut(e,t),queryFn:()=>lt(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})},ft=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,e,t],pt=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:ft(e??``,t.type),queryFn:async()=>e?(0,_.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})},mt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) view returns (string)`]),ht=async(e,n,r)=>{if(!r)return{};let i=(0,o.namehash)(r);try{let[{data:r,reverted:a}]=await(await fetch(`${e}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.vt(n).vetDomainsContractAddress,data:mt.encodeFunctionData(`resolver`,[i])}]})})).json();if(a)return{};let{resolverAddress:o}=mt.decodeFunctionResult(`resolver`,r);return(await(await fetch(`${e}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:t.x.map(e=>({to:o,data:mt.encodeFunctionData(`text`,[i,e])}))})})).json()).reduce((e,{data:n,reverted:r},i)=>{if(!r&&n&&n!==`0x`)try{let r=mt.decodeFunctionResult(`text`,n)[0];r&&(e[t.x[i]]=r)}catch(e){console.error(`Failed to decode text record for ${t.x[i]}:`,e)}return e},{})}catch(e){throw console.error(`Error fetching text records:`,e),e}},gt=(e,t)=>[`VECHAIN_KIT_TEXT_RECORDS`,e,t],_t=e=>{let{network:n}=$(),r=n.nodeUrl??t.vt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:gt(e,n.type),queryFn:()=>ht(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})},vt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function setText(bytes32 node, string key, string value) external`]),yt=(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:vt.encodeFunctionData(`setText`,[t,i,a]),value:`0`,comment:`Update ${i} record`})}return n},bt=({onSuccess:e,onError:t,signerAccountAddress:n,resolverAddress:i}={})=>{let a=(0,r.useCallback)(e=>{if(!i)throw Error(`Resolver address is required`);return yt(i,e)},[i]),o=Kn({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))}},xt=e=>[`VECHAIN_KIT`,`RESOLVER_ADDRESS`,e],St=e=>{let{network:n}=$();return Jo({address:t.vt(n.type).vetDomainsContractAddress,abi:v.VetDomainsRegistry__factory.abi,method:`resolver`,args:[e?(0,y.namehash)(e):`0x`],queryOptions:{select:e=>e[0],enabled:!!e}})},Ct={Mugshot:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/mugshot.png`,Greencart:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/greencart.png`,Cleanify:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/cleanify.png`,EVearn:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/evearn.png`},wt=`vechain_kit_cross_app_connection`,Tt=()=>{let e=t.lt(`vechain_kit_cross_app_connection`);if(!e)return null;try{let t=JSON.parse(e)?.ecosystemApp?.name;return t?Ct[t]??null:null}catch{return null}},Et=e=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR_OF_ADDRESS`,e],Dt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Et(e),queryFn:async()=>{if(!e||!n.nodeUrl)return Tt()??t.H(e??``);let r=await(0,_.getAddressDomain)(e,{networkUrl:n.nodeUrl});return r&&await(0,_.getAvatar)(r,{networkUrl:n.nodeUrl})||(Tt()??t.H(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})},Ot=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) returns (string avatar)`]),kt=new o.Interface([`function tokenURI(uint256 tokenId) view returns (string)`,`function uri(uint256 id) view returns (string)`]),At=async(e,n,r)=>{if(!r)throw Error(`Name is required`);let i=(0,o.namehash)(r);try{let[{data:r,reverted:a}]=await(await fetch(`${n}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.vt(e).vetDomainsContractAddress,data:Ot.encodeFunctionData(`resolver`,[i])}]})})).json();if(a)return null;let{resolverAddress:o}=Ot.decodeFunctionResult(`resolver`,r),[{data:s,reverted:c}]=await(await fetch(`${n}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:o,data:Ot.encodeFunctionData(`text`,[i,`avatar`])}]})})).json();if(c||s===`0x`)return null;try{let{avatar:t}=Ot.decodeFunctionResult(`text`,s),r=t===``?null:t;return r?Mt(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}},jt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,`LEGACY`,e,t];async function Mt(e,n,r){try{if(e.startsWith(`http`)||e.startsWith(`ipfs://`)||e.startsWith(`ar://`))return t.h(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:kt.encodeFunctionData(l?`uri`:`tokenURI`,[BigInt(c||0)])}],[{data:d,reverted:f}]=await fetch(`${r}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:u})}).then(e=>e.json());if(f)return console.error(`Failed to fetch tokenURI`),null;let p=``;try{p=kt.decodeFunctionResult(l?`uri`:`tokenURI`,d)[0]}catch(e){console.error(`Failed to decode avatar data:`,e),p=(0,o.toUtf8String)(d)}p=t.h(p,n)||p,l&&(p=p.replace(`{id}`,(0,o.zeroPadValue)((0,o.toBeHex)(BigInt(c||0)),32).slice(2)));let m=await fetch(p);if(!m.ok)return console.error(`Failed to fetch metadata`),null;let h=await m.json(),g=h.image||h.image_url||h.image_data;return g?t.h(g,n)||g:(console.error(`No image URL in metadata`),null)}return null}catch(e){return console.error(`Error parsing avatar record:`,e),null}}const Nt=e=>{let{network:n}=$(),r=n.nodeUrl??t.vt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:jt(e??``,n.type),queryFn:async()=>e?At(n.type,r,e):null,enabled:!!e&&!!r&&!!n.type})},Pt=v.VetDomainsReverseRegistrar__factory.createInterface(),Ft=(e,n)=>{let r=[];return r.push({to:t.vt(n.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Pt.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.U(e?.address??``,4,4)}`,abi:Pt.getFunction(`setName`)}),r},It=({onSuccess:e,onError:t})=>{let n=(0,p.useQueryClient)(),{account:i}=X(),{network:a}=$(),o=(0,r.useCallback)(()=>Ft(i,a),[i,a]),s=(0,r.useCallback)(async()=>{await Je(n,i?.address??``,``,``,``,a.type),e?.()},[e,n,i,a.type]),c=Kn({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())}},Lt=e=>{let{network:n}=$(),i=t.vt(n.type),{data:a,isLoading:o}=rs(e),{data:s,isLoading:c}=rn(e),{data:l,isLoading:u}=un(e),{data:d,isLoading:f}=cn(i.veDelegateTokenContractAddress,e),{data:p,isLoading:m}=cn(i.gloDollarContractAddress,e),h=on(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||_}},Rt={B3TR:`0x623374722d757364000000000000000000000000000000000000000000000000`,VET:`0x7665742d75736400000000000000000000000000000000000000000000000000`,VTHO:`0x7674686f2d757364000000000000000000000000000000000000000000000000`,GBP:`0x6762702d75736400000000000000000000000000000000000000000000000000`,EUR:`0x657572742d757364000000000000000000000000000000000000000000000000`},zt=async(e,n,r)=>{let i=await e.contracts.load(t.vt(r).oracleContractAddress,v.OracleVechainEnergy__factory.abi).read.getLatestValue(Rt[n]);if(!i)throw Error(`Failed to get price of ${n}`);return new a.BigNumber(i[0].toString()).div(0xe8d4a51000).toNumber()},Bt=e=>[`VECHAIN_KIT_PRICE`,e],Vt=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Bt(e),queryFn:async()=>zt(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})},Ht=()=>{let{network:e}=$(),n=t.vt(e.type),{data:i,isLoading:a}=Vt(`VET`),{data:o,isLoading:s}=Vt(`VTHO`),{data:c,isLoading:l}=Vt(`B3TR`),{data:u,isLoading:d}=Vt(`EUR`),{data:f,isLoading:p}=Vt(`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}},Ut=`vechain_kit_currency`,Wt=[`usd`,`eur`,`gbp`],Gt=()=>{let{currentCurrency:e,setCurrency:n}=$();return(0,r.useEffect)(()=>{t._t(`vechain_kit_currency`,e)},[e]),{currentCurrency:e,allCurrencies:Wt,changeCurrency:e=>{if(!Wt.includes(e)){console.error(`Invalid currency: ${e}`);return}n(e)}}},Kt=({address:e=``})=>{let{balances:t,isLoading:n}=Lt(e),{prices:i,exchangeRates:a,isLoading:o}=Ht(),{currentCurrency:s}=Gt(),c=(0,r.useMemo)(()=>t.map(e=>{let t=i[e.address]||0,n=Number(e.balance)*t,r=Pe(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}=Kt({address:e}),{currentCurrency:i}=Gt(),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)(()=>Ie(a,{currency:i}),[a,i]),isLoading:n,hasAnyBalance:t.length>0}},Jt=v.XAllocationVoting__factory.abi,Yt=`currentRoundId`,Xt=e=>Go({abi:Jt,address:e,method:Yt}),Zt=()=>{let{network:e}=$(),n=t.vt(e.type).xAllocationVotingContractAddress;return Jo({abi:Jt,address:n,method:Yt,args:[],queryOptions:{select:e=>e[0].toString()}})},Qt=async(e,t)=>(0,_.getTokenInfo)(e,{networkUrl:t}),$t=e=>[`VECHAIN_KIT_CUSTOM_TOKEN_INFO`,e],en=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:$t(e),queryFn:async()=>{if(!e)throw Error(`Token address is required`);if(!t.nodeUrl)throw Error(`Network node URL is required`);return Qt(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})},tn=()=>{let[e,n]=lc(cc.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 Qt(t,r.nodeUrl),address:t};n([...e,i])}},a=t=>{n(e.filter(e=>e.address!==t))},o=n=>e.some(e=>t.O(e.address,n)),s=e=>{let n={vet:`0x`,vtho:t.vt(r.type).vthoContractAddress,b3tr:t.vt(r.type).b3trContractAddress,vot3:t.vt(r.type).vot3ContractAddress,veDelegate:t.vt(r.type).veDelegate};return Object.values(n).includes(e)};return{customTokens:e,addToken:i,removeToken:a,isTokenIncluded:o,isDefaultToken:s}},nn=e=>[`VEBETTERDAO_BALANCE`,e,`B3TR`],rn=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:nn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,_.getB3trBalance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get b3tr balance`);let i=r[0];return t.V(i)},enabled:!!e&&!!n.type})},an=(e,t)=>[`VECHAIN_KIT_BALANCE`,t,`CUSTOM_TOKEN`,e],on=e=>{let{network:n}=$(),{customTokens:r}=tn();return(0,p.useQueries)({queries:r.map(r=>({queryKey:an(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,_.getErc20Balance)(r.address,e,{networkUrl:n.nodeUrl});if(!i)throw Error(`Failed to get token balance`);let a=t.V(i[0]);return{...r,...a}}}))})},sn=(e,t)=>[`VECHAIN_KIT`,`BALANCE`,`ERC20`,e,t],cn=(e,n)=>{let{network:r}=$();return(0,p.useQuery)({queryKey:sn(e,n),queryFn:async()=>{if(!n)throw Error(`Address is required`);let i=await(0,_.getErc20Balance)(e,n,{networkUrl:r.nodeUrl});if(!i)throw Error(`Failed to get vot3 balance`);let a=i[0];return t.V(a)},enabled:!!n&&!!r.type})},ln=e=>[`VEBETTERDAO_BALANCE`,e,`VOT3`],un=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ln(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,_.getVot3Balance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get vot3 balance`);let i=r[0];return t.V(i)},enabled:!!e&&!!n.type})},dn=(e,t)=>[`VECHAIN_KIT`,`IS_PERSON`,e,t],fn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:dn(e??``,t.type),queryFn:async()=>{if(!e)throw Error(`User address is required`);return(0,_.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})},pn=v.XAllocationVoting__factory.abi,mn=`getAppsOfRound`,hn=(e,n)=>qo({abi:pn,address:t.vt(n).xAllocationVotingContractAddress,method:mn,args:[BigInt(e??0)]}),gn=e=>{let{network:n}=$(),r=t.vt(n.type).xAllocationVotingContractAddress;return Jo({abi:pn,address:r,method:mn,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()}))}})},_n=v.XAllocationPool__factory.abi,vn=`getAppShares`,yn=e=>[`VECHAIN_KIT`,`XApps`,`Shares`,e],bn=(e,n)=>{let r=(0,f.useThor)(),{network:i}=$(),a=t.vt(i.type).xAllocationPoolContractAddress;return(0,p.useQuery)({queryKey:yn(n),queryFn:async()=>(await t.r({thor:r,calls:e.map(e=>({abi:_n,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})},xn=e=>{let{data:t}=gn(e),n=bn(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}},Sn=({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 C.isMobile&&a&&!t.a(a)?Error(n):a&&t.a(a)?Error(r):e instanceof Error?e:Error(i)},Cn=(0,y.defineChain)({id:`1176455790972829965191905223412607679856028701100105089447013101863`,name:`Vechain`,nativeCurrency:{name:`VeChain`,symbol:`VET`,decimals:18},rpcUrls:{default:{http:[`https://mainnet.vechain.org`]}},blockExplorers:{default:{name:`Vechain Explorer`,url:`https://explore.vechain.org`},vechainStats:{name:`Vechain Stats`,url:`https://vechainstats.com`}}}),wn=()=>(0,S.toPrivyWalletConnector)({id:t.rt,name:`VeChain`,iconUrl:`https://imagedelivery.net/oHBRUd2clqykxgDWmeAyLg/661dd77c-2f9d-40e7-baa1-f4e24fd7bf00/icon`,smartWalletMode:!1}),Tn=({privyEcosystemAppIDS:e,children:t})=>(0,i.jsx)(x.WagmiProvider,{config:(0,r.useRef)((0,x.createConfig)({chains:[Cn],ssr:!0,connectors:[wn(),...e.map(e=>(0,S.toPrivyWalletConnector)({id:e,name:``,iconUrl:``}))],transports:{[Cn.id]:(0,x.http)()},multiInjectedProviderDiscovery:!1})).current,children:t}),En=()=>{let{connectAsync:e,connectors:n}=(0,x.useConnect)(),{signTypedDataAsync:i}=(0,x.useSignTypedData)(),{signMessageAsync:a}=(0,x.useSignMessage)(),{disconnectAsync:o}=(0,x.useDisconnect)(),{isConnected:s}=(0,x.useAccount)(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{try{s&&(await o(),t.ft()&&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.rt));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 Sn({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 Sn({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}},Dn=(e,n)=>{let{data:r,isLoading:i}=Ue(e??``),{data:a,isLoading:o}=Dt(e??``),{data:s,isLoading:c}=_t(r?.domain??``),l=s?.header?t.h(s.header,n):null;return{domain:r?.domain,image:a,records:{...s,header:l},isLoading:i||o||c}},X=()=>{let{address:e,isConnected:n,isConnecting:i,isReconnecting:a}=(0,x.useAccount)(),{logout:o}=En(),{loading:s}=(0,u.useLoginWithOAuth)({}),{feeDelegation:c,network:l,privy:d}=$(),{user:p,authenticated:m,logout:h,ready:g}=(0,u.usePrivy)(),{data:_}=Hs(),{account:v,disconnect:y}=(0,f.useWallet)(),{getConnectionCache:b,clearConnectionCache:S}=Fo(),C=b(),w=Qo(),T=!!v,E=m&&!!p,D=E||n,O=E&&d?.appId===t.rt||n&&C?.ecosystemApp?.appId===t.rt,k=i||a||s||!g,[A,j]=(0,r.useState)(!1),M=n?{type:`privy-cross-app`,displayName:`Ecosystem`}:T?{type:`wallet`,displayName:`Wallet`}:{type:`privy`,displayName:`Social Login`};(0,r.useEffect)(()=>{let e=T||E||n;A!==e&&(j(e),e||(S(),t.ft()&&window.dispatchEvent(new Event(`wallet_disconnected`))))},[T,E,n,S,A]);let N=p?.linkedAccounts?.find(e=>e.type===`wallet`&&e.connectorType===`embedded`)?.address,P=T?v:n?e:N,{data:F}=Os(P),I=T?v:F?.address,L=Dn(I??``,l.type),R=Dn(P??``,l.type),z=Dn(F?.address??``,l.type),B=I?{address:I,domain:L.domain,image:L.image,isLoadingMetadata:L.isLoading,metadata:L.records}:null,V=P?{address:P,domain:R.domain,image:R.image,isLoadingMetadata:R.isLoading,metadata:R.records}:null,{data:ee}=hs(F?.address??``,V?.address??``),te=!!F?.address&&!!B?.address&&t.O(F?.address,B?.address),ne=(0,r.useCallback)(async()=>{try{j(!1),T?y():E?await h():n&&await o(),S(),t.ft()&&window.dispatchEvent(new Event(`wallet_disconnected`))}catch(e){console.error(`Error during disconnect:`,e)}},[T,y,E,h,n,o,S]);return{account:B,smartAccount:{address:F?.address??``,domain:z.domain,image:z.image,isDeployed:F?.isDeployed??!1,isActive:te,version:ee?.version??null,isLoadingMetadata:z.isLoading,metadata:z.records},connectedWallet:V,privyUser:p,connection:{isLoading:k,isConnected:A,isConnectedWithSocialLogin:E,isConnectedWithDappKit:T,isConnectedWithCrossApp:n,isConnectedWithPrivy:D,isConnectedWithVeChain:O,source:M,isInAppBrowser:(t.ft()&&window.vechain&&window.vechain.isInAppBrowser)??!1,nodeUrl:w,delegatorUrl:c?.delegatorUrl,chainId:_,network:l.type},disconnect:ne}},On=()=>{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`]})])}}},kn=async(e,n)=>{let r=t.h(e,n)||``,i=await fetch(r,{signal:AbortSignal.timeout(2e4)});if(!i.ok)throw Error(`HTTP error! status: ${i.status}`);return await i.json()},An=v.X2EarnApps__factory.abi,jn=e=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:[`xAppMetaData`,e],queryFn:async()=>{let i=t.vt(r.type).x2EarnAppsContractAddress,a=n.contracts.load(i,An),o=(await a.read.app(e))[0][3]?.toString()||``,[s]=await a.read.baseURI();return await kn(`${s}${o}`,r.type)},enabled:!!e})},Mn=async(e,n,r=!1)=>{if(!n)throw Error(`No URI provided`);let i=t.h(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},Nn=(e,t)=>[`VECHAIN_KIT`,`IPFS_METADATA`,e,t],Pn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Nn(n.type,e),queryFn:()=>Mn(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})},Fn=1024*1024*10,In=async(e,n)=>{if(!n)throw Error(`IPFS URI is required`);let r=await fetch(t.h(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>Fn)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.g(i.type)})},r.onerror=()=>{n(Error(`Error occurred while reading blob.`))}})},Ln=(e,t)=>[`VECHAIN_KIT`,`IPFS_IMAGE`,e,t],Rn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:Ln(t.type,e),queryFn:()=>In(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})},zn=e=>{let{network:t}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Ln(t.type,e),queryFn:()=>In(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}))})},Bn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Nn(n.type,e),queryFn:async()=>Mn(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}))})},Vn={maxSizeMB:.4,maxWidthOrHeight:1920,useWebWorker:!0},Hn=async e=>{let t=[];try{for(let n of e){let e=await(0,w.default)(n.file,Vn);t.push(e)}return t}catch(e){throw console.error(`compress error`,e),e}},Un=({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,w.default)(n,Vn));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}},Wn=({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,w.default)(n,Vn));let r={file:n,image:URL.createObjectURL(n)};return i(r),r},[e]),onRemove:a}},Gn=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)},Kn=({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=Qo(),_=qc(),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 Gn(u,[...i],e,{revision:s.Revision.NEXT,...c?{gasPadding:c}:{}})}catch(e){console.error(`Gas estimation failed`,e)}return(await p(i,{signer: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]),[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}=ec(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}},qn=(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}=Kn({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}},Jn=e=>e===`0x`||e===y.zeroAddress,Yn=(e,t,n,r)=>{let i={},a=r.toLowerCase();for(let t of e)try{let e=(0,y.decodeEventLog)({abi:v.MyERC20__factory.abi,eventName:`Transfer`,topics:t.topics,data:t.data}),n=e.args.from.toLowerCase(),r=e.args.to.toLowerCase(),o=e.args.value,s=typeof o==`bigint`?o:BigInt(o);if(n!==a&&r!==a)continue;let c=t.address.toLowerCase(),l=i[c]??{inflow:0n,outflow:0n};n===a&&(l.outflow+=s),r===a&&(l.inflow+=s),i[c]=l}catch{continue}if(n!==void 0){let e=BigInt(n);if(e>0n){let t=i[y.zeroAddress]??{inflow:0n,outflow:0n};t.outflow+=e,i[y.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[y.zeroAddress]??{inflow:0n,outflow:0n};n.inflow+=t,i[y.zeroAddress]=n}return i},Xn=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=Yn(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=Jn(e.fromTokenAddress),d=Jn(e.toTokenAddress),f=BigInt(e.amountIn);if(u){let e=c[y.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!==y.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===y.zeroAddress?`VET`:e} has outflow ${n.outflow.toString()}, expected 0`}}if(t.minimumOutputAmount&&t.minimumOutputAmount>0n)if(d){let e=c[y.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`}}},Zn=e=>e.startsWith(`0x`)?BigInt(e).toString():e,Qn=(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`}),$n=(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[Qn(t,e)]}return e},er=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,y.encodeFunctionData)({abi:$n(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`}`)}},tr=e=>{let t=er(e.functionCall);return{to:e.to,value:Zn(e.value),data:t,comment:e.comment||`Swap on aggregator`}},nr=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=await fetch(`${e.apiBaseUrl}?${r.toString()}`);if(!i.ok)throw Error(`API request failed: ${i.status} ${i.statusText}`);let a=await i.json(),o=a.clauses.map(tr),s=BigInt(a.amountOut),c=BigInt(a.amountOutMin);return{aggregatorName:e.name,aggregator:t,outputAmount:s,minimumOutputAmount:c,priceImpact:0,data:{clauses:o,path:a.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 Xn(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},rr={main:{supportedAddresses:[`0xE5fA980a6EfE5B79C2150a529da06AeF455963b6`,`0x7C755EC0165fCD926cC6faB10E7BB16a72E9f34A`]},test:{supportedAddresses:[]},solo:{supportedAddresses:[]}},ir=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,ar=e=>{let t={main:`https://vetrade.vet/api/quote/vck`,test:`https://vetrade.vet/api/quote/vck`,solo:`https://vetrade.vet/api/quote/vck`};return t[e]||t.main},or=t=>{let n=rr[t]??rr.main,i=nr({name:`VeTrade.vet`,apiBaseUrl:ar(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 Xn(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(ir(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(v.MyERC20__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}}},sr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,cr=()=>BigInt(Math.floor(Date.now()/1e3)+1200),lr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){let i=[sr(n.fromTokenAddress)?e.wrappedVET:n.fromTokenAddress,sr(n.toTokenAddress)?e.wrappedVET:n.toTokenAddress],a=BigInt(n.amountIn);try{let[o]=await r.contracts.load(e.routerAddress,v.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 Xn(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=cr();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=sr(t.fromTokenAddress),c=sr(t.toTokenAddress),l=s.ABIContract.ofAbi(v.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(v.MyERC20__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},ur={main:{routerAddress:`0xf21Dd7108D93af56FaB07423EfB90F4a3604DA89`,wrappedVET:`0xf9b02b47694fd635A413F16dC7B38aF06Cc16fe5`},test:{routerAddress:y.zeroAddress,wrappedVET:y.zeroAddress},solo:{routerAddress:y.zeroAddress,wrappedVET:y.zeroAddress}},dr=t=>{let n=ur[t]??ur.main;return lr({name:`BetterSwap.io`,routerAddress:n.routerAddress,wrappedVET:n.wrappedVET,getIcon:(t=`20px`)=>r.default.createElement(e.n,{boxSize:t})})},fr=e=>[or(e),dr(e)],pr=(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}=en(l===`0x`||l===y.zeroAddress||!l?``:l),{data:m}=en(u===`0x`||u===y.zeroAddress||!u?``:u),h=(0,r.useMemo)(()=>!l||l===`0x`||l===y.zeroAddress||!d?18:Number(d?.decimals??18),[l,d?.decimals]),g=(0,r.useMemo)(()=>!u||u===`0x`||u===y.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,y.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:b,error:x}=(0,p.useQuery)({queryKey:[`unified-swap-quotes`,_,c.network],queryFn:async()=>{if(!_||!s||!c.network)return{quotes:[],best:null};let e=fr(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:b,error:x,from:e?{...e,address:l??``,decimals:h}:null,to:t?{...t,address:u??``,decimals:g}:null}},mr=({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)(Ne,{isOpen:o,onClose:s,trapFocus:!1,children:[(0,i.jsxs)(J,{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`)})]})})]})]})},hr=()=>{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)(mr,{isOpen:d.isOpen,onClose:d.onClose,onResend:()=>s({email:a}),email:a,isLoading:c.status===`sending-code`})]})},gr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Po();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:async()=>{await a({provider:`google`})},icon:T.FcGoogle,text:r(`Continue with Google`)})})},_r=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Po();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:async()=>{await a({provider:`github`})},icon:g.LuGithub,text:r(`Continue with Github`)})})},vr=({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)(ca,{isDark:t,onClick:o,icon:t?e.b:e.x,text:a(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(pa,{})})})},yr=({isDark:t,gridColumn:a})=>{let{t:o}=(0,l.useTranslation)(),{login:s}=Io(),[c,u]=(0,r.useState)(),d=(0,n.useDisclosure)(),f=async()=>{d.onOpen();try{u(void 0),await s(),d.onClose()}catch(e){console.error(o(`Login failed:`),e),u(e instanceof Error?e.message:o(`Failed to connect with VeChain`))}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:a||4,w:`full`,children:(0,i.jsx)(ca,{isDark:t,onClick:f,icon:t?e.b:e.x,text:o(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(pa,{})})}),(0,i.jsx)(ga,{isOpen:d.isOpen,onClose:()=>{d.onClose()},onTryAgain:()=>{f()},error:c,title:o(`Connecting to VeChain`),loadingText:o(`Please approve the request in the connection request window...`)})]})},br=({isDark:e,gridColumn:t})=>{let{t:a}=(0,l.useTranslation)(),{loginWithPasskey:o}=Mo(),[s,c]=(0,r.useState)(),u=(0,n.useDisclosure)(),d=async()=>{u.onOpen();try{c(void 0),await o(),u.onClose()}catch(e){(e instanceof Error?e.message.toLowerCase():``).includes(`not found`)&&(console.error(e),c(e instanceof Error?e.message:a(`Failed to connect with Passkey`)))}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:t,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:d,icon:g.LuFingerprint,text:t&&t>=2?a(`Passkey`):void 0})}),(0,i.jsx)(ga,{isOpen:u.isOpen,onClose:()=>{u.onClose()},error:s,title:a(`Connecting with Passkey`),loadingText:a(`Please complete the passkey authentication...`),onTryAgain:()=>{d()}})]})},xr=({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]),(0,i.jsx)(n.GridItem,{colSpan:a||2,w:`full`,children:(0,i.jsx)(ca,{isDark:t,onClick:()=>{s()},icon:u?.allowedWallets?.includes(`sync2`)?g.LuWallet:t?e.o:e.a,iconWidth:`27px`,text:a>=2?p:void 0,rightIcon:u?.allowedWallets?.includes(`sync2`)&&(0,i.jsx)(n.Icon,{as:g.LuArrowRight})||void 0})})},Sr=({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)(ca,{isDark:e,onClick:t,icon:g.LuEllipsis,text:r&&r>=2?a(`More`):void 0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowRight})})})},Cr=()=>{let{loginMethods:e,darkMode:t}=$(),{login:r}=(0,u.usePrivy)(),{showGoogleLogin:a,showEmailLogin:o,showPasskey:s,showVeChainLogin:c,showDappKit:l,showMoreLogin:d,showGithubLogin:f,isOfficialVeChainApp:p}=To();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:e?.map(({method:e,gridColumn:n})=>{switch(e){case`email`:return o&&(0,i.jsx)(hr,{},`email`);case`google`:return a&&(0,i.jsx)(gr,{isDark:t,gridColumn:n},`google`);case`github`:return f&&(0,i.jsx)(_r,{isDark:t,gridColumn:n},`github`);case`vechain`:return c&&(p?(0,i.jsx)(vr,{isDark:t,gridColumn:n},`vechain`):(0,i.jsx)(yr,{isDark:t,gridColumn:n},`vechain`));case`passkey`:return s&&(0,i.jsx)(br,{isDark:t,gridColumn:n},`passkey`);case`dappkit`:return l&&(0,i.jsx)(xr,{isDark:t,gridColumn:n},`dappkit`);case`more`:return d&&(0,i.jsx)(Sr,{isDark:t,onViewMoreLogin:r,gridColumn:n},`more`);default:return null}})})})},wr=({appsInfo:e,isLoading:t})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useDisclosure)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Button,{fontSize:`sm`,variant:`link`,onClick:()=>{a.onOpen()},children:r(`Already have an x2earn app wallet?`)}),(0,i.jsx)(ba,{isOpen:a.isOpen,onClose:a.onClose,appsInfo:e,isLoading:t})]})},Tr=({setCurrentContent:e,onClose:t})=>{let{t:a}=(0,l.useTranslation)(),{connection:o}=X(),{loginModalUI:s,darkMode:c}=$(),{loginMethods:u,privyEcosystemAppIDS:d}=$(),{data:f,isLoading:p}=Be(d),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=()=>{e(`faq`)};(0,r.useEffect)(()=>{o.isConnected&&t()},[o.isConnected,t]);let g=u?.some(({method:e})=>e===`ecosystem`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(wc,{onClick:h}),(0,i.jsx)(n.ModalHeader,{children:a(`Log in or sign up`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),s?.logo&&(0,i.jsx)(n.HStack,{justify:`center`,children:(0,i.jsx)(n.Image,{src:s.logo||`/images/favicon.png`,maxW:`180px`,maxH:`90px`,m:8,alt:`logo`})}),(0,i.jsxs)(n.ModalBody,{children:[s?.description&&(0,i.jsx)(n.HStack,{spacing:4,w:`full`,justify:`center`,mb:`24px`,px:4,children:(0,i.jsx)(n.Text,{color:m,fontSize:`sm`,textAlign:`center`,children:s?.description})}),(0,i.jsx)(Cr,{})]}),g?(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(wr,{isDark:c,appsInfo:Object.values(f||{}),isLoading:p})})}):(0,i.jsx)(n.ModalFooter,{pt:0,pb:`5px`})]})},Er=({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}=js(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":`Notifications`,size:`sm`,variant:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,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})},Dr=({setCurrentContent:e,wallet:t,onClose:r})=>{let{t:a}=(0,l.useTranslation)(),{network:o}=$();return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(Er,{onClick:()=>{e(`settings`)},"data-testid":`settings-button`}),(0,i.jsxs)(n.ModalHeader,{children:[a(`Wallet`),o?.type!==`main`&&(0,i.jsx)(n.Tag,{size:`xs`,colorScheme:`orange`,fontSize:`2xs`,p:1,ml:1,textTransform:`uppercase`,children:`${o?.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:6,children:[(0,i.jsx)(Kr,{style:{justifyContent:`flex-start`},onClick:()=>{e(`profile`)},setCurrentContent:e,onClose:r,wallet:t}),(0,i.jsx)(Jr,{onAssetsClick:()=>{e(`assets`)}}),(0,i.jsx)(Zr,{setCurrentContent:e})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Or=({onSelectToken:e,onBack:t,showAllTokens:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s}=$(),{currentCurrency:c}=Gt(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{account:p}=X(),{tokensWithBalance:m,sortedTokens:h}=Kt({address:p?.address??``}),[_,v]=(0,r.useState)(``),y=(0,r.useMemo)(()=>{if(a){let e=h.filter(e=>Number(e.balance)>0),t=[...h.filter(e=>Number(e.balance)===0)].sort((e,t)=>e.symbol.localeCompare(t.symbol));return[...e,...t]}return m},[a,h,m]).filter(({symbol:e})=>e.toLowerCase().includes(_.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:o(`Select Token`)}),(0,i.jsx)(q,{onClick:t}),(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:s?`vechain-kit-overlay`:`vechain-kit-card`,borderRadius:`xl`,height:`56px`,pl:12,value:_,onChange:e=>v(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:f})})]}),(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:u,mt:4,children:o(a?`All tokens`:`Your tokens`)}),y.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,color:f}),(0,i.jsx)(n.Text,{fontSize:`lg`,color:u,children:o(`No tokens found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:d,children:o(`Try searching with a different term`)})]}):(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:y.map(t=>(0,i.jsx)(Le,{symbol:t.symbol,amount:Number(t.balance),currencyValue:t.valueInCurrency,currentCurrency:c,onClick:()=>e(t)},t.address))})]})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},kr=()=>{let{isolatedView:e,closeAccountModal:t}=Q();return{isolatedView:e,closeAccountModal:t}},Ar=({setCurrentContent:e,preselectedToken:a,initialAmount:s=``,initialToAddressOrDomain:c=``,onBack:u=()=>e(`main`)})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f,feeDelegation:p}=$(),{currentCurrency:m}=Gt(),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}=Ht(),{account:S}=X(),{isolatedView:C}=kr(),{tokensWithBalance:w}=Kt({address:S?.address??``}),[T,O]=(0,r.useState)(a??w[0]??null),[k,A]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!a&&!T&&w.length>0&&O(w[0])},[w,a,T]);let{register:j,watch:M,setValue:N,setError:P,formState:{errors:F,isValid:I},handleSubmit:L}=(0,E.useForm)({defaultValues:{amount:s,toAddressOrDomain:c},mode:`onChange`}),{toAddressOrDomain:R,amount:z}=M(),B=(0,r.useRef)(T);(0,r.useEffect)(()=>{B.current&&T&&B.current.address!==T.address&&N(`amount`,``),B.current=T},[T,N]);let V=(0,r.useMemo)(()=>T?Ie(Pe(Number(z)*T.priceUsd,m,x),{currency:m}):``,[z,T,m,x]),{data:ee,isLoading:te}=Ue(R),ne=()=>{T&&N(`amount`,T.balance)},re=()=>{u()},H=async t=>{if(T){if(!(ee?.isValidAddressOrDomain&&(!ee?.domain||ee?.domain&&ee?.isPrimaryDomain))){P(`toAddressOrDomain`,{type:`manual`,message:d(`Invalid address or domain`)});return}if(T){let e=(0,o.parseEther)(t.amount),n=p?.b3trTransfers?.minAmountInEther;if(T.symbol===`B3TR`&&typeof n==`number`&&n>0)try{if(e<(0,o.parseEther)(String(n))){P(`amount`,{type:`manual`,message:d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:T.symbol,min:n})});return}}catch{}if(e>(0,o.parseEther)(T.balance)){P(`amount`,{type:`manual`,message:d(`Insufficient {{symbol}} balance`,{symbol:T.symbol})});return}}e({type:`send-token-summary`,props:{toAddressOrDomain:t.toAddressOrDomain,resolvedDomain:ee?.domain,resolvedAddress:ee?.address,amount:t.amount,selectedToken:T,formattedTotalAmount:V,setCurrentContent:e}})}};return k?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:e=>{O(e),A(!1)},onBack:()=>{A(!1)}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Send`)}),!C&&(0,i.jsx)(q,{onClick:re}),(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:ne,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:_,children:[d(`Balance`),`:`,` `,Number(T?.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:6,borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!F.amount,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{...j(`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 T?.symbol===`B3TR`&&typeof n==`number`&&n>0&&t<n?d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:T.symbol,min:n}):!0}}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,N(`amount`,t,{shouldValidate:!0})},placeholder:`0`,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`tx-amount-input`,type:`number`,inputMode:`decimal`,color:h}),T?(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`},onClick:()=>A(!0),leftIcon:t.Q[T.symbol]?r.default.cloneElement(t.Q[T.symbol],{boxSize:`20px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.Z[T.symbol],alt:`${T.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:T.symbol.slice(0,3)})})}),children:[T.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:()=>A(!0),children:[d(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]})]}),T&&(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:_,children:(0,i.jsxs)(n.Text,{color:_,children:[`≈ `,V]})}),F.amount&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,mt:1,"data-testid":`amount-error-msg`,children:F.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:6,width:`100%`,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!F.toAddressOrDomain,children:[(0,i.jsx)(n.Input,{...j(`toAddressOrDomain`,{required:d(`Address is required`)}),onChange:e=>{let t=e.target.value.trim(),n=t.includes(`.`)?(0,D.ens_normalize)(t):t;e.target.value=n,N(`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`}),F.toAddressOrDomain&&(0,i.jsx)(n.Text,{color:y,fontSize:`sm`,"data-testid":`address-error-msg`,children:F.toAddressOrDomain.message})]})})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!T||!I,isLoading:te,onClick:L(H),"data-testid":`send-button`,children:d(T?`Send`:`Select Token`)})})]})},jr=({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}=Dt(s??``),{network:_,feeDelegation:v}=$(),{preferences:y}=bc(),{isolatedView:b,closeAccountModal:x}=kr(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w}=js(p?.address??``,h?.address??``,3),{open:T}=Eo(),E=(0,r.useMemo)(()=>g||t.H(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=t=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:f(`Transaction successful`),onDone:()=>{b?x():e(`main`)},showSocialButtons:!0}})},{sendTransaction:k,txReceipt:A,error:j,isWaitingForWalletConfirmation:M,isTransactionPending:N,clauses:P}=Js({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,tokenAddress:u.address,tokenName:u.symbol,onSuccess:()=>{O(A?.meta.txID??``)},onError:e=>{re(e??``)}}),{sendTransaction:F,txReceipt:I,error:L,isWaitingForWalletConfirmation:R,isTransactionPending:z,clauses:B}=Xs({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,onSuccess:()=>{O(I?.meta.txID??``)},onError:e=>{re(e??``)}}),V=()=>u.symbol===`VET`?I:A,ee=M||R,te=ee||N||z,ne=()=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:u,initialAmount:c,initialToAddressOrDomain:a}})},re=e=>{console.error(`Transaction failed:`,e)},[H,ie]=r.default.useState(null),[ae,U]=r.default.useState(null),oe=y.availableGasTokens.length>0&&(m.isConnectedWithPrivy||m.isConnectedWithVeChain)&&!v?.delegatorUrl,{data:se,isLoading:W,error:ce,refetch:le}=xc({clauses:u.symbol===`VET`?B:P,tokens:H?[H]:y.availableGasTokens,sendingAmount:c,sendingTokenSymbol:u.symbol,enabled:oe&&!!v?.genericDelegatorUrl}),ue=se?.usedToken,G=(W||!se)&&m.isConnectedWithPrivy&&!v?.delegatorUrl,de=r.default.useCallback(e=>{ie(e),U(e),setTimeout(()=>le(),100)},[le]),fe=!!ue&&!ce;return r.default.useEffect(()=>{ce&&H&&ie(null)},[ce,H]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:`Send`}),(0,i.jsx)(q,{isDisabled:te,onClick:ne}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:te})]}),(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.jsx)(Cc,{label:f(`From`),address:p?.address??``,domain:p?.domain,imageSrc:p?.image??``,imageAlt:`From account`,balance:Number(u.balance),tokenAddress:u.address}),(0,i.jsx)(Cc,{label:f(`To`),address:s||a,domain:o,imageSrc:E??``,imageAlt:`To account`,tokenAddress:u.address}),m.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:se,isLoading:W,isLoadingTransaction:te,onTokenChange:de,clauses:u.symbol===`VET`?B:P,userSelectedToken:ae}),(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)(Dc,{transactionError:u.symbol===`VET`?L:j,isSubmitting:te,isTxWaitingConfirmation:ee,onConfirm:D,transactionPendingText:f(`Sending...`),txReceipt:V(),buttonText:f(`Confirm`),isDisabled:te||G,gasEstimationError:ce,hasEnoughGasBalance:fe,isLoadingGasEstimation:W,showGasEstimationError:!v?.delegatorUrl&&m.isConnectedWithPrivy,context:`send`})})]})},Mr=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{account:r}=X(),{isolatedView:a}=kr(),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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Receive`)}),!a&&(0,i.jsx)(q,{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)(O.QRCode,{value:r?.address??``,size:200,removeQrCodeBehindLogo:!0,eyeRadius:4,logoPaddingStyle:`circle`,style:{borderRadius:`16px`}}),(0,i.jsx)(De,{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})]})]})},Nr=({quotes:e,selectedQuote:a,toTokenAddress:o,onSelectQuote:s,onBack:c})=>{let{t:u}=(0,l.useTranslation)(),{darkMode:d}=$(),{currentCurrency:f}=Gt(),{account:p}=X(),{exchangeRates:m,prices:h}=Ht(),{tokens:_}=Kt({address:p?.address??``}),[v,b]=(0,r.useState)(!1),x=(0,r.useMemo)(()=>o&&_.find(e=>t.O(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,y.formatEther)(BigInt(t.outputAmount||`0`)),r=Number(n)*e,i=Pe(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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:u(`Found following rates`)}),(0,i.jsx)(q,{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.Q[x.symbol]?r.default.cloneElement(t.Q[x.symbol],{boxSize:`24px`,borderRadius:`full`}):t.Z[x.symbol]?(0,i.jsx)(n.Image,{src:t.Z[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:[`≈ `,Ie(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:()=>b(!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,{})]})},Pr=e=>e===`0x`||e===y.zeroAddress||!e,Fr=(e,t,n,r)=>{if(!e||!t||!n||!r)return null;let i=t.toLowerCase(),a=n.toLowerCase(),o=r.toLowerCase(),s=Pr(n),c=Pr(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=v.MyERC20__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,y.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}},Ir=({setCurrentContent:e,fromTokenAddress:a,toTokenAddress:o})=>{let{t:s}=(0,l.useTranslation)(),{account:c,connection:u}=X(),{currentCurrency:d}=Gt(),{network:f,feeDelegation:p,darkMode:m}=$(),{isolatedView:h,closeAccountModal:_}=kr(),v=(0,n.useToken)(`colors`,`vechain-kit-card`),b=(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`),{preferences:C}=bc(),{sortedTokens:w}=Kt({address:c?.address??``}),[T,E]=(0,r.useState)(`main`),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),[j,M]=(0,r.useState)(``),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(1),[L,R]=(0,r.useState)(`1`),[z,B]=(0,r.useState)(null),[V,ee]=r.default.useState(null),[te,ne]=r.default.useState(null),[re,H]=r.default.useState([]),{prices:ie,exchangeRates:ae}=Ht(),U=F===1;r.default.useEffect(()=>{R(F===1?`1`:F===.5?`0.5`:F===3?`3`:F.toString())},[F]),r.default.useEffect(()=>{if(w.length!==0){if((a||o)&&(!D||!k)){if(a&&!D){let e=w.find(e=>t.O(e.address,a));e&&O(e)}if(o&&!k){let e=w.find(e=>t.O(e.address,o));e&&A(e)}return}if(!D&&!k){let e=w.find(e=>e.symbol===`VET`);e&&O(e);let n=w.find(e=>e.symbol===`B3TR`);if(!n)try{let e=t.vt(f.type).b3trContractAddress;e&&(n=w.find(n=>t.O(n.address,e)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}n&&A(n)}}},[w,D,k,a,o,f.type]),r.default.useEffect(()=>{B(null)},[D?.address,k?.address,j]);let{bestQuote:oe,quotes:se,isLoading:W,from:ce,to:le}=pr(D,k,j,c?.address??``,F,!!D&&!!k&&Number(j)>0),ue=(0,r.useMemo)(()=>{if(!j||Number(j)<=0||!ce)return 0n;try{return(0,y.parseUnits)(j,ce.decimals)}catch{return 0n}},[j,ce?.decimals]),G=z||oe,de=(0,r.useMemo)(()=>{if(!G?.outputAmount||!le)return`0`;try{return(0,y.formatUnits)(G.outputAmount,le.decimals)}catch{return`0`}},[G,le?.decimals]),fe=(0,r.useMemo)(()=>{if(!D||!j)return 0;let e=ie[D.address]||0;return Pe(Number(j)*e,d,ae)},[D?.address,j,ie,d,ae]),pe=(0,r.useMemo)(()=>{if(!k||!de)return 0;let e=ie[k.address]||0;return Pe(Number(de)*e,d,ae)},[k?.address,de,ie,d,ae]),K=(0,r.useMemo)(()=>!D||!k||!c?.address||ue===0n?null:{fromTokenAddress:D.address,toTokenAddress:k.address,amountIn:ue.toString(),userAddress:c.address,slippageTolerance:F},[D,k,c?.address,ue,F]),me=G?.gasCostVTHO??0;r.default.useEffect(()=>{(async()=>{if(!G||!K||!G.aggregator){H([]);return}try{H(await G.aggregator.buildSwapTransaction(K,G))}catch(e){console.error(`Failed to build swap clauses for gas estimation:`,e),H([])}})()},[G,K]);let he=C.availableGasTokens.length>0&&(u.isConnectedWithPrivy||u.isConnectedWithVeChain)&&!p?.delegatorUrl,{data:ge,isLoading:_e,error:ve,refetch:ye}=xc({clauses:re,tokens:V?[V]:C.availableGasTokens,sendingAmount:j,sendingTokenSymbol:D?.symbol??``,enabled:he&&!!p?.genericDelegatorUrl&&re.length>0}),be=ge?.usedToken,xe=(_e||!ge)&&u.isConnectedWithPrivy&&!p?.delegatorUrl,Se=r.default.useCallback(e=>{ee(e),ne(e),setTimeout(()=>ye(),100)},[ye]),Ce=!!be&&!ve;r.default.useEffect(()=>{ve&&V&&ee(null)},[ve,V]);let{executeSwap:we,isTransactionPending:Te,isWaitingForWalletConfirmation:Ee,txReceipt:De,status:Oe,error:ke}=qn(K,G),Ae=(0,r.useCallback)(()=>{let t=De?.meta.txID??``,n=s(`Swap successful`,{defaultValue:`Swap successful`}),r;if(De&&D&&k&&c?.address){let e=Fr(De,c.address,D.address,k.address);if(e&&ce&&le)try{let t=ce.decimals,n=le.decimals,i=(0,y.formatUnits)(e.fromAmount,t),a=(0,y.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:D.symbol,toAmount:o(a),toSymbol:k.symbol,defaultValue:`You successfully swapped ${o(i)} ${D.symbol} for ${o(a)} ${k.symbol}`})}catch(e){console.warn(`Failed to format swap amounts:`,e)}}!r&&D&&k&&(r=s(`You successfully swapped {fromToken} for {toToken}`,{fromToken:D.symbol,toToken:k.symbol,defaultValue:`You successfully swapped ${D.symbol} for ${k.symbol}`})),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:n,description:r,onDone:()=>{h?_():e(`main`)},showSocialButtons:!0}})},[D,k,j,G,De,c?.address,e,s,h,_]),je=(0,r.useCallback)(e=>{let t=typeof e==`string`?e:e.message;console.error(`Swap failed:`,t)},[D,k,j]),[Me,Ne]=r.default.useState(!1);r.default.useEffect(()=>{if(Oe===`ready`){Ne(!1);return}Me||(Oe===`success`&&De&&!De.reverted?(Ne(!0),Ae()):Oe===`error`&&ke?je(ke?.reason||ke?.message||String(ke)):De?.reverted&&je(`Transaction reverted`))},[Oe,De,ke,Ae,je,Me]);let Fe=(0,r.useCallback)(e=>{if(O(e),e.symbol===`VET`&&!k){let e=w.find(e=>e.symbol===`B3TR`);if(!e)try{let n=t.vt(f.type).b3trContractAddress;n&&(e=w.find(e=>t.O(e.address,n)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}e&&A(e)}E(`main`)},[k,w,f.type]),Le=(0,r.useCallback)(e=>{A(e),E(`main`)},[]),Re=(0,r.useCallback)(e=>{(/^\d*\.?\d*$/.test(e)||e===``)&&M(e)},[]),ze=(0,r.useCallback)(()=>{D&&M(D.balance)},[D]),Be=e=>{if(!e)return null;let n=t.Q[e.symbol],r=t.Z[e.symbol];return{symbol:e.symbol,logoComponent:n,logoUrl:r,balance:e.balance,value:e.valueInCurrency}},Y=Be(D),Ve=Be(k);return T===`select-from-token`?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:Fe,onBack:()=>E(`main`),showAllTokens:!1}):T===`select-quote`?(0,i.jsx)(Nr,{quotes:se,selectedQuote:G,toTokenAddress:k?.address??null,onSelectQuote:e=>{B(e),E(`main`)},onBack:()=>E(`main`)}):T===`select-to-token`?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:Le,onBack:()=>E(`main`),showAllTokens:!0}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Swap`)}),!h&&(0,i.jsx)(q,{onClick:()=>e(`main`),isDisabled:Te||Ee}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:Te||Ee})]}),(0,i.jsx)(n.Container,{maxW:`container.lg`,p:0,children:(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:b,children:s(`From`)}),Y&&(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:x,textDecoration:`underline`},onClick:ze,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Y.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:6,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:j,onChange:e=>Re(e.target.value),fontSize:`4xl`,fontWeight:`bold`,variant:`unstyled`,"data-testid":`swap-amount-input`,type:`number`,inputMode:`decimal`,color:Y&&j&&Number(j)>Number(Y.balance)?`red.500`:b}),Y?(0,i.jsxs)(n.Button,{onClick:()=>E(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Y.logoComponent?r.default.cloneElement(Y.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Y.logoUrl?(0,i.jsx)(n.Image,{src:Y.logoUrl,alt:`${Y.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:b,children:Y.symbol.slice(0,3)})})}):void 0,children:[Y.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>E(`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})]})]}),Y&&(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:[`≈`,` `,Ie(fe,{currency:d})]})})})]})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:4,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:b,children:s(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:v,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,p:6,width:`100%`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{value:Number(de).toLocaleString(void 0,{maximumFractionDigits:Number(de)>1e4?0:2}),readOnly:!0,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`swap-output-amount`,color:b}),Ve?(0,i.jsxs)(n.Button,{onClick:()=>E(`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:b,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:()=>E(`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})]})]}),Ve&&(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:[`≈`,` `,Ie(pe,{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:N&&!!G,animateOpacity:!0,children:(0,i.jsxs)(n.VStack,{spacing:1,align:`stretch`,p:4,borderRadius:`2xl`,bg:v,children:[G&&(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:()=>E(`select-quote`),color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:G.aggregator?.getIcon(`12px`),children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:b,children:G.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:b,children:[F,`%`]})]}),(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:()=>{I(1)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:U?`rgb(96 66 221)`:`transparent`,color:U?`white`:x,borderColor:U?`rgb(96 66 221)`:x,_hover:{bg:U?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:U?.8:1},children:`Auto`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{I(.5)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:F===.5?`rgb(96 66 221)`:`transparent`,color:F===.5?`white`:x,borderColor:F===.5?`rgb(96 66 221)`:x,_hover:{bg:F===.5?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:F===.5?.8:1},children:`0.5%`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{I(3)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:F===3?`rgb(96 66 221)`:`transparent`,color:F===3?`white`:x,borderColor:F===3?`rgb(96 66 221)`:x,_hover:{bg:F===3?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:F===3?.8:1},children:`3%`}),(0,i.jsxs)(n.InputGroup,{size:`sm`,flex:1,children:[(0,i.jsx)(n.Input,{value:L,onChange:e=>{let t=e.target.value;if((/^\d*\.?\d*$/.test(t)||t===``)&&(R(t),t!==``)){let e=parseFloat(t);!isNaN(e)&&e>=0&&e<=100&&I(e)}},placeholder:`1`,borderRadius:`md`,textAlign:`right`,pr:8,fontSize:`xs`,color:b}),(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:b,children:me>0?`${me.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:`-`})]})]})}),G&&(0,i.jsx)(n.Box,{minH:`24px`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Button,{variant:`ghost`,size:`xs`,onClick:()=>P(!N),rightIcon:(0,i.jsx)(n.Icon,{color:S,_hover:{color:x},as:N?g.LuArrowUp:g.LuArrowDown}),fontSize:`xs`,fontWeight:`light`,color:S,_hover:{color:x},children:s(N?`Hide`:`Show Advanced Options`)})}),re.length>0&&u.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:ge,isLoading:_e,isLoadingTransaction:Te,onTokenChange:Se,clauses:re,userSelectedToken:te})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Dc,{buttonText:s(W?`Loading quote...`:`Swap`),onConfirm:we,isSubmitting:Te,isTxWaitingConfirmation:Ee,transactionPendingText:s(`Swapping...`),txReceipt:De,transactionError:ke,onError:e=>{je(e)},isDisabled:!D||!k||!j||Number(j)<=0||W||!G||G?.reverted===!0||!!(Y&&j&&Number(j)>Number(Y.balance))||xe,gasEstimationError:ve,hasEnoughGasBalance:Ce,isLoadingGasEstimation:_e,showGasEstimationError:!p?.delegatorUrl&&u.isConnectedWithPrivy,context:`transaction`})})]})},Lr=({setCurrentContent:e,onBack:t=()=>e(`settings`),initialContentSource:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{isolatedView:o}=kr(),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)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Choose your account name`)}),!o&&(0,i.jsx)(q,{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`)})})]})},Rr=({domain:e,isCurrentDomain:r,onSelect:a})=>{let{connection:o}=X(),{t:s}=(0,l.useTranslation)(),c=Dn(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)(Ec,{props:{width:`40px`,height:`40px`,src:c.image??t.H(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.W(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)},zr=({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`)},Br=({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)(Rr,{domain:e,isCurrentDomain:e.name===s?.domain,onSelect:t},e.name)),s?.domain&&(0,i.jsx)(zr,{onUnset:r})]})})]})})})},Vr=({name:e,setCurrentContent:t,initialContentSource:a=`settings`})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{darkMode:c}=$(),{isolatedView:u}=kr(),[d,f]=(0,r.useState)((0,D.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}=Ke(d),{data:E,isLoading:O}=Ue(`${d}.veworld.vet`),{data:k,isLoading:A}=ot(d),{data:j,isLoading:M}=dt(s?.address,``),N=T||O||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)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Choose Name`)}),!u&&(0,i.jsx)(q,{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)(Br,{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,D.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,onClick:P,"data-testid":`continue-button`,children:o(`Continue`)})})]})},Hr=({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}=kr(),{account:m,connectedWallet:h,connection:g}=X(),{data:_}=js(m?.address??``,h?.address??``,3),{open:v}=Eo(),{preferences:y}=bc(),{feeDelegation:b}=$(),x=e=>{console.error(`Transaction failed:`,e)},S=It({onSuccess:()=>M()}),C=a.endsWith(`veworld.vet`),w=Qe({subdomain:t.split(`.veworld.vet`)[0],domain:a,alreadyOwned:o,onSuccess:()=>M()}),T=nt({domain:!s&&!C?t:``,alreadyOwned:o,onSuccess:()=>M()}),{sendTransaction:E,txReceipt:D,error:O,isWaitingForWalletConfirmation:k,isTransactionPending:A,clauses:j}=s?S:C?w:T,M=()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:D?.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)}}})},N=async()=>{if(_){v();return}try{await E()}catch(e){console.error(`Transaction failed:`,e)}},P=()=>{N()},F=()=>{e({type:`choose-name-search`,props:{setCurrentContent:e,name:t,initialContentSource:c}})},[I,L]=r.default.useState(null),[R,z]=r.default.useState(null),B=y.availableGasTokens.length>0&&(g.isConnectedWithPrivy||g.isConnectedWithVeChain)&&!b?.delegatorUrl,{data:V,isLoading:ee,error:te,refetch:ne}=xc({clauses:j(),tokens:I?[I]:y.availableGasTokens,enabled:B&&!!b?.genericDelegatorUrl}),re=V?.usedToken,H=(ee||!V)&&g.isConnectedWithPrivy&&!b?.delegatorUrl,ie=r.default.useCallback(e=>{L(e),z(e),setTimeout(()=>ne(),100)},[ne]),ae=!!re&&!te;return r.default.useEffect(()=>{te&&I&&L(null)},[te,I]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`confirm-domain`,children:u(s?`Confirm Unset Domain`:`Confirm Name`)}),(0,i.jsx)(q,{onClick:F,isDisabled:A}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:A})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:4,w:`full`,textAlign:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,color:d,children:u(s?`Are you sure you want to unset your current domain?`:`Are you sure you want to set your domain name to`)}),!s&&(0,i.jsx)(n.Text,{fontSize:`xl`,fontWeight:`bold`,color:d,"data-testid":`preconfirm-domain-val`,children:`${t}`})]}),g.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:V,isLoading:ee,isLoadingTransaction:A,onTokenChange:ie,clauses:j(),userSelectedToken:R})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Dc,{transactionError:O,isSubmitting:A,isTxWaitingConfirmation:k,onConfirm:N,onRetry:P,transactionPendingText:u(s?`Unsetting current domain...`:`Claiming name...`),txReceipt:D,buttonText:u(`Confirm`),isDisabled:A||H,onError:x,gasEstimationError:te,hasEnoughGasBalance:ae,isLoadingGasEstimation:ee,showGasEstimationError:!b?.delegatorUrl&&g.isConnectedWithPrivy,context:`domain`})})]})},Ur=()=>{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))})]})},Wr=({onGoBack:e,showLanguageSelector:t=!0})=>{let{i18n:r,t:a}=(0,l.useTranslation)(),{isolatedView:o}=kr(),s=(0,n.useToken)(`colors`,`vechain-kit-card`),c=(0,n.useToken)(`colors`,`vechain-kit-border`),u=(0,n.useToken)(`colors`,`vechain-kit-border-hover`);return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Help`)}),!o&&(0,i.jsx)(q,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[t&&(0,i.jsx)(n.Select,{borderRadius:`md`,size:`sm`,width:`auto`,value:r.language,onChange:e=>{r.changeLanguage(e.target.value)},bg:s,borderColor:c,_hover:{borderColor:u},children:ne.map(e=>(0,i.jsx)(`option`,{value:e,children:H[e]},e))}),(0,i.jsx)(n.Button,{as:n.Link,href:`https://docs.vechainkit.vechain.org/`,isExternal:!0,variant:`vechainKitSecondary`,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuExternalLink}),children:a(`For developers`)}),(0,i.jsx)(Ur,{})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Gr=({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.W(o?.domain??``,18,0):t.U(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})})]})})},Kr=({wallet:e,setCurrentContent:a,size:o=`md`,onClick:s,onClose:c,mt:l,style:u})=>{let[d,f]=(0,r.useState)(!1),{disconnect:p}=X(),m=async()=>{await t.st(e?.domain??e?.address??``)&&(f(!0),setTimeout(()=>{f(!1)},2e3))},h=()=>{p(),c()};return(0,i.jsxs)(n.HStack,{mt:l,w:`full`,...u,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)(Ec,{wallet:e,props:{width:7,height:7}}),(0,i.jsx)(n.Text,{fontSize:o,fontWeight:`500`,children:t.W(e?.domain??``,22,0)||t.U(e?.address??``,6,4)})]}),(0,i.jsx)(n.Icon,{boxSize:5,as:g.LuChevronRight,cursor:`pointer`,opacity:.5})]})}),(0,i.jsx)(n.IconButton,{"aria-label":`Copy address`,icon:(0,i.jsx)(n.Icon,{as:d?g.LuCheck:g.LuCopy}),onClick:m,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8}}),(0,i.jsx)(n.IconButton,{"aria-label":`Logout`,icon:(0,i.jsx)(n.Icon,{as:g.LuLogOut}),onClick:()=>a({type:`disconnect-confirm`,props:{onDisconnect:h,onBack:()=>a(`main`)}}),variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},colorScheme:`red`})]})},qr=({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}=Kt({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.Q[e.symbol]?r.default.cloneElement(t.Q[e.symbol],{width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):t.Z[e.symbol]?(0,i.jsx)(n.Image,{src:t.Z[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]})},Jr=({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}=On(),[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)};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:`flex-start`,alignItems:`center`,spacing:2,role:`group`,children:[(0,i.jsx)(n.Heading,{size:`xs`,fontWeight:`500`,color:m,children:o(`Assets`)}),(0,i.jsx)(n.Box,{display:`flex`,alignItems:`center`,justifyContent:`center`,w:`32px`,h:`32px`,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.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)(qr,{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})})})]})})]})},Yr=[{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`)}}],Xr=({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})},Zr=({mt:e,setCurrentContent:t})=>{let{account:r,smartAccount:a,connectedWallet:o,connection:s}=X(),{hasAnyBalance:c}=qt({address:r?.address??``}),{data:l}=js(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:Yr.map(e=>(0,i.jsx)(Xr,{icon:e.icon,label:e.label,onClick:()=>e.onClick(t),isDisabled:e.isDisabled?.(c),showRedDot:u&&e.label===`Settings`},e.label))})},Qr=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.lt(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t._t(i,`true`),n(!1)}}},$r=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isVisible:r,closeAnnouncement:a}=Qr(),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return r?(0,i.jsx)(n.Card,{w:`full`,variant:`featureAnnouncement`,overflow:`hidden`,onClick:()=>{e({type:`choose-name`,props:{setCurrentContent:e,onBack:()=>e(`main`),initialContentSource:`main`}}),a()},cursor:`pointer`,_hover:{opacity:.8},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsxs)(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:o,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:s,children:t(`Say goodbye to 0x addresses, claim your .veworld.vet subdomain now for free!`)})]}),(0,i.jsx)(n.IconButton,{size:`sm`,variant:`ghost`,colorScheme:`gray`,icon:(0,i.jsx)(g.LuCircleX,{}),onClick:e=>{e.stopPropagation(),a()},"aria-label":t(`Close announcement`)})]})})}):null},ei=()=>{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.`)})]})})})},ti=()=>{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.`)})]})})})},ni=()=>{let{t:e}=(0,l.useTranslation)(),{getConnectionCache:t}=Fo(),r=t();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:e(`Security preferences`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,mt:1,opacity:.7,children:e(`For security reasons, you can manage your embedded wallet settings only on the {{appName}} platform.`,{appName:r?.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:e(`Login methods`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:e(`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:e(`Security settings`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:e(`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(r?.ecosystemApp.website??`https://governance.vebetterdao.org/`,`_blank`)},children:[e(`Manage on {{appName}}`,{appName:r?.ecosystemApp.name??`origin app`}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},ri=({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}=Wn({compressImage:!0}),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(null),C=!!c?.domain,[w,T]=(0,r.useState)(null),[D,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(``),{register:j,watch:M,formState:{errors:N,isValid:P}}=(0,E.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.E(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!==D&&(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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Customization`)}),(0,i.jsx)(q,{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)(Ec,{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)(ti,{}),(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`)})})]})},ii=({setCurrentContent:e,changes:a,onDoneRedirectContent:o})=>{let{t:s}=(0,l.useTranslation)(),{darkMode:c,network:u,feeDelegation:d}=$(),{account:f,connectedWallet:m,connection:h}=X(),{preferences:g}=bc(),{data:_}=js(f?.address??``,m?.address??``,3),{open:v}=Eo(),{handleSubmit:y}=(0,E.useForm)({defaultValues:{...a,avatarIpfsHash:a.avatarIpfsHash??void 0}}),b=f?.domain??``,{data:x}=St(b),S=(0,p.useQueryClient)(),{sendTransaction:C,txReceipt:w,error:T,isWaitingForWalletConfirmation:D,isTransactionPending:O,clauses:k}=bt({resolverAddress:x,signerAccountAddress:f?.address??``,onSuccess:async()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:w?.meta.txID,title:s(`Profile Updated`),description:s(`Your changes have been saved successfully.`),onDone:()=>{e(o)}}});try{await U()}catch(e){console.error(`Error refreshing data:`,e)}},onError:e=>{console.error(`Error updating text record:`,e)}}),A=(0,r.useMemo)(()=>{let e=f?.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,f?.domain]),j=(0,r.useMemo)(()=>{try{return!x||A.length===0||!k?[]:k(A)}catch(e){return console.error(`Error building clauses:`,e),[]}},[A,k,x]),[M,N]=r.default.useState(null),[P,F]=r.default.useState(null),I=g.availableGasTokens.length>0&&(h.isConnectedWithPrivy||h.isConnectedWithVeChain)&&!d?.delegatorUrl,{data:L,isLoading:R,error:z,refetch:B}=xc({clauses:j,tokens:M?[M]:g.availableGasTokens,enabled:I&&!!d?.genericDelegatorUrl}),V=L?.usedToken,ee=(R||!L)&&h.isConnectedWithPrivy&&!d?.delegatorUrl,te=r.default.useCallback(e=>{N(e),F(e),setTimeout(()=>B(),100)},[B]),ne=!!V&&!z;r.default.useEffect(()=>{z&&M&&N(null)},[z,M]);let re=async()=>{if(_){v();return}try{A.length>0&&await C(A)}catch(e){console.error(`Error saving changes:`,e)}},H=(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,ie=()=>{y(re)()},ae=()=>{e({type:`account-customization`,props:{setCurrentContent:e}})},U=async()=>{a.avatarIpfsHash&&(S.setQueryData(ft(b,u.type),t.h(`ipfs://`+a.avatarIpfsHash,u.type)),S.setQueryData(Et(f?.address??``),t.h(`ipfs://`+a.avatarIpfsHash,u.type))),await S.invalidateQueries({queryKey:gt(b,u.type)}),await S.refetchQueries({queryKey:gt(b,u.type)})};return(0,i.jsxs)(n.Box,{as:`form`,onSubmit:y(re),children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Confirm Changes`)}),(0,i.jsx)(q,{isDisabled:O,onClick:ae}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:O})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,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&&H(s(`Display Name`),a.displayName),a.description&&H(s(`Description`),a.description),a.twitter&&H(s(`Twitter`),a.twitter),a.website&&H(s(`Website`),a.website),a.email&&H(s(`Email`),a.email)]}),h.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:L,isLoading:R,isLoadingTransaction:O,onTokenChange:te,clauses:j,userSelectedToken:P})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Dc,{transactionError:T,isSubmitting:O,isTxWaitingConfirmation:D,onConfirm:y(re),onRetry:ie,transactionPendingText:s(`Saving changes...`),txReceipt:w,buttonText:s(`Confirm`),isDisabled:O||ee,gasEstimationError:z,hasEnoughGasBalance:ne,isLoadingGasEstimation:R,showGasEstimationError:!d?.delegatorUrl&&h.isConnectedWithPrivy,context:`customization`})})]})},ai=({onEditClick:e,address:r,showHeader:a=!0,onLogout:o,showLinks:s=!0,showDescription:c=!0,showDisplayName:u=!0,showEdit:d=!0})=>{let{t:f}=(0,l.useTranslation)(),{account:p,disconnect:m}=X(),{network:h}=$(),{openAccountModal:_,closeAccountModal:v}=Q(),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),x=Dn(r,h.type),S=t.H(r),C=r===p?.address,w=x?.records?.url||x?.records?.[`com.x`]||x?.records?.email,T=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:4,w:`full`,children:[(0,i.jsx)(n.Box,{p:0,backgroundSize:`100% !important`,backgroundPosition:`center`,position:`relative`,background:a?`no-repeat url('${S}')`:`none`,w:`100%`,borderRadius:`14px 14px 0 0`}),(0,i.jsx)(Ec,{wallet:{address:r,domain:x?.domain,image:x?.image,isLoadingMetadata:x?.isLoading,metadata:x?.records},props:{width:`120px`,height:`120px`}}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[u&&x?.records?.display&&(0,i.jsx)(n.Text,{fontSize:`xl`,color:y,fontWeight:`bold`,w:`full`,textAlign:`center`,mt:2,"data-testid":`display-name-val`,children:x?.records?.display}),c&&x?.records?.description&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,w:`full`,textAlign:`center`,"data-testid":`description-val`,children:x?.records?.description}),s&&w&&(0,i.jsxs)(n.HStack,{w:`full`,justify:`center`,spacing:5,mt:4,children:[x?.records?.email&&(0,i.jsx)(n.Link,{href:`mailto:${x?.records?.email}`,target:`_blank`,"data-testid":`mail-link`,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:y})}),x?.records?.url&&(0,i.jsx)(n.Link,{href:T(x.records.url)??void 0,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`website-link`,children:(0,i.jsx)(n.Icon,{as:g.LuGlobe,color:y})}),x?.records?.[`com.x`]&&(0,i.jsx)(n.Link,{href:`https://x.com/${encodeURIComponent(String(x.records[`com.x`]))}`,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`twitter-link`,children:(0,i.jsx)(n.Icon,{as:k.FaXTwitter,color:y})})]}),(0,i.jsx)(De,{wallet:{address:r,domain:x?.domain,image:x?.image,isLoadingMetadata:x?.isLoading,metadata:x?.records},style:{mt:4}})]}),C&&d&&(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:(0,i.jsx)(n.Icon,{as:g.LuPencil}),onClick:e??(()=>{_({type:`account-customization`,props:{setCurrentContent:()=>v()}})}),"data-testid":`customize-button`,children:f(`Customize`)}),(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:o??(()=>{_({type:`disconnect-confirm`,props:{onDisconnect:()=>{m(),v()},onBack:()=>v()}})}),"data-testid":`logout-button`,children:f(`Logout`)})]})]})},oi=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{account:o,disconnect:s}=X();return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:r(`Profile`)}),!a&&(0,i.jsx)(q,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[!o?.domain&&(0,i.jsx)($r,{setCurrentContent:e}),(0,i.jsx)(ai,{onEditClick:()=>{e({type:`account-customization`,props:{setCurrentContent:e,initialContentSource:`profile`}})},address:o?.address??``,showHeader:!1,onLogout:()=>{e?.({type:`disconnect-confirm`,props:{onDisconnect:()=>{s(),t?.()},onBack:()=>e?.(`profile`)}})}})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},si=({setCurrentContent:e,handleClose:t,initialContent:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=js(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Is({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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(q,{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)(Dc,{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`)})]})})]})},ci=({setCurrentContent:e})=>{let{account:t}=X(),{sortedTokens:a}=Kt({address:t?.address}),{allowCustomTokens:o,darkMode:s}=$(),{currentCurrency:c}=Gt(),u=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{t:d}=(0,l.useTranslation)(),{isolatedView:f}=kr(),[p,m]=(0,r.useState)(``),h=t=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:t,onBack:()=>e(`assets`)}})},_=a.filter(({symbol:e})=>e.toLowerCase().includes(p.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Assets`)}),!f&&(0,i.jsx)(q,{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:s?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12,value:p,onChange:e=>m(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:u})})]}),(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,mt:2,children:_.map(e=>{let t=Number(e.balance)>0;return(0,i.jsx)(Le,{symbol:e.symbol,amount:Number(e.balance),currencyValue:e.valueInCurrency,currentCurrency:c,onClick:()=>h(e),isDisabled:!t},e.address)})})]}),(0,i.jsx)(n.ModalFooter,{children:o&&(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPencil,boxSize:4}),onClick:()=>e(`add-custom-token`),children:d(`Manage Custom Tokens`)})})]})]})},li=({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}=tn(),{register:h,setError:_,setValue:v,formState:{errors:y,isValid:b},handleSubmit:x}=(0,E.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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Manage Custom Tokens`)}),(0,i.jsx)(q,{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.Z[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.U(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`)})})]})},ui=({setCurrentContent:t})=>{let{t:r}=(0,l.useTranslation)(),{darkMode:a}=$(),{isolatedView:o}=kr();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Bridge`)}),!o&&(0,i.jsx)(q,{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(`https://swap.vechain.energy/`,`_blank`)},children:[r(`Launch vechain.energy`),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},di=({setCurrentContent:e})=>{let{t:a}=(0,l.useTranslation)(),{currentCurrency:o,changeCurrency:s,allCurrencies:c}=Gt(),u=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`);(0,r.useEffect)(()=>{t._t(`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.S[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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select currency`)}),(0,i.jsx)(q,{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})]})},fi=({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:H[e]}),t&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Select language`)}),(0,i.jsx)(q,{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:ne.map(e=>s(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},pi=({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.X[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`})]})})},mi=({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)(pi,{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))})},hi=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{preferences:a,reorderTokenPriority:o,toggleTokenExclusion:s}=bc(),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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Gas Token Preferences`)}),(0,i.jsx)(q,{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)(mi,{tokens:a.tokenPriority,excludedTokens:a.excludedTokens,onReorder:d,onToggleExclusion:s})]})]})})]})},gi=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{exportWallet:o,linkPasskey:s}=(0,u.usePrivy)(),{showMfaEnrollmentModal:c}=(0,u.useMfaEnrollment)(),{feeDelegation:d}=$(),{connection:f,disconnect:p,smartAccount:m,connectedWallet:h}=X(),{data:_}=js(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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Settings`)}),!a&&(0,i.jsx)(q,{onClick:()=>e(`main`)}),(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)(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(`Frequently asked questions`),onClick:()=>e({type:`faq`,props:{onGoBack:()=>e(`settings`),showLanguageSelector:!1}}),leftIcon:g.LuCircleHelp,rightIcon:g.LuChevronRight}),(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)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[(0,i.jsx)(n.Divider,{}),(0,i.jsx)(Z,{title:r(`Logout`),onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:b,onBack:()=>e(`settings`)}}),leftIcon:g.LuLogOut})]})})]})},_i=({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})]})]})},vi=(e,t=`en-US`)=>new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}).format(new Date(e)),yi=({document:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=e.documentSource===t._.VECHAIN_KIT&&e.documentType===t.v.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:vi(e.timestamp)})})]})},bi=({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:vi(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)(yi,{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},xi=()=>{let{account:e}=X(),{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),{agreements:s,documents:c}=Uc(),u=(0,r.useMemo)(()=>{let n=s?.filter(n=>t.O(n.walletAddress,e?.address));return[{id:`vechain-kit-terms`,...t.nt,documentType:t.v.TERMS,documentSource:t._.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`;return f?(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,children:(0,i.jsxs)(n.Accordion,{allowMultiple:!0,children:[(0,i.jsx)(bi,{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.v.TERMS],bg:p,hoverBg:m,currentPolicy:d[t.v.TERMS]}),(0,i.jsx)(bi,{title:a(`Privacy Policy`),description:a(`Privacy policy outlining the data collection and processing practices.`),documents:u[t.v.PRIVACY],bg:p,hoverBg:m,currentPolicy:d[t.v.PRIVACY]}),(0,i.jsx)(bi,{title:a(`Cookie Policy`),description:a(`Cookie policy outlining the use of cookies and tracking technologies.`),documents:u[t.v.COOKIES],bg:p,hoverBg:m,currentPolicy:d[t.v.COOKIES]})]})}):(0,i.jsx)(_i,{title:a(`No policies accepted`),description:a(`When you have accepted a policy, it will appear here`),icon:g.LuGavel})},Si=({onGoBack:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Terms and Policies`)}),(0,i.jsx)(q,{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)(xi,{})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Ci=({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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Logout`)}),(0,i.jsx)(q,{onClick:t}),a?(0,i.jsx)(n.ModalCloseButton,{onClick:r}):null]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,children:(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:c,children:u})})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{height:`60px`,colorScheme:`red`,w:`full`,onClick:e,"data-testid":`disconnect-button`,children:s(`Confirm`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:t,"data-testid":`cancel-logout-button`,children:s(`Cancel`)})]})})]})},wi=ke[`@vechain/dapp-kit-react`]||Ae[`@vechain/dapp-kit-react`]||`unknown`,Ti=ke[`@privy-io/react-auth`]||`unknown`,Ei=({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}=Be(p||[]),{onCopy:_,hasCopied:v}=(0,n.useClipboard)(``),{data:y,isLoading:b}=Ve(),{data:x,isLoading:S}=hs(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.vt(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.U(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:Oe,href:`https://github.com/vechain/vechain-kit/releases/tag/${Oe}`}),(0,i.jsx)(O,{label:`DAppKit`,value:wi}),(0,i.jsx)(O,{label:`Privy`,value:Ti})]}):null},Di=()=>{let{connection:t}=X(),{t:r}=(0,l.useTranslation)(),{privy:a,darkMode:o}=$(),{getConnectionCache:s}=Fo(),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.S,{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},Oi=({onGoBack:e})=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Fo(),a=r()??void 0;return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Connection Details`)}),(0,i.jsx)(q,{onClick:()=>{e()}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsx)(Ei,{connectionCache:a}),(0,i.jsx)(Di,{})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},ki=({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`)})]})]})},Ai=({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:E,linkSpotify:D,linkApple:O,linkInstagram:M,linkTiktok:N,linkGithub:P,linkLinkedIn:F,linkTelegram:I,linkFarcaster:L,linkPasskey:R,linkDiscord:z,unlinkEmail:B,unlinkGoogle:V,unlinkApple:ee,unlinkSpotify:te,unlinkInstagram:ne,unlinkTiktok:re,unlinkGithub:H,unlinkLinkedIn:ie,unlinkTelegram:ae,unlinkFarcaster:U,unlinkPhone:oe,unlinkPasskey:se,unlinkDiscord:W,linkWallet:ce}=(0,u.usePrivy)(),le=(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]),ue=e=>{switch(e){case`google_oauth`:return T.FcGoogle;case`email`:return g.LuMail;case`passkey`:return g.LuFingerprint;case`wallet`:return g.LuWallet;case`twitter_oauth`:return k.FaXTwitter;case`phone`:return g.LuPhone;case`spotify_oauth`:return j.FaSpotify;case`apple_oauth`:return j.FaApple;case`instagram_oauth`:return j.FaInstagram;case`tiktok_oauth`:return j.FaTiktok;case`github_oauth`:return g.LuGithub;case`linkedin_oauth`:return j.FaLinkedin;case`telegram`:return j.FaTelegram;case`farcaster`:return A.SiFarcaster;case`discord_oauth`:return j.FaDiscord;default:return}},G=()=>{let e=x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`);return e&&e?.length>1},de=async e=>{if(G()){v(!0);try{switch(e.type){case`google_oauth`:await V(e.subject);break;case`email`:await B(e.address);break;case`passkey`:await se(e.subject);break;case`phone`:await oe(e.number);break;case`spotify_oauth`:await te(e.subject);break;case`apple_oauth`:await ee(e.subject);break;case`instagram_oauth`:await ne(e.subject);break;case`tiktok_oauth`:await re(e.subject);break;case`github_oauth`:await H(e.subject);break;case`linkedin_oauth`:await ie(e.subject);break;case`telegram`:await ae(e.subject);break;case`farcaster`:await U(e.subject);break;case`discord_oauth`:await W(e.subject);break;default:break}}catch(e){console.error(e)}finally{v(!1),d(null)}}},fe=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.U(e.address)} - ${e.walletClientType}`;default:return``}},pe=x?.linkedAccounts?.map(e=>e.type)||[],K=o?.loginMethods||[],me=!pe.includes(`google_oauth`)&&K.includes(`google`),he=!pe.includes(`email`)&&K.includes(`email`),ge=!pe.includes(`twitter_oauth`)&&K.includes(`twitter`),_e=!pe.includes(`phone`)&&K.includes(`sms`),ve=!pe.includes(`spotify_oauth`)&&K.includes(`spotify`),ye=!pe.includes(`apple_oauth`)&&K.includes(`apple`),be=!pe.includes(`instagram_oauth`)&&K.includes(`instagram`),xe=!pe.includes(`tiktok_oauth`)&&K.includes(`tiktok`),Se=!pe.includes(`github_oauth`)&&K.includes(`github`),Ce=!pe.includes(`linkedin_oauth`)&&K.includes(`linkedin`),we=!pe.includes(`telegram`)&&K.includes(`telegram`),Te=!pe.includes(`farcaster`)&&K.includes(`farcaster`),Ee=!pe.includes(`discord_oauth`)&&K.includes(`discord`);return f?(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select Additional Login Method`)}),(0,i.jsx)(q,{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}),me&&(0,i.jsx)(Z,{title:a(`Link Google Account`),description:a(`Connect your Google account for easier access`),onClick:()=>C(),leftIcon:T.FcGoogle}),he&&(0,i.jsx)(Z,{title:a(`Link Email Account`),description:a(`Connect your email for easier access`),onClick:()=>S(),leftIcon:g.LuMail,stacked:!0}),ge&&(0,i.jsx)(Z,{title:a(`Link Twitter Account`),description:a(`Connect your Twitter account for easier access`),onClick:()=>w(),leftIcon:k.FaXTwitter}),_e&&(0,i.jsx)(Z,{title:a(`Link Phone Number`),description:a(`Connect your phone number for easier access`),onClick:()=>E(),leftIcon:g.LuPhone}),ve&&(0,i.jsx)(Z,{title:a(`Link Spotify Account`),description:a(`Connect your Spotify account for easier access`),onClick:()=>D(),leftIcon:j.FaSpotify}),ye&&(0,i.jsx)(Z,{title:a(`Link Apple Account`),description:a(`Connect your Apple account for easier access`),onClick:()=>O(),leftIcon:j.FaApple}),be&&(0,i.jsx)(Z,{title:a(`Link Instagram Account`),description:a(`Connect your Instagram account for easier access`),onClick:()=>M(),leftIcon:j.FaInstagram}),xe&&(0,i.jsx)(Z,{title:a(`Link Tiktok Account`),description:a(`Connect your Tiktok account for easier access`),onClick:()=>N(),leftIcon:j.FaTiktok}),Se&&(0,i.jsx)(Z,{title:a(`Link Github Account`),description:a(`Connect your Github account for easier access`),onClick:()=>P(),leftIcon:g.LuGithub}),Ce&&(0,i.jsx)(Z,{title:a(`Link LinkedIn Account`),description:a(`Connect your LinkedIn account for easier access`),onClick:()=>F(),leftIcon:j.FaLinkedin}),we&&(0,i.jsx)(Z,{title:a(`Link Telegram Account`),description:a(`Connect your Telegram account for easier access`),onClick:()=>I(),leftIcon:j.FaTelegram}),Te&&(0,i.jsx)(Z,{title:a(`Link Farcaster Account`),description:a(`Connect your Farcaster account for easier access`),onClick:()=>L(),leftIcon:A.SiFarcaster}),Ee&&(0,i.jsx)(Z,{title:a(`Link Discord Account`),description:a(`Connect your Discord account for easier access`),onClick:()=>z(),leftIcon:j.FaDiscord}),le&&(0,i.jsx)(Z,{title:a(`Link External Wallet`),description:a(`Connect an external wallet for easier access`),onClick:()=>ce(),leftIcon:g.LuWallet}),!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&!Ee&&(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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Remove Login Method`)}),(0,i.jsx)(q,{onClick:()=>d(null)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(ki,{accountType:c.type,accountDescription:fe(c),isLoading:_,onConfirm:()=>de(c),onCancel:()=>d(null)})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Login methods`)}),(0,i.jsx)(q,{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:ue(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:fe(e)})]})]}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,colorScheme:`red`,isDisabled:!G(),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:!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&!Ee,children:a(`Add Login Method`)})})]})},ji=[{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}],Mi=()=>{let{t:e}=(0,l.useTranslation)(),{account:t,connection:n,smartAccount:i}=X(),{addNotification:a,getNotifications:o}=Ni(),{data:s}=Ps(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])},Ni=()=>{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.ft())return;let r=n(e.address);t.lt(r.initialized)||(t._t(r.notifications,JSON.stringify(ji)),t._t(r.initialized,`true`))},[e?.address,n]);(0,r.useEffect)(()=>{i()},[i]);let a=(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return[];let r=t.lt(n(e.address).notifications);return r?JSON.parse(r):[]},[e?.address,n]),o=(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return[];let r=t.lt(n(e.address).archived);return r?JSON.parse(r):[]},[e?.address,n]),s=(0,r.useCallback)(r=>{if(!e?.address||!t.ft())return;let i=n(e.address),o=a(),s=t.lt(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._t(i.notifications,JSON.stringify([l,...o]))},[e?.address,a,n]),c=(0,r.useCallback)(r=>{if(!e?.address||!t.ft())return;let i=n(e.address),o=a().filter(e=>e.id!==r);t._t(i.notifications,JSON.stringify(o))},[e?.address,a,n]);return{getNotifications:a,getArchivedNotifications:o,addNotification:s,clearAllNotifications:(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return;let r=n(e.address),i=a();t._t(r.archived,JSON.stringify([...o(),...i])),t._t(r.notifications,JSON.stringify([]))},[e?.address,a,o,n]),markAsRead:(0,r.useCallback)(r=>{if(!e?.address||!t.ft())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._t(i.notifications,JSON.stringify(u)),t._t(i.archived,JSON.stringify(e))}},[e?.address,a,o,n]),deleteNotification:c}},Pi=({showArchived:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsx)(_i,{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})},Fi=({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)},Ii=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{getNotifications:o,getArchivedNotifications:s,clearAllNotifications:c,markAsRead:u}=Ni(),[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)(Tc,{children:[(0,i.jsxs)(J,{children:[!a&&(0,i.jsx)(q,{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)(Pi,{showArchived:d}):(0,i.jsx)(n.VStack,{spacing:3,children:S.map(e=>(0,i.jsx)(Fi,{notification:e,isArchiveView:d,onMarkAsRead:y},e.id))})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},Li=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`}},Ri=({category:e,...t})=>{let{t:r}=(0,l.useTranslation)(),a=e.toLowerCase();return(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:Li(a),borderRadius:`full`,px:2,...t,children:r(a)})},zi=({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)(Ri,{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.ot,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})]})})]}),Bi=({xApp:e,setCurrentContent:t,selectedCategory:r})=>{let{data:a,isLoading:o}=jn(e.id),{data:s,isLoading:c}=Rn(a?.logo);return(0,i.jsx)(n.Skeleton,{isLoaded:!o&&!c,borderRadius:`md`,height:`100%`,children:(0,i.jsx)(zi,{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}})}})})},Vi=({name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c})=>(0,i.jsx)(zi,{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}}),Hi=({})=>{let{t:e}=(0,l.useTranslation)(),{shortcuts:r}=fc();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.ot,alt:e.name,objectFit:`contain`,rounded:`full`})})})},e.url))})]})},Ui=({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)(Ri,{category:r,size:`md`,variant:e===r?`solid`:`outline`,cursor:`pointer`,onClick:()=>t(r)})},r))]})]})},Wi=[{name:`VeBetterDAO`,description:`Engage, earn and prosper by doing sustainable actions.`,external_url:`https://governance.vebetterdao.org/`,logo:`https://i.ibb.co/cgJBj83/vbd.png`,banner:`https://i.ibb.co/cgJBj83/vbd.png`,screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:`https://i.ibb.co/cgJBj83/vbd.png`},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:`https://vet.domains`,logo:`https://vet.domains/assets/walletconnect.png`,banner:`https://vet.domains/assets/walletconnect.png`,screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:`https://vet.domains/assets/walletconnect.png`},categories:[]}],Gi=({setCurrentContent:e,selectedCategory:t})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o,network:s}=$(),{isolatedView:c}=kr(),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}=Zt(),{data:_}=xn(h?(parseInt(h)-1).toString():`1`),{data:v,isLoading:y,error:b}=Wo(),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=Wi.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}=fc();return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Ecosystem`)}),!c&&(0,i.jsx)(q,{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)(Hi,{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)(Ui,{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)(Vi,{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)(Bi,{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)(Vi,{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})]})},Ki=({name:e,image:t,url:r,description:a})=>{let{t:o}=(0,l.useTranslation)(),{isShortcut:s,addShortcut:c,removeShortcut:u}=fc(),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`)})},qi=({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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t}),(0,i.jsx)(q,{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)(Ri,{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)(Ki,{name:t,image:r,url:a,description:o})]})})]})},Ji=`https://twitter.com/intent/tweet?text=`,Yi=`https://wa.me/?text=`,Xi=`https://telegram.me/share/url?url=`,Zi=({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}),Qi=({descriptionEncoded:e})=>{let{darkMode:t}=$();return(0,i.jsxs)(n.HStack,{gap:2,children:[(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://twitter.com/intent/tweet?text=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:t?`blackAlpha.700`:`lightgrey`,p:2,borderRadius:`full`,children:(0,i.jsx)(k.FaXTwitter,{size:22})})})}),(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://telegram.me/share/url?url=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#30abec`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaTelegramPlane,{color:`white`,size:22})})})}),(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://wa.me/?text=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#01cb37`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaWhatsapp,{size:22,color:`white`})})})})]})},$i=({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.vt(f.type).explorerUrl}/${s?.meta.txID}`;return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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:`vechainKitSecondary`,width:`full`,children:d(`Close`)}),a?.showExplorerButton&&s?.meta.txID&&(0,i.jsx)(n.Link,{href:`${t.vt(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:_})]})})]})})]})},ea=({isOpen:e,onClose:t,status:n,uiConfig:r,txReceipt:a,txError:o,onTryAgain:s})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,closeOnOverlayClick:n!==`pending`&&r?.isClosable,children:(0,i.jsx)($i,{status:n,onTryAgain:s,uiConfig:r,txReceipt:a,onClose:t,txError:o})}),ta=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.vt(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)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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})]})})]})})]})},na=({txId:e,title:r,description:a,onDone:o})=>{let{t:s}=(0,l.useTranslation)(),{network:c,darkMode:u}=$(),d=t.vt(c.type).explorerUrl;return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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})]})})]})})]})},ra={enter:e=>({opacity:0,x:e===`forward`?20:-20}),center:{opacity:1,x:0},exit:e=>({opacity:0,x:e===`forward`?-20:20})},ia={duration:.17,ease:[.4,0,.2,1]},aa=e=>{if(typeof e==`string`)return e;let t=e.type,n=JSON.stringify(e.props),r=0;for(let e=0;e<n.length;e++){let t=n.charCodeAt(e);r=(r<<5)-r+t,r&=r}return`${t}-${Math.abs(r)}`},oa=({isOpen:e,onClose:t,initialContent:n=`main`})=>{Mi();let{account:a}=X(),o=(0,r.useRef)(null),s=(0,r.useRef)(`forward`),{accountModalContent:c,setAccountModalContent:l}=Q();(0,r.useEffect)(()=>{e&&n&&l(n)},[e,n,l]);let u=(()=>{if(o.current===null||o.current===c)return s.current;let e=aa(o.current),t=aa(c);return t===`main`||t===`settings`&&e!==`main`||e.includes(`summary`)||e.includes(`confirm`)||e.includes(`operation`)?`backward`:`forward`})();(0,r.useEffect)(()=>{s.current=u,o.current=c},[c,u]);let d=(()=>{if(typeof c==`object`)switch(c.type){case`send-token`:return(0,i.jsx)(Ar,{...c.props});case`send-token-summary`:return(0,i.jsx)(jr,{...c.props});case`swap-token`:return(0,i.jsx)(Ir,{...c.props});case`choose-name`:return(0,i.jsx)(Lr,{...c.props});case`choose-name-search`:return(0,i.jsx)(Vr,{...c.props});case`choose-name-summary`:return(0,i.jsx)(Hr,{...c.props});case`app-overview`:return(0,i.jsx)(qi,{...c.props,setCurrentContent:l});case`disconnect-confirm`:return(0,i.jsx)(Ci,{...c.props});case`account-customization`:return(0,i.jsx)(ri,{...c.props});case`account-customization-summary`:return(0,i.jsx)(ii,{...c.props});case`successful-operation`:return(0,i.jsx)(ta,{...c.props});case`failed-operation`:return(0,i.jsx)(na,{...c.props});case`upgrade-smart-account`:return(0,i.jsx)(si,{...c.props});case`faq`:return(0,i.jsx)(Wr,{...c.props});case`terms-and-privacy`:return(0,i.jsx)(Si,{...c.props});case`ecosystem-with-category`:return(0,i.jsx)(Gi,{setCurrentContent:l,selectedCategory:c.props.selectedCategory})}switch(c){case`main`:return(0,i.jsx)(Dr,{setCurrentContent:l,onClose:t,wallet:a});case`settings`:return(0,i.jsx)(gi,{setCurrentContent:l,onLogoutSuccess:()=>{t()}});case`profile`:return(0,i.jsx)(oi,{setCurrentContent:l,onLogoutSuccess:()=>{t()}});case`assets`:return(0,i.jsx)(ci,{setCurrentContent:l});case`bridge`:return(0,i.jsx)(ui,{setCurrentContent:l});case`notifications`:return(0,i.jsx)(Ii,{setCurrentContent:l});case`receive-token`:return(0,i.jsx)(Mr,{setCurrentContent:l});case`swap-token`:return(0,i.jsx)(Ir,{setCurrentContent:l});case`connection-details`:return(0,i.jsx)(Oi,{onGoBack:()=>l(`settings`)});case`privy-linked-accounts`:return(0,i.jsx)(Ai,{onBack:()=>l(`settings`)});case`ecosystem`:return(0,i.jsx)(Gi,{setCurrentContent:l});case`add-custom-token`:return(0,i.jsx)(li,{setCurrentContent:l});case`change-currency`:return(0,i.jsx)(di,{setCurrentContent:l});case`change-language`:return(0,i.jsx)(fi,{setCurrentContent:l});case`gas-token-settings`:return(0,i.jsx)(hi,{setCurrentContent:l});default:return null}})(),f=aa(c);return(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,children:(0,i.jsx)(h.AnimatePresence,{mode:`wait`,initial:!1,children:d&&(0,i.jsx)(h.motion.div,{custom:s.current,variants:ra,initial:`enter`,animate:`center`,exit:`exit`,transition:ia,style:{width:`100%`},children:d},f)})})},sa=({isOpen:e,onClose:t})=>{let[n,a]=(0,r.useState)(`main`);return(0,r.useEffect)(()=>{e&&a(`main`)},[e]),(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,children:(()=>{switch(n){case`main`:return(0,i.jsx)(Tr,{setCurrentContent:a,onClose:t});case`faq`:return(0,i.jsx)(Wr,{onGoBack:()=>a(`main`)})}})()})},ca=({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`})}),la=({isLoading:e,buttonStyle:t})=>{let{t:r}=(0,l.useTranslation)(),{loginMethods:a,darkMode:o,privyEcosystemAppIDS:s}=$(),c=a?.some(({method:e})=>e===`ecosystem`),{data:u,isLoading:d}=Be(s);return(0,i.jsx)(n.Popover,{placement:`bottom-start`,size:`xl`,closeOnBlur:!1,variant:`vechainKitBase`,children:({isOpen:a})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.PopoverTrigger,{children:(0,i.jsxs)(n.Button,{isLoading:e,...t,isActive:a,children:[r(`Login`),(0,i.jsx)(n.Icon,{ml:2,as:g.LuChevronDown,transform:a?`rotate(180deg)`:`rotate(0deg)`,transition:`transform 0.2s`})]})}),(0,i.jsxs)(n.PopoverContent,{children:[(0,i.jsx)(n.PopoverBody,{children:(0,i.jsx)(Cr,{})}),(0,i.jsx)(n.PopoverFooter,{borderTop:`none`,pb:`15px`,children:c&&(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(wr,{isDark:o,appsInfo:Object.values(u||{}),isLoading:d})})})]})]})})},ua=({variant:e})=>{let{account:r}=X();return r?e===`icon`?null:e===`iconAndDomain`?r.domain?(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.W(r?.domain??``,16,0)}):(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.U(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.W(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.U(r.address??``,4,4)})]}),(0,i.jsx)(qr,{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.W(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,children:t.U(r.address??``,4,4)})]}):(0,i.jsx)(n.Spinner,{})},da=({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)(Ec,{wallet:o,props:{width:30,height:30,minWidth:30,minHeight:30}}),(0,i.jsx)(ua,{variant:s?t:e})]})})},fa=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconDomainAndAddress`,buttonStyle:r,connectionVariant:a=`modal`})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s,loginMethods:c}=$(),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)(Ya,{darkMode:s,children:[d.isConnected&&p?(0,i.jsx)(da,{mobileVariant:e,desktopVariant:t,onOpen:v.onOpen,buttonStyle:r}):a===`popover`&&!g?(0,i.jsx)(la,{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(`Login`)}),(0,i.jsx)(sa,{isOpen:_.isOpen,onClose:_.onClose}),(0,i.jsx)(oa,{isOpen:v.isOpen,onClose:v.onClose})]})},pa=()=>{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:T.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:k.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:k.FaDiscord,color:`white`,fontSize:`20px`})}),(0,i.jsx)(n.Icon,{zIndex:1,as:g.LuPlus,color:e?`black`:`white`,fontSize:`15px`})]})},ma=({status:e,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=t.vt(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:d(e===`error`?`Try again`:`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,variant:`ghost`,size:`sm`,borderRadius:`full`,"aria-label":`Close`,icon:(0,i.jsx)(n.Icon,{as:g.LuX,boxSize:4})})]}):null},ha=({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)(ma,{status:r,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:t})}):null},ga=({isOpen:e,onClose:t,error:n,title:r,loadingText:a,onTryAgain:o=()=>{}})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,trapFocus:!1,autoFocus:!1,backdropFilter:`blur(3px)`,children:n?(0,i.jsx)(va,{error:n,onClose:t,onTryAgain:o}):(0,i.jsx)(_a,{loadingText:a,title:r,onTryAgain:o})}),_a=({loadingText:e,title:t,onTryAgain:a})=>{let{t:o}=(0,l.useTranslation)(),[s,c]=r.default.useState(!1);return r.default.useEffect(()=>{let e=setTimeout(()=>{c(!0)},7e3);return()=>clearTimeout(e)},[C.isMobile]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(J,{children:(0,i.jsx)(n.ModalHeader,{children:t??o(`Connecting...`)})}),(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&&!s&&(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:e}),s&&(0,i.jsxs)(n.VStack,{mt:4,spacing:2,children:[(0,i.jsx)(n.Text,{color:`orange.300`,size:`sm`,textAlign:`center`,children:o(`This is taking longer than expected.`)}),(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:o(`You may want to try establishing the connection again.`)})]})]}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:s&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:a,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),o(`Try again`)]})})]})},va=({error:e,onClose:t,onTryAgain:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`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:1/0},animate:{scale:[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}),a(`Try again`)]})})]})},ya=({onClose:e,appsInfo:a,isLoading:o})=>{let{t:s}=(0,l.useTranslation)(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),[u,d]=(0,r.useState)(),[f,p]=(0,r.useState)(),m=(0,n.useDisclosure)(),{setConnectionCache:h}=Fo(),{login:g}=En(),_=async(n,r)=>{m.onOpen();try{d(void 0),p(r);try{await g(n),m.onClose(),h({name:r,logoUrl:a.find(e=>e.id===n)?.logo_url,appId:n,website:a.find(e=>e.id===n)?.website}),e()}catch(e){let n=e?.message;if(n&&t.a(n))return Error(`Login request was cancelled.`);d((e instanceof Error?e:Error(`'An unexpected issue occurred while logging in with this app. Please try again or contact support.',`)).message)}}catch(e){console.error(s(`Login failed:`),e),d(e instanceof Error?e.message:s(`Failed to connect with ecosystem app`))}};return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(J,{children:(0,i.jsxs)(n.ModalHeader,{children:[s(`Already have an x2earn app wallet?`),(0,i.jsx)(n.ModalCloseButton,{onClick:()=>{e()}})]})}),(0,i.jsxs)(n.ModalBody,{children:[o&&(0,i.jsx)(n.VStack,{minH:`200px`,w:`full`,justifyContent:`center`,children:(0,i.jsx)(n.Spinner,{})}),!o&&a&&(0,i.jsx)(n.VStack,{spacing:4,w:`full`,pb:6,children:a.map(e=>(0,i.jsxs)(n.Button,{variant:`loginIn`,fontSize:`14px`,fontWeight:`400`,p:6,borderRadius:16,w:`full`,onClick:()=>{_(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))}),!o&&!a&&(0,i.jsx)(n.Text,{textAlign:`center`,color:c,children:s(`No application from VeChain ecosystem is available to login.`)})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]}),(0,i.jsx)(ga,{isOpen:m.isOpen,onClose:()=>{m.onClose()},error:u,title:`${s(`Connecting with`)} ${f}`,loadingText:s(`Please approve the request in the connection request window...`),onTryAgain:()=>{if(f){let e=a.find(e=>e.name===f);e&&_(e.id,e.name)}}})]})},ba=({isOpen:e,onClose:t,appsInfo:n,isLoading:r})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,backdropFilter:`blur(3px)`,children:(0,i.jsx)(ya,{onClose:t,appsInfo:n,isLoading:r})}),xa=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.vt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`);return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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})]})})]})})]})},Sa=({setCurrentContent:e,handleClose:t,style:r})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=js(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Is({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)(J,{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)(Dc,{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})})})]})},Ca=({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)(Ne,{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)(xa,{...a.props})}else if(a===`upgrade-smart-account`)return(0,i.jsx)(Sa,{setCurrentContent:o,handleClose:t,style:n})})()})},{definePartsStyle:wa,defineMultiStyleConfig:Ta}=(0,n.createMultiStyleConfigHelpers)(P.modalAnatomy.keys),Ea=e=>({vechainKitBase:wa({dialog:{scrollbarWidth:`none`,overflow:`scroll`,overflowX:`hidden`,maxHeight:`600px`,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:{bg:e.buttons.button.bg},_active:{bg:e.buttons.button.bg,opacity:.8}},header:{w:`full`,color:e.colors.text.primary,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.bold,textAlign:`center`}})}),Da=e=>Ta({variants:Ea(e),defaultProps:{variant:`vechainKitBase`}}),{definePartsStyle:Oa,defineMultiStyleConfig:ka}=(0,n.createMultiStyleConfigHelpers)(P.cardAnatomy.keys),Aa=e=>({vechainKitBase:Oa({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}`}}),featureAnnouncement:Oa({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:Oa({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`}})}),ja=e=>ka({variants:Aa(e),defaultProps:{variant:`vechainKitBase`}}),Ma=(0,n.defineStyle)({borderRadius:`12px`}),Na=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)(()=>({width:`full`,minHeight:`50px`,height:`fit-content`,borderRadius:e.borders.radius.xl,p:0,bg:e.colors.error+`1f`,_hover:{bg:e.colors.error+`5e`,color:e.colors.error},transition:`all 0.2s`,color:e.colors.error})),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`}))}),Pa=e=>(0,n.defineStyleConfig)({baseStyle:Ma,variants:Na(e)}),{definePartsStyle:Fa,defineMultiStyleConfig:Ia}=(0,n.createMultiStyleConfigHelpers)(P.popoverAnatomy.keys),La=e=>({vechainKitBase:Fa({popper:{zIndex:1e3},content:{borderRadius:e.borders.radius.xl,border:`none`,backgroundColor:e.colors.background.modal,boxShadow:`0px 4px 16px rgba(0, 0, 0, 0.12)`,minWidth:`380px`},body:{padding:`16px`}})}),Ra=e=>Ia({variants:La(e),defaultProps:{variant:`vechainKitBase`}}),za=(e,t)=>({useSystemColorMode:!1,disableTransitionOnChange:!1,components:{Modal:Da(t),Card:ja(t),Button:Pa(t),Popover:Ra(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},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}),Ba=(e,t)=>{let r=(0,n.extendTheme)(za(e,_e(ge(e),ve(t,e))));return r.styles.global=()=>({}),r.__cssVars&&(r.__cssVars.global=()=>({})),r},{ToastContainer:Va}=(0,n.createStandaloneToast)(),Ha=()=>(0,N.default)({key:`vechain-kit`,prepend:!0}),Ua=({bodyFont:e,headingFont:t})=>(0,i.jsx)(M.Global,{styles:M.css`
119
+ }`,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`))),ct.parse(s.data)},ut=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,e,t],dt=(e,t)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ut(e,t),queryFn:()=>lt(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})},ft=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,e,t],pt=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:ft(e??``,t.type),queryFn:async()=>e?(0,_.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})},mt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) view returns (string)`]),ht=async(e,n,r)=>{if(!r)return{};let i=(0,o.namehash)(r);try{let[{data:r,reverted:a}]=await(await fetch(`${e}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.vt(n).vetDomainsContractAddress,data:mt.encodeFunctionData(`resolver`,[i])}]})})).json();if(a)return{};let{resolverAddress:o}=mt.decodeFunctionResult(`resolver`,r);return(await(await fetch(`${e}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:t.x.map(e=>({to:o,data:mt.encodeFunctionData(`text`,[i,e])}))})})).json()).reduce((e,{data:n,reverted:r},i)=>{if(!r&&n&&n!==`0x`)try{let r=mt.decodeFunctionResult(`text`,n)[0];r&&(e[t.x[i]]=r)}catch(e){console.error(`Failed to decode text record for ${t.x[i]}:`,e)}return e},{})}catch(e){throw console.error(`Error fetching text records:`,e),e}},gt=(e,t)=>[`VECHAIN_KIT_TEXT_RECORDS`,e,t],_t=e=>{let{network:n}=$(),r=n.nodeUrl??t.vt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:gt(e,n.type),queryFn:()=>ht(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})},vt=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function setText(bytes32 node, string key, string value) external`]),yt=(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:vt.encodeFunctionData(`setText`,[t,i,a]),value:`0`,comment:`Update ${i} record`})}return n},bt=({onSuccess:e,onError:t,signerAccountAddress:n,resolverAddress:i}={})=>{let a=(0,r.useCallback)(e=>{if(!i)throw Error(`Resolver address is required`);return yt(i,e)},[i]),o=Kn({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))}},xt=e=>[`VECHAIN_KIT`,`RESOLVER_ADDRESS`,e],St=e=>{let{network:n}=$();return Jo({address:t.vt(n.type).vetDomainsContractAddress,abi:v.VetDomainsRegistry__factory.abi,method:`resolver`,args:[e?(0,y.namehash)(e):`0x`],queryOptions:{select:e=>e[0],enabled:!!e}})},Ct={Mugshot:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/mugshot.png`,Greencart:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/greencart.png`,Cleanify:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/cleanify.png`,EVearn:`https://prod-vechainkit-docs-images-bucket.s3.eu-west-1.amazonaws.com/evearn.png`},wt=`vechain_kit_cross_app_connection`,Tt=()=>{let e=t.lt(`vechain_kit_cross_app_connection`);if(!e)return null;try{let t=JSON.parse(e)?.ecosystemApp?.name;return t?Ct[t]??null:null}catch{return null}},Et=e=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR_OF_ADDRESS`,e],Dt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Et(e),queryFn:async()=>{if(!e||!n.nodeUrl)return Tt()??t.H(e??``);let r=await(0,_.getAddressDomain)(e,{networkUrl:n.nodeUrl});return r&&await(0,_.getAvatar)(r,{networkUrl:n.nodeUrl})||(Tt()??t.H(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})},Ot=new o.Interface([`function resolver(bytes32 node) returns (address resolverAddress)`,`function text(bytes32 node, string key) returns (string avatar)`]),kt=new o.Interface([`function tokenURI(uint256 tokenId) view returns (string)`,`function uri(uint256 id) view returns (string)`]),At=async(e,n,r)=>{if(!r)throw Error(`Name is required`);let i=(0,o.namehash)(r);try{let[{data:r,reverted:a}]=await(await fetch(`${n}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:t.vt(e).vetDomainsContractAddress,data:Ot.encodeFunctionData(`resolver`,[i])}]})})).json();if(a)return null;let{resolverAddress:o}=Ot.decodeFunctionResult(`resolver`,r),[{data:s,reverted:c}]=await(await fetch(`${n}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:[{to:o,data:Ot.encodeFunctionData(`text`,[i,`avatar`])}]})})).json();if(c||s===`0x`)return null;try{let{avatar:t}=Ot.decodeFunctionResult(`text`,s),r=t===``?null:t;return r?Mt(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}},jt=(e,t)=>[`VECHAIN_KIT`,`VET_DOMAINS`,`AVATAR`,`LEGACY`,e,t];async function Mt(e,n,r){try{if(e.startsWith(`http`)||e.startsWith(`ipfs://`)||e.startsWith(`ar://`))return t.h(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:kt.encodeFunctionData(l?`uri`:`tokenURI`,[BigInt(c||0)])}],[{data:d,reverted:f}]=await fetch(`${r}/accounts/*`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({clauses:u})}).then(e=>e.json());if(f)return console.error(`Failed to fetch tokenURI`),null;let p=``;try{p=kt.decodeFunctionResult(l?`uri`:`tokenURI`,d)[0]}catch(e){console.error(`Failed to decode avatar data:`,e),p=(0,o.toUtf8String)(d)}p=t.h(p,n)||p,l&&(p=p.replace(`{id}`,(0,o.zeroPadValue)((0,o.toBeHex)(BigInt(c||0)),32).slice(2)));let m=await fetch(p);if(!m.ok)return console.error(`Failed to fetch metadata`),null;let h=await m.json(),g=h.image||h.image_url||h.image_data;return g?t.h(g,n)||g:(console.error(`No image URL in metadata`),null)}return null}catch(e){return console.error(`Error parsing avatar record:`,e),null}}const Nt=e=>{let{network:n}=$(),r=n.nodeUrl??t.vt(n.type).nodeUrl;return(0,p.useQuery)({queryKey:jt(e??``,n.type),queryFn:async()=>e?At(n.type,r,e):null,enabled:!!e&&!!r&&!!n.type})},Pt=v.VetDomainsReverseRegistrar__factory.createInterface(),Ft=(e,n)=>{let r=[];return r.push({to:t.vt(n.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:Pt.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.U(e?.address??``,4,4)}`,abi:Pt.getFunction(`setName`)}),r},It=({onSuccess:e,onError:t})=>{let n=(0,p.useQueryClient)(),{account:i}=X(),{network:a}=$(),o=(0,r.useCallback)(()=>Ft(i,a),[i,a]),s=(0,r.useCallback)(async()=>{await Je(n,i?.address??``,``,``,``,a.type),e?.()},[e,n,i,a.type]),c=Kn({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())}},Lt=e=>{let{network:n}=$(),i=t.vt(n.type),{data:a,isLoading:o}=rs(e),{data:s,isLoading:c}=rn(e),{data:l,isLoading:u}=un(e),{data:d,isLoading:f}=cn(i.veDelegateTokenContractAddress,e),{data:p,isLoading:m}=cn(i.gloDollarContractAddress,e),h=on(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||_}},Rt={B3TR:`0x623374722d757364000000000000000000000000000000000000000000000000`,VET:`0x7665742d75736400000000000000000000000000000000000000000000000000`,VTHO:`0x7674686f2d757364000000000000000000000000000000000000000000000000`,GBP:`0x6762702d75736400000000000000000000000000000000000000000000000000`,EUR:`0x657572742d757364000000000000000000000000000000000000000000000000`},zt=async(e,n,r)=>{let i=await e.contracts.load(t.vt(r).oracleContractAddress,v.OracleVechainEnergy__factory.abi).read.getLatestValue(Rt[n]);if(!i)throw Error(`Failed to get price of ${n}`);return new a.BigNumber(i[0].toString()).div(0xe8d4a51000).toNumber()},Bt=e=>[`VECHAIN_KIT_PRICE`,e],Vt=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Bt(e),queryFn:async()=>zt(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})},Ht=()=>{let{network:e}=$(),n=t.vt(e.type),{data:i,isLoading:a}=Vt(`VET`),{data:o,isLoading:s}=Vt(`VTHO`),{data:c,isLoading:l}=Vt(`B3TR`),{data:u,isLoading:d}=Vt(`EUR`),{data:f,isLoading:p}=Vt(`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}},Ut=`vechain_kit_currency`,Wt=[`usd`,`eur`,`gbp`],Gt=()=>{let{currentCurrency:e,setCurrency:n}=$();return(0,r.useEffect)(()=>{t._t(`vechain_kit_currency`,e)},[e]),{currentCurrency:e,allCurrencies:Wt,changeCurrency:e=>{if(!Wt.includes(e)){console.error(`Invalid currency: ${e}`);return}n(e)}}},Kt=({address:e=``})=>{let{balances:t,isLoading:n}=Lt(e),{prices:i,exchangeRates:a,isLoading:o}=Ht(),{currentCurrency:s}=Gt(),c=(0,r.useMemo)(()=>t.map(e=>{let t=i[e.address]||0,n=Number(e.balance)*t,r=Pe(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}=Kt({address:e}),{currentCurrency:i}=Gt(),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)(()=>Ie(a,{currency:i}),[a,i]),isLoading:n,hasAnyBalance:t.length>0}},Jt=v.XAllocationVoting__factory.abi,Yt=`currentRoundId`,Xt=e=>Go({abi:Jt,address:e,method:Yt}),Zt=()=>{let{network:e}=$(),n=t.vt(e.type).xAllocationVotingContractAddress;return Jo({abi:Jt,address:n,method:Yt,args:[],queryOptions:{select:e=>e[0].toString()}})},Qt=async(e,t)=>(0,_.getTokenInfo)(e,{networkUrl:t}),$t=e=>[`VECHAIN_KIT_CUSTOM_TOKEN_INFO`,e],en=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:$t(e),queryFn:async()=>{if(!e)throw Error(`Token address is required`);if(!t.nodeUrl)throw Error(`Network node URL is required`);return Qt(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})},tn=()=>{let[e,n]=lc(cc.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 Qt(t,r.nodeUrl),address:t};n([...e,i])}},a=t=>{n(e.filter(e=>e.address!==t))},o=n=>e.some(e=>t.O(e.address,n)),s=e=>{let n={vet:`0x`,vtho:t.vt(r.type).vthoContractAddress,b3tr:t.vt(r.type).b3trContractAddress,vot3:t.vt(r.type).vot3ContractAddress,veDelegate:t.vt(r.type).veDelegate};return Object.values(n).includes(e)};return{customTokens:e,addToken:i,removeToken:a,isTokenIncluded:o,isDefaultToken:s}},nn=e=>[`VEBETTERDAO_BALANCE`,e,`B3TR`],rn=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:nn(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,_.getB3trBalance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get b3tr balance`);let i=r[0];return t.V(i)},enabled:!!e&&!!n.type})},an=(e,t)=>[`VECHAIN_KIT_BALANCE`,t,`CUSTOM_TOKEN`,e],on=e=>{let{network:n}=$(),{customTokens:r}=tn();return(0,p.useQueries)({queries:r.map(r=>({queryKey:an(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,_.getErc20Balance)(r.address,e,{networkUrl:n.nodeUrl});if(!i)throw Error(`Failed to get token balance`);let a=t.V(i[0]);return{...r,...a}}}))})},sn=(e,t)=>[`VECHAIN_KIT`,`BALANCE`,`ERC20`,e,t],cn=(e,n)=>{let{network:r}=$();return(0,p.useQuery)({queryKey:sn(e,n),queryFn:async()=>{if(!n)throw Error(`Address is required`);let i=await(0,_.getErc20Balance)(e,n,{networkUrl:r.nodeUrl});if(!i)throw Error(`Failed to get vot3 balance`);let a=i[0];return t.V(a)},enabled:!!n&&!!r.type})},ln=e=>[`VEBETTERDAO_BALANCE`,e,`VOT3`],un=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:ln(e),queryFn:async()=>{if(!e)throw Error(`Address is required`);let r=await(0,_.getVot3Balance)(e,{networkUrl:n.nodeUrl});if(!r)throw Error(`Failed to get vot3 balance`);let i=r[0];return t.V(i)},enabled:!!e&&!!n.type})},dn=(e,t)=>[`VECHAIN_KIT`,`IS_PERSON`,e,t],fn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:dn(e??``,t.type),queryFn:async()=>{if(!e)throw Error(`User address is required`);return(0,_.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})},pn=v.XAllocationVoting__factory.abi,mn=`getAppsOfRound`,hn=(e,n)=>qo({abi:pn,address:t.vt(n).xAllocationVotingContractAddress,method:mn,args:[BigInt(e??0)]}),gn=e=>{let{network:n}=$(),r=t.vt(n.type).xAllocationVotingContractAddress;return Jo({abi:pn,address:r,method:mn,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()}))}})},_n=v.XAllocationPool__factory.abi,vn=`getAppShares`,yn=e=>[`VECHAIN_KIT`,`XApps`,`Shares`,e],bn=(e,n)=>{let r=(0,f.useThor)(),{network:i}=$(),a=t.vt(i.type).xAllocationPoolContractAddress;return(0,p.useQuery)({queryKey:yn(n),queryFn:async()=>(await t.r({thor:r,calls:e.map(e=>({abi:_n,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})},xn=e=>{let{data:t}=gn(e),n=bn(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}},Sn=({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 C.isMobile&&a&&!t.a(a)?Error(n):a&&t.a(a)?Error(r):e instanceof Error?e:Error(i)},Cn=(0,y.defineChain)({id:`1176455790972829965191905223412607679856028701100105089447013101863`,name:`Vechain`,nativeCurrency:{name:`VeChain`,symbol:`VET`,decimals:18},rpcUrls:{default:{http:[`https://mainnet.vechain.org`]}},blockExplorers:{default:{name:`Vechain Explorer`,url:`https://explore.vechain.org`},vechainStats:{name:`Vechain Stats`,url:`https://vechainstats.com`}}}),wn=()=>(0,S.toPrivyWalletConnector)({id:t.rt,name:`VeChain`,iconUrl:`https://imagedelivery.net/oHBRUd2clqykxgDWmeAyLg/661dd77c-2f9d-40e7-baa1-f4e24fd7bf00/icon`,smartWalletMode:!1}),Tn=({privyEcosystemAppIDS:e,children:t})=>(0,i.jsx)(x.WagmiProvider,{config:(0,r.useRef)((0,x.createConfig)({chains:[Cn],ssr:!0,connectors:[wn(),...e.map(e=>(0,S.toPrivyWalletConnector)({id:e,name:``,iconUrl:``}))],transports:{[Cn.id]:(0,x.http)()},multiInjectedProviderDiscovery:!1})).current,children:t}),En=()=>{let{connectAsync:e,connectors:n}=(0,x.useConnect)(),{signTypedDataAsync:i}=(0,x.useSignTypedData)(),{signMessageAsync:a}=(0,x.useSignMessage)(),{disconnectAsync:o}=(0,x.useDisconnect)(),{isConnected:s}=(0,x.useAccount)(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{try{s&&(await o(),t.ft()&&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.rt));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 Sn({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 Sn({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}},Dn=(e,n)=>{let{data:r,isLoading:i}=Ue(e??``),{data:a,isLoading:o}=Dt(e??``),{data:s,isLoading:c}=_t(r?.domain??``),l=s?.header?t.h(s.header,n):null;return{domain:r?.domain,image:a,records:{...s,header:l},isLoading:i||o||c}},X=()=>{let{address:e,isConnected:n,isConnecting:i,isReconnecting:a}=(0,x.useAccount)(),{logout:o}=En(),{loading:s}=(0,u.useLoginWithOAuth)({}),{feeDelegation:c,network:l,privy:d}=$(),{user:p,authenticated:m,logout:h,ready:g}=(0,u.usePrivy)(),{data:_}=Hs(),{account:v,disconnect:y}=(0,f.useWallet)(),{getConnectionCache:b,clearConnectionCache:S}=Fo(),C=b(),w=Qo(),T=!!v,E=m&&!!p,D=E||n,O=E&&d?.appId===t.rt||n&&C?.ecosystemApp?.appId===t.rt,k=i||a||s||!g,[A,j]=(0,r.useState)(!1),M=n?{type:`privy-cross-app`,displayName:`Ecosystem`}:T?{type:`wallet`,displayName:`Wallet`}:{type:`privy`,displayName:`Social Login`};(0,r.useEffect)(()=>{let e=T||E||n;A!==e&&(j(e),e||(S(),t.ft()&&window.dispatchEvent(new Event(`wallet_disconnected`))))},[T,E,n,S,A]);let N=p?.linkedAccounts?.find(e=>e.type===`wallet`&&e.connectorType===`embedded`)?.address,P=T?v:n?e:N,{data:F}=Os(P),I=T?v:F?.address,L=Dn(I??``,l.type),R=Dn(P??``,l.type),z=Dn(F?.address??``,l.type),B=I?{address:I,domain:L.domain,image:L.image,isLoadingMetadata:L.isLoading,metadata:L.records}:null,V=P?{address:P,domain:R.domain,image:R.image,isLoadingMetadata:R.isLoading,metadata:R.records}:null,{data:ee}=hs(F?.address??``,V?.address??``),te=!!F?.address&&!!B?.address&&t.O(F?.address,B?.address),ne=(0,r.useCallback)(async()=>{try{j(!1),T?y():E?await h():n&&await o(),S(),t.ft()&&window.dispatchEvent(new Event(`wallet_disconnected`))}catch(e){console.error(`Error during disconnect:`,e)}},[T,y,E,h,n,o,S]);return{account:B,smartAccount:{address:F?.address??``,domain:z.domain,image:z.image,isDeployed:F?.isDeployed??!1,isActive:te,version:ee?.version??null,isLoadingMetadata:z.isLoading,metadata:z.records},connectedWallet:V,privyUser:p,connection:{isLoading:k,isConnected:A,isConnectedWithSocialLogin:E,isConnectedWithDappKit:T,isConnectedWithCrossApp:n,isConnectedWithPrivy:D,isConnectedWithVeChain:O,source:M,isInAppBrowser:(t.ft()&&window.vechain&&window.vechain.isInAppBrowser)??!1,nodeUrl:w,delegatorUrl:c?.delegatorUrl,chainId:_,network:l.type},disconnect:ne}},On=()=>{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`]})])}}},kn=async(e,n)=>{let r=t.h(e,n)||``,i=await fetch(r,{signal:AbortSignal.timeout(2e4)});if(!i.ok)throw Error(`HTTP error! status: ${i.status}`);return await i.json()},An=v.X2EarnApps__factory.abi,jn=e=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:[`xAppMetaData`,e],queryFn:async()=>{let i=t.vt(r.type).x2EarnAppsContractAddress,a=n.contracts.load(i,An),o=(await a.read.app(e))[0][3]?.toString()||``,[s]=await a.read.baseURI();return await kn(`${s}${o}`,r.type)},enabled:!!e})},Mn=async(e,n,r=!1)=>{if(!n)throw Error(`No URI provided`);let i=t.h(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},Nn=(e,t)=>[`VECHAIN_KIT`,`IPFS_METADATA`,e,t],Pn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQuery)({queryKey:Nn(n.type,e),queryFn:()=>Mn(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})},Fn=1024*1024*10,In=async(e,n)=>{if(!n)throw Error(`IPFS URI is required`);let r=await fetch(t.h(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>Fn)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.g(i.type)})},r.onerror=()=>{n(Error(`Error occurred while reading blob.`))}})},Ln=(e,t)=>[`VECHAIN_KIT`,`IPFS_IMAGE`,e,t],Rn=e=>{let{network:t}=$();return(0,p.useQuery)({queryKey:Ln(t.type,e),queryFn:()=>In(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})},zn=e=>{let{network:t}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Ln(t.type,e),queryFn:()=>In(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}))})},Bn=(e,t=!1)=>{let{network:n}=$();return(0,p.useQueries)({queries:e.map(e=>({queryKey:Nn(n.type,e),queryFn:async()=>Mn(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}))})},Vn={maxSizeMB:.4,maxWidthOrHeight:1920,useWebWorker:!0},Hn=async e=>{let t=[];try{for(let n of e){let e=await(0,w.default)(n.file,Vn);t.push(e)}return t}catch(e){throw console.error(`compress error`,e),e}},Un=({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,w.default)(n,Vn));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}},Wn=({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,w.default)(n,Vn));let r={file:n,image:URL.createObjectURL(n)};return i(r),r},[e]),onRemove:a}},Gn=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)},Kn=({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=Qo(),_=qc(),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 Gn(u,[...i],e,{revision:s.Revision.NEXT,...c?{gasPadding:c}:{}})}catch(e){console.error(`Gas estimation failed`,e)}return(await p(i,{signer: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]),[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}=ec(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}},qn=(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}=Kn({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}},Jn=e=>e===`0x`||e===y.zeroAddress,Yn=(e,t,n,r)=>{let i={},a=r.toLowerCase();for(let t of e)try{let e=(0,y.decodeEventLog)({abi:v.MyERC20__factory.abi,eventName:`Transfer`,topics:t.topics,data:t.data}),n=e.args.from.toLowerCase(),r=e.args.to.toLowerCase(),o=e.args.value,s=typeof o==`bigint`?o:BigInt(o);if(n!==a&&r!==a)continue;let c=t.address.toLowerCase(),l=i[c]??{inflow:0n,outflow:0n};n===a&&(l.outflow+=s),r===a&&(l.inflow+=s),i[c]=l}catch{continue}if(n!==void 0){let e=BigInt(n);if(e>0n){let t=i[y.zeroAddress]??{inflow:0n,outflow:0n};t.outflow+=e,i[y.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[y.zeroAddress]??{inflow:0n,outflow:0n};n.inflow+=t,i[y.zeroAddress]=n}return i},Xn=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=Yn(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=Jn(e.fromTokenAddress),d=Jn(e.toTokenAddress),f=BigInt(e.amountIn);if(u){let e=c[y.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!==y.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===y.zeroAddress?`VET`:e} has outflow ${n.outflow.toString()}, expected 0`}}if(t.minimumOutputAmount&&t.minimumOutputAmount>0n)if(d){let e=c[y.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`}}},Zn=e=>e.startsWith(`0x`)?BigInt(e).toString():e,Qn=(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`}),$n=(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[Qn(t,e)]}return e},er=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,y.encodeFunctionData)({abi:$n(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`}`)}},tr=e=>{let t=er(e.functionCall);return{to:e.to,value:Zn(e.value),data:t,comment:e.comment||`Swap on aggregator`}},nr=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=await fetch(`${e.apiBaseUrl}?${r.toString()}`);if(!i.ok)throw Error(`API request failed: ${i.status} ${i.statusText}`);let a=await i.json(),o=a.clauses.map(tr),s=BigInt(a.amountOut),c=BigInt(a.amountOutMin);return{aggregatorName:e.name,aggregator:t,outputAmount:s,minimumOutputAmount:c,priceImpact:0,data:{clauses:o,path:a.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 Xn(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},rr={main:{supportedAddresses:[`0xE5fA980a6EfE5B79C2150a529da06AeF455963b6`,`0x7C755EC0165fCD926cC6faB10E7BB16a72E9f34A`]},test:{supportedAddresses:[]},solo:{supportedAddresses:[]}},ir=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,ar=e=>{let t={main:`https://vetrade.vet/api/quote/vck`,test:`https://vetrade.vet/api/quote/vck`,solo:`https://vetrade.vet/api/quote/vck`};return t[e]||t.main},or=t=>{let n=rr[t]??rr.main,i=nr({name:`VeTrade.vet`,apiBaseUrl:ar(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 Xn(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(ir(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(v.MyERC20__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}}},sr=e=>e===`0x`||e===`0x0000000000000000000000000000000000000000`,cr=()=>BigInt(Math.floor(Date.now()/1e3)+1200),lr=e=>{let t={name:e.name,getIcon:e.getIcon,async getQuote(n,r){let i=[sr(n.fromTokenAddress)?e.wrappedVET:n.fromTokenAddress,sr(n.toTokenAddress)?e.wrappedVET:n.toTokenAddress],a=BigInt(n.amountIn);try{let[o]=await r.contracts.load(e.routerAddress,v.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 Xn(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=cr();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=sr(t.fromTokenAddress),c=sr(t.toTokenAddress),l=s.ABIContract.ofAbi(v.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(v.MyERC20__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},ur={main:{routerAddress:`0xf21Dd7108D93af56FaB07423EfB90F4a3604DA89`,wrappedVET:`0xf9b02b47694fd635A413F16dC7B38aF06Cc16fe5`},test:{routerAddress:y.zeroAddress,wrappedVET:y.zeroAddress},solo:{routerAddress:y.zeroAddress,wrappedVET:y.zeroAddress}},dr=t=>{let n=ur[t]??ur.main;return lr({name:`BetterSwap.io`,routerAddress:n.routerAddress,wrappedVET:n.wrappedVET,getIcon:(t=`20px`)=>r.default.createElement(e.n,{boxSize:t})})},fr=e=>[or(e),dr(e)],pr=(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}=en(l===`0x`||l===y.zeroAddress||!l?``:l),{data:m}=en(u===`0x`||u===y.zeroAddress||!u?``:u),h=(0,r.useMemo)(()=>!l||l===`0x`||l===y.zeroAddress||!d?18:Number(d?.decimals??18),[l,d?.decimals]),g=(0,r.useMemo)(()=>!u||u===`0x`||u===y.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,y.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:b,error:x}=(0,p.useQuery)({queryKey:[`unified-swap-quotes`,_,c.network],queryFn:async()=>{if(!_||!s||!c.network)return{quotes:[],best:null};let e=fr(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:b,error:x,from:e?{...e,address:l??``,decimals:h}:null,to:t?{...t,address:u??``,decimals:g}:null}},mr=({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)(Ne,{isOpen:o,onClose:s,trapFocus:!1,children:[(0,i.jsxs)(J,{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`)})]})})]})]})},hr=()=>{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)(mr,{isOpen:d.isOpen,onClose:d.onClose,onResend:()=>s({email:a}),email:a,isLoading:c.status===`sending-code`})]})},gr=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Po();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:async()=>{await a({provider:`google`})},icon:T.FcGoogle,text:r(`Continue with Google`)})})},_r=({isDark:e,gridColumn:t})=>{let{t:r}=(0,l.useTranslation)(),{initOAuth:a}=Po();return(0,i.jsx)(n.GridItem,{colSpan:t??4,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:async()=>{await a({provider:`github`})},icon:g.LuGithub,text:r(`Continue with Github`)})})},vr=({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)(ca,{isDark:t,onClick:o,icon:t?e.b:e.x,text:a(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(pa,{})})})},yr=({isDark:t,gridColumn:a})=>{let{t:o}=(0,l.useTranslation)(),{login:s}=Io(),[c,u]=(0,r.useState)(),d=(0,n.useDisclosure)(),f=async()=>{d.onOpen();try{u(void 0),await s(),d.onClose()}catch(e){console.error(o(`Login failed:`),e),u(e instanceof Error?e.message:o(`Failed to connect with VeChain`))}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:a||4,w:`full`,children:(0,i.jsx)(ca,{isDark:t,onClick:f,icon:t?e.b:e.x,text:o(`Use social login with VeChain`),variant:`loginWithVechain`,rightIcon:(0,i.jsx)(pa,{})})}),(0,i.jsx)(ga,{isOpen:d.isOpen,onClose:()=>{d.onClose()},onTryAgain:()=>{f()},error:c,title:o(`Connecting to VeChain`),loadingText:o(`Please approve the request in the connection request window...`)})]})},br=({isDark:e,gridColumn:t})=>{let{t:a}=(0,l.useTranslation)(),{loginWithPasskey:o}=Mo(),[s,c]=(0,r.useState)(),u=(0,n.useDisclosure)(),d=async()=>{u.onOpen();try{c(void 0),await o(),u.onClose()}catch(e){(e instanceof Error?e.message.toLowerCase():``).includes(`not found`)&&(console.error(e),c(e instanceof Error?e.message:a(`Failed to connect with Passkey`)))}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.GridItem,{colSpan:t,w:`full`,children:(0,i.jsx)(ca,{isDark:e,onClick:d,icon:g.LuFingerprint,text:t&&t>=2?a(`Passkey`):void 0})}),(0,i.jsx)(ga,{isOpen:u.isOpen,onClose:()=>{u.onClose()},error:s,title:a(`Connecting with Passkey`),loadingText:a(`Please complete the passkey authentication...`),onTryAgain:()=>{d()}})]})},xr=({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]),(0,i.jsx)(n.GridItem,{colSpan:a||2,w:`full`,children:(0,i.jsx)(ca,{isDark:t,onClick:()=>{s()},icon:u?.allowedWallets?.includes(`sync2`)?g.LuWallet:t?e.o:e.a,iconWidth:`27px`,text:a>=2?p:void 0,rightIcon:u?.allowedWallets?.includes(`sync2`)&&(0,i.jsx)(n.Icon,{as:g.LuArrowRight})||void 0})})},Sr=({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)(ca,{isDark:e,onClick:t,icon:g.LuEllipsis,text:r&&r>=2?a(`More`):void 0,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuArrowRight})})})},Cr=()=>{let{loginMethods:e,darkMode:t}=$(),{login:r}=(0,u.usePrivy)(),{showGoogleLogin:a,showEmailLogin:o,showPasskey:s,showVeChainLogin:c,showDappKit:l,showMoreLogin:d,showGithubLogin:f,isOfficialVeChainApp:p}=To();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:e?.map(({method:e,gridColumn:n})=>{switch(e){case`email`:return o&&(0,i.jsx)(hr,{},`email`);case`google`:return a&&(0,i.jsx)(gr,{isDark:t,gridColumn:n},`google`);case`github`:return f&&(0,i.jsx)(_r,{isDark:t,gridColumn:n},`github`);case`vechain`:return c&&(p?(0,i.jsx)(vr,{isDark:t,gridColumn:n},`vechain`):(0,i.jsx)(yr,{isDark:t,gridColumn:n},`vechain`));case`passkey`:return s&&(0,i.jsx)(br,{isDark:t,gridColumn:n},`passkey`);case`dappkit`:return l&&(0,i.jsx)(xr,{isDark:t,gridColumn:n},`dappkit`);case`more`:return d&&(0,i.jsx)(Sr,{isDark:t,onViewMoreLogin:r,gridColumn:n},`more`);default:return null}})})})},wr=({appsInfo:e,isLoading:t})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useDisclosure)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Button,{fontSize:`sm`,variant:`link`,onClick:()=>{a.onOpen()},children:r(`Already have an x2earn app wallet?`)}),(0,i.jsx)(ba,{isOpen:a.isOpen,onClose:a.onClose,appsInfo:e,isLoading:t})]})},Tr=({setCurrentContent:e,onClose:t})=>{let{t:a}=(0,l.useTranslation)(),{connection:o}=X(),{loginModalUI:s,darkMode:c}=$(),{loginMethods:u,privyEcosystemAppIDS:d}=$(),{data:f,isLoading:p}=Be(d),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=()=>{e(`faq`)};(0,r.useEffect)(()=>{o.isConnected&&t()},[o.isConnected,t]);let g=u?.some(({method:e})=>e===`ecosystem`);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(wc,{onClick:h}),(0,i.jsx)(n.ModalHeader,{children:a(`Log in or sign up`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),s?.logo&&(0,i.jsx)(n.HStack,{justify:`center`,children:(0,i.jsx)(n.Image,{src:s.logo||`/images/favicon.png`,maxW:`180px`,maxH:`90px`,m:8,alt:`logo`})}),(0,i.jsxs)(n.ModalBody,{children:[s?.description&&(0,i.jsx)(n.HStack,{spacing:4,w:`full`,justify:`center`,mb:`24px`,px:4,children:(0,i.jsx)(n.Text,{color:m,fontSize:`sm`,textAlign:`center`,children:s?.description})}),(0,i.jsx)(Cr,{})]}),g?(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(wr,{isDark:c,appsInfo:Object.values(f||{}),isLoading:p})})}):(0,i.jsx)(n.ModalFooter,{pt:0,pb:`5px`})]})},Er=({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}=js(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":`Notifications`,size:`sm`,variant:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,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})},Dr=({setCurrentContent:e,wallet:t,onClose:r})=>{let{t:a}=(0,l.useTranslation)(),{network:o}=$();return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(Er,{onClick:()=>{e(`settings`)},"data-testid":`settings-button`}),(0,i.jsxs)(n.ModalHeader,{children:[a(`Wallet`),o?.type!==`main`&&(0,i.jsx)(n.Tag,{size:`xs`,colorScheme:`orange`,fontSize:`2xs`,p:1,ml:1,textTransform:`uppercase`,children:`${o?.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:6,children:[(0,i.jsx)(Kr,{style:{justifyContent:`flex-start`},onClick:()=>{e(`profile`)},setCurrentContent:e,onClose:r,wallet:t}),(0,i.jsx)(Jr,{onAssetsClick:()=>{e(`assets`)}}),(0,i.jsx)(Zr,{setCurrentContent:e})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Or=({onSelectToken:e,onBack:t,showAllTokens:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s}=$(),{currentCurrency:c}=Gt(),u=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),d=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),f=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{account:p}=X(),{tokensWithBalance:m,sortedTokens:h}=Kt({address:p?.address??``}),[_,v]=(0,r.useState)(``),y=(0,r.useMemo)(()=>{if(a){let e=h.filter(e=>Number(e.balance)>0),t=[...h.filter(e=>Number(e.balance)===0)].sort((e,t)=>e.symbol.localeCompare(t.symbol));return[...e,...t]}return m},[a,h,m]).filter(({symbol:e})=>e.toLowerCase().includes(_.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:o(`Select Token`)}),(0,i.jsx)(q,{onClick:t}),(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:s?`vechain-kit-overlay`:`vechain-kit-card`,borderRadius:`xl`,height:`56px`,pl:12,value:_,onChange:e=>v(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:f})})]}),(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:u,mt:4,children:o(a?`All tokens`:`Your tokens`)}),y.length===0?(0,i.jsxs)(n.VStack,{spacing:2,py:8,children:[(0,i.jsx)(n.Icon,{as:g.LuSlash,boxSize:12,color:f}),(0,i.jsx)(n.Text,{fontSize:`lg`,color:u,children:o(`No tokens found`)}),(0,i.jsx)(n.Text,{fontSize:`md`,color:d,children:o(`Try searching with a different term`)})]}):(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,children:y.map(t=>(0,i.jsx)(Le,{symbol:t.symbol,amount:Number(t.balance),currencyValue:t.valueInCurrency,currentCurrency:c,onClick:()=>e(t)},t.address))})]})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},kr=()=>{let{isolatedView:e,closeAccountModal:t}=Q();return{isolatedView:e,closeAccountModal:t}},Ar=({setCurrentContent:e,preselectedToken:a,initialAmount:s=``,initialToAddressOrDomain:c=``,onBack:u=()=>e(`main`)})=>{let{t:d}=(0,l.useTranslation)(),{darkMode:f,feeDelegation:p}=$(),{currentCurrency:m}=Gt(),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}=Ht(),{account:S}=X(),{isolatedView:C}=kr(),{tokensWithBalance:w}=Kt({address:S?.address??``}),[T,O]=(0,r.useState)(a??w[0]??null),[k,A]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!a&&!T&&w.length>0&&O(w[0])},[w,a,T]);let{register:j,watch:M,setValue:N,setError:P,formState:{errors:F,isValid:I},handleSubmit:L}=(0,E.useForm)({defaultValues:{amount:s,toAddressOrDomain:c},mode:`onChange`}),{toAddressOrDomain:R,amount:z}=M(),B=(0,r.useRef)(T);(0,r.useEffect)(()=>{B.current&&T&&B.current.address!==T.address&&N(`amount`,``),B.current=T},[T,N]);let V=(0,r.useMemo)(()=>T?Ie(Pe(Number(z)*T.priceUsd,m,x),{currency:m}):``,[z,T,m,x]),{data:ee,isLoading:te}=Ue(R),ne=()=>{T&&N(`amount`,T.balance)},re=()=>{u()},H=async t=>{if(T){if(!(ee?.isValidAddressOrDomain&&(!ee?.domain||ee?.domain&&ee?.isPrimaryDomain))){P(`toAddressOrDomain`,{type:`manual`,message:d(`Invalid address or domain`)});return}if(T){let e=(0,o.parseEther)(t.amount),n=p?.b3trTransfers?.minAmountInEther;if(T.symbol===`B3TR`&&typeof n==`number`&&n>0)try{if(e<(0,o.parseEther)(String(n))){P(`amount`,{type:`manual`,message:d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:T.symbol,min:n})});return}}catch{}if(e>(0,o.parseEther)(T.balance)){P(`amount`,{type:`manual`,message:d(`Insufficient {{symbol}} balance`,{symbol:T.symbol})});return}}e({type:`send-token-summary`,props:{toAddressOrDomain:t.toAddressOrDomain,resolvedDomain:ee?.domain,resolvedAddress:ee?.address,amount:t.amount,selectedToken:T,formattedTotalAmount:V,setCurrentContent:e}})}};return k?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:e=>{O(e),A(!1)},onBack:()=>{A(!1)}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Send`)}),!C&&(0,i.jsx)(q,{onClick:re}),(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:ne,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:_,children:[d(`Balance`),`:`,` `,Number(T?.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:6,borderRadius:`2xl`,bg:b,children:(0,i.jsx)(n.VStack,{align:`stretch`,spacing:2,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!F.amount,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,children:[(0,i.jsx)(n.Input,{...j(`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 T?.symbol===`B3TR`&&typeof n==`number`&&n>0&&t<n?d(`Minimum {{symbol}} transfer is {{min}}`,{symbol:T.symbol,min:n}):!0}}),onChange:e=>{let t=e.target.value.trim();e.target.value=t,N(`amount`,t,{shouldValidate:!0})},placeholder:`0`,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`tx-amount-input`,type:`number`,inputMode:`decimal`,color:h}),T?(0,i.jsxs)(n.Button,{variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:_,borderColor:_,_hover:{bg:f?`whiteAlpha.300`:`blackAlpha.300`},onClick:()=>A(!0),leftIcon:t.Q[T.symbol]?r.default.cloneElement(t.Q[T.symbol],{boxSize:`20px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.Z[T.symbol],alt:`${T.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:T.symbol.slice(0,3)})})}),children:[T.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:()=>A(!0),children:[d(`Select token`),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:_})]})]}),T&&(0,i.jsx)(n.HStack,{spacing:1,fontSize:`sm`,justifyContent:`space-between`,color:_,children:(0,i.jsxs)(n.Text,{color:_,children:[`≈ `,V]})}),F.amount&&(0,i.jsx)(n.Text,{color:`#ef4444`,fontSize:`sm`,mt:1,"data-testid":`amount-error-msg`,children:F.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:6,width:`100%`,children:(0,i.jsxs)(n.FormControl,{isInvalid:!!F.toAddressOrDomain,children:[(0,i.jsx)(n.Input,{...j(`toAddressOrDomain`,{required:d(`Address is required`)}),onChange:e=>{let t=e.target.value.trim(),n=t.includes(`.`)?(0,D.ens_normalize)(t):t;e.target.value=n,N(`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`}),F.toAddressOrDomain&&(0,i.jsx)(n.Text,{color:y,fontSize:`sm`,"data-testid":`address-error-msg`,children:F.toAddressOrDomain.message})]})})})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,isDisabled:!T||!I,isLoading:te,onClick:L(H),"data-testid":`send-button`,children:d(T?`Send`:`Select Token`)})})]})},jr=({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}=Dt(s??``),{network:_,feeDelegation:v}=$(),{preferences:y}=bc(),{isolatedView:b,closeAccountModal:x}=kr(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),{data:w}=js(p?.address??``,h?.address??``,3),{open:T}=Eo(),E=(0,r.useMemo)(()=>g||t.H(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=t=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:f(`Transaction successful`),onDone:()=>{b?x():e(`main`)},showSocialButtons:!0}})},{sendTransaction:k,txReceipt:A,error:j,isWaitingForWalletConfirmation:M,isTransactionPending:N,clauses:P}=Js({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,tokenAddress:u.address,tokenName:u.symbol,onSuccess:()=>{O(A?.meta.txID??``)},onError:e=>{re(e??``)}}),{sendTransaction:F,txReceipt:I,error:L,isWaitingForWalletConfirmation:R,isTransactionPending:z,clauses:B}=Xs({fromAddress:p?.address??``,receiverAddress:s||a,amount:c,onSuccess:()=>{O(I?.meta.txID??``)},onError:e=>{re(e??``)}}),V=()=>u.symbol===`VET`?I:A,ee=M||R,te=ee||N||z,ne=()=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:u,initialAmount:c,initialToAddressOrDomain:a}})},re=e=>{console.error(`Transaction failed:`,e)},[H,ie]=r.default.useState(null),[ae,U]=r.default.useState(null),oe=y.availableGasTokens.length>0&&(m.isConnectedWithPrivy||m.isConnectedWithVeChain)&&!v?.delegatorUrl,{data:se,isLoading:W,error:ce,refetch:le}=xc({clauses:u.symbol===`VET`?B:P,tokens:H?[H]:y.availableGasTokens,sendingAmount:c,sendingTokenSymbol:u.symbol,enabled:oe&&!!v?.genericDelegatorUrl}),ue=se?.usedToken,G=(W||!se)&&m.isConnectedWithPrivy&&!v?.delegatorUrl,de=r.default.useCallback(e=>{ie(e),U(e),setTimeout(()=>le(),100)},[le]),fe=!!ue&&!ce;return r.default.useEffect(()=>{ce&&H&&ie(null)},[ce,H]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:`Send`}),(0,i.jsx)(q,{isDisabled:te,onClick:ne}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:te})]}),(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.jsx)(Cc,{label:f(`From`),address:p?.address??``,domain:p?.domain,imageSrc:p?.image??``,imageAlt:`From account`,balance:Number(u.balance),tokenAddress:u.address}),(0,i.jsx)(Cc,{label:f(`To`),address:s||a,domain:o,imageSrc:E??``,imageAlt:`To account`,tokenAddress:u.address}),m.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:se,isLoading:W,isLoadingTransaction:te,onTokenChange:de,clauses:u.symbol===`VET`?B:P,userSelectedToken:ae}),(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)(Dc,{transactionError:u.symbol===`VET`?L:j,isSubmitting:te,isTxWaitingConfirmation:ee,onConfirm:D,transactionPendingText:f(`Sending...`),txReceipt:V(),buttonText:f(`Confirm`),isDisabled:te||G,gasEstimationError:ce,hasEnoughGasBalance:fe,isLoadingGasEstimation:W,showGasEstimationError:!v?.delegatorUrl&&m.isConnectedWithPrivy,context:`send`})})]})},Mr=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{account:r}=X(),{isolatedView:a}=kr(),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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Receive`)}),!a&&(0,i.jsx)(q,{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)(O.QRCode,{value:r?.address??``,size:200,removeQrCodeBehindLogo:!0,eyeRadius:4,logoPaddingStyle:`circle`,style:{borderRadius:`16px`}}),(0,i.jsx)(De,{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})]})]})},Nr=({quotes:e,selectedQuote:a,toTokenAddress:o,onSelectQuote:s,onBack:c})=>{let{t:u}=(0,l.useTranslation)(),{darkMode:d}=$(),{currentCurrency:f}=Gt(),{account:p}=X(),{exchangeRates:m,prices:h}=Ht(),{tokens:_}=Kt({address:p?.address??``}),[v,b]=(0,r.useState)(!1),x=(0,r.useMemo)(()=>o&&_.find(e=>t.O(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,y.formatEther)(BigInt(t.outputAmount||`0`)),r=Number(n)*e,i=Pe(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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:u(`Found following rates`)}),(0,i.jsx)(q,{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.Q[x.symbol]?r.default.cloneElement(t.Q[x.symbol],{boxSize:`24px`,borderRadius:`full`}):t.Z[x.symbol]?(0,i.jsx)(n.Image,{src:t.Z[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:[`≈ `,Ie(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:()=>b(!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,{})]})},Pr=e=>e===`0x`||e===y.zeroAddress||!e,Fr=(e,t,n,r)=>{if(!e||!t||!n||!r)return null;let i=t.toLowerCase(),a=n.toLowerCase(),o=r.toLowerCase(),s=Pr(n),c=Pr(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=v.MyERC20__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,y.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}},Ir=({setCurrentContent:e,fromTokenAddress:a,toTokenAddress:o})=>{let{t:s}=(0,l.useTranslation)(),{account:c,connection:u}=X(),{currentCurrency:d}=Gt(),{network:f,feeDelegation:p,darkMode:m}=$(),{isolatedView:h,closeAccountModal:_}=kr(),v=(0,n.useToken)(`colors`,`vechain-kit-card`),b=(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`),{preferences:C}=bc(),{sortedTokens:w}=Kt({address:c?.address??``}),[T,E]=(0,r.useState)(`main`),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),[j,M]=(0,r.useState)(``),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(1),[L,R]=(0,r.useState)(`1`),[z,B]=(0,r.useState)(null),[V,ee]=r.default.useState(null),[te,ne]=r.default.useState(null),[re,H]=r.default.useState([]),{prices:ie,exchangeRates:ae}=Ht(),U=F===1;r.default.useEffect(()=>{R(F===1?`1`:F===.5?`0.5`:F===3?`3`:F.toString())},[F]),r.default.useEffect(()=>{if(w.length!==0){if((a||o)&&(!D||!k)){if(a&&!D){let e=w.find(e=>t.O(e.address,a));e&&O(e)}if(o&&!k){let e=w.find(e=>t.O(e.address,o));e&&A(e)}return}if(!D&&!k){let e=w.find(e=>e.symbol===`VET`);e&&O(e);let n=w.find(e=>e.symbol===`B3TR`);if(!n)try{let e=t.vt(f.type).b3trContractAddress;e&&(n=w.find(n=>t.O(n.address,e)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}n&&A(n)}}},[w,D,k,a,o,f.type]),r.default.useEffect(()=>{B(null)},[D?.address,k?.address,j]);let{bestQuote:oe,quotes:se,isLoading:W,from:ce,to:le}=pr(D,k,j,c?.address??``,F,!!D&&!!k&&Number(j)>0),ue=(0,r.useMemo)(()=>{if(!j||Number(j)<=0||!ce)return 0n;try{return(0,y.parseUnits)(j,ce.decimals)}catch{return 0n}},[j,ce?.decimals]),G=z||oe,de=(0,r.useMemo)(()=>{if(!G?.outputAmount||!le)return`0`;try{return(0,y.formatUnits)(G.outputAmount,le.decimals)}catch{return`0`}},[G,le?.decimals]),fe=(0,r.useMemo)(()=>{if(!D||!j)return 0;let e=ie[D.address]||0;return Pe(Number(j)*e,d,ae)},[D?.address,j,ie,d,ae]),pe=(0,r.useMemo)(()=>{if(!k||!de)return 0;let e=ie[k.address]||0;return Pe(Number(de)*e,d,ae)},[k?.address,de,ie,d,ae]),K=(0,r.useMemo)(()=>!D||!k||!c?.address||ue===0n?null:{fromTokenAddress:D.address,toTokenAddress:k.address,amountIn:ue.toString(),userAddress:c.address,slippageTolerance:F},[D,k,c?.address,ue,F]),me=G?.gasCostVTHO??0;r.default.useEffect(()=>{(async()=>{if(!G||!K||!G.aggregator){H([]);return}try{H(await G.aggregator.buildSwapTransaction(K,G))}catch(e){console.error(`Failed to build swap clauses for gas estimation:`,e),H([])}})()},[G,K]);let he=C.availableGasTokens.length>0&&(u.isConnectedWithPrivy||u.isConnectedWithVeChain)&&!p?.delegatorUrl,{data:ge,isLoading:_e,error:ve,refetch:ye}=xc({clauses:re,tokens:V?[V]:C.availableGasTokens,sendingAmount:j,sendingTokenSymbol:D?.symbol??``,enabled:he&&!!p?.genericDelegatorUrl&&re.length>0}),be=ge?.usedToken,xe=(_e||!ge)&&u.isConnectedWithPrivy&&!p?.delegatorUrl,Se=r.default.useCallback(e=>{ee(e),ne(e),setTimeout(()=>ye(),100)},[ye]),Ce=!!be&&!ve;r.default.useEffect(()=>{ve&&V&&ee(null)},[ve,V]);let{executeSwap:we,isTransactionPending:Te,isWaitingForWalletConfirmation:Ee,txReceipt:De,status:Oe,error:ke}=qn(K,G),Ae=(0,r.useCallback)(()=>{let t=De?.meta.txID??``,n=s(`Swap successful`,{defaultValue:`Swap successful`}),r;if(De&&D&&k&&c?.address){let e=Fr(De,c.address,D.address,k.address);if(e&&ce&&le)try{let t=ce.decimals,n=le.decimals,i=(0,y.formatUnits)(e.fromAmount,t),a=(0,y.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:D.symbol,toAmount:o(a),toSymbol:k.symbol,defaultValue:`You successfully swapped ${o(i)} ${D.symbol} for ${o(a)} ${k.symbol}`})}catch(e){console.warn(`Failed to format swap amounts:`,e)}}!r&&D&&k&&(r=s(`You successfully swapped {fromToken} for {toToken}`,{fromToken:D.symbol,toToken:k.symbol,defaultValue:`You successfully swapped ${D.symbol} for ${k.symbol}`})),e({type:`successful-operation`,props:{setCurrentContent:e,txId:t,title:n,description:r,onDone:()=>{h?_():e(`main`)},showSocialButtons:!0}})},[D,k,j,G,De,c?.address,e,s,h,_]),je=(0,r.useCallback)(e=>{let t=typeof e==`string`?e:e.message;console.error(`Swap failed:`,t)},[D,k,j]),[Me,Ne]=r.default.useState(!1);r.default.useEffect(()=>{if(Oe===`ready`){Ne(!1);return}Me||(Oe===`success`&&De&&!De.reverted?(Ne(!0),Ae()):Oe===`error`&&ke?je(ke?.reason||ke?.message||String(ke)):De?.reverted&&je(`Transaction reverted`))},[Oe,De,ke,Ae,je,Me]);let Fe=(0,r.useCallback)(e=>{if(O(e),e.symbol===`VET`&&!k){let e=w.find(e=>e.symbol===`B3TR`);if(!e)try{let n=t.vt(f.type).b3trContractAddress;n&&(e=w.find(e=>t.O(e.address,n)))}catch(e){console.warn(`Failed to get B3TR address from config:`,e)}e&&A(e)}E(`main`)},[k,w,f.type]),Le=(0,r.useCallback)(e=>{A(e),E(`main`)},[]),Re=(0,r.useCallback)(e=>{(/^\d*\.?\d*$/.test(e)||e===``)&&M(e)},[]),ze=(0,r.useCallback)(()=>{D&&M(D.balance)},[D]),Be=e=>{if(!e)return null;let n=t.Q[e.symbol],r=t.Z[e.symbol];return{symbol:e.symbol,logoComponent:n,logoUrl:r,balance:e.balance,value:e.valueInCurrency}},Y=Be(D),Ve=Be(k);return T===`select-from-token`?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:Fe,onBack:()=>E(`main`),showAllTokens:!1}):T===`select-quote`?(0,i.jsx)(Nr,{quotes:se,selectedQuote:G,toTokenAddress:k?.address??null,onSelectQuote:e=>{B(e),E(`main`)},onBack:()=>E(`main`)}):T===`select-to-token`?(0,i.jsx)(Or,{setCurrentContent:e,onSelectToken:Le,onBack:()=>E(`main`),showAllTokens:!0}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Swap`)}),!h&&(0,i.jsx)(q,{onClick:()=>e(`main`),isDisabled:Te||Ee}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:Te||Ee})]}),(0,i.jsx)(n.Container,{maxW:`container.lg`,p:0,children:(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:b,children:s(`From`)}),Y&&(0,i.jsxs)(n.Text,{cursor:`pointer`,_hover:{color:x,textDecoration:`underline`},onClick:ze,noOfLines:1,overflow:`hidden`,textOverflow:`ellipsis`,fontSize:`sm`,fontWeight:`medium`,color:x,children:[s(`Balance`),`:`,` `,Number(Y.balance??0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),(0,i.jsx)(n.Box,{p:6,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:j,onChange:e=>Re(e.target.value),fontSize:`4xl`,fontWeight:`bold`,variant:`unstyled`,"data-testid":`swap-amount-input`,type:`number`,inputMode:`decimal`,color:Y&&j&&Number(j)>Number(Y.balance)?`red.500`:b}),Y?(0,i.jsxs)(n.Button,{onClick:()=>E(`select-from-token`),variant:`outline`,size:`sm`,borderRadius:`full`,px:6,color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:Y.logoComponent?r.default.cloneElement(Y.logoComponent,{boxSize:`20px`,borderRadius:`full`}):Y.logoUrl?(0,i.jsx)(n.Image,{src:Y.logoUrl,alt:`${Y.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:b,children:Y.symbol.slice(0,3)})})}):void 0,children:[Y.symbol,(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:x})]}):(0,i.jsxs)(n.Button,{onClick:()=>E(`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})]})]}),Y&&(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:[`≈`,` `,Ie(fe,{currency:d})]})})})]})}),(0,i.jsx)(n.HStack,{justify:`space-between`,mt:4,children:(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:b,children:s(`To`)})}),(0,i.jsx)(n.Box,{borderRadius:`2xl`,bg:v,children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:2,p:6,width:`100%`,children:[(0,i.jsxs)(n.HStack,{justify:`space-between`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{value:Number(de).toLocaleString(void 0,{maximumFractionDigits:Number(de)>1e4?0:2}),readOnly:!0,variant:`unstyled`,fontSize:`4xl`,fontWeight:`bold`,"data-testid":`swap-output-amount`,color:b}),Ve?(0,i.jsxs)(n.Button,{onClick:()=>E(`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:b,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:()=>E(`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})]})]}),Ve&&(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:[`≈`,` `,Ie(pe,{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:N&&!!G,animateOpacity:!0,children:(0,i.jsxs)(n.VStack,{spacing:1,align:`stretch`,p:4,borderRadius:`2xl`,bg:v,children:[G&&(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:()=>E(`select-quote`),color:x,borderColor:x,_hover:{bg:m?`whiteAlpha.300`:`blackAlpha.300`},leftIcon:G.aggregator?.getIcon(`12px`),children:(0,i.jsx)(n.Text,{fontSize:`xs`,color:b,children:G.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:b,children:[F,`%`]})]}),(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:()=>{I(1)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:U?`rgb(96 66 221)`:`transparent`,color:U?`white`:x,borderColor:U?`rgb(96 66 221)`:x,_hover:{bg:U?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:U?.8:1},children:`Auto`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{I(.5)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:F===.5?`rgb(96 66 221)`:`transparent`,color:F===.5?`white`:x,borderColor:F===.5?`rgb(96 66 221)`:x,_hover:{bg:F===.5?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:F===.5?.8:1},children:`0.5%`}),(0,i.jsx)(n.Button,{size:`sm`,variant:`outline`,onClick:()=>{I(3)},flex:`0 0 auto`,minW:`60px`,borderRadius:`md`,fontSize:`xs`,bg:F===3?`rgb(96 66 221)`:`transparent`,color:F===3?`white`:x,borderColor:F===3?`rgb(96 66 221)`:x,_hover:{bg:F===3?`rgb(96 66 221)`:m?`whiteAlpha.300`:`blackAlpha.300`,opacity:F===3?.8:1},children:`3%`}),(0,i.jsxs)(n.InputGroup,{size:`sm`,flex:1,children:[(0,i.jsx)(n.Input,{value:L,onChange:e=>{let t=e.target.value;if((/^\d*\.?\d*$/.test(t)||t===``)&&(R(t),t!==``)){let e=parseFloat(t);!isNaN(e)&&e>=0&&e<=100&&I(e)}},placeholder:`1`,borderRadius:`md`,textAlign:`right`,pr:8,fontSize:`xs`,color:b}),(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:b,children:me>0?`${me.toLocaleString(void 0,{maximumFractionDigits:2})} VTHO`:`-`})]})]})}),G&&(0,i.jsx)(n.Box,{minH:`24px`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Button,{variant:`ghost`,size:`xs`,onClick:()=>P(!N),rightIcon:(0,i.jsx)(n.Icon,{color:S,_hover:{color:x},as:N?g.LuArrowUp:g.LuArrowDown}),fontSize:`xs`,fontWeight:`light`,color:S,_hover:{color:x},children:s(N?`Hide`:`Show Advanced Options`)})}),re.length>0&&u.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:ge,isLoading:_e,isLoadingTransaction:Te,onTokenChange:Se,clauses:re,userSelectedToken:te})]})})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsx)(Dc,{buttonText:s(W?`Loading quote...`:`Swap`),onConfirm:we,isSubmitting:Te,isTxWaitingConfirmation:Ee,transactionPendingText:s(`Swapping...`),txReceipt:De,transactionError:ke,onError:e=>{je(e)},isDisabled:!D||!k||!j||Number(j)<=0||W||!G||G?.reverted===!0||!!(Y&&j&&Number(j)>Number(Y.balance))||xe,gasEstimationError:ve,hasEnoughGasBalance:Ce,isLoadingGasEstimation:_e,showGasEstimationError:!p?.delegatorUrl&&u.isConnectedWithPrivy,context:`transaction`})})]})},Lr=({setCurrentContent:e,onBack:t=()=>e(`settings`),initialContentSource:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{isolatedView:o}=kr(),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)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:a(`Choose your account name`)}),!o&&(0,i.jsx)(q,{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`)})})]})},Rr=({domain:e,isCurrentDomain:r,onSelect:a})=>{let{connection:o}=X(),{t:s}=(0,l.useTranslation)(),c=Dn(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)(Ec,{props:{width:`40px`,height:`40px`,src:c.image??t.H(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.W(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)},zr=({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`)},Br=({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)(Rr,{domain:e,isCurrentDomain:e.name===s?.domain,onSelect:t},e.name)),s?.domain&&(0,i.jsx)(zr,{onUnset:r})]})})]})})})},Vr=({name:e,setCurrentContent:t,initialContentSource:a=`settings`})=>{let{t:o}=(0,l.useTranslation)(),{account:s}=X(),{darkMode:c}=$(),{isolatedView:u}=kr(),[d,f]=(0,r.useState)((0,D.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}=Ke(d),{data:E,isLoading:O}=Ue(`${d}.veworld.vet`),{data:k,isLoading:A}=ot(d),{data:j,isLoading:M}=dt(s?.address,``),N=T||O||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)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Choose Name`)}),!u&&(0,i.jsx)(q,{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)(Br,{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,D.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,onClick:P,"data-testid":`continue-button`,children:o(`Continue`)})})]})},Hr=({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}=kr(),{account:m,connectedWallet:h,connection:g}=X(),{data:_}=js(m?.address??``,h?.address??``,3),{open:v}=Eo(),{preferences:y}=bc(),{feeDelegation:b}=$(),x=e=>{console.error(`Transaction failed:`,e)},S=It({onSuccess:()=>M()}),C=a.endsWith(`veworld.vet`),w=Qe({subdomain:t.split(`.veworld.vet`)[0],domain:a,alreadyOwned:o,onSuccess:()=>M()}),T=nt({domain:!s&&!C?t:``,alreadyOwned:o,onSuccess:()=>M()}),{sendTransaction:E,txReceipt:D,error:O,isWaitingForWalletConfirmation:k,isTransactionPending:A,clauses:j}=s?S:C?w:T,M=()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:D?.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)}}})},N=async()=>{if(_){v();return}try{await E()}catch(e){console.error(`Transaction failed:`,e)}},P=()=>{N()},F=()=>{e({type:`choose-name-search`,props:{setCurrentContent:e,name:t,initialContentSource:c}})},[I,L]=r.default.useState(null),[R,z]=r.default.useState(null),B=y.availableGasTokens.length>0&&(g.isConnectedWithPrivy||g.isConnectedWithVeChain)&&!b?.delegatorUrl,{data:V,isLoading:ee,error:te,refetch:ne}=xc({clauses:j(),tokens:I?[I]:y.availableGasTokens,enabled:B&&!!b?.genericDelegatorUrl}),re=V?.usedToken,H=(ee||!V)&&g.isConnectedWithPrivy&&!b?.delegatorUrl,ie=r.default.useCallback(e=>{L(e),z(e),setTimeout(()=>ne(),100)},[ne]),ae=!!re&&!te;return r.default.useEffect(()=>{te&&I&&L(null)},[te,I]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`confirm-domain`,children:u(s?`Confirm Unset Domain`:`Confirm Name`)}),(0,i.jsx)(q,{onClick:F,isDisabled:A}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:A})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:4,w:`full`,textAlign:`center`,children:[(0,i.jsx)(n.Text,{fontSize:`lg`,color:d,children:u(s?`Are you sure you want to unset your current domain?`:`Are you sure you want to set your domain name to`)}),!s&&(0,i.jsx)(n.Text,{fontSize:`xl`,fontWeight:`bold`,color:d,"data-testid":`preconfirm-domain-val`,children:`${t}`})]}),g.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:V,isLoading:ee,isLoadingTransaction:A,onTokenChange:ie,clauses:j(),userSelectedToken:R})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Dc,{transactionError:O,isSubmitting:A,isTxWaitingConfirmation:k,onConfirm:N,onRetry:P,transactionPendingText:u(s?`Unsetting current domain...`:`Claiming name...`),txReceipt:D,buttonText:u(`Confirm`),isDisabled:A||H,onError:x,gasEstimationError:te,hasEnoughGasBalance:ae,isLoadingGasEstimation:ee,showGasEstimationError:!b?.delegatorUrl&&g.isConnectedWithPrivy,context:`domain`})})]})},Ur=()=>{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))})]})},Wr=({onGoBack:e,showLanguageSelector:t=!0})=>{let{i18n:r,t:a}=(0,l.useTranslation)(),{isolatedView:o}=kr(),s=(0,n.useToken)(`colors`,`vechain-kit-card`),c=(0,n.useToken)(`colors`,`vechain-kit-border`),u=(0,n.useToken)(`colors`,`vechain-kit-border-hover`);return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Help`)}),!o&&(0,i.jsx)(q,{onClick:e}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:6,align:`stretch`,children:[t&&(0,i.jsx)(n.Select,{borderRadius:`md`,size:`sm`,width:`auto`,value:r.language,onChange:e=>{r.changeLanguage(e.target.value)},bg:s,borderColor:c,_hover:{borderColor:u},children:ne.map(e=>(0,i.jsx)(`option`,{value:e,children:H[e]},e))}),(0,i.jsx)(n.Button,{as:n.Link,href:`https://docs.vechainkit.vechain.org/`,isExternal:!0,variant:`vechainKitSecondary`,rightIcon:(0,i.jsx)(n.Icon,{as:g.LuExternalLink}),children:a(`For developers`)}),(0,i.jsx)(Ur,{})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Gr=({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.W(o?.domain??``,18,0):t.U(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})})]})})},Kr=({wallet:e,setCurrentContent:a,size:o=`md`,onClick:s,onClose:c,mt:l,style:u})=>{let[d,f]=(0,r.useState)(!1),{disconnect:p}=X(),m=async()=>{await t.st(e?.domain??e?.address??``)&&(f(!0),setTimeout(()=>{f(!1)},2e3))},h=()=>{p(),c()};return(0,i.jsxs)(n.HStack,{mt:l,w:`full`,...u,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)(Ec,{wallet:e,props:{width:7,height:7}}),(0,i.jsx)(n.Text,{fontSize:o,fontWeight:`500`,children:t.W(e?.domain??``,22,0)||t.U(e?.address??``,6,4)})]}),(0,i.jsx)(n.Icon,{boxSize:5,as:g.LuChevronRight,cursor:`pointer`,opacity:.5})]})}),(0,i.jsx)(n.IconButton,{"aria-label":`Copy address`,icon:(0,i.jsx)(n.Icon,{as:d?g.LuCheck:g.LuCopy}),onClick:m,variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8}}),(0,i.jsx)(n.IconButton,{"aria-label":`Logout`,icon:(0,i.jsx)(n.Icon,{as:g.LuLogOut}),onClick:()=>a({type:`disconnect-confirm`,props:{onDisconnect:h,onBack:()=>a(`main`)}}),variant:`ghost`,size:`sm`,opacity:.5,_hover:{opacity:.8},colorScheme:`red`})]})},qr=({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}=Kt({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.Q[e.symbol]?r.default.cloneElement(t.Q[e.symbol],{width:`${o*.8}px`,height:`${o*.8}px`,rounded:`full`}):t.Z[e.symbol]?(0,i.jsx)(n.Image,{src:t.Z[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]})},Jr=({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}=On(),[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)};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:`flex-start`,alignItems:`center`,spacing:2,role:`group`,children:[(0,i.jsx)(n.Heading,{size:`xs`,fontWeight:`500`,color:m,children:o(`Assets`)}),(0,i.jsx)(n.Box,{display:`flex`,alignItems:`center`,justifyContent:`center`,w:`32px`,h:`32px`,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.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)(qr,{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})})})]})})]})},Yr=[{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`)}}],Xr=({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})},Zr=({mt:e,setCurrentContent:t})=>{let{account:r,smartAccount:a,connectedWallet:o,connection:s}=X(),{hasAnyBalance:c}=qt({address:r?.address??``}),{data:l}=js(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:Yr.map(e=>(0,i.jsx)(Xr,{icon:e.icon,label:e.label,onClick:()=>e.onClick(t),isDisabled:e.isDisabled?.(c),showRedDot:u&&e.label===`Settings`},e.label))})},Qr=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.lt(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t._t(i,`true`),n(!1)}}},$r=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isVisible:r,closeAnnouncement:a}=Qr(),o=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),s=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`);return r?(0,i.jsx)(n.Card,{w:`full`,variant:`featureAnnouncement`,overflow:`hidden`,onClick:()=>{e({type:`choose-name`,props:{setCurrentContent:e,onBack:()=>e(`main`),initialContentSource:`main`}}),a()},cursor:`pointer`,_hover:{opacity:.8},children:(0,i.jsx)(n.CardBody,{p:4,children:(0,i.jsxs)(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:o,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:s,children:t(`Say goodbye to 0x addresses, claim your .veworld.vet subdomain now for free!`)})]}),(0,i.jsx)(n.IconButton,{size:`sm`,variant:`ghost`,colorScheme:`gray`,icon:(0,i.jsx)(g.LuCircleX,{}),onClick:e=>{e.stopPropagation(),a()},"aria-label":t(`Close announcement`)})]})})}):null},ei=()=>{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.`)})]})})})},ti=()=>{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.`)})]})})})},ni=()=>{let{t:e}=(0,l.useTranslation)(),{getConnectionCache:t}=Fo(),r=t();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:e(`Security preferences`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,mt:1,opacity:.7,children:e(`For security reasons, you can manage your embedded wallet settings only on the {{appName}} platform.`,{appName:r?.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:e(`Login methods`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:e(`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:e(`Security settings`)}),(0,i.jsx)(n.Text,{fontSize:`xs`,opacity:.7,lineHeight:`shorter`,children:e(`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(r?.ecosystemApp.website??`https://governance.vebetterdao.org/`,`_blank`)},children:[e(`Manage on {{appName}}`,{appName:r?.ecosystemApp.name??`origin app`}),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},ri=({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}=Wn({compressImage:!0}),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(null),C=!!c?.domain,[w,T]=(0,r.useState)(null),[D,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(``),{register:j,watch:M,formState:{errors:N,isValid:P}}=(0,E.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.E(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!==D&&(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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:o(`Customization`)}),(0,i.jsx)(q,{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)(Ec,{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)(ti,{}),(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`)})})]})},ii=({setCurrentContent:e,changes:a,onDoneRedirectContent:o})=>{let{t:s}=(0,l.useTranslation)(),{darkMode:c,network:u,feeDelegation:d}=$(),{account:f,connectedWallet:m,connection:h}=X(),{preferences:g}=bc(),{data:_}=js(f?.address??``,m?.address??``,3),{open:v}=Eo(),{handleSubmit:y}=(0,E.useForm)({defaultValues:{...a,avatarIpfsHash:a.avatarIpfsHash??void 0}}),b=f?.domain??``,{data:x}=St(b),S=(0,p.useQueryClient)(),{sendTransaction:C,txReceipt:w,error:T,isWaitingForWalletConfirmation:D,isTransactionPending:O,clauses:k}=bt({resolverAddress:x,signerAccountAddress:f?.address??``,onSuccess:async()=>{e({type:`successful-operation`,props:{setCurrentContent:e,txId:w?.meta.txID,title:s(`Profile Updated`),description:s(`Your changes have been saved successfully.`),onDone:()=>{e(o)}}});try{await U()}catch(e){console.error(`Error refreshing data:`,e)}},onError:e=>{console.error(`Error updating text record:`,e)}}),A=(0,r.useMemo)(()=>{let e=f?.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,f?.domain]),j=(0,r.useMemo)(()=>{try{return!x||A.length===0||!k?[]:k(A)}catch(e){return console.error(`Error building clauses:`,e),[]}},[A,k,x]),[M,N]=r.default.useState(null),[P,F]=r.default.useState(null),I=g.availableGasTokens.length>0&&(h.isConnectedWithPrivy||h.isConnectedWithVeChain)&&!d?.delegatorUrl,{data:L,isLoading:R,error:z,refetch:B}=xc({clauses:j,tokens:M?[M]:g.availableGasTokens,enabled:I&&!!d?.genericDelegatorUrl}),V=L?.usedToken,ee=(R||!L)&&h.isConnectedWithPrivy&&!d?.delegatorUrl,te=r.default.useCallback(e=>{N(e),F(e),setTimeout(()=>B(),100)},[B]),ne=!!V&&!z;r.default.useEffect(()=>{z&&M&&N(null)},[z,M]);let re=async()=>{if(_){v();return}try{A.length>0&&await C(A)}catch(e){console.error(`Error saving changes:`,e)}},H=(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,ie=()=>{y(re)()},ae=()=>{e({type:`account-customization`,props:{setCurrentContent:e}})},U=async()=>{a.avatarIpfsHash&&(S.setQueryData(ft(b,u.type),t.h(`ipfs://`+a.avatarIpfsHash,u.type)),S.setQueryData(Et(f?.address??``),t.h(`ipfs://`+a.avatarIpfsHash,u.type))),await S.invalidateQueries({queryKey:gt(b,u.type)}),await S.refetchQueries({queryKey:gt(b,u.type)})};return(0,i.jsxs)(n.Box,{as:`form`,onSubmit:y(re),children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Confirm Changes`)}),(0,i.jsx)(q,{isDisabled:O,onClick:ae}),(0,i.jsx)(n.ModalCloseButton,{isDisabled:O})]}),(0,i.jsxs)(n.ModalBody,{children:[(0,i.jsxs)(n.VStack,{spacing:4,align:`stretch`,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&&H(s(`Display Name`),a.displayName),a.description&&H(s(`Description`),a.description),a.twitter&&H(s(`Twitter`),a.twitter),a.website&&H(s(`Website`),a.website),a.email&&H(s(`Email`),a.email)]}),h.isConnectedWithPrivy&&(0,i.jsx)(Ac,{estimation:L,isLoading:R,isLoadingTransaction:O,onTokenChange:te,clauses:j,userSelectedToken:P})]}),(0,i.jsx)(n.ModalFooter,{gap:4,w:`full`,children:(0,i.jsx)(Dc,{transactionError:T,isSubmitting:O,isTxWaitingConfirmation:D,onConfirm:y(re),onRetry:ie,transactionPendingText:s(`Saving changes...`),txReceipt:w,buttonText:s(`Confirm`),isDisabled:O||ee,gasEstimationError:z,hasEnoughGasBalance:ne,isLoadingGasEstimation:R,showGasEstimationError:!d?.delegatorUrl&&h.isConnectedWithPrivy,context:`customization`})})]})},ai=({onEditClick:e,address:r,showHeader:a=!0,onLogout:o,showLinks:s=!0,showDescription:c=!0,showDisplayName:u=!0,showEdit:d=!0})=>{let{t:f}=(0,l.useTranslation)(),{account:p,disconnect:m}=X(),{network:h}=$(),{openAccountModal:_,closeAccountModal:v}=Q(),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),x=Dn(r,h.type),S=t.H(r),C=r===p?.address,w=x?.records?.url||x?.records?.[`com.x`]||x?.records?.email,T=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:4,w:`full`,children:[(0,i.jsx)(n.Box,{p:0,backgroundSize:`100% !important`,backgroundPosition:`center`,position:`relative`,background:a?`no-repeat url('${S}')`:`none`,w:`100%`,borderRadius:`14px 14px 0 0`}),(0,i.jsx)(Ec,{wallet:{address:r,domain:x?.domain,image:x?.image,isLoadingMetadata:x?.isLoading,metadata:x?.records},props:{width:`120px`,height:`120px`}}),(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[u&&x?.records?.display&&(0,i.jsx)(n.Text,{fontSize:`xl`,color:y,fontWeight:`bold`,w:`full`,textAlign:`center`,mt:2,"data-testid":`display-name-val`,children:x?.records?.display}),c&&x?.records?.description&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:b,w:`full`,textAlign:`center`,"data-testid":`description-val`,children:x?.records?.description}),s&&w&&(0,i.jsxs)(n.HStack,{w:`full`,justify:`center`,spacing:5,mt:4,children:[x?.records?.email&&(0,i.jsx)(n.Link,{href:`mailto:${x?.records?.email}`,target:`_blank`,"data-testid":`mail-link`,children:(0,i.jsx)(n.Icon,{as:g.LuMail,color:y})}),x?.records?.url&&(0,i.jsx)(n.Link,{href:T(x.records.url)??void 0,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`website-link`,children:(0,i.jsx)(n.Icon,{as:g.LuGlobe,color:y})}),x?.records?.[`com.x`]&&(0,i.jsx)(n.Link,{href:`https://x.com/${encodeURIComponent(String(x.records[`com.x`]))}`,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`twitter-link`,children:(0,i.jsx)(n.Icon,{as:k.FaXTwitter,color:y})})]}),(0,i.jsx)(De,{wallet:{address:r,domain:x?.domain,image:x?.image,isLoadingMetadata:x?.isLoading,metadata:x?.records},style:{mt:4}})]}),C&&d&&(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:(0,i.jsx)(n.Icon,{as:g.LuPencil}),onClick:e??(()=>{_({type:`account-customization`,props:{setCurrentContent:()=>v()}})}),"data-testid":`customize-button`,children:f(`Customize`)}),(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:o??(()=>{_({type:`disconnect-confirm`,props:{onDisconnect:()=>{m(),v()},onBack:()=>v()}})}),"data-testid":`logout-button`,children:f(`Logout`)})]})]})},oi=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{account:o,disconnect:s}=X();return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{"data-testid":`modal-title`,children:r(`Profile`)}),!a&&(0,i.jsx)(q,{onClick:()=>e(`main`)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:2,children:[!o?.domain&&(0,i.jsx)($r,{setCurrentContent:e}),(0,i.jsx)(ai,{onEditClick:()=>{e({type:`account-customization`,props:{setCurrentContent:e,initialContentSource:`profile`}})},address:o?.address??``,showHeader:!1,onLogout:()=>{e?.({type:`disconnect-confirm`,props:{onDisconnect:()=>{s(),t?.()},onBack:()=>e?.(`profile`)}})}})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},si=({setCurrentContent:e,handleClose:t,initialContent:r=`settings`})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=js(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Is({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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Account upgrade required`)}),(0,i.jsx)(q,{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)(Dc,{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`)})]})})]})},ci=({setCurrentContent:e})=>{let{account:t}=X(),{sortedTokens:a}=Kt({address:t?.address}),{allowCustomTokens:o,darkMode:s}=$(),{currentCurrency:c}=Gt(),u=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`),{t:d}=(0,l.useTranslation)(),{isolatedView:f}=kr(),[p,m]=(0,r.useState)(``),h=t=>{e({type:`send-token`,props:{setCurrentContent:e,preselectedToken:t,onBack:()=>e(`assets`)}})},_=a.filter(({symbol:e})=>e.toLowerCase().includes(p.toLowerCase()));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:d(`Assets`)}),!f&&(0,i.jsx)(q,{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:s?`#00000038`:`gray.50`,borderRadius:`xl`,height:`56px`,pl:12,value:p,onChange:e=>m(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:u})})]}),(0,i.jsx)(n.VStack,{spacing:2,align:`stretch`,mt:2,children:_.map(e=>{let t=Number(e.balance)>0;return(0,i.jsx)(Le,{symbol:e.symbol,amount:Number(e.balance),currencyValue:e.valueInCurrency,currentCurrency:c,onClick:()=>h(e),isDisabled:!t},e.address)})})]}),(0,i.jsx)(n.ModalFooter,{children:o&&(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,leftIcon:(0,i.jsx)(n.Icon,{as:g.LuPencil,boxSize:4}),onClick:()=>e(`add-custom-token`),children:d(`Manage Custom Tokens`)})})]})]})},li=({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}=tn(),{register:h,setError:_,setValue:v,formState:{errors:y,isValid:b},handleSubmit:x}=(0,E.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)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Manage Custom Tokens`)}),(0,i.jsx)(q,{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.Z[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.U(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`)})})]})},ui=({setCurrentContent:t})=>{let{t:r}=(0,l.useTranslation)(),{darkMode:a}=$(),{isolatedView:o}=kr();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Bridge`)}),!o&&(0,i.jsx)(q,{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(`https://swap.vechain.energy/`,`_blank`)},children:[r(`Launch vechain.energy`),(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:2})]})})]})},di=({setCurrentContent:e})=>{let{t:a}=(0,l.useTranslation)(),{currentCurrency:o,changeCurrency:s,allCurrencies:c}=Gt(),u=(0,n.useColorModeValue)(`rgba(0, 0, 0, 0.1)`,`rgba(255, 255, 255, 0.05)`);(0,r.useEffect)(()=>{t._t(`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.S[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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select currency`)}),(0,i.jsx)(q,{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})]})},fi=({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:H[e]}),t&&(0,i.jsx)(n.Icon,{as:g.LuCheck,boxSize:5,color:`blue.500`})]},e)};return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Select language`)}),(0,i.jsx)(q,{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:ne.map(e=>s(e))})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},pi=({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.X[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`})]})})},mi=({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)(pi,{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))})},hi=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{preferences:a,reorderTokenPriority:o,toggleTokenExclusion:s}=bc(),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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Gas Token Preferences`)}),(0,i.jsx)(q,{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)(mi,{tokens:a.tokenPriority,excludedTokens:a.excludedTokens,onReorder:d,onToggleExclusion:s})]})]})})]})},gi=({setCurrentContent:e,onLogoutSuccess:t})=>{let{t:r}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{exportWallet:o,linkPasskey:s}=(0,u.usePrivy)(),{showMfaEnrollmentModal:c}=(0,u.useMfaEnrollment)(),{feeDelegation:d}=$(),{connection:f,disconnect:p,smartAccount:m,connectedWallet:h}=X(),{data:_}=js(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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:r(`Settings`)}),!a&&(0,i.jsx)(q,{onClick:()=>e(`main`)}),(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)(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(`Frequently asked questions`),onClick:()=>e({type:`faq`,props:{onGoBack:()=>e(`settings`),showLanguageSelector:!1}}),leftIcon:g.LuCircleHelp,rightIcon:g.LuChevronRight}),(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)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[(0,i.jsx)(n.Divider,{}),(0,i.jsx)(Z,{title:r(`Logout`),onClick:()=>e({type:`disconnect-confirm`,props:{onDisconnect:b,onBack:()=>e(`settings`)}}),leftIcon:g.LuLogOut})]})})]})},_i=({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})]})]})},vi=(e,t=`en-US`)=>new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}).format(new Date(e)),yi=({document:e})=>{let{t:r}=(0,l.useTranslation)(),a=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),o=e.documentSource===t._.VECHAIN_KIT&&e.documentType===t.v.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:vi(e.timestamp)})})]})},bi=({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:vi(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)(yi,{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},xi=()=>{let{account:e}=X(),{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),{agreements:s,documents:c}=Uc(),u=(0,r.useMemo)(()=>{let n=s?.filter(n=>t.O(n.walletAddress,e?.address));return[{id:`vechain-kit-terms`,...t.nt,documentType:t.v.TERMS,documentSource:t._.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`;return f?(0,i.jsx)(n.VStack,{spacing:4,align:`stretch`,children:(0,i.jsxs)(n.Accordion,{allowMultiple:!0,children:[(0,i.jsx)(bi,{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.v.TERMS],bg:p,hoverBg:m,currentPolicy:d[t.v.TERMS]}),(0,i.jsx)(bi,{title:a(`Privacy Policy`),description:a(`Privacy policy outlining the data collection and processing practices.`),documents:u[t.v.PRIVACY],bg:p,hoverBg:m,currentPolicy:d[t.v.PRIVACY]}),(0,i.jsx)(bi,{title:a(`Cookie Policy`),description:a(`Cookie policy outlining the use of cookies and tracking technologies.`),documents:u[t.v.COOKIES],bg:p,hoverBg:m,currentPolicy:d[t.v.COOKIES]})]})}):(0,i.jsx)(_i,{title:a(`No policies accepted`),description:a(`When you have accepted a policy, it will appear here`),icon:g.LuGavel})},Si=({onGoBack:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Terms and Policies`)}),(0,i.jsx)(q,{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)(xi,{})})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},Ci=({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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:s(`Logout`)}),(0,i.jsx)(q,{onClick:t}),a?(0,i.jsx)(n.ModalCloseButton,{onClick:r}):null]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(n.VStack,{spacing:6,align:`stretch`,children:(0,i.jsx)(n.Text,{fontSize:`md`,textAlign:`center`,color:c,children:u})})}),(0,i.jsx)(n.ModalFooter,{w:`full`,children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{height:`60px`,colorScheme:`red`,w:`full`,onClick:e,"data-testid":`disconnect-button`,children:s(`Confirm`)}),(0,i.jsx)(n.Button,{variant:`vechainKitSecondary`,onClick:t,"data-testid":`cancel-logout-button`,children:s(`Cancel`)})]})})]})},wi=ke[`@vechain/dapp-kit-react`]||Ae[`@vechain/dapp-kit-react`]||`unknown`,Ti=ke[`@privy-io/react-auth`]||`unknown`,Ei=({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}=Be(p||[]),{onCopy:_,hasCopied:v}=(0,n.useClipboard)(``),{data:y,isLoading:b}=Ve(),{data:x,isLoading:S}=hs(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.vt(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.U(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:Oe,href:`https://github.com/vechain/vechain-kit/releases/tag/${Oe}`}),(0,i.jsx)(O,{label:`DAppKit`,value:wi}),(0,i.jsx)(O,{label:`Privy`,value:Ti})]}):null},Di=()=>{let{connection:t}=X(),{t:r}=(0,l.useTranslation)(),{privy:a,darkMode:o}=$(),{getConnectionCache:s}=Fo(),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.S,{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},Oi=({onGoBack:e})=>{let{t}=(0,l.useTranslation)(),{getConnectionCache:r}=Fo(),a=r()??void 0;return(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t(`Connection Details`)}),(0,i.jsx)(q,{onClick:()=>{e()}}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsxs)(n.ModalBody,{w:`full`,children:[(0,i.jsx)(Ei,{connectionCache:a}),(0,i.jsx)(Di,{})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]})},ki=({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`)})]})]})},Ai=({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:E,linkSpotify:D,linkApple:O,linkInstagram:M,linkTiktok:N,linkGithub:P,linkLinkedIn:F,linkTelegram:I,linkFarcaster:L,linkPasskey:R,linkDiscord:z,unlinkEmail:B,unlinkGoogle:V,unlinkApple:ee,unlinkSpotify:te,unlinkInstagram:ne,unlinkTiktok:re,unlinkGithub:H,unlinkLinkedIn:ie,unlinkTelegram:ae,unlinkFarcaster:U,unlinkPhone:oe,unlinkPasskey:se,unlinkDiscord:W,linkWallet:ce}=(0,u.usePrivy)(),le=(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]),ue=e=>{switch(e){case`google_oauth`:return T.FcGoogle;case`email`:return g.LuMail;case`passkey`:return g.LuFingerprint;case`wallet`:return g.LuWallet;case`twitter_oauth`:return k.FaXTwitter;case`phone`:return g.LuPhone;case`spotify_oauth`:return j.FaSpotify;case`apple_oauth`:return j.FaApple;case`instagram_oauth`:return j.FaInstagram;case`tiktok_oauth`:return j.FaTiktok;case`github_oauth`:return g.LuGithub;case`linkedin_oauth`:return j.FaLinkedin;case`telegram`:return j.FaTelegram;case`farcaster`:return A.SiFarcaster;case`discord_oauth`:return j.FaDiscord;default:return}},G=()=>{let e=x?.linkedAccounts?.filter(e=>e.type!==`wallet`||e.type===`wallet`&&e.connectorType!==`embedded`);return e&&e?.length>1},de=async e=>{if(G()){v(!0);try{switch(e.type){case`google_oauth`:await V(e.subject);break;case`email`:await B(e.address);break;case`passkey`:await se(e.subject);break;case`phone`:await oe(e.number);break;case`spotify_oauth`:await te(e.subject);break;case`apple_oauth`:await ee(e.subject);break;case`instagram_oauth`:await ne(e.subject);break;case`tiktok_oauth`:await re(e.subject);break;case`github_oauth`:await H(e.subject);break;case`linkedin_oauth`:await ie(e.subject);break;case`telegram`:await ae(e.subject);break;case`farcaster`:await U(e.subject);break;case`discord_oauth`:await W(e.subject);break;default:break}}catch(e){console.error(e)}finally{v(!1),d(null)}}},fe=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.U(e.address)} - ${e.walletClientType}`;default:return``}},pe=x?.linkedAccounts?.map(e=>e.type)||[],K=o?.loginMethods||[],me=!pe.includes(`google_oauth`)&&K.includes(`google`),he=!pe.includes(`email`)&&K.includes(`email`),ge=!pe.includes(`twitter_oauth`)&&K.includes(`twitter`),_e=!pe.includes(`phone`)&&K.includes(`sms`),ve=!pe.includes(`spotify_oauth`)&&K.includes(`spotify`),ye=!pe.includes(`apple_oauth`)&&K.includes(`apple`),be=!pe.includes(`instagram_oauth`)&&K.includes(`instagram`),xe=!pe.includes(`tiktok_oauth`)&&K.includes(`tiktok`),Se=!pe.includes(`github_oauth`)&&K.includes(`github`),Ce=!pe.includes(`linkedin_oauth`)&&K.includes(`linkedin`),we=!pe.includes(`telegram`)&&K.includes(`telegram`),Te=!pe.includes(`farcaster`)&&K.includes(`farcaster`),Ee=!pe.includes(`discord_oauth`)&&K.includes(`discord`);return f?(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Select Additional Login Method`)}),(0,i.jsx)(q,{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}),me&&(0,i.jsx)(Z,{title:a(`Link Google Account`),description:a(`Connect your Google account for easier access`),onClick:()=>C(),leftIcon:T.FcGoogle}),he&&(0,i.jsx)(Z,{title:a(`Link Email Account`),description:a(`Connect your email for easier access`),onClick:()=>S(),leftIcon:g.LuMail,stacked:!0}),ge&&(0,i.jsx)(Z,{title:a(`Link Twitter Account`),description:a(`Connect your Twitter account for easier access`),onClick:()=>w(),leftIcon:k.FaXTwitter}),_e&&(0,i.jsx)(Z,{title:a(`Link Phone Number`),description:a(`Connect your phone number for easier access`),onClick:()=>E(),leftIcon:g.LuPhone}),ve&&(0,i.jsx)(Z,{title:a(`Link Spotify Account`),description:a(`Connect your Spotify account for easier access`),onClick:()=>D(),leftIcon:j.FaSpotify}),ye&&(0,i.jsx)(Z,{title:a(`Link Apple Account`),description:a(`Connect your Apple account for easier access`),onClick:()=>O(),leftIcon:j.FaApple}),be&&(0,i.jsx)(Z,{title:a(`Link Instagram Account`),description:a(`Connect your Instagram account for easier access`),onClick:()=>M(),leftIcon:j.FaInstagram}),xe&&(0,i.jsx)(Z,{title:a(`Link Tiktok Account`),description:a(`Connect your Tiktok account for easier access`),onClick:()=>N(),leftIcon:j.FaTiktok}),Se&&(0,i.jsx)(Z,{title:a(`Link Github Account`),description:a(`Connect your Github account for easier access`),onClick:()=>P(),leftIcon:g.LuGithub}),Ce&&(0,i.jsx)(Z,{title:a(`Link LinkedIn Account`),description:a(`Connect your LinkedIn account for easier access`),onClick:()=>F(),leftIcon:j.FaLinkedin}),we&&(0,i.jsx)(Z,{title:a(`Link Telegram Account`),description:a(`Connect your Telegram account for easier access`),onClick:()=>I(),leftIcon:j.FaTelegram}),Te&&(0,i.jsx)(Z,{title:a(`Link Farcaster Account`),description:a(`Connect your Farcaster account for easier access`),onClick:()=>L(),leftIcon:A.SiFarcaster}),Ee&&(0,i.jsx)(Z,{title:a(`Link Discord Account`),description:a(`Connect your Discord account for easier access`),onClick:()=>z(),leftIcon:j.FaDiscord}),le&&(0,i.jsx)(Z,{title:a(`Link External Wallet`),description:a(`Connect an external wallet for easier access`),onClick:()=>ce(),leftIcon:g.LuWallet}),!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&!Ee&&(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)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Remove Login Method`)}),(0,i.jsx)(q,{onClick:()=>d(null)}),(0,i.jsx)(n.ModalCloseButton,{})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsx)(ki,{accountType:c.type,accountDescription:fe(c),isLoading:_,onConfirm:()=>de(c),onCancel:()=>d(null)})}),(0,i.jsx)(n.ModalFooter,{pt:0})]}):(0,i.jsxs)(Tc,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Login methods`)}),(0,i.jsx)(q,{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:ue(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:fe(e)})]})]}),(0,i.jsx)(n.Button,{size:`sm`,variant:`ghost`,colorScheme:`red`,isDisabled:!G(),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:!me&&!he&&!ge&&!_e&&!ve&&!ye&&!be&&!xe&&!Se&&!Ce&&!we&&!Te&&!Ee,children:a(`Add Login Method`)})})]})},ji=[{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}],Mi=()=>{let{t:e}=(0,l.useTranslation)(),{account:t,connection:n,smartAccount:i}=X(),{addNotification:a,getNotifications:o}=Ni(),{data:s}=Ps(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])},Ni=()=>{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.ft())return;let r=n(e.address);t.lt(r.initialized)||(t._t(r.notifications,JSON.stringify(ji)),t._t(r.initialized,`true`))},[e?.address,n]);(0,r.useEffect)(()=>{i()},[i]);let a=(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return[];let r=t.lt(n(e.address).notifications);return r?JSON.parse(r):[]},[e?.address,n]),o=(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return[];let r=t.lt(n(e.address).archived);return r?JSON.parse(r):[]},[e?.address,n]),s=(0,r.useCallback)(r=>{if(!e?.address||!t.ft())return;let i=n(e.address),o=a(),s=t.lt(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._t(i.notifications,JSON.stringify([l,...o]))},[e?.address,a,n]),c=(0,r.useCallback)(r=>{if(!e?.address||!t.ft())return;let i=n(e.address),o=a().filter(e=>e.id!==r);t._t(i.notifications,JSON.stringify(o))},[e?.address,a,n]);return{getNotifications:a,getArchivedNotifications:o,addNotification:s,clearAllNotifications:(0,r.useCallback)(()=>{if(!e?.address||!t.ft())return;let r=n(e.address),i=a();t._t(r.archived,JSON.stringify([...o(),...i])),t._t(r.notifications,JSON.stringify([]))},[e?.address,a,o,n]),markAsRead:(0,r.useCallback)(r=>{if(!e?.address||!t.ft())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._t(i.notifications,JSON.stringify(u)),t._t(i.archived,JSON.stringify(e))}},[e?.address,a,o,n]),deleteNotification:c}},Pi=({showArchived:e})=>{let{t}=(0,l.useTranslation)();return(0,i.jsx)(_i,{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})},Fi=({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)},Ii=({setCurrentContent:e})=>{let{t}=(0,l.useTranslation)(),{isolatedView:a}=kr(),{getNotifications:o,getArchivedNotifications:s,clearAllNotifications:c,markAsRead:u}=Ni(),[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)(Tc,{children:[(0,i.jsxs)(J,{children:[!a&&(0,i.jsx)(q,{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)(Pi,{showArchived:d}):(0,i.jsx)(n.VStack,{spacing:3,children:S.map(e=>(0,i.jsx)(Fi,{notification:e,isArchiveView:d,onMarkAsRead:y},e.id))})]})}),(0,i.jsx)(n.ModalFooter,{pt:0})]})]})},Li=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`}},Ri=({category:e,...t})=>{let{t:r}=(0,l.useTranslation)(),a=e.toLowerCase();return(0,i.jsx)(n.Tag,{size:`sm`,colorScheme:Li(a),borderRadius:`full`,px:2,...t,children:r(a)})},zi=({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)(Ri,{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.ot,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})]})})]}),Bi=({xApp:e,setCurrentContent:t,selectedCategory:r})=>{let{data:a,isLoading:o}=jn(e.id),{data:s,isLoading:c}=Rn(a?.logo);return(0,i.jsx)(n.Skeleton,{isLoaded:!o&&!c,borderRadius:`md`,height:`100%`,children:(0,i.jsx)(zi,{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}})}})})},Vi=({name:e,image:t,url:n,description:r,category:a,logoComponent:o,selectedCategory:s,setCurrentContent:c})=>(0,i.jsx)(zi,{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}}),Hi=({})=>{let{t:e}=(0,l.useTranslation)(),{shortcuts:r}=fc();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.ot,alt:e.name,objectFit:`contain`,rounded:`full`})})})},e.url))})]})},Ui=({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)(Ri,{category:r,size:`md`,variant:e===r?`solid`:`outline`,cursor:`pointer`,onClick:()=>t(r)})},r))]})]})},Wi=[{name:`VeBetterDAO`,description:`Engage, earn and prosper by doing sustainable actions.`,external_url:`https://governance.vebetterdao.org/`,logo:`https://i.ibb.co/cgJBj83/vbd.png`,banner:`https://i.ibb.co/cgJBj83/vbd.png`,screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:`https://i.ibb.co/cgJBj83/vbd.png`},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:`https://vet.domains`,logo:`https://vet.domains/assets/walletconnect.png`,banner:`https://vet.domains/assets/walletconnect.png`,screenshots:[],social_urls:[],app_urls:[],tweets:[],ve_world:{banner:`https://vet.domains/assets/walletconnect.png`},categories:[]}],Gi=({setCurrentContent:e,selectedCategory:t})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o,network:s}=$(),{isolatedView:c}=kr(),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}=Zt(),{data:_}=xn(h?(parseInt(h)-1).toString():`1`),{data:v,isLoading:y,error:b}=Wo(),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=Wi.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}=fc();return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`Ecosystem`)}),!c&&(0,i.jsx)(q,{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)(Hi,{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)(Ui,{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)(Vi,{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)(Bi,{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)(Vi,{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})]})},Ki=({name:e,image:t,url:r,description:a})=>{let{t:o}=(0,l.useTranslation)(),{isShortcut:s,addShortcut:c,removeShortcut:u}=fc(),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`)})},qi=({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)(n.Box,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:t}),(0,i.jsx)(q,{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)(Ri,{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)(Ki,{name:t,image:r,url:a,description:o})]})})]})},Ji=`https://twitter.com/intent/tweet?text=`,Yi=`https://wa.me/?text=`,Xi=`https://telegram.me/share/url?url=`,Zi=({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}),Qi=({descriptionEncoded:e})=>{let{darkMode:t}=$();return(0,i.jsxs)(n.HStack,{gap:2,children:[(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://twitter.com/intent/tweet?text=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:t?`blackAlpha.700`:`lightgrey`,p:2,borderRadius:`full`,children:(0,i.jsx)(k.FaXTwitter,{size:22})})})}),(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://telegram.me/share/url?url=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#30abec`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaTelegramPlane,{color:`white`,size:22})})})}),(0,i.jsx)(Zi,{children:(0,i.jsx)(n.Link,{href:`https://wa.me/?text=${e}`,isExternal:!0,children:(0,i.jsx)(n.Box,{bg:`#01cb37`,p:2,borderRadius:`full`,children:(0,i.jsx)(j.FaWhatsapp,{size:22,color:`white`})})})})]})},$i=({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.vt(f.type).explorerUrl}/${s?.meta.txID}`;return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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:`vechainKitSecondary`,width:`full`,children:d(`Close`)}),a?.showExplorerButton&&s?.meta.txID&&(0,i.jsx)(n.Link,{href:`${t.vt(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:_})]})})]})})]})},ea=({isOpen:e,onClose:t,status:n,uiConfig:r,txReceipt:a,txError:o,onTryAgain:s})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,closeOnOverlayClick:n!==`pending`&&r?.isClosable,children:(0,i.jsx)($i,{status:n,onTryAgain:s,uiConfig:r,txReceipt:a,onClose:t,txError:o})}),ta=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.vt(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)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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})]})})]})})]})},na=({txId:e,title:r,description:a,onDone:o})=>{let{t:s}=(0,l.useTranslation)(),{network:c,darkMode:u}=$(),d=t.vt(c.type).explorerUrl;return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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})]})})]})})]})},ra={enter:e=>({opacity:0,x:e===`forward`?20:-20}),center:{opacity:1,x:0},exit:e=>({opacity:0,x:e===`forward`?-20:20})},ia={duration:.17,ease:[.4,0,.2,1]},aa=e=>{if(typeof e==`string`)return e;let t=e.type,n=JSON.stringify(e.props),r=0;for(let e=0;e<n.length;e++){let t=n.charCodeAt(e);r=(r<<5)-r+t,r&=r}return`${t}-${Math.abs(r)}`},oa=({isOpen:e,onClose:t,initialContent:n=`main`})=>{Mi();let{account:a}=X(),o=(0,r.useRef)(null),s=(0,r.useRef)(`forward`),c=(0,r.useRef)(!1),{accountModalContent:l,setAccountModalContent:u}=Q(),d=!c.current&&e?n:l;(0,r.useEffect)(()=>{e&&!c.current&&(o.current=null,s.current=`forward`,u(n)),c.current=e},[e,n,u]);let f=(()=>{if(o.current===null||o.current===d)return s.current;let e=aa(o.current),t=aa(d);return t===`main`||t===`settings`&&e!==`main`||e.includes(`summary`)||e.includes(`confirm`)||e.includes(`operation`)?`backward`:`forward`})();(0,r.useEffect)(()=>{s.current=f,o.current=d},[d,f]);let p=(()=>{if(typeof d==`object`)switch(d.type){case`send-token`:return(0,i.jsx)(Ar,{...d.props});case`send-token-summary`:return(0,i.jsx)(jr,{...d.props});case`swap-token`:return(0,i.jsx)(Ir,{...d.props});case`choose-name`:return(0,i.jsx)(Lr,{...d.props});case`choose-name-search`:return(0,i.jsx)(Vr,{...d.props});case`choose-name-summary`:return(0,i.jsx)(Hr,{...d.props});case`app-overview`:return(0,i.jsx)(qi,{...d.props,setCurrentContent:u});case`disconnect-confirm`:return(0,i.jsx)(Ci,{...d.props});case`account-customization`:return(0,i.jsx)(ri,{...d.props});case`account-customization-summary`:return(0,i.jsx)(ii,{...d.props});case`successful-operation`:return(0,i.jsx)(ta,{...d.props});case`failed-operation`:return(0,i.jsx)(na,{...d.props});case`upgrade-smart-account`:return(0,i.jsx)(si,{...d.props});case`faq`:return(0,i.jsx)(Wr,{...d.props});case`terms-and-privacy`:return(0,i.jsx)(Si,{...d.props});case`ecosystem-with-category`:return(0,i.jsx)(Gi,{setCurrentContent:u,selectedCategory:d.props.selectedCategory})}switch(d){case`main`:return(0,i.jsx)(Dr,{setCurrentContent:u,onClose:t,wallet:a});case`settings`:return(0,i.jsx)(gi,{setCurrentContent:u,onLogoutSuccess:()=>{t()}});case`profile`:return(0,i.jsx)(oi,{setCurrentContent:u,onLogoutSuccess:()=>{t()}});case`assets`:return(0,i.jsx)(ci,{setCurrentContent:u});case`bridge`:return(0,i.jsx)(ui,{setCurrentContent:u});case`notifications`:return(0,i.jsx)(Ii,{setCurrentContent:u});case`receive-token`:return(0,i.jsx)(Mr,{setCurrentContent:u});case`swap-token`:return(0,i.jsx)(Ir,{setCurrentContent:u});case`connection-details`:return(0,i.jsx)(Oi,{onGoBack:()=>u(`settings`)});case`privy-linked-accounts`:return(0,i.jsx)(Ai,{onBack:()=>u(`settings`)});case`ecosystem`:return(0,i.jsx)(Gi,{setCurrentContent:u});case`add-custom-token`:return(0,i.jsx)(li,{setCurrentContent:u});case`change-currency`:return(0,i.jsx)(di,{setCurrentContent:u});case`change-language`:return(0,i.jsx)(fi,{setCurrentContent:u});case`gas-token-settings`:return(0,i.jsx)(hi,{setCurrentContent:u});default:return null}})(),m=aa(d);return(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,children:(0,i.jsx)(h.AnimatePresence,{mode:`wait`,initial:!1,children:e&&p&&(0,i.jsx)(h.motion.div,{custom:s.current,variants:ra,initial:`enter`,animate:`center`,exit:`exit`,transition:ia,style:{width:`100%`},children:p},m)},e?`open`:`closed`)})},sa=({isOpen:e,onClose:t})=>{let[n,a]=(0,r.useState)(`main`);return(0,r.useEffect)(()=>{e&&a(`main`)},[e]),(0,i.jsx)(Ne,{isOpen:e,onClose:t,allowExternalFocus:!0,blockScrollOnMount:!0,children:(()=>{switch(n){case`main`:return(0,i.jsx)(Tr,{setCurrentContent:a,onClose:t});case`faq`:return(0,i.jsx)(Wr,{onGoBack:()=>a(`main`)})}})()})},ca=({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`})}),la=({isLoading:e,buttonStyle:t})=>{let{t:r}=(0,l.useTranslation)(),{loginMethods:a,darkMode:o,privyEcosystemAppIDS:s}=$(),c=a?.some(({method:e})=>e===`ecosystem`),{data:u,isLoading:d}=Be(s);return(0,i.jsx)(n.Popover,{placement:`bottom-start`,size:`xl`,closeOnBlur:!1,variant:`vechainKitBase`,children:({isOpen:a})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.PopoverTrigger,{children:(0,i.jsxs)(n.Button,{isLoading:e,...t,isActive:a,children:[r(`Login`),(0,i.jsx)(n.Icon,{ml:2,as:g.LuChevronDown,transform:a?`rotate(180deg)`:`rotate(0deg)`,transition:`transform 0.2s`})]})}),(0,i.jsxs)(n.PopoverContent,{children:[(0,i.jsx)(n.PopoverBody,{children:(0,i.jsx)(Cr,{})}),(0,i.jsx)(n.PopoverFooter,{borderTop:`none`,pb:`15px`,children:c&&(0,i.jsx)(n.HStack,{justify:`center`,w:`full`,children:(0,i.jsx)(wr,{isDark:o,appsInfo:Object.values(u||{}),isLoading:d})})})]})]})})},ua=({variant:e})=>{let{account:r}=X();return r?e===`icon`?null:e===`iconAndDomain`?r.domain?(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.W(r?.domain??``,16,0)}):(0,i.jsx)(n.Text,{fontSize:`sm`,children:t.U(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.W(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.U(r.address??``,4,4)})]}),(0,i.jsx)(qr,{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.W(r?.domain??``,16,0)}),(0,i.jsx)(n.Text,{fontSize:r.domain?`xs`:`sm`,opacity:r.domain?.5:1,children:t.U(r.address??``,4,4)})]}):(0,i.jsx)(n.Spinner,{})},da=({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)(Ec,{wallet:o,props:{width:30,height:30,minWidth:30,minHeight:30}}),(0,i.jsx)(ua,{variant:s?t:e})]})})},fa=({mobileVariant:e=`iconAndDomain`,desktopVariant:t=`iconDomainAndAddress`,buttonStyle:r,connectionVariant:a=`modal`})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s,loginMethods:c}=$(),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)(Ya,{darkMode:s,children:[d.isConnected&&p?(0,i.jsx)(da,{mobileVariant:e,desktopVariant:t,onOpen:v.onOpen,buttonStyle:r}):a===`popover`&&!g?(0,i.jsx)(la,{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(`Login`)}),(0,i.jsx)(sa,{isOpen:_.isOpen,onClose:_.onClose}),(0,i.jsx)(oa,{isOpen:v.isOpen,onClose:v.onClose})]})},pa=()=>{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:T.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:k.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:k.FaDiscord,color:`white`,fontSize:`20px`})}),(0,i.jsx)(n.Icon,{zIndex:1,as:g.LuPlus,color:e?`black`:`white`,fontSize:`15px`})]})},ma=({status:e,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:u})=>{let{t:d}=(0,l.useTranslation)(),{network:f}=$(),p=t.vt(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:d(e===`error`?`Try again`:`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,variant:`ghost`,size:`sm`,borderRadius:`full`,"aria-label":`Close`,icon:(0,i.jsx)(n.Icon,{as:g.LuX,boxSize:4})})]}):null},ha=({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)(ma,{status:r,txReceipt:a,txError:o,onTryAgain:s,description:c,onClose:t})}):null},ga=({isOpen:e,onClose:t,error:n,title:r,loadingText:a,onTryAgain:o=()=>{}})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,trapFocus:!1,autoFocus:!1,backdropFilter:`blur(3px)`,children:n?(0,i.jsx)(va,{error:n,onClose:t,onTryAgain:o}):(0,i.jsx)(_a,{loadingText:a,title:r,onTryAgain:o})}),_a=({loadingText:e,title:t,onTryAgain:a})=>{let{t:o}=(0,l.useTranslation)(),[s,c]=r.default.useState(!1);return r.default.useEffect(()=>{let e=setTimeout(()=>{c(!0)},7e3);return()=>clearTimeout(e)},[C.isMobile]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(J,{children:(0,i.jsx)(n.ModalHeader,{children:t??o(`Connecting...`)})}),(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&&!s&&(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:e}),s&&(0,i.jsxs)(n.VStack,{mt:4,spacing:2,children:[(0,i.jsx)(n.Text,{color:`orange.300`,size:`sm`,textAlign:`center`,children:o(`This is taking longer than expected.`)}),(0,i.jsx)(n.Text,{size:`sm`,textAlign:`center`,children:o(`You may want to try establishing the connection again.`)})]})]}),(0,i.jsx)(n.ModalFooter,{justifyContent:`center`,children:s&&(0,i.jsxs)(n.Button,{variant:`vechainKitPrimary`,onClick:a,children:[(0,i.jsx)(n.Icon,{mr:2,as:g.LuRefreshCw}),o(`Try again`)]})})]})},va=({error:e,onClose:t,onTryAgain:r})=>{let{t:a}=(0,l.useTranslation)();return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(J,{children:[(0,i.jsx)(n.ModalHeader,{children:a(`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:1/0},animate:{scale:[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}),a(`Try again`)]})})]})},ya=({onClose:e,appsInfo:a,isLoading:o})=>{let{t:s}=(0,l.useTranslation)(),c=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),[u,d]=(0,r.useState)(),[f,p]=(0,r.useState)(),m=(0,n.useDisclosure)(),{setConnectionCache:h}=Fo(),{login:g}=En(),_=async(n,r)=>{m.onOpen();try{d(void 0),p(r);try{await g(n),m.onClose(),h({name:r,logoUrl:a.find(e=>e.id===n)?.logo_url,appId:n,website:a.find(e=>e.id===n)?.website}),e()}catch(e){let n=e?.message;if(n&&t.a(n))return Error(`Login request was cancelled.`);d((e instanceof Error?e:Error(`'An unexpected issue occurred while logging in with this app. Please try again or contact support.',`)).message)}}catch(e){console.error(s(`Login failed:`),e),d(e instanceof Error?e.message:s(`Failed to connect with ecosystem app`))}};return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(J,{children:(0,i.jsxs)(n.ModalHeader,{children:[s(`Already have an x2earn app wallet?`),(0,i.jsx)(n.ModalCloseButton,{onClick:()=>{e()}})]})}),(0,i.jsxs)(n.ModalBody,{children:[o&&(0,i.jsx)(n.VStack,{minH:`200px`,w:`full`,justifyContent:`center`,children:(0,i.jsx)(n.Spinner,{})}),!o&&a&&(0,i.jsx)(n.VStack,{spacing:4,w:`full`,pb:6,children:a.map(e=>(0,i.jsxs)(n.Button,{variant:`loginIn`,fontSize:`14px`,fontWeight:`400`,p:6,borderRadius:16,w:`full`,onClick:()=>{_(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))}),!o&&!a&&(0,i.jsx)(n.Text,{textAlign:`center`,color:c,children:s(`No application from VeChain ecosystem is available to login.`)})]}),(0,i.jsx)(n.ModalFooter,{pt:0})]}),(0,i.jsx)(ga,{isOpen:m.isOpen,onClose:()=>{m.onClose()},error:u,title:`${s(`Connecting with`)} ${f}`,loadingText:s(`Please approve the request in the connection request window...`),onTryAgain:()=>{if(f){let e=a.find(e=>e.name===f);e&&_(e.id,e.name)}}})]})},ba=({isOpen:e,onClose:t,appsInfo:n,isLoading:r})=>(0,i.jsx)(Ne,{isOpen:e,onClose:t,backdropFilter:`blur(3px)`,children:(0,i.jsx)(ya,{onClose:t,appsInfo:n,isLoading:r})}),xa=({txId:e,title:r,description:a,onDone:o,showSocialButtons:s=!1})=>{let{t:c}=(0,l.useTranslation)(),{network:u}=$(),d=t.vt(u.type).explorerUrl,f=`${d}/${e}`,p=(0,n.useToken)(`colors`,`vechain-kit-success`);return(0,i.jsxs)(n.Box,{children:[(0,i.jsxs)(J,{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)(Qi,{descriptionEncoded: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})]})})]})})]})},Sa=({setCurrentContent:e,handleClose:t,style:r})=>{let{t:a}=(0,l.useTranslation)(),{smartAccount:o,connectedWallet:s}=X(),{data:c}=js(o?.address??``,s?.address??``,3),{sendTransaction:u,isTransactionPending:d,isWaitingForWalletConfirmation:f,error:p,txReceipt:m}=Is({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)(J,{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)(Dc,{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})})})]})},Ca=({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)(Ne,{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)(xa,{...a.props})}else if(a===`upgrade-smart-account`)return(0,i.jsx)(Sa,{setCurrentContent:o,handleClose:t,style:n})})()})},{definePartsStyle:wa,defineMultiStyleConfig:Ta}=(0,n.createMultiStyleConfigHelpers)(P.modalAnatomy.keys),Ea=e=>({vechainKitBase:wa({dialog:{scrollbarWidth:`none`,overflow:`scroll`,overflowX:`hidden`,maxHeight:`600px`,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:{bg:e.buttons.button.bg},_active:{bg:e.buttons.button.bg,opacity:.8}},header:{w:`full`,color:e.colors.text.primary,fontSize:e.fonts.sizes.medium,fontWeight:e.fonts.weights.bold,textAlign:`center`}})}),Da=e=>Ta({variants:Ea(e),defaultProps:{variant:`vechainKitBase`}}),{definePartsStyle:Oa,defineMultiStyleConfig:ka}=(0,n.createMultiStyleConfigHelpers)(P.cardAnatomy.keys),Aa=e=>({vechainKitBase:Oa({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}`}}),featureAnnouncement:Oa({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:Oa({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`}})}),ja=e=>ka({variants:Aa(e),defaultProps:{variant:`vechainKitBase`}}),Ma=(0,n.defineStyle)({borderRadius:`12px`}),Na=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)(()=>({width:`full`,minHeight:`50px`,height:`fit-content`,borderRadius:e.borders.radius.xl,p:0,bg:e.colors.error+`1f`,_hover:{bg:e.colors.error+`5e`,color:e.colors.error},transition:`all 0.2s`,color:e.colors.error})),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`}))}),Pa=e=>(0,n.defineStyleConfig)({baseStyle:Ma,variants:Na(e)}),{definePartsStyle:Fa,defineMultiStyleConfig:Ia}=(0,n.createMultiStyleConfigHelpers)(P.popoverAnatomy.keys),La=e=>({vechainKitBase:Fa({popper:{zIndex:1e3},content:{borderRadius:e.borders.radius.xl,border:`none`,backgroundColor:e.colors.background.modal,boxShadow:`0px 4px 16px rgba(0, 0, 0, 0.12)`,minWidth:`380px`},body:{padding:`16px`}})}),Ra=e=>Ia({variants:La(e),defaultProps:{variant:`vechainKitBase`}}),za=(e,t)=>({useSystemColorMode:!1,disableTransitionOnChange:!1,components:{Modal:Da(t),Card:ja(t),Button:Pa(t),Popover:Ra(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},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}),Ba=(e,t)=>{let r=(0,n.extendTheme)(za(e,_e(ge(e),ve(t,e))));return r.styles.global=()=>({}),r.__cssVars&&(r.__cssVars.global=()=>({})),r},{ToastContainer:Va}=(0,n.createStandaloneToast)(),Ha=()=>(0,N.default)({key:`vechain-kit`,prepend:!0}),Ua=({bodyFont:e,headingFont:t})=>(0,i.jsx)(M.Global,{styles:M.css`
120
120
  /* define CSS layers with proper priority order */
121
121
  @layer vechain-kit, host-app;
122
122
 
@@ -189,7 +189,7 @@ const e=require(`./assets-DXVXPy3w.cjs`),t=require(`./utils-Bl-JeVTg.cjs`);let n
189
189
  font-family: ${t} !important;
190
190
  }
191
191
  }
192
- `}),Wa=({children:e,theme:t,bodyFont:a,headingFont:o})=>(0,i.jsxs)(M.CacheProvider,{value:(0,r.useMemo)(()=>Ha(),[]),children:[(0,i.jsx)(Ua,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,children:e})]}),Ga=({darkMode:e})=>{try{if(t.ht(`[data-chakra-color-mode]`))return null}catch(e){console.error(e)}return(0,i.jsx)(n.ColorModeScript,{initialColorMode:e?`dark`:`light`})},Ka=(0,r.createContext)({portalRootRef:void 0,tokens:void 0}),qa=()=>{let e=(0,r.useContext)(Ka);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},Ja=({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,{})},Ya=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(Jc),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>_e(ge(t),ve(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...Ba(t,l),config:{...Ba(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]);return(0,i.jsxs)(Ka.Provider,{value:{portalRootRef:o,tokens:u},children:[(0,i.jsx)(Ga,{darkMode:t}),(0,i.jsxs)(Wa,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,children:[(0,i.jsx)(Ja,{darkMode:t}),(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})]}),(0,i.jsx)(Va,{})]})},Xa=(0,r.createContext)(null),Q=()=>{let e=(0,r.useContext)(Xa);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},Za=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),{setSource:c,connectV2:l}=(0,f.useWallet)(),u=(0,r.useCallback)(()=>{t.ft()&&window.vechain&&window.vechain.isInAppBrowser?(c(`veworld`),l(null)):s(!0)},[]),d=(0,r.useCallback)(()=>s(!1),[]),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(!1),_=(0,r.useCallback)((e,t)=>{P(e??`main`),g(t?.isolatedView??!1),m(!0)},[]),v=(0,r.useCallback)(()=>{m(!1),setTimeout(()=>{g(!1)},300)},[]),[y,b]=(0,r.useState)(!1),x=(0,r.useCallback)(()=>b(!0),[]),S=(0,r.useCallback)(()=>b(!1),[]),[C,w]=(0,r.useState)(!1),T=(0,r.useCallback)(()=>w(!0),[]),E=(0,r.useCallback)(()=>w(!1),[]),[D,O]=(0,r.useState)(!1),[k,A]=(0,r.useState)(void 0),j=(0,r.useCallback)(e=>{A(e),O(!0)},[]),M=(0,r.useCallback)(()=>O(!1),[]),[N,P]=(0,r.useState)(`main`);return(0,i.jsxs)(Xa.Provider,{value:{openConnectModal:u,closeConnectModal:d,isConnectModalOpen:o,openAccountModal:_,closeAccountModal:v,isAccountModalOpen:p,setAccountModalContent:P,accountModalContent:N,isolatedView:h,openTransactionModal:x,closeTransactionModal:S,isTransactionModalOpen:y,openTransactionToast:T,closeTransactionToast:E,isTransactionToastOpen:C,openUpgradeSmartAccountModal:j,closeUpgradeSmartAccountModal:M,isUpgradeSmartAccountModalOpen:D},children:[e,(0,i.jsxs)(Ya,{darkMode:n,theme:a,children:[(0,i.jsx)(sa,{isOpen:o,onClose:d}),(0,i.jsx)(oa,{isOpen:p,onClose:v,initialContent:N}),(0,i.jsx)(Ca,{isOpen:D,onClose:M,style:k})]})]})},Qa=()=>{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:n,close:t?o:r,isOpen:t?!1:i}},$a=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),eo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:()=>e(),close:t,isOpen:n}},to=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),no=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=Q();return{open:e,close:t,isOpen:n}},ro=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),io=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=Q();return{open:e,close:t,isOpen:n}},ao=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),oo=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=Q();return{open:()=>{e.isConnected?i():t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},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:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},lo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),uo=()=>{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}},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:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},mo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ho=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},go=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),_o=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},vo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),yo=()=>{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}},bo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:()=>{e({type:`account-customization`,props:{setCurrentContent:r}})},close:()=>{t()},isOpen:n}},So=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Co=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},wo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),To=()=>{let{privy:e,loginMethods:n}=$(),i=e?.appId===t.rt,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}},Eo=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=Q();return{open:()=>t(e),close:n,isOpen:r}},Do=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Oo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},ko=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Ao=()=>{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=qc();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]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},jo=()=>{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=qc();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)},[])}},Mo=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}};let No=!1;const Po=()=>{let{createWallet:e}=(0,u.useCreateWallet)(),{initOAuth:t}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:t})=>{if(t&&!No){No=!0;try{await e()}catch(e){throw No=!1,console.error(`Failed to create wallet:`,e),e}}},[e])});return{initOAuth:async({provider:e})=>{try{await t({provider:e})}catch(e){throw e}}}},Fo=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t._t(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.lt(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t.mt(e)},[])}},Io=()=>{let{login:e}=En(),{setConnectionCache:n}=Fo(),{data:r}=Be([t.rt]);return{login:async()=>{try{await e(t.rt),n({name:`VeChain`,logoUrl:r?.[t.rt]?.logo_url,appId:t.rt,website:`https://governance.vebetterdao.org`})}catch(e){throw Sn({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.`})}}}},Lo=`vechain-kit-app-hub-apps`,Ro=`vechain-kit-app-hub-apps-expiry`,zo=1440*60*1e3,Bo=`https://api.github.com`,Vo=`https://raw.githubusercontent.com/vechain/app-hub/master`,Ho=()=>[`VECHAIN_KIT`,`appHub`,`apps`],Uo=async()=>{if(typeof window<`u`)try{let e=t.lt(Lo),n=t.lt(Ro);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 e=await fetch(`https://api.github.com/repos/vechain/app-hub/contents/apps`);if(!e.ok)throw Error(`Failed to fetch app directories`);let n=(await e.json()).map(async e=>{if(e.type!==`dir`)return null;let t=`${Vo}/apps/${e.name}/manifest.json`,n=await fetch(t);if(!n.ok)return console.warn(`Failed to fetch manifest for ${e.name}`),null;try{let t=await n.json();return{id:e.name,name:t.name,description:t.desc,url:t.href,logo:`${Vo}/apps/${e.name}/logo.png`,category:t.category,tags:t.tags||[],isVeWorldSupported:t.isVeWorldSupported||!1,repo:t.repo,contracts:t.contracts,veBetterDaoId:t.veBetterDaoId}}catch(t){return console.warn(`Error parsing manifest for ${e.name}:`,t),null}}),r=(await Promise.all(n)).filter(e=>e!==null);if(typeof window<`u`)try{t._t(Lo,JSON.stringify(r)),t._t(Ro,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return r},Wo=()=>(0,p.useQuery)({queryKey:Ho(),queryFn:async()=>{try{return await Uo()}catch(e){let t=localStorage.getItem(Lo);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),Go=({abi:e,address:t,method:n})=>[`callClause`,t,n],Ko=e=>e.map(e=>typeof e==`bigint`?e.toString():Array.isArray(e)?Ko(e):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,typeof t==`bigint`?t.toString():t])):e),qo=({abi:e,address:t,method:n,args:r})=>[`callClause`,t,n,...r?.length?Ko(r):[]],Jo=({address:e,abi:n,method:r,args:i,queryOptions:a})=>{let o=(0,f.useThor)();return(0,p.useQuery)({queryKey:qo({abi:n,address:e,method:r,args:i}),queryFn:async()=>t.n({thor:o,contractAddress:e,abi:n,method:r,args:i}),...a})},Yo=({thor:e,calls:n,queryKey:r,enabled:i=!0})=>(0,p.useQuery)({queryKey:r,queryFn:()=>t.r({thor:e,calls:n}),enabled:i}),Xo=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},Zo=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},Qo=()=>{let{network:e}=$();return e.nodeUrl??t.vt(e.type).nodeUrl},$o=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.ft()){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},es=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},ts=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,y.formatEther)(BigInt(n.balance)).toString(),energy:(0,y.formatEther)(BigInt(n.energy)).toString()}},ns=e=>[`VECHAIN_KIT_BALANCE`,e],rs=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:ns(e),queryFn:()=>ts(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},is=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.vt(r).accountFactoryAddress,v.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()},as=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],os=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:as(e,n.type),queryFn:async()=>is(t,e,n.type),enabled:!!t&&!!e&&!!n})},ss=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.vt(n).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},cs=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],ls=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:cs(t.type),queryFn:async()=>ss(e,t.type),enabled:!!e&&!!t})},us=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.vt(r).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},ds=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],fs=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ds(e,n.type),queryFn:async()=>us(t,e,n.type),enabled:!!t&&!!e&&!!n})},ps=v.SocialLoginSmartAccountFactory__factory.abi,ms=(e,n,r)=>qo({abi:ps,address:t.vt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),hs=(e,n)=>{let{network:r}=$();return Jo({address:t.vt(r.type).accountFactoryAddress,abi:ps,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]})}})},gs=v.SocialLoginSmartAccountFactory__factory.abi,_s=`hasLegacyAccount`,vs=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:gs,contractAddress:t.vt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},ys=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],bs=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ys(e,n.type),queryFn:async()=>vs(t,e,n.type),enabled:!!t&&!!e&&!!n})},xs=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},Ss=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Cs=e=>{let t=Qo(),n=F.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ss(e),queryFn:async()=>xs(n,e),enabled:!!n&&!!e})},ws=()=>{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:ds(i,r.type)}),e.cancelQueries({queryKey:ms(a,i,r.type)}),e.cancelQueries({queryKey:ys(i,r.type)}),e.cancelQueries({queryKey:cs(r.type)}),e.cancelQueries({queryKey:As(a,i,3,r.type)}),e.cancelQueries({queryKey:Ns(a,3,r.type)}),e.cancelQueries({queryKey:as(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:ds(i,r.type)}),e.refetchQueries({queryKey:ms(a,i,r.type)}),e.refetchQueries({queryKey:ys(i,r.type)}),e.refetchQueries({queryKey:cs(r.type)}),e.refetchQueries({queryKey:As(a,i,3,r.type)}),e.refetchQueries({queryKey:Ns(a,3,r.type)}),e.refetchQueries({queryKey:as(3,r.type)})])}}},Ts=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Ds(n)}),e.cancelQueries({queryKey:Ss(n)})]),await Promise.all([e.refetchQueries({queryKey:Ds(n)}),e.refetchQueries({queryKey:Ss(n)})])}}},Es=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.vt(n).accountFactoryAddress,v.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}},Ds=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Os=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ds(e),queryFn:()=>Es(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},ks=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.vt(a).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.vt(a).accountFactoryAddress}`);return o[0]},As=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],js=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:As(e,t,n,i.type),queryFn:async()=>ks(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},Ms=async(e,n,r,i)=>{let a=await e.contracts.load(t.vt(i).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},Ns=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],Ps=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:Ns(e,t,r.type),queryFn:async()=>Ms(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},Fs=v.SocialLoginSmartAccount__factory.createInterface(),Is=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=ws(),{refresh:s}=Ts(),{data:c}=os(n),l=(0,r.useCallback)(async()=>{if(!e||!t.A(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:Fs.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:Fs.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=Kn({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.U(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())}},Ls=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],Rs=10*t.o.SECOND,zs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ls(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:Rs})},Bs=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},Vs=()=>[`VECHAIN_KIT_CHAIN_ID`],Hs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Vs(),queryFn:()=>Bs(e),enabled:!!e})},Us=1e3,Ws=async({thor:e,order:t=`asc`,offset:n=0,limit:r=Us,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},Gs=async({nodeUrl:e,thor:t,order:n=`asc`,from:r=0,to:i,filterCriteria:a})=>{let o=[],s=0;for(;;){let c=await Ws({nodeUrl:e,thor:t,filterCriteria:a,from:r,to:i??2**53-1,limit:Us,order:n,offset:s});if(o.push(...c),c.length<Us)return o;s+=Us}},Ks=v.MyERC20__factory.createInterface(),qs=(e,n,r,i)=>{if(!e||!n||!t.A(e))throw Error(`Invalid receiver address or amount`);let a=[];return a.push({to:r,value:`0x0`,data:Ks.encodeFunctionData(`transfer`,[e,(0,y.parseEther)(n)]),comment:`Transfer ${n} ${i} to ${e}`,abi:Ks.getFunction(`transfer`)}),a},Js=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,onSuccess:s,onError:c})=>{let{refresh:l}=On(),u=(0,r.useMemo)(()=>qs(n,i,a,o),[n,i,a,o]),d=Kn({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.U(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)}},Ys=(e,n)=>{if(!e||!n||!t.A(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,y.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},Xs=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=On(),c=(0,r.useMemo)(()=>Ys(n,i),[n,i]),l=Kn({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.U(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)}},Zs=({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=Kn({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}},Qs=10*t.o.SECOND,$s=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],ec=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:$s(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*Qs,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},tc=(e,t)=>{let n=(0,y.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},nc=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],rc=({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 Gs({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=>tc(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)(()=>nc({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function ic({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,y.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 ac({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,y.encodeFunctionData)(e.data):e.data)||`0x`}}}function oc(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=En(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=Hs();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const sc=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=oc(),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=>ac({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.vt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(v.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(v.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=ic({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.vt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(v.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(v.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 cc=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}({});const lc=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.lt(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t._t(e,JSON.stringify(i))},[e,i]),[i,a]},uc=`vechain-kit-storage-change`,dc=(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(uc,{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(uc,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(uc,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])]},fc=()=>{let[e,t]=lc(cc.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)}},pc=async(e,t,n,r,i)=>await(await fetch(t+`estimate/clauses/`+r.toLowerCase()+`?type=smartaccount&speed=`+i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json(),mc=async e=>await(await fetch(e+`deposit/account`,{method:`GET`,headers:{"Content-Type":`application/json`}})).json(),hc=async(e,t,n,r)=>await(await fetch(r+`sign/transaction/authorized/`+n.toLowerCase(),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json(),gc=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 _c(e,t){return s.Transaction.of(e.body,I.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function vc(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const yc=()=>{let{connectedWallet:e}=X(),{data:n}=Os(e?.address??``),{data:i}=hs(n?.address??``,e?.address??``),{preferences:a}=bc(),o=v.MyERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=sc(),u=F.ThorClient.at(t.vt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await pc(n?.address??``,r,e,c,`medium`),f=await mc(r),p={to:c===`VET`?f.depositAccount:t.X[c].address,value:c===`VET`?(0,y.parseEther)(d.transactionCost?.toString()??`0`).toString():`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,(0,y.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 gc(m,u,t.B,!0),g=await s.Transaction.of(h).signAsSender(s.HexUInt.of(t.B.privateKey).bytes),_=await hc(s.HexUInt.of(g.encoded).toString(),t.B.address,c,r),v=_c(g,_.signature),b={clauses:m,simulateTransactionOptions:{caller:t.B.address??``,gasPayer:_.address}},x=await u.transactions.simulateTransaction(b.clauses,{...b.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.B])}},bc=()=>{let[e,n]=dc(cc.GAS_TOKEN_PREFERENCES,t.q);return{preferences:e,supportedTokens:t.X,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])}},xc=({clauses:e,enabled:t=!0,tokens:n,sendingAmount:r,sendingTokenSymbol:i})=>{let{connectedWallet:a,account:o}=X(),{data:s}=Os(a?.address??``),{feeDelegation:c}=$(),{balances:l}=Lt(o?.address??``),{updatePreferences:u}=bc();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 pc(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})},Sc=({clauses:e,tokens:t,enabled:n=!0})=>{let{connectedWallet:r}=X(),{data:i}=Os(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 pc(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})},Cc=({label:e,address:a,domain:o,imageSrc:s,imageAlt:c=`Account`,hideAddress:u=!1,balance:d,tokenAddress:f})=>{let{t:p}=(0,l.useTranslation)(),m=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),g=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:_}=qt({address:a}),{tokens:v,isLoading:y}=Kt({address:a}),b=(0,r.useMemo)(()=>f?v.find(e=>e.address===f):null,[v,f]),x=(0,r.useMemo)(()=>d===void 0?b?Number(b.balance):0:d,[d,b]),S=b?.symbol||``;return _||y?(0,i.jsxs)(n.Box,{w:`full`,p:2,borderRadius:`2xl`,bg:g,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,mb:2,color:m,children:e}),(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`xl`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!u&&(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:m,children:p(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]})]}):(0,i.jsxs)(n.Box,{w:`full`,p:2,borderRadius:`2xl`,bg:g,wordBreak:`break-word`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,mb:2,color:m,children:e}),(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:s,alt:c,boxSize:`40px`,borderRadius:`xl`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:m,"data-testid":`${e.toLowerCase()}-domain`,children:o}),!u&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:h,"data-testid":`${e.toLowerCase()}-address`,children:t.U(a,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:m,"data-testid":`${e.toLowerCase()}-address`,children:t.U(a,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:m,children:p(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:h,children:[x.toLocaleString(void 0,{maximumFractionDigits:2}),S&&` ${S}`]})]})]})]})},wc=({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:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,...t}),Tc=({children:e,...t})=>(es(),(0,i.jsx)(n.VStack,{...t,children:e})),Ec=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image);return(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})},Dc=({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.vt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},Oc=({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}),kc=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{balances:p}=Lt(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)(Ne,{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.X[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.Q[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.b(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`)})]})})]})},Ac=({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:_}=bc(),{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}=Sc({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}=Lt(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.X[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.b(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.Q[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)(kc,{isOpen:v,onClose:b,selectedToken:M||h.availableGasTokens[0],onTokenSelect:D,availableTokens:h.availableGasTokens,tokenEstimations:C,walletAddress:m?.address??``})]})},jc=({isOpen:e,onClose:t,steps:r,activeStep:a,goToPrevious:o,setActiveStep:s,disableBackButton:c,disableCloseButton:l,closeOnOverlayClick:u=!0,isCloseable:d=!0})=>{let f=()=>{s(0),t()},[p]=(0,n.useMediaQuery)(`(min-width: 1060px)`),m=r[a],g=a===0,_=!g&&!c||m?.title||p&&!l;return m?(0,i.jsx)(Ne,{closeOnOverlayClick:u,isOpen:e,onClose:f,isCloseable:d,blockScrollOnMount:!0,children:(0,i.jsx)(n.Card,{p:0,bg:`none`,children:(0,i.jsxs)(n.CardBody,{p:0,children:[_?(0,i.jsxs)(J,{children:[m?.title?(0,i.jsx)(n.ModalHeader,{children:m.title}):null,!g&&!c?(0,i.jsx)(q,{onClick:o}):null,p&&!l?(0,i.jsx)(n.ModalCloseButton,{onClick:t}):null]}):null,m?.description?(0,i.jsx)(n.Text,{fontSize:{base:14,md:16},fontWeight:400,px:4,children:m?.description}):null,(0,i.jsx)(h.motion.div,{initial:`hidden`,animate:`visible`,style:{width:`100%`},children:m.content},m.key)]})})}):null},Mc=({document:e,register:t,isText:r=!1})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),s=e.displayName??a(`Policy`),c=o?`whiteAlpha.400`:`blackAlpha.400`,u=o?`blue.300`:`blue.500`,d=o?`blue.200`:`blue.700`,f=(()=>{if(!e.documentType)return s;switch(e.documentType){case`terms`:return e.displayName||`Terms of Service`;case`privacy`:return e.displayName||`Privacy Policy`;case`cookies`:return e.displayName||`Cookie Policy`;default:return e.displayName||`Legal Document`}})();return r?(0,i.jsxs)(n.Link,{href:e.url,isExternal:!0,color:`blue.500`,textDecoration:`underline`,_hover:{color:`blue.300`,textDecoration:`underline`},fontWeight:`medium`,display:`contents`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{...t(e.id,{required:e.required}),type:`checkbox`,hidden:!0}),f,(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:1,boxSize:3})]},e.id):(0,i.jsx)(n.HStack,{width:`full`,borderRadius:`md`,transition:`all 0.2s`,children:(0,i.jsxs)(n.HStack,{align:`flex-start`,spacing:3,width:`full`,children:[(0,i.jsx)(n.Checkbox,{mt:`2px`,size:`md`,colorScheme:`blue`,borderColor:c,...t(e.id,{required:e.required}),"data-testid":`tnc-checkbox`}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[a(`I have read and agree to `),(0,i.jsxs)(n.Link,{href:e.url,isExternal:!0,color:u,textDecoration:`underline`,_hover:{color:d,textDecoration:`underline`},fontWeight:`medium`,display:`contents`,alignItems:`center`,children:[f,(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:1})]}),e.required&&(0,i.jsx)(n.Text,{as:`span`,color:`red.500`,fontWeight:`bold`,children:`*`})]})]})},e.id)},Nc=({onAgree:e,onReject:t,onlyOptionalDocuments:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s}=$(),{documentsNotAgreed:c}=Uc(),{requiredDocuments:u,optionalDocuments:d}=(0,r.useMemo)(()=>c.reduce((e,t)=>(t.required?e.requiredDocuments.push(t):e.optionalDocuments.push(t),e),{requiredDocuments:[],optionalDocuments:[]}),[c]),{handleSubmit:f,register:p,formState:{isValid:m},watch:h}=(0,E.useForm)({defaultValues:(0,r.useMemo)(()=>c.reduce((e,t)=>(e[t.id]=t.required,e),{}),[c])}),g=h(),_=(0,r.useMemo)(()=>c.filter(e=>g[e.id]),[c,g]),v=c?.length===_.length,y=(0,r.useCallback)(t=>{let n=new Set(Object.entries(t).filter(([e,t])=>t).map(([e])=>e));return e(c.filter(e=>n.has(e.id)))},[c,e]),b=s?`#3a3a3a`:`#eaeaea`,x=s?`#2a2a2a`:`#f5f5f5`,S=s?`gray.300`:`gray.600`,C=s?`0 2px 8px rgba(0, 0, 0, 0.2)`:`0 2px 8px rgba(0, 0, 0, 0.05)`,w=u.length>0,T=d.length>0,D=(0,r.useMemo)(()=>{let e=d.filter(e=>g[e.id]).length;return o(v?`Accept all`:a&&e===0?`Ignore and continue`:w&&!T||w&&e===0?`Accept`:`Accept selected`)},[a,v,d,g]),O=e=>e===u.length-2&&u.length>1?o(` and `):`, `;return(0,i.jsx)(n.Stack,{width:`full`,children:(0,i.jsxs)(`form`,{onSubmit:f(y),children:[(0,i.jsx)(J,{children:(0,i.jsx)(n.ModalHeader,{children:o(`Terms and Policies`)})}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:5,width:`full`,children:[w&&(0,i.jsxs)(n.Text,{as:`span`,fontSize:`sm`,children:[o(`By continuing, you agree to`),` `,u.map((e,t)=>(0,i.jsxs)(r.Fragment,{children:[(0,i.jsx)(Mc,{document:e,register:p,isText:!0},e.id),t<u.length-1?O(t):null]},e.id)),`.`,` `,o(`Please take a moment to review all the policies, with acceptance being mandatory to continue.`)]}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:S,mb:3,children:(0,i.jsx)(l.Trans,{i18nKey:`<bold>Your privacy matters.</bold> You’re in control, accept to enable optional features like cookies that help us enhance your experience.`,components:{bold:(0,i.jsx)(n.Text,{as:`span`,fontWeight:`semibold`,color:S})}})}),T&&(0,i.jsxs)(n.Stack,{p:4,borderRadius:`xl`,bg:x,borderWidth:`1px`,borderColor:b,boxShadow:C,spacing:5,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:S,children:o(`Optional`)}),(0,i.jsx)(n.VStack,{align:`stretch`,spacing:4,children:d.map(e=>(0,i.jsx)(Mc,{document:e,register:p},e.id))})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:3,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,width:`full`,type:`submit`,isDisabled:!m,"data-testid":`accept-tnc-button`,children:D}),!a&&(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:t,"data-testid":`reject-tnc-button`,colorScheme:`red`,children:o(`Reject and logout`)})]})})]})})};var Pc=function(e){return e.REVIEW_DOCUMENTS=`REVIEW_DOCUMENTS`,e.REJECT_DOCUMENTS=`REJECT_DOCUMENTS`,e}(Pc||{});const Fc=({isOpen:e,onAgree:t,handleLogout:a,onlyOptionalDocuments:o})=>{let{t:s}=(0,l.useTranslation)(),{activeStep:c,goToPrevious:u,setActiveStep:d,goToNext:f}=(0,n.useSteps)({index:0,count:Object.keys(Pc).length}),p=()=>{d(0)},m=()=>{f()},h=()=>{a(),p()};return(0,i.jsx)(jc,{isOpen:e,onClose:()=>{},goToPrevious:u,goToNext:f,setActiveStep:d,steps:(0,r.useMemo)(()=>[{key:Pc.REVIEW_DOCUMENTS,content:(0,i.jsx)(Nc,{onAgree:t,onReject:m,onlyOptionalDocuments:o})},{key:Pc.REJECT_DOCUMENTS,content:(0,i.jsx)(Ci,{onDisconnect:h,onBack:u,onClose:u,text:s(`Are you sure you want to reject the policies and disconnect?`),showCloseButton:!1})}],[Nc,Ci,t,h]),disableCloseButton:!0,disableBackButton:!0,isCloseable:!1,closeOnOverlayClick:!1,activeStep:c})},Ic=`vechain-kit-legal-documents`,Lc=`vechain-kit-legal-documents-optional-reject`,Rc=e=>`${e.documentType}-${e.url.replace(/[^\w-]+/g,`-`)}-v${e.version}`,zc=e=>e.map(e=>({...e,id:Rc(e)})),Bc=e=>e.filter(e=>!e.required),Vc=(e,t)=>{let n=Date.now();return e.map(e=>({...e,walletAddress:t,timestamp:n}))},Hc=(0,r.createContext)(void 0),Uc=()=>(0,r.useContext)(Hc)||{hasAgreedToRequiredDocuments:!0,agreements:[],walletAddress:void 0,documents:[],documentsNotAgreed:[]},Wc=({children:e})=>{let{connection:n,account:a,disconnect:o}=X(),{darkMode:s,legalDocuments:c,theme:l}=$(),[u,d]=dc(`vechain-kit-legal-documents`,[]),[f,p]=dc(`vechain-kit-legal-documents-optional-reject`,[]),[m,h]=(0,r.useState)(!1),g=(0,r.useCallback)((e,n)=>f.some(r=>t.O(r.walletAddress,n)&&r.id===e.id),[f]),[_,v]=(0,r.useMemo)(()=>{let e=zc([{items:c?.cookiePolicy||[],type:t.v.COOKIES,source:t._.APPLICATION},{items:c?.privacyPolicy||[],type:t.v.PRIVACY,source:t._.APPLICATION},{items:c?.termsAndConditions||[],type:t.v.TERMS,source:t._.APPLICATION}].flatMap(e=>e.items.map(t=>({...t,documentType:e.type,documentSource:e.source}))));return[e,e.filter(e=>e.required)]},[c]),y=(0,r.useMemo)(()=>a?.address?_.filter(e=>u.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)?!1:!f.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)):[],[_,a?.address,u,f]),b=(0,r.useMemo)(()=>!v.length||!a?.address?!0:v.every(e=>u.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)),[v,u,a?.address]),x=(0,r.useMemo)(()=>{if(!a?.address||!y?.length)return!1;let e=Bc(y);return e.length===0?!1:e.some(e=>!g(e,a.address))},[y,a?.address,Bc,g]),S=(0,r.useMemo)(()=>b&&x,[b,x]);(0,r.useMemo)(()=>{let e=new Set(u.map(e=>e.id));return _.some(t=>e.has(t.id))},[_,u]),(0,r.useEffect)(()=>{n.isConnected&&a?.address?h(!b||x):h(!1)},[n.isConnected,a?.address,b,x]);let C=(0,r.useCallback)((e,n)=>{let r=Array.isArray(e)?e:[e];if(!r.length)return;let i=Vc(r,n);d([...u.filter(e=>!t.O(e.walletAddress,n)||!r.some(t=>t.id===e.id)),...i])},[u,Vc]),w=(0,r.useCallback)(e=>{if(!a?.address)return;let t=Bc(y);if(t.length===0)return;let n=e.map(e=>e.id),r=t.filter(e=>!n.includes(e.id));if(!r?.length)return;let i=Vc(r,a.address);p(e=>[...e,...i])},[a?.address,y,Bc,Vc]),T=(0,r.useCallback)(e=>{if(!a?.address)return;let t=Array.isArray(e)?e:[e];t.length>0&&C(t,a.address),w(t),h(!1)},[a?.address,C,w]);return(0,i.jsxs)(Hc.Provider,{value:{hasAgreedToRequiredDocuments:b,agreements:u,walletAddress:a?.address,documents:_,documentsNotAgreed:y},children:[e,(0,i.jsx)(Ya,{darkMode:s,theme:l,children:(0,i.jsx)(Fc,{isOpen:m,onAgree:T,handleLogout:S?()=>{}:()=>{o(),h(!1)},onlyOptionalDocuments:S})})]})},Gc=(0,r.createContext)(null),Kc=({children:e,nodeUrl:n,delegatorUrl:a=t.at(),delegateAllTransactions:o,genericDelegator:s})=>{let{signTypedData:c,exportWallet:l,signMessage:d}=(0,u.usePrivy)(),{signTypedData:f,signMessage:p}=En(),{connection:m,connectedWallet:h}=X(),{network:g}=$(),{data:_}=Os(h?.address??``),{data:v}=hs(_?.address??``,h?.address??``),{data:y}=bs(h?.address??``),{buildClausesWithAuth:b}=sc(),{sendTransactionUsingGenericDelegator:x}=yc(),S=F.ThorClient.at(n),C=async(e,r,i,o)=>{if(!_?.address)throw Error(`Smart account address is not set`);let s=new F.VeChainProvider(S,i??new F.ProviderInternalBaseWallet([{privateKey:Buffer.from(t.B.privateKey.slice(2),`hex`),address:t.B.address}],{gasPayer:{gasPayerServiceUrl:r??a}}),!0),c=o??await s.getSigner(t.B.address),l=F.signerUtils.transactionBodyToTransactionRequestInput(e,t.B.address),u=await c.signTransaction(l),{id:d}=await fetch(`${n}/transactions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({raw:u})}).then(e=>e.json());return d},w=(0,r.useCallback)(async({txClauses:e=[],title:n=`Sign Transaction`,description:r,buttonText:i=`Sign`,delegationUrl:o})=>{if(!_||_&&!_.address||!h||h&&!h.address)throw Error(`Address or embedded wallet is missing`);if(s&&!o)return await x({clauses:e,genericDelegatorUrl:a??``});let c=await b({clauses:e,smartAccount:_,version:y?1:v?.version??3,title:n,description:r,buttonText:i}),l={clauses:c,simulateTransactionOptions:{caller:t.B.address}},u=await S.transactions.simulateTransaction(l.clauses,{...l.simulateTransactionOptions});for(let e=0;e<u.length;e++)if(u[e].reverted)return console.error(`simulatedTx1[i].vmError: ${u[e].vmError}`),u[e].vmError;return await C(await gc(c,S,t.B,!0),o)},[x,s,_,h,a,b,y,v,S]);return(0,i.jsx)(Gc.Provider,{value:{accountFactory:t.vt(g.type).accountFactoryAddress,sendTransaction:w,signMessage:async e=>m.isConnectedWithCrossApp?await p(e):(await d({message:e})).signature,signTypedData:async e=>m.isConnectedWithCrossApp?await f({...e,address:h?.address,types:Object.fromEntries(Object.entries(e.types).map(([e,t])=>[e,[...t]]))}):(await c(e)).signature,exportWallet:l,delegateAllTransactions:o},children:e})},qc=()=>{let e=(0,r.useContext)(Gc);if(!e)throw Error(`usePrivyWalletProvider must be used within a PrivyWalletProvider`);return e},Jc=(0,r.createContext)(null),$=()=>{let e=(0,r.useContext)(Jc);if(!e)throw Error(`useVeChainKitConfig must be used within VeChainKit`);return e},Yc=e=>{let n=[],r={...e};if(r.dappKit||={allowedWallets:[`veworld`]},(r.privy!==void 0||r.loginMethods?.some(e=>e.method===`vechain`||e.method===`ecosystem`))&&(r.feeDelegation?!r.feeDelegation.delegatorUrl&&!r.feeDelegation.genericDelegatorUrl&&(r.feeDelegation.genericDelegatorUrl=t.at()):r.feeDelegation={genericDelegatorUrl:t.at()}),!r.network||!r.network.type)r.network={type:`main`};else{let e=r.network.type;[`main`,`test`,`solo`].includes(e)||n.push(`network.type must be either "main", "test" or "solo"`)}if(r.loginMethods||=[{method:`vechain`,gridColumn:4},{method:`ecosystem`,gridColumn:4},{method:`dappkit`,gridColumn:4}],r.loginMethods&&!r.privy){let e=r.loginMethods.filter(e=>[`email`,`google`,`passkey`,`more`].includes(e.method));e.length>0&&n.push(`Login methods ${e.map(e=>`"${e.method}"`).join(`, `)} require Privy configuration. Please either remove these methods or configure the privy prop.`)}if(r?.legalDocuments&&(r.legalDocuments.termsAndConditions&&r.legalDocuments.termsAndConditions.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.termsAndConditions.url is invalid: ${e.url}`)}),r.legalDocuments.privacyPolicy&&r.legalDocuments.privacyPolicy.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.privacyPolicy.url is invalid: ${e.url}`)}),r.legalDocuments.cookiePolicy&&r.legalDocuments.cookiePolicy.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.cookiePolicy.url is invalid: ${e.url}`)})),n.length>0)throw Error(`VeChainKit Configuration Error:
192
+ `}),Wa=({children:e,theme:t,bodyFont:a,headingFont:o})=>(0,i.jsxs)(M.CacheProvider,{value:(0,r.useMemo)(()=>Ha(),[]),children:[(0,i.jsx)(Ua,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,children:e})]}),Ga=({darkMode:e})=>{try{if(t.ht(`[data-chakra-color-mode]`))return null}catch(e){console.error(e)}return(0,i.jsx)(n.ColorModeScript,{initialColorMode:e?`dark`:`light`})},Ka=(0,r.createContext)({portalRootRef:void 0,tokens:void 0}),qa=()=>{let e=(0,r.useContext)(Ka);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},Ja=({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,{})},Ya=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(Jc),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>_e(ge(t),ve(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...Ba(t,l),config:{...Ba(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]);return(0,i.jsxs)(Ka.Provider,{value:{portalRootRef:o,tokens:u},children:[(0,i.jsx)(Ga,{darkMode:t}),(0,i.jsxs)(Wa,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,children:[(0,i.jsx)(Ja,{darkMode:t}),(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})]}),(0,i.jsx)(Va,{})]})},Xa=(0,r.createContext)(null),Q=()=>{let e=(0,r.useContext)(Xa);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},Za=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),{setSource:c,connectV2:l}=(0,f.useWallet)(),u=(0,r.useCallback)(()=>{t.ft()&&window.vechain&&window.vechain.isInAppBrowser?(c(`veworld`),l(null)):s(!0)},[]),d=(0,r.useCallback)(()=>s(!1),[]),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(`main`),y=(0,r.useCallback)((e,t)=>{v(e??`main`),g(t?.isolatedView??!1),m(!0)},[]),b=(0,r.useCallback)(()=>{m(!1),v(`main`),setTimeout(()=>{g(!1)},300)},[]),[x,S]=(0,r.useState)(!1),C=(0,r.useCallback)(()=>S(!0),[]),w=(0,r.useCallback)(()=>S(!1),[]),[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,M]=(0,r.useState)(void 0),N=(0,r.useCallback)(e=>{M(e),A(!0)},[]),P=(0,r.useCallback)(()=>A(!1),[]);return(0,i.jsxs)(Xa.Provider,{value:{openConnectModal:u,closeConnectModal:d,isConnectModalOpen:o,openAccountModal:y,closeAccountModal:b,isAccountModalOpen:p,setAccountModalContent:v,accountModalContent:_,isolatedView:h,openTransactionModal:C,closeTransactionModal:w,isTransactionModalOpen:x,openTransactionToast:D,closeTransactionToast:O,isTransactionToastOpen:T,openUpgradeSmartAccountModal:N,closeUpgradeSmartAccountModal:P,isUpgradeSmartAccountModalOpen:k},children:[e,(0,i.jsxs)(Ya,{darkMode:n,theme:a,children:[(0,i.jsx)(sa,{isOpen:o,onClose:d}),(0,i.jsx)(oa,{isOpen:p,onClose:b,initialContent:_}),(0,i.jsx)(Ca,{isOpen:k,onClose:P,style:j})]})]})},Qa=()=>{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:n,close:t?o:r,isOpen:t?!1:i}},$a=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),eo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:()=>e(),close:t,isOpen:n}},to=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),no=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=Q();return{open:e,close:t,isOpen:n}},ro=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),io=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=Q();return{open:e,close:t,isOpen:n}},ao=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),oo=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=Q();return{open:()=>{e.isConnected?i():t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},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:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},lo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),uo=()=>{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}},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:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},mo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),ho=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},go=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),_o=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},vo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),yo=()=>{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}},bo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=Q();return{open:()=>{e({type:`account-customization`,props:{setCurrentContent:r}})},close:()=>{t()},isOpen:n}},So=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Co=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},wo=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),To=()=>{let{privy:e,loginMethods:n}=$(),i=e?.appId===t.rt,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}},Eo=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=Q();return{open:()=>t(e),close:n,isOpen:r}},Do=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Oo=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=Q();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},ko=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Ao=()=>{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=qc();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]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},jo=()=>{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=qc();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)},[])}},Mo=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}};let No=!1;const Po=()=>{let{createWallet:e}=(0,u.useCreateWallet)(),{initOAuth:t}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:t})=>{if(t&&!No){No=!0;try{await e()}catch(e){throw No=!1,console.error(`Failed to create wallet:`,e),e}}},[e])});return{initOAuth:async({provider:e})=>{try{await t({provider:e})}catch(e){throw e}}}},Fo=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t._t(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.lt(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t.mt(e)},[])}},Io=()=>{let{login:e}=En(),{setConnectionCache:n}=Fo(),{data:r}=Be([t.rt]);return{login:async()=>{try{await e(t.rt),n({name:`VeChain`,logoUrl:r?.[t.rt]?.logo_url,appId:t.rt,website:`https://governance.vebetterdao.org`})}catch(e){throw Sn({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.`})}}}},Lo=`vechain-kit-app-hub-apps`,Ro=`vechain-kit-app-hub-apps-expiry`,zo=1440*60*1e3,Bo=`https://api.github.com`,Vo=`https://raw.githubusercontent.com/vechain/app-hub/master`,Ho=()=>[`VECHAIN_KIT`,`appHub`,`apps`],Uo=async()=>{if(typeof window<`u`)try{let e=t.lt(Lo),n=t.lt(Ro);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 e=await fetch(`https://api.github.com/repos/vechain/app-hub/contents/apps`);if(!e.ok)throw Error(`Failed to fetch app directories`);let n=(await e.json()).map(async e=>{if(e.type!==`dir`)return null;let t=`${Vo}/apps/${e.name}/manifest.json`,n=await fetch(t);if(!n.ok)return console.warn(`Failed to fetch manifest for ${e.name}`),null;try{let t=await n.json();return{id:e.name,name:t.name,description:t.desc,url:t.href,logo:`${Vo}/apps/${e.name}/logo.png`,category:t.category,tags:t.tags||[],isVeWorldSupported:t.isVeWorldSupported||!1,repo:t.repo,contracts:t.contracts,veBetterDaoId:t.veBetterDaoId}}catch(t){return console.warn(`Error parsing manifest for ${e.name}:`,t),null}}),r=(await Promise.all(n)).filter(e=>e!==null);if(typeof window<`u`)try{t._t(Lo,JSON.stringify(r)),t._t(Ro,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return r},Wo=()=>(0,p.useQuery)({queryKey:Ho(),queryFn:async()=>{try{return await Uo()}catch(e){let t=localStorage.getItem(Lo);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),Go=({abi:e,address:t,method:n})=>[`callClause`,t,n],Ko=e=>e.map(e=>typeof e==`bigint`?e.toString():Array.isArray(e)?Ko(e):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,typeof t==`bigint`?t.toString():t])):e),qo=({abi:e,address:t,method:n,args:r})=>[`callClause`,t,n,...r?.length?Ko(r):[]],Jo=({address:e,abi:n,method:r,args:i,queryOptions:a})=>{let o=(0,f.useThor)();return(0,p.useQuery)({queryKey:qo({abi:n,address:e,method:r,args:i}),queryFn:async()=>t.n({thor:o,contractAddress:e,abi:n,method:r,args:i}),...a})},Yo=({thor:e,calls:n,queryKey:r,enabled:i=!0})=>(0,p.useQuery)({queryKey:r,queryFn:()=>t.r({thor:e,calls:n}),enabled:i}),Xo=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},Zo=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},Qo=()=>{let{network:e}=$();return e.nodeUrl??t.vt(e.type).nodeUrl},$o=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.ft()){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},es=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},ts=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,y.formatEther)(BigInt(n.balance)).toString(),energy:(0,y.formatEther)(BigInt(n.energy)).toString()}},ns=e=>[`VECHAIN_KIT_BALANCE`,e],rs=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:ns(e),queryFn:()=>ts(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},is=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.vt(r).accountFactoryAddress,v.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()},as=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],os=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:as(e,n.type),queryFn:async()=>is(t,e,n.type),enabled:!!t&&!!e&&!!n})},ss=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.vt(n).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},cs=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],ls=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:cs(t.type),queryFn:async()=>ss(e,t.type),enabled:!!e&&!!t})},us=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.vt(r).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},ds=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],fs=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ds(e,n.type),queryFn:async()=>us(t,e,n.type),enabled:!!t&&!!e&&!!n})},ps=v.SocialLoginSmartAccountFactory__factory.abi,ms=(e,n,r)=>qo({abi:ps,address:t.vt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),hs=(e,n)=>{let{network:r}=$();return Jo({address:t.vt(r.type).accountFactoryAddress,abi:ps,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]})}})},gs=v.SocialLoginSmartAccountFactory__factory.abi,_s=`hasLegacyAccount`,vs=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:gs,contractAddress:t.vt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},ys=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],bs=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:ys(e,n.type),queryFn:async()=>vs(t,e,n.type),enabled:!!t&&!!e&&!!n})},xs=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},Ss=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Cs=e=>{let t=Qo(),n=F.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ss(e),queryFn:async()=>xs(n,e),enabled:!!n&&!!e})},ws=()=>{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:ds(i,r.type)}),e.cancelQueries({queryKey:ms(a,i,r.type)}),e.cancelQueries({queryKey:ys(i,r.type)}),e.cancelQueries({queryKey:cs(r.type)}),e.cancelQueries({queryKey:As(a,i,3,r.type)}),e.cancelQueries({queryKey:Ns(a,3,r.type)}),e.cancelQueries({queryKey:as(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:ds(i,r.type)}),e.refetchQueries({queryKey:ms(a,i,r.type)}),e.refetchQueries({queryKey:ys(i,r.type)}),e.refetchQueries({queryKey:cs(r.type)}),e.refetchQueries({queryKey:As(a,i,3,r.type)}),e.refetchQueries({queryKey:Ns(a,3,r.type)}),e.refetchQueries({queryKey:as(3,r.type)})])}}},Ts=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Ds(n)}),e.cancelQueries({queryKey:Ss(n)})]),await Promise.all([e.refetchQueries({queryKey:Ds(n)}),e.refetchQueries({queryKey:Ss(n)})])}}},Es=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.vt(n).accountFactoryAddress,v.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}},Ds=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Os=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ds(e),queryFn:()=>Es(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},ks=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.vt(a).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.vt(a).accountFactoryAddress}`);return o[0]},As=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],js=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:As(e,t,n,i.type),queryFn:async()=>ks(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},Ms=async(e,n,r,i)=>{let a=await e.contracts.load(t.vt(i).accountFactoryAddress,v.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},Ns=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],Ps=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:Ns(e,t,r.type),queryFn:async()=>Ms(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},Fs=v.SocialLoginSmartAccount__factory.createInterface(),Is=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=ws(),{refresh:s}=Ts(),{data:c}=os(n),l=(0,r.useCallback)(async()=>{if(!e||!t.A(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:Fs.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:Fs.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=Kn({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.U(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())}},Ls=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],Rs=10*t.o.SECOND,zs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Ls(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:Rs})},Bs=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},Vs=()=>[`VECHAIN_KIT_CHAIN_ID`],Hs=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:Vs(),queryFn:()=>Bs(e),enabled:!!e})},Us=1e3,Ws=async({thor:e,order:t=`asc`,offset:n=0,limit:r=Us,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},Gs=async({nodeUrl:e,thor:t,order:n=`asc`,from:r=0,to:i,filterCriteria:a})=>{let o=[],s=0;for(;;){let c=await Ws({nodeUrl:e,thor:t,filterCriteria:a,from:r,to:i??2**53-1,limit:Us,order:n,offset:s});if(o.push(...c),c.length<Us)return o;s+=Us}},Ks=v.MyERC20__factory.createInterface(),qs=(e,n,r,i)=>{if(!e||!n||!t.A(e))throw Error(`Invalid receiver address or amount`);let a=[];return a.push({to:r,value:`0x0`,data:Ks.encodeFunctionData(`transfer`,[e,(0,y.parseEther)(n)]),comment:`Transfer ${n} ${i} to ${e}`,abi:Ks.getFunction(`transfer`)}),a},Js=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,onSuccess:s,onError:c})=>{let{refresh:l}=On(),u=(0,r.useMemo)(()=>qs(n,i,a,o),[n,i,a,o]),d=Kn({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.U(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)}},Ys=(e,n)=>{if(!e||!n||!t.A(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,y.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},Xs=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=On(),c=(0,r.useMemo)(()=>Ys(n,i),[n,i]),l=Kn({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.U(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)}},Zs=({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=Kn({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}},Qs=10*t.o.SECOND,$s=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],ec=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:$s(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*Qs,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},tc=(e,t)=>{let n=(0,y.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},nc=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],rc=({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 Gs({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=>tc(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)(()=>nc({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function ic({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,y.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 ac({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,y.encodeFunctionData)(e.data):e.data)||`0x`}}}function oc(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=En(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=Hs();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const sc=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=oc(),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=>ac({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.vt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(v.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(v.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=ic({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.vt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(v.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(v.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 cc=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}({});const lc=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.lt(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t._t(e,JSON.stringify(i))},[e,i]),[i,a]},uc=`vechain-kit-storage-change`,dc=(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(uc,{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(uc,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(uc,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])]},fc=()=>{let[e,t]=lc(cc.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)}},pc=async(e,t,n,r,i)=>await(await fetch(t+`estimate/clauses/`+r.toLowerCase()+`?type=smartaccount&speed=`+i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json(),mc=async e=>await(await fetch(e+`deposit/account`,{method:`GET`,headers:{"Content-Type":`application/json`}})).json(),hc=async(e,t,n,r)=>await(await fetch(r+`sign/transaction/authorized/`+n.toLowerCase(),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json(),gc=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 _c(e,t){return s.Transaction.of(e.body,I.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function vc(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const yc=()=>{let{connectedWallet:e}=X(),{data:n}=Os(e?.address??``),{data:i}=hs(n?.address??``,e?.address??``),{preferences:a}=bc(),o=v.MyERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=sc(),u=F.ThorClient.at(t.vt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await pc(n?.address??``,r,e,c,`medium`),f=await mc(r),p={to:c===`VET`?f.depositAccount:t.X[c].address,value:c===`VET`?(0,y.parseEther)(d.transactionCost?.toString()??`0`).toString():`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,(0,y.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 gc(m,u,t.B,!0),g=await s.Transaction.of(h).signAsSender(s.HexUInt.of(t.B.privateKey).bytes),_=await hc(s.HexUInt.of(g.encoded).toString(),t.B.address,c,r),v=_c(g,_.signature),b={clauses:m,simulateTransactionOptions:{caller:t.B.address??``,gasPayer:_.address}},x=await u.transactions.simulateTransaction(b.clauses,{...b.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.B])}},bc=()=>{let[e,n]=dc(cc.GAS_TOKEN_PREFERENCES,t.q);return{preferences:e,supportedTokens:t.X,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])}},xc=({clauses:e,enabled:t=!0,tokens:n,sendingAmount:r,sendingTokenSymbol:i})=>{let{connectedWallet:a,account:o}=X(),{data:s}=Os(a?.address??``),{feeDelegation:c}=$(),{balances:l}=Lt(o?.address??``),{updatePreferences:u}=bc();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 pc(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})},Sc=({clauses:e,tokens:t,enabled:n=!0})=>{let{connectedWallet:r}=X(),{data:i}=Os(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 pc(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})},Cc=({label:e,address:a,domain:o,imageSrc:s,imageAlt:c=`Account`,hideAddress:u=!1,balance:d,tokenAddress:f})=>{let{t:p}=(0,l.useTranslation)(),m=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),h=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),g=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:_}=qt({address:a}),{tokens:v,isLoading:y}=Kt({address:a}),b=(0,r.useMemo)(()=>f?v.find(e=>e.address===f):null,[v,f]),x=(0,r.useMemo)(()=>d===void 0?b?Number(b.balance):0:d,[d,b]),S=b?.symbol||``;return _||y?(0,i.jsxs)(n.Box,{w:`full`,p:2,borderRadius:`2xl`,bg:g,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,mb:2,color:m,children:e}),(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`xl`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!u&&(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:m,children:p(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]})]}):(0,i.jsxs)(n.Box,{w:`full`,p:2,borderRadius:`2xl`,bg:g,wordBreak:`break-word`,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`bold`,mb:2,color:m,children:e}),(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:s,alt:c,boxSize:`40px`,borderRadius:`xl`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:m,"data-testid":`${e.toLowerCase()}-domain`,children:o}),!u&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:h,"data-testid":`${e.toLowerCase()}-address`,children:t.U(a,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:m,"data-testid":`${e.toLowerCase()}-address`,children:t.U(a,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:m,children:p(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:h,children:[x.toLocaleString(void 0,{maximumFractionDigits:2}),S&&` ${S}`]})]})]})]})},wc=({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:`ghost`,position:`absolute`,borderRadius:`50%`,left:`10px`,top:`10px`,onClick:e,...t}),Tc=({children:e,...t})=>(es(),(0,i.jsx)(n.VStack,{...t,children:e})),Ec=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image);return(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})},Dc=({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.vt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},Oc=({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}),kc=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{balances:p}=Lt(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)(Ne,{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.X[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.Q[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.b(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`)})]})})]})},Ac=({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:_}=bc(),{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}=Sc({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}=Lt(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.X[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.b(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.Q[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)(kc,{isOpen:v,onClose:b,selectedToken:M||h.availableGasTokens[0],onTokenSelect:D,availableTokens:h.availableGasTokens,tokenEstimations:C,walletAddress:m?.address??``})]})},jc=({isOpen:e,onClose:t,steps:r,activeStep:a,goToPrevious:o,setActiveStep:s,disableBackButton:c,disableCloseButton:l,closeOnOverlayClick:u=!0,isCloseable:d=!0})=>{let f=()=>{s(0),t()},[p]=(0,n.useMediaQuery)(`(min-width: 1060px)`),m=r[a],g=a===0,_=!g&&!c||m?.title||p&&!l;return m?(0,i.jsx)(Ne,{closeOnOverlayClick:u,isOpen:e,onClose:f,isCloseable:d,blockScrollOnMount:!0,children:(0,i.jsx)(n.Card,{p:0,bg:`none`,children:(0,i.jsxs)(n.CardBody,{p:0,children:[_?(0,i.jsxs)(J,{children:[m?.title?(0,i.jsx)(n.ModalHeader,{children:m.title}):null,!g&&!c?(0,i.jsx)(q,{onClick:o}):null,p&&!l?(0,i.jsx)(n.ModalCloseButton,{onClick:t}):null]}):null,m?.description?(0,i.jsx)(n.Text,{fontSize:{base:14,md:16},fontWeight:400,px:4,children:m?.description}):null,(0,i.jsx)(h.motion.div,{initial:`hidden`,animate:`visible`,style:{width:`100%`},children:m.content},m.key)]})})}):null},Mc=({document:e,register:t,isText:r=!1})=>{let{t:a}=(0,l.useTranslation)(),{darkMode:o}=$(),s=e.displayName??a(`Policy`),c=o?`whiteAlpha.400`:`blackAlpha.400`,u=o?`blue.300`:`blue.500`,d=o?`blue.200`:`blue.700`,f=(()=>{if(!e.documentType)return s;switch(e.documentType){case`terms`:return e.displayName||`Terms of Service`;case`privacy`:return e.displayName||`Privacy Policy`;case`cookies`:return e.displayName||`Cookie Policy`;default:return e.displayName||`Legal Document`}})();return r?(0,i.jsxs)(n.Link,{href:e.url,isExternal:!0,color:`blue.500`,textDecoration:`underline`,_hover:{color:`blue.300`,textDecoration:`underline`},fontWeight:`medium`,display:`contents`,alignItems:`center`,children:[(0,i.jsx)(n.Input,{...t(e.id,{required:e.required}),type:`checkbox`,hidden:!0}),f,(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:1,boxSize:3})]},e.id):(0,i.jsx)(n.HStack,{width:`full`,borderRadius:`md`,transition:`all 0.2s`,children:(0,i.jsxs)(n.HStack,{align:`flex-start`,spacing:3,width:`full`,children:[(0,i.jsx)(n.Checkbox,{mt:`2px`,size:`md`,colorScheme:`blue`,borderColor:c,...t(e.id,{required:e.required}),"data-testid":`tnc-checkbox`}),(0,i.jsxs)(n.Text,{fontSize:`xs`,children:[a(`I have read and agree to `),(0,i.jsxs)(n.Link,{href:e.url,isExternal:!0,color:u,textDecoration:`underline`,_hover:{color:d,textDecoration:`underline`},fontWeight:`medium`,display:`contents`,alignItems:`center`,children:[f,(0,i.jsx)(n.Icon,{as:g.LuExternalLink,ml:1})]}),e.required&&(0,i.jsx)(n.Text,{as:`span`,color:`red.500`,fontWeight:`bold`,children:`*`})]})]})},e.id)},Nc=({onAgree:e,onReject:t,onlyOptionalDocuments:a=!1})=>{let{t:o}=(0,l.useTranslation)(),{darkMode:s}=$(),{documentsNotAgreed:c}=Uc(),{requiredDocuments:u,optionalDocuments:d}=(0,r.useMemo)(()=>c.reduce((e,t)=>(t.required?e.requiredDocuments.push(t):e.optionalDocuments.push(t),e),{requiredDocuments:[],optionalDocuments:[]}),[c]),{handleSubmit:f,register:p,formState:{isValid:m},watch:h}=(0,E.useForm)({defaultValues:(0,r.useMemo)(()=>c.reduce((e,t)=>(e[t.id]=t.required,e),{}),[c])}),g=h(),_=(0,r.useMemo)(()=>c.filter(e=>g[e.id]),[c,g]),v=c?.length===_.length,y=(0,r.useCallback)(t=>{let n=new Set(Object.entries(t).filter(([e,t])=>t).map(([e])=>e));return e(c.filter(e=>n.has(e.id)))},[c,e]),b=s?`#3a3a3a`:`#eaeaea`,x=s?`#2a2a2a`:`#f5f5f5`,S=s?`gray.300`:`gray.600`,C=s?`0 2px 8px rgba(0, 0, 0, 0.2)`:`0 2px 8px rgba(0, 0, 0, 0.05)`,w=u.length>0,T=d.length>0,D=(0,r.useMemo)(()=>{let e=d.filter(e=>g[e.id]).length;return o(v?`Accept all`:a&&e===0?`Ignore and continue`:w&&!T||w&&e===0?`Accept`:`Accept selected`)},[a,v,d,g]),O=e=>e===u.length-2&&u.length>1?o(` and `):`, `;return(0,i.jsx)(n.Stack,{width:`full`,children:(0,i.jsxs)(`form`,{onSubmit:f(y),children:[(0,i.jsx)(J,{children:(0,i.jsx)(n.ModalHeader,{children:o(`Terms and Policies`)})}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{align:`stretch`,spacing:5,width:`full`,children:[w&&(0,i.jsxs)(n.Text,{as:`span`,fontSize:`sm`,children:[o(`By continuing, you agree to`),` `,u.map((e,t)=>(0,i.jsxs)(r.Fragment,{children:[(0,i.jsx)(Mc,{document:e,register:p,isText:!0},e.id),t<u.length-1?O(t):null]},e.id)),`.`,` `,o(`Please take a moment to review all the policies, with acceptance being mandatory to continue.`)]}),a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:S,mb:3,children:(0,i.jsx)(l.Trans,{i18nKey:`<bold>Your privacy matters.</bold> You’re in control, accept to enable optional features like cookies that help us enhance your experience.`,components:{bold:(0,i.jsx)(n.Text,{as:`span`,fontWeight:`semibold`,color:S})}})}),T&&(0,i.jsxs)(n.Stack,{p:4,borderRadius:`xl`,bg:x,borderWidth:`1px`,borderColor:b,boxShadow:C,spacing:5,children:[(0,i.jsx)(n.Text,{fontSize:`md`,fontWeight:`bold`,color:S,children:o(`Optional`)}),(0,i.jsx)(n.VStack,{align:`stretch`,spacing:4,children:d.map(e=>(0,i.jsx)(Mc,{document:e,register:p},e.id))})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{width:`full`,spacing:3,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,width:`full`,type:`submit`,isDisabled:!m,"data-testid":`accept-tnc-button`,children:D}),!a&&(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:t,"data-testid":`reject-tnc-button`,colorScheme:`red`,children:o(`Reject and logout`)})]})})]})})};var Pc=function(e){return e.REVIEW_DOCUMENTS=`REVIEW_DOCUMENTS`,e.REJECT_DOCUMENTS=`REJECT_DOCUMENTS`,e}(Pc||{});const Fc=({isOpen:e,onAgree:t,handleLogout:a,onlyOptionalDocuments:o})=>{let{t:s}=(0,l.useTranslation)(),{activeStep:c,goToPrevious:u,setActiveStep:d,goToNext:f}=(0,n.useSteps)({index:0,count:Object.keys(Pc).length}),p=()=>{d(0)},m=()=>{f()},h=()=>{a(),p()};return(0,i.jsx)(jc,{isOpen:e,onClose:()=>{},goToPrevious:u,goToNext:f,setActiveStep:d,steps:(0,r.useMemo)(()=>[{key:Pc.REVIEW_DOCUMENTS,content:(0,i.jsx)(Nc,{onAgree:t,onReject:m,onlyOptionalDocuments:o})},{key:Pc.REJECT_DOCUMENTS,content:(0,i.jsx)(Ci,{onDisconnect:h,onBack:u,onClose:u,text:s(`Are you sure you want to reject the policies and disconnect?`),showCloseButton:!1})}],[Nc,Ci,t,h]),disableCloseButton:!0,disableBackButton:!0,isCloseable:!1,closeOnOverlayClick:!1,activeStep:c})},Ic=`vechain-kit-legal-documents`,Lc=`vechain-kit-legal-documents-optional-reject`,Rc=e=>`${e.documentType}-${e.url.replace(/[^\w-]+/g,`-`)}-v${e.version}`,zc=e=>e.map(e=>({...e,id:Rc(e)})),Bc=e=>e.filter(e=>!e.required),Vc=(e,t)=>{let n=Date.now();return e.map(e=>({...e,walletAddress:t,timestamp:n}))},Hc=(0,r.createContext)(void 0),Uc=()=>(0,r.useContext)(Hc)||{hasAgreedToRequiredDocuments:!0,agreements:[],walletAddress:void 0,documents:[],documentsNotAgreed:[]},Wc=({children:e})=>{let{connection:n,account:a,disconnect:o}=X(),{darkMode:s,legalDocuments:c,theme:l}=$(),[u,d]=dc(`vechain-kit-legal-documents`,[]),[f,p]=dc(`vechain-kit-legal-documents-optional-reject`,[]),[m,h]=(0,r.useState)(!1),g=(0,r.useCallback)((e,n)=>f.some(r=>t.O(r.walletAddress,n)&&r.id===e.id),[f]),[_,v]=(0,r.useMemo)(()=>{let e=zc([{items:c?.cookiePolicy||[],type:t.v.COOKIES,source:t._.APPLICATION},{items:c?.privacyPolicy||[],type:t.v.PRIVACY,source:t._.APPLICATION},{items:c?.termsAndConditions||[],type:t.v.TERMS,source:t._.APPLICATION}].flatMap(e=>e.items.map(t=>({...t,documentType:e.type,documentSource:e.source}))));return[e,e.filter(e=>e.required)]},[c]),y=(0,r.useMemo)(()=>a?.address?_.filter(e=>u.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)?!1:!f.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)):[],[_,a?.address,u,f]),b=(0,r.useMemo)(()=>!v.length||!a?.address?!0:v.every(e=>u.some(n=>t.O(n.walletAddress,a.address)&&n.id===e.id)),[v,u,a?.address]),x=(0,r.useMemo)(()=>{if(!a?.address||!y?.length)return!1;let e=Bc(y);return e.length===0?!1:e.some(e=>!g(e,a.address))},[y,a?.address,Bc,g]),S=(0,r.useMemo)(()=>b&&x,[b,x]);(0,r.useMemo)(()=>{let e=new Set(u.map(e=>e.id));return _.some(t=>e.has(t.id))},[_,u]),(0,r.useEffect)(()=>{n.isConnected&&a?.address?h(!b||x):h(!1)},[n.isConnected,a?.address,b,x]);let C=(0,r.useCallback)((e,n)=>{let r=Array.isArray(e)?e:[e];if(!r.length)return;let i=Vc(r,n);d([...u.filter(e=>!t.O(e.walletAddress,n)||!r.some(t=>t.id===e.id)),...i])},[u,Vc]),w=(0,r.useCallback)(e=>{if(!a?.address)return;let t=Bc(y);if(t.length===0)return;let n=e.map(e=>e.id),r=t.filter(e=>!n.includes(e.id));if(!r?.length)return;let i=Vc(r,a.address);p(e=>[...e,...i])},[a?.address,y,Bc,Vc]),T=(0,r.useCallback)(e=>{if(!a?.address)return;let t=Array.isArray(e)?e:[e];t.length>0&&C(t,a.address),w(t),h(!1)},[a?.address,C,w]);return(0,i.jsxs)(Hc.Provider,{value:{hasAgreedToRequiredDocuments:b,agreements:u,walletAddress:a?.address,documents:_,documentsNotAgreed:y},children:[e,(0,i.jsx)(Ya,{darkMode:s,theme:l,children:(0,i.jsx)(Fc,{isOpen:m,onAgree:T,handleLogout:S?()=>{}:()=>{o(),h(!1)},onlyOptionalDocuments:S})})]})},Gc=(0,r.createContext)(null),Kc=({children:e,nodeUrl:n,delegatorUrl:a=t.at(),delegateAllTransactions:o,genericDelegator:s})=>{let{signTypedData:c,exportWallet:l,signMessage:d}=(0,u.usePrivy)(),{signTypedData:f,signMessage:p}=En(),{connection:m,connectedWallet:h}=X(),{network:g}=$(),{data:_}=Os(h?.address??``),{data:v}=hs(_?.address??``,h?.address??``),{data:y}=bs(h?.address??``),{buildClausesWithAuth:b}=sc(),{sendTransactionUsingGenericDelegator:x}=yc(),S=F.ThorClient.at(n),C=async(e,r,i,o)=>{if(!_?.address)throw Error(`Smart account address is not set`);let s=new F.VeChainProvider(S,i??new F.ProviderInternalBaseWallet([{privateKey:Buffer.from(t.B.privateKey.slice(2),`hex`),address:t.B.address}],{gasPayer:{gasPayerServiceUrl:r??a}}),!0),c=o??await s.getSigner(t.B.address),l=F.signerUtils.transactionBodyToTransactionRequestInput(e,t.B.address),u=await c.signTransaction(l),{id:d}=await fetch(`${n}/transactions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({raw:u})}).then(e=>e.json());return d},w=(0,r.useCallback)(async({txClauses:e=[],title:n=`Sign Transaction`,description:r,buttonText:i=`Sign`,delegationUrl:o})=>{if(!_||_&&!_.address||!h||h&&!h.address)throw Error(`Address or embedded wallet is missing`);if(s&&!o)return await x({clauses:e,genericDelegatorUrl:a??``});let c=await b({clauses:e,smartAccount:_,version:y?1:v?.version??3,title:n,description:r,buttonText:i}),l={clauses:c,simulateTransactionOptions:{caller:t.B.address}},u=await S.transactions.simulateTransaction(l.clauses,{...l.simulateTransactionOptions});for(let e=0;e<u.length;e++)if(u[e].reverted)return console.error(`simulatedTx1[i].vmError: ${u[e].vmError}`),u[e].vmError;return await C(await gc(c,S,t.B,!0),o)},[x,s,_,h,a,b,y,v,S]);return(0,i.jsx)(Gc.Provider,{value:{accountFactory:t.vt(g.type).accountFactoryAddress,sendTransaction:w,signMessage:async e=>m.isConnectedWithCrossApp?await p(e):(await d({message:e})).signature,signTypedData:async e=>m.isConnectedWithCrossApp?await f({...e,address:h?.address,types:Object.fromEntries(Object.entries(e.types).map(([e,t])=>[e,[...t]]))}):(await c(e)).signature,exportWallet:l,delegateAllTransactions:o},children:e})},qc=()=>{let e=(0,r.useContext)(Gc);if(!e)throw Error(`usePrivyWalletProvider must be used within a PrivyWalletProvider`);return e},Jc=(0,r.createContext)(null),$=()=>{let e=(0,r.useContext)(Jc);if(!e)throw Error(`useVeChainKitConfig must be used within VeChainKit`);return e},Yc=e=>{let n=[],r={...e};if(r.dappKit||={allowedWallets:[`veworld`]},(r.privy!==void 0||r.loginMethods?.some(e=>e.method===`vechain`||e.method===`ecosystem`))&&(r.feeDelegation?!r.feeDelegation.delegatorUrl&&!r.feeDelegation.genericDelegatorUrl&&(r.feeDelegation.genericDelegatorUrl=t.at()):r.feeDelegation={genericDelegatorUrl:t.at()}),!r.network||!r.network.type)r.network={type:`main`};else{let e=r.network.type;[`main`,`test`,`solo`].includes(e)||n.push(`network.type must be either "main", "test" or "solo"`)}if(r.loginMethods||=[{method:`vechain`,gridColumn:4},{method:`ecosystem`,gridColumn:4},{method:`dappkit`,gridColumn:4}],r.loginMethods&&!r.privy){let e=r.loginMethods.filter(e=>[`email`,`google`,`passkey`,`more`].includes(e.method));e.length>0&&n.push(`Login methods ${e.map(e=>`"${e.method}"`).join(`, `)} require Privy configuration. Please either remove these methods or configure the privy prop.`)}if(r?.legalDocuments&&(r.legalDocuments.termsAndConditions&&r.legalDocuments.termsAndConditions.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.termsAndConditions.url is invalid: ${e.url}`)}),r.legalDocuments.privacyPolicy&&r.legalDocuments.privacyPolicy.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.privacyPolicy.url is invalid: ${e.url}`)}),r.legalDocuments.cookiePolicy&&r.legalDocuments.cookiePolicy.forEach(e=>{t.i(e.url)||n.push(`legalDocuments.cookiePolicy.url is invalid: ${e.url}`)})),n.length>0)throw Error(`VeChainKit Configuration Error:
193
193
  `+n.join(`
194
194
  `));return r},Xc=`vechain_kit_currency`,Zc=e=>{let{children:n,privy:a,feeDelegation:o,dappKit:s,loginModalUI:c,loginMethods:l,darkMode:p=!1,i18n:m,language:h=`en`,network:g,allowCustomTokens:_,legalDocuments:v,defaultCurrency:y=`usd`,theme:b,onLanguageChange:x,onCurrencyChange:S}=Yc(e),C=g?.type??`main`,w=g?.nodeUrl??t.vt(C).nodeUrl,T={...g,type:C,nodeUrl:w},E=s??{allowedWallets:[`veworld`]},[D,O]=(0,r.useState)(()=>typeof window<`u`&&t.lt(`i18nextLng`)||h),[k,A]=(0,r.useState)(()=>{try{return t.lt(Xc)||y}catch{return y}}),j=(0,r.useRef)(!1),M=(0,r.useRef)(!1),N=l,P=(0,r.useMemo)(()=>N?.find(e=>e.method===`ecosystem`)?.allowedApps??t.J.map(e=>e.id),[N]),F,I;a?(F=a.appId,I=a.clientId):(F=`clzdb5k0b02b9qvzjm6jpknsc`,I=`client-WY2oy87y6KNrHFnpXuwVsiFMkwPZKTYpExtjvUQuMbCMF`),(0,r.useEffect)(()=>{oe(U),m&&Object.keys(m).forEach(e=>{U.addResourceBundle(e,`translation`,m[e],!0,!0)});let e=(typeof window<`u`?t.lt(`i18nextLng`):null)||D;e&&U.language!==e&&(j.current=!0,U.changeLanguage(e),e!==D&&O(e),j.current=!1)},[]),(0,r.useEffect)(()=>{let e=typeof window<`u`?t.lt(`i18nextLng`):null;h&&!e&&h!==D&&(j.current=!0,U.changeLanguage(h),O(h),j.current=!1)},[h,D]),(0,r.useEffect)(()=>{let e=e=>{!j.current&&e!==D&&(O(e),x?.(e))};return U.on(`languageChanged`,e),()=>{U.off(`languageChanged`,e)}},[D,x]),(0,r.useEffect)(()=>{let e=t.lt(Xc);y&&!e&&y!==k&&(M.current=!0,A(y),t._t(Xc,y),M.current=!1)},[y,k]),(0,r.useEffect)(()=>{let e=()=>{try{let e=t.lt(Xc);if(e&&e!==k&&!M.current){let t=e;A(t),S?.(t)}}catch{}};e();let n=t=>{t.key===Xc&&t.newValue&&e()};window.addEventListener(`storage`,n);let r=setInterval(e,500);return()=>{window.removeEventListener(`storage`,n),clearInterval(r)}},[k,S]);let L=e=>{j.current=!0,U.changeLanguage(e),O(e),j.current=!1},R=e=>{M.current=!0,A(e),t._t(Xc,e),M.current=!1};(0,r.useEffect)(()=>{t._t(t.tt.NETWORK,C)},[C]);let z=(0,r.useMemo)(()=>_e(ge(p),ve(b,p)),[b,p]),B=(0,r.useMemo)(()=>be(z,p),[z,p]),V=(0,r.useMemo)(()=>xe(z,p),[z,p]);return(0,r.useEffect)(()=>{let e=ye(z.colors.background.card,p),t=ye(z.colors.background.cardElevated,p),n=p?`transparent`:`#ffffff`,r=p?`transparent`:`#ffffff`,i=p?`transparent`:`#ffffff`;Ce(V,z.effects.backdropFilter.modal,e,t,n,r,i,z.colors.border.default)},[V,z.effects.backdropFilter.modal,z.colors.background.card,z.colors.background.cardElevated,z.colors.border.default,p]),(0,r.useEffect)(()=>{Se()},[]),(0,i.jsxs)(Ee,{children:[(0,i.jsx)(d.ReactQueryDevtools,{initialIsOpen:!1}),(0,i.jsx)(Tn,{privyEcosystemAppIDS:P,children:(0,i.jsx)(Jc.Provider,{value:{privy:a,privyEcosystemAppIDS:P,feeDelegation:o,dappKit:E,loginModalUI:c,loginMethods:N,darkMode:p,i18n:m,currentLanguage:D,network:T,allowCustomTokens:_,legalDocuments:v,currentCurrency:k,theme:b,setLanguage:L,setCurrency:R},children:(0,i.jsx)(u.PrivyProvider,{appId:F,clientId:I,config:{loginMethodsAndOrder:{primary:a?.loginMethods.slice(0,4)??[],overflow:a?.loginMethods.slice(4)??[]},externalWallets:{walletConnect:{enabled:!1}},appearance:{theme:p?`dark`:`light`,accentColor:a?.appearance.accentColor??(z.buttons.primaryButton.bg?.startsWith(`#`)?z.buttons.primaryButton.bg:p?`#3182CE`:`#2B6CB0`),loginMessage:a?.appearance.loginMessage,logo:a?.appearance.logo},embeddedWallets:{createOnLogin:a?.embeddedWallets?.createOnLogin??`all-users`},passkeys:{shouldUnlinkOnUnenrollMfa:!1}},children:(0,i.jsx)(f.DAppKitProvider,{node:T.nodeUrl,v2Api:{enabled:E.v2Api?.enabled??!0,external:E.v2Api?.external??!1},i18n:m,language:D,logLevel:E.logLevel,modalParent:E.modalParent,onSourceClick:E.onSourceClick,usePersistence:E.usePersistence??!0,allowedWallets:E.allowedWallets,walletConnectOptions:E.walletConnectOptions,themeMode:p?`DARK`:`LIGHT`,themeVariables:E.themeVariables?{...B,...E.themeVariables}:B,children:(0,i.jsx)(Kc,{nodeUrl:T.nodeUrl,delegatorUrl:o?.delegatorUrl??o?.genericDelegatorUrl,delegateAllTransactions:o?.delegateAllTransactions??!1,genericDelegator:!!(!o?.delegatorUrl&&o?.genericDelegatorUrl),children:(0,i.jsx)(Za,{children:(0,i.jsx)(Wc,{children:n})})})})})})})]})};exports.AccountAvatar=Ec,exports.AccountCustomizationModalProvider=So,exports.AccountDetailsButton=Gr,exports.AccountMainContent=Dr,exports.AccountModal=oa,exports.AccountModalProvider=to,exports.AccountSelector=Kr,exports.ActionButton=Z,exports.AddressDisplay=De,exports.AddressDisplayCard=Cc,exports.AssetButton=Le,exports.AssetsContent=ci,exports.BalanceSection=Jr,exports.BaseModal=Ne,exports.BetterSwapLogo=e.n,exports.BridgeContent=ui,exports.CURRENCY_SYMBOLS=t.S,exports.ChangeCurrencyContent=di,exports.ChooseNameContent=Lr,exports.ChooseNameModalProvider=lo,exports.ChooseNameSearchContent=Vr,exports.ChooseNameSummaryContent=Hr,exports.ColorModeSync=Ja,exports.ConnectModal=sa,exports.ConnectModalProvider=$a,exports.ConnectPopover=la,exports.ConnectionButton=ca,exports.CrossAppConnectionSecurityCard=ni,exports.CustomizationContent=ri,exports.CustomizationSummaryContent=ii,Object.defineProperty(exports,`DAppKitWalletButton`,{enumerable:!0,get:function(){return f.WalletButton}}),exports.DappKitButton=xr,exports.DisconnectConfirmContent=Ci,exports.DomainRequiredAlert=ti,exports.ENS_TEXT_RECORDS=t.x,exports.EcosystemButton=wr,exports.EcosystemModal=ba,exports.EmailLoginButton=hr,exports.ExchangeWarningAlert=ei,exports.ExploreEcosystemModalProvider=go,exports.FAQContent=Wr,exports.FAQModalProvider=bo,exports.FeatureAnnouncementCard=$r,exports.GasFeeSummary=Ac,exports.GasFeeTokenSelector=kc,exports.GasTokenSettingsContent=hi,exports.GitHubLogo=e.w,exports.GoogleLogo=e.T,exports.LanguageSettingsContent=fi,exports.LegalDocumentItem=Mc,exports.LegalDocumentSource=t._,exports.LegalDocumentType=t.v,exports.LegalDocumentsModal=Fc,exports.LegalDocumentsProvider=Wc,exports.LocalStorageKey=cc,exports.LoginLoadingModal=ga,exports.LoginWithGithubButton=_r,exports.LoginWithGoogleButton=gr,exports.MAX_IMAGE_SIZE=Fn,exports.MainContent=Tr,exports.ManageCustomTokenContent=li,exports.ModalBackButton=q,exports.ModalFAQButton=wc,exports.ModalNotificationButton=Oc,exports.ModalProvider=Za,exports.NFTMediaType=t.C,exports.NotificationsModalProvider=vo,exports.PRICE_FEED_IDS=Rt,exports.PasskeyLoginButton=br,exports.PrivyButton=Sr,exports.PrivyLogo=e.i,exports.PrivyWalletProvider=Kc,exports.ProfileContent=oi,exports.ProfileModalProvider=ko,exports.QuickActionsSection=Zr,exports.ReceiveModalProvider=wo,exports.ReceiveTokenContent=Mr,exports.ScrollToTopWrapper=Tc,exports.SelectTokenContent=Or,exports.SendTokenContent=Ar,exports.SendTokenModalProvider=fo,exports.SendTokenSummaryContent=jr,exports.SettingsContent=gi,exports.ShareButtons=Qi,exports.SocialIcons=pa,exports.StickyFooterContainer=Me,exports.StickyHeaderContainer=J,exports.SwapTokenContent=Ir,exports.SwapTokenModalProvider=mo,exports.TermsAndPrivacyContent=Si,Object.defineProperty(exports,`ThorClient`,{enumerable:!0,get:function(){return F.ThorClient}}),exports.TransactionButtonAndStatus=Dc,exports.TransactionModal=ea,exports.TransactionModalContent=$i,exports.TransactionModalProvider=ro,exports.TransactionToast=ha,exports.TransactionToastProvider=ao,exports.TwitterLogo=e.C,exports.UpgradeSmartAccountContent=si,exports.UpgradeSmartAccountModal=Ca,exports.UpgradeSmartAccountModalProvider=Do,exports.VETLogo=e.c,exports.VTHOLogo=e.s,exports.VeBetterIcon=e.l,exports.VeBetterIconDark=e.u,exports.VeBetterIconLight=e.d,exports.VeBetterLogo=e.f,exports.VeBetterLogoDark=e.p,exports.VeBetterLogoLight=e.m,exports.VeChainKitContext=Jc,exports.VeChainKitProvider=Zc,exports.VeChainLoginButton=yr,exports.VeChainWithPrivyLoginButton=vr,exports.VePassportUserStatus=t.w,exports.VeTradeLogo=e.t,exports.VeWorldLogoDark=e.a,exports.VeWorldLogoLight=e.o,exports.VechainEnergy=e.r,exports.VechainIcon=e.h,exports.VechainIconDark=e.g,exports.VechainIconLight=e._,exports.VechainKitThemeProvider=Ya,exports.VechainLogo=e.S,exports.VechainLogoDark=e.x,exports.VechainLogoHorizontalDark=e.y,exports.VechainLogoHorizontalLight=e.v,exports.VechainLogoLight=e.b,exports.VersionFooter=je,exports.WalletButton=fa,exports.WalletModalProvider=so,exports.buildBatchAuthorizationTypedData=ic,exports.buildCallClauses=t.t,exports.buildClauses=yt,exports.buildERC20Clauses=qs,exports.buildSingleAuthorizationTypedData=ac,exports.buildVETClauses=Ys,exports.buildVetDomainClauses=tt,exports.calculateTotalCost=t.y,exports.compressImages=Hn,exports.currentBlockQueryKey=Ls,exports.decodeEventLog=tc,exports.decodeRawTx=vc,exports.delegateAuthorized=hc,exports.estimateAndBuildTxBody=gc,exports.estimateGas=pc,exports.executeCallClause=t.n,exports.executeMultipleClausesCall=t.r,exports.fetchAppHubApps=Uo,exports.fetchPrivyAppInfo=Re,exports.fetchPrivyStatus=Y,exports.formatGasCost=t.b,exports.getAccountAddress=us,exports.getAccountAddressQueryKey=ds,exports.getAccountBalance=ts,exports.getAccountBalanceQueryKey=ns,exports.getAccountImplementationAddress=is,exports.getAccountImplementationAddressQueryKey=as,exports.getAccountVersionQueryKey=ms,exports.getAllEventLogs=Gs,exports.getAppHubAppsQueryKey=Ho,exports.getAvatarLegacy=At,exports.getAvatarLegacyQueryKey=jt,exports.getAvatarOfAddressQueryKey=Et,exports.getAvatarQueryKey=ft,exports.getB3trBalanceQueryKey=nn,exports.getCallClauseQueryKey=Go,exports.getCallClauseQueryKeyWithArgs=qo,exports.getChainId=Bs,exports.getChainIdQueryKey=Vs,exports.getConfig=t.vt,exports.getCurrentAccountImplementationVersion=ss,exports.getCurrentAccountImplementationVersionQueryKey=cs,exports.getCurrentAllocationsRoundIdQueryKey=Xt,exports.getCustomTokenBalanceQueryKey=an,exports.getCustomTokenInfoQueryKey=$t,exports.getDepositAccount=mc,exports.getDomainsOfAddress=lt,exports.getDomainsOfAddressQueryKey=ut,exports.getEnsRecordExistsQueryKey=Ge,exports.getErc20BalanceQueryKey=sn,exports.getEventLogs=Ws,exports.getEventsKey=nc,exports.getHasV1SmartAccount=vs,exports.getHasV1SmartAccountQueryKey=ys,exports.getIpfsImage=In,exports.getIpfsImageQueryKey=Ln,exports.getIpfsMetadata=Mn,exports.getIpfsMetadataQueryKey=Nn,exports.getIsDeployed=xs,exports.getIsDeployedQueryKey=Ss,exports.getIsDomainProtectedQueryKey=rt,exports.getIsPersonQueryKey=dn,exports.getPrivyAppInfoQueryKey=ze,exports.getResolverAddressQueryKey=xt,exports.getRoundXAppsQueryKey=hn,exports.getSmartAccount=Es,exports.getSmartAccountQueryKey=Ds,exports.getTextRecords=ht,exports.getTextRecordsQueryKey=gt,exports.getTokenInfo=Qt,exports.getTokenUsdPrice=zt,exports.getTokenUsdPriceQueryKey=Bt,exports.getUpgradeRequired=ks,exports.getUpgradeRequiredForAccount=Ms,exports.getUpgradeRequiredForAccountQueryKey=Ns,exports.getUpgradeRequiredQueryKey=As,exports.getVechainDomainQueryKey=He,exports.getVot3BalanceQueryKey=ln,exports.getXAppMetadata=kn,exports.getXAppsSharesQueryKey=yn,exports.imageCompressionOptions=Vn,exports.signVip191Transaction=_c,exports.txReceiptQueryKey=$s,exports.useAccountBalance=rs,exports.useAccountCustomizationModal=xo,exports.useAccountImplementationAddress=os,exports.useAccountModal=eo,exports.useAccountModalOptions=kr,exports.useAppHubApps=Wo,exports.useBuildClauses=sc,exports.useBuildTransaction=Zs,exports.useCallClause=Jo,exports.useChooseNameModal=co,exports.useClaimVeWorldSubdomain=Qe,exports.useClaimVetDomain=nt,exports.useConnectModal=Qa,exports.useCrossAppConnectionCache=Fo,exports.useCurrency=Gt,exports.useCurrentAccountImplementationVersion=ls,exports.useCurrentAllocationsRoundId=Zt,exports.useCurrentBlock=zs,exports.useCurrentCurrency=Zo,exports.useCurrentLanguage=Xo,exports.useCustomTokens=tn,Object.defineProperty(exports,`useDAppKitWallet`,{enumerable:!0,get:function(){return f.useWallet}}),Object.defineProperty(exports,`useDAppKitWalletModal`,{enumerable:!0,get:function(){return f.useWalletModal}}),exports.useEcosystemShortcuts=fc,exports.useEnsRecordExists=Ke,exports.useEstimateAllTokens=Sc,exports.useEvents=rc,exports.useExploreEcosystemModal=ho,exports.useFAQModal=yo,exports.useFeatureAnnouncement=Qr,exports.useFetchAppInfo=Be,exports.useFetchPrivyStatus=Ve,exports.useGasTokenSelection=bc,exports.useGenericDelegator=yc,exports.useGenericDelegatorFeeEstimation=xc,exports.useGetAccountAddress=fs,exports.useGetAccountVersion=hs,exports.useGetAvatar=pt,exports.useGetAvatarLegacy=Nt,exports.useGetAvatarOfAddress=Dt,exports.useGetB3trBalance=rn,exports.useGetChainId=Hs,exports.useGetCustomTokenBalances=on,exports.useGetCustomTokenInfo=en,exports.useGetDomainsOfAddress=dt,exports.useGetErc20Balance=cn,exports.useGetNodeUrl=Qo,exports.useGetResolverAddress=St,exports.useGetTextRecords=_t,exports.useGetTokenUsdPrice=Vt,exports.useGetVot3Balance=un,exports.useHasV1SmartAccount=bs,exports.useIpfsImage=Rn,exports.useIpfsImageList=zn,exports.useIpfsMetadata=Pn,exports.useIpfsMetadatas=Bn,exports.useIsDomainProtected=ot,exports.useIsPWA=$o,exports.useIsPerson=fn,exports.useIsSmartAccountDeployed=Cs,exports.useLegalDocuments=Uc,exports.useLocalStorage=lc,exports.useLoginModalContent=To,exports.useLoginWithOAuth=Po,exports.useLoginWithPasskey=Mo,exports.useLoginWithVeChain=Io,Object.defineProperty(exports,`useMfaEnrollment`,{enumerable:!0,get:function(){return u.useMfaEnrollment}}),exports.useModal=Q,exports.useMostVotedAppsInRound=xn,exports.useMultipleClausesCall=Yo,exports.useNotificationAlerts=Mi,exports.useNotifications=Ni,exports.useNotificationsModal=_o,Object.defineProperty(exports,`usePrivy`,{enumerable:!0,get:function(){return u.usePrivy}}),exports.usePrivyWalletProvider=qc,exports.useProfileModal=Oo,exports.useReceiveModal=Co,exports.useRefreshBalances=On,exports.useRefreshFactoryQueries=ws,exports.useRefreshMetadata=qe,exports.useRefreshSmartAccountQueries=Ts,exports.useRoundXApps=gn,exports.useScrollToTop=es,exports.useSendTokenModal=uo,exports.useSendTransaction=Kn,Object.defineProperty(exports,`useSetWalletRecovery`,{enumerable:!0,get:function(){return u.useSetWalletRecovery}}),exports.useSignMessage=Ao,exports.useSignTypedData=jo,exports.useSingleImageUpload=Wn,exports.useSmartAccount=Os,exports.useSwapQuotes=pr,exports.useSwapTokenModal=po,exports.useSwapTransaction=qn,exports.useSyncableLocalStorage=dc,Object.defineProperty(exports,`useThor`,{enumerable:!0,get:function(){return f.useThor}}),exports.useTokenBalances=Lt,exports.useTokenPrices=Ht,exports.useTokensWithValues=Kt,exports.useTotalBalance=qt,exports.useTransactionModal=no,exports.useTransactionToast=io,exports.useTransferERC20=Js,exports.useTransferVET=Xs,exports.useTxReceipt=ec,exports.useUnsetDomain=It,exports.useUpdateTextRecord=bt,exports.useUpgradeRequired=js,exports.useUpgradeRequiredForAccount=Ps,exports.useUpgradeSmartAccount=Is,exports.useUpgradeSmartAccountModal=Eo,exports.useUploadImages=Un,exports.useVeChainKitConfig=$,exports.useVechainDomain=Ue,exports.useVechainKitThemeConfig=qa,exports.useWallet=X,exports.useWalletMetadata=Dn,exports.useWalletModal=oo,exports.useXAppMetadata=jn,exports.useXAppsShares=bn;
195
195
  //# sourceMappingURL=index.cjs.map