@vechain/vechain-kit 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -41
- package/dist/assets/index.d.cts +1 -1
- package/dist/assets/index.d.mts +1 -1
- package/dist/{index-Bekk3wer.d.cts → index-BjQrND59.d.mts} +4 -4
- package/dist/{index-Bekk3wer.d.cts.map → index-BjQrND59.d.mts.map} +1 -1
- package/dist/{index-BvuXDx6d.d.mts → index-C8Uj8ple.d.cts} +4 -4
- package/dist/{index-BvuXDx6d.d.mts.map → index-C8Uj8ple.d.cts.map} +1 -1
- package/dist/{index-DqmXn4Mz.d.mts → index-Gsp1h6d7.d.mts} +51 -51
- package/dist/{index-DqmXn4Mz.d.mts.map → index-Gsp1h6d7.d.mts.map} +1 -1
- package/dist/{index-lFyi52Xi.d.cts → index-aWHEC3vV.d.cts} +51 -51
- package/dist/{index-lFyi52Xi.d.cts.map → index-aWHEC3vV.d.cts.map} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.mts +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -118,7 +118,7 @@ const e=require(`./assets-CZs6EVH8.cjs`),t=require(`./utils-C4gc1L9t.cjs`);let n
|
|
|
118
118
|
opacity: 0.5 !important;
|
|
119
119
|
}
|
|
120
120
|
`),d.length>0&&(u.textContent=d.join(`
|
|
121
|
-
`))}let Le=null;function Re(){return Le||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),Le}const ze=({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:Re(),children:e})},J=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`Back`,icon:(0,i.jsx)(n.Icon,{as:g.LuChevronLeft,fontSize:`20px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,onClick:e,lineHeight:`0`,...t}),Be=({wallet:e,label:a,style:o,showHumanAddress:s=!0,setCurrentContent:c,onLogout:u})=>{let{t:d}=(0,l.useTranslation)(),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useColorModeValue)(`#ebebeb`,`#ffffff0a`),b=(0,n.useColorModeValue)(`#ffffff`,`transparent`),x=async(e,n)=>{await t.ut(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))},S=()=>{c&&(e?.domain?c({type:`choose-name-search`,props:{name:``,setCurrentContent:c,initialContentSource:`profile`}}):c({type:`choose-name`,props:{setCurrentContent:c,initialContentSource:`profile`,onBack:()=>c(`profile`)}}))};return(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,...o,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:v,children:a}),(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[e?.domain&&(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:m?d(`Copied!`):e.domain}),(0,i.jsxs)(n.HStack,{spacing:2,children:[c&&(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuPencil,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:S,"aria-label":`Edit domain`}),(0,i.jsx)(n.IconButton,{icon:m?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:()=>x(e.domain||``,h),"aria-label":`Copy domain`})]})]}),(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuWallet,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:f?d(`Copied!`):s?t.W(e?.address??``,8,7):e?.address}),(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuLogOut,{}),onClick:()=>c?.({type:`disconnect-confirm`,props:{onDisconnect:()=>u?.(),onBack:()=>c?.(`profile`)}}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`}),(0,i.jsx)(n.IconButton,{icon:f?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),onClick:()=>x(e?.address??``,p),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`})]})]})]})]})})};var Ve=`2.10.0`,He={"@adraffy/ens-normalize":`^1.11.0`,"@chakra-ui/react":`^2.8.2`,"@emotion/styled":`^11.14.1`,"@privy-io/cross-app-connect":`0.5.8`,"@privy-io/react-auth":`2.25.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.3.0`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.6.0-rc`,"@wagmi/core":`^2.17.2`,"bignumber.js":`^9.1.2`,"browser-image-compression":`^2.0.2`,dotenv:`^16.4.7`,ethers:`^6.13.5`,"framer-motion":`^11.15.0`,i18next:`^24.2.1`,"i18next-browser-languagedetector":`^8.0.2`,net:`^1.0.2`,process:`^0.11.10`,react:`^18.2.0`,"react-device-detect":`^2.2.3`,"react-hook-form":`^7.54.2`,"react-i18next":`^15.4.0`,"react-icons":`^5.4.0`,"react-qrcode-logo":`^3.0.0`,vaul:`^1.1.2`,viem:`^2.29.3`,wagmi:`^2.15.4`},Ue={"@chakra-ui/react":`^2.8.2`,"@emotion/react":`^11.0.0`,"@emotion/styled":`^11.0.0`,"@tanstack/react-query":`^5.64.2`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const We=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.X,{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/${Ve}`,isExternal:!0,pt:`1px`,children:[`v`,Ve]})]})},Ge=(0,r.createContext)({hasContentBelow:!1}),Ke=()=>(0,r.useContext)(Ge),Y=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(null),l=(0,r.useRef)(!0),{tokens:u}=mc(),d=u?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=e=>{if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t);if(e.overflowY===`auto`||e.overflowY===`scroll`||e.overflow===`auto`||e.overflow===`scroll`)return t;t=t.parentElement}return null},t=([e])=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{if(l.current){l.current=!1,a(!1);return}a(!e.isIntersecting)},50)},n=e(s.current),r={threshold:0};n&&(r.root=n,r.rootMargin=`0px`);let i=new IntersectionObserver(t,r),u=setTimeout(()=>{o.current&&i.observe(o.current)},200);return()=>{clearTimeout(u),c.current&&clearTimeout(c.current),i.disconnect()}},[]),(0,i.jsxs)(Ge.Provider,{value:{hasContentBelow:t},children:[(0,i.jsx)(n.Box,{ref:s,position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?d:`none`,style:{WebkitBackdropFilter:t?d:`none`},zIndex:1e3,boxShadow:t?`0px 2px 4px 1px rgb(0 0 0 / 10%)`:`none`,transition:`box-shadow 0.2s ease-in-out`,children:e}),(0,i.jsx)(`div`,{ref:o,style:{height:`1px`,width:`100%`,pointerEvents:`none`,visibility:`hidden`,marginTop:`-1px`}})]})},qe=({children:e})=>(0,i.jsx)(n.Box,{position:`absolute`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,w:`full`,children:e}),Je=({scrollableContainerRef:e,observerRef:t})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-border`),{tokens:o}=mc(),s=o?.effects?.backdropFilter?.stickyHeader??`blur(20px)`,[c,l]=(0,r.useState)(!1),u=(0,r.useRef)(null),d=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{let n=([e])=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{if(d.current){d.current=!1,l(!1);return}l(!e.isIntersecting)},50)},r={threshold:0};e.current&&(r.root=e.current,r.rootMargin=`0px`);let i=new IntersectionObserver(n,r),a=setTimeout(()=>{t.current&&i.observe(t.current)},200);return()=>{clearTimeout(a),u.current&&clearTimeout(u.current),i.disconnect()}},[e,t]),(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,w:`full`,backdropFilter:c?s:`none`,style:{WebkitBackdropFilter:c?s:`none`},zIndex:999,transition:`backdrop-filter 0.2s ease-in-out`,children:(0,i.jsx)(n.Box,{mx:`auto`,w:`34px`,h:`5px`,bg:a,mt:4,rounded:`full`})})},Ye=({isOpen:e,onClose:t,children:a,ariaTitle:o,ariaDescription:s,isDismissable:c=!0,minHeight:l,maxHeight:u=`68vh`,closeThreshold:d=.5})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-modal`),p=(0,n.useToken)(`colors`,`vechain-kit-overlay`),m=(0,r.useRef)(null),h=(0,r.useRef)(null),{tokens:g}=mc(),v=g?.effects?.backdropFilter?.overlay,y=g?.colors?.border?.modal||`none`;return(0,i.jsx)(_.Drawer.Root,{dismissible:c,shouldScaleBackground:!0,repositionInputs:!1,open:e,closeThreshold:d,onOpenChange:e=>{e||t()},children:(0,i.jsxs)(_.Drawer.Portal,{children:[(0,i.jsx)(_.Drawer.Overlay,{style:{zIndex:100,position:`fixed`,top:0,right:0,bottom:0,left:0,backgroundColor:p,backdropFilter:v,WebkitBackdropFilter:v}}),(0,i.jsxs)(_.Drawer.Content,{"aria-description":s,style:{zIndex:101,backgroundColor:f,borderRadius:`24px 24px 0 0`,border:y,position:`fixed`,bottom:0,left:0,right:0,...l&&{minHeight:l},maxHeight:u,display:`flex`,flexDirection:`column`},children:[(0,i.jsx)(_.Drawer.Title,{style:{position:`absolute`,width:`1px`,height:`1px`,padding:0,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:0},children:o}),(0,i.jsxs)(n.Box,{ref:m,flex:`1`,overflowY:`auto`,sx:{paddingBottom:`max(env(safe-area-inset-bottom), 16px)`},children:[(0,i.jsx)(Je,{scrollableContainerRef:m,observerRef:h}),(0,i.jsx)(`div`,{ref:h,style:{height:`1px`,width:`100%`,visibility:`hidden`,marginTop:`-1px`}}),a]})]})]})})},Xe=({isOpen:e,onClose:t,children:r,size:a=`sm`,isCentered:o=!0,motionPreset:s=`slideInBottom`,closeOnOverlayClick:c=!0,blockScrollOnMount:l=!1,allowExternalFocus:u=!1,backdropFilter:d,isCloseable:f=!0,useBottomSheetOnMobile:p,mobileMinHeight:m,mobileMaxHeight:h=`57vh`,desktopMinHeight:g,desktopMaxHeight:_})=>{let[v]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:y,themeConfig:b,tokens:x}=mc(),S=p??b?.modal?.useBottomSheetOnMobile??!1,C=(0,n.useToken)(`colors`,`vechain-kit-modal`),w=(0,n.useToken)(`colors`,`vechain-kit-overlay`),T=x?.effects?.backdropFilter?.overlay,E=x?.effects?.backdropFilter?.modal,D=d??T??`blur(3px)`,O=v?{minHeight:g,maxHeight:_}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`,minHeight:m,maxHeight:h},k=(0,i.jsxs)(n.Modal,{motionPreset:s,isOpen:e,onClose:t,isCentered:o,size:a,returnFocusOnClose:!1,blockScrollOnMount:l,closeOnOverlayClick:c&&f,preserveScrollBarGap:!0,portalProps:{containerRef:y},trapFocus:!u,autoFocus:!u,variant:`vechainKitBase`,children:[(0,i.jsx)(n.ModalOverlay,{bg:w,backdropFilter:D}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:C,sx:{backdropFilter:E,WebkitBackdropFilter:E},...O,children:r})]});return(0,i.jsx)(i.Fragment,{children:!v&&S?(0,i.jsx)(n.Modal,{isOpen:e,onClose:t,size:a,blockScrollOnMount:!1,trapFocus:!1,children:(0,i.jsx)(Ye,{isOpen:e,onClose:t,ariaTitle:`Dialog`,ariaDescription:`Dialog content area`,isDismissable:f,minHeight:m,maxHeight:h,children:r})}):k})},Ze=async t=>{let n=new URL(`/api/v1/apps/${t}`,e._),r=await fetch(n,{headers:{"privy-app-id":t}});if(!r.ok)throw Error(`Failed to fetch Privy app info`);return r.json()},Qe=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],$e=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:Qe(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>Ze(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.Y.find(e=>e.id===i);return[i,{...e,website:a?.website}]}))},enabled:n.length>0,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},et=async()=>{try{let t=new URL(`summary.json`,e.v),n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch Privy status`);return(await n.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},tt=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:et,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}),nt=e=>[`VECHAIN_KIT_DOMAIN`,e],rt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:nt(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);if(n.type!==`main`&&n.type!==`test`){let n=t.j(e);return{address:n?e:void 0,domain:void 0,isValidAddressOrDomain:n,isPrimaryDomain:!1}}let r=await(0,v.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.j(e);if(!r&&!i)throw Error(`Input must be a valid domain or address`);let a=null,o=null,s=!1;return r?(a=await(0,v.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,v.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,v.isPrimaryDomain)(o,e,{networkUrl:n.nodeUrl}))),{address:a||void 0,domain:o||void 0,isValidAddressOrDomain:r||i,isPrimaryDomain:s}},enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address or domain is required`||e===`input must be a valid domain or address`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},it=async(e,n,r)=>{let i=(0,b.keccak256)((0,b.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,b.keccak256)((0,b.toBytes)(r))])),a=await e.contracts.load(t.xt(n).vetDomainsContractAddress,y.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},at=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],ot=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:at(e),queryFn:()=>it(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})},st=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:Et(e??``,r.type)}),n.invalidateQueries({queryKey:At(e,r.type)}),n.invalidateQueries({queryKey:Bt(t)})])}}},ct=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:nt(t)}),e.invalidateQueries({queryKey:nt(n)}),e.invalidateQueries({queryKey:at(r)}),e.invalidateQueries({queryKey:wt(t,`.vet`)}),e.invalidateQueries({queryKey:wt(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:At(n)})]),await Promise.all([e.refetchQueries({queryKey:nt(t)}),e.refetchQueries({queryKey:nt(n)}),e.refetchQueries({queryKey:wt(t,`.vet`)}),e.refetchQueries({queryKey:wt(t,`.veworld.vet`)}),e.refetchQueries({queryKey:Et(r+`.`+i,a)}),e.refetchQueries({queryKey:At(n)}),e.refetchQueries({queryKey:at(r)}),e.refetchQueries({queryKey:Bt(t)})])},lt=y.VeworldSubdomainClaimer__factory.createInterface(),ut=y.VetDomainsReverseRegistrar__factory.createInterface(),dt=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:ut.getFunction(`setName`)}),r){s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:ut.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.xt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.W(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if(pt(n))s.push({to:t.xt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:lt.encodeFunctionData(`claim`,[e,t.xt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:lt.getFunction(`claim`)}),s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:ut.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},ft=({subdomain:e,domain:n,onSuccess:i,onError:a,alreadyOwned:o=!1})=>{let s=(0,p.useQueryClient)(),{account:c}=X(),{network:l}=$(),{refresh:u}=st(e+`.`+n,c?.address??``),d=(0,r.useCallback)(()=>dt(e,n,o,c,l),[e,n,o,c,l]),f=(0,r.useCallback)(async()=>{let t=`${e}.${n}`;await ct(s,c?.address??``,t,e,n,l.type),u(),i?.()},[i,e,n,s,c,l.type,u]),m=Rr({signerAccountAddress:c?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e}.${n} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:f,onTxFailedOrCancelled:()=>{a?.()}});return{...m,clauses:d,sendTransaction:async()=>m.sendTransaction(d(),t.ct())}},pt=e=>e.endsWith(`veworld.vet`),mt=y.VetDomainsReverseRegistrar__factory.createInterface(),ht=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.xt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:mt.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:mt.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.xt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.W(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},gt=({domain:e,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let{network:o}=$(),s=(0,p.useQueryClient)(),{account:c}=X(),{refresh:l}=st(e,c?.address??``),u=(0,r.useCallback)(()=>ht(e,a,c,o),[e,a,c,o]),d=(0,r.useCallback)(async()=>{await ct(s,c?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,o.type),l(),n?.()},[n,e,s,c,o.type,l]),f=Rr({signerAccountAddress:c?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:d,onTxFailedOrCancelled:i});return{...f,clauses:u,sendTransaction:async()=>f.sendTransaction(u(),t.ct())}},_t=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],vt=s.ABIContract.ofAbi(y.VeworldSubdomainClaimer__factory.abi),yt=async(e,n,r)=>{let i=t.xt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,vt.abi).read.isDomainProtected(r))[0]},bt=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:_t(e),queryFn:()=>yt(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})},xt=x.z.object({name:x.z.string()}),St=x.z.object({domains:x.z.array(xt)}),Ct=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.xt(e).graphQlIndexerUrl,a=`query Registrations {
|
|
121
|
+
`))}let Le=null;function Re(){return Le||=new p.QueryClient({defaultOptions:{queries:{queryKeyHashFn:m.hashFn,retry:0,staleTime:3e4,refetchOnWindowFocus:!0,refetchOnMount:!0,refetchOnReconnect:!0,refetchInterval:!1,refetchIntervalInBackground:!1}}}),Le}const ze=({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:Re(),children:e})},J=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`Back`,icon:(0,i.jsx)(n.Icon,{as:g.LuChevronLeft,fontSize:`20px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,left:`10px`,top:`8px`,onClick:e,lineHeight:`0`,...t}),Be=({wallet:e,label:a,style:o,showHumanAddress:s=!0,setCurrentContent:c,onLogout:u})=>{let{t:d}=(0,l.useTranslation)(),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(!1),_=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),v=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),y=(0,n.useColorModeValue)(`#ebebeb`,`#ffffff0a`),b=(0,n.useColorModeValue)(`#ffffff`,`transparent`),x=async(e,n)=>{await t.ut(e)&&(n(!0),setTimeout(()=>{n(!1)},2e3))},S=()=>{c&&(e?.domain?c({type:`choose-name-search`,props:{name:``,setCurrentContent:c,initialContentSource:`profile`}}):c({type:`choose-name`,props:{setCurrentContent:c,initialContentSource:`profile`,onBack:()=>c(`profile`)}}))};return(0,i.jsx)(n.VStack,{w:`full`,justifyContent:`center`,...o,children:(0,i.jsxs)(n.VStack,{w:`full`,spacing:4,children:[a&&(0,i.jsx)(n.Text,{fontSize:`sm`,color:v,children:a}),(0,i.jsxs)(n.VStack,{spacing:2,w:`full`,children:[e?.domain&&(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuSquareUser,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:m?d(`Copied!`):e.domain}),(0,i.jsxs)(n.HStack,{spacing:2,children:[c&&(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuPencil,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:S,"aria-label":`Edit domain`}),(0,i.jsx)(n.IconButton,{icon:m?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),height:`30px`,borderRadius:`5px`,variant:`vechainKitSecondary`,onClick:()=>x(e.domain||``,h),"aria-label":`Copy domain`})]})]}),(0,i.jsxs)(n.HStack,{w:`full`,spacing:3,px:4,py:2,borderWidth:1,borderColor:y,borderRadius:`md`,bg:b,children:[(0,i.jsx)(n.Icon,{as:g.LuWallet,color:v}),(0,i.jsx)(n.Text,{flex:1,fontSize:`sm`,fontWeight:`700`,color:_,noOfLines:1,children:f?d(`Copied!`):s?t.W(e?.address??``,8,7):e?.address}),(0,i.jsxs)(n.HStack,{spacing:2,children:[(0,i.jsx)(n.IconButton,{icon:(0,i.jsx)(g.LuLogOut,{}),onClick:()=>c?.({type:`disconnect-confirm`,props:{onDisconnect:()=>u?.(),onBack:()=>c?.(`profile`)}}),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`}),(0,i.jsx)(n.IconButton,{icon:f?(0,i.jsx)(g.LuCheck,{}):(0,i.jsx)(g.LuCopy,{}),onClick:()=>x(e?.address??``,p),variant:`vechainKitSecondary`,height:`30px`,w:`30px`,borderRadius:`5px`,"aria-label":`Copy address`})]})]})]})]})})};var Ve=`2.10.1`,He={"@adraffy/ens-normalize":`^1.11.0`,"@chakra-ui/react":`^2.8.2`,"@emotion/styled":`^11.14.1`,"@privy-io/cross-app-connect":`0.5.8`,"@privy-io/react-auth":`2.25.0`,"@solana/web3.js":`^1.98.0`,"@tanstack/react-query":`^5.64.2`,"@tanstack/react-query-devtools":`^5.64.1`,"@vechain/contract-getters":`1.3.0`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"@vechain/picasso":`^2.1.1`,"@vechain/vechain-contract-types":`1.6.0-rc`,"@wagmi/core":`^2.17.2`,"bignumber.js":`^9.1.2`,"browser-image-compression":`^2.0.2`,dotenv:`^16.4.7`,ethers:`^6.13.5`,"framer-motion":`^11.15.0`,i18next:`^24.2.1`,"i18next-browser-languagedetector":`^8.0.2`,net:`^1.0.2`,process:`^0.11.10`,react:`^18.2.0`,"react-device-detect":`^2.2.3`,"react-hook-form":`^7.54.2`,"react-i18next":`^15.4.0`,"react-icons":`^5.4.0`,"react-qrcode-logo":`^3.0.0`,vaul:`^1.1.2`,viem:`^2.29.3`,wagmi:`^2.15.4`},Ue={"@chakra-ui/react":`^2.8.2`,"@emotion/react":`^11.0.0`,"@emotion/styled":`^11.0.0`,"@tanstack/react-query":`^5.64.2`,"@vechain/dapp-kit-react":`2.1.0-rc.5`,"framer-motion":`^11.0.0`,react:`^18.0.0`,"react-dom":`^18.0.0`};const We=({...t})=>{let{darkMode:r}=$();return(0,i.jsxs)(n.HStack,{w:`full`,justifyContent:`center`,alignItems:`center`,spacing:0,...t,children:[(0,i.jsx)(e.X,{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/${Ve}`,isExternal:!0,pt:`1px`,children:[`v`,Ve]})]})},Ge=(0,r.createContext)({hasContentBelow:!1}),Ke=()=>(0,r.useContext)(Ge),Y=({children:e})=>{let[t,a]=(0,r.useState)(!1),o=(0,r.useRef)(null),s=(0,r.useRef)(null),c=(0,r.useRef)(null),l=(0,r.useRef)(!0),{tokens:u}=mc(),d=u?.effects?.backdropFilter?.stickyHeader??`blur(20px)`;return(0,r.useEffect)(()=>{let e=e=>{if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t);if(e.overflowY===`auto`||e.overflowY===`scroll`||e.overflow===`auto`||e.overflow===`scroll`)return t;t=t.parentElement}return null},t=([e])=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{if(l.current){l.current=!1,a(!1);return}a(!e.isIntersecting)},50)},n=e(s.current),r={threshold:0};n&&(r.root=n,r.rootMargin=`0px`);let i=new IntersectionObserver(t,r),u=setTimeout(()=>{o.current&&i.observe(o.current)},200);return()=>{clearTimeout(u),c.current&&clearTimeout(c.current),i.disconnect()}},[]),(0,i.jsxs)(Ge.Provider,{value:{hasContentBelow:t},children:[(0,i.jsx)(n.Box,{ref:s,position:`sticky`,top:`0`,left:`0`,w:`full`,borderRadius:`24px 24px 0px 0px`,backdropFilter:t?d:`none`,style:{WebkitBackdropFilter:t?d:`none`},zIndex:1e3,boxShadow:t?`0px 2px 4px 1px rgb(0 0 0 / 10%)`:`none`,transition:`box-shadow 0.2s ease-in-out`,children:e}),(0,i.jsx)(`div`,{ref:o,style:{height:`1px`,width:`100%`,pointerEvents:`none`,visibility:`hidden`,marginTop:`-1px`}})]})},qe=({children:e})=>(0,i.jsx)(n.Box,{position:`absolute`,bottom:`0`,left:`0`,right:`0`,bg:(0,n.useToken)(`colors`,`vechain-kit-modal`),zIndex:`1000`,p:4,w:`full`,children:e}),Je=({scrollableContainerRef:e,observerRef:t})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-border`),{tokens:o}=mc(),s=o?.effects?.backdropFilter?.stickyHeader??`blur(20px)`,[c,l]=(0,r.useState)(!1),u=(0,r.useRef)(null),d=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{let n=([e])=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{if(d.current){d.current=!1,l(!1);return}l(!e.isIntersecting)},50)},r={threshold:0};e.current&&(r.root=e.current,r.rootMargin=`0px`);let i=new IntersectionObserver(n,r),a=setTimeout(()=>{t.current&&i.observe(t.current)},200);return()=>{clearTimeout(a),u.current&&clearTimeout(u.current),i.disconnect()}},[e,t]),(0,i.jsx)(n.Box,{position:`sticky`,top:`0`,w:`full`,backdropFilter:c?s:`none`,style:{WebkitBackdropFilter:c?s:`none`},zIndex:999,transition:`backdrop-filter 0.2s ease-in-out`,children:(0,i.jsx)(n.Box,{mx:`auto`,w:`34px`,h:`5px`,bg:a,mt:4,rounded:`full`})})},Ye=({isOpen:e,onClose:t,children:a,ariaTitle:o,ariaDescription:s,isDismissable:c=!0,minHeight:l,maxHeight:u=`68vh`,closeThreshold:d=.5})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-modal`),p=(0,n.useToken)(`colors`,`vechain-kit-overlay`),m=(0,r.useRef)(null),h=(0,r.useRef)(null),{tokens:g}=mc(),v=g?.effects?.backdropFilter?.overlay,y=g?.colors?.border?.modal||`none`;return(0,i.jsx)(_.Drawer.Root,{dismissible:c,shouldScaleBackground:!0,repositionInputs:!1,open:e,closeThreshold:d,onOpenChange:e=>{e||t()},children:(0,i.jsxs)(_.Drawer.Portal,{children:[(0,i.jsx)(_.Drawer.Overlay,{style:{zIndex:100,position:`fixed`,top:0,right:0,bottom:0,left:0,backgroundColor:p,backdropFilter:v,WebkitBackdropFilter:v}}),(0,i.jsxs)(_.Drawer.Content,{"aria-description":s,style:{zIndex:101,backgroundColor:f,borderRadius:`24px 24px 0 0`,border:y,position:`fixed`,bottom:0,left:0,right:0,...l&&{minHeight:l},maxHeight:u,display:`flex`,flexDirection:`column`},children:[(0,i.jsx)(_.Drawer.Title,{style:{position:`absolute`,width:`1px`,height:`1px`,padding:0,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:0},children:o}),(0,i.jsxs)(n.Box,{ref:m,flex:`1`,overflowY:`auto`,sx:{paddingBottom:`max(env(safe-area-inset-bottom), 16px)`},children:[(0,i.jsx)(Je,{scrollableContainerRef:m,observerRef:h}),(0,i.jsx)(`div`,{ref:h,style:{height:`1px`,width:`100%`,visibility:`hidden`,marginTop:`-1px`}}),a]})]})]})})},Xe=({isOpen:e,onClose:t,children:r,size:a=`sm`,isCentered:o=!0,motionPreset:s=`slideInBottom`,closeOnOverlayClick:c=!0,blockScrollOnMount:l=!1,allowExternalFocus:u=!1,backdropFilter:d,isCloseable:f=!0,useBottomSheetOnMobile:p,mobileMinHeight:m,mobileMaxHeight:h=`57vh`,desktopMinHeight:g,desktopMaxHeight:_})=>{let[v]=(0,n.useMediaQuery)(`(min-width: 768px)`),{portalRootRef:y,themeConfig:b,tokens:x}=mc(),S=p??b?.modal?.useBottomSheetOnMobile??!1,C=(0,n.useToken)(`colors`,`vechain-kit-modal`),w=(0,n.useToken)(`colors`,`vechain-kit-overlay`),T=x?.effects?.backdropFilter?.overlay,E=x?.effects?.backdropFilter?.modal,D=d??T??`blur(3px)`,O=v?{minHeight:g,maxHeight:_}:{position:`fixed`,bottom:`0`,mb:`0`,maxW:`2xl`,borderRadius:`24px 24px 0px 0px !important`,overflowY:`auto`,overflowX:`hidden`,scrollBehavior:`smooth`,minHeight:m,maxHeight:h},k=(0,i.jsxs)(n.Modal,{motionPreset:s,isOpen:e,onClose:t,isCentered:o,size:a,returnFocusOnClose:!1,blockScrollOnMount:l,closeOnOverlayClick:c&&f,preserveScrollBarGap:!0,portalProps:{containerRef:y},trapFocus:!u,autoFocus:!u,variant:`vechainKitBase`,children:[(0,i.jsx)(n.ModalOverlay,{bg:w,backdropFilter:D}),(0,i.jsx)(n.ModalContent,{role:`dialog`,"aria-modal":!u,bg:C,sx:{backdropFilter:E,WebkitBackdropFilter:E},...O,children:r})]});return(0,i.jsx)(i.Fragment,{children:!v&&S?(0,i.jsx)(n.Modal,{isOpen:e,onClose:t,size:a,blockScrollOnMount:!1,trapFocus:!1,children:(0,i.jsx)(Ye,{isOpen:e,onClose:t,ariaTitle:`Dialog`,ariaDescription:`Dialog content area`,isDismissable:f,minHeight:m,maxHeight:h,children:r})}):k})},Ze=async t=>{let n=new URL(`/api/v1/apps/${t}`,e._),r=await fetch(n,{headers:{"privy-app-id":t}});if(!r.ok)throw Error(`Failed to fetch Privy app info`);return r.json()},Qe=e=>[`VECHAIN_KIT_PRIVY_APP_INFO`,...Array.isArray(e)?e:[e]],$e=e=>{let n=Array.isArray(e)?e:[e];return(0,p.useQuery)({queryKey:Qe(e),queryFn:async()=>{let e=await Promise.all(n.map(e=>Ze(e)));return Object.fromEntries(e.map((e,r)=>{let i=n[r],a=t.Y.find(e=>e.id===i);return[i,{...e,website:a?.website}]}))},enabled:n.length>0,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`))return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},et=async()=>{try{let t=new URL(`summary.json`,e.v),n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch Privy status`);return(await n.json()).page.status??`No data`}catch(e){return console.error(`Error fetching data:`,e),`Error fetching data`}},tt=()=>(0,p.useQuery)({queryKey:[`PRIVY_STATUS`],queryFn:et,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}),nt=e=>[`VECHAIN_KIT_DOMAIN`,e],rt=e=>{let{network:n}=$();return(0,p.useQuery)({queryKey:nt(e),queryFn:async()=>{if(!e)throw Error(`Address or domain is required`);if(n.type!==`main`&&n.type!==`test`){let n=t.j(e);return{address:n?e:void 0,domain:void 0,isValidAddressOrDomain:n,isPrimaryDomain:!1}}let r=await(0,v.isValidDomain)(e,{networkUrl:n.nodeUrl}),i=t.j(e);if(!r&&!i)throw Error(`Input must be a valid domain or address`);let a=null,o=null,s=!1;return r?(a=await(0,v.getDomainAddress)(e,{networkUrl:n.nodeUrl}),o=e,a&&(s=await(0,v.isPrimaryDomain)(e,a,{networkUrl:n.nodeUrl}))):(o=await(0,v.getAddressDomain)(e,{networkUrl:n.nodeUrl}),a=e,o&&(s=await(0,v.isPrimaryDomain)(o,e,{networkUrl:n.nodeUrl}))),{address:a||void 0,domain:o||void 0,isValidAddressOrDomain:r||i,isPrimaryDomain:s}},enabled:!!e&&!!n.type,retry:(e,t)=>{if(t instanceof Error){let e=t.message.toLowerCase();if(e.includes(`cancel`)||e.includes(`abort`)||e===`address or domain is required`||e===`input must be a valid domain or address`)return!1}return e<2},gcTime:1e3*60*5,staleTime:1e3*60})},it=async(e,n,r)=>{let i=(0,b.keccak256)((0,b.concat)([`0x571e15b4bbf879cf28e5075190137be8e18500e3d38543bf0cbcdb54e00b02cc`,(0,b.keccak256)((0,b.toBytes)(r))])),a=await e.contracts.load(t.xt(n).vetDomainsContractAddress,y.VetDomainsRegistry__factory.abi).read.recordExists(i);if(!a)throw Error(`Failed to get ENS record exists for ${r}`);return a[0]},at=e=>[`VECHAIN_KIT_ENS_RECORD_VE_WORLD_EXISTS`,e],ot=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:at(e),queryFn:()=>it(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})},st=(e,t)=>{let n=(0,p.useQueryClient)(),{network:r}=$();return{refresh:async()=>{await Promise.all([n.invalidateQueries({queryKey:Et(e??``,r.type)}),n.invalidateQueries({queryKey:At(e,r.type)}),n.invalidateQueries({queryKey:Bt(t)})])}}},ct=async(e,t,n,r,i,a)=>{await Promise.all([e.invalidateQueries({queryKey:nt(t)}),e.invalidateQueries({queryKey:nt(n)}),e.invalidateQueries({queryKey:at(r)}),e.invalidateQueries({queryKey:wt(t,`.vet`)}),e.invalidateQueries({queryKey:wt(t,`.veworld.vet`)}),e.invalidateQueries({queryKey:At(n)})]),await Promise.all([e.refetchQueries({queryKey:nt(t)}),e.refetchQueries({queryKey:nt(n)}),e.refetchQueries({queryKey:wt(t,`.vet`)}),e.refetchQueries({queryKey:wt(t,`.veworld.vet`)}),e.refetchQueries({queryKey:Et(r+`.`+i,a)}),e.refetchQueries({queryKey:At(n)}),e.refetchQueries({queryKey:at(r)}),e.refetchQueries({queryKey:Bt(t)})])},lt=y.VeworldSubdomainClaimer__factory.createInterface(),ut=y.VetDomainsReverseRegistrar__factory.createInterface(),dt=(e,n,r,i,a)=>{let s=[];if(!e)throw Error(`Invalid subdomain`);let c=`${e}.${n}`;if(s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[``]),comment:`Unsetting your current VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:ut.getFunction(`setName`)}),r){s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[c]),comment:`Setting your VeChain nickname to ${c}`,abi:ut.getFunction(`setName`)});let e=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),n=o.ethers.namehash(c);s.push({to:t.xt(a.type).vetDomainsPublicResolverAddress,value:`0x0`,data:e.encodeFunctionData(`setAddr`,[n,i?.address||``]),comment:`Setting the address for ${c} to ${t.W(i?.address??``,4,4)}`,abi:e.getFunction(`setAddr`)})}else if(pt(n))s.push({to:t.xt(a.type).veWorldSubdomainClaimerContractAddress,value:`0x0`,data:lt.encodeFunctionData(`claim`,[e,t.xt(a.type).vetDomainsPublicResolverAddress]),comment:`Claim VeChain subdomain: ${e}.${n}`,abi:lt.getFunction(`claim`)}),s.push({to:t.xt(a.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:ut.encodeFunctionData(`setName`,[e+`.`+n]),comment:`Set ${e}.${n} as the VeChain nickname of the account ${t.W(i?.address??``,4,4)}`,abi:ut.getFunction(`setName`)});else throw Error(`This hook only supports .veworld.vet subdomains`);return s},ft=({subdomain:e,domain:n,onSuccess:i,onError:a,alreadyOwned:o=!1})=>{let s=(0,p.useQueryClient)(),{account:c}=X(),{network:l}=$(),{refresh:u}=st(e+`.`+n,c?.address??``),d=(0,r.useCallback)(()=>dt(e,n,o,c,l),[e,n,o,c,l]),f=(0,r.useCallback)(async()=>{let t=`${e}.${n}`;await ct(s,c?.address??``,t,e,n,l.type),u(),i?.()},[i,e,n,s,c,l.type,u]),m=Rr({signerAccountAddress:c?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e}.${n} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:f,onTxFailedOrCancelled:()=>{a?.()}});return{...m,clauses:d,sendTransaction:async()=>m.sendTransaction(d(),t.ct())}},pt=e=>e.endsWith(`veworld.vet`),mt=y.VetDomainsReverseRegistrar__factory.createInterface(),ht=(e,n,r,i)=>{let a=[];if(!e)throw Error(`Invalid domain`);if(n){a.push({to:t.xt(i.type).vetDomainsReverseRegistrarAddress,value:`0x0`,data:mt.encodeFunctionData(`setName`,[e]),comment:`Setting your VeChain nickname to ${e}`,abi:mt.getFunction(`setName`)});let n=new o.ethers.Interface([`function setAddr(bytes32 node, address addr)`]),s=o.ethers.namehash(e);a.push({to:t.xt(i.type).vetDomainsPublicResolverAddress,value:`0x0`,data:n.encodeFunctionData(`setAddr`,[s,r?.address||``]),comment:`Setting the address for ${e} to ${t.W(r?.address??``,4,4)}`,abi:n.getFunction(`setAddr`)})}else throw Error(`Primary .vet domains are not supported yet`);return a},gt=({domain:e,onSuccess:n,onError:i,alreadyOwned:a=!1})=>{let{network:o}=$(),s=(0,p.useQueryClient)(),{account:c}=X(),{refresh:l}=st(e,c?.address??``),u=(0,r.useCallback)(()=>ht(e,a,c,o),[e,a,c,o]),d=(0,r.useCallback)(async()=>{await ct(s,c?.address??``,e,``,e.endsWith(`.vet`)?e:`${e}.vet`,o.type),l(),n?.()},[n,e,s,c,o.type,l]),f=Rr({signerAccountAddress:c?.address??``,privyUIOptions:{title:`Sign to claim your VeChain nickname`,description:`Claim ${e} as your VeChain nickname`,buttonText:`Sign to continue`},onTxConfirmed:d,onTxFailedOrCancelled:i});return{...f,clauses:u,sendTransaction:async()=>f.sendTransaction(u(),t.ct())}},_t=e=>[`VECHAIN_KIT_DOMAIN`,e,`IS_DOMAIN_PROTECTED`],vt=s.ABIContract.ofAbi(y.VeworldSubdomainClaimer__factory.abi),yt=async(e,n,r)=>{let i=t.xt(n).veWorldSubdomainClaimerContractAddress;return(await e.contracts.load(i,vt.abi).read.isDomainProtected(r))[0]},bt=(e,t=!0)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:_t(e),queryFn:()=>yt(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})},xt=x.z.object({name:x.z.string()}),St=x.z.object({domains:x.z.array(xt)}),Ct=async(e,n,r)=>{if(!n)throw Error(`Address is required`);let i=t.xt(e).graphQlIndexerUrl,a=`query Registrations {
|
|
122
122
|
domains(
|
|
123
123
|
where: ${r?`{owner: "${n.toLowerCase()}", parent_: {name: "${r}"}}`:`{owner: "${n.toLowerCase()}"}`}
|
|
124
124
|
) {
|
|
@@ -203,7 +203,7 @@ const e=require(`./assets-CZs6EVH8.cjs`),t=require(`./utils-C4gc1L9t.cjs`);let n
|
|
|
203
203
|
font-family: ${t} !important;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
`}),fc=({children:e,theme:t,bodyFont:a,headingFont:o,colorModeManager:s})=>(0,i.jsxs)(D.CacheProvider,{value:(0,r.useMemo)(()=>uc(),[]),children:[(0,i.jsx)(dc,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,colorModeManager:s,children:e})]}),pc=(0,r.createContext)({portalRootRef:void 0,tokens:void 0,themeConfig:void 0}),mc=()=>{let e=(0,r.useContext)(pc);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},hc=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(Bd),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>Ae(ke(t),je(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...cc(t,l),config:{...cc(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]),f=(0,r.useMemo)(()=>({type:`localStorage`,ssr:!1,get:()=>t?`dark`:`light`,set:()=>{}}),[t]);return(0,i.jsxs)(pc.Provider,{value:{portalRootRef:o,tokens:u,themeConfig:l},children:[(0,i.jsx)(fc,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,colorModeManager:f,children:(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})}),(0,i.jsx)(lc,{})]})},gc=(0,r.createContext)(null),_c=()=>{let e=(0,r.useContext)(gc);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},vc=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),[c,l]=(0,r.useState)(`main`),[u,d]=(0,r.useState)(!1),{setSource:p,connectV2:m}=(0,f.useWallet)(),h=(0,r.useCallback)((e,n)=>{t.ht()&&window.vechain&&window.vechain.isInAppBrowser?(p(`veworld`),m(null)):(l(e??`main`),d(n??!1),s(!0))},[]),g=(0,r.useCallback)(()=>{s(!1),l(`main`),d(!1)},[]),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(`main`),C=(0,r.useCallback)((e,t)=>{S(e??`main`),b(t?.isolatedView??!1),v(!0)},[]),w=(0,r.useCallback)(()=>{v(!1),S(`main`),setTimeout(()=>{b(!1)},300)},[]),[T,E]=(0,r.useState)(!1),D=(0,r.useCallback)(()=>E(!0),[]),O=(0,r.useCallback)(()=>E(!1),[]),[k,A]=(0,r.useState)(!1),j=(0,r.useCallback)(()=>A(!0),[]),M=(0,r.useCallback)(()=>A(!1),[]),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(void 0),L=(0,r.useCallback)(e=>{I(e),P(!0)},[]),R=(0,r.useCallback)(()=>P(!1),[]);return(0,i.jsxs)(gc.Provider,{value:{openConnectModal:h,closeConnectModal:g,isConnectModalOpen:o,connectModalContent:c,setConnectModalContent:l,connectModalPreventAutoClose:u,setConnectModalPreventAutoClose:d,openAccountModal:C,closeAccountModal:w,isAccountModalOpen:_,setAccountModalContent:S,accountModalContent:x,isolatedView:y,openTransactionModal:D,closeTransactionModal:O,isTransactionModalOpen:T,openTransactionToast:j,closeTransactionToast:M,isTransactionToastOpen:k,openUpgradeSmartAccountModal:L,closeUpgradeSmartAccountModal:R,isUpgradeSmartAccountModalOpen:N},children:[e,(0,i.jsxs)(hc,{darkMode:n,theme:a,children:[(0,i.jsx)(Cs,{isOpen:o,onClose:g,initialContent:c,preventAutoClose:u}),(0,i.jsx)(us,{isOpen:_,onClose:w,initialContent:x}),(0,i.jsx)(Fs,{isOpen:N,onClose:R,style:F})]})]})},yc=()=>{let{loginMethods:e}=$(),t=e?.length===1&&e[0].method===`dappkit`,{openConnectModal:n,closeConnectModal:r,isConnectModalOpen:i}=_c(),{open:a,close:o}=(0,f.useWalletModal)();return{open:t?a:e=>n(e),close:t?o:r,isOpen:t?!1:i}},bc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:()=>e(),close:t,isOpen:n}},Sc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Cc=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=_c();return{open:e,close:t,isOpen:n}},wc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Tc=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=_c();return{open:e,close:t,isOpen:n}},Ec=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Dc=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=_c();return{open:n=>{e.isConnected?i(void 0,n):t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},Oc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),kc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},Ac=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),jc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`send-token`,props:{setCurrentContent:r}},t)},close:()=>{t()},isOpen:n}},Mc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Nc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},Pc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Fc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},Ic=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Lc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},Rc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),zc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`faq`,props:{onGoBack:()=>r(`main`),showLanguageSelector:!1}},t)},close:()=>{t()},isOpen:n}},Bc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Vc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`account-customization`,t)},close:()=>{t()},isOpen:n}},Hc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Uc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},Wc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Gc=()=>{let{privy:e,loginMethods:n,dappKit:i}=$(),a=e?.appId===t.at,o=i?.allowedWallets,s=e=>n?Array.isArray(e)?e.some(e=>n.some(t=>t.method===e)):n.some(t=>t.method===e):!0,c=(0,r.useMemo)(()=>n?n.length===0||s(`ecosystem`):!0,[n]),l=(0,r.useMemo)(()=>s(`vechain`),[n]),u=(0,r.useMemo)(()=>s(`dappkit`),[n]),d=(0,r.useMemo)(()=>s(`passkey`),[n]),f=(0,r.useMemo)(()=>s(`email`),[n]),p=(0,r.useMemo)(()=>s(`google`),[n]),m=(0,r.useMemo)(()=>s(`apple`),[n]),h=(0,r.useMemo)(()=>s(`more`),[n]),g=(0,r.useMemo)(()=>s(`github`),[n]),_={showGoogleLogin:p,showAppleLogin:m,showEmailLogin:f,showPasskey:d,showVeChainLogin:l,showDappKit:u,showVeWorld:(0,r.useMemo)(()=>s(`veworld`)?o?o.includes(`veworld`):!0:!1,[n,o]),showSync2:(0,r.useMemo)(()=>s(`sync2`)?o?o.includes(`sync2`):!0:!1,[n,o]),showWalletConnect:(0,r.useMemo)(()=>s(`wallet-connect`)?o?o.includes(`wallet-connect`):!0:!1,[n,o]),showEcosystem:c,showMoreLogin:h,showGithubLogin:g,isOfficialVeChainApp:!1};return e?a?{..._,isOfficialVeChainApp:!0}:{..._}:{..._,showEmailLogin:!1,showPasskey:!1}},Kc=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=_c();return{open:()=>t(e),close:n,isOpen:r}},qc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Jc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},Yc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Xc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`settings`,t)},close:()=>{t()},isOpen:n}},Zc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Qc=()=>{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=zd();return{signMessage:(0,r.useCallback)(async e=>{if(!c)throw Error(`Account not found`);t(!0),o(null),i(null);try{let t=null;return t=s.isConnectedWithDappKit?(await l({purpose:`agreement`,payload:{type:`text`,content:e}},{signer:c.address})).signature:await u.signMessage(e),i(t),t}catch(e){let t=e instanceof Error?e:Error(String(e));throw o(t),t}finally{t(!1)}},[s,u,c?.address]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},$c=()=>{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=zd();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)},[])}},el=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}},tl=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t.bt(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.ft(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t._t(e)},[])}},nl=()=>{let{login:n}=_r(),{setConnectionCache:r}=tl(),{data:i}=$e([t.at]);return{login:async a=>{try{await n(t.at,a),r({name:`VeChain`,logoUrl:i?.[t.at]?.logo_url,appId:t.at,website:e.x})}catch(e){throw ur({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.`})}}}};let rl=!1;const il=new Set([`google`,`apple`,`twitter`,`discord`,`github`,`tiktok`,`line`]),al=()=>{let{privy:e}=$(),{createWallet:t}=(0,u.useCreateWallet)(),{login:n}=nl(),{initOAuth:i}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:e})=>{if(e&&!rl){rl=!0;try{await t()}catch(e){throw rl=!1,console.error(`Failed to create wallet:`,e),e}}},[t])});return{initOAuth:async({provider:t})=>{if(!e){if(il.has(t)){await n({intent:t});return}throw Error(`OAuth provider "${t}" requires a Privy configuration. Supported without Privy via the VeChain whitelabel host: ${[...il].join(`, `)}.`)}await i({provider:t})}}},ol={veworld:`VeWorld`,sync2:`Sync2`,sync:`Sync`,"wallet-connect":`WalletConnect`},sl=`https://www.veworld.com/discover/browser/ul/`,cl=e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;if(e&&typeof e==`object`){let t=e;if(typeof t.message==`string`)return t.message;if(typeof t.reason==`string`)return t.reason;try{return JSON.stringify(e)}catch{return``}}return``},ll=(e,n)=>{let{t:i}=(0,l.useTranslation)(),{setSource:a,connect:o}=(0,f.useWallet)(),s=(0,r.useCallback)(async()=>{let r=ol[e]??e,c=()=>{s()};if(e===`veworld`&&typeof window<`u`&&!window.vechain){window.open(`https://www.veworld.com/discover/browser/ul/${encodeURIComponent(window.location.href)}`,`_self`);return}n({type:`loading`,props:{title:`${i(`Connecting with`)} ${r}`,loadingText:i(e===`wallet-connect`?`Scan the QR code with your wallet to continue.`:`Open your wallet and confirm the connection request.`),onTryAgain:c}});try{a(e),await o()}catch(e){let r=cl(e);if(t.a(r)){n(`main`);return}n({type:`error`,props:{error:r||i(`Failed to connect, please try again later.`),onTryAgain:c}})}},[e,a,o,n,i]);return{connect:s}},ul=`vechain-kit-app-hub-apps`,dl=`vechain-kit-app-hub-apps-expiry`,fl=1440*60*1e3,pl=()=>[`VECHAIN_KIT`,`appHub`,`apps`],ml=async()=>{if(typeof window<`u`)try{let e=t.ft(ul),n=t.ft(dl);if(e&&n){let t=parseInt(n,10);if(Date.now()<t)return JSON.parse(e)}}catch{console.warn(`Invalid app-hub cache, fetching fresh data`)}let n=new URL(`contents/apps`,e.a),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch app directories`);let i=(await r.json()).map(async t=>{if(t.type!==`dir`)return null;let n=new URL(`master/apps/${t.name}/manifest.json`,e.o),r=await fetch(n);if(!r.ok)return console.warn(`Failed to fetch manifest for ${t.name}`),null;try{let n=await r.json(),i=new URL(`master/apps/${t.name}/logo.png`,e.o);return{id:t.name,name:n.name,description:n.desc,url:n.href,logo:i.toString(),category:n.category,tags:n.tags||[],isVeWorldSupported:n.isVeWorldSupported||!1,repo:n.repo,contracts:n.contracts,veBetterDaoId:n.veBetterDaoId}}catch(e){return console.warn(`Error parsing manifest for ${t.name}:`,e),null}}),a=(await Promise.all(i)).filter(e=>e!==null);if(typeof window<`u`)try{t.bt(ul,JSON.stringify(a)),t.bt(dl,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return a},hl=()=>(0,p.useQuery)({queryKey:pl(),queryFn:async()=>{try{return await ml()}catch(e){let t=localStorage.getItem(ul);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),gl=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},_l=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},vl=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.ft(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t.bt(i,`true`),n(!1)}}},yl=()=>{let{network:e}=$();return e.nodeUrl??t.xt(e.type).nodeUrl},bl=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.ht()){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},xl=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},Sl=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,b.formatEther)(BigInt(n.balance)).toString(),energy:(0,b.formatEther)(BigInt(n.energy)).toString()}},Cl=e=>B.balance.native(e),wl=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:Cl(e),queryFn:()=>Sl(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},Tl=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.xt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi),a;switch(n){case 1:case 2:a=i.read.accountImplementationV1();break;case 3:a=i.read.accountImplementationV3();break;default:throw Error(`Invalid version, must be between 1 and 3`)}let o=await a;if(!o)throw Error(`Failed to get account implementation address`);return o[0].toString()},El=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],Dl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:El(e,n.type),queryFn:async()=>Tl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Ol=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.xt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},kl=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],Al=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:kl(t.type),queryFn:async()=>Ol(e,t.type),enabled:!!e&&!!t})},jl=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.xt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},Ml=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],Nl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ml(e,n.type),queryFn:async()=>jl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Pl=y.SocialLoginSmartAccountFactory__factory.abi,Fl=(e,n,r)=>bi({abi:Pl,address:t.xt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),Il=(e,n)=>{let{network:r}=$();return xi({address:t.xt(r.type).accountFactoryAddress,abi:Pl,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]}),enabled:!!e&&!!n}})},Ll=y.SocialLoginSmartAccountFactory__factory.abi,Rl=`hasLegacyAccount`,zl=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:Ll,contractAddress:t.xt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},Bl=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],Vl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Bl(e,n.type),queryFn:async()=>zl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Hl=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},Ul=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Wl=e=>{let t=yl(),n=R.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ul(e),queryFn:async()=>Hl(n,e),enabled:!!n&&!!e})},Gl=()=>{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:Ml(i,r.type)}),e.cancelQueries({queryKey:Fl(a,i,r.type)}),e.cancelQueries({queryKey:Bl(i,r.type)}),e.cancelQueries({queryKey:kl(r.type)}),e.cancelQueries({queryKey:Zl(a,i,3,r.type)}),e.cancelQueries({queryKey:eu(a,3,r.type)}),e.cancelQueries({queryKey:El(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:Ml(i,r.type)}),e.refetchQueries({queryKey:Fl(a,i,r.type)}),e.refetchQueries({queryKey:Bl(i,r.type)}),e.refetchQueries({queryKey:kl(r.type)}),e.refetchQueries({queryKey:Zl(a,i,3,r.type)}),e.refetchQueries({queryKey:eu(a,3,r.type)}),e.refetchQueries({queryKey:El(3,r.type)})])}}},Kl=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Jl(n)}),e.cancelQueries({queryKey:Ul(n)})]),await Promise.all([e.refetchQueries({queryKey:Jl(n)}),e.refetchQueries({queryKey:Ul(n)})])}}},ql=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.xt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(r);if(!i)throw Error(`Failed to get account address of ${r}`);let a=s.Address.of(i[0].toString()),o=await e.accounts.getAccount(a);if(!o)throw Error(`Failed to get account detail of ${a}`);return{address:a.toString(),isDeployed:o.hasCode}},Jl=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Yl=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Jl(e),queryFn:()=>ql(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},Xl=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.xt(a).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.xt(a).accountFactoryAddress}`);return o[0]},Zl=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],Ql=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:Zl(e,t,n,i.type),queryFn:async()=>Xl(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},$l=async(e,n,r,i)=>{let a=await e.contracts.load(t.xt(i).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},eu=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],tu=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:eu(e,t,r.type),queryFn:async()=>$l(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},nu=y.SocialLoginSmartAccount__factory.createInterface(),ru=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=Gl(),{refresh:s}=Kl(),{data:c}=Dl(n),l=(0,r.useCallback)(async()=>{if(!e||!t.j(e))throw Error(`Invalid smart account address`);if(!c)throw Error(`Unable to fetch implementation address for version ${n}`);return[{to:e,value:`0x0`,data:nu.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:nu.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=Rr({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.W(e)} to version ${n}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{await Promise.all([o(),s()]),i?.()},onTxFailedOrCancelled:async()=>{a?.()}});return{...u,sendTransaction:async()=>u.sendTransaction(await l())}},iu=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],au=10*t.s.SECOND,ou=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:iu(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:au})},su=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},cu=()=>[`VECHAIN_KIT_CHAIN_ID`],lu=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:cu(),queryFn:()=>su(e),enabled:!!e})},uu=y.IERC20__factory.createInterface(),du=(e,n,r,i,a)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);let o=[];return o.push({to:r,value:`0x0`,data:uu.encodeFunctionData(`transfer`,[e,(0,b.parseUnits)(n,a)]),comment:`Transfer ${n} ${i} to ${e}`,abi:uu.getFunction(`transfer`)}),o},fu=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,tokenDecimals:s,onSuccess:c,onError:l})=>{let{refresh:u}=lr(),{data:d,isLoading:f,error:p}=An(s===void 0?a:``),m=(0,r.useMemo)(()=>{let e=s??d?.decimals;if(e==null)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0},[s,d?.decimals]),h=(0,r.useMemo)(()=>m===void 0?[]:du(n,i,a,o,m),[n,i,a,o,m]),g=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{u(),c?.()},onTxFailedOrCancelled:async e=>{l?.(e instanceof Error?e.message:String(e))}});return{...g,clauses:h,isLoadingTokenInfo:f,sendTransaction:async()=>{if(m===void 0){let e=p?`Failed to load token info: ${p.message}`:`Token decimals are required`;l?.(e);return}return g.sendTransaction(h)}}},pu=new o.Interface([`function safeTransferFrom(address from, address to, uint256 tokenId)`]),mu=(e,n,r,i,a)=>{if(!n||!t.j(n)||!e||!t.j(e)||!r||!t.j(r)||i===``)throw Error(`Invalid transfer parameters`);let o=pu.getFunction(`safeTransferFrom`);if(!o)throw Error(`safeTransferFrom not found in ERC721 interface`);return[{to:r,value:`0x0`,data:pu.encodeFunctionData(`safeTransferFrom`,[e,n,BigInt(i)]),comment:`Transfer ${a??`NFT`} #${i} to ${n}`,abi:o}]},hu=({fromAddress:e,receiverAddress:n,collectionAddress:i,tokenId:a,collectionName:o,onSuccess:s,onError:c})=>{let{refresh:l}=lr(),u=(0,p.useQueryClient)(),{network:d}=$(),f=(0,r.useMemo)(()=>{try{return mu(e,n,i,a,o)}catch{return[]}},[e,n,i,a,o]),m=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm NFT Transfer`,description:`Transfer ${o??`NFT`} #${a} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{l(),await u.invalidateQueries({queryKey:fi(e,d.type)}),s?.()},onTxFailedOrCancelled:async e=>{c?.(e instanceof Error?e.message:String(e))}});return{...m,clauses:f,sendTransaction:async()=>{if(!f.length){c?.(`Invalid transfer parameters`);return}return m.sendTransaction(f)}}},gu=(e,n)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);if(isNaN(Number(n)))throw Error(`Invalid amount`);let r=[];try{r.push({to:e,value:(0,b.parseEther)(n).toString(),data:`0x`,comment:`Transfer ${n} VET to ${e}`})}catch(e){throw console.error(`Error building clauses:`,e),Error(`Invalid amount format`)}return r},_u=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=lr(),c=(0,r.useMemo)(()=>gu(n,i),[n,i]),l=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{s(),a?.()},onTxFailedOrCancelled:async e=>{o?.(e instanceof Error?e.message:String(e))}});return{...l,clauses:c,sendTransaction:async()=>l.sendTransaction(c)}},vu=({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=Rr({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}},yu=10*t.s.SECOND,bu=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],xu=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:bu(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*yu,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},Su=(e,t)=>{let n=(0,b.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},Cu=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],wu=({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 an({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=>Su(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)(()=>Cu({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function Tu({clauses:e,chainId:t,verifyingContract:n}){let r=[],i=[],a=[];return e.forEach(e=>{r.push(e.to??``),i.push(String(e.value)),typeof e.data==`object`&&`abi`in e.data?a.push((0,b.encodeFunctionData)(e.data)):a.push(e.data||`0x`)}),{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n},types:{ExecuteBatchWithAuthorization:[{name:`to`,type:`address[]`},{name:`value`,type:`uint256[]`},{name:`data`,type:`bytes[]`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`},{name:`nonce`,type:`bytes32`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteBatchWithAuthorization`,message:{to:r,value:i,data:a,validAfter:0,validBefore:Math.floor(Date.now()/1e3)+300,nonce:o.ethers.hexlify(o.ethers.randomBytes(32))}}}function Eu({clause:e,chainId:t,smartAccount:n}){return{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n.address??``},types:{ExecuteWithAuthorization:[{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`data`,type:`bytes`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteWithAuthorization`,message:{validAfter:0,validBefore:Math.floor(Date.now()/1e3)+60,to:e.to,value:String(e.value),data:(typeof e.data==`object`&&`abi`in e.data?(0,b.encodeFunctionData)(e.data):e.data)||`0x`}}}function Du(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=_r(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=lu();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const Ou=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=Du(),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=>Eu({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.xt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeWithAuthorization`),[e.message.to,BigInt(e.message.value),e.message.data,BigInt(e.message.validAfter),BigInt(e.message.validBefore),g[t]]))}),m}async function u(c){let{clauses:l,smartAccount:u,title:d,description:f,buttonText:p=`Sign`}=c,m=[],h=Tu({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.xt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeBatchWithAuthorization`),[h.message.to,h.message.value?.map(e=>BigInt(e))??0,h.message.data,BigInt(h.message.validAfter),BigInt(h.message.validBefore),h.message.nonce,g])),m}return{buildClausesWithAuth:c}};let ku=function(e){return e.CUSTOM_TOKENS=`vechain_kit_custom_tokens`,e.ECOSYSTEM_SHORTCUTS=`vechain-kit-ecosystem-shortcuts`,e.CURRENCY=`vechain_kit_currency`,e.NODE_URL=`vechain_kit_node_url`,e.NETWORK=`vechain_kit_network`,e.GAS_TOKEN_PREFERENCES=`vechain_kit_gas_token_preferences`,e.SHOW_ASSETS=`vechain_kit_show_assets`,e}({});const Au=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.ft(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t.bt(e,JSON.stringify(i))},[e,i]),[i,a]},ju=`vechain-kit-storage-change`,Mu=(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(ju,{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(ju,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(ju,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])]},Nu=()=>{let[e,t]=Au(ku.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)}},Pu=1.1,Fu={VET:21e3,VTHO:55e3,B3TR:55e3},Iu={1:8e4,3:12e4},Lu=e=>Iu[e]??Iu[3],Ru=async(e,t,n,r,i)=>{let a=new URL(`estimate/clauses/${r.toLowerCase()}`,t);return a.searchParams.set(`type`,`smartaccount`),a.searchParams.set(`speed`,i),await(await fetch(a,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json()},zu=async e=>{let t=new URL(`deposit/account`,e);return await(await fetch(t,{method:`GET`,headers:{"Content-Type":`application/json`}})).json()},Bu=async(e,t,n,r)=>{let i=new URL(`sign/transaction/authorized/${n.toLowerCase()}`,r);return await(await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json()},Vu=async(e,t,n,r)=>{let i=await t.gas.estimateGas(e,n?.address??``,{gasPadding:1}),a=Math.max(i.totalGas,0);return await t.transactions.buildTransactionBody(e,a,{isDelegated:r})},Hu=6e3,Uu=(e,t)=>new Promise(n=>{let r=setTimeout(()=>n(null),t);e.then(e=>{clearTimeout(r),n(e)}).catch(()=>{clearTimeout(r),n(null)})}),Wu=async({thor:e,clauses:t,smartAccountAddress:n,version:r,timeoutMs:i=Hu})=>{let a=(await Uu(e.gas.estimateGas(t,n),i))?.totalGas;if(!a||a<=0)return null;let o=Lu(r);return Math.ceil((a+o)*Pu)},Gu=({totalGasNoFeePayer:e,gasToken:t,estimationResponse:n})=>{let r=e+Fu[t],i=0;if(n.transactionCost&&n.estimatedGas&&n.estimatedGas>0)i=n.transactionCost/n.estimatedGas;else if(n.vthoPerGasAtSpeed){let e=n.rate??1,t=n.serviceFee??0;i=n.vthoPerGasAtSpeed*e*(1+t)}return!i||i<=0?0:r*i},Ku=async({thor:e,clauses:t,smartAccountAddress:n,version:r,estimationResponse:i,gasToken:a,timeoutMs:o})=>{let s=(i.transactionCost??0)*2,c=await Wu({thor:e,clauses:t,smartAccountAddress:n,version:r,timeoutMs:o});if(c===null)return s;let l=Gu({totalGasNoFeePayer:c,gasToken:a,estimationResponse:i});return l>0?l:s};function qu(e,t){return s.Transaction.of(e.body,z.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function Ju(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const Yu=()=>{let{connectedWallet:e}=X(),{data:n}=Yl(e?.address??``),{data:i}=Il(n?.address??``,e?.address??``),{preferences:a}=Xu(),o=y.IERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=Ou(),u=R.ThorClient.at(t.xt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await Ru(n?.address??``,r,e,c,`medium`),f=await zu(r),p=await Ku({thor:u,clauses:e,smartAccountAddress:n?.address??``,version:i?.version??0,estimationResponse:d,gasToken:c}),m=(0,b.parseEther)(p.toString()).toString(),h={to:c===`VET`?f.depositAccount:t.Q[c].address,value:c===`VET`?m:`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,m]),comment:`Transfer ${p} ${c} to ${f.depositAccount}`,abi:c===`VET`?void 0:o.getFunction(`transfer`)},g=await l({clauses:[...e,h],smartAccount:n,version:i?.version??0}),_=await Vu(g,u,t.V,!0),v=await s.Transaction.of(_).signAsSender(s.HexUInt.of(t.V.privateKey).bytes),y=await Bu(s.HexUInt.of(v.encoded).toString(),t.V.address,c,r),x=qu(v,y.signature),S={clauses:g,simulateTransactionOptions:{caller:t.V.address??``,gasPayer:y.address}},C=await u.transactions.simulateTransaction(S.clauses,{...S.simulateTransactionOptions});for(let e=0;e<C.length;e++)if(C[e].reverted)throw Error(C[e].vmError);return(await u.transactions.sendTransaction(x)).id}catch(e){console.error(`Error sending transaction using generic delegator`,e)}throw Error(`Failed to send transaction using generic delegator, no gas tokens have sufficient balance or are enabled in Gas Token Preferences`)},[a,n,i,l,u,t.V])}},Xu=()=>{let[e,n]=Mu(ku.GAS_TOKEN_PREFERENCES,t.J);return{preferences:e,supportedTokens:t.Q,updatePreferences:(0,r.useCallback)(e=>{n(t=>({...t,...e}))},[n]),reorderTokenPriority:(0,r.useCallback)(e=>{n(t=>{let n=e.filter(e=>t.availableGasTokens.includes(e)&&!t.excludedTokens.includes(e));return{...t,tokenPriority:e,availableGasTokens:n,gasTokenToUse:n[0]??t.gasTokenToUse}})},[n]),toggleTokenExclusion:(0,r.useCallback)(e=>{n(t=>{let n=t.excludedTokens.includes(e),r=n?t.excludedTokens.filter(t=>t!==e):[...t.excludedTokens,e],i=t.tokenPriority.indexOf(e),a=n?[...t.availableGasTokens.slice(0,i),e,...t.availableGasTokens.slice(i)]:t.availableGasTokens.filter(t=>t!==e);return{...t,excludedTokens:r,availableGasTokens:a,gasTokenToUse:a[0]??t.gasTokenToUse}})},[n])}},Zu=({clauses:e,enabled:n=!0,tokens:r,sendingAmount:i,sendingTokenSymbol:a})=>{let{connectedWallet:o,account:s}=X(),{data:c}=Yl(o?.address??``),{data:l}=Il(c?.address??``,o?.address??``),{feeDelegation:u,network:d}=$(),{balances:f}=Zt(s?.address??``),{updatePreferences:m}=Xu(),h=R.ThorClient.at(t.xt(d.type).nodeUrl);return(0,p.useQuery)({queryKey:[`gas-estimation`,JSON.stringify(e),JSON.stringify(r),i,a],queryFn:async()=>{let t=await Wu({thor:h,clauses:e,smartAccountAddress:c?.address??``,version:l?.version??0}),n=null;for(let o of r)try{let r=await Ru(c?.address??``,u?.genericDelegatorUrl??``,e,o,`medium`),s=t===null?(r.transactionCost??0)*2:Gu({totalGasNoFeePayer:t,gasToken:o,estimationResponse:r}),l=Number(f.find(e=>e.symbol===o)?.balance||0),d=s+(i&&a&&o===a?Number(i):0);if(l>=d)return m({gasTokenToUse:o}),{...r,transactionCost:s,usedToken:o};n=Error(`Insufficient ${o} balance: has ${l}, needs ${d}`)}catch(e){n=e}throw n||Error(`All gas tokens failed estimation or have insufficient balance`)},enabled:n&&e.length>0&&!!c?.address&&!!u?.genericDelegatorUrl&&r.length>0&&f.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1,retry:!1,retryDelay:1e3})},Qu=({clauses:e,tokens:n,enabled:r=!0})=>{let{connectedWallet:i}=X(),{data:a}=Yl(i?.address??``),{data:o}=Il(a?.address??``,i?.address??``),{feeDelegation:s,network:c}=$(),l=R.ThorClient.at(t.xt(c.type).nodeUrl);return(0,p.useQuery)({queryKey:[`gas-estimation-all-tokens`,JSON.stringify(e),JSON.stringify(n)],queryFn:async()=>{let t={},r=await Wu({thor:l,clauses:e,smartAccountAddress:a?.address??``,version:o?.version??0});return await Promise.all(n.map(async n=>{try{let i=await Ru(a?.address??``,s?.genericDelegatorUrl??``,e,n,`medium`);t[n]={cost:(r===null?(i.transactionCost??0)*2:Gu({totalGasNoFeePayer:r,gasToken:n,estimationResponse:i}))||0,loading:!1}}catch(e){t[n]={cost:0,loading:!1,error:e instanceof Error?e.message:`Unknown error`}}})),t},enabled:r&&e.length>0&&!!a?.address&&!!s?.genericDelegatorUrl&&n.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},$u=({valuePct:e,showSuffix:t,...r})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-success`),o=(0,n.useToken)(`colors`,`vechain-kit-error`),s=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`);if(e===void 0||!Number.isFinite(e))return null;let c=e>0?`+`:``;return(0,i.jsxs)(n.HStack,{spacing:1,align:`baseline`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,fontWeight:`600`,color:e===0?s:e>0?a:o,...r,children:[c,e.toFixed(2),`%`]}),t&&(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`500`,color:s,children:`24h`})]})},ed=({symbol:e,amount:a,currencyValue:o,currentCurrency:s,isDisabled:c,onClick:l,priceChange24hPct:u,...d})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-card`),[h]=Au(ku.SHOW_ASSETS,!0),g=h?a.toLocaleString(void 0,{maximumFractionDigits:2}):`*`.repeat(4),_=h?hn(o,{currency:s}):`*`.repeat(4);return(0,i.jsxs)(n.Button,{height:`64px`,variant:`ghost`,bg:m,borderRadius:`xl`,justifyContent:`space-between`,isDisabled:c,px:4,py:3,w:`100%`,_hover:{bg:m,opacity:.85},_active:{bg:m,opacity:.7},_disabled:{cursor:`not-allowed`,opacity:.5},onClick:l,"data-testid":`asset-${e}`,...d,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,minW:0,children:[t.et[e]?r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[e],alt:`${e} logo`,boxSize:`36px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`36px`,borderRadius:`full`,bg:`whiteAlpha.300`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`11px`,fontWeight:`bold`,color:f,children:e.slice(0,3)})})}),(0,i.jsxs)(n.VStack,{align:`flex-start`,spacing:0,minW:0,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,fontSize:`md`,color:f,lineHeight:`short`,children:e}),(0,i.jsxs)(n.Text,{fontSize:`sm`,color:p,lineHeight:`short`,noOfLines:1,children:[g,` `,e]})]})]}),(0,i.jsxs)(n.VStack,{align:`flex-end`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,fontSize:`md`,color:f,lineHeight:`short`,"data-testid":`${e}-balance`,children:_}),h&&(0,i.jsx)($u,{valuePct:u,lineHeight:`short`})]})]})},td=({address:e,domain:a,imageSrc:o,imageAlt:s=`Account`,hideAddress:c=!1,balance:u,tokenAddress:d})=>{let{t:f}=(0,l.useTranslation)(),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:g}=Pn({address:e}),{tokens:_,isLoading:v}=yn({address:e}),y=(0,r.useMemo)(()=>d?_.find(e=>e.address===d):null,[_,d]),b=(0,r.useMemo)(()=>u===void 0?y?Number(y.balance):0:u,[u,y]),x=y?.symbol||``;return g||v?(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!c&&(0,i.jsx)(n.Skeleton,{mt:2,height:`12px`,width:`100px`,borderRadius:`md`})]})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]}):(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:o,alt:s,boxSize:`40px`,borderRadius:`full`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:a?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:a}),!c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:m,children:t.W(e,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:t.W(e,6,4)})})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:m,children:[b.toLocaleString(void 0,{maximumFractionDigits:2}),x&&` ${x}`]})]})]})},nd=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`FAQ`,icon:(0,i.jsx)(n.Icon,{as:g.LuCircleHelp,fontSize:`17px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,lineHeight:`normal`,left:`10px`,top:`8px`,onClick:e,...t}),rd=({children:e,...t})=>(xl(),(0,i.jsx)(n.VStack,{...t,children:e})),id=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image),o=(0,r.useRef)(e?.address);return(0,r.useEffect)(()=>{o.current!==e?.address&&(a.current=e?.image,o.current=e?.address)},[e?.address]),(0,r.useEffect)(()=>{e?.image&&!e.isLoadingMetadata&&(a.current=e.image)},[e?.image,e?.isLoadingMetadata]),!t?.src&&!e?.image&&!a.current||e?.isLoadingMetadata?(0,i.jsx)(n.Skeleton,{rounded:`full`,width:t?.width,height:t?.height}):(0,i.jsx)(n.Image,{src:t?.src||e?.image||a.current,alt:t?.alt||e?.domain,objectFit:`cover`,rounded:`full`,...t})},ad=({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.xt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},od=({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}),sd=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{darkMode:p}=$(),{balances:m}=Zt(d),[h,g]=r.default.useState(o),[_,v]=r.default.useState(!1),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=p?`rgba(255, 255, 255, 0.08)`:`rgba(0, 0, 0, 0.04)`,C=p?`rgba(255, 255, 255, 0.16)`:`rgba(0, 0, 0, 0.12)`,w=p?`rgba(255, 255, 255, 0.12)`:`rgba(0, 0, 0, 0.06)`,T=e=>e?w:`transparent`,E=e=>e?y:`transparent`;r.default.useEffect(()=>{e&&(g(o),v(!1))},[e,o]);let D=()=>{s(h,_),a()},O=e=>{let t=m.find(t=>t.symbol===e);return t?Number(t.balance).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):`0.00`},k=e=>{let t=m.find(t=>t.symbol===e),n=u[e];return!t||!n?!1:Number(t.balance)<n.cost};return(0,i.jsxs)(Xe,{isOpen:e,onClose:a,size:`sm`,children:[(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:y,children:f(`Fee token`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`normal`,color:b,mt:1,children:f(`Select the token to pay the fee with`)})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,children:[c.map(e=>{let a=t.Q[e],o=h===e,s=u[e]||{cost:0,loading:!0},c=k(e);return(0,i.jsx)(n.Box,{cursor:c?`not-allowed`:`pointer`,bg:T(o),border:`1px`,borderColor:E(o),borderRadius:`md`,p:3,transition:`all 0.2s ease`,_hover:{backgroundColor:c||o?T(o):S,borderColor:c||o?E(o):C},opacity:c?.5:1,onClick:()=>!c&&g(e),children:(0,i.jsxs)(n.HStack,{spacing:3,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,children:[r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:y,children:a.symbol}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:b,children:[f(`Balance`),`:`,` `,O(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:y,children:t.x(s.cost,2)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:b,children:a.symbol})]})})]})},e)}),h!==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:y,children:f(`Use this token for future transactions`)}),(0,i.jsx)(n.Switch,{id:`remember-choice`,isChecked:_,onChange:e=>v(e.target.checked),color:y})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:D,isDisabled:k(h),children:f(`Apply`)}),(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:a,children:f(`Cancel`)})]})})]})},cd=({estimation:e,isLoading:a,isLoadingTransaction:o,onTokenChange:s,clauses:c=[],userSelectedToken:u})=>{let{t:d}=(0,l.useTranslation)(),{feeDelegation:f,darkMode:p}=$(),{connection:m,account:h}=X(),{preferences:_,reorderTokenPriority:v}=Xu(),{isOpen:y,onOpen:b,onClose:x}=(0,n.useDisclosure)(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),w=p?`rgba(255, 255, 255, 0.08)`:`rgba(0, 0, 0, 0.04)`,[T,E]=(0,r.useState)(()=>{let e={};return _.availableGasTokens.forEach(t=>{e[t]={cost:0,loading:!0}}),e}),{data:D,isLoading:O}=Qu({clauses:c,tokens:_.availableGasTokens,enabled:c.length>0});(0,r.useEffect)(()=>{!O&&D&&E(D)},[D,O]),(0,r.useEffect)(()=>{e&&E(t=>({...t,[e.usedToken]:{cost:e.transactionCost||0,loading:!1}}))},[e]),(0,r.useEffect)(()=>{O&&E(_.availableGasTokens.reduce((e,t)=>(e[t]={cost:0,loading:!0},e),{}))},[O,_.availableGasTokens]);let k=(0,r.useCallback)((t,n)=>{n&&v([t,..._.tokenPriority.filter(e=>e!==t)]),s&&t!==e?.usedToken&&s(t)},[e,s,v,_.tokenPriority]);if(f?.delegatorUrl||m.isConnectedWithDappKit||_.availableGasTokens.length===0)return null;let{balances:A}=Zt(h?.address??``),j=e=>{let t=A.find(t=>t.symbol===e),n=T[e];return!t||!n||n.loading?!0:Number(t.balance)<n.cost},M=e?.usedToken,N=_.availableGasTokens,P;M?P=M:u&&N.includes(u)?P=u:(P=N.find(e=>T[e]&&!T[e].loading&&!j(e)),P||=N.find(e=>T[e]&&!T[e].loading),P||=N[0]);let F=P?T[P]:void 0,I=M&&e?.transactionCost?e.transactionCost:F?.cost||0,L=P?t.Q[P]: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:C,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||!M&&(!F||F.loading)||!L?(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:S,fontSize:`sm`,fontWeight:`semibold`,children:[t.x(I,2),` `,L.symbol]}),(0,i.jsxs)(n.Text,{color:C,fontSize:`xs`,children:[`≈`,` $`,(I*.01).toFixed(2)]})]})})})]}),(0,i.jsxs)(n.Button,{onClick:b,variant:`outline`,size:`sm`,borderRadius:`full`,px:6,disabled:o,color:C,borderColor:C,_hover:{bg:w,color:S,borderColor:S},leftIcon:r.default.cloneElement(t.et[P||_.availableGasTokens[0]],{boxSize:`20px`,borderRadius:`full`}),children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,children:P||_.availableGasTokens[0]}),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:C})]})]}),(0,i.jsx)(sd,{isOpen:y,onClose:x,selectedToken:P||_.availableGasTokens[0],onTokenSelect:k,availableTokens:_.availableGasTokens,tokenEstimations:T,walletAddress:h?.address??``})]})},ld=D.keyframes`
|
|
206
|
+
`}),fc=({children:e,theme:t,bodyFont:a,headingFont:o,colorModeManager:s})=>(0,i.jsxs)(D.CacheProvider,{value:(0,r.useMemo)(()=>uc(),[]),children:[(0,i.jsx)(dc,{bodyFont:a,headingFont:o}),(0,i.jsx)(n.ChakraProvider,{theme:t,resetCSS:!1,portalZIndex:void 0,colorModeManager:s,children:e})]}),pc=(0,r.createContext)({portalRootRef:void 0,tokens:void 0,themeConfig:void 0}),mc=()=>{let e=(0,r.useContext)(pc);if(!e)throw Error(`useVechainKitTheme must be used within a VechainKitThemeProvider`);return e},hc=({children:e,darkMode:t=!1,theme:a})=>{let o=(0,r.useRef)(null),s=(0,r.useContext)(Bd),c=s?s.theme:void 0,l=a??c,u=(0,r.useMemo)(()=>Ae(ke(t),je(l,t)),[t,l]),d=(0,r.useMemo)(()=>({...cc(t,l),config:{...cc(t,l).config,initialColorMode:t?`dark`:`light`}}),[t,l]),f=(0,r.useMemo)(()=>({type:`localStorage`,ssr:!1,get:()=>t?`dark`:`light`,set:()=>{}}),[t]);return(0,i.jsxs)(pc.Provider,{value:{portalRootRef:o,tokens:u,themeConfig:l},children:[(0,i.jsx)(fc,{theme:d,bodyFont:u.fonts.body,headingFont:u.fonts.heading,colorModeManager:f,children:(0,i.jsx)(n.Box,{id:`vechain-kit-root`,ref:o,bg:`transparent`,borderRadius:`12px`,children:e})}),(0,i.jsx)(lc,{})]})},gc=(0,r.createContext)(null),_c=()=>{let e=(0,r.useContext)(gc);if(!e)throw Error(`useModal must be used within ModalProvider`);return e},vc=({children:e})=>{let{darkMode:n,theme:a}=$(),[o,s]=(0,r.useState)(!1),[c,l]=(0,r.useState)(`main`),[u,d]=(0,r.useState)(!1),{setSource:p,connectV2:m}=(0,f.useWallet)(),h=(0,r.useCallback)((e,n)=>{t.ht()&&window.vechain&&window.vechain.isInAppBrowser?(p(`veworld`),m(null)):(l(e??`main`),d(n??!1),s(!0))},[]),g=(0,r.useCallback)(()=>{s(!1),l(`main`),d(!1)},[]),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(`main`),C=(0,r.useCallback)((e,t)=>{S(e??`main`),b(t?.isolatedView??!1),v(!0)},[]),w=(0,r.useCallback)(()=>{v(!1),S(`main`),setTimeout(()=>{b(!1)},300)},[]),[T,E]=(0,r.useState)(!1),D=(0,r.useCallback)(()=>E(!0),[]),O=(0,r.useCallback)(()=>E(!1),[]),[k,A]=(0,r.useState)(!1),j=(0,r.useCallback)(()=>A(!0),[]),M=(0,r.useCallback)(()=>A(!1),[]),[N,P]=(0,r.useState)(!1),[F,I]=(0,r.useState)(void 0),L=(0,r.useCallback)(e=>{I(e),P(!0)},[]),R=(0,r.useCallback)(()=>P(!1),[]);return(0,i.jsxs)(gc.Provider,{value:{openConnectModal:h,closeConnectModal:g,isConnectModalOpen:o,connectModalContent:c,setConnectModalContent:l,connectModalPreventAutoClose:u,setConnectModalPreventAutoClose:d,openAccountModal:C,closeAccountModal:w,isAccountModalOpen:_,setAccountModalContent:S,accountModalContent:x,isolatedView:y,openTransactionModal:D,closeTransactionModal:O,isTransactionModalOpen:T,openTransactionToast:j,closeTransactionToast:M,isTransactionToastOpen:k,openUpgradeSmartAccountModal:L,closeUpgradeSmartAccountModal:R,isUpgradeSmartAccountModalOpen:N},children:[e,(0,i.jsxs)(hc,{darkMode:n,theme:a,children:[(0,i.jsx)(Cs,{isOpen:o,onClose:g,initialContent:c,preventAutoClose:u}),(0,i.jsx)(us,{isOpen:_,onClose:w,initialContent:x}),(0,i.jsx)(Fs,{isOpen:N,onClose:R,style:F})]})]})},yc=()=>{let{loginMethods:e}=$(),t=e?.length===1&&e[0].method===`dappkit`,{openConnectModal:n,closeConnectModal:r,isConnectModalOpen:i}=_c(),{open:a,close:o}=(0,f.useWalletModal)();return{open:t?a:e=>n(e),close:t?o:r,isOpen:t?!1:i}},bc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),xc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:()=>e(),close:t,isOpen:n}},Sc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Cc=()=>{let{openTransactionModal:e,closeTransactionModal:t,isTransactionModalOpen:n}=_c();return{open:e,close:t,isOpen:n}},wc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Tc=()=>{let{openTransactionToast:e,closeTransactionToast:t,isTransactionToastOpen:n}=_c();return{open:e,close:t,isOpen:n}},Ec=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Dc=()=>{let{connection:e}=X(),{openConnectModal:t,closeConnectModal:n,isConnectModalOpen:r,openAccountModal:i,closeAccountModal:a,isAccountModalOpen:o}=_c();return{open:n=>{e.isConnected?i(void 0,n):t()},close:()=>{o&&a(),r&&n()},isOpen:r||o}},Oc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),kc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`choose-name`,props:{setCurrentContent:r,onBack:()=>r(`main`),initialContentSource:`main`}},t)},close:()=>{t()},isOpen:n}},Ac=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),jc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`send-token`,props:{setCurrentContent:r}},t)},close:()=>{t()},isOpen:n}},Mc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Nc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`swap-token`,props:{setCurrentContent:r,fromTokenAddress:t?.fromTokenAddress,toTokenAddress:t?.toTokenAddress}},{isolatedView:t?.isolatedView})},close:()=>{t()},isOpen:n}},Pc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Fc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`ecosystem`,t)},close:()=>{t()},isOpen:n}},Ic=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Lc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`notifications`,t)},close:()=>{t()},isOpen:n}},Rc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),zc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n,setAccountModalContent:r}=_c();return{open:t=>{e({type:`faq`,props:{onGoBack:()=>r(`main`),showLanguageSelector:!1}},t)},close:()=>{t()},isOpen:n}},Bc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Vc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`account-customization`,t)},close:()=>{t()},isOpen:n}},Hc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Uc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`receive-token`,t)},close:()=>{t()},isOpen:n}},Wc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Gc=()=>{let{privy:e,loginMethods:n,dappKit:i}=$(),a=e?.appId===t.at,o=i?.allowedWallets,s=e=>n?Array.isArray(e)?e.some(e=>n.some(t=>t.method===e)):n.some(t=>t.method===e):!0,c=(0,r.useMemo)(()=>n?n.length===0||s(`ecosystem`):!0,[n]),l=(0,r.useMemo)(()=>s(`vechain`),[n]),u=(0,r.useMemo)(()=>s(`dappkit`),[n]),d=(0,r.useMemo)(()=>s(`passkey`),[n]),f=(0,r.useMemo)(()=>s(`email`),[n]),p=(0,r.useMemo)(()=>s(`google`),[n]),m=(0,r.useMemo)(()=>s(`apple`),[n]),h=(0,r.useMemo)(()=>s(`more`),[n]),g=(0,r.useMemo)(()=>s(`github`),[n]),_={showGoogleLogin:p,showAppleLogin:m,showEmailLogin:f,showPasskey:d,showVeChainLogin:l,showDappKit:u,showVeWorld:(0,r.useMemo)(()=>s(`veworld`)?o?o.includes(`veworld`):!0:!1,[n,o]),showSync2:(0,r.useMemo)(()=>s(`sync2`)?o?o.includes(`sync2`):!0:!1,[n,o]),showWalletConnect:(0,r.useMemo)(()=>s(`wallet-connect`)?o?o.includes(`wallet-connect`):!0:!1,[n,o]),showEcosystem:c,showMoreLogin:h,showGithubLogin:g,isOfficialVeChainApp:!1};return e?a?{..._,isOfficialVeChainApp:!0}:{..._}:{..._,showEmailLogin:!1,showPasskey:!1}},Kc=e=>{let{openUpgradeSmartAccountModal:t,closeUpgradeSmartAccountModal:n,isUpgradeSmartAccountModalOpen:r}=_c();return{open:()=>t(e),close:n,isOpen:r}},qc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Jc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`profile`,t)},close:()=>{t()},isOpen:n}},Yc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Xc=()=>{let{openAccountModal:e,closeAccountModal:t,isAccountModalOpen:n}=_c();return{open:t=>{e(`settings`,t)},close:()=>{t()},isOpen:n}},Zc=({children:e})=>(0,i.jsx)(i.Fragment,{children:e}),Qc=()=>{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=zd();return{signMessage:(0,r.useCallback)(async e=>{if(!c)throw Error(`Account not found`);t(!0),o(null),i(null);try{let t=null;return t=s.isConnectedWithDappKit?(await l({purpose:`agreement`,payload:{type:`text`,content:e}},{signer:c.address})).signature:await u.signMessage(e),i(t),t}catch(e){let t=e instanceof Error?e:Error(String(e));throw o(t),t}finally{t(!1)}},[s,u,c?.address]),isSigningPending:e,signature:n,error:a,reset:(0,r.useCallback)(()=>{t(!1),i(null),o(null)},[])}},$c=()=>{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=zd();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)},[])}},el=()=>{let{loginWithPasskey:e}=(0,u.useLoginWithPasskey)();return{loginWithPasskey:async()=>{try{await e()}catch(e){throw e}}}},tl=()=>{let e=`vechain_kit_cross_app_connection`;return{setConnectionCache:(0,r.useCallback)(n=>{let r={timestamp:Date.now(),ecosystemApp:n};t.bt(e,JSON.stringify(r))},[]),getConnectionCache:(0,r.useCallback)(()=>{let n=t.ft(e);return n?JSON.parse(n):null},[]),clearConnectionCache:(0,r.useCallback)(()=>{t._t(e)},[])}},nl=()=>{let{login:n}=_r(),{setConnectionCache:r}=tl(),{data:i}=$e([t.at]);return{login:async a=>{try{await n(t.at,a),r({name:`VeChain`,logoUrl:i?.[t.at]?.logo_url,appId:t.at,website:e.x})}catch(e){throw ur({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.`})}}}};let rl=!1;const il=new Set([`google`,`apple`,`twitter`,`discord`,`github`,`tiktok`,`line`]),al=()=>{let{privy:e}=$(),{createWallet:t}=(0,u.useCreateWallet)(),{login:n}=nl(),{initOAuth:i}=(0,u.useLoginWithOAuth)({onComplete:(0,r.useCallback)(async({isNewUser:e})=>{if(e&&!rl){rl=!0;try{await t()}catch(e){throw rl=!1,console.error(`Failed to create wallet:`,e),e}}},[t])});return{initOAuth:async({provider:t})=>{if(!e){if(il.has(t)){await n({intent:t});return}throw Error(`OAuth provider "${t}" requires a Privy configuration. Supported without Privy via the VeChain whitelabel host: ${[...il].join(`, `)}.`)}await i({provider:t})}}},ol={veworld:`VeWorld`,sync2:`Sync2`,sync:`Sync`,"wallet-connect":`WalletConnect`},sl=`https://www.veworld.com/discover/browser/ul/`,cl=e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;if(e&&typeof e==`object`){let t=e;if(typeof t.message==`string`)return t.message;if(typeof t.reason==`string`)return t.reason;try{return JSON.stringify(e)}catch{return``}}return``},ll=(e,n)=>{let{t:i}=(0,l.useTranslation)(),{setSource:a,connect:o}=(0,f.useWallet)(),{close:s}=(0,f.useWalletModal)(),c=(0,r.useCallback)(async()=>{let r=ol[e]??e,l=()=>{c()};if(e===`veworld`&&typeof window<`u`&&!window.vechain){window.open(`https://www.veworld.com/discover/browser/ul/${encodeURIComponent(window.location.href)}`,`_self`);return}n({type:`loading`,props:{title:`${i(`Connecting with`)} ${r}`,loadingText:i(e===`wallet-connect`?`Scan the QR code with your wallet to continue.`:`Open your wallet and confirm the connection request.`),onTryAgain:l}});try{a(e),await o(),e===`wallet-connect`&&s()}catch(e){let r=cl(e);if(t.a(r)){n(`main`);return}n({type:`error`,props:{error:r||i(`Failed to connect, please try again later.`),onTryAgain:l}})}},[e,a,o,s,n,i]);return{connect:c}},ul=`vechain-kit-app-hub-apps`,dl=`vechain-kit-app-hub-apps-expiry`,fl=1440*60*1e3,pl=()=>[`VECHAIN_KIT`,`appHub`,`apps`],ml=async()=>{if(typeof window<`u`)try{let e=t.ft(ul),n=t.ft(dl);if(e&&n){let t=parseInt(n,10);if(Date.now()<t)return JSON.parse(e)}}catch{console.warn(`Invalid app-hub cache, fetching fresh data`)}let n=new URL(`contents/apps`,e.a),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch app directories`);let i=(await r.json()).map(async t=>{if(t.type!==`dir`)return null;let n=new URL(`master/apps/${t.name}/manifest.json`,e.o),r=await fetch(n);if(!r.ok)return console.warn(`Failed to fetch manifest for ${t.name}`),null;try{let n=await r.json(),i=new URL(`master/apps/${t.name}/logo.png`,e.o);return{id:t.name,name:n.name,description:n.desc,url:n.href,logo:i.toString(),category:n.category,tags:n.tags||[],isVeWorldSupported:n.isVeWorldSupported||!1,repo:n.repo,contracts:n.contracts,veBetterDaoId:n.veBetterDaoId}}catch(e){return console.warn(`Error parsing manifest for ${t.name}:`,e),null}}),a=(await Promise.all(i)).filter(e=>e!==null);if(typeof window<`u`)try{t.bt(ul,JSON.stringify(a)),t.bt(dl,(Date.now()+864e5).toString())}catch(e){console.warn(`Failed to cache app-hub data:`,e)}return a},hl=()=>(0,p.useQuery)({queryKey:pl(),queryFn:async()=>{try{return await ml()}catch(e){let t=localStorage.getItem(ul);if(t)return JSON.parse(t);throw e}},staleTime:1e3*60*60,retry:2}),gl=()=>{let{currentLanguage:e,setLanguage:t}=$();return{currentLanguage:e,setLanguage:t}},_l=()=>{let{currentCurrency:e,setCurrency:t}=$();return{currentCurrency:e,setCurrency:t}},vl=()=>{let[e,n]=(0,r.useState)(!0),i=`vechain_kit_feature_announcement_closed`;return(0,r.useEffect)(()=>{t.ft(i)&&n(!1)},[]),{isVisible:e,closeAnnouncement:()=>{t.bt(i,`true`),n(!1)}}},yl=()=>{let{network:e}=$();return e.nodeUrl??t.xt(e.type).nodeUrl},bl=()=>{let[e,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.ht()){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},xl=()=>{(0,r.useEffect)(()=>{let e=document.querySelector(`.chakra-modal__content`);e&&(e.scrollTop=0)},[])},Sl=async(e,t)=>{if(!t)throw Error(`Address is required`);let n=await e.accounts.getAccount(s.Address.of(t));return{balance:(0,b.formatEther)(BigInt(n.balance)).toString(),energy:(0,b.formatEther)(BigInt(n.energy)).toString()}},Cl=e=>B.balance.native(e),wl=e=>{let t=(0,f.useThor)();return(0,p.useQuery)({queryKey:Cl(e),queryFn:()=>Sl(t,e),enabled:!!e&&s.Address.isValid(e),refetchInterval:1e4})},Tl=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.xt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi),a;switch(n){case 1:case 2:a=i.read.accountImplementationV1();break;case 3:a=i.read.accountImplementationV3();break;default:throw Error(`Invalid version, must be between 1 and 3`)}let o=await a;if(!o)throw Error(`Failed to get account implementation address`);return o[0].toString()},El=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`IMPLEMENTATION_ADDRESS`,e,t],Dl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:El(e,n.type),queryFn:async()=>Tl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Ol=async(e,n)=>{if(!n)throw Error(`Network type is required`);let r=await e.contracts.load(t.xt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.currentAccountImplementationVersion();if(!r)throw Error(`Failed to get current account implementation version`);return parseInt(r[0].toString())},kl=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`CURRENT_ACCOUNT_IMPLEMENTATION_VERSION`,e],Al=()=>{let e=(0,f.useThor)(),{network:t}=$();return(0,p.useQuery)({queryKey:kl(t.type),queryFn:async()=>Ol(e,t.type),enabled:!!e&&!!t})},jl=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.xt(r).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(n);if(!i)throw Error(`Failed to get account address of ${n}`);return i[0].toString()},Ml=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`ADDRESS`,e,t],Nl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Ml(e,n.type),queryFn:async()=>jl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Pl=y.SocialLoginSmartAccountFactory__factory.abi,Fl=(e,n,r)=>bi({abi:Pl,address:t.xt(r).accountFactoryAddress,method:`getAccountVersion`,args:[e,n]}),Il=(e,n)=>{let{network:r}=$();return xi({address:t.xt(r.type).accountFactoryAddress,abi:Pl,method:`getAccountVersion`,args:[e,n],queryOptions:{select:e=>({version:parseInt(e[0].toString()),isDeployed:e[1]}),enabled:!!e&&!!n}})},Ll=y.SocialLoginSmartAccountFactory__factory.abi,Rl=`hasLegacyAccount`,zl=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:Ll,contractAddress:t.xt(r).accountFactoryAddress,method:`hasLegacyAccount`,args:[n]});return i},Bl=(e,t)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`HAS_V1_SMART_ACCOUNT`,e,t],Vl=e=>{let t=(0,f.useThor)(),{network:n}=$();return(0,p.useQuery)({queryKey:Bl(e,n.type),queryFn:async()=>zl(t,e,n.type),enabled:!!t&&!!e&&!!n})},Hl=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},Ul=e=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`IS_DEPLOYED`,e],Wl=e=>{let t=yl(),n=R.ThorClient.at(t);return(0,p.useQuery)({queryKey:Ul(e),queryFn:async()=>Hl(n,e),enabled:!!n&&!!e})},Gl=()=>{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:Ml(i,r.type)}),e.cancelQueries({queryKey:Fl(a,i,r.type)}),e.cancelQueries({queryKey:Bl(i,r.type)}),e.cancelQueries({queryKey:kl(r.type)}),e.cancelQueries({queryKey:Zl(a,i,3,r.type)}),e.cancelQueries({queryKey:eu(a,3,r.type)}),e.cancelQueries({queryKey:El(3,r.type)})]),await Promise.all([e.refetchQueries({queryKey:Ml(i,r.type)}),e.refetchQueries({queryKey:Fl(a,i,r.type)}),e.refetchQueries({queryKey:Bl(i,r.type)}),e.refetchQueries({queryKey:kl(r.type)}),e.refetchQueries({queryKey:Zl(a,i,3,r.type)}),e.refetchQueries({queryKey:eu(a,3,r.type)}),e.refetchQueries({queryKey:El(3,r.type)})])}}},Kl=()=>{let e=(0,p.useQueryClient)(),{smartAccount:t}=X();return{refresh:async()=>{let n=t?.address??``;await Promise.all([e.cancelQueries({queryKey:Jl(n)}),e.cancelQueries({queryKey:Ul(n)})]),await Promise.all([e.refetchQueries({queryKey:Jl(n)}),e.refetchQueries({queryKey:Ul(n)})])}}},ql=async(e,n,r)=>{if(!r)return{address:void 0};let i=await e.contracts.load(t.xt(n).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.getAccountAddress(r);if(!i)throw Error(`Failed to get account address of ${r}`);let a=s.Address.of(i[0].toString()),o=await e.accounts.getAccount(a);if(!o)throw Error(`Failed to get account detail of ${a}`);return{address:a.toString(),isDeployed:o.hasCode}},Jl=e=>[`VECHAIN_KIT_SMART_ACCOUNT`,e],Yl=e=>{let{network:t}=$(),n=(0,f.useThor)();return(0,p.useQuery)({queryKey:Jl(e),queryFn:()=>ql(n,t.type,e),enabled:!!e&&!!t.type&&!!n})},Xl=async(e,n,r,i,a)=>{let o=await e.contracts.load(t.xt(a).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequired(n,r,BigInt(i));if(!o)throw Error(`Failed to get upgrade required of contract address ${t.xt(a).accountFactoryAddress}`);return o[0]},Zl=(e,t,n,r)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`UPGRADE_REQUIRED`,e,t,n,r],Ql=(e,t,n)=>{let r=(0,f.useThor)(),{network:i}=$();return(0,p.useQuery)({queryKey:Zl(e,t,n,i.type),queryFn:async()=>Xl(r,e,t,n,i.type),enabled:!!r&&!!e&&!!t&&!!i.type})},$l=async(e,n,r,i)=>{let a=await e.contracts.load(t.xt(i).accountFactoryAddress,y.SocialLoginSmartAccountFactory__factory.abi).read.upgradeRequiredForAccount(n,BigInt(r));if(!a)throw Error(`Failed to get upgrade required for contract address ${n}`);return a[0]},eu=(e,t,n)=>[`VECHAIN_KIT`,`SMART_ACCOUNT`,`FACTORY`,`NEEDS_UPGRADE_FOR_ACCOUNT`,e,t,n],tu=(e,t)=>{let n=(0,f.useThor)(),{network:r}=$();return(0,p.useQuery)({queryKey:eu(e,t,r.type),queryFn:async()=>$l(n,e,t,r.type),enabled:!!n&&!!r&&!!e&&!!t&&e!==``})},nu=y.SocialLoginSmartAccount__factory.createInterface(),ru=({smartAccountAddress:e,targetVersion:n,onSuccess:i,onError:a})=>{let{refresh:o}=Gl(),{refresh:s}=Kl(),{data:c}=Dl(n),l=(0,r.useCallback)(async()=>{if(!e||!t.j(e))throw Error(`Invalid smart account address`);if(!c)throw Error(`Unable to fetch implementation address for version ${n}`);return[{to:e,value:`0x0`,data:nu.encodeFunctionData(`upgradeToAndCall`,[c,`0x`]),comment:`Upgrade account to version ${n}`,abi:nu.getFunction(`upgradeToAndCall`).format(`json`)}]},[e,c,n]),u=Rr({privyUIOptions:{title:`Upgrade Smart Account`,description:`Upgrading your account at ${t.W(e)} to version ${n}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{await Promise.all([o(),s()]),i?.()},onTxFailedOrCancelled:async()=>{a?.()}});return{...u,sendTransaction:async()=>u.sendTransaction(await l())}},iu=()=>[`VECHAIN_KIT`,`CURRENT_BLOCK`],au=10*t.s.SECOND,ou=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:iu(),queryFn:async()=>{let t=await e.blocks.getBestBlockExpanded();if(!t)throw Error(`Failed to fetch current block`);return t},staleTime:1e3*60,refetchInterval:au})},su=async e=>{let t=await e.blocks.getGenesisBlock();if(!t)throw Error(`Genesis block not found`);return t.id},cu=()=>[`VECHAIN_KIT_CHAIN_ID`],lu=()=>{let e=(0,f.useThor)();return(0,p.useQuery)({queryKey:cu(),queryFn:()=>su(e),enabled:!!e})},uu=y.IERC20__factory.createInterface(),du=(e,n,r,i,a)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);let o=[];return o.push({to:r,value:`0x0`,data:uu.encodeFunctionData(`transfer`,[e,(0,b.parseUnits)(n,a)]),comment:`Transfer ${n} ${i} to ${e}`,abi:uu.getFunction(`transfer`)}),o},fu=({fromAddress:e,receiverAddress:n,amount:i,tokenAddress:a,tokenName:o,tokenDecimals:s,onSuccess:c,onError:l})=>{let{refresh:u}=lr(),{data:d,isLoading:f,error:p}=An(s===void 0?a:``),m=(0,r.useMemo)(()=>{let e=s??d?.decimals;if(e==null)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0},[s,d?.decimals]),h=(0,r.useMemo)(()=>m===void 0?[]:du(n,i,a,o,m),[n,i,a,o,m]),g=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} ${o} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{u(),c?.()},onTxFailedOrCancelled:async e=>{l?.(e instanceof Error?e.message:String(e))}});return{...g,clauses:h,isLoadingTokenInfo:f,sendTransaction:async()=>{if(m===void 0){let e=p?`Failed to load token info: ${p.message}`:`Token decimals are required`;l?.(e);return}return g.sendTransaction(h)}}},pu=new o.Interface([`function safeTransferFrom(address from, address to, uint256 tokenId)`]),mu=(e,n,r,i,a)=>{if(!n||!t.j(n)||!e||!t.j(e)||!r||!t.j(r)||i===``)throw Error(`Invalid transfer parameters`);let o=pu.getFunction(`safeTransferFrom`);if(!o)throw Error(`safeTransferFrom not found in ERC721 interface`);return[{to:r,value:`0x0`,data:pu.encodeFunctionData(`safeTransferFrom`,[e,n,BigInt(i)]),comment:`Transfer ${a??`NFT`} #${i} to ${n}`,abi:o}]},hu=({fromAddress:e,receiverAddress:n,collectionAddress:i,tokenId:a,collectionName:o,onSuccess:s,onError:c})=>{let{refresh:l}=lr(),u=(0,p.useQueryClient)(),{network:d}=$(),f=(0,r.useMemo)(()=>{try{return mu(e,n,i,a,o)}catch{return[]}},[e,n,i,a,o]),m=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm NFT Transfer`,description:`Transfer ${o??`NFT`} #${a} to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{l(),await u.invalidateQueries({queryKey:fi(e,d.type)}),s?.()},onTxFailedOrCancelled:async e=>{c?.(e instanceof Error?e.message:String(e))}});return{...m,clauses:f,sendTransaction:async()=>{if(!f.length){c?.(`Invalid transfer parameters`);return}return m.sendTransaction(f)}}},gu=(e,n)=>{if(!e||!n||!t.j(e))throw Error(`Invalid receiver address or amount`);if(isNaN(Number(n)))throw Error(`Invalid amount`);let r=[];try{r.push({to:e,value:(0,b.parseEther)(n).toString(),data:`0x`,comment:`Transfer ${n} VET to ${e}`})}catch(e){throw console.error(`Error building clauses:`,e),Error(`Invalid amount format`)}return r},_u=({fromAddress:e,receiverAddress:n,amount:i,onSuccess:a,onError:o})=>{let{refresh:s}=lr(),c=(0,r.useMemo)(()=>gu(n,i),[n,i]),l=Rr({signerAccountAddress:e,privyUIOptions:{title:`Confirm Transfer`,description:`Transfer ${i} VET to ${t.W(n)}`,buttonText:`Sign to continue`},onTxConfirmed:async()=>{s(),a?.()},onTxFailedOrCancelled:async e=>{o?.(e instanceof Error?e.message:String(e))}});return{...l,clauses:c,sendTransaction:async()=>l.sendTransaction(c)}},vu=({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=Rr({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}},yu=10*t.s.SECOND,bu=e=>[`VECHAIN_KIT`,`TX_RECEIPT`,e],xu=(e,t=5)=>{let n=(0,f.useThor)();return(0,p.useQuery)({queryKey:bu(e),queryFn:async()=>{let r=await n.transactions.waitForTransaction(e,{timeoutMs:t*yu,intervalMs:3e3});if(!r)throw Error(`Transaction receipt not found`);return r},enabled:!!e})},Su=(e,t)=>{let n=(0,b.decodeEventLog)({abi:t,data:e.data.toString(),topics:e.topics.map(e=>e.toString())});return{meta:e.meta,decodedData:n}},Cu=({eventName:e,filterParams:t})=>[e,t?JSON.stringify(t):`all`],wu=({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 an({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=>Su(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)(()=>Cu({eventName:n,filterParams:i}),[n,i]),enabled:!!s})};function Tu({clauses:e,chainId:t,verifyingContract:n}){let r=[],i=[],a=[];return e.forEach(e=>{r.push(e.to??``),i.push(String(e.value)),typeof e.data==`object`&&`abi`in e.data?a.push((0,b.encodeFunctionData)(e.data)):a.push(e.data||`0x`)}),{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n},types:{ExecuteBatchWithAuthorization:[{name:`to`,type:`address[]`},{name:`value`,type:`uint256[]`},{name:`data`,type:`bytes[]`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`},{name:`nonce`,type:`bytes32`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteBatchWithAuthorization`,message:{to:r,value:i,data:a,validAfter:0,validBefore:Math.floor(Date.now()/1e3)+300,nonce:o.ethers.hexlify(o.ethers.randomBytes(32))}}}function Eu({clause:e,chainId:t,smartAccount:n}){return{domain:{name:`Wallet`,version:`1`,chainId:t,verifyingContract:n.address??``},types:{ExecuteWithAuthorization:[{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`data`,type:`bytes`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`}],EIP712Domain:[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}]},primaryType:`ExecuteWithAuthorization`,message:{validAfter:0,validBefore:Math.floor(Date.now()/1e3)+60,to:e.to,value:String(e.value),data:(typeof e.data==`object`&&`abi`in e.data?(0,b.encodeFunctionData)(e.data):e.data)||`0x`}}}function Du(){let{connection:e,connectedWallet:t}=X(),{signTypedData:n}=_r(),{signTypedData:r}=(0,u.usePrivy)(),{network:i}=$(),{data:a}=lu();return{connection:e,connectedWallet:t,signTypedDataWithCrossApp:n,signTypedDataPrivy:r,network:i,chainId:a}}const Ou=()=>{let{connection:e,connectedWallet:n,signTypedDataWithCrossApp:r,signTypedDataPrivy:i,network:a,chainId:o}=Du(),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=>Eu({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.xt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),h.forEach((e,t)=>{m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeWithAuthorization`),[e.message.to,BigInt(e.message.value),e.message.data,BigInt(e.message.validAfter),BigInt(e.message.validBefore),g[t]]))}),m}async function u(c){let{clauses:l,smartAccount:u,title:d,description:f,buttonText:p=`Sign`}=c,m=[],h=Tu({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.xt(a.type).accountFactoryAddress),s.ABIContract.ofAbi(y.SocialLoginSmartAccountFactory__factory.abi).getFunction(`createAccount`),[n?.address??``])),m.push(s.Clause.callFunction(s.Address.of(u.address??``),s.ABIContract.ofAbi(y.SocialLoginSmartAccount__factory.abi).getFunction(`executeBatchWithAuthorization`),[h.message.to,h.message.value?.map(e=>BigInt(e))??0,h.message.data,BigInt(h.message.validAfter),BigInt(h.message.validBefore),h.message.nonce,g])),m}return{buildClausesWithAuth:c}};let ku=function(e){return e.CUSTOM_TOKENS=`vechain_kit_custom_tokens`,e.ECOSYSTEM_SHORTCUTS=`vechain-kit-ecosystem-shortcuts`,e.CURRENCY=`vechain_kit_currency`,e.NODE_URL=`vechain_kit_node_url`,e.NETWORK=`vechain_kit_network`,e.GAS_TOKEN_PREFERENCES=`vechain_kit_gas_token_preferences`,e.SHOW_ASSETS=`vechain_kit_show_assets`,e}({});const Au=(e,n)=>{let[i,a]=(0,r.useState)(()=>{try{let r=t.ft(e);return r?JSON.parse(r):n}catch(e){return console.error(e),n}});return(0,r.useEffect)(()=>{t.bt(e,JSON.stringify(i))},[e,i]),[i,a]},ju=`vechain-kit-storage-change`,Mu=(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(ju,{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(ju,r),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(ju,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])]},Nu=()=>{let[e,t]=Au(ku.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)}},Pu=1.1,Fu={VET:21e3,VTHO:55e3,B3TR:55e3},Iu={1:8e4,3:12e4},Lu=e=>Iu[e]??Iu[3],Ru=async(e,t,n,r,i)=>{let a=new URL(`estimate/clauses/${r.toLowerCase()}`,t);return a.searchParams.set(`type`,`smartaccount`),a.searchParams.set(`speed`,i),await(await fetch(a,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clauses:n,signer:e})})).json()},zu=async e=>{let t=new URL(`deposit/account`,e);return await(await fetch(t,{method:`GET`,headers:{"Content-Type":`application/json`}})).json()},Bu=async(e,t,n,r)=>{let i=new URL(`sign/transaction/authorized/${n.toLowerCase()}`,r);return await(await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({raw:e,origin:t,token:n.toLowerCase()})})).json()},Vu=async(e,t,n,r)=>{let i=await t.gas.estimateGas(e,n?.address??``,{gasPadding:1}),a=Math.max(i.totalGas,0);return await t.transactions.buildTransactionBody(e,a,{isDelegated:r})},Hu=6e3,Uu=(e,t)=>new Promise(n=>{let r=setTimeout(()=>n(null),t);e.then(e=>{clearTimeout(r),n(e)}).catch(()=>{clearTimeout(r),n(null)})}),Wu=async({thor:e,clauses:t,smartAccountAddress:n,version:r,timeoutMs:i=Hu})=>{let a=(await Uu(e.gas.estimateGas(t,n),i))?.totalGas;if(!a||a<=0)return null;let o=Lu(r);return Math.ceil((a+o)*Pu)},Gu=({totalGasNoFeePayer:e,gasToken:t,estimationResponse:n})=>{let r=e+Fu[t],i=0;if(n.transactionCost&&n.estimatedGas&&n.estimatedGas>0)i=n.transactionCost/n.estimatedGas;else if(n.vthoPerGasAtSpeed){let e=n.rate??1,t=n.serviceFee??0;i=n.vthoPerGasAtSpeed*e*(1+t)}return!i||i<=0?0:r*i},Ku=async({thor:e,clauses:t,smartAccountAddress:n,version:r,estimationResponse:i,gasToken:a,timeoutMs:o})=>{let s=(i.transactionCost??0)*2,c=await Wu({thor:e,clauses:t,smartAccountAddress:n,version:r,timeoutMs:o});if(c===null)return s;let l=Gu({totalGasNoFeePayer:c,gasToken:a,estimationResponse:i});return l>0?l:s};function qu(e,t){return s.Transaction.of(e.body,z.concatBytes(e.signature??new Uint8Array,s.HexUInt.of(t.slice(2)).bytes))}function Ju(e,t){return s.Transaction.decode(s.HexUInt.of(e.slice(2)).bytes,t)}const Yu=()=>{let{connectedWallet:e}=X(),{data:n}=Yl(e?.address??``),{data:i}=Il(n?.address??``,e?.address??``),{preferences:a}=Xu(),o=y.IERC20__factory.createInterface(),{network:c}=$(),{buildClausesWithAuth:l}=Ou(),u=R.ThorClient.at(t.xt(c.type).nodeUrl);return{sendTransactionUsingGenericDelegator:(0,r.useCallback)(async({clauses:e,genericDelegatorUrl:r})=>{try{let c=a.gasTokenToUse,d=await Ru(n?.address??``,r,e,c,`medium`),f=await zu(r),p=await Ku({thor:u,clauses:e,smartAccountAddress:n?.address??``,version:i?.version??0,estimationResponse:d,gasToken:c}),m=(0,b.parseEther)(p.toString()).toString(),h={to:c===`VET`?f.depositAccount:t.Q[c].address,value:c===`VET`?m:`0x0`,data:c===`VET`?`0x`:o.encodeFunctionData(`transfer`,[f.depositAccount,m]),comment:`Transfer ${p} ${c} to ${f.depositAccount}`,abi:c===`VET`?void 0:o.getFunction(`transfer`)},g=await l({clauses:[...e,h],smartAccount:n,version:i?.version??0}),_=await Vu(g,u,t.V,!0),v=await s.Transaction.of(_).signAsSender(s.HexUInt.of(t.V.privateKey).bytes),y=await Bu(s.HexUInt.of(v.encoded).toString(),t.V.address,c,r),x=qu(v,y.signature),S={clauses:g,simulateTransactionOptions:{caller:t.V.address??``,gasPayer:y.address}},C=await u.transactions.simulateTransaction(S.clauses,{...S.simulateTransactionOptions});for(let e=0;e<C.length;e++)if(C[e].reverted)throw Error(C[e].vmError);return(await u.transactions.sendTransaction(x)).id}catch(e){console.error(`Error sending transaction using generic delegator`,e)}throw Error(`Failed to send transaction using generic delegator, no gas tokens have sufficient balance or are enabled in Gas Token Preferences`)},[a,n,i,l,u,t.V])}},Xu=()=>{let[e,n]=Mu(ku.GAS_TOKEN_PREFERENCES,t.J);return{preferences:e,supportedTokens:t.Q,updatePreferences:(0,r.useCallback)(e=>{n(t=>({...t,...e}))},[n]),reorderTokenPriority:(0,r.useCallback)(e=>{n(t=>{let n=e.filter(e=>t.availableGasTokens.includes(e)&&!t.excludedTokens.includes(e));return{...t,tokenPriority:e,availableGasTokens:n,gasTokenToUse:n[0]??t.gasTokenToUse}})},[n]),toggleTokenExclusion:(0,r.useCallback)(e=>{n(t=>{let n=t.excludedTokens.includes(e),r=n?t.excludedTokens.filter(t=>t!==e):[...t.excludedTokens,e],i=t.tokenPriority.indexOf(e),a=n?[...t.availableGasTokens.slice(0,i),e,...t.availableGasTokens.slice(i)]:t.availableGasTokens.filter(t=>t!==e);return{...t,excludedTokens:r,availableGasTokens:a,gasTokenToUse:a[0]??t.gasTokenToUse}})},[n])}},Zu=({clauses:e,enabled:n=!0,tokens:r,sendingAmount:i,sendingTokenSymbol:a})=>{let{connectedWallet:o,account:s}=X(),{data:c}=Yl(o?.address??``),{data:l}=Il(c?.address??``,o?.address??``),{feeDelegation:u,network:d}=$(),{balances:f}=Zt(s?.address??``),{updatePreferences:m}=Xu(),h=R.ThorClient.at(t.xt(d.type).nodeUrl);return(0,p.useQuery)({queryKey:[`gas-estimation`,JSON.stringify(e),JSON.stringify(r),i,a],queryFn:async()=>{let t=await Wu({thor:h,clauses:e,smartAccountAddress:c?.address??``,version:l?.version??0}),n=null;for(let o of r)try{let r=await Ru(c?.address??``,u?.genericDelegatorUrl??``,e,o,`medium`),s=t===null?(r.transactionCost??0)*2:Gu({totalGasNoFeePayer:t,gasToken:o,estimationResponse:r}),l=Number(f.find(e=>e.symbol===o)?.balance||0),d=s+(i&&a&&o===a?Number(i):0);if(l>=d)return m({gasTokenToUse:o}),{...r,transactionCost:s,usedToken:o};n=Error(`Insufficient ${o} balance: has ${l}, needs ${d}`)}catch(e){n=e}throw n||Error(`All gas tokens failed estimation or have insufficient balance`)},enabled:n&&e.length>0&&!!c?.address&&!!u?.genericDelegatorUrl&&r.length>0&&f.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1,retry:!1,retryDelay:1e3})},Qu=({clauses:e,tokens:n,enabled:r=!0})=>{let{connectedWallet:i}=X(),{data:a}=Yl(i?.address??``),{data:o}=Il(a?.address??``,i?.address??``),{feeDelegation:s,network:c}=$(),l=R.ThorClient.at(t.xt(c.type).nodeUrl);return(0,p.useQuery)({queryKey:[`gas-estimation-all-tokens`,JSON.stringify(e),JSON.stringify(n)],queryFn:async()=>{let t={},r=await Wu({thor:l,clauses:e,smartAccountAddress:a?.address??``,version:o?.version??0});return await Promise.all(n.map(async n=>{try{let i=await Ru(a?.address??``,s?.genericDelegatorUrl??``,e,n,`medium`);t[n]={cost:(r===null?(i.transactionCost??0)*2:Gu({totalGasNoFeePayer:r,gasToken:n,estimationResponse:i}))||0,loading:!1}}catch(e){t[n]={cost:0,loading:!1,error:e instanceof Error?e.message:`Unknown error`}}})),t},enabled:r&&e.length>0&&!!a?.address&&!!s?.genericDelegatorUrl&&n.length>0,staleTime:30*1e3,gcTime:300*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},$u=({valuePct:e,showSuffix:t,...r})=>{let a=(0,n.useToken)(`colors`,`vechain-kit-success`),o=(0,n.useToken)(`colors`,`vechain-kit-error`),s=(0,n.useToken)(`colors`,`vechain-kit-text-tertiary`);if(e===void 0||!Number.isFinite(e))return null;let c=e>0?`+`:``;return(0,i.jsxs)(n.HStack,{spacing:1,align:`baseline`,children:[(0,i.jsxs)(n.Text,{fontSize:`xs`,fontWeight:`600`,color:e===0?s:e>0?a:o,...r,children:[c,e.toFixed(2),`%`]}),t&&(0,i.jsx)(n.Text,{fontSize:`xs`,fontWeight:`500`,color:s,children:`24h`})]})},ed=({symbol:e,amount:a,currencyValue:o,currentCurrency:s,isDisabled:c,onClick:l,priceChange24hPct:u,...d})=>{let f=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),p=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),m=(0,n.useToken)(`colors`,`vechain-kit-card`),[h]=Au(ku.SHOW_ASSETS,!0),g=h?a.toLocaleString(void 0,{maximumFractionDigits:2}):`*`.repeat(4),_=h?hn(o,{currency:s}):`*`.repeat(4);return(0,i.jsxs)(n.Button,{height:`64px`,variant:`ghost`,bg:m,borderRadius:`xl`,justifyContent:`space-between`,isDisabled:c,px:4,py:3,w:`100%`,_hover:{bg:m,opacity:.85},_active:{bg:m,opacity:.7},_disabled:{cursor:`not-allowed`,opacity:.5},onClick:l,"data-testid":`asset-${e}`,...d,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,minW:0,children:[t.et[e]?r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}):(0,i.jsx)(n.Image,{src:t.$[e],alt:`${e} logo`,boxSize:`36px`,borderRadius:`full`,fallback:(0,i.jsx)(n.Box,{boxSize:`36px`,borderRadius:`full`,bg:`whiteAlpha.300`,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,i.jsx)(n.Text,{fontSize:`11px`,fontWeight:`bold`,color:f,children:e.slice(0,3)})})}),(0,i.jsxs)(n.VStack,{align:`flex-start`,spacing:0,minW:0,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,fontSize:`md`,color:f,lineHeight:`short`,children:e}),(0,i.jsxs)(n.Text,{fontSize:`sm`,color:p,lineHeight:`short`,noOfLines:1,children:[g,` `,e]})]})]}),(0,i.jsxs)(n.VStack,{align:`flex-end`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`700`,fontSize:`md`,color:f,lineHeight:`short`,"data-testid":`${e}-balance`,children:_}),h&&(0,i.jsx)($u,{valuePct:u,lineHeight:`short`})]})]})},td=({address:e,domain:a,imageSrc:o,imageAlt:s=`Account`,hideAddress:c=!1,balance:u,tokenAddress:d})=>{let{t:f}=(0,l.useTranslation)(),p=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),m=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),h=(0,n.useToken)(`colors`,`vechain-kit-card`),{isLoading:g}=Pn({address:e}),{tokens:_,isLoading:v}=yn({address:e}),y=(0,r.useMemo)(()=>d?_.find(e=>e.address===d):null,[_,d]),b=(0,r.useMemo)(()=>u===void 0?y?Number(y.balance):0:u,[u,y]),x=y?.symbol||``;return g||v?(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Skeleton,{boxSize:`40px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Skeleton,{height:`16px`,width:`120px`,borderRadius:`md`}),!c&&(0,i.jsx)(n.Skeleton,{mt:2,height:`12px`,width:`100px`,borderRadius:`md`})]})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsx)(n.Skeleton,{height:`12px`,width:`80px`,borderRadius:`md`})]})]}):(0,i.jsxs)(n.HStack,{minH:`50px`,justify:`space-between`,p:4,borderRadius:`2xl`,bg:h,children:[(0,i.jsxs)(n.HStack,{children:[(0,i.jsx)(n.Image,{src:o,alt:s,boxSize:`40px`,borderRadius:`full`,objectFit:`cover`}),(0,i.jsx)(n.VStack,{align:`start`,spacing:0,children:a?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:a}),!c&&(0,i.jsx)(n.Text,{fontSize:`xs`,color:m,children:t.W(e,6,4)})]}):(0,i.jsx)(n.Text,{fontWeight:`medium`,fontSize:`sm`,color:p,children:t.W(e,6,4)})})]}),(0,i.jsxs)(n.VStack,{justify:`flex-start`,align:`flex-end`,spacing:0,mr:2,children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`medium`,color:p,children:f(`Balance`)}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:m,children:[b.toLocaleString(void 0,{maximumFractionDigits:2}),x&&` ${x}`]})]})]})},nd=({onClick:e,...t})=>(0,i.jsx)(n.IconButton,{"aria-label":`FAQ`,icon:(0,i.jsx)(n.Icon,{as:g.LuCircleHelp,fontSize:`17px`}),size:`sm`,variant:`vechainKitHeaderIconButtons`,position:`absolute`,lineHeight:`normal`,left:`10px`,top:`8px`,onClick:e,...t}),rd=({children:e,...t})=>(xl(),(0,i.jsx)(n.VStack,{...t,children:e})),id=({wallet:e,props:t})=>{let a=(0,r.useRef)(e?.image),o=(0,r.useRef)(e?.address);return(0,r.useEffect)(()=>{o.current!==e?.address&&(a.current=e?.image,o.current=e?.address)},[e?.address]),(0,r.useEffect)(()=>{e?.image&&!e.isLoadingMetadata&&(a.current=e.image)},[e?.image,e?.isLoadingMetadata]),!t?.src&&!e?.image&&!a.current||e?.isLoadingMetadata?(0,i.jsx)(n.Skeleton,{rounded:`full`,width:t?.width,height:t?.height}):(0,i.jsx)(n.Image,{src:t?.src||e?.image||a.current,alt:t?.alt||e?.domain,objectFit:`cover`,rounded:`full`,...t})},ad=({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.xt(w.type).explorerUrl}/${d?.meta.txID}`,target:`_blank`,rel:`noopener noreferrer`,children:S(`View transaction on the explorer`)})]})},od=({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}),sd=({isOpen:e,onClose:a,selectedToken:o,onTokenSelect:s,availableTokens:c,tokenEstimations:u,walletAddress:d})=>{let{t:f}=(0,l.useTranslation)(),{darkMode:p}=$(),{balances:m}=Zt(d),[h,g]=r.default.useState(o),[_,v]=r.default.useState(!1),y=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),b=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),x=(0,n.useToken)(`colors`,`vechain-kit-error`),S=p?`rgba(255, 255, 255, 0.08)`:`rgba(0, 0, 0, 0.04)`,C=p?`rgba(255, 255, 255, 0.16)`:`rgba(0, 0, 0, 0.12)`,w=p?`rgba(255, 255, 255, 0.12)`:`rgba(0, 0, 0, 0.06)`,T=e=>e?w:`transparent`,E=e=>e?y:`transparent`;r.default.useEffect(()=>{e&&(g(o),v(!1))},[e,o]);let D=()=>{s(h,_),a()},O=e=>{let t=m.find(t=>t.symbol===e);return t?Number(t.balance).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):`0.00`},k=e=>{let t=m.find(t=>t.symbol===e),n=u[e];return!t||!n?!1:Number(t.balance)<n.cost};return(0,i.jsxs)(Xe,{isOpen:e,onClose:a,size:`sm`,children:[(0,i.jsxs)(n.ModalHeader,{children:[(0,i.jsx)(n.Text,{fontSize:`lg`,fontWeight:`semibold`,color:y,children:f(`Fee token`)}),(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`normal`,color:b,mt:1,children:f(`Select the token to pay the fee with`)})]}),(0,i.jsx)(n.ModalBody,{children:(0,i.jsxs)(n.VStack,{spacing:2,align:`stretch`,children:[c.map(e=>{let a=t.Q[e],o=h===e,s=u[e]||{cost:0,loading:!0},c=k(e);return(0,i.jsx)(n.Box,{cursor:c?`not-allowed`:`pointer`,bg:T(o),border:`1px`,borderColor:E(o),borderRadius:`md`,p:3,transition:`all 0.2s ease`,_hover:{backgroundColor:c||o?T(o):S,borderColor:c||o?E(o):C},opacity:c?.5:1,onClick:()=>!c&&g(e),children:(0,i.jsxs)(n.HStack,{spacing:3,justify:`space-between`,children:[(0,i.jsxs)(n.HStack,{spacing:3,flex:1,children:[r.default.cloneElement(t.et[e],{boxSize:`36px`,borderRadius:`full`}),(0,i.jsxs)(n.VStack,{align:`start`,spacing:0,children:[(0,i.jsx)(n.Text,{fontWeight:`medium`,color:y,children:a.symbol}),(0,i.jsxs)(n.Text,{fontSize:`xs`,color:b,children:[f(`Balance`),`:`,` `,O(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:y,children:t.x(s.cost,2)}),(0,i.jsx)(n.Text,{fontSize:`xs`,color:b,children:a.symbol})]})})]})},e)}),h!==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:y,children:f(`Use this token for future transactions`)}),(0,i.jsx)(n.Switch,{id:`remember-choice`,isChecked:_,onChange:e=>v(e.target.checked),color:y})]})]})}),(0,i.jsx)(n.ModalFooter,{children:(0,i.jsxs)(n.VStack,{spacing:3,w:`full`,children:[(0,i.jsx)(n.Button,{variant:`vechainKitPrimary`,onClick:D,isDisabled:k(h),children:f(`Apply`)}),(0,i.jsx)(n.Button,{variant:`ghost`,width:`full`,onClick:a,children:f(`Cancel`)})]})})]})},cd=({estimation:e,isLoading:a,isLoadingTransaction:o,onTokenChange:s,clauses:c=[],userSelectedToken:u})=>{let{t:d}=(0,l.useTranslation)(),{feeDelegation:f,darkMode:p}=$(),{connection:m,account:h}=X(),{preferences:_,reorderTokenPriority:v}=Xu(),{isOpen:y,onOpen:b,onClose:x}=(0,n.useDisclosure)(),S=(0,n.useToken)(`colors`,`vechain-kit-text-primary`),C=(0,n.useToken)(`colors`,`vechain-kit-text-secondary`),w=p?`rgba(255, 255, 255, 0.08)`:`rgba(0, 0, 0, 0.04)`,[T,E]=(0,r.useState)(()=>{let e={};return _.availableGasTokens.forEach(t=>{e[t]={cost:0,loading:!0}}),e}),{data:D,isLoading:O}=Qu({clauses:c,tokens:_.availableGasTokens,enabled:c.length>0});(0,r.useEffect)(()=>{!O&&D&&E(D)},[D,O]),(0,r.useEffect)(()=>{e&&E(t=>({...t,[e.usedToken]:{cost:e.transactionCost||0,loading:!1}}))},[e]),(0,r.useEffect)(()=>{O&&E(_.availableGasTokens.reduce((e,t)=>(e[t]={cost:0,loading:!0},e),{}))},[O,_.availableGasTokens]);let k=(0,r.useCallback)((t,n)=>{n&&v([t,..._.tokenPriority.filter(e=>e!==t)]),s&&t!==e?.usedToken&&s(t)},[e,s,v,_.tokenPriority]);if(f?.delegatorUrl||m.isConnectedWithDappKit||_.availableGasTokens.length===0)return null;let{balances:A}=Zt(h?.address??``),j=e=>{let t=A.find(t=>t.symbol===e),n=T[e];return!t||!n||n.loading?!0:Number(t.balance)<n.cost},M=e?.usedToken,N=_.availableGasTokens,P;M?P=M:u&&N.includes(u)?P=u:(P=N.find(e=>T[e]&&!T[e].loading&&!j(e)),P||=N.find(e=>T[e]&&!T[e].loading),P||=N[0]);let F=P?T[P]:void 0,I=M&&e?.transactionCost?e.transactionCost:F?.cost||0,L=P?t.Q[P]: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:C,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||!M&&(!F||F.loading)||!L?(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:S,fontSize:`sm`,fontWeight:`semibold`,children:[t.x(I,2),` `,L.symbol]}),(0,i.jsxs)(n.Text,{color:C,fontSize:`xs`,children:[`≈`,` $`,(I*.01).toFixed(2)]})]})})})]}),(0,i.jsxs)(n.Button,{onClick:b,variant:`outline`,size:`sm`,borderRadius:`full`,px:6,disabled:o,color:C,borderColor:C,_hover:{bg:w,color:S,borderColor:S},leftIcon:r.default.cloneElement(t.et[P||_.availableGasTokens[0]],{boxSize:`20px`,borderRadius:`full`}),children:[(0,i.jsx)(n.Text,{fontSize:`sm`,fontWeight:`semibold`,children:P||_.availableGasTokens[0]}),(0,i.jsx)(n.Icon,{as:g.LuChevronDown,boxSize:5,color:C})]})]}),(0,i.jsx)(sd,{isOpen:y,onClose:x,selectedToken:P||_.availableGasTokens[0],onTokenSelect:k,availableTokens:_.availableGasTokens,tokenEstimations:T,walletAddress:h?.address??``})]})},ld=D.keyframes`
|
|
207
207
|
from {
|
|
208
208
|
transform: translateY(-100%);
|
|
209
209
|
opacity: 0;
|