@initia/interwovenkit-react 2.0.6 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +3817 -3069
- package/dist/styles.css +1 -1
- package/dist/styles.js +1 -1
- package/package.json +40 -38
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ur=require("@privy-io/cross-app-connect/rainbow-kit"),de=require("wagmi"),$=require("@tanstack/react-query"),v=require("@initia/utils"),F=require("bignumber.js"),w=require("ramda"),Ne=require("@lukemorales/query-key-factory"),L=require("ky"),_=require("react"),V=require("@cosmjs/encoding"),va=require("@mysten/bcs"),H=require("jotai"),Lr=require("@amplitude/analytics-browser"),t=require("react/jsx-runtime"),yn=require("@cosmjs/amino/build/signdoc"),jn=require("@cosmjs/crypto"),sr=require("@cosmjs/math"),Is=require("@cosmjs/proto-signing"),Pe=require("@cosmjs/stargate"),nr=require("@cosmjs/tendermint-rpc"),wa=require("cosmjs-types/cosmos/tx/signing/v1beta1/signing"),st=require("cosmjs-types/cosmos/tx/v1beta1/tx"),We=require("ethers"),Ht=require("@initia/amino-converter"),Qt=require("@cosmjs/amino"),ba=require("cosmjs-types/cosmos/auth/v1beta1/auth"),vn=require("cosmjs-types/cosmos/crypto/secp256k1/keys"),Ca=require("cosmjs-types/google/protobuf/any"),ke=require("date-fns"),qn=require("@initia/initia.proto/cosmos/authz/v1beta1/tx"),rr=require("@initia/initia.proto/cosmos/authz/v1beta1/authz"),or=require("@initia/initia.proto/cosmos/feegrant/v1beta1/feegrant"),zr=require("@initia/initia.proto/cosmos/feegrant/v1beta1/tx"),se=require("radix-ui"),Ie=require("usehooks-ts"),Kr=require("react-error-boundary"),D=require("clsx"),Ae=require("@base-ui-components/react/dialog"),Ia=require("xss"),A=require("@initia/icons-react"),rt=require("@react-spring/web"),Ns=require("change-case"),Le=require("@base-ui-components/react/select"),Js=require("@base-ui-components/react/collapsible"),ar=require("nanoid"),Na=require("react-dom"),ue=require("react-hook-form"),Sa=require("jotai/utils"),Wr=require("react-merge-refs"),Aa=require("react-intersection-observer"),ka=require("@noble/hashes/sha3"),_t=require("@noble/hashes/utils"),$a=require("qr-code-styling"),Ke=require("@base-ui-components/react"),Ze=require("@base-ui-components/react/tabs"),It=require("@base-ui-components/react/popover"),ir=require("cosmjs-types/cosmos/bank/v1beta1/tx");function Ta(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const Dn=Ta(Lr),Gt=1.4,Hr=1.05,Qr={defaultChainId:"interwoven-1",registryUrl:"https://registry.initia.xyz",routerApiUrl:"https://router-api.initia.xyz",glyphUrl:"https://glyph.initia.xyz",usernamesModuleAddress:"0x72ed9b26ecdcd6a21d304df50f19abfdbe31d2c02f60c84627844620a45940ef",theme:"dark"},Ea={defaultChainId:"initiation-2",registryUrl:"https://registry.testnet.initia.xyz",routerApiUrl:"https://router-api.initiation-2.initia.xyz",glyphUrl:"https://glyph.initiation-2.initia.xyz",usernamesModuleAddress:"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a",theme:"dark",disableAnalytics:!0},Pn="cmbq1ozyc006al70lx4uciz0q",Ss={id:Pn,name:"Socials",iconUrl:"https://assets.initia.xyz/images/wallets/Privy.webp",iconBackground:"#ffffff"},qa=Ur.toPrivyWalletConnector(Ss),Da=Ur.toPrivyWallet(Ss),Gr=_.createContext(null);function X(){const e=_.useContext(Gr);if(!e)throw new Error("Check if the InterwovenKitProvider is mounted");return e}const Q={SECOND:1e3,MINUTE:1e3*60,INFINITY:1e3*60*60};async function Pa(e){if(e instanceof L.HTTPError){const{response:s}=e,n=s.headers.get("content-type")??"";if(w.includes("application/json",n))try{const r=await s.json();if(r.message)return r.message}catch{return e.message}try{return await s.text()}catch{return e.message}}if(e instanceof Error){if(w.path(["code"],e)===4001||w.path(["code"],e)==="ACTION_REJECTED")return"User rejected";const s=w.path(["error","message"],e),n=w.path(["cause","message"],e),r=w.path(["shortMessage"],e);return s||n||r||e.message}return String(e)}async function He(e){return new Error(await Pa(e))}const As=Ne.createQueryKeys("interwovenkit:chain",{list:e=>[e],profiles:e=>[e],prices:e=>[e],gasPrices:e=>[e]});function is(e){const s=w.path([0,"address"],e);if(!s)throw new Error("URL not found");return s}function Ra(e){const{chain_id:s,chain_name:n,pretty_name:r,logo_URIs:o,apis:a,metadata:i}=e,c=r||n,l=o?.png??"",{rpc:d,rest:u,["json-rpc"]:h,indexer:m}=a,f=is(d),g=is(u),p=is(m),x=i?.minitia?.type==="minievm"?is(h):void 0;return{...e,chainId:s,name:c,logoUrl:l,rpcUrl:f,restUrl:g,indexerUrl:p,jsonRpcUrl:x}}function ae(){const{defaultChainId:e,registryUrl:s,customChain:n}=X(),{data:r}=$.useSuspenseQuery({queryKey:As.list(s).queryKey,queryFn:()=>L.create({prefixUrl:s}).get("chains.json").json(),select:o=>(n?[n,...o.filter(i=>i.chain_id!==n.chain_id)]:o).map(Ra).toSorted(w.descend(i=>i.chainId===e)),staleTime:Q.MINUTE});return r}function Vr(){const{registryUrl:e}=X(),{data:s}=$.useSuspenseQuery({queryKey:As.profiles(e).queryKey,queryFn:()=>L.create({prefixUrl:e}).get("profiles.json").json(),staleTime:Q.MINUTE});return s}function Te(){const e=_e(),s=ae(),n=Vr();return r=>{const o=s.find(i=>i.chain_id===r);if(o)return o;const a=n.find(i=>i.chain_id===r);if(!a)throw new Error(`Chain not found: ${r}`);return{chain_id:a.chain_id,chain_name:a.name,pretty_name:a.pretty_name,network_type:e.network_type,bech32_prefix:"init",fees:{fee_tokens:[]},apis:{rpc:[],rest:[],indexer:[]},chainId:r,name:a.pretty_name,logoUrl:a.logo,rpcUrl:"",restUrl:"",indexerUrl:"",jsonRpcUrl:""}}}function Me(e){return Te()(e)}function Zt(){const{defaultChainId:e}=X();return Me(e)}function _e(){const s=ae().find(n=>n.metadata?.is_l1);if(!s)throw new Error("Layer 1 not found");return s}function Yr(){return({chainId:e})=>$.queryOptions({queryKey:As.prices(e).queryKey,queryFn:()=>L.create({prefixUrl:"https://api.initia.xyz"}).get(`initia/${e}/assets`,{searchParams:{quote:"USD",with_prices:!0}}).json(),staleTime:Q.SECOND})}function ks(e){const s=Yr();return $.useQuery(s(e))}function Ba(){const e=ae(),s=Yr();return $.useQueries({queries:e.map(n=>s(n))})}const Ma=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60">
|
|
2
2
|
<circle fill="#2F3337" cx="30" cy="30" r="30"/>
|
|
3
3
|
<path fill="#757C82" d="M26.328 34.288v-.48c0-2.048 1.024-2.816 4.128-4.16 3.104-1.28 3.712-1.952 3.712-3.488v-.128c0-1.664-1.344-2.464-4.224-2.464-2.816 0-4.416.736-4.768 3.296h-5.248c.416-5.536 4.416-7.584 9.888-7.584h.352c6.208 0 9.28 2.496 9.28 6.24v.352c0 3.392-1.28 4.96-5.376 6.592-1.504.64-2.048 1.024-2.208 1.824h-5.536ZM26.168 42v-5.152h5.792V42h-5.792Z"/>
|
|
4
|
-
</svg>`,oa=encodeURIComponent(ra),wn=`data:image/svg+xml;utf8,${oa}`,fs=ke.createQueryKeys("interwovenkit:asset",{list:e=>[e],item:(e,s)=>[e,s],resource:(e,s)=>[e.chainId,s.denom],denom:(e,s)=>[e,s],metadata:(e,s)=>[e,s]});function aa(e){const{base:s,symbol:n,denom_units:r=[],display:o,logo_URIs:a,name:i,address:l,traces:c}=e,d=r.find(m=>m.denom===o)?.exponent??r.find(m=>m.denom===s)?.exponent??v.head(r)?.exponent??0,u=a?.png??"";return{denom:s,symbol:n,decimals:d,logoUrl:u,name:i,address:l,traces:c}}function Sr(){const e=A.useQueryClient();return s=>{const n=s?.metadata?.assetlist;return A.queryOptions({queryKey:fs.list(n).queryKey,queryFn:async()=>n?Z.get(n).json():{assets:[]},select:({assets:r})=>{if(!s)return[];const o=r.map(aa);for(const a of o)e.setQueryData(fs.item(s.chainId,a.denom).queryKey,a);return o},staleTime:K.MINUTE})}}function Qt(e){const s=Sr(),{data:n}=A.useSuspenseQuery(s(e));return n}function ia(){const e=oe(),s=Sr();return A.useQueries({queries:e.map(n=>s(n))})}function Ue(e){const s=Qt(e),n=le(),r=Qt(n),o=Ar(e);return a=>{const i=s.find(c=>c.denom===a);if(i)return i;const l=r.find(c=>c.denom===o(a));return l?{...l,denom:a}:{denom:a,symbol:"",decimals:0,logoUrl:wn}}}function kr(e,s){const n=Ue(s),o=A.useQueryClient().getQueryData(fs.item(s.chainId,e).queryKey);return o||n(e)}function Ar(e){const s=le(),n=Qt(e);return r=>{if(e.metadata?.is_l1)return r;if(r.startsWith("l2/")||r.startsWith("ibc/")){const a=n.find(i=>i.denom===r)?.traces;if(a){for(const i of a)if(i.counterparty.chain_name===s.chain_name)return i.counterparty.base_denom}}const o=s.metadata?.ibc_channels?.find(({chain_id:a,version:i})=>a===e.chain_id&&i==="ics20-1")?.channel_id;return o?w.getIbcDenom(o,r):""}}function ca(e){return e.pagination?.next_key??null}async function $r(e,s,n){const r=Z.create(s),o=async(a,i)=>{const l=await r.extend(i?{searchParams:{"pagination.key":i}}:{}).get(e).json(),c=l[n]??[],d=ca(l),u=[...a,...c];return d?o(u,d):u};return o([],null)}const Hn="usernames";function la({restUrl:e,moduleAddress:s}){const{viewFunction:n}=w.createMoveClient(e);async function r(i){if(!w.InitiaAddress.validate(i))return null;const l=await n({moduleAddress:s,moduleName:Hn,functionName:"get_name_from_address",typeArgs:[],args:[W.toBase64(w.InitiaAddress(i,32).bytes)]});return l?l+".init":null}function o(i){return/^[A-Za-z0-9-]{3,64}\.init$/.test(i)}async function a(i){if(!o(i))return null;const l=await n({moduleAddress:s,moduleName:Hn,functionName:"get_address_from_name",typeArgs:[],args:[Uo.bcs.string().serialize(i.toLowerCase().replace(".init","")).toBase64()]});return l?w.InitiaAddress(l).bech32:null}return{restUrl:e,getUsername:r,getAddress:a,validateUsername:o}}const Is=ke.createQueryKeys("interwovenkit:account",{username:(e,s)=>[e,s],address:(e,s)=>[e,s],balances:(e,s)=>[e,s],txs:(e,s)=>[e,s]});function Tr(){const{restUrl:e}=le(),{usernamesModuleAddress:s}=ee();return la({restUrl:e,moduleAddress:s})}function Er(){const e=ae();return s=>A.queryOptions({queryKey:Is.balances(s.restUrl,e).queryKey,queryFn:()=>$r(`cosmos/bank/v1beta1/balances/${e}`,{prefixUrl:s.restUrl},"balances"),staleTime:K.SECOND})}function Cn(e){const s=Er(),{data:n}=A.useSuspenseQuery(s(e));return n}function da(){const e=oe(),s=Er();return A.useQueries({queries:e.map(n=>s(n))})}function ua(e){const s=Cn(e),n=Qt(e),r=Ue(e),o=Ar(e),{data:a}=Cs(e),i=c=>e.fees.fee_tokens.some(d=>d.denom===c),l=c=>n.some(d=>d.denom===c);return v.sortWith([v.descend(({denom:c})=>o(c)==="uinit"),v.descend(({denom:c})=>i(c)),v.descend(({value:c})=>c),v.descend(({denom:c})=>l(c)),({balance:c},{balance:d})=>M(d).comparedTo(c)??0,v.descend(({symbol:c})=>c.toLowerCase())],s.filter(({amount:c})=>!M(c).isZero()).map(({amount:c,denom:d})=>{const u=r(d),m=a?.find(({id:_})=>_===u?.denom)?.price??0,h=M(c).times(m).div(M(10).pow(u.decimals)).toNumber();return{...u,balance:c,price:m,value:h}}))}function ha(e){if(e?.typeUrl==="/initia.crypto.v1beta1.ethsecp256k1.PubKey"){const{key:s}=un.PubKey.decode(e.value);return Ht.encodeSecp256k1Pubkey(s)}return js.decodeOptionalPubkey(e)}function ma({typeUrl:e,value:s}){if(e==="/cosmos.auth.v1beta1.BaseAccount"){const{address:n,pubKey:r,accountNumber:o,sequence:a}=zo.BaseAccount.decode(s),i=ha(r);return{address:n,pubkey:i,accountNumber:Number(o),sequence:Number(a)}}return qe.accountFromAny({typeUrl:e,value:s})}function _a(e){return e.type==="initia/PubKeyEthSecp256k1"}const fa={...Ht.pubkeyType,ethsecp256k1:"initia/PubKeyEthSecp256k1"};function pa(e){if(_a(e)){const s=un.PubKey.fromPartial({key:W.fromBase64(e.value)});return Ko.Any.fromPartial({typeUrl:"/initia.crypto.v1beta1.ethsecp256k1.PubKey",value:Uint8Array.from(un.PubKey.encode(s).finish())})}return js.encodePubkey(e)}function qr(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");return{type:fa.ethsecp256k1,value:W.toBase64(e)}}function ga(e,s){if(s.length!==64)throw new Error("Signature must be 64 bytes long. Cosmos SDK uses a 2x32 byte fixed length encoding for the secp256k1 signature integers r and s.");return{pub_key:qr(e),signature:W.toBase64(s)}}const Ae="interwovenkit",U={PUBLIC_KEY:`${Ae}:public-key`,BRIDGE_SRC_CHAIN_ID:`${Ae}:bridge:src-chain-id`,BRIDGE_SRC_DENOM:`${Ae}:bridge:src-denom`,BRIDGE_DST_CHAIN_ID:`${Ae}:bridge:dst-chain-id`,BRIDGE_DST_DENOM:`${Ae}:bridge:dst-denom`,BRIDGE_QUANTITY:`${Ae}:bridge:quantity`,BRIDGE_SLIPPAGE_PERCENT:`${Ae}:bridge:slippage-percent`,BRIDGE_ROUTE_TYPE:`${Ae}:bridge:route-type`,BRIDGE_HISTORY:`${Ae}:bridge:history`,OP_REMINDER:`${Ae}:op:reminder`},Ns=()=>{const e=ee();return new js.Registry([...Kt.protoRegistry,...e.protoTypes??[]])},Yt=()=>{const e=ee();return new qe.AminoTypes({...Kt.aminoConverters,...e.aminoConverters})};class xa{constructor(s,n,r){this.address=s,this.signMessage=n,this.layer1RestUrl=r}cachedPublicKey=null;async getCachedPublicKey(){if(this.cachedPublicKey)return this.cachedPublicKey;const s=`${U.PUBLIC_KEY}:${this.address}`,n=localStorage.getItem(s);if(n)return this.cachedPublicKey=W.fromHex(n),W.fromHex(n);const r=await this.getPublicKeyFromRestApi();if(r)return this.cachedPublicKey=r,localStorage.setItem(s,W.toHex(r)),r;const o=await this.getPublicKey();return this.cachedPublicKey=o,localStorage.setItem(s,W.toHex(o)),o}async getPublicKeyFromRestApi(){try{const n=(await Z.create({prefixUrl:this.layer1RestUrl}).get(`cosmos/auth/v1beta1/account_info/${this.address}`).json())?.info?.pub_key?.key;return n?W.fromBase64(n):null}catch{return null}}async getPublicKey(){const s="Sign this message to identify your Initia account.",n=await this.signMessage(s),r=Ze.ethers.hashMessage(s),o=Ze.ethers.SigningKey.recoverPublicKey(r,n);return dn.Secp256k1.compressPubkey(W.fromHex(o.replace("0x","")))}async getAccounts(){return[{address:this.address,algo:"ethsecp256k1",pubkey:await this.getCachedPublicKey()}]}async signAmino(s,n){if(this.address!==s)throw new Error("Signer address does not match the provided address");const r=ln.escapeCharacters(ln.sortedJsonStringify(n)),o=await this.signMessage(r),a=W.fromHex(o.replace("0x","")).subarray(0,-1),l=dn.Secp256k1Signature.fromFixedLength(a).toFixedLength(),c=ga(await this.getCachedPublicKey(),l);return{signed:n,signature:c}}}function In(){const e=Ns(),s=Yt(),n=$t(),r=Pr();return async function(o,a,i,l,c,d){if(!n)throw new Error("Signer not initialized");const u=await r(o),{accountNumber:m,...h}=await u.getSequence(a),_=h.sequence+(d?.incrementSequence??0),[g]=await n.getAccounts(),p=pa(qr(g.pubkey)),j=Lo.SignMode.SIGN_MODE_EIP_191,S=i.map(x=>s.toAmino(x)),N=ln.makeSignDoc(S,l,o,c,m,_),{signature:I,signed:b}=await n.signAmino(a,N),D={typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{messages:b.msgs.map(x=>s.fromAmino(x)),memo:c}},F=e.encode(D),C=Un.Int53.fromString(b.fee.gas).toNumber(),P=Un.Int53.fromString(b.sequence).toNumber(),y=js.makeAuthInfoBytes([{pubkey:p,sequence:P}],b.fee.amount,C,b.fee.granter,b.fee.payer,j);return Ge.TxRaw.fromPartial({bodyBytes:F,authInfoBytes:y,signatures:[W.fromBase64(I.signature)]})}}function $t(){const e=ae(),{signMessageAsync:s}=ve.useSignMessage(),n=le();return f.useMemo(()=>new xa(e,r=>s({message:r}),n.restUrl),[e,s,n.restUrl])}const zs=new Map,Ks=new Map;function Dr(){const e=Xe();return async s=>{if(zs.has(s))return zs.get(s);const{rpcUrl:n}=e(s),r=await Ln.Comet38Client.create(new Ln.HttpClient(n));return zs.set(s,r),r}}function Pr(){const e=Ns(),s=Yt(),n=$t(),r=ae(),o=Dr();return async a=>{const i=`${r}:${a}`;if(Ks.has(i))return Ks.get(i);if(!n)throw new Error("Signer not initialized");const l=await o(a),c=await qe.SigningStargateClient.createWithSigner(l,n,{registry:e,aminoTypes:s,accountParser:ma,broadcastPollIntervalMs:500});return Ks.set(i,c),c}}function Rr(){const{connector:e}=ve.useAccount();return async()=>{if(!e)throw new Error("Wallet not connected");return new Ze.BrowserProvider(await e.getProvider())}}const Br=f.createContext(null);function Ss(){return f.useContext(Br)}function Fr(){const{location:e}=Ss();return e}function ks(){const{path:e}=Fr();return e}function ft(){const{state:e={}}=Fr();return e}function ya(){const{history:e}=Ss();return e}function he(){const{navigate:e}=Ss();return e}function Mr(){const{reset:e}=Ss();return e}const Nn=({to:e,state:s,shouldReset:n,children:r,onClick:o,...a})=>{const i=he(),l=Mr(),c=d=>{d.preventDefault(),o?.(d),n?l(e,s):i(e,s)};return t.jsx("button",{type:"button",...a,onClick:c,children:r})},Or=({children:e,initialEntry:s})=>{const[n,r]=f.useState([s??{path:"/"}]),o=n[n.length-1],a=f.useCallback((l,c)=>{r(d=>{if(typeof l=="string")return[...d,{path:l,state:c}];const u=d.length+l;if(u<1)return d;const m=v.take(u,d);return c!==void 0?v.adjust(u-1,h=>({...h,state:c}),m):m})},[]),i=f.useCallback((l,c)=>{r([{path:l,state:c}])},[]);return t.jsx(Br.Provider,{value:{location:o,history:n,navigate:a,reset:i},children:e})},Ur=f.createContext(null),As=()=>f.useContext(Ur);class Lr extends Error{originalError;moduleAddress;moduleName;errorCode;errorCodeHex;isFromRegistry;constructor(s,n,r,o,a,i,l){super(s),this.name="MoveError",this.originalError=n,this.moduleAddress=r,this.moduleName=o,this.errorCode=a,this.errorCodeHex=i,this.isFromRegistry=l}}const ja=/VM aborted: location=([0-9A-Fa-f]+)::(\w+), code=(\d+)/,Hs=new Map;function va(e){const s=e.match(ja);if(!s)return null;const[,n,r,o]=s;return{moduleAddress:`0x${n.replace(/^0+/,"")||"0"}`,moduleName:r,errorCode:o.replace(/^0+/,"")||"0"}}async function ba(e,s,n){const r=`${e}:${s}`;if(Hs.has(r))return Hs.get(r);try{const o=s==="0x1"?"0x1.json":`${e}/${s}.json`,a=`${n}/errors/${o}`,{errors:i={}}=await Z.get(a).json();return Hs.set(r,i),i}catch{return null}}function wa(e,s,n,r,o,a,i){return new Lr(e,s,n,r,o,a,i)}async function Ct(e,s,n){if(!s.metadata?.is_l1&&s.metadata?.minitia?.type!=="minimove")return await Fe(e);const r=va(e.message);if(!r)return await Fe(e);const o=await ba(s.chain_name,r.moduleAddress,n),a=`0x${parseInt(r.errorCode,10).toString(16)}`,i=`Failed with code ${a} in module ${r.moduleName} at ${r.moduleAddress}`,l=o?.[r.moduleName]?.[r.errorCode],c=l||i,d=!!l;return wa(c,e,r.moduleAddress,r.moduleName,r.errorCode,a,d)}const Ca="c33b940c24c17e95f7d9d525d508ac61";function Ia(){const{disableAnalytics:e}=ee();f.useEffect(()=>{e||bn.init(Ca,{autocapture:!1})},[e])}function Na(){const{connector:e}=ve.useAccount(),{defaultChainId:s,disableAnalytics:n}=ee();f.useEffect(()=>{const r=new yr.Identify;e?.name&&r.set("connector",e.name),s&&r.set("defaultChainId",s),bn.identify(r)},[s,e?.name,n])}function $s(){const e=ks();return f.useCallback((n,r)=>{bn.track(n,{path:e,...r})},[e])}const Sa=G.atom(!1);function Tt(){const e=Mr(),[s,n]=G.useAtom(Sa),r=$s();return{isDrawerOpen:s,openDrawer:(i,l)=>{i&&e(i,l),n(!0),r("Widget Opened")},closeDrawer:()=>{n(!1),r("Widget Closed")}}}function zr(){const e=he(),{closeDrawer:s}=Tt(),{disconnect:n}=ve.useDisconnect();return()=>{e("/blank"),s(),n(),localStorage.removeItem(U.BRIDGE_SRC_CHAIN_ID),localStorage.removeItem(U.BRIDGE_SRC_DENOM),localStorage.removeItem(U.BRIDGE_DST_CHAIN_ID),localStorage.removeItem(U.BRIDGE_DST_DENOM),localStorage.removeItem(U.BRIDGE_QUANTITY),localStorage.removeItem(U.BRIDGE_SLIPPAGE_PERCENT)}}const Kr="approve",Ts=G.atom(),Hr=G.atom(null);function Wr(){const e=G.useAtomValue(Ts);if(!e)throw new Error("Tx request not found");return e}function Sn(){const e=he(),s=ae(),{defaultChainId:n,registryUrl:r}=ee(),o=Xe(),{openDrawer:a,closeDrawer:i}=Tt(),{openModal:l,closeModal:c}=As(),d=G.useSetAtom(Ts),u=G.useSetAtom(Hr),m=Dr(),h=Pr(),_=$t(),g=Ns(),p=async({messages:C,memo:P,chainId:y=n})=>{try{return await(await h(y)).simulate(s,C,P)}catch(x){throw await Ct(x,o(y),r)}},j=async({messages:C,memo:P,chainId:y=n})=>{const x=await m(y),$=qe.QueryClient.withExtensions(x,qe.setupTxExtension),T=C.map(ie=>g.encodeAsAny(ie)),[R]=await _.getAccounts(),L=Ht.encodeSecp256k1Pubkey(R.pubkey),q=await h(y),{sequence:H}=await q.getSequence(s);return $.tx.simulate(T,P,L,H)},S=async({txRequest:C,broadcaster:P})=>{const x={...{memo:"",chainId:n,gas:C.gas||await p(C),gasAdjustment:Wt,gasPrices:null,spendCoins:[],internal:!1},...C};return new Promise(($,T)=>{d({txRequest:x,resolve:async L=>{try{const q=await h(x.chainId),H=await P(q,Ge.TxRaw.encode(L).finish());$(H),typeof x.internal=="string"&&e(x.internal)}catch(q){T(await Ct(q,o(x.chainId),r))}finally{R()}},reject:L=>{T(L),R()}}),x.internal?l({path:"/tx"}):a("/tx");const R=()=>{if(!x.internal){e("/blank"),i();return}c()}})},N=async C=>{const P=C.chainId??n;try{const y=await S({txRequest:C,broadcaster:async(x,$)=>await x.broadcastTxSync($)});return C.internal&&typeof C.internal!="number"&&(u({txHash:y,chainId:P,status:"loading"}),F({txHash:y,chainId:C.chainId}).then(x=>{u({status:x.code===0?"success":"error",chainId:P,txHash:y})}).catch(()=>{u({status:"error",chainId:P,txHash:y})})),y}catch(y){throw C.internal&&typeof C.internal!="number"&&u({status:"error",chainId:P,error:y}),y}},I=(C,P=30*1e3,y=.5*1e3)=>S({txRequest:C,broadcaster:async(x,$)=>{const T=await x.broadcastTx($,P,y);if(T.code!==0)throw new Error(T.rawLog);return T}}),b=In(),E=async C=>{const P=C.chainId??n;try{const{messages:y,memo:x="",fee:$}=C,T=await h(P),R=await b(P,s,y,$,x);return await T.broadcastTxSync(Ge.TxRaw.encode(R).finish())}catch(y){throw await Ct(y,o(P),r)}},D=async(C,P=30*1e3,y=.5*1e3)=>{const x=C.chainId??n;try{const{messages:$,memo:T="",fee:R}=C,L=await h(x),q=await b(x,s,$,R,T),H=await L.broadcastTx(Ge.TxRaw.encode(q).finish(),P,y);if(H.code!==0)throw new Error(H.rawLog);return H}catch($){throw await Ct($,o(x),r)}},F=async({chainId:C=n,...P})=>{try{const y=await h(C);return await Qr({...P,client:y})}catch(y){throw await Ct(y,o(C),r)}};return{estimateGas:p,simulateTx:j,requestTxSync:N,requestTxBlock:I,submitTxSync:E,submitTxBlock:D,waitForTxConfirmation:F}}async function Qr({txHash:e,client:s,timeoutMs:n=30*1e3,intervalMs:r=.5*1e3}){const o=Date.now();for(;;){const a=await s.getTx(e);if(a){if(a.code!==0)throw new Error(a.rawLog);return a}if(Date.now()-o>=n)throw new Error(`Transaction was submitted, but not found on the chain within ${n/1e3} seconds.`);await new Promise(i=>setTimeout(i,r))}}const ka="INIT",Aa="Initia";function kn(e){return e.assets.reduce((s,{value:n})=>s+(n??0),0)}function $a(e){return e.assets.reduce((s,{quantity:n})=>s.plus(n),M(0)).toString()}function Ta(e,s){return{symbol:s?.symbol??e,logoUrl:s?.logoUrl??wn}}function Wn(e){return v.pick(["chainId","name","logoUrl"],e)}function Ea(e){return v.sortWith([v.descend(({symbol:s})=>s===ka),v.descend(kn),v.descend(({assets:s})=>s.length),v.ascend(({symbol:s})=>s)])(e)}function qa(e){return v.sortWith([v.descend(({value:s})=>s??0),v.descend(({quantity:s})=>Number(s)),v.ascend(({chain:s})=>s.name)])(e)}function Da(e){return v.sortWith([v.descend(({chain:s})=>s.name===Aa),v.ascend(({chain:s})=>s.name),v.ascend(({denom:s})=>s)])(e)}function Pa(e,s){return v.sortWith([v.descend(({chainId:n})=>n===s),v.descend(v.prop("value"))])(e)}function Ra(e,s,n,r,o){const a={};for(const u of e){const m=u.chainId,h=s[m]??[],_=n[m],g=r[m],p=[];for(const{amount:j,denom:S}of h){if(!M(j).gt(0))continue;const N=_?.find(F=>F.denom===S),I=g?.find(F=>F.id===S)?.price,b=N?.decimals??0,E=w.fromBaseUnit(j,{decimals:b}),D=I?M(E).times(I).toNumber():void 0;p.push({...Ta(S,N),amount:j,denom:S,decimals:b,quantity:E,price:I,value:D,address:N?.address,unlisted:!N,chain:Wn(u)})}a[m]=p}const i=new Map;for(const[u,m]of Object.entries(a)){if(m.length===0)continue;const h=e.find(g=>g.chainId===u);if(!h)continue;const _=m.reduce((g,{value:p})=>g+(p??0),0);i.set(u,{...Wn(h),value:_})}const l=new Map;for(const u of Object.values(a))for(const m of u)if(!m.unlisted){const{symbol:h}=m,_=l.get(h)??[];l.set(h,[..._,m])}const c=[];for(const[u,m]of l){const h=v.head(m);if(!h)continue;const _=qa(m);c.push({symbol:u,logoUrl:h.logoUrl,assets:_})}const d=[];for(const u of Object.values(a))for(const m of u)m.unlisted&&d.push(m);return{chainsByValue:Pa(Array.from(i.values()),o),assetGroups:Ea(c),unlistedAssets:Da(d),totalValue:c.reduce((u,m)=>u+kn(m),0)}}function An(){const{defaultChainId:e}=ee(),s=oe(),n=da(),r=ia(),o=na(),a=s.map(h=>h.chainId),i=v.zipObj(a,n.map(v.prop("data"))),l=v.zipObj(a,r.map(v.prop("data"))),c=v.zipObj(a,o.map(v.prop("data"))),d=Ra(s,i,l,c,e),u=[n,r,o].flat().some(({isLoading:h})=>h);return{...d,isLoading:u,refetch:()=>{n.forEach(({refetch:h})=>h()),r.forEach(({refetch:h})=>h()),o.forEach(({refetch:h})=>h())}}}function ae(){const e=Es();return e?w.InitiaAddress(e).bech32:""}function Es(){const{address:e}=ve.useAccount();return e?w.InitiaAddress(e).hex:""}function Et(){const e=Gt(),s=ae(),n=Es();return e.metadata?.minitia?.type==="minievm"?n:s}function Vr(){const e=Et(),s=Tr();return A.useQuery({queryKey:Is.username(s.restUrl,e).queryKey,queryFn:()=>s.getUsername(e),enabled:!!e,staleTime:K.MINUTE})}function fe(){const e=Et(),s=ae(),n=Es(),{data:r}=Vr(),o=$t(),a=zr(),{isDrawerOpen:i,openDrawer:l}=Tt(),c=()=>{l("/")},d=()=>{l("/connect")},u=_=>{l("/bridge",_)},m=Sn();return{address:e,initiaAddress:s,hexAddress:n,username:r,offlineSigner:o,isConnected:!!e,isOpen:i,openConnect:d,openWallet:c,openBridge:u,disconnect:a,...m}}const Ba="_status_tn9m1_1",Fa="_error_tn9m1_9",Qn={status:Ba,error:Fa},X=({error:e,children:s})=>t.jsx("p",{className:B(Qn.status,{[Qn.error]:e}),children:s}),pe=({errorBoundaryProps:e={fallbackRender:({error:r})=>t.jsx(X,{error:!0,children:r.message})},suspenseFallback:s=t.jsx(X,{children:"Loading..."}),children:n})=>t.jsx(jr.ErrorBoundary,{...e,children:t.jsx(f.Suspense,{fallback:s,children:n})});function Ma(){const e=["initia-wallet-widget:last-connected-wallet","initia-wallet-widget:fee-denoms","initia-wallet-widget:chain-ids","initia-wallet-widget:opened-layers-assets","initia-wallet-widget:opened-layers-nft"],s={"initia-wallet-widget:ethereum-public-keys":{prefix:U.PUBLIC_KEY,getSuffix:n=>w.InitiaAddress(n).bech32}};for(const n of e)localStorage.removeItem(n);for(const[n,{prefix:r,getSuffix:o}]of Object.entries(s)){const a=localStorage.getItem(n);if(a)try{const i=JSON.parse(a);for(const[l,c]of Object.entries(i)){const d=`${r}:${o(l)}`;localStorage.setItem(d,c)}localStorage.removeItem(n)}catch{}}}const De=ke.createQueryKeys("interwovenkit:skip",{chains:null,assets:e=>[e],asset:(e,s)=>[e,s],balances:(e,s)=>[e,s],route:(e,s)=>[e,s],routeErrorInfo:e=>[e],txTrack:(e,s)=>[e,s],txStatus:(e,s)=>[e,s]});function Le(){const{routerApiUrl:e}=ee();return f.useMemo(()=>Z.create({prefixUrl:e}),[e])}function kt(e){const s=Le(),n=A.useQueryClient(),{data:r}=A.useSuspenseQuery({queryKey:De.assets(e).queryKey,queryFn:()=>s.get("v2/fungible/assets",{searchParams:{chain_ids:e}}).json(),select:({chain_to_assets_map:o})=>{const{assets:a}=o[e]??{assets:[]};for(const i of a)n.setQueryData(De.asset(e,i.denom).queryKey,i);return a.toSorted(v.descend(i=>i.symbol==="INIT"))},staleTime:K.MINUTE});return r}function Gr(e){const s=kt(e);return n=>{const r=s.find(o=>o.denom===n);if(!r)throw new Error(`Asset not found: ${n}`);return r}}function Me(e,s){return Gr(s)(e)}function Yr(){const e=oe();return s=>e.some(n=>n.chain_id===s)}function Zt(){const e=Yr();return s=>e(s.chain_id)?"initia":s.chain_type}function Vt(e){return Zt()(e)}function $n(){const e=Le(),{data:s}=A.useSuspenseQuery({queryKey:De.chains.queryKey,queryFn:()=>e.get("v2/info/chains").json(),select:({chains:n})=>v.sortWith([v.descend(({chain_name:r})=>r==="initia"),v.ascend(({pretty_name:r})=>r)],n),staleTime:K.MINUTE});return s}function pt(){const e=$n(),s=Ir();return n=>{const r=e.find(a=>a.chain_id===n);if(r)return r;const o=s.find(a=>a.chain_id===n);if(!o)throw new Error(`Chain not found: ${n}`);return{chain_id:o.chain_id,chain_name:o.name,pretty_name:o.pretty_name,logo_uri:o.logo,chain_type:"cosmos",rpc:"",rest:""}}}function Pe(e){return pt()(e)}const Oa=()=>(Ia(),Na(),null),Ua="_loader_4gdsk_1",La={loader:Ua},gt=({size:e=24,color:s="currentColor",border:n=2})=>{const r={width:`${e}px`,height:`${e}px`,borderColor:`${s} ${s} transparent ${s}`,borderWidth:`${n}px`};return t.jsx("div",{className:La.loader,style:r})},za="_button_1n7c4_1",Ka="_outline_1n7c4_25",Ha="_sm_1n7c4_43",Wa="_full_1n7c4_49",Qa="_small_1n7c4_53",Va="_unpadded_1n7c4_83",dt={button:za,outline:Ka,sm:Ha,full:Wa,small:Qa,unpadded:Va},Zr=e=>{const{sm:s,fullWidth:n,loading:r,className:o,children:a,disabled:i,...l}=e;return t.jsx("button",{...l,className:B(dt.button,{[dt.sm]:s,[dt.full]:n},o),disabled:!!r||i,children:r?t.jsxs(t.Fragment,{children:[t.jsx(gt,{color:"currentColor",size:16}),typeof r=="string"&&t.jsx("span",{className:dt.loading,children:r})]}):a})},Ga=({className:e,...s})=>t.jsx(Zr,{...s,className:B(dt.outline,e)}),Ya=({className:e,unpadded:s,...n})=>t.jsx("button",{...n,className:B(dt.small,{[dt.unpadded]:s},e)}),V={White:Zr,Outline:Ga,Small:Ya},Za="_footer_xif7g_1",Ja="_actions_xif7g_10",Vn={footer:Za,actions:Ja},re=({extra:e,className:s,children:n})=>t.jsxs("footer",{className:B(Vn.footer,s),children:[e,t.jsx("div",{className:Vn.actions,children:n})]}),Xa="_scrollable_abvhw_1",ei={scrollable:Xa},ze=({className:e,children:s,ref:n})=>t.jsx("div",{ref:n,className:B(ei.scrollable,e),children:s});function qs(){return Ne.useMediaQuery("(max-width: 576px)")}const hn="interwoven-kit";function Jr(){const e=document.querySelector(hn)||document.body.appendChild(document.createElement(hn));return e.shadowRoot||e.attachShadow({mode:"open"})}function ti(){const{theme:e,container:s}=ee();return f.useEffect(()=>{document.querySelector(hn)?.setAttribute("data-theme",e)},[e]),s??Jr()}function si(e){const s=Jr(),n=document.createElement("style");n.textContent=e,s.appendChild(n)}const Tn=f.createContext(null);function mt(){const{container:e}=f.useContext(Tn);return e}function Xr(e){const s=mt();return s?getComputedStyle(s).getPropertyValue(e):""}function ni(){return Ne.useScrollLock(),null}function ri(e){return/^[A-F0-9]{64}$/i.test(e)}function oi(e,s){const{txHash:n,accountAddress:r,pathSuffix:o}=s;if(n)return ri(n)?v.path(["explorers",0,"tx_page"],e)?.replace(/\$\{txHash\}/g,n):void 0;if(r){if(!w.InitiaAddress.validate(r))return;const i=v.path(["explorers",0,"account_page"],e)?.replace(/\$\{accountAddress\}/g,r);return i&&o?i+o:i}}function ai(e){try{const s=new URL(e,window.location.href);if(!["http:","https:"].includes(s.protocol))throw new Error("Invalid protocol");return s.toString()}catch{return"#"}}const ii="_link_guafb_1",Gn={link:ii},Ds=({chainId:e,txHash:s,accountAddress:n,pathSuffix:r,...o})=>{const{showIcon:a,className:i,children:l,onClick:c,...d}=o,u=Oe(e),m=oi(u,{txHash:s,accountAddress:n,pathSuffix:r}),h=s?w.truncate(s):n?w.truncate(n):"",_=l??h;return m?t.jsxs("a",{...d,href:Ho(ai(m)),className:B(Gn.link,i),onClick:c,target:"_blank",children:[_,a&&t.jsx(k.IconExternalLink,{size:12})]}):t.jsx("span",{...d,className:B(Gn.link,i),children:_})},eo=f.createContext(null),En=()=>f.useContext(eo),ci=()=>{const[e,s]=G.useAtom(Hr),{showNotification:n,updateNotification:r,hideNotification:o}=En();return f.useEffect(()=>{if(!e)return;const{status:a,chainId:i,txHash:l,error:c}=e,d=c?c.message:l?t.jsx(Ds,{txHash:l,chainId:i,onClick:o,showIcon:!0,children:"View on Initia Scan"}):null;switch(a){case"loading":n({type:"loading",title:"Transaction is pending..."});break;case"error":r({type:"error",title:"Transaction failed",description:d}),s(null);break;case"success":r({type:"success",title:"Transaction is successful!",description:d,autoHide:!0}),s(null);break}},[e,s,n,r,o]),null},ps=({value:e,children:s})=>{const[n,r]=f.useState(!1);return s({copy:async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1e3)}catch{}},copied:n})},li="_placeholder_10r3x_1",di="_logo_10r3x_5",Yn={placeholder:li,logo:di},Q=({src:e,alt:s,placeholder:n,classNames:r,style:o,logo:a,...i})=>{const[l,c]=f.useState(void 0),{width:d,height:u}=i,m=n??t.jsx("div",{className:B(Yn.placeholder,r?.placeholder),style:{width:d,height:u,...o}});return!e||l===e?m:t.jsx("img",{...i,className:B(i.className,{[Yn.logo]:a}),style:{width:d,height:u,...o},src:e,alt:s,loading:"lazy",onError:()=>c(e)})},to=f.createContext(!1),ui="_overlay_2lgi8_1",hi="_fullscreen_2lgi8_15",mi="_content_2lgi8_19",_i="_header_2lgi8_54",fi="_title_2lgi8_63",pi="_close_2lgi8_68",ot={overlay:ui,fullscreen:hi,content:mi,header:_i,title:fi,close:pi},so=({title:e,children:s,trigger:n,className:r,open:o,onOpenChange:a})=>{const i=mt(),l=f.useContext(to);return i?t.jsxs(Ie.Dialog.Root,{open:o,onOpenChange:a,modal:!1,children:[n&&t.jsx(Ie.Dialog.Trigger,{className:r,children:n}),t.jsxs(Ie.Dialog.Portal,{container:i,children:[t.jsx(Ie.Dialog.Backdrop,{className:B(ot.overlay,{[ot.fullscreen]:l}),onClick:()=>a(!1),forceRender:!0}),t.jsxs(Ie.Dialog.Popup,{className:B(ot.content,{[ot.fullscreen]:l}),children:[e&&t.jsxs("header",{className:ot.header,children:[t.jsx(Ie.Dialog.Title,{className:ot.title,children:e}),t.jsx(Ie.Dialog.Close,{className:ot.close,children:t.jsx(k.IconClose,{size:20})})]}),s]})]})]}):null},_t=({title:e,content:s,children:n,className:r})=>{const[o,a]=f.useState(!1),i=()=>a(!1);return t.jsx(so,{title:e,trigger:n,className:r,open:o,onOpenChange:a,children:s(i)})},gi="_root_19tvg_1",xi="_address_19tvg_9",yi="_copy_19tvg_19",ji="_labelWrapper_19tvg_33",vi="_labelCopy_19tvg_43",bi="_labelCopied_19tvg_47",wi="_copied_19tvg_55",Ci="_derived_19tvg_65",Ii="_derivedLabel_19tvg_78",Ni="_derivedAddress_19tvg_82",Si="_hexAddress_19tvg_88",ki="_derivedCopy_19tvg_93",ue={root:gi,address:xi,copy:yi,labelWrapper:ji,labelCopy:vi,labelCopied:bi,copied:wi,derived:Ci,derivedLabel:Ii,derivedAddress:Ni,hexAddress:Si,derivedCopy:ki},Ai=()=>{const e=f.useRef(null),s=f.useRef(null),{initiaAddress:n,hexAddress:r}=fe(),o=Xr("--gray-0");return f.useEffect(()=>{e.current&&(s.current?s.current.update({data:n}):(s.current=new Wo({type:"canvas",width:400,height:400,margin:0,data:n,image:"https://registry.initia.xyz/images/INIT.png",qrOptions:{mode:"Byte",errorCorrectionLevel:"H"},imageOptions:{crossOrigin:"anonymous",margin:12},dotsOptions:{type:"dots",color:o},cornersSquareOptions:{type:"extra-rounded",color:o},cornersDotOptions:{type:"dot",color:o},backgroundOptions:{color:"transparent"}}),s.current.append(e.current)))},[n,o]),t.jsxs("div",{className:ue.root,children:[t.jsx("div",{ref:e,style:{width:200,height:200}}),t.jsx("span",{className:ue.address,children:n}),t.jsx(ps,{value:n,children:({copy:a,copied:i})=>t.jsxs("button",{className:B(ue.copy,{[ue.copied]:i}),onClick:a,children:[t.jsx(k.IconCopy,{size:12}),t.jsxs("div",{className:ue.labelWrapper,children:[t.jsx("span",{className:ue.labelCopy,children:"Copy address"}),t.jsx("span",{className:ue.labelCopied,children:"Copied!"})]})]})}),t.jsx(ps,{value:r,children:({copy:a,copied:i})=>t.jsxs("button",{className:B(ue.derived,{[ue.copied]:i}),onClick:a,children:[t.jsx("span",{className:ue.derivedLabel,children:"Derived from"}),t.jsxs("span",{className:ue.derivedAddress,children:[t.jsx("span",{className:ue.hexAddress,children:w.truncate(r)}),t.jsx(k.IconCopy,{size:12,className:ue.derivedCopy}),i&&t.jsx("span",{className:ue.copiedText,children:"Copied!"})]})]})})]})},$i="_header_1cvtq_1",Ti="_account_1cvtq_16",Ei="_name_1cvtq_27",qi="_address_1cvtq_31",Di="_icon_1cvtq_35",Pi="_copied_1cvtq_42",Ri="_button_1cvtq_57",Bi="_qr_1cvtq_68",Fi="_disconnect_1cvtq_72",Mi="_label_1cvtq_82",Oi="_expanded_1cvtq_90",ge={header:$i,account:Ti,name:Ei,address:qi,icon:Di,copied:Pi,button:Ri,qr:Bi,disconnect:Fi,label:Mi,expanded:Oi},Ui=()=>{const e=Gt(),{connector:s}=ve.useAccount(),n=zr(),{address:r,username:o}=fe(),a=o??r,[i,l]=f.useState(!1),c=f.useRef(null),d=Je.useSpring({width:i?140:52,config:{tension:500,friction:30,clamp:!0}}),u=()=>{i?n():l(!0)},m=()=>{i&&(c.current=setTimeout(()=>{l(!1)},500))},h=()=>{c.current&&(clearTimeout(c.current),c.current=null)};return f.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),s?t.jsxs("header",{className:ge.header,children:[t.jsx(ps,{value:r,children:({copy:_,copied:g})=>t.jsxs("button",{className:B(ge.account,{[ge.copied]:g}),onClick:_,children:[t.jsx(Q,{src:s.icon,width:18,height:18}),t.jsx("div",{className:ge.address,children:w.truncate(r)}),t.jsx("div",{className:ge.name,children:w.truncate(a)}),t.jsx(k.IconCopy,{className:ge.icon,size:12}),g?"Copied!":""]})}),e.metadata?.is_l1&&t.jsx(_t,{title:"Initia address",content:()=>t.jsx(Ai,{}),className:B(ge.button,ge.qr),children:t.jsx(k.IconQrCode,{size:16})}),t.jsxs(Je.animated.button,{className:B(ge.button,ge.disconnect,{[ge.expanded]:i}),style:d,onClick:u,onMouseLeave:m,onMouseEnter:h,children:[t.jsx(k.IconSignOut,{size:16}),t.jsx("span",{className:ge.label,children:"Disconnect"})]})]}):null},Li="_overlay_1dhd9_1",zi="_content_1dhd9_27",Ki="_inner_1dhd9_58",Ws={overlay:Li,content:zi,inner:Ki},Hi=({children:e})=>{const{isDrawerOpen:s,closeDrawer:n}=Tt(),{setContainer:r}=f.useContext(Tn),o=qs(),a=ti(),i=G.useAtomValue(Ts),l=A.useIsMutating({mutationKey:[Kr]}),c=()=>{const _=l?"User exited before response arrived. Transaction may succeed or fail.":"User rejected";n(),i?.reject(new Error(_))},d=ks(),u=he(),m=A.useQueryClient(),h={fallbackRender:({error:_,resetErrorBoundary:g})=>{const p=()=>{d==="/bridge"&&(localStorage.removeItem(U.BRIDGE_SRC_CHAIN_ID),localStorage.removeItem(U.BRIDGE_SRC_DENOM),localStorage.removeItem(U.BRIDGE_DST_CHAIN_ID),localStorage.removeItem(U.BRIDGE_DST_DENOM)),u("/"),m.clear(),g()};return t.jsxs(ze,{children:[t.jsx(X,{error:!0,children:_.message}),t.jsx(re,{children:t.jsx(V.White,{onClick:p,children:"Retry"})})]})}};return t.jsx(Ie.Dialog.Root,{open:s,onOpenChange:_=>!_&&c(),modal:!1,children:t.jsxs(Ie.Dialog.Portal,{container:a,children:[o&&t.jsx(Ie.Dialog.Backdrop,{className:Ws.overlay,onClick:c,children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",width:"14",height:"14",children:[t.jsx("path",{d:"M7.168 14.04 l 6.028 -6.028 l -6.028 -6.028 L8.57 .582 L16 8.012 l -7.43 7.43 l -1.402 -1.402 Z"}),t.jsx("path",{d:"M0.028 14.04 l 6.028 -6.028 L0.028 1.984 L1.43 .582 l 7.43 7.43 l -7.43 7.43 L0.028 14.04 Z"})]})}),t.jsx(Ie.Dialog.Popup,{className:Ws.content,children:t.jsxs("div",{className:B(Ws.inner,"body"),ref:r,children:[o&&t.jsx(ni,{}),t.jsx(ci,{}),t.jsx(Ui,{}),t.jsx(pe,{errorBoundaryProps:h,children:e})]})})]})})},mn=({children:e})=>{const s=f.useRef(null),[n,r]=f.useState(0),o=Je.useSpring({height:n,config:{tension:500,friction:30,clamp:!0}});return f.useEffect(()=>{if(s.current){const{height:a}=s.current.getBoundingClientRect();r(a)}},[e]),e?t.jsx(Je.animated.div,{style:{overflow:"hidden",...o},children:t.jsx("div",{ref:s,children:e})}):null},Wi="_help_7m3jv_1",Qi="_icon_7m3jv_10",Vi="_info_7m3jv_17",Gi="_warning_7m3jv_21",Yi="_error_7m3jv_25",Zi="_success_7m3jv_31",Qs={help:Wi,icon:Qi,info:Vi,warning:Gi,error:Yi,success:Zi},It=({level:e,className:s,mt:n=8,children:r})=>{if(!r)return null;const o=()=>{switch(e){case"loading":return t.jsx(gt,{size:12});case"info":return t.jsx(k.IconInfoFilled,{size:12});case"warning":case"error":return t.jsx(k.IconWarningFilled,{size:12});default:return t.jsx(k.IconCheckCircleFilled,{size:12})}};return t.jsxs("div",{className:B(Qs.help,e&&Qs[e],s),style:{marginTop:n},children:[t.jsx("div",{className:Qs.icon,children:o()}),r]})},Ji="_stack_14kq8_1",Xi="_help_14kq8_6",ec="_info_14kq8_14",tc="_warning_14kq8_19",sc="_error_14kq8_24",nc="_success_14kq8_29",_n={stack:Ji,help:Xi,info:ec,warning:tc,error:sc,success:nc},rc=({children:e})=>!e||Array.isArray(e)&&e.filter(Boolean).length===0?null:t.jsx(mn,{children:t.jsx("div",{className:_n.stack,children:e})}),ne=e=>t.jsx(It,{...e,className:B(_n.help,_n[e.level]),mt:0});ne.Stack=rc;const oc="_root_hypwm_1",ac="_item_hypwm_10",ic="_chevron_hypwm_14",cc="_trigger_hypwm_19",lc="_content_hypwm_39",Rt={root:oc,item:ac,chevron:ic,trigger:cc,content:lc};function dc(e){const{list:s,getKey:n,renderHeader:r,renderContent:o,footer:a,...i}=e;return t.jsxs(Y.Accordion.Root,{className:Rt.root,type:"multiple",...i,children:[s.map((l,c)=>t.jsxs(Y.Accordion.Item,{className:Rt.item,value:n?.(l)??String(c),children:[t.jsx(Y.Accordion.Header,{children:t.jsxs(Y.Accordion.Trigger,{className:Rt.trigger,children:[r(l),t.jsx(k.IconChevronDown,{className:Rt.chevron,size:16})]})}),t.jsx(Y.Accordion.Content,{className:Rt.content,children:o(l)})]},n?.(l)??c)),a]})}const uc=10;function no(){const e=ae();return(s,n)=>A.queryOptions({queryKey:Is.txs(s.indexerUrl,e).queryKey,queryFn:async()=>{if(!n.enabled)return[];const r={"pagination.reverse":!0,"pagination.limit":uc},{txs:o}=await Z.create({prefixUrl:s.indexerUrl}).get(`indexer/tx/v1/txs/by_account/${e}`,{searchParams:r}).json();return o},staleTime:K.SECOND})}function hc(e,s){const n=no();return A.useSuspenseQuery(n(e,s))}function mc(e,s){const n=e.flatMap((r,o)=>(s[o]??[]).map(i=>({...i,chain:r})));return v.sortWith([v.descend(r=>new Date(r.timestamp).getTime())])(n)}const _c=()=>{const e=oe(),s=no(),n=A.useQueries({queries:e.map(i=>s(i,{enabled:!0}))}),r=n.map(v.prop("data")),o=mc(e,r),a=n.some(i=>i.isLoading);return{activities:o,isLoading:a}};function ro(e){const{data:s}=A.useSuspenseQuery({queryKey:ws.gasPrices(e).queryKey,queryFn:async()=>{if(e.metadata?.is_l1){const{restUrl:n}=e,{gas_prices:r}=await Z.create({prefixUrl:n}).get("initia/tx/v1/gas_prices").json();return r.toSorted(v.descend(({denom:o})=>o==="uinit")).map(({denom:o,amount:a})=>{const i=o==="uinit"?1:br;return{amount:M(a).times(i).toFixed(18),denom:o}})}return e.fees.fee_tokens.map(({denom:n,fixed_min_gas_price:r})=>{if(v.isNil(r))throw new Error(`${n} has no price`);return{amount:String(r),denom:n}})},staleTime:K.SECOND});return s}function oo(e){const s=ae(),{data:n}=hc(e,{enabled:e.fees.fee_tokens.length>=2});if(e.fees.fee_tokens.length===0)return null;const r=e.fees.fee_tokens[0].denom;if(e.fees.fee_tokens.length===1)return r;try{return n.find(({tx:a})=>a.auth_info.signer_infos.some(i=>w.InitiaAddress.equals(s,Ze.computeAddress(`0x${W.toHex(dn.Secp256k1.uncompressPubkey(W.fromBase64(i.public_key.key)))}`))))?.tx.auth_info.fee.amount[0]?.denom??r}catch{return r}}const fc="_value_9u3br_1",pc="_trigger_9u3br_7",gc="_icon_9u3br_23",xc="_content_9u3br_32",yc="_item_9u3br_40",Bt={value:fc,trigger:pc,icon:gc,content:xc,item:yc},jc=({options:e,value:s,onChange:n})=>{const r=mt(),{txRequest:o}=Wr(),a=Oe(o.chainId),i=Ue(a),l=(p,j)=>{if(w.formatAmount(p,{decimals:j})==="0.000000")return 8},c=({amount:[{amount:p,denom:j}]})=>{if(M(p).isZero())return"0";const{symbol:S,decimals:N}=i(j),I=l(p,N);return`${w.formatAmount(p,{decimals:N,dp:I})} ${S}`};if(e.length===1)return t.jsx("span",{className:"monospace",children:c(e[0])});const d=e.find(p=>p.amount[0].denom===s);if(!d)throw new Error("Fee option not found");const[{amount:u,denom:m}]=d.amount,{decimals:h,symbol:_}=i(m),g=l(u,h);return t.jsxs(Re.Select.Root,{value:s,onValueChange:n,modal:!1,children:[t.jsxs("div",{className:Bt.value,children:[t.jsx("span",{className:"monospace",children:w.formatAmount(u,{decimals:h,dp:g})}),t.jsxs(Re.Select.Trigger,{className:Bt.trigger,children:[t.jsx(Re.Select.Value,{children:_}),t.jsx(Re.Select.Icon,{className:Bt.icon,children:t.jsx(k.IconChevronDown,{size:16})})]})]}),t.jsx(Re.Select.Portal,{container:r,children:t.jsx(Re.Select.Positioner,{className:Bt.content,alignItemWithTrigger:!1,sideOffset:6,align:"end",children:t.jsx(Re.Select.Popup,{children:e.map(p=>{const[{denom:j}]=p.amount;return t.jsx(Re.Select.Item,{className:Bt.item,value:j,children:t.jsx(Re.Select.ItemText,{children:c(p)})},j)})})})})]})},vc="_root_7u427_1",bc="_trigger_7u427_5",wc="_chevron_7u427_13",Cc="_panel_7u427_27",Ic="_details_7u427_38",Nc="_row_7u427_47",bt={root:vc,trigger:bc,chevron:wc,panel:Cc,details:Ic,row:Nc},Sc=({spend:e,fee:s,total:n,balance:r,symbol:o,decimals:a})=>{const i=[e&&{label:"Spend",value:e},{label:"Fee",value:s},e&&{label:"Required (spend + fee)",value:n},{label:"Balance",value:r}].filter(Boolean),l=a===6?void 0:8;return t.jsxs(Ls.Collapsible.Root,{className:bt.root,children:[t.jsxs(Ls.Collapsible.Trigger,{className:bt.trigger,children:[t.jsx("span",{children:"Insufficient balance for fee"}),t.jsx(k.IconChevronDown,{className:bt.chevron,size:16})]}),t.jsx(Ls.Collapsible.Panel,{className:bt.panel,children:t.jsx("div",{className:bt.details,children:i.map(({label:c,value:d})=>t.jsxs("div",{className:bt.row,children:[t.jsx("span",{children:c}),t.jsxs("span",{children:[w.formatAmount(d,{decimals:a,dp:l})," ",o]})]},c))})})]})};function gs(e){switch(typeof e){case"string":return e;case"number":case"bigint":return e.toString();case"boolean":return e?"true":"false";case"object":return e===null?"null":e instanceof Uint8Array?W.toBase64(e):Array.isArray(e)?`[${e.map(gs).join(",")}]`:JSON.stringify(e,(s,n)=>typeof n=="bigint"?n.toString():n);default:return"unknown"}}const kc="_container_1xzyq_1",Ac="_toggle_1xzyq_5",$c="_list_1xzyq_11",Tc="_arg_1xzyq_16",Ec="_type_1xzyq_21",Ft={container:kc,toggle:Ac,list:$c,arg:Tc,type:Ec},qc=ke.createQueryKeys("interwovenkit:move",{abi:(e,s,n,r)=>[e,s,n,r]}),Dc=({type:e,arg:s})=>gs(w.resolveBcsType(e).parse(s)),Pc=({msg:e,chainId:s,fallback:n})=>{const[r,o]=Ne.useToggle(!1),{restUrl:a}=Oe(s),{moduleAddress:i,moduleName:l,functionName:c,args:d}=e,{data:u}=A.useQuery({queryKey:qc.abi(a,i,l,c).queryKey,queryFn:async()=>{const h=await Z.create({prefixUrl:a}).get(`initia/move/v1/accounts/${i}/modules/${l}`).json(),g=JSON.parse(h.module.abi).exposed_functions.find(({name:p})=>p===c);if(!g)throw new Error(`Function ${c} not found in module ${l}`);return g.params.filter(p=>!p.startsWith("&"))},staleTime:K.INFINITY});if(!u)return n;const m=(h,_)=>{const g=u[_];return t.jsxs("div",{className:Ft.arg,children:[t.jsx("div",{className:Ft.type,children:g}),t.jsx(jr.ErrorBoundary,{fallback:t.jsx("div",{className:"error",children:"Error decoding argument"}),children:t.jsx(Dc,{type:g,arg:h})})]},_)};return t.jsxs("div",{className:Ft.container,children:[t.jsx(V.Small,{className:Ft.toggle,onClick:o,disabled:!u,children:r?"Encode":"Decode"}),r?t.jsx("div",{className:Ft.list,children:d.map(m)}):n]})},Rc="_list_r67rl_1",Bc="_key_r67rl_8",Fc="_value_r67rl_13",Vs={list:Rc,key:Bc,value:Fc},Mc=({message:e,chainId:s})=>{const{typeUrl:n,value:r}=e;return t.jsx("div",{className:Vs.list,children:Object.entries(r).map(([o,a])=>t.jsxs("div",{children:[t.jsx("div",{className:Vs.key,children:o}),t.jsx("div",{className:Vs.value,children:n==="/initia.move.v1.MsgExecute"&&o==="args"?t.jsx(Pc,{msg:r,chainId:s,fallback:gs(a)}):gs(a)})]},o))})},Oc="_item_1n572_1",Uc="_title_1n572_10",Lc="_content_1n572_14",Gs={item:Oc,title:Uc,content:Lc},Ys=({title:e,content:s})=>t.jsxs("div",{className:Gs.item,children:[t.jsx("div",{className:Gs.title,children:e}),t.jsx("div",{className:Gs.content,children:s})]});function Se(e){if(e&&M(e).gt(0)&&M(e).lt(.01))return"<$0.01";const s=w.formatNumber(e,{dp:2});return s?`$${s}`:""}function ao(e,s){const n={};for(const r of e)if(r.attributes.some(a=>a.key==="msg_index")){if(r.type==="coin_spent"){const a=r.attributes.find(l=>l.key==="spender")?.value,i=r.attributes.find(l=>l.key==="amount")?.value;if(a===s&&i){const[l,c]=i.match(/^(\d+)(.+)$/)?.slice(1)||[];if(l&&c){const d=n[c]||BigInt(0);n[c]=d-BigInt(l)}}}if(r.type==="coin_received"){const a=r.attributes.find(l=>l.key==="receiver")?.value,i=r.attributes.find(l=>l.key==="amount")?.value;if(a===s&&i){const[l,c]=i.match(/^(\d+)(.+)$/)?.slice(1)||[];if(l&&c){const d=n[c]||BigInt(0);n[c]=d+BigInt(l)}}}}return Object.entries(n).filter(([,r])=>r!==BigInt(0)).map(([r,o])=>({amount:o.toString(),denom:r}))}function io(e,s){const n={};for(const r of e)if(r.attributes.some(a=>a.key==="msg_index")&&r.type==="move"){const a=r.attributes.find(c=>c.key==="type_tag")?.value,i=r.attributes.find(c=>c.key==="data")?.value;if(!a||!i)continue;let l;try{l=JSON.parse(i)}catch{continue}if(a==="0x1::fungible_asset::WithdrawEvent"){const c=l.store_addr,d=l.amount,u=l.metadata_addr;if(c&&d&&u&&w.createUserDerivedObjectAddress(s,u)===c){const h=n[u]||BigInt(0);n[u]=h-BigInt(d)}}if(a==="0x1::fungible_asset::DepositEvent"){const c=l.store_addr,d=l.amount,u=l.metadata_addr;if(c&&d&&u&&w.createUserDerivedObjectAddress(s,u)===c){const h=n[u]||BigInt(0);n[u]=h+BigInt(d)}}}return Object.entries(n).filter(([,r])=>r!==BigInt(0)).map(([r,o])=>({amount:o.toString(),metadata:r}))}const co=({metadata:e,chain:s,children:n})=>{const{restUrl:r}=s,{data:o}=A.useSuspenseQuery({queryKey:fs.denom(r,e).queryKey,queryFn:()=>Z.create({prefixUrl:r}).get("initia/move/v1/denom",{searchParams:{metadata:e}}).json(),select:({denom:a})=>a,staleTime:K.INFINITY});return n(o)},zc="_root_jioyr_1",Kc="_title_jioyr_7",Hc="_changes_jioyr_13",Wc="_change_jioyr_13",Qc="_amount_jioyr_34",Vc="_text_jioyr_40",Gc="_value_jioyr_47",ut={root:zc,title:Kc,changes:Hc,change:Wc,amount:Qc,text:Vc,value:Gc},lo=({amount:e,asset:s,price:n})=>{const{denom:r,symbol:o,decimals:a,logoUrl:i}=s,l=w.formatAmount(e,{decimals:a}),c=n&&M(w.fromBaseUnit(e,{decimals:a})).times(n).abs();return t.jsxs("div",{className:ut.change,children:[t.jsxs("div",{className:ut.amount,children:[t.jsx(Q,{src:i,width:14,height:14,logo:!0}),t.jsxs("span",{className:ut.text,children:[l," ",o||r]})]}),c&&t.jsx("div",{className:ut.value,children:Se(c)})]})},Yc=({changes:e,chain:s})=>{const n=Ue(s),{data:r}=Cs(s);return e.map(({amount:o,denom:a},i)=>{const l=n(a),c=r?.find(({id:d})=>d===a)?.price;return t.jsx(lo,{amount:o,asset:l,price:c},i)})},Zc=({changes:e,chain:s})=>{const n=Ue(s),{data:r}=Cs(s);return e.map(({amount:o,metadata:a},i)=>t.jsx(co,{metadata:a,chain:s,children:l=>{const c=r?.find(({id:d})=>d===l)?.price;return t.jsx(lo,{amount:o,asset:n(l),price:c})}},i))};function Jc(e,s){return typeof s=="bigint"?s.toString():s}const Xc=ke.createQueryKeys("interwovenkit:tx",{simulate:e=>[JSON.stringify(e,Jc)]}),el=({messages:e,memo:s,chainId:n})=>{const{initiaAddress:r,hexAddress:o}=fe(),a=Oe(n),{simulateTx:i}=Sn(),{data:l}=A.useSuspenseQuery({queryKey:Xc.simulate({messages:e,memo:s,chainId:n}).queryKey,queryFn:()=>i({messages:e,memo:s,chainId:n}),staleTime:K.SECOND}),c=h=>t.jsxs("div",{className:ut.root,children:[t.jsx("h2",{className:ut.title,children:"Estimated changes"}),t.jsx("div",{className:ut.changes,children:h})]});if(!l)return null;const d=l.result?.events??[];if(d.length===0)return null;if(a.metadata?.is_l1||a.metadata?.minitia?.type==="minimove"){const h=io(d,o),[_]=Zn(h);return _.length===0?null:c(t.jsx(Zc,{changes:_,chain:a}))}const u=ao(d,r),[m]=Zn(u);return m.length===0?null:c(t.jsx(Yc,{changes:m,chain:a}))};function Zn(e){return v.partition(s=>new M(s.amount).isNegative(),e)}const tl="_title_kspdu_1",sl="_meta_kspdu_7",nl="_footer_kspdu_14",Zs={title:tl,meta:sl,footer:nl},uo=()=>{const{txRequest:e,resolve:s,reject:n}=Wr(),{messages:r,memo:o,chainId:a,gas:i,gasAdjustment:l,spendCoins:c}=e,d=ae(),u=$t(),m=In(),h=Oe(a),_=Cn(h),g=ro(h),p=oo(h),j=Ue(h),S=(e.gasPrices??g).map(({amount:x,denom:$})=>qe.calculateFee(Math.ceil(i*l),qe.GasPrice.fromString(x+$))),N=S.map(x=>x.amount[0]),I=x=>{const $=_.find(O=>O.denom===x)?.amount??"0",T=N.find(O=>O.denom===x)?.amount??"0",R=c.filter(O=>O.denom===x).reduce((O,be)=>M(O).plus(be.amount),M("0")),L=M(T).plus(R),q=M($).gte(L),{symbol:H,decimals:ie}=j(x);return{symbol:H,decimals:ie,spend:R.gt(0)?R.toFixed():null,fee:T,total:L.toFixed(),balance:$,isSufficient:q}},b=()=>{if(p&&I(p).isSufficient)return p;for(const{denom:x}of N)if(I(x).isSufficient)return x;return N[0]?.denom},[E,D]=f.useState(b),{mutate:F,isPending:C}=A.useMutation({mutationKey:[Kr],mutationFn:async()=>{const x=S.find(T=>T.amount[0].denom===E);if(!x)throw new Error("Fee not found");if(!u)throw new Error("Signer not initialized");const $=await m(a,d,r,x,o);await s($)},onError:async x=>{n(x)}}),P=I(E),y=!P.isSufficient;return t.jsxs(t.Fragment,{children:[t.jsxs(ze,{children:[t.jsx("h1",{className:Zs.title,children:"Confirm tx"}),t.jsxs("div",{className:Zs.meta,children:[t.jsx(Ys,{title:"Chain",content:a}),t.jsx(Ys,{title:"Tx fee",content:t.jsx(jc,{options:S,value:E,onChange:D})}),o&&t.jsx(Ys,{title:"Memo",content:o}),y&&t.jsx(ne,{level:"error",children:t.jsx(Sc,{...P})})]}),t.jsx(el,{messages:r,memo:o,chainId:a}),t.jsx(dc,{list:r,renderHeader:({typeUrl:x})=>vs.sentenceCase(x.split(".").pop().replace(/^Msg/,"")),renderContent:x=>t.jsx(Mc,{message:x,chainId:a})})]}),t.jsxs(re,{className:Zs.footer,children:[t.jsx(V.Outline,{onClick:()=>n(new Error("User rejected")),disabled:C,children:"Reject"}),t.jsx(V.White,{onClick:()=>F(),disabled:y,loading:C,children:"Approve"})]})]})},rl=({children:e})=>{const[{title:s,content:n,path:r},o]=f.useState({}),[a,i]=f.useState(!1),l=G.useAtomValue(Ts),c=f.useCallback(m=>{o(m),i(!0)},[]),d=f.useCallback(()=>{o({}),i(!1)},[]),u=f.useCallback(m=>{m||(l?.reject(new Error("User rejected")),o({})),i(m)},[l]);return t.jsxs(Ur.Provider,{value:{openModal:c,closeModal:d},children:[e,t.jsx(so,{title:s,open:a,onOpenChange:u,children:t.jsx(pe,{children:r==="/tx"?t.jsx(uo,{}):n})})]})},ol="_container_1zg8z_1",al="_toast_1zg8z_10",il="_info_1zg8z_23",cl="_success_1zg8z_27",ll="_error_1zg8z_31",dl="_icon_1zg8z_36",ul="_content_1zg8z_43",hl="_title_1zg8z_46",ml="_description_1zg8z_51",_l="_close_1zg8z_72",Qe={container:ol,toast:al,info:il,success:cl,error:ll,icon:dl,content:ul,title:hl,description:ml,close:_l},fl=({notification:e,onClose:s,...n})=>{const r=Je.useTransition(e,{keys:a=>a?.id||"empty",from:{transform:"translateY(-52px)",opacity:0},enter:{transform:"translateY(0px)",opacity:1},leave:{transform:"translateY(-52px)",opacity:0},config:{tension:500,friction:30,clamp:!0}}),o=a=>{switch(a){case"loading":return t.jsx(gt,{size:16});case"info":case"success":return t.jsx(k.IconCheckCircleFilled,{size:16});case"error":return t.jsx(k.IconCloseCircleFilled,{size:16});default:return null}};return r((a,i)=>{if(!i)return null;const{type:l,title:c,description:d}=i,u=o(l);return t.jsx(Je.animated.div,{style:a,className:Qe.container,children:t.jsxs("div",{className:B(Qe.toast,l&&Qe[l]),...n,children:[u&&t.jsx("div",{className:Qe.icon,children:u}),t.jsxs("div",{className:Qe.content,children:[t.jsx("p",{className:Qe.title,children:c}),d&&t.jsx("div",{className:Qe.description,children:d})]}),t.jsx("button",{className:Qe.close,onClick:s,children:t.jsx(k.IconClose,{size:14})})]})})})},Js=5e3,pl=({children:e})=>{const s=mt(),[n,r]=f.useState(null),o=f.useRef(null),a=f.useRef(!1),i=()=>{o.current&&(clearTimeout(o.current),o.current=null)},l=f.useCallback(()=>{i(),r(null)},[]),c=f.useCallback(h=>{i(),r({...h,id:zn.nanoid()}),h.autoHide&&!a.current&&(o.current=setTimeout(()=>l(),Js))},[l]),d=f.useCallback(h=>{i(),r(_=>_?{..._,...h}:{...h,id:zn.nanoid()}),h.autoHide&&!a.current&&(o.current=setTimeout(()=>l(),Js))},[l]),u=()=>{i(),a.current=!0},m=()=>{i(),a.current=!1,n?.autoHide&&(o.current=setTimeout(()=>l(),Js))};return f.useEffect(()=>()=>i(),[]),t.jsxs(eo.Provider,{value:{showNotification:c,updateNotification:d,hideNotification:l},children:[e,s&&Qo.createPortal(t.jsx(fl,{notification:n,onClose:l,onMouseEnter:u,onMouseLeave:m}),s)]})},gl=({children:e})=>{const[s,n]=f.useState(null);return t.jsx(Tn.Provider,{value:{container:s,setContainer:n},children:e})},xl="_container_1a4ds_1",yl="_badge_1a4ds_5",Jn={container:xl,badge:yl},ho=e=>{const{offset:s=-4,disabled:n,children:r,className:o}=e;return t.jsxs("div",{className:B(Jn.container,o),children:[r,!n&&t.jsx("div",{className:Jn.badge,style:{right:s,top:s}})]})},jl="_header_acels_1",vl="_back_acels_11",bl="_title_acels_23",Xs={header:jl,back:vl,title:bl},xt=({title:e,backButton:s,extra:n,children:r})=>t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:Xs.header,children:[t.jsx(Nn,{to:s??-1,className:Xs.back,shouldReset:!!s,children:t.jsx(k.IconBack,{size:16})}),t.jsx("h1",{className:Xs.title,children:e}),n]}),t.jsx(ze,{children:r})]});function mo(){const{initiaAddress:e,hexAddress:s}=fe(),n=pt(),r=Zt();return o=>{const a=n(o);switch(r(a)){case"initia":return e;case"evm":return s;default:return""}}}function _o(){const e=pt(),s=Zt();return(n,r)=>{const o=e(r);switch(s(o)){case"initia":return w.InitiaAddress.validate(n);case"evm":return Ze.isAddress(n);case"cosmos":try{return W.fromBech32(n).prefix===o.bech32_prefix}catch{return!1}default:return!1}}}function wl(){const e=pt(),s=Zt();return({initialAddress:n,initialChainId:r,chainId:o,fallbackAddress:a})=>{const i=e(r),l=s(i),c=e(o),d=s(c);if(l==="evm"&&d==="initia")return w.InitiaAddress(n).bech32;if(l==="initia"&&d==="evm")return w.InitiaAddress(n).hex;if(l===d)return n;if(a){if(d==="initia")return w.InitiaAddress(a).bech32;if(d==="evm")return w.InitiaAddress(a).hex}return""}}function Cl(){return le().network_type==="testnet"}function et(){return ce.useFormContext()}function Il(){const e=ft(),s=Cl(),n={quantity:"",slippagePercent:"0.5",sender:"",cosmosWalletName:"",recipient:""},r={...n,srcChainId:"initiation-2",srcDenom:"uusdc",dstChainId:"initiation-2",dstDenom:"uinit"},o={...n,srcChainId:"interwoven-1",srcDenom:"ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4",dstChainId:"interwoven-1",dstDenom:"uinit"},a=v.pickBy(i=>i!==null,{srcChainId:localStorage.getItem(U.BRIDGE_SRC_CHAIN_ID),srcDenom:localStorage.getItem(U.BRIDGE_SRC_DENOM),dstChainId:localStorage.getItem(U.BRIDGE_DST_CHAIN_ID),dstDenom:localStorage.getItem(U.BRIDGE_DST_DENOM),quantity:localStorage.getItem(U.BRIDGE_QUANTITY),slippagePercent:localStorage.getItem(U.BRIDGE_SLIPPAGE_PERCENT)});return{...s?r:o,...a,...e}}const Nl="_root_xwz5z_1",Sl="_header_xwz5z_6",kl="_title_xwz5z_12",Al="_warning_xwz5z_18",$l="_content_xwz5z_22",Tl="_footer_xwz5z_26",El="_secondary_xwz5z_36",at={root:Nl,header:Sl,title:kl,warning:Al,content:$l,footer:Tl,secondary:El},fo=e=>{const{type:s,icon:n,title:r,children:o,primaryButton:a,secondaryButton:i}=e;return t.jsxs(ze,{className:at.root,children:[t.jsxs("header",{className:B(at.header,s&&at[s]),children:[n,t.jsx("h1",{className:at.title,children:r})]}),t.jsx("div",{className:at.content,children:o}),t.jsxs("footer",{className:at.footer,children:[t.jsx(V.White,{onClick:a.onClick,sm:!0,fullWidth:!0,children:a.label}),t.jsxs("button",{className:at.secondary,onClick:i.onClick,children:[t.jsx("span",{children:i.label}),t.jsx(k.IconChevronRight,{size:14})]})]})]})},ql="_list_tmcxc_1",Dl="_row_tmcxc_8",Pl="_dt_tmcxc_19",Rl="_asset_tmcxc_25",rs={list:ql,row:Dl,dt:Pl,asset:Rl},Bl=({list:e,onNavigate:s,onDismiss:n})=>{const r=le(),o=Xe(),a=Ue(r);return t.jsx(fo,{title:"Ready to claim",primaryButton:{label:"View withdrawal status",onClick:s},secondaryButton:{label:"Do not show again",onClick:n},children:t.jsx("div",{className:rs.list,children:e.toSorted((i,l)=>i.chainId.localeCompare(l.chainId)).map(({txHash:i,chainId:l,amount:c,denom:d})=>{const u=o(l),{decimals:m,symbol:h}=a(d),_=w.formatAmount(c,{decimals:m});return t.jsxs("div",{className:rs.row,children:[t.jsxs("div",{className:rs.dt,children:[t.jsx(Q,{src:u.logoUrl,width:16,height:16,logo:!0}),t.jsx("span",{children:u.name})]}),t.jsxs("span",{className:rs.asset,children:[_," ",h]})]},i)})})})};function en(e,s){return e.chainId===s.chainId&&e.txHash===s.txHash}const os=({chainId:e,txHash:s})=>`${U.OP_REMINDER}:${e}:${s}`,Fl=Vo.atomWithStorage(U.OP_REMINDER,[]);function qt(){const e=ae(),[s=[],n]=G.useAtom(Fl),r=f.useMemo(()=>s.map(c=>{const d=localStorage.getItem(os(c));return d?JSON.parse(d):null}).filter(c=>{if(!c)return!1;const{recipient:d,claimableAt:u}=c;return d!==e?!1:At.isPast(u)}),[e,s]),o=f.useCallback((c,d)=>{s.some(u=>en(u,c))||(n((u=[])=>[...u,c]),localStorage.setItem(os(c),JSON.stringify(d)))},[s,n]),a=f.useCallback(c=>{n((d=[])=>d.filter(u=>!en(u,c))),localStorage.removeItem(os(c))},[n]),i=f.useCallback(c=>{const d=c.filter(u=>!s.some(m=>en(m,u)));d.length!==0&&n((u=[])=>[...u,...d])},[s,n]),l=f.useCallback((c,d)=>{localStorage.setItem(os(c),JSON.stringify(d)),n((u=[])=>[...u])},[n]);return{reminders:r,addReminder:o,removeReminder:a,syncReminders:i,setReminder:l}}function po(){const e=he(),{openModal:s,closeModal:n}=As(),{reminders:r,setReminder:o}=qt();f.useEffect(()=>{const a=r.filter(c=>!c.dismissed);if(a.length===0)return;const i=()=>{const c=a.every(d=>d.chainId===a[0].chainId)?a[0].chainId:void 0;e("/op/withdrawals",{chainId:c}),l()},l=()=>{n();for(const c of a)o(c,{...c,dismissed:!0})};s({content:f.createElement(Bl,{list:a,onNavigate:i,onDismiss:l})})},[r,n,e,s,o])}const Ml="_wrapper_5ssm8_1",Ol="_balance_5ssm8_11",Ul="_button_5ssm8_15",tn={wrapper:Ml,balance:Ol,button:Ul},go=({onClick:e,children:s,disabled:n})=>t.jsxs("div",{className:tn.wrapper,children:[t.jsx(k.IconWallet,{size:16}),t.jsx("span",{className:tn.balance,children:s}),t.jsx("button",{type:"button",tabIndex:-1,className:tn.button,onClick:()=>e(),disabled:n,children:"MAX"})]}),Ll="_fieldset_y241y_1",zl="_upper_y241y_9",Kl="_select_y241y_14",Hl="_account_y241y_19",Wl="_lower_y241y_24",Ql="_wrapper_y241y_25",Vl="_balance_y241y_32",Gl="_value_y241y_36",Yl="_error_y241y_49",Be={fieldset:Ll,upper:zl,select:Kl,account:Hl,lower:Wl,wrapper:Ql,balance:Vl,value:Gl,error:Yl},fn=e=>{const{selectButton:s,accountButton:n,quantityInput:r,balanceButton:o,value:a,errorMessage:i,hideNumbers:l}=e;return t.jsxs("div",{className:Be.fieldset,children:[t.jsxs("div",{className:Be.upper,children:[t.jsx("div",{className:Be.select,children:s}),t.jsx("div",{className:Be.account,children:n})]}),!l&&t.jsxs("div",{className:Be.lower,children:[r,t.jsxs("div",{className:Be.wrapper,children:[t.jsx("div",{className:Be.balance,children:o}),a&&t.jsx("div",{className:Be.value,children:a})]}),i&&t.jsxs("footer",{className:Be.error,children:[t.jsx(k.IconWarningFilled,{size:12}),t.jsx("p",{children:i})]})]})]})};function Jt(){const e=f.useRef(null),s=qs();return f.useEffect(()=>{s||e.current?.focus()},[s]),e}const Zl="_input_h8073_1",Jl={input:Zl};function Xn(e,s){const n=e.replace(/[^0-9.]/g,""),[r,...o]=n.split(".");return o.length===0?r:`${r}.${o.join("").slice(0,s)}`}function xo(e){const{name:s,control:n,dp:r=6,className:o,rules:a,...i}=e,l=Jt();return t.jsx(ce.Controller,{name:s,control:n,rules:a,render:({field:c})=>t.jsx("input",{...c,className:B(Jl.input,o),onChange:d=>c.onChange(Xn(d.target.value,r)),onPaste:d=>{d.preventDefault();const u=d.clipboardData.getData("text");if(!/^[0-9,]+(\.[0-9]+)?$/.test(u))return;const h=u.replace(/,/g,""),_=Xn(h,r);c.onChange(_)},placeholder:"0",inputMode:"decimal",autoComplete:"off",...i,ref:vr.mergeRefs([c.ref,l])})})}const Xl="_input_qpv94_1",ed="_placeholder_qpv94_18",pn={input:Xl,placeholder:ed},td=({children:e})=>t.jsx("p",{className:B(pn.input,{[pn.placeholder]:M(e).isZero()}),children:e}),xs=({balance:e,decimals:s})=>{const{control:n}=ce.useFormContext(),r={required:"Enter amount",validate:o=>M(o).isZero()?"Enter amount":M(w.toBaseUnit(o,{decimals:s})).gt(e??0)?"Insufficient balance":!0};return t.jsx(xo,{name:"quantity",control:n,className:pn.input,rules:r})};xs.ReadOnly=td;const sd="_tooltip_6zakp_1",nd="_arrow_6zakp_43",er={tooltip:sd,arrow:nd},Xt=({label:e,children:s,small:n,...r})=>t.jsxs(Y.Tooltip.Root,{...r,children:[t.jsx(Y.Tooltip.Trigger,{asChild:!0,children:s}),t.jsx(Y.Tooltip.Portal,{container:mt(),children:t.jsxs(Y.Tooltip.Content,{className:B(er.tooltip,{small:n}),collisionBoundary:mt(),collisionPadding:8,sideOffset:4,children:[e,t.jsx(Y.Tooltip.Arrow,{className:er.arrow})]})})]});function qn(e,s){const n=Le();return A.useQuery({queryKey:De.balances(s,e).queryKey,queryFn:()=>n.post("v2/info/balances",{json:{chains:{[s]:{address:e,denoms:[]}}}}).json(),select:({chains:r})=>e?r?r[s].denoms??{}:{}:{},enabled:!!e,staleTime:K.SECOND})}function rd(e,s,n){const{data:r={}}=qn(e,s);return v.path([n],r)}const od=[["d",1440*60],["h",3600],["m",60],["s",1]];function gn(e){if(!e)return;const{formattedParts:s}=od.reduce(({remainingSeconds:n,formattedParts:r},[o,a])=>{const i=Math.floor(n/a);return{remainingSeconds:n-i*a,formattedParts:i>0?[...r,`${i}${o}`]:r}},{remainingSeconds:e,formattedParts:[]});return s.join(" ")}function yo(e){return e?.map(s=>{const{amount:n,origin_asset:r}=s;return`${w.formatAmount(n,{decimals:r.decimals??0})} ${r.symbol}`}).join(", ")}function tr(e,s){const{watch:n}=et(),r=n(),o=Le(),a=$s(),i={...r,quantity:e},l=A.useQueryClient();return A.useQuery({queryKey:De.route(i,s?.isOpWithdraw).queryKey,queryFn:async()=>{const{srcChainId:c,srcDenom:d,quantity:u,dstChainId:m,dstDenom:h}=i,{decimals:_}=l.getQueryData(De.asset(c,d).queryKey)??{decimals:0},g={amount_in:w.toBaseUnit(u,{decimals:_}),source_asset_chain_id:c,source_asset_denom:d,dest_asset_chain_id:m,dest_asset_denom:h,is_op_withdraw:s?.isOpWithdraw},p=await o.post("v2/fungible/route",{json:g}).json(),j={quantity:i.quantity,srcChainId:i.srcChainId,srcDenom:i.srcDenom,dstChainId:i.dstChainId,dstDenom:i.dstDenom};return a("Bridge Simulation Success",j),p},enabled:!!Number(i.quantity)&&!s?.disabled,staleTime:K.MINUTE})}function ad(e){return A.useQuery({queryKey:De.routeErrorInfo(e||new Error).queryKey,queryFn:async()=>{if(!e||!(e instanceof Z.HTTPError))return null;const{response:s}=e;return(s.headers.get("content-type")??"").includes("application/json")?(await s.json()).info??null:null}})}function id(){const{watch:e}=et(),{srcChainId:s,srcDenom:n,dstChainId:r,dstDenom:o}=e(),a=Pe(s),i=Vt(a),l=Me(n,s),c=Me(o,r),d=le(),u=oe();return i==="initia"&&r===d.chainId&&l.symbol===c.symbol&&u.find(m=>m.chainId===s)?.metadata?.op_denoms?.includes(c.denom)}const cd="_label_9417z_1",ld="_wrapper_9417z_7",dd="_input_9417z_10",ud="_clear_9417z_18",as={label:cd,wrapper:ld,input:dd,clear:ud},Dn=({mode:e="onChange",myAddress:s,...n})=>{const{validate:r=w.InitiaAddress.validate,chainType:o="initia",onApply:a,ref:i}=n,l=Jt(),{control:c,getValues:d,setValue:u,formState:m}=ce.useFormContext(),h=d("recipient"),[_,g]=f.useState(h),p=Tr(),{data:j,isLoading:S,error:N}=A.useQuery({queryKey:Is.address(p.restUrl,_).queryKey,queryFn:()=>p.getAddress(_),staleTime:K.MINUTE,enabled:p.validateUsername(_)}),I=j??(r(_)?_:""),b=s&&w.InitiaAddress.equals(I,s),E=async()=>{try{const C=await navigator.clipboard.readText();g(C.trim())}catch{}};f.useEffect(()=>{e==="onChange"&&(!_&&!m.dirtyFields.recipient||u("recipient",j??_,{shouldValidate:!0,shouldDirty:!0}))},[m.dirtyFields.recipient,_,e,u,j]);const D=()=>{S||N||(u("recipient",I,{shouldValidate:!0,shouldDirty:!0}),a?.())},F=()=>{if(S)return t.jsx(It,{level:"loading",children:"Resolving username..."});if(N)return t.jsx(It,{level:"error",children:N.message});if(j)return t.jsx(It,{level:"success",className:"monospace",children:j});if(e==="onSubmit"&&_&&!I)return t.jsx(It,{level:"error",children:"Invalid address"})};return t.jsxs("div",{children:[t.jsxs("label",{htmlFor:"recipient",className:as.label,children:[t.jsx("span",{children:"Recipient"}),t.jsx(V.Small,{type:"button",tabIndex:-1,onClick:E,children:"Paste"})]}),t.jsxs("div",{className:as.wrapper,children:[t.jsx(ce.Controller,{name:"recipient",control:c,rules:{required:"Recipient address is required",validate:C=>r(C)||"Invalid address"},render:()=>t.jsx("input",{id:"recipient",className:B(as.input,"monospace"),value:_,onChange:C=>g(C.target.value.trim()),placeholder:o==="initia"?"Address or username":"Enter address",autoComplete:"off","data-has-value":_?"true":void 0,ref:e==="onSubmit"?vr.mergeRefs([i,l]):i})}),!!_&&t.jsx("button",{type:"button",className:as.clear,onClick:()=>g(""),"aria-label":"Clear recipient",children:t.jsx(k.IconCloseCircleFilled,{size:16})})]}),F(),b&&t.jsx(It,{children:"This is my address"}),e==="onSubmit"&&t.jsx(re,{extra:(!s||!!I&&!b)&&t.jsx(ne,{level:"warning",children:"Do not enter an exchange address. Tokens sent to an address that does not support bridge transfer will be irretrievable."}),children:t.jsx(V.White,{type:"button",onClick:D,disabled:S||!!N||!I,children:"Apply"})})]})},hd="_scrollable_1p1lw_1",md="_list_1p1lw_5",_d="_item_1p1lw_9",fd="_name_1p1lw_13",is={scrollable:hd,list:md,item:_d,name:fd};function jo({onSelect:e,list:s,...n}){const{getImage:r,getName:o,getKey:a,getIsLoading:i,getDisabled:l}=n;return t.jsx(ze,{className:is.scrollable,children:t.jsx("div",{className:is.list,children:s.map(c=>t.jsxs("button",{className:is.item,onClick:()=>e(c),disabled:i?.(c)||l?.(c),children:[t.jsx(Q,{src:r(c),width:28,height:28}),t.jsx("span",{className:is.name,children:o(c)}),i?.(c)&&t.jsx(gt,{size:16})]},a(c)))})})}function Ps(){const e=[{name:"Keplr",image:"https://assets.initia.xyz/images/wallets/Keplr.webp",getProvider:()=>window.keplr,fallbackUrl:"https://keplr.app/get"},{name:"Leap",image:"https://assets.initia.xyz/images/wallets/Leap.webp",getProvider:()=>window.leap,fallbackUrl:"https://leapwallet.io/download"}];return{list:e,find:n=>e.find(r=>r.name===n)}}const pd="_account_iwrlj_8",gd="_clear_iwrlj_27",xd="_white_iwrlj_38",Mt={account:pd,clear:gd,white:xd},sr=({type:e})=>{const{watch:s,setValue:n}=et(),{srcChainId:r,dstChainId:o,cosmosWalletName:a}=s(),l=s(e==="src"?"sender":"recipient"),c=Vt(Pe(o)),{list:d,find:u}=Ps(),m=u(a),h=mo(),_=_o(),g=h(o),p=w.InitiaAddress.equals(l,g),j=()=>t.jsx(_t,{title:"Connect wallet",content:I=>t.jsx(jo,{onSelect:async b=>{const E=b.getProvider();if(!E)return window.open(b.fallbackUrl,"_blank");const D=E.getOfflineSigner(r),[{address:F}]=await D.getAccounts();n("sender",F),n("cosmosWalletName",b.name),I()},list:d,getImage:b=>b.image,getName:b=>b.name,getKey:b=>b.name}),className:B(Mt.account,{[Mt.white]:!l}),children:l?t.jsxs(t.Fragment,{children:[m&&t.jsx(Q,{src:m.image,width:18,height:18}),t.jsx("span",{className:"monospace",children:w.truncate(l)})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"Connect wallet"}),t.jsx(k.IconChevronRight,{size:14})]})}),S=I=>t.jsx(_t,{title:"Recipient",content:b=>t.jsx(ze,{children:t.jsx(Dn,{mode:"onSubmit",myAddress:g,chainType:c,validate:E=>_(E,o),onApply:b})}),className:Mt.account,children:I}),N=()=>{switch(c){case"initia":case"evm":return p?S(t.jsx(k.IconWallet,{size:14})):t.jsxs("div",{className:Mt.account,children:[t.jsx("span",{className:"monospace",children:w.truncate(l)}),t.jsx("button",{type:"button",className:Mt.clear,onClick:()=>n("recipient",g,{shouldValidate:!0}),"aria-label":"Reset to my address",children:t.jsx(k.IconCloseCircleFilled,{size:14})})]});case"cosmos":return S(t.jsxs(t.Fragment,{children:[l?t.jsx("span",{className:"monospace",children:w.truncate(l)}):t.jsx("span",{children:"Recipient"}),t.jsx(k.IconEdit,{size:14})]}))}};switch(e){case"src":return j();case"dst":return N()}},yd="_images_cj4xz_1",sn={images:yd},Rs=({assetLogoUrl:e,assetLogoSize:s=36,chainLogoUrl:n,chainLogoSize:r=18,chainLogoOffset:o=6,className:a})=>t.jsxs("div",{className:B(sn.images,a),style:{position:"relative"},children:[t.jsx(Q,{src:e,width:s,height:s,className:sn.asset,logo:!0}),t.jsx(Q,{src:n,width:r,height:r,className:sn.chain,style:{position:"absolute",bottom:0,right:-1*o},logo:!0})]}),jd="_root_1ipwv_1",vd="_content_1ipwv_10",bd="_details_1ipwv_18",wd="_symbol_1ipwv_23",Cd="_chain_1ipwv_31",Id="_chevron_1ipwv_40",it={root:jd,content:vd,details:bd,symbol:wd,chain:Cd,chevron:Id},vo=({asset:e,chain:s,readOnly:n})=>{const r=t.jsxs("div",{className:it.content,children:[t.jsx(Rs,{assetLogoUrl:e.logoUrl,chainLogoUrl:s.logoUrl}),t.jsxs("div",{className:it.details,children:[t.jsx("div",{className:it.symbol,children:e.symbol||e.denom}),t.jsxs("div",{className:it.chain,children:["on ",s.name]})]})]});return n?t.jsx("div",{className:it.root,children:r}):t.jsxs("div",{className:it.root,children:[r,t.jsx(k.IconChevronDown,{size:16,className:it.chevron})]})};function Nd(e,s,n){return n.filter(r=>{const o=e.map(a=>r[a]).map(a=>String(a??"").toLowerCase());return v.any(v.includes(s.toLowerCase()),o)})}const Sd="_root_7yxgy_1",kd="_label_7yxgy_7",Ad="_input_7yxgy_19",$d="_hasValue_7yxgy_29",Td="_clear_7yxgy_33",Ot={root:Sd,label:kd,input:Ad,hasValue:$d,clear:Td},Bs=e=>{const{rootClassName:s,padding:n=16,iconSize:r=16,onClear:o,ref:a,...i}=e;return t.jsxs("div",{className:B(Ot.root,s,{[Ot.hasValue]:i.value}),style:{"--search-input-padding":`${n}px`,"--search-input-icon-size":`${r}px`},children:[t.jsx("label",{htmlFor:"search",className:Ot.label,children:t.jsx(k.IconSearch,{size:r})}),t.jsx("input",{className:Ot.input,id:"search",type:"text",maxLength:100,ref:a,...i}),i.value&&t.jsx("button",{type:"button",className:Ot.clear,"aria-label":"Clear search",onMouseDown:l=>l.preventDefault(),onClick:o,children:t.jsx(k.IconCloseCircleFilled,{size:r})})]})},Ed="_container_1voou_1",qd="_search_1voou_6",Dd="_list_1voou_10",Pd="_item_1voou_14",Rd="_logo_1voou_35",Bd="_info_1voou_39",Fd="_symbol_1voou_44",Md="_name_1voou_52",Od="_balance_1voou_58",Ud="_value_1voou_65",je={container:Ed,search:qd,list:Dd,item:Pd,logo:Rd,info:Bd,symbol:Fd,name:Md,balance:Od,value:Ud},es=e=>{const{assets:s,onSelect:n,renderAsset:r=(l,c)=>c(l)}=e,[o,a]=f.useState(""),i=Nd(["symbol"],o,s);return t.jsxs("div",{className:je.container,children:[t.jsx(Bs,{value:o,onChange:l=>a(l.target.value),onClear:()=>a(""),placeholder:"Search by symbol",rootClassName:je.search,padding:20,ref:Jt()}),i.length===0?t.jsx(X,{children:"No assets"}):t.jsx("div",{className:je.list,children:i.map(l=>t.jsx("button",{type:"button",className:je.item,onClick:()=>n(l.denom),children:r(l,c=>{const{denom:d,logoUrl:u,symbol:m,name:h,balance:_,decimals:g,value:p=0}=c;return t.jsxs(t.Fragment,{children:[t.jsx(Q,{src:u,width:32,height:32,className:je.logo,logo:!0}),t.jsxs("div",{className:je.info,children:[t.jsx("div",{className:je.symbol,children:m||d}),t.jsx("div",{className:je.name,children:h})]}),t.jsxs("div",{className:je.balance,children:[_&&t.jsx("div",{children:w.formatAmount(_,{decimals:g})}),p>0&&t.jsx("div",{className:je.value,children:Se(p)})]})]})})},l.denom))})]})},Ld=()=>t.jsxs("div",{className:je.container,children:[t.jsx(Bs,{rootClassName:je.search,padding:20,placeholder:"Search by symbol",readOnly:!0}),t.jsx(X,{children:"Loading..."})]});es.Placeholder=Ld;const zd="_stack_a3b9q_1",Kd="_title_a3b9q_8",Hd="_grid_a3b9q_15",Wd="_item_a3b9q_21",Qd="_button_a3b9q_25",Vd="_active_a3b9q_43",Nt={stack:zd,title:Kd,grid:Hd,item:Wd,button:Qd,active:Vd},ht=({label:e,chains:s,value:n,onSelect:r,getShowIndicator:o})=>t.jsxs("div",{children:[e&&t.jsx("h2",{className:Nt.title,children:e}),t.jsx("div",{className:Nt.grid,children:s.map(({chainId:a,name:i,logoUrl:l})=>t.jsx(ho,{offset:-2,disabled:!o?.(a),className:Nt.item,children:t.jsx(Xt,{label:i,disableHoverableContent:!0,children:t.jsx("button",{type:"button",className:B(Nt.button,{[Nt.active]:a===n}),onClick:()=>r(a),children:t.jsx(Q,{src:l,width:28,height:28,logo:!0})})})},a))})]}),Gd=({children:e})=>t.jsx("div",{className:Nt.stack,children:e});ht.Stack=Gd;const Yd=({address:e,chain:s,onSelect:n})=>{const r=kt(s.chain_id),{data:o={}}=qn(e,s.chain_id);return t.jsx(es,{assets:v.sortWith([v.descend(a=>a.symbol==="INIT"),v.descend(a=>a.value),({balance:a="0"},{balance:i="0"})=>M(i).comparedTo(a)??0,v.ascend(a=>a.symbol.toLowerCase())],r.filter(a=>!a.hidden).map(a=>{const{denom:i,symbol:l=w.truncate(i),logo_uri:c}=a,d=o[i]??{};return{...a,symbol:l,decimals:a.decimals??0,logoUrl:c??"",name:a.name??"",balance:d.amount,value:Number(d.value_usd??0)}})),onSelect:n})},Zd=({type:e,afterSelect:s})=>{const n=e==="src"?"srcChainId":"dstChainId",r=e==="src"?"srcDenom":"dstDenom",o=e==="src"?"sender":"recipient",a=Et(),i=$n(),{watch:l,setValue:c}=et(),d=l(o),u=l(n),m=l(r),[h,_]=f.useState(u),g=Pe(h),p=wl(),j=Yr(),[S,N]=v.partition(b=>j(b.chain_id),i.filter(b=>!b.hidden)),I=b=>{if(u===h&&m===b){s();return}c(n,h),c(r,b),s()};return t.jsxs(t.Fragment,{children:[t.jsxs(ht.Stack,{children:[t.jsx(ht,{label:"Interwoven Economy",chains:S.map(({chain_id:b,chain_name:E,pretty_name:D,logo_uri:F})=>({chainId:b,name:D||E,logoUrl:F??""})),value:h,onSelect:_}),t.jsx(ht,{label:"Chains",chains:N.map(({chain_id:b,chain_name:E,pretty_name:D,logo_uri:F})=>({chainId:b,name:D||E,logoUrl:F??""})),value:h,onSelect:_})]}),t.jsx(pe,{suspenseFallback:t.jsx(es.Placeholder,{}),children:t.jsx(Yd,{address:p({initialAddress:d,initialChainId:u,chainId:h,fallbackAddress:e==="src"?a:void 0}),chain:g,onSelect:I})},h)]})},nr=({type:e})=>{const s=e==="src"?"srcChainId":"dstChainId",n=e==="src"?"srcDenom":"dstDenom",r=e==="src"?"Select source chain and asset":"Select destination chain and asset",{watch:o}=et(),a=o(s),i=o(n),l=Pe(a),c=Me(i,a);return t.jsx(_t,{title:r,content:d=>t.jsx(Zd,{type:e,afterSelect:d}),children:t.jsx(vo,{asset:{denom:c.denom,decimals:c.decimals??0,symbol:c.symbol,logoUrl:c.logo_uri??""},chain:{chainId:l.chain_id,name:l.pretty_name||l.chain_name,logoUrl:l.logo_uri??""}})})},Jd="_skeleton_1l4jn_1",Xd={skeleton:Jd},nn=({width:e="100%",height:s})=>t.jsx("div",{className:Xd.skeleton,style:{width:e,height:s}}),eu="_stack_1ip8h_1",tu="_button_1ip8h_6",su="_isLoading_1ip8h_19",nu="_disabled_1ip8h_19",ru="_checked_1ip8h_23",ou="_header_1ip8h_37",au="_title_1ip8h_43",iu="_duration_1ip8h_52",cu="_warning_1ip8h_62",lu="_amount_1ip8h_66",du="_value_1ip8h_67",ye={stack:eu,button:tu,isLoading:su,disabled:nu,checked:ru,header:ou,title:au,duration:iu,warning:cu,amount:lu,value:du},uu=({children:e})=>t.jsx("div",{className:ye.stack,children:e}),hs=({label:e,query:s,value:n,onSelect:r,...o})=>{const{data:a,isLoading:i}=s,{watch:l}=et(),{dstChainId:c,dstDenom:d}=l(),u=Me(d,c),m=!i&&o.checked,h=!i&&!a;return t.jsxs("button",{type:"button",className:B(ye.button,{[ye.isLoading]:i,[ye.disabled]:h,[ye.checked]:m}),onClick:()=>{i||h||r(n)},children:[t.jsxs("div",{className:ye.header,children:[t.jsxs("div",{className:ye.title,children:[t.jsx("span",{children:e}),m&&t.jsx(k.IconCheck,{size:14})]}),i?t.jsx(nn,{width:80,height:16}):a?t.jsxs("div",{className:B(ye.duration,{[ye.warning]:n==="op"}),children:[t.jsx(k.IconClockFilled,{size:12}),t.jsx("span",{children:gn(a.estimated_route_duration_seconds)})]}):t.jsx("div",{className:ye.duration,children:"Not available"})]}),(i||a)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:ye.amount,children:i?t.jsx(nn,{width:260,height:40}):a?w.formatAmount(a.amount_out,{decimals:u.decimals}):null}),t.jsx("div",{className:ye.value,children:i?t.jsx(nn,{width:120,height:16}):a?a.usd_amount_out?Se(a.usd_amount_out):"$-":null})]})]})};hs.Stack=uu;const hu="_description_s1yto_1",mu="_presets_s1yto_8",_u="_preset_s1yto_8",fu="_active_s1yto_28",pu="_custom_s1yto_39",gu="_wrapper_s1yto_45",xu="_percent_s1yto_54",$e={description:hu,presets:mu,preset:_u,active:fu,custom:pu,wrapper:gu,percent:xu},rr=["0.1","0.5","1.0"],yu=({afterConfirm:e})=>{const s=et(),n=s.getValues("slippagePercent"),[r,o]=f.useState(null),{control:a,watch:i,getValues:l,setValue:c}=ce.useForm({defaultValues:{value:n}}),d=i("value");f.useEffect(()=>{const p=rr.findIndex(j=>j===n);o(p>=0?p:null)},[n]);const u=(p,j)=>{c("value",p),o(j)},m=()=>{o(null)},h=f.useMemo(()=>Number(d)>100?{type:"error",text:"Slippage must be less than 100%"}:Number(d)>5?{type:"warning",text:"Your transaction may be frontrun"}:Number(d)<.1?{type:"warning",text:"Your transaction may fail"}:null,[d]),_=h?.type==="error",g=({value:p})=>{s.setValue("slippagePercent",p),e()};return t.jsxs(ze,{children:[t.jsx("p",{className:$e.description,children:"Slippage is how much price movement you can tolerate between the time you send out a transaction and the time it's executed."}),t.jsxs("div",{className:$e.presets,children:[rr.map((p,j)=>t.jsxs("button",{type:"button",className:B($e.preset,{[$e.active]:r===j}),onClick:()=>u(p,j),children:[p,"%"]},p)),r!==null?t.jsx("button",{type:"button",className:B($e.preset,$e.custom),onClick:()=>o(null),children:"Custom"}):t.jsxs("div",{className:$e.wrapper,children:[t.jsx(xo,{name:"value",control:a,dp:2,onFocus:m,placeholder:"",className:B($e.preset,$e.active)}),t.jsx("span",{className:$e.percent,children:"%"})]})]}),h&&t.jsx(ne,{level:h.type,children:h.text}),t.jsx(re,{children:t.jsx(V.White,{type:"button",onClick:()=>g(l()),disabled:_,children:"Confirm"})})]})},ju="_form_1coq4_1",vu="_arrow_1coq4_5",bu="_divider_1coq4_13",wu="_flip_1coq4_21",Cu="_meta_1coq4_37",Iu="_row_1coq4_50",Nu="_title_1coq4_56",Su="_description_1coq4_60",ku="_icon_1coq4_67",Au="_edit_1coq4_72",$u="_warning_1coq4_93",_e={form:ju,arrow:vu,divider:bu,flip:wu,meta:Cu,row:Iu,title:Nu,description:Su,icon:ku,edit:Au,warning:$u},Tu=()=>{const e=he(),s=qs(),[n,r]=Ne.useLocalStorage(U.BRIDGE_ROUTE_TYPE,"default"),{watch:o,setValue:a,handleSubmit:i,formState:l}=et(),c=o(),{srcChainId:d,srcDenom:u,dstChainId:m,dstDenom:h,quantity:_,sender:g,slippagePercent:p}=c,j=Xe(),S=Pe(d),N=Vt(S),I=Pe(m),b=Vt(I),E=Me(u,d),D=Me(h,m),{data:F}=qn(g,d),C=rd(g,d,u),P=!C?.amount||M(C.amount).isZero(),[y]=Ne.useDebounceValue(_,300),x=N!=="initia"&&b!=="initia",$=id(),T=tr(y,{disabled:x}),R=tr(y,{isOpWithdraw:!0,disabled:!$}),L=$&&n==="op"?R:T,{data:q,isLoading:H,isFetching:ie,error:O}=L,{data:be}=ad(O),tt=y&&(H||ie),Ke=()=>{a("srcChainId",m),a("srcDenom",h),a("dstChainId",d),a("dstDenom",u),a("quantity","",{shouldTouch:!1,shouldDirty:!1})},{openModal:st,closeModal:de}=As(),me=i(z=>{if(q?.warning){const{type:rt="",message:Us}=q.warning??{};st({content:t.jsx(fo,{type:"warning",icon:t.jsx(k.IconWarningFilled,{size:40}),title:vs.sentenceCase(rt),primaryButton:{label:"Cancel",onClick:de},secondaryButton:{label:"Proceed anyway",onClick:()=>{e("/bridge/preview",{route:q,values:z}),de()}},children:t.jsx("p",{className:_e.warning,children:Us})})});return}e("/bridge/preview",{route:q,values:z})}),jt=f.useMemo(()=>q?.estimated_fees?.filter(({fee_behavior:z})=>z==="FEE_BEHAVIOR_DEDUCTED")??[],[q]),nt=f.useMemo(()=>q?.estimated_fees?.filter(({fee_behavior:z})=>z==="FEE_BEHAVIOR_ADDITIONAL")??[],[q]),Pt=f.useMemo(()=>{for(const z of nt){const rt=F?.[z.origin_asset.denom]?.amount??"0",Us=q?.source_asset_denom===z.origin_asset.denom?q.amount_in:"0";if(M(rt).lt(M(Us).plus(z.amount??"0")))return`Insufficient ${z.origin_asset.symbol} for fees`}},[F,q,nt]),Mn=f.useMemo(()=>{if(!c.sender)return"Connect wallet";if(!c.quantity||!y)return"Enter amount";if(!c.recipient)return"Enter recipient address";if(l.errors.quantity)return l.errors.quantity.message;if(!q)return"Route not found";if(Pt)return Pt},[y,Pt,l,q,c]),Fo=q?w.formatAmount(q.amount_out,{decimals:D.decimals}):"0",Mo=M(_).gt(0)&&M(_).isEqualTo(w.fromBaseUnit(C?.amount,{decimals:C?.decimals??0})),Oo=(()=>{switch(N){case"initia":return j(d).fees.fee_tokens.some(({denom:z})=>z===u);case"cosmos":return S.fee_assets.some(({denom:z})=>z===u);case"evm":return!Ze.isAddress(u);default:return!1}})(),Os=f.useCallback((z,rt)=>z.length?t.jsxs("div",{className:_e.description,children:[yo(z),!s&&t.jsx(Xt,{label:rt,children:t.jsx("span",{className:_e.icon,children:t.jsx(k.IconInfoFilled,{size:12})})})]}):null,[s]),ts=M(_).gt(0)&&$,On=f.useMemo(()=>q?[{condition:!!q.estimated_fees?.length,title:"Fees",content:t.jsxs("div",{children:[Os(jt,"Fee deducted from the amount you receive"),Os(nt,"Fee charged in addition to the amount you enter")]})},{condition:!ts&&!!gn(q.estimated_route_duration_seconds),title:"Estimated time",content:t.jsx("span",{className:_e.description,children:gn(q.estimated_route_duration_seconds)})},{condition:q.does_swap,title:"Slippage",content:t.jsxs("span",{className:_e.description,children:[t.jsxs("span",{children:[p,"%"]}),t.jsx(_t,{title:"Slippage tolerance",content:z=>t.jsx(yu,{afterConfirm:z}),className:_e.edit,children:t.jsx(k.IconSettingFilled,{size:12})})]})}].filter(z=>z.condition):[],[nt,jt,Os,q,ts,p]);return t.jsxs("form",{className:_e.form,onSubmit:me,children:[t.jsx(fn,{selectButton:t.jsx(nr,{type:"src"}),accountButton:N==="cosmos"&&t.jsx(sr,{type:"src"}),quantityInput:t.jsx(xs,{balance:C?.amount,decimals:E?.decimals}),balanceButton:t.jsx(go,{onClick:()=>a("quantity",w.fromBaseUnit(C?.amount,{decimals:E?.decimals??0}),{shouldValidate:!0}),disabled:P,children:w.formatAmount(C?.amount??"0",{decimals:E.decimals})}),value:q?q.usd_amount_in?Se(q.usd_amount_in):"$-":"$0"}),t.jsxs("div",{className:_e.arrow,children:[t.jsx("div",{className:_e.divider}),t.jsx("button",{type:"button",className:_e.flip,onClick:()=>Ke(),children:t.jsx(k.IconChevronDown,{size:16})})]}),t.jsx(fn,{selectButton:t.jsx(nr,{type:"dst"}),accountButton:t.jsx(sr,{type:"dst"}),quantityInput:t.jsx(xs.ReadOnly,{children:Fo}),value:q?q.usd_amount_out?Se(q.usd_amount_out):"$-":"$0",hideNumbers:ts}),t.jsx(mn,{children:ts?t.jsxs(hs.Stack,{children:[t.jsx(hs,{label:"Fast",query:T,value:"default",onSelect:r,checked:n==="default"}),t.jsx(hs,{label:"Lossless",query:R,value:"op",onSelect:r,checked:n==="op"})]}):null}),t.jsx(re,{extra:t.jsxs(t.Fragment,{children:[t.jsxs(ne.Stack,{children:[q?.extra_infos?.map(z=>t.jsx(ne,{level:"info",children:z},z)),be&&t.jsx(ne,{level:"info",children:be}),Mo&&Oo&&t.jsx(ne,{level:"warning",children:"Make sure to leave enough for transaction fee"}),q?.warning&&t.jsx(ne,{level:"warning",children:q.warning.message}),q?.extra_warnings?.map(z=>t.jsx(ne,{level:"warning",children:z},z))]}),t.jsx(mn,{children:On.length>0&&t.jsx("div",{className:_e.meta,children:On.map((z,rt)=>t.jsxs("div",{className:_e.row,children:[t.jsx("span",{className:_e.title,children:z.title}),z.content]},rt))})})]}),children:t.jsx(V.White,{loading:tt&&"Simulating...",disabled:!!Mn,children:Mn??"Preview route"})})]})},Eu=()=>{po();const e=ya(),s=he(),{closeDrawer:n}=Tt(),r=Et(),o=Il(),a=ce.useForm({mode:"onChange",defaultValues:o}),{watch:i,setValue:l}=a,{srcChainId:c,dstChainId:d,srcDenom:u,dstDenom:m,quantity:h,slippagePercent:_,recipient:g}=i();i((y,{name:x})=>{(x==="srcChainId"||x==="srcDenom")&&l("quantity","",{shouldTouch:!1,shouldDirty:!1})});const p=mo(),j=p(c),S=p(d),I=_o()(g,d);f.useEffect(()=>{l("cosmosWalletName",void 0),l("sender",j)},[c,j,l]),f.useEffect(()=>{I||l("recipient",S)},[S,I,l]);const b=kt(c),E=kt(d),D=f.useMemo(()=>{if(!b.find(y=>y.denom===u))return`${u} is not available for bridge/swap on ${c}`;if(!E.find(y=>y.denom===m))return`${m} is not available for bridge/swap on ${d}`},[E,d,m,b,c,u]);f.useEffect(()=>{D||(localStorage.setItem(U.BRIDGE_SRC_CHAIN_ID,c),localStorage.setItem(U.BRIDGE_SRC_DENOM,u),localStorage.setItem(U.BRIDGE_DST_CHAIN_ID,d),localStorage.setItem(U.BRIDGE_DST_DENOM,m),localStorage.setItem(U.BRIDGE_QUANTITY,h),localStorage.setItem(U.BRIDGE_SLIPPAGE_PERCENT,_))},[c,u,d,m,h,_,D]);const F=e[0].path==="/bridge",C=()=>t.jsxs(t.Fragment,{children:[t.jsx(X,{error:!0,children:D}),t.jsx(re,{children:F?t.jsx(V.White,{onClick:n,children:"Close"}):t.jsx(V.White,{onClick:()=>s(-1),children:"Go back"})})]}),{reminders:P}=qt();return t.jsx(xt,{title:"Bridge/Swap",backButton:F?"/":void 0,extra:t.jsxs(t.Fragment,{children:[t.jsx(V.Small,{onClick:()=>s("/bridge/history"),unpadded:!0,children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",width:"12",height:"12",children:[t.jsx("path",{d:"m0 9.818 1.414-1.414 L2 8.99 V8 a7 7 0 1 1 7 7 v-2 a5 5 0 1 0-5-5 v1.354 l.95-.95 1.414 1.414 L3.182 13 0 9.818 Z"}),t.jsx("path",{d:"M9 5.5 H7.5 v3.75 h3.75 v-1.5 H9 V5.5 Z"})]})}),t.jsx(ho,{offset:0,disabled:P.length===0,children:t.jsx(V.Small,{onClick:()=>s("/op/withdrawals"),disabled:!r,children:t.jsx("span",{children:"Withdrawal status"})})})]}),children:D?C():t.jsx(ce.FormProvider,{...a,children:t.jsx(pe,{children:t.jsx(Tu,{})})})})},qu="_button_14cv7_1",Du="_checkbox_14cv7_10",Pu="_checked_14cv7_23",cs={button:qu,checkbox:Du,checked:Pu},Ru=({checked:e,onClick:s,label:n,className:r})=>t.jsxs("button",{type:"button",className:B(cs.button,r),onClick:s,children:[t.jsx("div",{className:B(cs.checkbox,{[cs.checked]:e}),children:e&&t.jsx(k.IconCheck,{size:12})}),t.jsx("span",{className:cs.label,children:n})]}),Bu="_button_1iys9_1",Fu={button:Bu},bo=({onClick:e,disabled:s})=>{const{ref:n,inView:r}=Go.useInView();return f.useEffect(()=>{r&&e()},[r,e]),t.jsxs("button",{className:Fu.button,onClick:e,disabled:s,ref:n,children:[t.jsx("span",{children:"Load more"}),t.jsx(k.IconChevronDown,{size:12})]})};function wo(e,s){return e.reduce((n,r)=>{const o=s(r);if(!o)return n;const a=o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),i=n[a]||[];return{...n,[a]:[...i,r]}},{})}const ms=({chainId:e,txHash:s})=>`${U.BRIDGE_HISTORY}:${e}:${s}`,ys=100,or=10;function Co(){const[e,s]=Ne.useLocalStorage(U.BRIDGE_HISTORY,[]),n=f.useCallback((o,a)=>{localStorage.setItem(ms(o),JSON.stringify(a));for(const i of e.slice(ys-1))localStorage.removeItem(ms(i));s((i=[])=>[o,...i.slice(0,ys-1)])},[e,s]),r=f.useCallback(o=>{const a=localStorage.getItem(ms(o));return a?JSON.parse(a):null},[]);return{history:e,addHistoryItem:n,getHistoryDetails:r}}function Io(e){return Ne.useLocalStorage(ms(e),null)}async function Mu(e,s){const n=Z.create({prefixUrl:s}),r=`cosmos/auth/v1beta1/account_info/${e}`;for(let o=1;o<=24;o++)try{return await n.get(r).json()}catch{await new Promise(a=>setTimeout(a,5e3))}throw new Error(`Timeout: ${e} not found`)}async function xn(e,s){const{chain_type:n,chain_id:r,chain_name:o,evm_fee_asset:a,rpc:i}=s;if(n!=="evm")throw new Error(`Chain is not an EVM chain: ${o}`);try{await e.send("wallet_switchEthereumChain",[{chainId:`0x${Number(r).toString(16)}`}])}catch(l){if(v.path(["error","code"],l)!==4902)throw l;if(!a)throw new Error(`Fee asset is not defined for chain: ${o}`);await e.send("wallet_addEthereumChain",[{chainId:`0x${Number(r).toString(16)}`,chainName:o,nativeCurrency:a,rpcUrls:[i]}]),await e.send("wallet_switchEthereumChain",[{chainId:`0x${Number(r).toString(16)}`}])}}function Dt(){return ft()}function Ou(e){const s=he(),{showNotification:n,updateNotification:r,hideNotification:o}=En(),{addHistoryItem:a}=Co(),i=$s(),{route:l,values:c}=Dt(),{srcChainId:d,sender:u,recipient:m,cosmosWalletName:h}=c,_=Rr(),{requestTxSync:g,waitForTxConfirmation:p}=fe(),{find:j}=Ps(),S=Ns(),N=Yt(),I=Pe(d),b=Vt(I),E=Gr(d),D=A.useQueryClient(),{registryUrl:F}=ee(),C=Xe(),{addReminder:P}=qt(),y=Le();return A.useMutation({mutationFn:async()=>{try{if("cosmos_tx"in e){if(!e.cosmos_tx.msgs)throw new Error("Invalid transaction data");const x=e.cosmos_tx.msgs.map(({msg_type_url:de,msg:me})=>{if(!(de&&me))throw new Error("Invalid transaction data");return N.fromAmino({type:Kt.aminoConverters[de].aminoType,value:JSON.parse(me)})});if(b==="initia"){const{srcDenom:de,quantity:me}=c,{decimals:jt}=E(de),nt=await g({messages:x,chainId:d,internal:1,spendCoins:[{denom:de,amount:w.toBaseUnit(me,{decimals:jt})}]}),Pt=p({txHash:nt,chainId:d});return{txHash:nt,wait:Pt}}const $=j(h)?.getProvider();if(!$)throw new Error("Wallet not connected");const T=$.getOfflineSignerOnlyAmino(d),R=await qe.SigningStargateClient.connectWithSigner(I.rpc,T,{registry:S,aminoTypes:N}),L=await R.getAllBalances(u),q=I.fee_assets.find(de=>L.some(me=>me.denom===de.denom&&M(me.amount).gt(0)));if(!q){const me=["Insufficient balance for fees.",`Available fee assets: ${I.fee_assets.map(jt=>E(jt.denom).symbol).join(", ")}`,"(note: asset symbols may refer to different tokens across chains)"].join(" ");throw new Error(me)}const{denom:H,gas_price:ie}=q;if(!ie)throw new Error(`Gas price not found for ${H}`);const O=await R.simulate(u,x,""),be=qe.GasPrice.fromString(ie.average+H),tt=qe.calculateFee(Math.ceil(O*Wt),be),Ke=await R.signAndBroadcastSync(u,x,tt),st=Qr({txHash:Ke,client:R});return{txHash:Ke,wait:st}}if("evm_tx"in e){const{chain_id:x,to:$,value:T,data:R}=e.evm_tx,L=await _(),q=await L.getSigner();await xn(L,I);const H=await q.sendTransaction({chainId:x,to:$,value:T,data:`0x${R}`});return{txHash:H.hash,wait:H.wait()}}throw new Error("Unlisted chain type")}catch(x){throw await Fe(x)}},onSuccess:async({txHash:x,wait:$})=>{localStorage.removeItem(U.BRIDGE_QUANTITY),s(-1),n({type:"loading",title:"Transaction is pending..."});try{await $;const T=Pn(l)==="OP Bridge withdrawal",R=T?{success:!0,error:null}:await Hu(y,x,d);if(!R.success&&R.error){const O=R.error instanceof Error?R.error.message:String(R.error);n({type:"error",title:"Transaction tracking failed",description:`Failed to track transaction: ${O}. The transaction may still be processing.`,autoHide:!0})}const L=R.success,H=zu({txHash:x,srcChainId:d,route:l,values:c,recipient:m},L);a(H.tx,H.details),r(Lu(o));const ie=rn(c,x);if(i("Bridge Transaction Success",ie),T){const O=Ku(H.tx,l,m);P(H.tx,O)}}catch(T){const R=T instanceof Error?T.message:String(T);r({type:"error",title:"Transaction not confirmed",description:R});const L={...rn(c,x),error:R};i("Bridge Confirmation Failed",L)}finally{D.invalidateQueries({queryKey:De.balances(d,u).queryKey})}},onError:async x=>{const $=b==="initia"?await Ct(x,C(d),F):x;n({type:"error",title:"Transaction failed",description:$.message});const T=rn(c);i("Bridge Transaction Failed",{...T,error:$.message})}})}function Uu(){const e=Le(),s=ae(),n=In(),{route:r,values:o}=Dt(),a=pt();return A.useMutation({mutationFn:async()=>{try{const{chain_id:i,hook:l}=await e.post("op-hook",{json:{source_address:s,source_asset_chain_id:r.source_asset_chain_id,source_asset_denom:r.source_asset_denom,dest_address:w.InitiaAddress(o.recipient).bech32,dest_asset_chain_id:r.dest_asset_chain_id,dest_asset_denom:r.dest_asset_denom}}).json();await Mu(s,a(r.dest_asset_chain_id).rest);const c=l.map(({msg_type_url:m,msg:h})=>Kt.aminoTypes.fromAmino({type:Kt.aminoConverters[m].aminoType,value:JSON.parse(h)})),d=await n(i,s,c,{amount:[],gas:"1"},"",{incrementSequence:i===o.srcChainId?2:0}),u=Ge.Tx.fromPartial({body:Ge.TxBody.decode(d.bodyBytes),authInfo:Ge.AuthInfo.decode(d.authInfoBytes),signatures:d.signatures});return{signer:s,hook:W.toBase64(Ge.Tx.encode(u).finish())}}catch(i){throw await Fe(i)}}})}function Lu(e){return{type:"info",title:"Transaction submitted",description:f.createElement(f.Fragment,null,"Check ",f.createElement(Nn,{to:"/bridge/history",onClick:e},"the activity page")," for transaction status"),autoHide:!0}}function rn(e,s){return{quantity:e.quantity,srcChainId:e.srcChainId,srcDenom:e.srcDenom,dstChainId:e.dstChainId,dstDenom:e.dstDenom,txHash:s}}function zu(e,s){const{txHash:n,srcChainId:r,route:o,values:a}=e,i={chainId:r,txHash:n},l=Pn(o)==="OP Bridge withdrawal";return{tx:i,details:{...i,timestamp:Date.now(),route:o,values:a,state:l?"success":void 0,tracked:s},isOpWithdraw:l}}function Ku(e,s,n){return{...e,recipient:w.InitiaAddress(n).bech32,claimableAt:Date.now()+s.estimated_route_duration_seconds*1e3,amount:s.amount_out,denom:s.dest_asset_denom}}async function Hu(e,s,n){for(let a=0;a<=30;a++)try{return await e.post("v2/tx/track",{json:{tx_hash:s,chain_id:n}}).json(),{success:!0,error:null}}catch(i){if(a===30)return{success:!1,error:await Fe(i)};await new Promise(l=>setTimeout(l,1e3))}return{success:!1,error:new Error("Maximum retries exceeded")}}function Wu(e){const{chainId:s,txHash:n,tracked:r}=e,o=Le();return A.useQuery({queryKey:De.txTrack(s,n).queryKey,queryFn:async()=>{try{return await o.post("v2/tx/track",{json:{tx_hash:n,chain_id:s}}).json()}catch(a){throw await Fe(a)}},select:({tx_hash:a})=>a,retry:6,retryDelay:5e3,staleTime:K.INFINITY,enabled:!r})}function Qu(e){const{timestamp:s,chainId:n,txHash:r,tracked:o,state:a}=e,i=Le();return A.useQuery({queryKey:De.txStatus(n,r).queryKey,queryFn:()=>i.get("v2/tx/status",{searchParams:{tx_hash:r,chain_id:n}}).json(),enabled:!!r&&o&&!a,refetchInterval:({state:{data:l}})=>{if(!l)return!1;const{status:c}=l;if(c==="STATE_COMPLETED")return!1;const d=s+e.route.estimated_route_duration_seconds*1e3,u=Date.now(),m=Math.floor((d-u)/1e3);return m<=0?1e3:m<=300?5e3:60*1e3},staleTime:K.INFINITY})}var _s=(e=>(e.OP_WITHDRAW="OP Bridge withdrawal",e.SKIP="Skip",e))(_s||{});function Pn(e){const{operations:s,dest_asset_denom:n}=e;return v.has("op_init_transfer",v.head(s))&&n==="uinit"?"OP Bridge withdrawal":"Skip"}const Vu="_success_t4dfk_1",Gu="_error_t4dfk_5",ar={success:Vu,error:Gu},Yu=({tx:e})=>{const[s,n]=Io(e);if(!s)throw new Error("Bridge history details not found");const{data:r}=Qu(s),o=s.state??Zu(r);switch(f.useEffect(()=>{o!=="loading"&&n(a=>{if(!a)throw new Error("Bridge history details not found");return{...a,tracked:!0,state:o}})},[n,o]),o){case"error":return t.jsx("div",{className:ar.error,children:t.jsx(k.IconCloseCircleFilled,{size:14})});case"success":return t.jsx("div",{className:ar.success,children:t.jsx(k.IconCheckCircleFilled,{size:14})});default:return t.jsx(gt,{size:14})}};function Zu(e){if(!e)return"loading";switch(e.state){case"STATE_ABANDONED":case"STATE_COMPLETED_ERROR":case"STATE_PENDING_ERROR":return"error";case"STATE_COMPLETED_SUCCESS":return"success";default:return"loading"}}const Ju="_link_12p3n_1",Xu="_header_12p3n_22",eh="_title_12p3n_30",th="_date_12p3n_36",sh="_explorer_12p3n_40",nh="_fees_12p3n_55",rh="_label_12p3n_63",oh="_content_12p3n_67",ah="_route_12p3n_73",ih="_row_12p3n_78",ch="_asset_12p3n_84",lh="_amount_12p3n_92",dh="_chain_12p3n_97",uh="_account_12p3n_106",hh="_arrow_12p3n_113",te={link:Ju,header:Xu,title:eh,date:th,explorer:sh,fees:nh,label:rh,content:oh,route:ah,row:ih,asset:ch,amount:lh,chain:dh,account:uh,arrow:hh},mh=({tx:e})=>{const[s,n]=Io(e);if(!s)throw new Error("Bridge history details not found");const{chainId:r,txHash:o,route:a,values:i,timestamp:l,tracked:c}=s,{data:d}=Wu(s),{address:u="",connector:m}=ve.useAccount(),{find:h}=Ps();f.useEffect(()=>{d&&n(L=>{if(!L)throw new Error("Bridge history details not found");return{...L,tracked:!0}})},[n,d]);const{amount_in:_,amount_out:g,source_asset_chain_id:p,source_asset_denom:j,dest_asset_chain_id:S,dest_asset_denom:N,estimated_fees:I=[]}=a,b=Pe(p),E=Pe(S),D=Me(j,p),F=Me(N,S),C=(L,q)=>q?t.jsx(Q,{src:q,width:12,height:12}):w.InitiaAddress.equals(L,u)?t.jsx(Q,{src:m?.icon,width:12,height:12}):t.jsx(k.IconWallet,{size:12}),P=(L,{symbol:q,decimals:H,logo_uri:ie},{chain_name:O,pretty_name:be,...tt},Ke,st)=>t.jsxs("div",{className:te.row,children:[t.jsx(Rs,{assetLogoUrl:ie,chainLogoUrl:tt.logo_uri??void 0}),t.jsxs("div",{children:[t.jsxs("div",{className:te.asset,children:[t.jsx("span",{className:te.amount,children:w.formatAmount(L,{decimals:H})}),t.jsx("span",{children:q})]}),t.jsxs("div",{className:te.chain,children:[t.jsxs("span",{children:["on ",be||O]}),t.jsxs("div",{className:te.account,children:[st,t.jsx("span",{className:"monospace",children:w.truncate(Ke)})]})]})]})]}),y=Pn(a),x=f.useMemo(()=>{switch(y){case _s.SKIP:return"Skip Explorer";case _s.OP_WITHDRAW:return"Initia Scan"}},[y]),$=t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:te.header,children:[t.jsxs("div",{className:te.title,children:[c?t.jsx(Yu,{tx:e}):t.jsx(gt,{size:14}),t.jsx("div",{className:te.date,children:At.format(new Date(l),"h:mm a")})]}),t.jsxs("div",{className:te.explorer,children:[t.jsx("span",{children:x}),t.jsx(k.IconExternalLink,{size:12})]})]}),t.jsxs("div",{className:te.route,children:[P(_,D,b,i.sender,C(i.sender,h(i.cosmosWalletName)?.image)),t.jsx("div",{className:te.arrow,children:t.jsx(k.IconArrowDown,{size:12})}),P(g,F,E,i.recipient,C(i.recipient))]}),I.length>0&&t.jsxs("div",{className:te.fees,children:[t.jsx("span",{className:te.label,children:"Fees"}),t.jsx("span",{className:te.content,children:yo(I)})]})]});if(y===_s.OP_WITHDRAW)return t.jsx(Ds,{chainId:r,txHash:o,className:te.link,children:$});const T=new URLSearchParams({tx_hash:o,chain_id:r}),R=new URL(`?${T.toString()}`,"https://explorer.skip.build");return t.jsx("a",{href:R.toString(),className:te.link,target:"_blank",children:$})},_h="_history_13u9z_1",fh="_header_13u9z_5",ph="_checkbox_13u9z_9",gh="_groups_13u9z_13",xh="_dateGroup_13u9z_21",yh="_dateHeader_13u9z_26",jh="_list_13u9z_32",ct={history:_h,header:fh,checkbox:ph,groups:gh,dateGroup:xh,dateHeader:yh,list:jh},vh=()=>{const{initiaAddress:e,hexAddress:s}=fe(),{history:n,getHistoryDetails:r}=Co(),o=n.filter(_=>r(_)),a=o.filter(_=>{const g=r(_);if(!g)return!1;const{values:p}=g,{sender:j,recipient:S}=p;return[j,S].some(N=>[e,s].includes(N))}),[i,l]=f.useState(1),[c,d]=Ne.useToggle(!a.length),u=c?o:a,m=u.slice(0,i*or),h=f.useMemo(()=>wo(m,_=>{const g=r(_);if(g)return new Date(g.timestamp)}),[m,r]);return t.jsx(xt,{title:"Bridge/Swap activity",children:t.jsxs("div",{className:ct.history,children:[o.length>0&&o.length!==a.length&&t.jsx("header",{className:ct.header,children:t.jsx(Ru,{checked:c,onClick:d,label:"Show all transactions stored in this browser",className:ct.checkbox})}),u.length===0?t.jsx(X,{children:"No bridge/swap activity"}):t.jsx("div",{className:ct.groups,children:Object.entries(h).map(([_,g])=>t.jsxs("div",{className:ct.dateGroup,children:[t.jsx("div",{className:ct.dateHeader,children:_}),t.jsx("div",{className:ct.list,children:g.map(p=>t.jsx(pe,{children:t.jsx(mh,{tx:p})},p.txHash))})]},_))}),u.length>i*or?t.jsx(bo,{onClick:()=>l(_=>_+1)}):n.length>=ys&&t.jsxs(X,{children:["Only the latest ",ys," items are stored. Older entries will be removed automatically."]})]})})},bh=({tx:e})=>{const{mutate:s,isPending:n}=Ou(e);return t.jsx(re,{children:t.jsx(V.White,{onClick:()=>s(),loading:n&&"Signing transaction...",children:"Confirm"})})},wh="_content_c0tee_1",Ch="_info_c0tee_6",Ih="_arrow_c0tee_11",Nh="_divider_c0tee_19",Sh="_type_c0tee_26",kh="_asset_c0tee_44",Ah="_amount_c0tee_52",$h="_lower_c0tee_57",Th="_chain_c0tee_63",Eh="_address_c0tee_69",xe={content:wh,info:Ch,arrow:Ih,divider:Nh,type:Sh,asset:kh,amount:Ah,lower:$h,chain:Th,address:Eh},No=e=>{const{source:s,label:n,amount:r,denom:o,chainId:a,address:i,walletIcon:l}=e,{symbol:c=w.truncate(o),decimals:d=0,logo_uri:u=wn}=e,{chain_name:m,pretty_name:h,..._}=Pe(a);return t.jsxs("div",{children:[!s&&t.jsxs("div",{className:xe.arrow,children:[t.jsx("div",{className:xe.divider}),n?t.jsx(Xt,{label:n,children:t.jsx("button",{className:xe.type,children:t.jsx(k.IconArrowDown,{size:12})})}):t.jsx("span",{className:xe.type,children:t.jsx(k.IconArrowDown,{size:12})}),t.jsx("div",{className:xe.divider})]}),t.jsxs("div",{className:xe.content,children:[t.jsx(Rs,{assetLogoUrl:u,chainLogoUrl:_.logo_uri??void 0}),t.jsxs("div",{className:xe.info,children:[t.jsxs("div",{className:xe.asset,children:[t.jsx("span",{className:xe.amount,children:w.formatAmount(r,{decimals:d})}),t.jsx("span",{children:c})]}),t.jsxs("div",{className:xe.lower,children:[t.jsxs("div",{className:xe.chain,children:["on ",h||m]}),i&&t.jsx(ps,{value:i,children:({copy:g,copied:p})=>t.jsxs("button",{className:xe.address,onClick:g,children:[l,p?t.jsx("span",{children:"Copied!"}):t.jsx("span",{className:"monospace",children:w.truncate(i)})]})})]})]})]})]})},St=e=>{const s=Me(e.denom,e.chainId);return t.jsx(No,{...e,...s})};St.Placeholder=No;const qh="_root_1l4he_1",Dh="_flexEnd_1l4he_6",Ph="_toggle_1l4he_11",Rh="_route_1l4he_34",Bh="_content_1l4he_41",Ut={root:qh,flexEnd:Dh,toggle:Ph,route:Rh,content:Bh};function Fh(e){const s=({name:n})=>n==="initia-dex"?"Initia DEX":vs.capitalCase(v.head(n?.split("-")??[])??"");if("transfer"in e)return{label:"Bridge via IBC",...e,...e.transfer};if("bank_send"in e)return{label:"Send",...e,...e.bank_send};if("swap"in e){const n=e.swap?.swap_venues?.map(s).join(", ");return{label:n?`Swap on ${n}`:"Swap",...e,...e.swap}}if("axelar_transfer"in e)return{label:"Bridge via Axelar",...e,...e.axelar_transfer};if("cctp_transfer"in e)return{label:"Bridge via CCTP",...e,...e.cctp_transfer};if("hyperlane_transfer"in e)return{label:"Bridge via Hyperlane",...e,...e.hyperlane_transfer};if("evm_swap"in e){const n=e.evm_swap?.swap_venues?.map(s).join(", ");return{label:n?`Swap on ${n}`:"Swap",...e,...e.evm_swap}}if("op_init_transfer"in e)return{label:"Bridge via OP Bridge",...e,...e.op_init_transfer};if("go_fast_transfer"in e)return{label:"Bridge via Go Fast",...e,...e.go_fast_transfer};if("eureka_transfer"in e)return{label:"Bridge via Eureka",...e,...e.eureka_transfer};if("stargate_transfer"in e)return{label:"Bridge via Stargate",...e,...e.stargate_transfer};if("layer_zero_transfer"in e)return{label:"Bridge via LayerZero",...e,...e.layer_zero_transfer};throw new Error("Unknown operation type")}const Mh=({addressList:e})=>{const{values:s,route:n}=Dt(),{source_asset_denom:r,source_asset_chain_id:o,amount_in:a,operations:i}=n,l=v.zipObj(n.required_chain_addresses,e),{find:c}=Ps(),{connector:d,address:u=""}=ve.useAccount(),[m,h]=Ne.useToggle(!1),_=i.length>1,g=t.jsx(Q,{src:s.cosmosWalletName?c(s.cosmosWalletName)?.image:d?.icon,width:12,height:12}),p={amount:a,denom:r,chainId:o,address:s.sender,walletIcon:g},j=E=>w.InitiaAddress.equals(E,u)?g:t.jsx(k.IconWallet,{size:11}),S=E=>{const{label:D,amount_out:F,denom:C,denom_out:P=C,chain_id:y,from_chain_id:x,to_chain_id:$=y??x}=E,T=l[$];return{label:_&&!m?void 0:D,amount:F,denom:P,chainId:$,address:T,walletIcon:j(T)}},N=i.map(Fh).map(S),I=N.slice(0,-1),b=N[N.length-1];return t.jsxs(Y.Collapsible.Root,{className:Ut.root,open:m,onOpenChange:h,children:[_&&t.jsx("div",{className:Ut.flexEnd,children:t.jsx(Y.Collapsible.Trigger,{className:Ut.toggle,children:m?t.jsxs(t.Fragment,{children:[t.jsx(k.IconMinus,{size:12}),t.jsx("span",{children:"Hide details"})]}):t.jsxs(t.Fragment,{children:[t.jsx(k.IconList,{size:12}),t.jsx("span",{children:"Show details"})]})})}),t.jsxs("div",{className:Ut.route,children:[t.jsx(St,{...p,source:!0}),t.jsx(Y.Collapsible.Content,{className:Ut.content,children:I.map((E,D)=>t.jsx(pe,{suspenseFallback:t.jsx(St.Placeholder,{...E}),errorBoundaryProps:{fallback:t.jsx(St.Placeholder,{...E})},children:t.jsx(St,{...E})},D))}),t.jsx(St,{...b})]})]})},yn=({error:e})=>{const s=he();return t.jsx(re,{extra:t.jsx(ne,{level:"error",children:e.message}),children:t.jsx(V.White,{onClick:()=>s("/bridge"),children:"Home"})})},Oh=({children:e})=>{const s=Dt(),{route:n,values:r}=s,{required_chain_addresses:o}=n,{srcChainId:a,dstChainId:i,sender:l,recipient:c}=r,{initiaAddress:d,hexAddress:u}=fe(),m=$t(),h=pt(),_=Zt(),g=h(a),p=_(g),j=o.slice(0,-1).some(F=>{const C=h(F);return _(C)==="cosmos"})&&p!=="cosmos",[S,N]=f.useState(void 0),[I,b]=f.useState(!1),[E,D]=f.useState(null);if(f.useEffect(()=>{(async()=>{try{if(!j)return;if(!m)throw new Error("Wallet not connected");b(!0),D(null);const[{pubkey:C}]=await m.getAccounts();N(C)}catch(C){D(await Fe(C))}finally{b(!1)}})()},[j,m]),E)return t.jsx(yn,{error:E});if(I)return t.jsx(re,{children:t.jsx(V.White,{loading:I&&"Generating intermediary addresses..."})});if(!j||S){const F=o.map((C,P)=>{if(P===o.length-1){const R=h(i);return _(R)==="initia"?w.InitiaAddress(c).bech32:c}const y=h(C),x=_(y),$=h(a),T=_($);switch(x){case"initia":return d;case"evm":return u;case"cosmos":{if(T==="cosmos")return W.toBech32(y.bech32_prefix,W.fromBech32(l).data);if(!S)throw new Error("Pubkey not found");return Ht.pubkeyToAddress(Ht.encodeSecp256k1Pubkey(S),y.bech32_prefix)}default:throw new Error("Unlisted chain type")}});return e(F)}return null},Uh=({tx:e,children:s})=>{const n=Rr(),r=pt(),{data:o,isLoading:a}=A.useQuery({queryKey:["erc20-approvals-needed",e],queryFn:async()=>{if(!("evm_tx"in e))return[];if(!e.evm_tx.required_erc20_approvals)return[];const{chain_id:u,signer_address:m}=e.evm_tx,h=await n();await xn(h,r(u));const _=["function allowance(address owner, address spender) view returns (uint256)"];return(await Promise.all(e.evm_tx.required_erc20_approvals.map(async p=>{const{token_contract:j,spender:S}=p,I=await new Ze.ethers.Contract(j,_,h).allowance(m,S);return{approval:p,currentAllowance:BigInt(I.toString())}}))).filter(({approval:p,currentAllowance:j})=>j<BigInt(p.amount)).map(({approval:p})=>p)},enabled:!!e&&"evm_tx"in e&&!!e.evm_tx.required_erc20_approvals}),{mutate:i,data:l,isPending:c,error:d}=A.useMutation({mutationFn:async()=>{try{if(!("evm_tx"in e))throw new Error("Transaction is not EVM");if(!o||o.length===0)throw new Error("No approvals needed");const{chain_id:u}=e.evm_tx,m=await n(),h=await m.getSigner();await xn(m,r(u));for(const _ of o){const{token_contract:g,spender:p,amount:j}=_,S=["function approve(address spender, uint256 amount) external returns (bool)"];await(await new Ze.ethers.Contract(g,S,h).approve(p,j)).wait()}return!0}catch(u){throw await Fe(u)}}});return a?t.jsx(re,{children:t.jsx(V.White,{loading:"Checking approvals..."})}):o&&o.length>0&&!l?t.jsx(re,{extra:t.jsx(ne,{level:"error",children:d?.message}),children:t.jsx(V.White,{onClick:()=>i(),loading:c&&"Approving tokens...",children:"Approve tokens"})}):s},Lh=({addressList:e,signedOpHook:s,children:n})=>{const r=Le(),{route:o,values:a}=Dt(),[i,l]=f.useState(void 0),[c,d]=f.useState(!1),[u,m]=f.useState(null);return f.useEffect(()=>{(async()=>{try{if(o.required_op_hook&&!s)throw new Error("Op hook is required");d(!0),m(null);const _={address_list:e,amount_in:o.amount_in,amount_out:o.amount_out,source_asset_chain_id:o.source_asset_chain_id,source_asset_denom:o.source_asset_denom,dest_asset_chain_id:o.dest_asset_chain_id,dest_asset_denom:o.dest_asset_denom,slippage_tolerance_percent:a.slippagePercent,operations:o.operations,signed_op_hook:s},{txs:g}=await r.post("v2/fungible/msgs",{json:_}).json();if(!g||g.length===0)throw new Error("No transaction data found");const[p]=g;l(p)}catch(_){m(_)}finally{d(!1)}})()},[o,a,e,s,r]),u?t.jsx(yn,{error:u}):c?t.jsx(re,{children:t.jsx(V.White,{loading:c&&"Fetching messages..."})}):i?n(i):t.jsx(yn,{error:new Error("Failed to fetch messages")})},zh=({children:e})=>{const{route:s}=Dt(),n=Uu();return s.required_op_hook&&!n.data?t.jsx(re,{extra:t.jsx(ne,{level:"error",children:n.error?.message}),children:t.jsx(V.White,{onClick:()=>n.mutate(),loading:n.isPending&&"Awaiting signature...",children:"Authorize conversion"})}):e(n.data)},Kh=()=>t.jsx(xt,{title:"Route preview",children:t.jsx(Oh,{children:e=>t.jsxs(t.Fragment,{children:[t.jsx(Mh,{addressList:e}),t.jsx(zh,{children:s=>t.jsx(Lh,{addressList:e,signedOpHook:s,children:n=>t.jsx(Uh,{tx:n,children:t.jsx(bh,{tx:n})})})})]})})}),So=f.createContext(null);function Fs(){return f.useContext(So)}const yt=ke.createQueryKeys("interwovenkit:op",{bridge:e=>[e],withdrawals:(e,s)=>[e,s],latestOutput:e=>[e],output:(e,s)=>[e,s],outputResponse:(e,s)=>[e,s],withdrawalClaimed:(e,s)=>[e,s]});function Ms(){const{restUrl:e}=le();return f.useMemo(()=>Z.create({prefixUrl:e}),[e])}function Hh(e){const s=Ms(),{data:n}=A.useSuspenseQuery({queryKey:yt.bridge(e).queryKey,queryFn:()=>s.get(`opinit/ophost/v1/bridges/${e}`).json(),staleTime:K.INFINITY});return n}const ir=20;function Wh(e){const s=ae();return A.useSuspenseInfiniteQuery({queryKey:yt.withdrawals(e,s).queryKey,queryFn:async({pageParam:n})=>{if(!s)return[];const r={limit:ir,offset:n,order:"desc"},{withdrawals:o}=await Z.create({prefixUrl:e}).get(`withdrawals/${s}`,{searchParams:r}).json();return o},getNextPageParam:n=>{const r=v.last(n)?.sequence;return n.length<ir||!r||r<=1?null:r-1},initialPageParam:0,staleTime:K.SECOND})}function Qh(e){const s=Ms(),{data:n}=A.useSuspenseQuery({queryKey:yt.latestOutput(e).queryKey,queryFn:()=>s.get(`opinit/ophost/v1/bridges/${e}/outputs`,{searchParams:{"pagination.reverse":!0,"pagination.limit":1}}).json(),select:({output_proposals:r})=>{const[o]=r;return o||null},staleTime:K.SECOND});return n}function Vh({bridge_id:e,output_index:s}){const n=Ms(),{data:r}=A.useSuspenseQuery({queryKey:yt.output(e,s).queryKey,queryFn:async()=>{try{return await n.get(`opinit/ophost/v1/bridges/${e}/outputs/${s}`).json()}catch{return null}},staleTime:K.SECOND});return r}function Gh({bridge_id:e,sequence:s}){const r=oe().find(({metadata:c})=>c?.op_bridge_id===e.toString())?.chain_id;if(!r)throw new Error(`Chain not found for bridge_id: ${e}`);const a=Xe()(r);if(!a)throw new Error(`Chain not found: ${r}`);const i=a.metadata?.executor_uri;if(!i)throw new Error(`Executor URL not found: ${r}`);const{data:l}=A.useSuspenseQuery({queryKey:yt.outputResponse(i,s).queryKey,queryFn:()=>Z.create({prefixUrl:i}).get(`withdrawal/${s}`).json(),staleTime:K.SECOND});return l}function ko(e,s){const{bridge_id:n}=e,r=Ms(),{data:o}=A.useSuspenseQuery({queryKey:yt.withdrawalClaimed(n,s).queryKey,queryFn:()=>r.get(`opinit/ophost/v1/bridges/${n}/withdrawals/claimed/by_hash`,{searchParams:{withdrawal_hash:s}}).json(),select:({claimed:a})=>a,staleTime:({state:{data:a}})=>a?.claimed?1/0:K.SECOND});return o}function Lt(e){return Yo.sha3_256.create().update(e).digest()}function on(e,s){const n=new ArrayBuffer(s);return new DataView(n).setBigUint64(0,BigInt(e),!1),new Uint8Array(n)}function Ao(e){const{bridge_id:s,sequence:n,amount:r,from:o,to:a}=e,i=on(s.toString(),8),l=on(n.toString(),8),c=on(r.amount,8),d=ss.concatBytes(i,l,Lt(ss.utf8ToBytes(o)),Lt(ss.utf8ToBytes(a)),Lt(ss.utf8ToBytes(r.denom)),c);return Lt(Lt(d))}const Yh="_button_1btdg_1",Zh="_claimed_1btdg_23",cr={button:Yh,claimed:Zh},Jh=()=>{const{withdrawalTx:e}=Fs(),{bridge_id:s,sequence:n,amount:r,output_index:o,withdrawal_proofs:a,storage_root:i,from:l,to:c,version:d}=e,u=le(),m=ae(),{requestTxSync:h,waitForTxConfirmation:_}=fe(),g=Gh(e),p=W.toBase64(Ao(e)),j=ko(e,p),S=A.useQueryClient(),{mutate:N,isPending:I}=A.useMutation({mutationFn:async()=>{if(!g)throw new Error("Output not found");const{last_block_hash:b}=g;return h({chainId:u.chain_id,messages:[{typeUrl:"/opinit.ophost.v1.MsgFinalizeTokenWithdrawal",value:{sender:m,bridgeId:BigInt(s),outputIndex:BigInt(o),withdrawalProofs:a.map(W.fromBase64),from:l,to:c,sequence:BigInt(n),amount:r,version:W.fromBase64(d),storageRoot:W.fromBase64(i),lastBlockHash:W.fromBase64(b)}}],internal:!0})},onSuccess:async b=>{await _({chainId:u.chain_id,txHash:b}),S.invalidateQueries({queryKey:yt.withdrawalClaimed(s,p).queryKey})}});return j?t.jsxs("div",{className:cr.claimed,children:[t.jsx(k.IconCheckCircleFilled,{size:14}),t.jsx("span",{children:"Claimed"})]}):t.jsx("button",{className:cr.button,onClick:()=>N(),disabled:I,children:"Claim"})},Xh=({children:e})=>{const{withdrawalTx:s}=Fs(),n=Hh(s.bridge_id),r=Vh(s),o=f.useMemo(()=>{if(!r)return null;const{bridge_config:a}=n,{output_proposal:i}=r;return At.addSeconds(new Date(i.l1_block_time),parseFloat(a.finalization_period))},[n,r]);return e(o)},$o=1e3,em=60,tm=60,sm=24,jn=$o*em,vn=jn*tm,lr=vn*sm,nm=({date:e})=>{const s=f.useCallback(()=>{const d=new Date().getTime(),m=e.getTime()-d;if(m<=0)return{days:0,hours:0,minutes:0,seconds:0};const h=Math.floor(m/lr),_=Math.floor(m%lr/vn),g=Math.floor(m%vn/jn),p=Math.floor(m%jn/$o);return{days:h,hours:_,minutes:g,seconds:p}},[e]),[n,r]=f.useState(s());f.useEffect(()=>{const d=window.setInterval(()=>{r(s())},1e3);return()=>window.clearInterval(d)},[s,e]);const o=d=>d.toString().padStart(2,"0"),{days:a,hours:i,minutes:l,seconds:c}=n;return t.jsx(Xt,{label:e.toLocaleString(),children:t.jsxs("span",{className:"monospace",children:[a,"d ",o(i),"h ",o(l),"m ",o(c),"s"]})})},rm="_container_1lz3w_1",om="_title_1lz3w_5",dr={container:rm,title:om},am=({date:e})=>t.jsxs("div",{className:dr.container,children:[t.jsx("div",{className:dr.title,children:"Claimable in"}),t.jsx(nm,{date:e})]}),im="_container_1oldz_1",cm="_icon_1oldz_7",ur={container:im,icon:cm},lm="Withdrawal will begin within an hour",hr=()=>{const e=qs();return t.jsxs("div",{className:ur.container,children:[t.jsx("span",{children:"In progress"}),!e&&t.jsx(Xt,{label:lm,children:t.jsx("span",{className:ur.icon,children:t.jsx(k.IconInfoFilled,{size:12})})})]})},dm=({children:e})=>{const{withdrawalTx:s}=Fs(),n=Qh(s.bridge_id),r=s.output_index>Number(n?.output_index);return e(r)},um=({date:e,children:s})=>{const{chainId:n,withdrawalTx:r}=Fs(),o=W.toBase64(Ao(r)),a=ko(r,o),{setReminder:i,removeReminder:l}=qt();return f.useEffect(()=>{const c={chainId:n,txHash:r.tx_hash};a?l(c):i(c,{...c,recipient:r.to,claimableAt:e.getTime(),amount:r.amount.amount,denom:r.amount.denom,dismissed:At.isPast(e.getTime())?!0:void 0})},[n,a,e,l,i,r]),s},hm=()=>t.jsx(dm,{children:e=>e?t.jsx(hr,{}):t.jsx(Xh,{children:s=>s?t.jsx(um,{date:s,children:At.isFuture(s)?t.jsx(am,{date:s}):t.jsx(Jh,{})}):t.jsx(hr,{})})}),mm="_asset_6h8u2_1",_m="_info_6h8u2_7",fm="_symbol_6h8u2_11",an={asset:mm,info:_m,symbol:fm},pm=({amount:e,denom:s})=>{const n=le(),r=kr(s,n),{symbol:o,logoUrl:a,decimals:i}=r;return t.jsxs("div",{className:an.asset,children:[t.jsx(Q,{src:a,width:32,height:32,logo:!0}),t.jsxs("div",{className:an.info,children:[t.jsx("span",{className:"monospace",children:w.formatAmount(e,{decimals:i})}),t.jsx("span",{className:an.symbol,children:o})]})]})},gm="_item_km5w2_1",xm={item:gm},ym=({chain:e})=>{const s=e.metadata?.executor_uri;if(!s)throw new Error("Executor URL is not defined");const{data:n,fetchNextPage:r,hasNextPage:o,isFetching:a}=Wh(s),i=f.useMemo(()=>n?.pages.flat()??[],[n]),{syncReminders:l}=qt();return f.useEffect(()=>{const c=i.map(d=>({chainId:e.chainId,txHash:d.tx_hash}));l(c)},[e.chainId,i,l]),i.length?t.jsxs(t.Fragment,{children:[i.map(c=>{const{amount:d}=c;return t.jsxs("div",{className:xm.item,children:[t.jsx(pm,{...d}),t.jsx(pe,{suspenseFallback:null,children:t.jsx(So.Provider,{value:{chainId:e.chainId,withdrawalTx:c},children:t.jsx(hm,{})})})]},c.sequence)}),o&&t.jsx(bo,{onClick:()=>r(),disabled:a})]}):t.jsx(X,{children:"No withdrawals"})},jm="_content_dj1qm_1",vm="_title_dj1qm_5",mr={content:jm,title:vm},bm=()=>{const{chainId:e}=ft(),s=oe(),n=Gt(),[r,o]=f.useState(e??(n.metadata?.is_l1?"":n.chainId)),a=Xe(),{reminders:i}=qt(),l=r?a(r):void 0;return t.jsxs(xt,{title:"OP Bridge withdrawals",children:[t.jsx(ht,{chains:s.filter(({metadata:c})=>!c?.is_l1&&c?.op_denoms?.length),value:r,onSelect:o,getShowIndicator:c=>i.some(d=>d.chainId===c)}),t.jsx("div",{className:mr.content,children:l?t.jsxs(t.Fragment,{children:[t.jsx("h2",{className:mr.title,children:l.name}),t.jsx(pe,{children:t.jsx(ym,{chain:l})},r)]}):t.jsx(ne,{level:"info",children:"Select a chain to display your OP Bridge withdrawals"})})]})},wm="_page_1f6wh_1",Cm="_title_1f6wh_10",Im="_scrollable_1f6wh_17",Nm="_list_1f6wh_22",Sm="_item_1f6wh_32",km="_name_1f6wh_56",Am="_dimmed_1f6wh_64",$m="_recent_1f6wh_68",Tm="_installed_1f6wh_69",we={page:wm,title:Cm,scrollable:Im,list:Nm,item:Sm,name:km,dimmed:Am,recent:$m,installed:Tm},Em=[{name:"Rabby",url:"https://rabby.io"},{name:"Phantom",url:"https://phantom.com"},{name:"Keplr",url:"https://keplr.app"},{name:"Leap",url:"https://leapwallet.io"}],_r=({onSuccess:e})=>{const{connectors:s,connectAsync:n}=ve.useConnect(),r=Ne.useReadLocalStorage("wagmi.recentConnectorId"),[o,a]=f.useState(null),{mutate:i,isPending:l}=A.useMutation({mutationFn:async c=>{a(c.id);try{await n({connector:c})}catch(d){throw await Fe(d)}},onSettled:()=>{a(null)},onSuccess:()=>{e?.()}});return t.jsxs("div",{className:we.page,children:[t.jsx("h1",{className:we.title,children:"Connect wallet"}),t.jsx(ze,{className:we.scrollable,children:t.jsxs("div",{className:we.list,children:[s.toSorted(v.descend(c=>c.id===r)).map(c=>{const{name:d,icon:u,id:m}=c;return t.jsxs("button",{className:we.item,onClick:()=>i(c),disabled:l,children:[t.jsx(Q,{src:u,width:24,height:24}),t.jsx("span",{className:we.name,children:d}),o===m?t.jsx(gt,{size:16}):r===m?t.jsx("span",{className:we.recent,children:"Recent"}):c.id===bs.id?null:t.jsx("span",{className:we.installed,children:"Installed"})]},m)}),Em.filter(({name:c})=>!s.some(d=>d.name.includes(c))).map(({name:c,url:d})=>{const u=`https://assets.initia.xyz/images/wallets/${c}.webp`;return t.jsxs("a",{href:d,className:we.item,target:"_blank",children:[t.jsx(Q,{src:u,width:24,height:24}),t.jsx("span",{className:B(we.name,we.dimmed),children:c}),t.jsx(k.IconExternalLink,{size:10})]},c)})]})})]})},qm="_trigger_kivvl_1",Dm="_icon_kivvl_21",Pm="_full_kivvl_25",Rm="_triggerContent_kivvl_30",Bm="_triggerText_kivvl_38",Fm="_popoverBackdrop_kivvl_49",Mm="_popoverPositioner_kivvl_68",Om="_popoverPopup_kivvl_72",Um="_search_kivvl_96",Lm="_viewport_kivvl_101",zm="_item_kivvl_106",Km="_highlighted_kivvl_120",Hm="_active_kivvl_124",Wm="_name_kivvl_129",Qm="_extra_kivvl_133",se={trigger:qm,icon:Dm,full:Pm,triggerContent:Rm,triggerText:Bm,popoverBackdrop:Fm,popoverPositioner:Mm,popoverPopup:Om,search:Um,viewport:Lm,item:zm,highlighted:Km,active:Hm,name:Wm,extra:Qm},Rn=({value:e,onChange:s,chainIds:n,renderExtra:r,fullWidth:o})=>{const[a,i]=f.useState(""),[l,c]=f.useState(!1),[d,u]=f.useState(0),[m,h]=f.useState(),_=f.useRef([]),g=f.useRef(null),p=oe(),j=n.map(y=>p.find(x=>x.chainId===y)).filter(Boolean),S=y=>t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:y,height:y,viewBox:"0 0 14 14",children:[t.jsx("path",{fill:"var(--dimmed)",d:"M5.69625 12.04C8.47976 12.04 10.7362 9.78348 10.7362 6.99996C10.7362 4.21645 8.47976 1.95996 5.69625 1.95996C2.91273 1.95996 0.65625 4.21645 0.65625 6.99996C0.65625 9.78348 2.91273 12.04 5.69625 12.04Z"}),t.jsx("path",{fill:"var(--dimmed)",d:"M9.66003 2.63379C10.85 3.71879 11.6025 5.26754 11.6025 7.00004C11.6025 8.73254 10.85 10.2813 9.66003 11.3663C11.7513 10.99 13.3438 9.19629 13.3438 7.00004C13.3438 4.80379 11.7513 3.00129 9.66003 2.63379Z"})]}),N=f.useMemo(()=>({chainId:"",name:"All",logoUrl:S}),[]),I=f.useMemo(()=>{const y=[N,...j];if(!a)return y;const x=a.toLowerCase();return y.filter($=>$.name.toLowerCase().includes(x)||$.chainId.toLowerCase().includes(x))},[j,a,N]),b=j.find(y=>y.chainId===e)||N,E=parseInt(Xr("--drawer-offset")),D=6,F=()=>{if(i(""),u(-1),g.current){const x=g.current.getBoundingClientRect().bottom+D,$=window.innerHeight-x-2*E;h($)}c(!0)};f.useEffect(()=>{d>=0&&d<_.current.length&&_.current[d]?.scrollIntoView({block:"nearest",behavior:"auto"})},[d]);const C=f.useCallback(y=>{switch(y.key){case"ArrowDown":y.preventDefault(),u(x=>(x+1)%I.length);break;case"ArrowUp":y.preventDefault(),u(x=>(x-1+I.length)%I.length);break;case"Enter":y.preventDefault(),I[d]&&(s(I[d].chainId),c(!1));break;case"Escape":y.preventDefault(),c(!1);break}},[I,d,s,c]),P=y=>{s(y),c(!1)};return t.jsxs(vt.Popover.Root,{open:l,onOpenChange:F,modal:"trap-focus",children:[t.jsx(vt.Popover.Trigger,{render:t.jsxs("button",{className:B(se.trigger,{[se.full]:o}),"aria-expanded":l,role:"listbox",ref:g,children:[t.jsxs("div",{className:se.triggerContent,children:[typeof b.logoUrl=="string"?t.jsx(Q,{src:b.logoUrl,width:14,height:14,logo:!0}):b.logoUrl(14),t.jsx("span",{className:se.triggerText,children:b.name})]}),t.jsx(k.IconChevronDown,{size:16,className:se.icon})]})}),t.jsxs(vt.Popover.Portal,{container:mt(),children:[t.jsx(vt.Popover.Backdrop,{className:se.popoverBackdrop,onClick:()=>c(!1)}),t.jsx(vt.Popover.Positioner,{className:se.popoverPositioner,align:"end",side:"bottom",sideOffset:D,collisionAvoidance:{side:"none"},children:t.jsxs(vt.Popover.Popup,{className:B(se.popoverPopup,{[se.full]:o}),style:{maxHeight:m},children:[t.jsx(Bs,{value:a,onChange:y=>{i(y.target.value),u(0)},onClear:()=>i(""),onKeyDown:C,placeholder:"Search appchains",rootClassName:se.search,ref:Jt()}),t.jsx("div",{className:se.viewport,role:"listbox",children:I.length===0?t.jsx(X,{children:"No appchains found"}):I.map(({chainId:y,name:x,logoUrl:$},T)=>t.jsxs("div",{className:B(se.item,{[se.highlighted]:T===d,[se.active]:e===y}),onClick:()=>P(y),onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),P(y))},onMouseEnter:()=>u(T),role:"option","aria-selected":e===y,tabIndex:-1,ref:R=>{R&&(_.current[T]=R)},children:[typeof $=="string"?t.jsx(Q,{src:$,width:16,height:16,logo:!0}):$(16),t.jsx("span",{className:se.name,children:x}),r&&t.jsx("span",{className:se.extra,children:r(y)})]},y))})]})})]})]})},Vm="_container_t1267_1",Gm="_controls_t1267_7",Ym="_search_t1267_13",Bn={container:Vm,controls:Gm,search:Ym},Zm=({children:e})=>t.jsx("div",{className:Bn.container,children:e}),Jm=({children:e})=>t.jsx("div",{className:Bn.controls,children:e}),Xm=e=>t.jsx(Bs,{...e,rootClassName:Bn.search}),Ye={Root:Zm,Controls:Jm,SearchInput:Xm},e_=G.atom(""),t_=G.atom(""),s_=G.atom(""),n_=G.atom(""),r_=G.atom(""),o_="_change_1x9v4_1",a_="_positive_1x9v4_10",i_="_negative_1x9v4_14",cn={change:o_,positive:a_,negative:i_},To=({amount:e,asset:s})=>{const{denom:n,symbol:r,decimals:o}=s,a=new M(e).isPositive(),i=new M(e).abs().toString();return t.jsxs("div",{className:B(cn.change,a?cn.positive:cn.negative),children:[a?"+":"-",w.formatAmount(i,{decimals:o})," ",r||n]})},c_=({changes:e,chain:s})=>{const n=Ue(s);return e.map(({amount:r,denom:o},a)=>t.jsx(To,{amount:r,asset:n(o)},a))},l_=({changes:e,chain:s})=>{const n=Ue(s);return e.map(({amount:r,metadata:o},a)=>t.jsx(co,{metadata:o,chain:s,children:i=>t.jsx(To,{amount:r,asset:n(i)})},a))},d_=({events:e,chain:s})=>{const{initiaAddress:n,hexAddress:r}=fe();return s.metadata?.is_l1||s.metadata?.minitia?.type==="minimove"?t.jsx(l_,{changes:io(e,r),chain:s}):t.jsx(c_,{changes:ao(e,n),chain:s})},u_="_message_1g2hc_1",h_="_more_1g2hc_8",fr={message:u_,more:h_},m_=({messages:e})=>t.jsxs(t.Fragment,{children:[e.slice(0,3).map((s,n)=>t.jsx("p",{className:fr.message,children:vs.sentenceCase(s["@type"].split("Msg")[1])},n)),e.length>3&&t.jsx("footer",{className:fr.more,children:`+${e.length-3} more`})]}),__="_link_oq58b_1",f_="_inner_oq58b_15",p_="_header_oq58b_20",g_="_time_oq58b_29",x_="_error_oq58b_35",y_="_timestamp_oq58b_39",j_="_chainInfo_oq58b_44",v_="_content_oq58b_52",b_="_messages_oq58b_59",w_="_changes_oq58b_64",Te={link:__,inner:f_,header:p_,time:g_,error:x_,timestamp:y_,chainInfo:j_,content:v_,messages:b_,changes:w_},C_=({txItem:e,chain:s})=>t.jsx(Ds,{txHash:e.txhash,chainId:s.chainId,className:Te.link,children:t.jsxs("div",{className:Te.inner,children:[t.jsxs("div",{className:Te.header,children:[t.jsxs("div",{className:Te.time,children:[e.code!==0&&t.jsx(k.IconWarningFilled,{size:14,className:Te.error}),t.jsx("span",{className:Te.timestamp,children:At.format(new Date(e.timestamp),"h:mm a")})]}),t.jsxs("div",{className:Te.chainInfo,children:[t.jsx(Q,{src:s.logoUrl,width:12,height:12,logo:!0}),t.jsx("span",{children:s.name})]})]}),t.jsxs("div",{className:Te.content,children:[t.jsx("div",{className:Te.messages,children:t.jsx(m_,{messages:e.tx.body.messages})}),t.jsx("div",{className:Te.changes,children:t.jsx(pe,{suspenseFallback:null,errorBoundaryProps:{fallback:null},children:t.jsx(d_,{...e,chain:s})})})]})]})}),I_="_list_1wa9p_1",N_="_dateGroup_1wa9p_7",S_="_dateHeader_1wa9p_12",k_="_more_1wa9p_18",ls={list:I_,dateGroup:N_,dateHeader:S_,more:k_},A_=({list:e,chainId:s})=>{const n=ae(),r=f.useMemo(()=>wo(e,o=>{if(o.timestamp)return new Date(o.timestamp)}),[e]);return e.length===0?t.jsx(X,{children:"No activity found"}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:ls.list,children:Object.entries(r).map(([o,a])=>t.jsxs("div",{className:ls.dateGroup,children:[t.jsx("div",{className:ls.dateHeader,children:o}),a.map(i=>t.jsx(pe,{errorBoundaryProps:{fallback:null},children:t.jsx(C_,{txItem:i,chain:i.chain})},i.txhash))]},o))}),t.jsx(Ds,{chainId:s,accountAddress:n,pathSuffix:"/txs",className:ls.more,showIcon:!0,children:"View more on Initia Scan"})]})},$_=()=>{const{activities:e,isLoading:s}=_c(),[n,r]=G.useAtom(r_),o=le(),a=f.useMemo(()=>Array.from(new Set(e.map(l=>l.chain.chainId))),[e]),i=f.useMemo(()=>n?e.filter(l=>l.chain.chainId===n):e,[e,n]);return s&&e.length===0?t.jsx(X,{children:"Loading activities..."}):!e.length&&!s?t.jsx(X,{children:"No activity yet"}):t.jsxs(Ye.Root,{children:[t.jsx(Ye.Controls,{children:t.jsx(Rn,{value:n,onChange:r,chainIds:a,fullWidth:!0})}),t.jsx(A_,{list:i,chainId:n||o.chainId})]})},T_="2.0.6",E_="_version_1sf5y_1",q_={version:E_},D_=()=>t.jsxs("aside",{className:q_.version,children:["v",T_]}),Eo=f.createContext(null);function qo(){return f.useContext(Eo)}const P_="_popup_nbecp_1",R_="_item_nbecp_19",ds={popup:P_,item:R_},Do=({asset:e,children:s})=>{const{denom:n,decimals:r,symbol:o,logoUrl:a,unlisted:i,address:l,chain:c}=e,{chainId:d}=c,[u,m]=f.useState(!1),h=he(),_=qo(),{showNotification:g}=En(),{defaultChainId:p}=ee(),{evm_chain_id:j}=Gt(),S=ve.useChainId(),{switchChainAsync:N}=ve.useSwitchChain(),{watchAssetAsync:I}=ve.useWatchAsset(),b=()=>{m(!1),h("/send",{denom:n,chain:c})},E=()=>{m(!1),h("/bridge",{srcChainId:d,srcDenom:n,quantity:""})},D=A.useMutation({mutationFn:async()=>{if(!l)throw new Error("Address is required");const F=a;return await N({chainId:Number(j)}),I({type:"ERC20",options:{address:l,symbol:o,decimals:r,image:F}})},onSuccess:()=>{g({type:"success",title:"Asset added",description:"Asset added to wallet"})},onError:F=>{g({type:"error",title:"Asset addition failed",description:F.message})}});return t.jsxs(We.Menu.Root,{open:u,onOpenChange:m,modal:!1,children:[t.jsx(We.Menu.Trigger,{render:s}),t.jsx(We.Menu.Portal,{container:_,children:t.jsx(We.Menu.Positioner,{side:"bottom",sideOffset:-6,align:"end",children:t.jsxs(We.Menu.Popup,{className:ds.popup,children:[t.jsxs(We.Menu.Item,{className:ds.item,onClick:b,children:[t.jsx(k.IconArrowRight,{size:16}),t.jsx("span",{children:"Send"})]}),t.jsxs(We.Menu.Item,{className:ds.item,onClick:E,disabled:i,children:[t.jsx(k.IconSwap,{size:16}),t.jsx("span",{children:"Bridge/Swap"})]}),d===p&&j===S&&!!l&&t.jsxs(We.Menu.Item,{className:ds.item,onClick:()=>D.mutate(),disabled:D.isPending||D.data,children:[D.data?t.jsx(k.IconCheck,{size:16}):t.jsx(k.IconPlus,{size:16}),t.jsx("span",{children:"Add to Wallet"})]})]})})})]})},B_="_item_knoro_1",F_="_info_knoro_22",M_="_images_knoro_28",O_="_name_knoro_32",U_="_value_knoro_38",L_="_amount_knoro_46",z_="_usd_knoro_52",lt={item:B_,info:F_,images:M_,name:O_,value:U_,amount:L_,usd:z_},K_=({asset:e})=>{const{amount:s,value:n,logoUrl:r,chain:o}=e,a=w.formatAmount(s,{decimals:e.decimals});return t.jsx(Do,{asset:e,children:t.jsxs("button",{className:lt.item,children:[t.jsxs("div",{className:lt.info,children:[t.jsx(Rs,{assetLogoUrl:r,chainLogoUrl:o.logoUrl,assetLogoSize:24,chainLogoSize:14,chainLogoOffset:4,className:lt.images}),t.jsx("span",{className:lt.name,children:o.name})]}),t.jsxs("div",{className:lt.value,children:[t.jsx("span",{className:lt.amount,children:a}),Number(n)>0&&t.jsx("span",{className:lt.usd,children:Se(n)})]})]})})},H_="_container_g5q73_1",W_="_assetItem_g5q73_6",Q_="_assetInfo_g5q73_26",V_="_logo_g5q73_32",G_="_symbol_g5q73_36",Y_="_chainName_g5q73_46",Z_="_chainInfos_g5q73_52",J_="_chainLogos_g5q73_58",X_="_chainLogo_g5q73_58",ef="_moreChains_g5q73_69",tf="_expandIcon_g5q73_81",sf="_expanded_g5q73_85",nf="_valueColumn_g5q73_90",rf="_amount_g5q73_99",of="_value_g5q73_90",af="_collapsibleContent_g5q73_112",cf="_chainsList_g5q73_142",J={container:H_,assetItem:W_,assetInfo:Q_,logo:V_,symbol:G_,chainName:Y_,chainInfos:Z_,chainLogos:J_,chainLogo:X_,moreChains:ef,expandIcon:tf,expanded:sf,valueColumn:nf,amount:rf,value:of,collapsibleContent:af,chainsList:cf},lf=G.atom([]),Po=({assetGroup:e})=>{const{symbol:s,logoUrl:n,assets:r}=e,o=r.length===1,[a,i]=G.useAtom(lf),l=f.useMemo(()=>$a(e),[e]),c=f.useMemo(()=>kn(e),[e]),d=a.includes(s),u=()=>{i(h=>d?v.without([s],h):v.uniq([...h,s]))},m=()=>t.jsxs("button",{className:J.assetItem,children:[t.jsxs("div",{className:J.assetInfo,children:[n&&t.jsx(Q,{src:n,width:32,height:32,className:J.logo,logo:!0}),t.jsxs("div",{className:J.details,children:[t.jsx("div",{className:J.symbol,children:s}),o?t.jsx("div",{className:J.chainName,children:r[0].chain.name}):t.jsxs("div",{className:J.chainInfos,children:[t.jsx("div",{className:J.chainLogos,children:r.slice(0,5).map(({chain:h})=>t.jsx(Q,{src:h.logoUrl,width:16,height:16,className:J.chainLogo,logo:!0},h.chainId))}),r.length>5&&t.jsxs("span",{className:J.moreChains,children:["+",r.length-5]}),t.jsx(k.IconChevronDown,{size:16,className:B(J.expandIcon,{[J.expanded]:d})})]})]})]}),t.jsxs("div",{className:J.valueColumn,children:[t.jsx("div",{className:J.amount,children:w.formatNumber(l,{dp:r[0].unlisted?0:6})}),c>0&&t.jsx("div",{className:J.value,children:Se(c)})]})]});if(o){const[h]=r;return t.jsx("div",{className:J.container,children:t.jsx(Do,{asset:h,children:m()})})}return t.jsx("div",{className:J.container,children:t.jsxs(Y.Collapsible.Root,{open:d,onOpenChange:u,children:[t.jsx(Y.Collapsible.Trigger,{asChild:!0,children:m()}),t.jsx(Y.Collapsible.Content,{className:J.collapsibleContent,children:t.jsx("div",{className:J.chainsList,children:r.map(h=>t.jsx(K_,{asset:h},h.chain.chainId))})})]})})},df="_collapsible_1spkj_1",uf="_trigger_1spkj_5",hf="_divider_1spkj_20",mf="_label_1spkj_26",_f="_chevron_1spkj_31",ff="_content_1spkj_39",pf="_list_1spkj_43",Ve={collapsible:df,trigger:uf,divider:hf,label:mf,chevron:_f,content:ff,list:pf},gf=({unlistedAssets:e})=>{const[s,n]=f.useState(!0),r=qo(),o=f.useRef(null),[a,i]=f.useState(0);f.useEffect(()=>{if(o.current){const d=o.current.scrollHeight;i(d)}},[e]);const l=d=>{if(d&&!s&&r?.current){const u=r.current;u.scrollTo({top:u.scrollHeight,behavior:"auto"}),window.setTimeout(()=>{u.scrollTo({top:u.scrollHeight,behavior:"smooth"})},150)}n(d)},c=Je.useSpring({height:s?a:0,opacity:s?1:0,config:{tension:500,friction:30,clamp:!0}});return e.length===0?null:t.jsxs(Y.Collapsible.Root,{open:s,onOpenChange:l,className:Ve.collapsible,children:[t.jsxs(Y.Collapsible.Trigger,{className:Ve.trigger,children:[t.jsx("div",{className:Ve.divider}),t.jsxs("span",{className:Ve.label,children:["Unlisted assets (",e.length,")"]}),t.jsx(k.IconChevronDown,{className:Ve.chevron,size:12,"data-state":s?"open":"closed"}),t.jsx("div",{className:Ve.divider})]}),t.jsx(Y.Collapsible.Content,{forceMount:!0,asChild:!0,children:t.jsx(Je.animated.div,{className:Ve.content,style:c,children:t.jsx("div",{className:Ve.list,ref:o,children:e.map(d=>t.jsx(Po,{assetGroup:{...d,assets:[d]}},d.denom))})})})]})},xf="_list_szwvw_1",yf={list:xf},jf=()=>{const[e,s]=G.useAtom(e_),[n,r]=G.useAtom(t_),{assetGroups:o,unlistedAssets:a,chainsByValue:i,totalValue:l,isLoading:c}=An(),d=i.map(({chainId:h})=>h),u=f.useMemo(()=>{const h=e?o.filter(g=>{const{symbol:p,assets:j}=g;return p.toLowerCase().includes(e.toLowerCase())||j.some(({denom:S,address:N})=>S.toLowerCase().includes(e.toLowerCase())||N?.toLowerCase().includes(e.toLowerCase()))}):o;return n?h.map(g=>({...g,assets:g.assets.filter(({chain:p})=>p.chainId===n)})).filter(g=>g.assets.length>0):h},[o,e,n]),m=f.useMemo(()=>{const h=e?a.filter(({denom:g,address:p})=>g.toLowerCase().includes(e.toLowerCase())||p?.toLowerCase().includes(e.toLowerCase())):a;return n?h.filter(({chain:g})=>g.chainId===n):h},[a,e,n]);return c&&o.length===0?t.jsx(X,{children:"Loading assets..."}):!u.length&&!m.length&&!e&&!n&&!c?t.jsx(X,{children:"No assets"}):t.jsxs(t.Fragment,{children:[t.jsxs(Ye.Root,{children:[t.jsxs(Ye.Controls,{children:[t.jsx(Ye.SearchInput,{value:e,onChange:h=>s(h.target.value),onClear:()=>s(""),placeholder:"Search assets"}),t.jsx(Rn,{value:n,onChange:r,chainIds:d,renderExtra:h=>{if(!h)return Se(l);const _=i.find(g=>g.chainId===h);return _?Se(_.value):null}})]}),t.jsx("div",{children:u.length===0&&m.length===0?t.jsx(X,{children:"No assets found"}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:yf.list,children:u.map(h=>t.jsx(Po,{assetGroup:h},h.symbol))}),t.jsx(gf,{unlistedAssets:m})]})})]}),t.jsx(D_,{})]})},vf="_thumbnail_1lblb_1",bf="_placeholder_1lblb_16",wf="_clickable_1lblb_22",zt={thumbnail:vf,placeholder:bf,clickable:wf},Fn=({nftInfo:e,size:s,onClick:n})=>{const{collection_addr:r,object_addr:o,nft:a,chain:i}=e,{glyphUrl:l}=ee(),c=new URL(`/v1/${i.chainId}/${r}/${o||a.token_id}`,l).toString();return n?t.jsx("button",{className:B(zt.thumbnail,zt.clickable),onClick:n,style:{width:s,height:s},children:t.jsx(Q,{src:c,classNames:{placeholder:zt.placeholder}})}):t.jsx("div",{className:zt.thumbnail,style:{width:s,height:s},children:t.jsx(Q,{src:c,classNames:{placeholder:zt.placeholder}})})},Cf="_nftItem_eopro_1",If="_collectionName_eopro_9",Nf="_nftName_eopro_19",Sf="_chainInfo_eopro_29",us={nftItem:Cf,collectionName:If,nftName:Nf,chainInfo:Sf},kf=({normalizedNft:e})=>{const{collection_name:s,name:n,chain:r}=e,o=he();return t.jsxs("div",{className:us.nftItem,children:[t.jsx(Fn,{nftInfo:e,onClick:()=>o("/nft",e)}),t.jsxs("div",{children:[t.jsx("div",{className:us.collectionName,children:s}),t.jsx("div",{className:us.nftName,children:n}),t.jsxs("div",{className:us.chainInfo,children:[t.jsx(Q,{src:r.logoUrl,width:12,height:12,logo:!0}),t.jsx("span",{children:r.name})]})]})]})},Ro=ke.createQueryKeys("interwovenkit:nft",{nfts:(e,s)=>[e,s],metadata:e=>[e]});function Af(e,s){const{nft:n}=e,r=s.name??n.token_id;return{...e,...n,...s,name:r}}function $f(e,s){return e.flatMap((n,r)=>(s[r]??[]).map(a=>({...a,chain:n})))}const Tf=()=>{const e=ae(),s=oe(),n=A.useQueries({queries:s.map(c=>({queryKey:Ro.nfts(c.indexerUrl,e).queryKey,queryFn:()=>$r(`indexer/nft/v1/tokens/by_account/${e}`,{prefixUrl:c.indexerUrl},"tokens"),staleTime:K.SECOND}))}),r=n.map(v.prop("data")),o=$f(s,r),a=o.reduce((c,{chain:d})=>({...c,[d.chainId]:(c[d.chainId]||0)+1}),{}),i=Object.values(a).reduce((c,d)=>c+d,0),l=n.some(c=>c.isLoading);return{nftInfos:o,chainCounts:a,totalCount:i,isLoading:l}};function Ef(e){const s=pr(e);return A.useQuery({queryKey:Ro.metadata(s).queryKey,queryFn:async()=>{try{if(!s)return{};const n=await Z.get(s).json();return{...n,image:pr(n.image)}}catch{return{}}},staleTime:K.INFINITY})}function pr(e){return e?.replace("ipfs://","https://ipfs.io/ipfs/")}const qf=({nftInfo:e,children:s})=>{const{data:n={}}=Ef(e.nft.uri),r=Af(e,n);return s(r)},Df="_grid_a1fhu_1",Pf={grid:Df},Rf=()=>{const[e,s]=G.useAtom(s_),[n,r]=G.useAtom(n_),{nftInfos:o,chainCounts:a,totalCount:i,isLoading:l}=Tf(),c=f.useMemo(()=>o.filter(({collection_addr:u,collection_name:m,nft:h,object_addr:_,chain:g})=>{if(n&&g.chainId!==n)return!1;if(e){const p=e.trim().toLowerCase();return u.toLowerCase().includes(p)||m.toLowerCase().includes(p)||h.token_id.toLowerCase().includes(p)||_.toLowerCase().includes(p)}return!0}),[o,n,e]),d=f.useMemo(()=>Array.from(new Set(o.map(({chain:u})=>u.chainId))),[o]);return l&&o.length===0?t.jsx(X,{children:"Loading NFTs..."}):!o.length&&!e&&!l?t.jsx(X,{children:"No NFTs"}):t.jsxs(Ye.Root,{children:[t.jsxs(Ye.Controls,{children:[t.jsx(Ye.SearchInput,{value:e,onChange:u=>s(u.target.value),onClear:()=>s(""),placeholder:"Search NFTs"}),t.jsx(Rn,{value:n,onChange:r,chainIds:d,renderExtra:u=>u?a[u]||0:i})]}),c.length===0?t.jsx(X,{children:"No NFTs found"}):t.jsx("div",{className:Pf.grid,children:c.map(u=>{const{collection_addr:m,nft:h}=u;return t.jsx(qf,{nftInfo:u,children:_=>t.jsx(kf,{normalizedNft:_})},m+h.token_id)})})]})},Bf="_totalValue_1udv1_1",Ff="_totalLabel_1udv1_7",Mf="_totalAmount_1udv1_13",Of="_loading_1udv1_18",Uf="_nav_1udv1_23",Lf="_item_1udv1_28",zf="_tabs_1udv1_51",Kf="_tab_1udv1_51",Ce={totalValue:Bf,totalLabel:Ff,totalAmount:Mf,loading:Of,nav:Uf,item:Lf,tabs:zf,tab:Kf},Hf=()=>{po();const e=he(),s=ks(),{totalValue:n,isLoading:r}=An(),o=f.useRef(null);return t.jsx(Eo.Provider,{value:o,children:t.jsxs(ze,{ref:o,children:[t.jsxs("div",{className:Ce.totalValue,children:[t.jsx("div",{className:Ce.totalLabel,children:"Total value"}),t.jsx("div",{className:B(Ce.totalAmount,{[Ce.loading]:r}),children:Se(n)})]}),t.jsxs("div",{className:Ce.nav,children:[t.jsxs(Nn,{to:"/send",className:Ce.item,children:[t.jsx(k.IconArrowRight,{size:16}),t.jsx("span",{children:"Send"})]}),t.jsxs("button",{className:Ce.item,onClick:()=>e("/bridge"),children:[t.jsx(k.IconSwap,{size:16}),t.jsx("span",{children:"Bridge/Swap"})]})]}),t.jsxs(He.Tabs.Root,{value:s,onValueChange:e,children:[t.jsxs(He.Tabs.List,{className:Ce.tabs,children:[t.jsx(He.Tabs.Tab,{className:Ce.tab,value:"/",children:"Assets"}),t.jsx(He.Tabs.Tab,{className:Ce.tab,value:"/nfts",children:"NFTs"}),t.jsx(He.Tabs.Tab,{className:Ce.tab,value:"/activity",children:"Activity"})]}),t.jsx(He.Tabs.Panel,{value:"/",children:t.jsx(jf,{})}),t.jsx(He.Tabs.Panel,{value:"/nfts",children:t.jsx(Rf,{})}),t.jsx(He.Tabs.Panel,{value:"/activity",children:t.jsx($_,{})})]})]})})},Wf="_header_4z0mk_1",Qf="_collectionName_4z0mk_6",Vf="_name_4z0mk_12",Gf="_chainInfo_4z0mk_18",Yf="_attributes_4z0mk_28",Zf="_title_4z0mk_31",Jf="_count_4z0mk_36",Xf="_item_4z0mk_40",ep="_type_4z0mk_46",tp="_value_4z0mk_52",Ee={header:Wf,collectionName:Qf,name:Vf,chainInfo:Gf,attributes:Yf,title:Zf,count:Jf,item:Xf,type:ep,value:tp},sp=ke.createQueryKeys("interwovenkit:nft-details",{validation:e=>[e]}),np=()=>{const e=he(),s=ft(),{collection_name:n,name:r,attributes:o,chain:a,collection_addr:i,token_id:l,object_addr:c}=s,{routerApiUrl:d}=ee(),u=Yt(),m=le(),{initiaAddress:h}=fe(),{simulateTx:_}=Sn(),g=A.useQuery({queryKey:sp.validation({collection_addr:i,nft:s,token_id:l,object_addr:c,sender:h,recipient:h,srcChain:a,dstChain:a,layer1:m,routerApiUrl:d}).queryKey,queryFn:async()=>{const p={from_address:h,from_chain_id:a.chainId,to_address:h,to_chain_id:a.chainId,collection_address:i,token_ids:[l],object_addresses:[c]},{msgs:j}=await Z.create({prefixUrl:d}).post("nft",{json:p}).json(),S=j.map(N=>u.fromAmino(N));return await _({messages:S,chainId:a.chainId})},staleTime:K.INFINITY});return t.jsxs(xt,{title:"NFT details",children:[t.jsxs("header",{className:Ee.header,children:[t.jsx(Fn,{nftInfo:s}),t.jsxs("div",{children:[t.jsx("div",{className:Ee.collectionName,children:n}),t.jsx("h2",{className:Ee.name,children:r}),t.jsxs("div",{className:Ee.chainInfo,children:[t.jsx(Q,{src:a.logoUrl,width:14,height:14,logo:!0}),t.jsx("span",{children:a.name})]})]})]}),t.jsx(re,{children:t.jsx(V.White,{onClick:()=>e("/nft/send",s),disabled:!g.data,loading:g.isLoading?"Checking transferability...":void 0,sm:!0,children:g.error?"Non-transferable NFT":"Send"})}),o&&t.jsxs("div",{className:Ee.attributes,children:[t.jsxs("header",{className:Ee.title,children:["Traits ",t.jsxs("span",{className:Ee.count,children:["(",o.length,")"]})]}),t.jsx("div",{children:o.map(({trait_type:p,value:j})=>t.jsxs("div",{className:Ee.item,children:[t.jsx("div",{className:Ee.type,children:p}),t.jsx("div",{className:Ee.value,children:j})]},p))})]})]})};function rp({balances:e,gasPrices:s,gas:n}){return s.map(({denom:r,amount:o})=>{const a=M(o).times(n).toFixed(0,M.ROUND_CEIL),i=e.find(l=>l.denom===r)?.amount??"0";return{amount:a,denom:r,balance:i}}).filter(({amount:r,balance:o})=>M(o).gte(r))}function op({denom:e,balances:s,gasPrices:n,lastFeeDenom:r,gas:o}){const a=s.find(d=>d.denom===e)?.amount??"0",i=rp({balances:s,gasPrices:n,gas:o}),l=i.find(d=>d.denom===r);if(i.length===0)return a;if(e===r&&l){const d=M(a).minus(l.amount);return M.max(d,0).toString()}const c=i.find(d=>d.denom!==e)||i[0];if(!l&&e===c.denom){const d=M(a).minus(c.amount);return M.max(d,0).toString()}return M(a).toString()}const ap=({chain:e,onSelect:s})=>{const n=ua(e);return t.jsx(es,{assets:n,onSelect:s})},ip=({afterSelect:e})=>{const{watch:s,setValue:n}=ce.useFormContext(),{chainId:r,denom:o}=s(),{chainId:a}=s(),[i,l]=f.useState(a),c=Oe(i),d=oe(),u=m=>{if(r===i&&o===m){e();return}n("chainId",i),n("denom",m),n("quantity","",{shouldTouch:!1,shouldDirty:!1}),e()};return t.jsxs(t.Fragment,{children:[t.jsx(ht.Stack,{children:t.jsx(ht,{chains:d,value:i,onSelect:l})}),t.jsx(pe,{suspenseFallback:t.jsx(es.Placeholder,{}),children:t.jsx(ap,{chain:c,onSelect:u})},i)]})},cp="_fields_brpej_1",lp="_divider_brpej_11",gr={fields:cp,divider:lp},dp=ke.createQueryKeys("interwovenkit:send",{gas:e=>[e]}),up=()=>{const{address:e,initiaAddress:s,estimateGas:n,requestTxSync:r}=fe(),{register:o,watch:a,setValue:i,handleSubmit:l,formState:c}=ce.useFormContext(),{errors:d}=c,{chainId:u,denom:m,recipient:h,quantity:_,memo:g}=a(),p=Oe(u),j=Cn(p),S=ro(p),N=oo(p),I=kr(m,p),{data:b}=Cs(p),{decimals:E}=I,D=j.find(O=>O.denom===m)?.amount??"0",F=b?.find(({id:O})=>O===m)?.price,{data:C=0,isLoading:P}=A.useQuery({queryKey:dp.gas({chainId:u,denom:m,recipient:h,initiaAddress:s}).queryKey,queryFn:()=>{const O=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:Kn.MsgSend.fromPartial({fromAddress:s,toAddress:w.InitiaAddress(h).bech32,amount:[{denom:m,amount:"1"}]})}];return n({messages:O,chainId:u})},enabled:w.InitiaAddress.validate(h),staleTime:K.INFINITY}),y=Math.ceil(C*Wt),x=op({denom:m,balances:j,gasPrices:S,lastFeeDenom:N,gas:y}),$=M(D).isZero(),R=S.some(({denom:O})=>O===m)&&P,L=$||R,{mutate:q,isPending:H}=A.useMutation({mutationFn:({chainId:O,denom:be,quantity:tt,recipient:Ke,memo:st})=>{const de=w.toBaseUnit(tt,{decimals:E}),me=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:Kn.MsgSend.fromPartial({fromAddress:s,toAddress:w.InitiaAddress(Ke).bech32,amount:[{denom:be,amount:de}]})}];return r({messages:me,memo:st,chainId:O,gas:C,gasAdjustment:Wt,gasPrices:S,spendCoins:[{denom:be,amount:de}],internal:"/"})}}),ie=f.useMemo(()=>{if(!_)return"Enter amount";if(d.quantity)return d.quantity.message;if(!h)return"Enter recipient address";if(d.recipient)return d.recipient.message;if(d.memo)return d.memo.message},[_,h,d.quantity,d.recipient,d.memo]);return t.jsx(xt,{title:"Send",children:t.jsxs("form",{onSubmit:l(O=>q(O)),children:[t.jsxs("div",{className:gr.fields,children:[t.jsx(fn,{selectButton:t.jsx(_t,{title:"Select chain and asset",content:O=>t.jsx(ip,{afterSelect:O}),children:t.jsx(vo,{asset:I,chain:p})}),quantityInput:t.jsx(xs,{balance:D,decimals:E}),balanceButton:t.jsx(go,{onClick:()=>i("quantity",w.fromBaseUnit(x,{decimals:E}),{shouldValidate:!0}),disabled:L,children:w.formatAmount(D??"0",{decimals:E})}),value:_?F?Se(M(_).times(F)):"$-":"$0"}),t.jsx("div",{className:gr.divider}),t.jsx(Dn,{myAddress:e}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:"memo",children:"Memo (optional)"}),t.jsx("input",{...o("memo",{validate:O=>!O||new Blob([O]).size<=256||"Memo is too long"}),id:"memo",autoComplete:"off"})]}),t.jsx(ne.Stack,{children:!g&&t.jsx(ne,{level:"warning",children:"Check if the above transaction requires a memo"})})]}),t.jsx(re,{children:t.jsx(V.White,{type:"submit",loading:(P?"Estimating gas...":!1)||H,disabled:!!ie,children:ie??"Confirm"})})]})})},hp=()=>{const e=ft(),s=Gt(),n=Qt(s),{chain:r=s}=e,o=v.head(n);if(!e.denom&&!o)throw new Error("Asset list not found. This occurs during local development when asset list is not configured. Use asset-specific send buttons instead of the default send button, or register chain in Initia Registry with at least one asset defined.");const a=e.denom??o?.denom,i=ce.useForm({mode:"onChange",defaultValues:{chainId:r.chainId,denom:a,quantity:"",recipient:"",memo:""}});return t.jsx(ce.FormProvider,{...i,children:t.jsx(up,{})})},mp="_header_5w36t_1",_p="_name_5w36t_8",fp="_collection_5w36t_15",pp="_nft_5w36t_20",gp="_fields_5w36t_24",xp="_chain_5w36t_29",wt={header:mp,name:_p,collection:fp,nft:pp,fields:gp,chain:xp},yp=ke.createQueryKeys("interwovenkit:send-nft",{simulation:e=>[e]}),jp=()=>{const e=oe(),s=ft(),{chain:n,collection_addr:r,collection_name:o,name:a}=s,{routerApiUrl:i}=ee(),l=Yt(),c=le(),{address:d,initiaAddress:u,requestTxSync:m}=fe(),{watch:h,setValue:_,handleSubmit:g,formState:p}=ce.useFormContext(),{errors:j}=p,S=h(),{recipient:N,dstChainId:I}=S,b=Oe(I),E=A.useQuery({queryKey:yp.simulation({collection_addr:r,nft:s,sender:u,recipient:N,srcChain:n,dstChain:b,layer1:c,routerApiUrl:i}).queryKey,queryFn:async()=>{const $={from_address:u,from_chain_id:n.chainId,to_address:w.InitiaAddress(N).bech32,to_chain_id:b.chainId,collection_address:r,token_ids:[s.token_id],object_addresses:[s.object_addr]},{msgs:T}=await Z.create({prefixUrl:i}).post("nft",{json:$}).json();return T.map(R=>l.fromAmino(R))},enabled:w.InitiaAddress.validate(N)}),{data:D,isLoading:F,error:C}=E,{mutate:P,isPending:y}=A.useMutation({mutationFn:async()=>{if(!D)throw new Error("Route not found");await m({messages:D,chainId:n.chainId,internal:"/nfts"})}}),x=f.useMemo(()=>{if(!N)return"Enter recipient address";if(j.recipient)return j.recipient.message;if(C)return"Route not found"},[N,j.recipient,C]);return t.jsxs("form",{onSubmit:g(()=>P()),children:[t.jsxs("header",{className:wt.header,children:[t.jsx(Fn,{nftInfo:s,size:80}),t.jsxs("div",{className:wt.name,children:[t.jsx("div",{className:wt.collection,children:o}),t.jsx("div",{className:wt.nft,children:a})]})]}),t.jsxs("div",{className:wt.fields,children:[t.jsx(Y.VisuallyHidden.Root,{children:t.jsxs("div",{children:[t.jsx("div",{className:"label",children:"Destination appchain"}),t.jsxs(_t,{title:"Destination appchain",content:$=>t.jsx(jo,{onSelect:({chainId:T})=>{_("dstChainId",T),$()},list:e,getImage:T=>T.logoUrl,getName:T=>T.name,getKey:T=>T.chainId}),className:B("input",wt.chain),children:[t.jsx(Q,{src:b.logoUrl,width:20,height:20,logo:!0}),t.jsx("span",{children:b.name})]})]})}),t.jsx(Dn,{myAddress:d,ref:Jt()})]}),t.jsx(re,{children:t.jsx(V.White,{loading:(F?"Finding route...":!1)||y,disabled:!!x,children:x??"Confirm"})})]})},vp=()=>{const{chain:e}=ft(),s=ce.useForm({mode:"onChange",defaultValues:{dstChainId:e.chainId,recipient:""}});return t.jsx(xt,{title:"Send NFT",children:t.jsx(ce.FormProvider,{...s,children:t.jsx(jp,{})})})},Bo=()=>{const e=he(),s=ks(),n=Et(),{closeDrawer:r}=Tt(),{closeModal:o}=As();f.useEffect(()=>{o(),s.startsWith("/bridge/")&&e("/bridge"),(s==="/collection"||s.startsWith("/nft"))&&e("/nfts")},[n]);const a=$s();if(f.useEffect(()=>{a("Page View")},[s,a]),s==="/connect")return n?null:t.jsx(_r,{onSuccess:r});if(s==="/blank")return null;if(!n)return t.jsx(_r,{});switch(s){case"/":case"/nfts":case"/activity":return t.jsx(Hf,{});case"/send":return t.jsx(hp,{},n);case"/nft":return t.jsx(np,{});case"/nft/send":return t.jsx(vp,{},n);case"/bridge":return t.jsx(Eu,{},n);case"/bridge/preview":return t.jsx(Kh,{});case"/bridge/history":return t.jsx(vh,{});case"/op/withdrawals":return t.jsx(bm,{});case"/tx":return t.jsx(uo,{})}},bp="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@100..700&display=swap",wp=()=>t.jsxs(t.Fragment,{children:[t.jsx("link",{rel:"preconnect",href:"https://fonts.googleapis.com"}),t.jsx("link",{rel:"preconnect",href:"https://fonts.gstatic.com",crossOrigin:""}),t.jsx("link",{rel:"stylesheet",href:bp}),t.jsx("link",{rel:"stylesheet",href:"https://assets.initia.xyz/fonts/PilatWide.css"})]}),Cp=()=>{oe();const e=le();return $n(),kt(localStorage.getItem(U.BRIDGE_SRC_CHAIN_ID)??e.chainId),kt(localStorage.getItem(U.BRIDGE_DST_CHAIN_ID)??e.chainId),null},Ip=new A.QueryClient({defaultOptions:{queries:{retry:0}}}),Np=({children:e,...s})=>(f.useEffect(()=>{Ma()},[]),Ne.useIsClient()?t.jsxs(t.Fragment,{children:[t.jsx(wp,{}),t.jsx(Cr.Provider,{value:{...wr,...s},children:t.jsx(Or,{children:t.jsx(gl,{children:t.jsx(Y.Tooltip.Provider,{delayDuration:0,skipDelayDuration:0,children:t.jsx(pl,{children:t.jsxs(rl,{children:[e,t.jsxs(A.QueryClientProvider,{client:Ip,children:[t.jsx(Oa,{}),t.jsx(pe,{suspenseFallback:null,errorBoundaryProps:{fallback:null},children:t.jsx(Cp,{})}),t.jsx(Hi,{children:t.jsx(Bo,{})})]})]})})})})})})]}):null),Sp=({bridge:e})=>t.jsx(Or,{initialEntry:{path:e?"/bridge":"/",state:e},children:t.jsx("div",{className:"body",children:t.jsx(to.Provider,{value:!!e,children:t.jsx(pe,{children:t.jsx(Bo,{})})})})});exports.DEFAULT_GAS_ADJUSTMENT=Wt;exports.DEFAULT_GAS_PRICE_MULTIPLIER=br;exports.InterwovenKit=Sp;exports.InterwovenKitProvider=Np;exports.MAINNET=wr;exports.MoveError=Lr;exports.TESTNET=Jo;exports.initiaPrivyWallet=ea;exports.initiaPrivyWalletConnector=Xo;exports.initiaPrivyWalletOptions=bs;exports.injectStyles=si;exports.useAddress=Et;exports.useHexAddress=Es;exports.useInitiaAddress=ae;exports.useInterwovenKit=fe;exports.usePortfolio=An;exports.useUsernameQuery=Vr;
|
|
4
|
+
</svg>`,Fa=encodeURIComponent(Ma),Rn=`data:image/svg+xml;utf8,${Fa}`,js=Ne.createQueryKeys("interwovenkit:asset",{list:e=>[e],item:(e,s)=>[e,s],resource:(e,s)=>[e.chainId,s.denom],denom:(e,s)=>[e,s],metadata:(e,s)=>[e,s]});function Oa(e){const{base:s,symbol:n,denom_units:r=[],display:o,logo_URIs:a,name:i,address:c,traces:l}=e,d=r.find(h=>h.denom===o)?.exponent??r.find(h=>h.denom===s)?.exponent??w.head(r)?.exponent??0,u=a?.png??"";return{denom:s,symbol:n,decimals:d,logoUrl:u,name:i,address:c,traces:l}}function Jr(){const e=$.useQueryClient();return s=>{const n=s?.metadata?.assetlist;return $.queryOptions({queryKey:js.list(n).queryKey,queryFn:async()=>n?L.get(n).json():{assets:[]},select:({assets:r})=>{if(!s)return[];const o=r.map(Oa);for(const a of o)e.setQueryData(js.item(s.chainId,a.denom).queryKey,a);return o},staleTime:Q.MINUTE})}}function Vt(e){const s=Jr(),{data:n}=$.useSuspenseQuery(s(e));return n}function Ua(){const e=ae(),s=Jr();return $.useQueries({queries:e.map(n=>s(n))})}function Ge(e){const s=Vt(e),n=_e(),r=Vt(n),o=Xr(e);return a=>{const i=s.find(l=>l.denom===a);if(i)return i;const c=r.find(l=>l.denom===o(a));return c?{...c,denom:a}:{denom:a,symbol:"",decimals:0,logoUrl:Rn}}}function Zr(e,s){const n=Ge(s),o=$.useQueryClient().getQueryData(js.item(s.chainId,e).queryKey);return o||n(e)}function Xr(e){const s=_e(),n=Vt(e);return r=>{if(e.metadata?.is_l1)return r;if(r.startsWith("l2/")||r.startsWith("ibc/")){const a=n.find(i=>i.denom===r)?.traces;if(a){for(const i of a)if(i.counterparty.chain_name===s.chain_name)return i.counterparty.base_denom}}const o=s.metadata?.ibc_channels?.find(({chain_id:a,version:i})=>a===e.chain_id&&i==="ics20-1")?.channel_id;return o?v.getIbcDenom(o,r):""}}function La(e){return e.pagination?.next_key??null}async function eo(e,s,n){const r=L.create(s),o=async(a,i)=>{const c=await r.extend(i?{searchParams:{"pagination.key":i}}:{}).get(e).json(),l=c[n]??[],d=La(c),u=[...a,...l];return d?o(u,d):u};return o([],null)}const cr="usernames";function za({restUrl:e,moduleAddress:s}){const{viewFunction:n}=v.createMoveClient(e);async function r(i){if(!v.InitiaAddress.validate(i))return null;const c=await n({moduleAddress:s,moduleName:cr,functionName:"get_name_from_address",typeArgs:[],args:[V.toBase64(v.InitiaAddress(i,32).bytes)]});return c?c+".init":null}function o(i){return/^[A-Za-z0-9-]{3,64}\.init$/.test(i)}async function a(i){if(!o(i))return null;const c=await n({moduleAddress:s,moduleName:cr,functionName:"get_address_from_name",typeArgs:[],args:[va.bcs.string().serialize(i.toLowerCase().replace(".init","")).toBase64()]});return c?v.InitiaAddress(c).bech32:null}return{restUrl:e,getUsername:r,getAddress:a,validateUsername:o}}const $s=Ne.createQueryKeys("interwovenkit:account",{username:(e,s)=>[e,s],address:(e,s)=>[e,s],balances:(e,s)=>[e,s],txs:(e,s)=>[e,s]});function to(){const{restUrl:e}=_e(),{usernamesModuleAddress:s}=X();return za({restUrl:e,moduleAddress:s})}function so(){const e=ee();return s=>$.queryOptions({queryKey:$s.balances(s.restUrl,e).queryKey,queryFn:()=>eo(`cosmos/bank/v1beta1/balances/${e}`,{prefixUrl:s.restUrl},"balances"),staleTime:Q.SECOND})}function Bn(e){const s=so(),{data:n}=$.useSuspenseQuery(s(e));return n}function Ka(){const e=ae(),s=so();return $.useQueries({queries:e.map(n=>s(n))})}function Wa(e){const s=Bn(e),n=Vt(e),r=Ge(e),o=Xr(e),{data:a}=ks(e),i=l=>e.fees.fee_tokens.some(d=>d.denom===l),c=l=>n.some(d=>d.denom===l);return w.sortWith([w.descend(({denom:l})=>o(l)==="uinit"),w.descend(({denom:l})=>i(l)),w.descend(({value:l})=>l),w.descend(({denom:l})=>c(l)),({balance:l},{balance:d})=>F(d).comparedTo(l)??0,w.descend(({symbol:l})=>l.toLowerCase())],s.filter(({amount:l})=>!F(l).isZero()).map(({amount:l,denom:d})=>{const u=r(d),h=a?.find(({id:f})=>f===u?.denom)?.price??0,m=F(l).times(h).div(F(10).pow(u.decimals)).toNumber();return{...u,balance:l,price:h,value:m}}))}const no=_.createContext(null);function Ts(){return _.useContext(no)}function ro(){const{location:e}=Ts();return e}function Es(){const{path:e}=ro();return e}function jt(){const{state:e={}}=ro();return e}function Ha(){const{history:e}=Ts();return e}function he(){const{navigate:e}=Ts();return e}function oo(){const{reset:e}=Ts();return e}const Et=({to:e,state:s,shouldReset:n,children:r,onClick:o,...a})=>{const i=he(),c=oo(),l=d=>{d.preventDefault(),o?.(d),n?c(e,s):i(e,s)};return t.jsx("button",{type:"button",...a,onClick:l,children:r})},ao=({children:e,initialEntry:s})=>{const[n,r]=_.useState([s??{path:"/"}]),o=n[n.length-1],a=_.useCallback((c,l)=>{r(d=>{if(typeof c=="string")return[...d,{path:c,state:l}];const u=d.length+c;if(u<1)return d;const h=w.take(u,d);return l!==void 0?w.adjust(u-1,m=>({...m,state:l}),h):h})},[]),i=_.useCallback((c,l)=>{r([{path:c,state:l}])},[]);return t.jsx(no.Provider,{value:{location:o,history:n,navigate:a,reset:i},children:e})},Qa="c33b940c24c17e95f7d9d525d508ac61";function Ga(){const{disableAnalytics:e}=X();_.useEffect(()=>{e||Dn.init(Qa,{autocapture:!1})},[e])}function Va(){const{connector:e}=de.useAccount(),{defaultChainId:s,disableAnalytics:n}=X();_.useEffect(()=>{const r=new Lr.Identify;e?.name&&r.set("connector",e.name),s&&r.set("defaultChainId",s),Dn.identify(r)},[s,e?.name,n])}function qs(){const e=Es();return _.useCallback((n,r)=>{Dn.track(n,{path:e,...r})},[e])}const Ee="interwovenkit",Ya=1e3,io=60*Ya,co=60*io,lr=24*co,U={PUBLIC_KEY:`${Ee}:public-key`,BRIDGE_SRC_CHAIN_ID:`${Ee}:bridge:src-chain-id`,BRIDGE_SRC_DENOM:`${Ee}:bridge:src-denom`,BRIDGE_DST_CHAIN_ID:`${Ee}:bridge:dst-chain-id`,BRIDGE_DST_DENOM:`${Ee}:bridge:dst-denom`,BRIDGE_QUANTITY:`${Ee}:bridge:quantity`,BRIDGE_SLIPPAGE_PERCENT:`${Ee}:bridge:slippage-percent`,BRIDGE_ROUTE_TYPE:`${Ee}:bridge:route-type`,BRIDGE_HISTORY:`${Ee}:bridge:history`,OP_REMINDER:`${Ee}:op:reminder`},Ja=H.atom(!1);function Ve(){const e=oo(),[s,n]=H.useAtom(Ja),r=qs();return{isDrawerOpen:s,openDrawer:(i,c)=>{i&&e(i,c),n(!0),r("Widget Opened")},closeDrawer:()=>{n(!1),r("Widget Closed")}}}function Mn(){const e=he(),{closeDrawer:s}=Ve(),{disconnect:n}=de.useDisconnect();return()=>{e("/blank"),s(),n(),localStorage.removeItem(U.BRIDGE_SRC_CHAIN_ID),localStorage.removeItem(U.BRIDGE_SRC_DENOM),localStorage.removeItem(U.BRIDGE_DST_CHAIN_ID),localStorage.removeItem(U.BRIDGE_DST_DENOM),localStorage.removeItem(U.BRIDGE_QUANTITY),localStorage.removeItem(U.BRIDGE_SLIPPAGE_PERCENT)}}function Fn(){const{privyContext:e}=X(),{address:s}=de.useAccount();return e?s?!!e.privy.user?.linkedAccounts.map(r=>"address"in r&&r.address).filter(r=>!!r)?.some(r=>v.InitiaAddress.equals(r,s)):!1:!0}function Za(){const{privyContext:e}=X(),s=Fn(),{address:n}=de.useAccount(),{signMessageAsync:r}=de.useSignMessage(),o=Mn(),a=!!e?.privy.ready,i=_.useRef(e);_.useEffect(()=>{i.current=e},[e]);const c=async l=>{try{if(!i.current)throw new Error("Privy context not found");i.current.privy.authenticated&&await i.current.privy.logout();const d=await i.current.siwe.generateSiweMessage({chainId:"eip155:1",address:l});if(!d)throw new Error("Failed to generate SIWE message");const u=await r({message:d});await i.current.siwe.loginWithSiwe({signature:u,message:d})}catch{o()}};_.useEffect(()=>{s||a&&n&&c(n)},[s,a,n])}function Xa(e){if(e?.typeUrl==="/initia.crypto.v1beta1.ethsecp256k1.PubKey"){const{key:s}=vn.PubKey.decode(e.value);return Qt.encodeSecp256k1Pubkey(s)}return Is.decodeOptionalPubkey(e)}function ei({typeUrl:e,value:s}){if(e==="/cosmos.auth.v1beta1.BaseAccount"){const{address:n,pubKey:r,accountNumber:o,sequence:a}=ba.BaseAccount.decode(s),i=Xa(r);return{address:n,pubkey:i,accountNumber:Number(o),sequence:Number(a)}}return Pe.accountFromAny({typeUrl:e,value:s})}function ti(e){return e.type==="initia/PubKeyEthSecp256k1"}const si={...Qt.pubkeyType,ethsecp256k1:"initia/PubKeyEthSecp256k1"};function ni(e){if(ti(e)){const s=vn.PubKey.fromPartial({key:V.fromBase64(e.value)});return Ca.Any.fromPartial({typeUrl:"/initia.crypto.v1beta1.ethsecp256k1.PubKey",value:Uint8Array.from(vn.PubKey.encode(s).finish())})}return Is.encodePubkey(e)}function lo(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");return{type:si.ethsecp256k1,value:V.toBase64(e)}}function ri(e,s){if(s.length!==64)throw new Error("Signature must be 64 bytes long. Cosmos SDK uses a 2x32 byte fixed length encoding for the secp256k1 signature integers r and s.");return{pub_key:lo(e),signature:V.toBase64(s)}}const Xt=()=>{const e=X();return new Is.Registry([...Ht.protoRegistry,...e.protoTypes??[]])},Ds=()=>{const e=X();return new Pe.AminoTypes({...Ht.aminoConverters,...e.aminoConverters})};class uo{constructor(s,n,r){this.address=s,this.signMessage=n,this.restUrl=r}cachedPublicKey=null;async getCachedPublicKey(){if(this.cachedPublicKey)return this.cachedPublicKey;const s=`${U.PUBLIC_KEY}:${this.address}`,n=localStorage.getItem(s);if(n)return this.cachedPublicKey=V.fromHex(n),V.fromHex(n);const r=await this.getPublicKeyFromRestApi();if(r)return this.cachedPublicKey=r,localStorage.setItem(s,V.toHex(r)),r;const o=await this.getPublicKey();return this.cachedPublicKey=o,localStorage.setItem(s,V.toHex(o)),o}async getPublicKeyFromRestApi(){try{const n=(await L.create({prefixUrl:this.restUrl}).get(`cosmos/auth/v1beta1/account_info/${this.address}`).json())?.info?.pub_key?.key;return n?V.fromBase64(n):null}catch{return null}}async getPublicKey(){const s="Sign this message to identify your Initia account.",n=await this.signMessage(s),r=We.ethers.hashMessage(s),o=We.ethers.SigningKey.recoverPublicKey(r,n);return jn.Secp256k1.compressPubkey(V.fromHex(o.replace("0x","")))}async getAccounts(){return[{address:this.address,algo:"ethsecp256k1",pubkey:await this.getCachedPublicKey()}]}async signAmino(s,n){if(this.address!==s)throw new Error("Signer address does not match the provided address");const r=yn.escapeCharacters(yn.sortedJsonStringify(n)),o=await this.signMessage(r),a=V.fromHex(o.replace("0x","")).subarray(0,-1),c=jn.Secp256k1Signature.fromFixedLength(a).toFixedLength(),l=ri(await this.getCachedPublicKey(),c);return{signed:n,signature:l}}}function Ps(){const e=Xt(),s=Ds(),n=es(),r=mo();return async function(o,a,i,c,l,d){const u=d?.customSigner??n;if(!u)throw new Error("Signer not initialized");const h=await r(o),{accountNumber:m,...f}=await h.getSequence(a),g=f.sequence+(d?.incrementSequence??0),[p]=await u.getAccounts(),x=ni(lo(p.pubkey)),S=wa.SignMode.SIGN_MODE_EIP_191,I=i.map(y=>s.toAmino(y)),N=yn.makeSignDoc(I,c,o,l,m,g),{signature:C,signed:T}=await u.signAmino(a,N),R={typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{messages:T.msgs.map(y=>s.fromAmino(y)),memo:l}},B=e.encode(R),z=sr.Int53.fromString(T.fee.gas).toNumber(),j=sr.Int53.fromString(T.sequence).toNumber(),b=Is.makeAuthInfoBytes([{pubkey:x,sequence:j}],T.fee.amount,z,T.fee.granter,T.fee.payer,S);return st.TxRaw.fromPartial({bodyBytes:B,authInfoBytes:b,signatures:[V.fromBase64(C.signature)]})}}function es(){const e=ee(),{signMessageAsync:s}=de.useSignMessage(),n=_e();return _.useMemo(()=>new uo(e,r=>s({message:r}),n.restUrl),[e,s,n.restUrl])}const Zs=new Map,Xs=new Map;function ho(){const e=Te();return async s=>{if(Zs.has(s))return Zs.get(s);const{rpcUrl:n}=e(s),r=await nr.Comet38Client.create(new nr.HttpClient(n));return Zs.set(s,r),r}}function mo(){const e=Xt(),s=Ds(),n=es(),r=ee(),o=ho();return async a=>{const i=`${r}:${a}`;if(Xs.has(i))return Xs.get(i);if(!n)throw new Error("Signer not initialized");const c=await o(a),l=await Pe.SigningStargateClient.createWithSigner(c,n,{registry:e,aminoTypes:s,accountParser:ei,broadcastPollIntervalMs:500});return Xs.set(i,l),l}}function fo(){const{connector:e}=de.useAccount();return async()=>{if(!e)throw new Error("Wallet not connected");return new We.BrowserProvider(await e.getProvider())}}function _o(){const e=ee(),s=Te();return{fetchFeegrant:async(o,a)=>{if(!e)return null;const i=s(o),c=L.create({prefixUrl:i.restUrl});try{const{allowance:l}=await c.get(`cosmos/feegrant/v1beta1/allowance/${e}/${a}`).json();return l}catch{return null}},fetchGrants:async(o,a)=>{if(!e)return[];const i=s(o),c=L.create({prefixUrl:i.restUrl}),{grants:l}=await c.get("cosmos/authz/v1beta1/grants",{searchParams:{granter:e,grantee:a}}).json();return l}}}function go(){const{privyContext:e}=X(),s=Fn();if(!(!e||!s))return e.wallets.find(n=>n.connectorType==="embedded")}function Rs(){const e=go();return e?.address?v.InitiaAddress(e.address).bech32:void 0}function po(){const e=go(),s=Rs(),n=Xt(),r=Te(),o=Ps();return async(a,i,c,l,d)=>{if(!e||!s)throw new Error("Embedded wallet not initialized");const u=[{typeUrl:"/cosmos.authz.v1beta1.MsgExec",value:qn.MsgExec.fromPartial({grantee:s,msgs:c.map(f=>({typeUrl:f.typeUrl,value:n.encode(f)}))})}],h={...l,granter:i},m=new uo(s,e.sign,r(a).restUrl);return await o(a,s,u,h,d,{customSigner:m})}}const Yt=Ne.createQueryKeys("interwovenkit:autosign",{expirations:(e,s)=>[e,s],grants:(e,s)=>[e,s]});function Bs(){const e=X(),s=Zt(),{enableAutoSign:n,defaultChainId:r}=e;if(!n)return{[r]:[]};if(typeof n!="boolean")return n;switch(s.metadata?.minitia?.type){case"minievm":return{[r]:["/minievm.evm.v1.MsgCall"]};case"miniwasm":return{[r]:["/cosmwasm.wasm.v1.MsgExecuteContract"]};default:return{[r]:["/initia.move.v1.MsgExecute"]}}}function xo(){const{data:e}=On(),s=Bs();return async(n,r)=>{const o=r.every(i=>{const c=s[n];return c?c.includes(i.typeUrl):!1}),a=e?.isEnabledByChain[n]??!1;return o&&a}}function On(){const e=ee(),s=Rs(),n=Bs(),{fetchFeegrant:r,fetchGrants:o}=_o();return $.useQuery({queryKey:Yt.expirations(e,s).queryKey,queryFn:async()=>{if(!e||!s)return{expiredAtByChain:{},isEnabledByChain:{}};const a={};for(const[c,l]of Object.entries(n))try{const d=await o(c,s);if(!l.every(x=>d.some(S=>S.authorization?.msg===x))){a[c]=null;continue}const h=await r(c,s);if(!h){a[c]=null;continue}const m=d.filter(x=>l.includes(x.authorization.msg)).map(x=>x.expiration),f=h.allowance.expiration,g=[...m,f],p=Un(g);a[c]=p?new Date(p):void 0}catch{a[c]=null}const i={};for(const[c,l]of Object.entries(a))switch(l){case null:i[c]=!1;break;case void 0:i[c]=!0;break;default:i[c]=ke.isFuture(l);break}return{expiredAtByChain:a,isEnabledByChain:i}},staleTime:Q.INFINITY,retry:!1})}function oi(){const{data:e,refetch:s}=On();_.useEffect(()=>{if(!e)return;const n=new Date,r=Object.values(e.expiredAtByChain).filter(c=>c instanceof Date&&ke.isFuture(c));if(r.length===0)return;const a=Un(r).getTime()-n.getTime();if(a<=0)return;const i=setTimeout(()=>{s()},a+100);return()=>clearTimeout(i)},[e,s])}function Un(e){return e.filter(s=>s!==void 0).toSorted((s,n)=>new Date(s).getTime()-new Date(n).getTime())[0]}const yo=_.createContext(null),Ms=()=>_.useContext(yo);class jo extends Error{originalError;moduleAddress;moduleName;errorCode;errorCodeHex;isFromRegistry;constructor(s,n,r,o,a,i,c){super(s),this.name="MoveError",this.originalError=n,this.moduleAddress=r,this.moduleName=o,this.errorCode=a,this.errorCodeHex=i,this.isFromRegistry=c}}const ai=/VM aborted: location=([0-9A-Fa-f]+)::(\w+), code=(\d+)/,en=new Map;function ii(e){const s=e.match(ai);if(!s)return null;const[,n,r,o]=s;return{moduleAddress:`0x${n.replace(/^0+/,"")||"0"}`,moduleName:r,errorCode:o.replace(/^0+/,"")||"0"}}async function ci(e,s,n){const r=`${e}:${s}`;if(en.has(r))return en.get(r);try{const o=s==="0x1"?"0x1.json":`${e}/${s}.json`,a=`${n}/errors/${o}`,{errors:i={}}=await L.get(a).json();return en.set(r,i),i}catch{return null}}function li(e,s,n,r,o,a,i){return new jo(e,s,n,r,o,a,i)}async function At(e,s,n){if(!s.metadata?.is_l1&&s.metadata?.minitia?.type!=="minimove")return await He(e);const r=ii(e.message);if(!r)return await He(e);const o=await ci(s.chain_name,r.moduleAddress,n),a=`0x${parseInt(r.errorCode,10).toString(16)}`,i=`Failed with code ${a} in module ${r.moduleName} at ${r.moduleAddress}`,c=o?.[r.moduleName]?.[r.errorCode],l=c||i,d=!!c;return li(l,e,r.moduleAddress,r.moduleName,r.errorCode,a,d)}const vo="approve",Fs=H.atom(),wo=H.atom(null);function bo(){const e=H.useAtomValue(Fs);if(!e)throw new Error("Tx request not found");return e}function Os(){const e=he(),s=ee(),{defaultChainId:n,registryUrl:r}=X(),o=Te(),{openDrawer:a,closeDrawer:i}=Ve(),{openModal:c,closeModal:l}=Ms(),d=H.useSetAtom(Fs),u=H.useSetAtom(wo),h=ho(),m=mo(),f=es(),g=Xt(),p=xo(),x=po(),S=Ps(),I=async({messages:j,memo:b,chainId:y=n})=>{try{return await(await m(y)).simulate(s,j,b)}catch(k){throw await At(k,o(y),r)}},N=async({messages:j,memo:b,chainId:y=n})=>{const k=await h(y),q=Pe.QueryClient.withExtensions(k,Pe.setupTxExtension),M=j.map(Z=>g.encodeAsAny(Z)),[E]=await f.getAccounts(),G=Qt.encodeSecp256k1Pubkey(E.pubkey),te=await m(y),{sequence:O}=await te.getSequence(s);return q.tx.simulate(M,b,G,O)},C=async({txRequest:j,broadcaster:b})=>{const k={...{memo:"",chainId:n,gas:j.gas||await I(j),gasAdjustment:Gt,gasPrices:null,spendCoins:[],internal:!1},...j};return new Promise((q,M)=>{d({txRequest:k,resolve:async G=>{try{const te=await m(k.chainId),O=await b(te,st.TxRaw.encode(G).finish());q(O),typeof k.internal=="string"&&e(k.internal)}catch(te){M(await At(te,o(k.chainId),r))}finally{E()}},reject:G=>{M(G),E()}}),k.internal?c({path:"/tx"}):a("/tx");const E=()=>{if(!k.internal){e("/blank"),i();return}l()}})},T=async j=>{const b=j.chainId??n;try{const y=await C({txRequest:j,broadcaster:async(k,q)=>await k.broadcastTxSync(q)});return j.internal&&typeof j.internal!="number"&&(u({txHash:y,chainId:b,status:"loading"}),z({txHash:y,chainId:j.chainId}).then(k=>{u({status:k.code===0?"success":"error",chainId:b,txHash:y})}).catch(()=>{u({status:"error",chainId:b,txHash:y})})),y}catch(y){throw j.internal&&typeof j.internal!="number"&&u({status:"error",chainId:b,error:y}),y}},P=(j,b=30*1e3,y=.5*1e3)=>C({txRequest:j,broadcaster:async(k,q)=>{const M=await k.broadcastTx(q,b,y);if(M.code!==0)throw new Error(M.rawLog);return M}}),R=async j=>{const b=j.chainId??n;try{const{messages:y,memo:k="",fee:q}=j,M=await m(b),G=await p(b,y)?await x(b,s,y,q,k):await S(b,s,y,q,k);return await M.broadcastTxSync(st.TxRaw.encode(G).finish())}catch(y){throw await At(y,o(b),r)}},B=async(j,b=30*1e3,y=.5*1e3)=>{const k=j.chainId??n;try{const{messages:q,memo:M="",fee:E}=j,G=await m(k),O=await p(k,q)?await x(k,s,q,E,M):await S(k,s,q,E,M),Z=await G.broadcastTx(st.TxRaw.encode(O).finish(),b,y);if(Z.code!==0)throw new Error(Z.rawLog);return Z}catch(q){throw await At(q,o(k),r)}},z=async({chainId:j=n,...b})=>{try{const y=await m(j);return await Co({...b,client:y})}catch(y){throw await At(y,o(j),r)}};return{estimateGas:I,simulateTx:N,requestTxSync:T,requestTxBlock:P,submitTxSync:R,submitTxBlock:B,waitForTxConfirmation:z}}async function Co({txHash:e,client:s,timeoutMs:n=30*1e3,intervalMs:r=.5*1e3}){const o=Date.now();for(;;){const a=await s.getTx(e);if(a){if(a.code!==0)throw new Error(a.rawLog);return a}if(Date.now()-o>=n)throw new Error(`Transaction was submitted, but not found on the chain within ${n/1e3} seconds.`);await new Promise(i=>setTimeout(i,r))}}const ts=H.atom(null);function Io(){const e=ee(),s=Bs(),{fetchFeegrant:n,fetchGrants:r}=_o();return async o=>{const{chainId:a,grantee:i}=o;if(!e)throw new Error("Granter wallet not initialized");const c=await n(a,i),l=await r(a,i),d=c?[{typeUrl:"/cosmos.feegrant.v1beta1.MsgRevokeAllowance",value:zr.MsgRevokeAllowance.fromPartial({granter:e,grantee:i})}]:[],u=s[a].filter(h=>l.some(m=>m?.authorization?.msg===h)).map(h=>({typeUrl:"/cosmos.authz.v1beta1.MsgRevoke",value:qn.MsgRevoke.fromPartial({granter:e,grantee:i,msgTypeUrl:h})}));return[...d,...u]}}function di(){const{privyContext:e}=X(),s=ee(),n=Rs(),r=Bs(),{requestTxBlock:o}=Os(),a=$.useQueryClient(),[i,c]=H.useAtom(ts),{closeDrawer:l}=Ve(),d=Io(),u=async()=>{if(n)return n;if(!e)throw new Error("Privy context not available");const h=await e.createWallet({createAdditional:!1});return v.InitiaAddress(h.address).bech32};return $.useMutation({mutationFn:async h=>{if(!i)throw new Error("No pending request");const{chainId:m}=i,f=await u();if(!s||!f)throw new Error("Wallets not initialized");const g=await d({chainId:m,grantee:f}),p=h===0?void 0:ke.addMilliseconds(new Date,h),x={typeUrl:"/cosmos.feegrant.v1beta1.MsgGrantAllowance",value:zr.MsgGrantAllowance.fromPartial({granter:s,grantee:f,allowance:{typeUrl:"/cosmos.feegrant.v1beta1.BasicAllowance",value:or.BasicAllowance.encode(or.BasicAllowance.fromPartial({expiration:p})).finish()}})},S=r[m].map(N=>({typeUrl:"/cosmos.authz.v1beta1.MsgGrant",value:qn.MsgGrant.fromPartial({granter:s,grantee:f,grant:{authorization:{typeUrl:"/cosmos.authz.v1beta1.GenericAuthorization",value:rr.GenericAuthorization.encode(rr.GenericAuthorization.fromPartial({msg:N})).finish()},expiration:p}})})),I=[...g,x,...S];await o({messages:I,chainId:m,internal:!0})},onSuccess:async()=>{await a.invalidateQueries({queryKey:Yt.expirations._def}),i?.resolve()},onError:h=>{i?.reject(h)},onSettled:()=>{c(null),l()}})}function No(e){const s=X(),n=Rs(),r=e?.grantee||n,{requestTxBlock:o}=Os(),a=$.useQueryClient(),i=Io();return $.useMutation({mutationFn:async(c=s.defaultChainId)=>{if(!r)throw new Error("Wallets not initialized");const l=await i({chainId:c,grantee:r});await o({messages:l,chainId:c,internal:e?.internal})},onSuccess:async()=>{const c=[Yt.expirations._def,Yt.grants._def];for(const l of c)await a.invalidateQueries({queryKey:l})}})}function ui(){const{defaultChainId:e}=X(),{openDrawer:s}=Ve(),n=H.useSetAtom(ts),r=No(),{data:o={expiredAtByChain:{},isEnabledByChain:{}},isLoading:a}=On();return{...o,isLoading:a,enable:async(l=e)=>new Promise((d,u)=>{n({chainId:l,resolve:d,reject:u}),s("/autosign/enable")}),disable:async(l=e)=>{await r.mutateAsync(l)}}}const hi="INIT",mi="Initia";function Ln(e){return e.assets.reduce((s,{value:n})=>s+(n??0),0)}function fi(e){return e.assets.reduce((s,{quantity:n})=>s.plus(n),F(0)).toString()}function _i(e,s){return{symbol:s?.symbol??e,logoUrl:s?.logoUrl??Rn}}function dr(e){return w.pick(["chainId","name","logoUrl"],e)}function gi(e){return w.sortWith([w.descend(({symbol:s})=>s===hi),w.descend(Ln),w.descend(({assets:s})=>s.length),w.ascend(({symbol:s})=>s)])(e)}function pi(e){return w.sortWith([w.descend(({value:s})=>s??0),w.descend(({quantity:s})=>Number(s)),w.ascend(({chain:s})=>s.name)])(e)}function xi(e){return w.sortWith([w.descend(({chain:s})=>s.name===mi),w.ascend(({chain:s})=>s.name),w.ascend(({denom:s})=>s)])(e)}function yi(e,s){return w.sortWith([w.descend(({chainId:n})=>n===s),w.descend(w.prop("value"))])(e)}function ji(e,s,n,r,o){const a={};for(const u of e){const h=u.chainId,m=s[h]??[],f=n[h],g=r[h],p=[];for(const{amount:x,denom:S}of m){if(!F(x).gt(0))continue;const I=f?.find(R=>R.denom===S),N=g?.find(R=>R.id===S)?.price,C=I?.decimals??0,T=v.fromBaseUnit(x,{decimals:C}),P=N?F(T).times(N).toNumber():void 0;p.push({..._i(S,I),amount:x,denom:S,decimals:C,quantity:T,price:N,value:P,address:I?.address,unlisted:!I,chain:dr(u)})}a[h]=p}const i=new Map;for(const[u,h]of Object.entries(a)){if(h.length===0)continue;const m=e.find(g=>g.chainId===u);if(!m)continue;const f=h.reduce((g,{value:p})=>g+(p??0),0);i.set(u,{...dr(m),value:f})}const c=new Map;for(const u of Object.values(a))for(const h of u)if(!h.unlisted){const{symbol:m}=h,f=c.get(m)??[];c.set(m,[...f,h])}const l=[];for(const[u,h]of c){const m=w.head(h);if(!m)continue;const f=pi(h);l.push({symbol:u,logoUrl:m.logoUrl,assets:f})}const d=[];for(const u of Object.values(a))for(const h of u)h.unlisted&&d.push(h);return{chainsByValue:yi(Array.from(i.values()),o),assetGroups:gi(l),unlistedAssets:xi(d),totalValue:l.reduce((u,h)=>u+Ln(h),0)}}function zn(){const{defaultChainId:e}=X(),s=ae(),n=Ka(),r=Ua(),o=Ba(),a=s.map(m=>m.chainId),i=w.zipObj(a,n.map(w.prop("data"))),c=w.zipObj(a,r.map(w.prop("data"))),l=w.zipObj(a,o.map(w.prop("data"))),d=ji(s,i,c,l,e),u=[n,r,o].flat().some(({isLoading:m})=>m);return{...d,isLoading:u,refetch:()=>{n.forEach(({refetch:m})=>m()),r.forEach(({refetch:m})=>m()),o.forEach(({refetch:m})=>m())}}}function ee(){const e=Us();return e?v.InitiaAddress(e).bech32:""}function Us(){const{address:e}=de.useAccount(),s=Fn();return!e||!s?"":v.InitiaAddress(e).hex}function Pt(){const e=Zt(),s=ee(),n=Us();return e.metadata?.minitia?.type==="minievm"?n:s}function So(){const e=Pt(),s=to();return $.useQuery({queryKey:$s.username(s.restUrl,e).queryKey,queryFn:()=>s.getUsername(e),enabled:!!e,staleTime:Q.MINUTE})}function xe(){const e=Pt(),s=ee(),n=Us(),{data:r}=So(),o=es(),a=Mn(),i=ui(),{isDrawerOpen:c,openDrawer:l}=Ve(),d=()=>{l("/")},u=()=>{l("/connect")},h=g=>{l("/bridge",g)},m=Os();return{address:e,initiaAddress:s,hexAddress:n,username:r,offlineSigner:o,isConnected:!!e,isOpen:c,openConnect:u,openWallet:d,openBridge:h,disconnect:a,autoSign:i,...m}}const vi="_status_tn9m1_1",wi="_error_tn9m1_9",ur={status:vi,error:wi},ne=({error:e,children:s})=>t.jsx("p",{className:D(ur.status,{[ur.error]:e}),children:s}),ye=({errorBoundaryProps:e={fallbackRender:({error:r})=>t.jsx(ne,{error:!0,children:r.message})},suspenseFallback:s=t.jsx(ne,{children:"Loading..."}),children:n})=>t.jsx(Kr.ErrorBoundary,{...e,children:t.jsx(_.Suspense,{fallback:s,children:n})});function bi(){const e=["initia-wallet-widget:last-connected-wallet","initia-wallet-widget:fee-denoms","initia-wallet-widget:chain-ids","initia-wallet-widget:opened-layers-assets","initia-wallet-widget:opened-layers-nft"],s={"initia-wallet-widget:ethereum-public-keys":{prefix:U.PUBLIC_KEY,getSuffix:n=>v.InitiaAddress(n).bech32}};for(const n of e)localStorage.removeItem(n);for(const[n,{prefix:r,getSuffix:o}]of Object.entries(s)){const a=localStorage.getItem(n);if(a)try{const i=JSON.parse(a);for(const[c,l]of Object.entries(i)){const d=`${r}:${o(c)}`;localStorage.setItem(d,l)}localStorage.removeItem(n)}catch{}}}const Re=Ne.createQueryKeys("interwovenkit:skip",{chains:null,assets:e=>[e],asset:(e,s)=>[e,s],balances:(e,s)=>[e,s],route:(e,s)=>[e,s],routeErrorInfo:e=>[e],txTrack:(e,s)=>[e,s],txStatus:(e,s)=>[e,s]});function Ye(){const{routerApiUrl:e}=X();return _.useMemo(()=>L.create({prefixUrl:e}),[e])}function qt(e){const s=Ye(),n=$.useQueryClient(),{data:r}=$.useSuspenseQuery({queryKey:Re.assets(e).queryKey,queryFn:()=>s.get("v2/fungible/assets",{searchParams:{chain_ids:e}}).json(),select:({chain_to_assets_map:o})=>{const{assets:a}=o[e]??{assets:[]};for(const i of a)n.setQueryData(Re.asset(e,i.denom).queryKey,i);return a.toSorted(w.descend(i=>i.symbol==="INIT"))},staleTime:Q.MINUTE});return r}function Ao(e){const s=qt(e);return n=>{const r=s.find(o=>o.denom===n);if(!r)throw new Error(`Asset not found: ${n}`);return r}}function Qe(e,s){return Ao(s)(e)}function ko(){const e=ae();return s=>e.some(n=>n.chain_id===s)}function ss(){const e=ko();return s=>e(s.chain_id)?"initia":s.chain_type}function Jt(e){return ss()(e)}function Kn(){const e=Ye(),{data:s}=$.useSuspenseQuery({queryKey:Re.chains.queryKey,queryFn:()=>e.get("v2/info/chains").json(),select:({chains:n})=>w.sortWith([w.descend(({chain_name:r})=>r==="initia"),w.ascend(({pretty_name:r})=>r)],n),staleTime:Q.MINUTE});return s}function vt(){const e=Kn(),s=Vr();return n=>{const r=e.find(a=>a.chain_id===n);if(r)return r;const o=s.find(a=>a.chain_id===n);if(!o)throw new Error(`Chain not found: ${n}`);return{chain_id:o.chain_id,chain_name:o.name,pretty_name:o.pretty_name,logo_uri:o.logo,chain_type:"cosmos",rpc:"",rest:""}}}function Be(e){return vt()(e)}const Ci=()=>(Ga(),Va(),null),Ii="_loader_1vxch_1",Ni={loader:Ii},wt=({size:e=24,color:s="currentColor",border:n=2})=>{const r={width:`${e}px`,height:`${e}px`,borderColor:`${s} ${s} transparent ${s}`,borderWidth:`${n}px`};return t.jsx("div",{className:Ni.loader,style:r})},Si="_button_1q027_1",Ai="_outline_1q027_28",ki="_sm_1q027_46",$i="_full_1q027_53",Ti="_small_1q027_57",Ei="_unpadded_1q027_88",gt={button:Si,outline:Ai,sm:ki,full:$i,small:Ti,unpadded:Ei},$o=e=>{const{sm:s,fullWidth:n,loading:r,className:o,children:a,disabled:i,...c}=e;return t.jsx("button",{...c,className:D(gt.button,{[gt.sm]:s,[gt.full]:n},o),disabled:!!r||i,children:r?t.jsxs(t.Fragment,{children:[t.jsx(wt,{color:"currentColor",size:16}),typeof r=="string"&&t.jsx("span",{className:gt.loading,children:r})]}):a})},qi=({className:e,...s})=>t.jsx($o,{...s,className:D(gt.outline,e)}),Di=({className:e,unpadded:s,...n})=>t.jsx("button",{...n,className:D(gt.small,{[gt.unpadded]:s},e)}),J={White:$o,Outline:qi,Small:Di},Pi="_footer_1vp4h_1",Ri="_actions_1vp4h_10",hr={footer:Pi,actions:Ri},ie=({extra:e,className:s,children:n})=>t.jsxs("footer",{className:D(hr.footer,s),children:[e,t.jsx("div",{className:hr.actions,children:n})]}),Bi="_scrollable_13su7_1",Mi={scrollable:Bi},Fe=({className:e,children:s,ref:n})=>t.jsx("div",{ref:n,className:D(Mi.scrollable,e),children:s});function Ls(){return Ie.useMediaQuery("(max-width: 576px)")}const wn="interwoven-kit";function To(){const e=document.querySelector(wn)||document.body.appendChild(document.createElement(wn));return e.shadowRoot||e.attachShadow({mode:"open"})}function Fi(){const{theme:e,container:s}=X();return _.useEffect(()=>{document.querySelector(wn)?.setAttribute("data-theme",e)},[e]),s??To()}function Oi(e){const s=To(),n=document.createElement("style");n.textContent=e,s.appendChild(n)}const Wn=_.createContext(null);function yt(){const{container:e}=_.useContext(Wn);return e}function Eo(e){const s=yt();return s?getComputedStyle(s).getPropertyValue(e):""}function Ui(){return Ie.useScrollLock(),null}function Li(e){return/^[A-F0-9]{64}$/i.test(e)}function zi(e,s){const{txHash:n,accountAddress:r,pathSuffix:o}=s;if(n)return Li(n)?w.path(["explorers",0,"tx_page"],e)?.replace(/\$\{txHash\}/g,n):void 0;if(r){if(!v.InitiaAddress.validate(r))return;const i=w.path(["explorers",0,"account_page"],e)?.replace(/\$\{accountAddress\}/g,r);return i&&o?i+o:i}}function Ki(e){try{const s=new URL(e,window.location.href);if(!["http:","https:"].includes(s.protocol))throw new Error("Invalid protocol");return s.toString()}catch{return"#"}}const Wi="_link_j1lkz_1",mr={link:Wi},zs=({chainId:e,txHash:s,accountAddress:n,pathSuffix:r,...o})=>{const{showIcon:a,className:i,children:c,onClick:l,...d}=o,u=Me(e),h=zi(u,{txHash:s,accountAddress:n,pathSuffix:r}),m=s?v.truncate(s):n?v.truncate(n):"",f=c??m;return h?t.jsxs("a",{...d,href:Ia(Ki(h)),className:D(mr.link,i),onClick:l,target:"_blank",children:[f,a&&t.jsx(A.IconExternalLink,{size:12})]}):t.jsx("span",{...d,className:D(mr.link,i),children:f})},qo=_.createContext(null),Hn=()=>_.useContext(qo),Hi=()=>{const[e,s]=H.useAtom(wo),{showNotification:n,updateNotification:r,hideNotification:o}=Hn();return _.useEffect(()=>{if(!e)return;const{status:a,chainId:i,txHash:c,error:l}=e,d=l?l.message:c?t.jsx(zs,{txHash:c,chainId:i,onClick:o,showIcon:!0,children:"View on Initia Scan"}):null;switch(a){case"loading":n({type:"loading",title:"Transaction is pending..."});break;case"error":r({type:"error",title:"Transaction failed",description:d}),s(null);break;case"success":r({type:"success",title:"Transaction is successful!",description:d,autoHide:!0}),s(null);break}},[e,s,n,r,o]),null},vs=({value:e,children:s})=>{const[n,r]=_.useState(!1);return s({copy:async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1e3)}catch{}},copied:n})},Qi="_placeholder_10r3x_1",Gi="_logo_10r3x_5",fr={placeholder:Qi,logo:Gi},Y=({src:e,alt:s,placeholder:n,classNames:r,style:o,logo:a,...i})=>{const[c,l]=_.useState(void 0),{width:d,height:u}=i,h=n??t.jsx("div",{className:D(fr.placeholder,r?.placeholder),style:{width:d,height:u,...o}});return!e||c===e?h:t.jsx("img",{...i,className:D(i.className,{[fr.logo]:a}),style:{width:d,height:u,...o},src:e,alt:s,loading:"lazy",onError:()=>l(e)})},Vi="_header_1q8ju_1",Yi="_account_1q8ju_17",Ji="_name_1q8ju_28",Zi="_address_1q8ju_32",Xi="_icon_1q8ju_36",ec="_copied_1q8ju_43",tc="_button_1q8ju_58",sc="_settings_1q8ju_69",nc="_disconnect_1q8ju_73",rc="_label_1q8ju_83",oc="_expanded_1q8ju_91",je={header:Vi,account:Yi,name:Ji,address:Zi,icon:Xi,copied:ec,button:tc,settings:sc,disconnect:nc,label:rc,expanded:oc},ac=()=>{const{connector:e}=de.useAccount(),s=Mn(),{address:n,username:r}=xe(),o=r??n,[a,i]=_.useState(!1),c=_.useRef(null),l=rt.useSpring({width:a?140:52,config:{tension:500,friction:30,clamp:!0}}),d=()=>{a?s():i(!0)},u=()=>{a&&(c.current=setTimeout(()=>{i(!1)},500))},h=()=>{c.current&&(clearTimeout(c.current),c.current=null)};if(_.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),!e||!n)return null;const m=e.id==="io.privy.wallet"?"https://assets.initia.xyz/images/wallets/Privy.webp":e.icon;return t.jsxs("header",{className:je.header,children:[t.jsx(vs,{value:n,children:({copy:f,copied:g})=>t.jsxs("button",{className:D(je.account,{[je.copied]:g}),onClick:f,children:[t.jsx(Y,{src:m,width:18,height:18}),t.jsx("div",{className:je.address,children:v.truncate(n)}),t.jsx("div",{className:je.name,children:v.truncate(o)}),t.jsx(A.IconCopy,{className:je.icon,size:12}),g?"Copied!":""]})}),t.jsx(Et,{to:"/settings",className:D(je.button,je.settings),"aria-label":"Open settings",children:t.jsx(A.IconSettingFilled,{size:16})}),t.jsxs(rt.animated.button,{className:D(je.button,je.disconnect,{[je.expanded]:a}),style:l,onClick:d,onMouseLeave:u,onMouseEnter:h,children:[t.jsx(A.IconSignOut,{size:16}),t.jsx("span",{className:je.label,children:"Disconnect"})]})]})},ic="_overlay_jij9g_1",cc="_content_jij9g_28",lc="_inner_jij9g_60",tn={overlay:ic,content:cc,inner:lc},dc=({children:e})=>{const{isDrawerOpen:s,closeDrawer:n}=Ve(),{setContainer:r}=_.useContext(Wn),o=Ls(),a=Fi(),i=H.useAtomValue(Fs),c=H.useAtomValue(ts),l=$.useIsMutating({mutationKey:[vo]}),d=()=>{const g=l?"User exited before response arrived. Transaction may succeed or fail.":"User rejected";n(),i?.reject(new Error(g)),c?.reject(new Error("User rejected"))},u=Es(),h=he(),m=$.useQueryClient(),f={fallbackRender:({error:g,resetErrorBoundary:p})=>{const x=()=>{u==="/bridge"&&(localStorage.removeItem(U.BRIDGE_SRC_CHAIN_ID),localStorage.removeItem(U.BRIDGE_SRC_DENOM),localStorage.removeItem(U.BRIDGE_DST_CHAIN_ID),localStorage.removeItem(U.BRIDGE_DST_DENOM)),h("/"),m.clear(),p()};return t.jsxs(Fe,{children:[t.jsx(ne,{error:!0,children:g.message}),t.jsx(ie,{children:t.jsx(J.White,{onClick:x,children:"Retry"})})]})}};return t.jsx(Ae.Dialog.Root,{open:s,onOpenChange:g=>!g&&d(),modal:!1,children:t.jsxs(Ae.Dialog.Portal,{container:a,children:[o&&t.jsx(Ae.Dialog.Backdrop,{className:tn.overlay,onClick:d,children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",width:"14",height:"14",children:[t.jsx("path",{d:"M7.168 14.04 l 6.028 -6.028 l -6.028 -6.028 L8.57 .582 L16 8.012 l -7.43 7.43 l -1.402 -1.402 Z"}),t.jsx("path",{d:"M0.028 14.04 l 6.028 -6.028 L0.028 1.984 L1.43 .582 l 7.43 7.43 l -7.43 7.43 L0.028 14.04 Z"})]})}),t.jsx(Ae.Dialog.Popup,{className:tn.content,children:t.jsxs("div",{className:D(tn.inner,"body"),ref:r,children:[o&&t.jsx(Ui,{}),t.jsx(Hi,{}),t.jsx(ac,{}),t.jsx(ye,{errorBoundaryProps:f,children:e})]})})]})})},Do=_.createContext(!1),uc="_overlay_1iyfl_1",hc="_fullscreen_1iyfl_15",mc="_content_1iyfl_19",fc="_header_1iyfl_56",_c="_title_1iyfl_65",gc="_close_1iyfl_70",lt={overlay:uc,fullscreen:hc,content:mc,header:fc,title:_c,close:gc},Po=({title:e,children:s,trigger:n,className:r,open:o,onOpenChange:a})=>{const i=yt(),c=_.useContext(Do);return i?t.jsxs(Ae.Dialog.Root,{open:o,onOpenChange:a,modal:!1,children:[n&&t.jsx(Ae.Dialog.Trigger,{className:r,children:n}),t.jsxs(Ae.Dialog.Portal,{container:i,children:[t.jsx(Ae.Dialog.Backdrop,{className:D(lt.overlay,{[lt.fullscreen]:c}),onClick:()=>a(!1),forceRender:!0}),t.jsxs(Ae.Dialog.Popup,{className:D(lt.content,{[lt.fullscreen]:c}),children:[e&&t.jsxs("header",{className:lt.header,children:[t.jsx(Ae.Dialog.Title,{className:lt.title,children:e}),t.jsx(Ae.Dialog.Close,{className:lt.close,children:t.jsx(A.IconClose,{size:20})})]}),s]})]})]}):null},bn=({children:e})=>{const s=_.useRef(null),[n,r]=_.useState(0),o=rt.useSpring({height:n,config:{tension:500,friction:30,clamp:!0}});return _.useEffect(()=>{if(s.current){const{height:a}=s.current.getBoundingClientRect();r(a)}},[e]),e?t.jsx(rt.animated.div,{style:{overflow:"hidden",...o},children:t.jsx("div",{ref:s,children:e})}):null},pc="_help_qcmtq_1",xc="_icon_qcmtq_10",yc="_info_qcmtq_19",jc="_warning_qcmtq_23",vc="_error_qcmtq_27",wc="_success_qcmtq_33",sn={help:pc,icon:xc,info:yc,warning:jc,error:vc,success:wc},kt=({level:e,className:s,mt:n=8,children:r})=>{if(!r)return null;const o=()=>{switch(e){case"loading":return t.jsx(wt,{size:12});case"info":return t.jsx(A.IconInfoFilled,{size:12});case"warning":case"error":return t.jsx(A.IconWarningFilled,{size:12});default:return t.jsx(A.IconCheckCircleFilled,{size:12})}};return t.jsxs("div",{className:D(sn.help,e&&sn[e],s),style:{marginTop:n},children:[t.jsx("div",{className:sn.icon,children:o()}),r]})},bc="_stack_a6m7u_1",Cc="_help_a6m7u_6",Ic="_info_a6m7u_14",Nc="_warning_a6m7u_19",Sc="_error_a6m7u_24",Ac="_success_a6m7u_29",Cn={stack:bc,help:Cc,info:Ic,warning:Nc,error:Sc,success:Ac},kc=({children:e})=>!e||Array.isArray(e)&&e.filter(Boolean).length===0?null:t.jsx(bn,{children:t.jsx("div",{className:Cn.stack,children:e})}),oe=({mt:e=0,...s})=>t.jsx(kt,{...s,className:D(Cn.help,Cn[s.level]),mt:e});oe.Stack=kc;const $c="_root_16p5j_1",Tc="_item_16p5j_10",Ec="_chevron_16p5j_14",qc="_trigger_16p5j_19",Dc="_content_16p5j_39",Ft={root:$c,item:Tc,chevron:Ec,trigger:qc,content:Dc};function Pc(e){const{list:s,getKey:n,renderHeader:r,renderContent:o,footer:a,...i}=e;return t.jsxs(se.Accordion.Root,{className:Ft.root,type:"multiple",...i,children:[s.map((c,l)=>t.jsxs(se.Accordion.Item,{className:Ft.item,value:n?.(c)??String(l),children:[t.jsx(se.Accordion.Header,{children:t.jsxs(se.Accordion.Trigger,{className:Ft.trigger,children:[r(c),t.jsx(A.IconChevronDown,{className:Ft.chevron,size:16})]})}),t.jsx(se.Accordion.Content,{className:Ft.content,children:o(c)})]},n?.(c)??l)),a]})}const Rc=10;function Ro(){const e=ee();return(s,n)=>$.queryOptions({queryKey:$s.txs(s.indexerUrl,e).queryKey,queryFn:async()=>{if(!n.enabled)return[];const r={"pagination.reverse":!0,"pagination.limit":Rc},{txs:o}=await L.create({prefixUrl:s.indexerUrl}).get(`indexer/tx/v1/txs/by_account/${e}`,{searchParams:r}).json();return o},staleTime:Q.SECOND})}function Bc(e,s){const n=Ro();return $.useSuspenseQuery(n(e,s))}function Mc(e,s){const n=e.flatMap((r,o)=>(s[o]??[]).map(i=>({...i,chain:r})));return w.sortWith([w.descend(r=>new Date(r.timestamp).getTime())])(n)}const Fc=()=>{const e=ae(),s=Ro(),n=$.useQueries({queries:e.map(i=>s(i,{enabled:!0}))}),r=n.map(w.prop("data")),o=Mc(e,r),a=n.some(i=>i.isLoading);return{activities:o,isLoading:a}};function Bo(e){const{data:s}=$.useSuspenseQuery({queryKey:As.gasPrices(e).queryKey,queryFn:async()=>{if(e.metadata?.is_l1){const{restUrl:n}=e,{gas_prices:r}=await L.create({prefixUrl:n}).get("initia/tx/v1/gas_prices").json();return r.toSorted(w.descend(({denom:o})=>o==="uinit")).map(({denom:o,amount:a})=>{const i=o==="uinit"?1:Hr;return{amount:F(a).times(i).toFixed(18),denom:o}})}return e.fees.fee_tokens.map(({denom:n,fixed_min_gas_price:r})=>{if(w.isNil(r))throw new Error(`${n} has no price`);return{amount:String(r),denom:n}})},staleTime:Q.SECOND});return s}function Mo(e){const s=ee(),{data:n}=Bc(e,{enabled:e.fees.fee_tokens.length>=2});if(e.fees.fee_tokens.length===0)return null;const r=e.fees.fee_tokens[0].denom;if(e.fees.fee_tokens.length===1)return r;try{return n.find(({tx:a})=>a.auth_info.signer_infos.some(i=>v.InitiaAddress.equals(s,We.computeAddress(`0x${V.toHex(jn.Secp256k1.uncompressPubkey(V.fromBase64(i.public_key.key)))}`))))?.tx.auth_info.fee.amount[0]?.denom??r}catch{return r}}const Oc="_trigger_u613p_1",Uc="_icon_u613p_18",Lc="_content_u613p_27",zc="_item_u613p_36",Kc="_itemText_u613p_52",Wc="_itemIndicator_u613p_57",Hc="_active_u613p_60",Xe={trigger:Oc,icon:Uc,content:Lc,item:zc,itemText:Kc,itemIndicator:Wc,active:Hc};function Fo({options:e,value:s,onChange:n,classNames:r}){const o=yt(),a=e.find(c=>c.value===s);if(!a)throw new Error("Selected option not found");const i=c=>{const l=e.find(d=>String(d.value)===c);if(!l)throw new Error(`Option not found: ${c}`);n(l.value)};return t.jsxs(Le.Select.Root,{value:String(s),onValueChange:i,modal:!1,children:[t.jsxs(Le.Select.Trigger,{className:D(Xe.trigger,r?.trigger),children:[t.jsx(Le.Select.Value,{children:a.triggerLabel||a.label}),t.jsx(Le.Select.Icon,{className:Xe.icon,children:t.jsx(A.IconChevronDown,{size:12})})]}),t.jsx(Le.Select.Portal,{container:o,children:t.jsx(Le.Select.Positioner,{className:Xe.content,alignItemWithTrigger:!1,sideOffset:6,align:"end",children:t.jsx(Le.Select.Popup,{className:Xe.popup,children:e.map(c=>t.jsxs(Le.Select.Item,{className:D(Xe.item,r?.item),value:String(c.value),children:[t.jsx(Le.Select.ItemText,{className:D(Xe.itemText,r?.itemText),children:c.label}),t.jsx(A.IconCheck,{size:12,className:D(Xe.itemIndicator,{[Xe.active]:c.value===s})})]},String(c.value)))})})})]})}const Qc="_root_1t37n_1",Gc="_trigger_1t37n_7",Vc="_item_1t37n_11",Yc="_itemText_1t37n_17",_r={root:Qc,trigger:Gc,item:Vc,itemText:Yc},Jc=({options:e,value:s,onChange:n})=>{const{txRequest:r}=bo(),o=Me(r.chainId),a=Ge(o),i=(g,p)=>{if(v.formatAmount(g,{decimals:p})==="0.000000")return 8},c=({amount:[{amount:g,denom:p}]})=>{if(F(g).isZero())return"0";const{symbol:x,decimals:S}=a(p),I=i(g,S);return`${v.formatAmount(g,{decimals:S,dp:I})} ${x}`},l=e.map(g=>{const[{denom:p}]=g.amount,{symbol:x}=a(p);return{value:p,label:c(g),triggerLabel:x}});if(e.length===1)return t.jsx("span",{className:"monospace",children:c(e[0])});const d=e.find(g=>g.amount[0].denom===s);if(!d)throw new Error("Fee option not found");const[{amount:u,denom:h}]=d.amount,{decimals:m}=a(h),f=i(u,m);return t.jsxs("div",{className:_r.root,children:[t.jsx("span",{className:"monospace",children:v.formatAmount(u,{decimals:m,dp:f})}),t.jsx(Fo,{options:l,value:s,onChange:n,classNames:_r})]})},Zc="_root_16nr2_1",Xc="_trigger_16nr2_5",el="_chevron_16nr2_13",tl="_panel_16nr2_27",sl="_details_16nr2_39",nl="_row_16nr2_48",Nt={root:Zc,trigger:Xc,chevron:el,panel:tl,details:sl,row:nl},rl=({spend:e,fee:s,total:n,balance:r,symbol:o,decimals:a})=>{const i=[e&&{label:"Spend",value:e},{label:"Fee",value:s},e&&{label:"Required (spend + fee)",value:n},{label:"Balance",value:r}].filter(Boolean),c=a===6?void 0:8;return t.jsxs(Js.Collapsible.Root,{className:Nt.root,children:[t.jsxs(Js.Collapsible.Trigger,{className:Nt.trigger,children:[t.jsx("span",{children:"Insufficient balance for fee"}),t.jsx(A.IconChevronDown,{className:Nt.chevron,size:16})]}),t.jsx(Js.Collapsible.Panel,{className:Nt.panel,children:t.jsx("div",{className:Nt.details,children:i.map(({label:l,value:d})=>t.jsxs("div",{className:Nt.row,children:[t.jsx("span",{children:l}),t.jsxs("span",{children:[v.formatAmount(d,{decimals:a,dp:c})," ",o]})]},l))})})]})};function ws(e){switch(typeof e){case"string":return e;case"number":case"bigint":return e.toString();case"boolean":return e?"true":"false";case"object":return e===null?"null":e instanceof Uint8Array?V.toBase64(e):Array.isArray(e)?`[${e.map(ws).join(",")}]`:JSON.stringify(e,(s,n)=>typeof n=="bigint"?n.toString():n);default:return"unknown"}}const ol="_container_1xzyq_1",al="_toggle_1xzyq_5",il="_list_1xzyq_11",cl="_arg_1xzyq_16",ll="_type_1xzyq_21",Ot={container:ol,toggle:al,list:il,arg:cl,type:ll},dl=Ne.createQueryKeys("interwovenkit:move",{abi:(e,s,n,r)=>[e,s,n,r]}),ul=({type:e,arg:s})=>ws(v.resolveBcsType(e).parse(s)),hl=({msg:e,chainId:s,fallback:n})=>{const[r,o]=Ie.useToggle(!1),{restUrl:a}=Me(s),{moduleAddress:i,moduleName:c,functionName:l,args:d}=e,{data:u}=$.useQuery({queryKey:dl.abi(a,i,c,l).queryKey,queryFn:async()=>{const m=await L.create({prefixUrl:a}).get(`initia/move/v1/accounts/${i}/modules/${c}`).json(),g=JSON.parse(m.module.abi).exposed_functions.find(({name:p})=>p===l);if(!g)throw new Error(`Function ${l} not found in module ${c}`);return g.params.filter(p=>!p.startsWith("&"))},staleTime:Q.INFINITY});if(!u)return n;const h=(m,f)=>{const g=u[f];return t.jsxs("div",{className:Ot.arg,children:[t.jsx("div",{className:Ot.type,children:g}),t.jsx(Kr.ErrorBoundary,{fallback:t.jsx("div",{className:"error",children:"Error decoding argument"}),children:t.jsx(ul,{type:g,arg:m})})]},f)};return t.jsxs("div",{className:Ot.container,children:[t.jsx(J.Small,{className:Ot.toggle,onClick:o,disabled:!u,children:r?"Encode":"Decode"}),r?t.jsx("div",{className:Ot.list,children:d.map(h)}):n]})},ml="_list_oip9m_1",fl="_key_oip9m_9",_l="_value_oip9m_14",nn={list:ml,key:fl,value:_l},gl=({message:e,chainId:s})=>{const{typeUrl:n,value:r}=e;return t.jsx("div",{className:nn.list,children:Object.entries(r).map(([o,a])=>t.jsxs("div",{children:[t.jsx("div",{className:nn.key,children:o}),t.jsx("div",{className:nn.value,children:n==="/initia.move.v1.MsgExecute"&&o==="args"?t.jsx(hl,{msg:r,chainId:s,fallback:ws(a)}):ws(a)})]},o))})},pl="_item_1n572_1",xl="_title_1n572_10",yl="_content_1n572_14",rn={item:pl,title:xl,content:yl},on=({title:e,content:s})=>t.jsxs("div",{className:rn.item,children:[t.jsx("div",{className:rn.title,children:e}),t.jsx("div",{className:rn.content,children:s})]});function $e(e){if(e&&F(e).gt(0)&&F(e).lt(.01))return"<$0.01";const s=v.formatNumber(e,{dp:2});return s?`$${s}`:""}function Oo(e,s){const n={};for(const r of e)if(r.attributes.some(a=>a.key==="msg_index")){if(r.type==="coin_spent"){const a=r.attributes.find(c=>c.key==="spender")?.value,i=r.attributes.find(c=>c.key==="amount")?.value;if(a===s&&i){const[c,l]=i.match(/^(\d+)(.+)$/)?.slice(1)||[];if(c&&l){const d=n[l]||BigInt(0);n[l]=d-BigInt(c)}}}if(r.type==="coin_received"){const a=r.attributes.find(c=>c.key==="receiver")?.value,i=r.attributes.find(c=>c.key==="amount")?.value;if(a===s&&i){const[c,l]=i.match(/^(\d+)(.+)$/)?.slice(1)||[];if(c&&l){const d=n[l]||BigInt(0);n[l]=d+BigInt(c)}}}}return Object.entries(n).filter(([,r])=>r!==BigInt(0)).map(([r,o])=>({amount:o.toString(),denom:r}))}function Uo(e,s){const n={};for(const r of e)if(r.attributes.some(a=>a.key==="msg_index")&&r.type==="move"){const a=r.attributes.find(l=>l.key==="type_tag")?.value,i=r.attributes.find(l=>l.key==="data")?.value;if(!a||!i)continue;let c;try{c=JSON.parse(i)}catch{continue}if(a==="0x1::fungible_asset::WithdrawEvent"){const l=c.store_addr,d=c.amount,u=c.metadata_addr;if(l&&d&&u&&v.createUserDerivedObjectAddress(s,u)===l){const m=n[u]||BigInt(0);n[u]=m-BigInt(d)}}if(a==="0x1::fungible_asset::DepositEvent"){const l=c.store_addr,d=c.amount,u=c.metadata_addr;if(l&&d&&u&&v.createUserDerivedObjectAddress(s,u)===l){const m=n[u]||BigInt(0);n[u]=m+BigInt(d)}}}return Object.entries(n).filter(([,r])=>r!==BigInt(0)).map(([r,o])=>({amount:o.toString(),metadata:r}))}const Lo=({metadata:e,chain:s,children:n})=>{const{restUrl:r}=s,{data:o}=$.useSuspenseQuery({queryKey:js.denom(r,e).queryKey,queryFn:()=>L.create({prefixUrl:r}).get("initia/move/v1/denom",{searchParams:{metadata:e}}).json(),select:({denom:a})=>a,staleTime:Q.INFINITY});return n(o)},jl="_root_1p8a4_1",vl="_title_1p8a4_8",wl="_changes_1p8a4_14",bl="_change_1p8a4_14",Cl="_amount_1p8a4_35",Il="_text_1p8a4_42",Nl="_value_1p8a4_49",pt={root:jl,title:vl,changes:wl,change:bl,amount:Cl,text:Il,value:Nl},zo=({amount:e,asset:s,price:n})=>{const{denom:r,symbol:o,decimals:a,logoUrl:i}=s,c=v.formatAmount(e,{decimals:a}),l=n&&F(v.fromBaseUnit(e,{decimals:a})).times(n).abs();return t.jsxs("div",{className:pt.change,children:[t.jsxs("div",{className:pt.amount,children:[t.jsx(Y,{src:i,width:14,height:14,logo:!0}),t.jsxs("span",{className:pt.text,children:[c," ",o||r]})]}),l&&t.jsx("div",{className:pt.value,children:$e(l)})]})},Sl=({changes:e,chain:s})=>{const n=Ge(s),{data:r}=ks(s);return e.map(({amount:o,denom:a},i)=>{const c=n(a),l=r?.find(({id:d})=>d===a)?.price;return t.jsx(zo,{amount:o,asset:c,price:l},i)})},Al=({changes:e,chain:s})=>{const n=Ge(s),{data:r}=ks(s);return e.map(({amount:o,metadata:a},i)=>t.jsx(Lo,{metadata:a,chain:s,children:c=>{const l=r?.find(({id:d})=>d===c)?.price;return t.jsx(zo,{amount:o,asset:n(c),price:l})}},i))};function kl(e,s){return typeof s=="bigint"?s.toString():s}const $l=Ne.createQueryKeys("interwovenkit:tx",{simulate:e=>[JSON.stringify(e,kl)]}),Tl=({messages:e,memo:s,chainId:n})=>{const{initiaAddress:r,hexAddress:o}=xe(),a=Me(n),{simulateTx:i}=Os(),{data:c}=$.useSuspenseQuery({queryKey:$l.simulate({messages:e,memo:s,chainId:n}).queryKey,queryFn:()=>i({messages:e,memo:s,chainId:n}),staleTime:Q.SECOND}),l=m=>t.jsxs("div",{className:pt.root,children:[t.jsx("h2",{className:pt.title,children:"Estimated changes"}),t.jsx("div",{className:pt.changes,children:m})]});if(!c)return null;const d=c.result?.events??[];if(d.length===0)return null;if(a.metadata?.is_l1||a.metadata?.minitia?.type==="minimove"){const m=Uo(d,o),[f]=gr(m);return f.length===0?null:l(t.jsx(Al,{changes:f,chain:a}))}const u=Oo(d,r),[h]=gr(u);return h.length===0?null:l(t.jsx(Sl,{changes:h,chain:a}))};function gr(e){return w.partition(s=>new F(s.amount).isNegative(),e)}const El="_title_1d032_1",ql="_meta_1d032_7",Dl="_footer_1d032_14",Pl="_rejectButton_1d032_19",cs={title:El,meta:ql,footer:Dl,rejectButton:Pl},Ko=()=>{const{txRequest:e,resolve:s,reject:n}=bo(),{messages:r,memo:o,chainId:a,gas:i,gasAdjustment:c,spendCoins:l}=e,d=ee(),u=Ps(),h=Me(a),m=Bn(h),f=Bo(h),g=Mo(h),p=Ge(h),x=xo(),S=po(),I=(e.gasPrices??f).map(({amount:y,denom:k})=>Pe.calculateFee(Math.ceil(i*c),Pe.GasPrice.fromString(y+k))),N=I.map(y=>y.amount[0]),C=y=>{const k=m.find(Z=>Z.denom===y)?.amount??"0",q=N.find(Z=>Z.denom===y)?.amount??"0",M=l.filter(Z=>Z.denom===y).reduce((Z,Ue)=>F(Z).plus(Ue.amount),F("0")),E=F(q).plus(M),G=F(k).gte(E),{symbol:te,decimals:O}=p(y);return{symbol:te,decimals:O,spend:M.gt(0)?M.toFixed():null,fee:q,total:E.toFixed(),balance:k,isSufficient:G}},T=()=>{if(g&&C(g).isSufficient)return g;for(const{denom:y}of N)if(C(y).isSufficient)return y;return N[0]?.denom},[P,R]=_.useState(T),{mutate:B,isPending:z}=$.useMutation({mutationKey:[vo],mutationFn:async()=>{const y=I.find(M=>M.amount[0].denom===P);if(!y)throw new Error("Fee not found");const q=!e.internal&&await x(a,r)?await S(a,d,r,y,o||""):await u(a,d,r,y,o);await s(q)},onError:async y=>{n(y)}}),j=C(P),b=!j.isSufficient;return t.jsxs(t.Fragment,{children:[t.jsxs(Fe,{children:[t.jsx("h1",{className:cs.title,children:"Confirm tx"}),t.jsxs("div",{className:cs.meta,children:[t.jsx(on,{title:"Chain",content:a}),t.jsx(on,{title:"Tx fee",content:t.jsx(Jc,{options:I,value:P,onChange:R})}),o&&t.jsx(on,{title:"Memo",content:o}),b&&t.jsx(oe,{level:"error",children:t.jsx(rl,{...j})})]}),t.jsx(Tl,{messages:r,memo:o,chainId:a}),t.jsx(Pc,{list:r,renderHeader:({typeUrl:y})=>Ns.sentenceCase(y.split(".").pop().replace(/^Msg/,"")),renderContent:y=>t.jsx(gl,{message:y,chainId:a})})]}),t.jsxs(ie,{className:cs.footer,children:[t.jsx(J.Outline,{onClick:()=>n(new Error("User rejected")),disabled:z,className:cs.rejectButton,children:t.jsx(A.IconClose,{size:16})}),t.jsx(J.White,{onClick:()=>B(),disabled:b,loading:z,children:"Approve"})]})]})},Rl=({children:e})=>{const[{title:s,content:n,path:r},o]=_.useState({}),[a,i]=_.useState(!1),c=H.useAtomValue(Fs),l=_.useCallback(h=>{o(h),i(!0)},[]),d=_.useCallback(()=>{o({}),i(!1)},[]),u=_.useCallback(h=>{h||(c?.reject(new Error("User rejected")),o({})),i(h)},[c]);return t.jsxs(yo.Provider,{value:{openModal:l,closeModal:d},children:[e,t.jsx(Po,{title:s,open:a,onOpenChange:u,children:t.jsx(ye,{children:r==="/tx"?t.jsx(Ko,{}):n})})]})},Bl="_container_1w1hx_1",Ml="_toast_1w1hx_11",Fl="_info_1w1hx_24",Ol="_success_1w1hx_28",Ul="_error_1w1hx_32",Ll="_icon_1w1hx_37",zl="_content_1w1hx_45",Kl="_title_1w1hx_48",Wl="_description_1w1hx_53",Hl="_close_1w1hx_75",et={container:Bl,toast:Ml,info:Fl,success:Ol,error:Ul,icon:Ll,content:zl,title:Kl,description:Wl,close:Hl},Ql=({notification:e,onClose:s,...n})=>{const r=rt.useTransition(e,{keys:a=>a?.id||"empty",from:{transform:"translateY(-52px)",opacity:0},enter:{transform:"translateY(0px)",opacity:1},leave:{transform:"translateY(-52px)",opacity:0},config:{tension:500,friction:30,clamp:!0}}),o=a=>{switch(a){case"loading":return t.jsx(wt,{size:16});case"info":case"success":return t.jsx(A.IconCheckCircleFilled,{size:16});case"error":return t.jsx(A.IconCloseCircleFilled,{size:16});default:return null}};return r((a,i)=>{if(!i)return null;const{type:c,title:l,description:d}=i,u=o(c);return t.jsx(rt.animated.div,{style:a,className:et.container,children:t.jsxs("div",{className:D(et.toast,c&&et[c]),...n,children:[u&&t.jsx("div",{className:et.icon,children:u}),t.jsxs("div",{className:et.content,children:[t.jsx("p",{className:et.title,children:l}),d&&t.jsx("div",{className:et.description,children:d})]}),t.jsx("button",{className:et.close,onClick:s,children:t.jsx(A.IconClose,{size:14})})]})})})},an=5e3,Gl=({children:e})=>{const s=yt(),[n,r]=_.useState(null),o=_.useRef(null),a=_.useRef(!1),i=()=>{o.current&&(clearTimeout(o.current),o.current=null)},c=_.useCallback(()=>{i(),r(null)},[]),l=_.useCallback(m=>{i(),r({...m,id:ar.nanoid()}),m.autoHide&&!a.current&&(o.current=setTimeout(()=>c(),an))},[c]),d=_.useCallback(m=>{i(),r(f=>f?{...f,...m}:{...m,id:ar.nanoid()}),m.autoHide&&!a.current&&(o.current=setTimeout(()=>c(),an))},[c]),u=()=>{i(),a.current=!0},h=()=>{i(),a.current=!1,n?.autoHide&&(o.current=setTimeout(()=>c(),an))};return _.useEffect(()=>()=>i(),[]),t.jsxs(qo.Provider,{value:{showNotification:l,updateNotification:d,hideNotification:c},children:[e,s&&Na.createPortal(t.jsx(Ql,{notification:n,onClose:c,onMouseEnter:u,onMouseLeave:h}),s)]})},Vl=({children:e})=>{const[s,n]=_.useState(null);return t.jsx(Wn.Provider,{value:{container:s,setContainer:n},children:e})},Wo=[{value:10*io,label:"for 10 minutes"},{value:co,label:"for 1 hour"},{value:lr,label:"for 1 day"},{value:7*lr,label:"for 7 days"},{value:0,label:"until revoked"}],Yl=Wo[0].value,Jl="_container_1422v_1",Zl="_title_1422v_7",Xl="_description_1422v_14",ed="_sectionTitle_1422v_20",td="_websiteInfo_1422v_27",sd="_favicon_1422v_37",nd="_websiteTitle_1422v_42",rd="_websiteHost_1422v_48",od="_warningContent_1422v_54",ad="_ignoreButton_1422v_61",id="_infoList_1422v_65",cd="_infoItem_1422v_75",ld="_label_1422v_84",dd="_infoValue_1422v_94",ud="_durationTrigger_1422v_100",hd="_durationItem_1422v_101",md="_featureList_1422v_105",fd="_featureItem_1422v_113",_d="_checkIcon_1422v_123",gd="_learnMoreLink_1422v_127",pd="_feedbackContainer_1422v_140",xd="_footer_1422v_146",W={container:Jl,title:Zl,description:Xl,sectionTitle:ed,websiteInfo:td,favicon:sd,websiteTitle:nd,websiteHost:rd,warningContent:od,ignoreButton:ad,infoList:id,infoItem:cd,label:ld,infoValue:dd,durationTrigger:ud,durationItem:hd,featureList:md,featureItem:fd,checkIcon:_d,learnMoreLink:gd,feedbackContainer:pd,footer:xd},yd=Ne.createQueryKeys("interwovenkit:account",{info:(e,s)=>({queryKey:[e,s],queryFn:async()=>{const n=L.create({prefixUrl:e}),r=`cosmos/auth/v1beta1/account_info/${s}`;return n.get(r).json()}})}),jd=()=>{const[e,s]=_.useState(Yl),[n,r]=H.useAtom(ts),[o,a]=_.useState(!1),i=Te(),c=ae(),{address:l,username:d}=xe(),{mutate:u,isPending:h}=di(),{closeDrawer:m}=Ve();if(!n)throw new Error("Pending request not found");const{logoUrl:f,name:g,restUrl:p}=i(n.chainId),{data:x,isLoading:S}=$.useQuery(yd.info(p,l)),I={favicon:document.querySelector('link[rel="icon"]')?.getAttribute("href")||"",title:document.title,hostname:window.location.hostname},N=c.some(R=>{if(!R.website)return!1;const B=pr(new URL(R.website).hostname),z=pr(window.location.hostname);return B===z}),C=()=>{u(e)},T=()=>{n?.reject(new Error("User cancelled")),r(null),m()},P=!N&&!o;return t.jsxs(t.Fragment,{children:[t.jsxs(Fe,{className:W.container,children:[t.jsxs("header",{children:[t.jsx("h1",{className:W.title,children:"Enable auto-signing"}),t.jsx("p",{className:W.description,children:"An application is requesting to enable auto-signing"})]}),t.jsxs("section",{children:[t.jsx("h2",{className:W.sectionTitle,children:"Requested by"}),t.jsxs("div",{className:W.websiteInfo,children:[t.jsx("img",{src:I.favicon,alt:"",className:W.favicon}),t.jsxs("div",{children:[t.jsx("div",{className:W.websiteTitle,children:I.title}),t.jsx("div",{className:W.websiteHost,children:I.hostname})]})]})]}),t.jsxs("section",{children:[t.jsx("h2",{className:W.sectionTitle,children:"Applies to"}),t.jsxs("div",{className:W.infoList,children:[t.jsxs("div",{className:W.infoItem,children:[t.jsx("div",{className:W.label,children:"Address"}),t.jsxs("div",{className:W.infoValue,children:[t.jsx(A.IconWallet,{size:14}),t.jsx("span",{className:"monospace",children:v.truncate(d??l)})]})]}),t.jsxs("div",{className:W.infoItem,children:[t.jsx("div",{className:W.label,children:"Chain"}),t.jsxs("div",{className:W.infoValue,children:[t.jsx(Y,{src:f,width:14,height:14,logo:!0}),t.jsx("span",{children:g})]})]}),t.jsxs("div",{className:W.infoItem,children:[t.jsx("div",{className:W.label,children:"Duration"}),t.jsx(Fo,{options:Wo,value:e,onChange:s,classNames:{trigger:W.durationTrigger,item:W.durationItem}})]})]})]}),t.jsxs("section",{children:[t.jsx("h2",{className:W.sectionTitle,children:"About auto-signing"}),t.jsx("ul",{className:W.featureList,children:["Send transactions without confirmation pop-ups","Protected by Privy embedded wallet","Revoke permissions any time in settings"].map(R=>t.jsxs("li",{className:W.featureItem,children:[t.jsx(A.IconCheckCircle,{size:12,className:W.checkIcon}),t.jsx("span",{children:R})]},R))}),t.jsxs("a",{href:"https://docs.initia.xyz/user-guides/wallet/auto-signing/introduction",target:"_blank",className:W.learnMoreLink,children:["Learn more ",t.jsx(A.IconExternalLink,{size:12})]})]})]}),t.jsxs(ie,{className:W.footer,extra:t.jsxs("div",{className:W.feedbackContainer,children:[!S&&!x&&t.jsx(oe,{level:"error",children:"Insufficient balance for fee"}),!N&&!o&&t.jsx(oe,{level:"warning",children:t.jsxs("div",{className:W.warningContent,children:[t.jsx("span",{children:"You are on an unverified website"}),t.jsx("button",{onClick:()=>a(!0),className:W.ignoreButton,children:"Ignore"})]})})]}),children:[t.jsx(J.Outline,{onClick:T,children:"Cancel"}),t.jsx(J.White,{onClick:C,disabled:P||!x||S,loading:h,children:"Enable"})]})]})},vd=()=>H.useAtomValue(ts)?t.jsx(jd,{}):null;function pr(e){const s=e.split(".");return s.length<2?e:s.slice(-2).join(".")}const wd="_container_mqvhs_1",bd="_badge_mqvhs_5",xr={container:wd,badge:bd},Ho=e=>{const{offset:s=-4,disabled:n,children:r,className:o}=e;return t.jsxs("div",{className:D(xr.container,o),children:[r,!n&&t.jsx("div",{className:xr.badge,style:{right:s,top:s}})]})},Cd="_header_s7mee_1",Id="_back_s7mee_12",Nd="_title_s7mee_24",cn={header:Cd,back:Id,title:Nd},Oe=({title:e,backButton:s,extra:n,children:r})=>t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:cn.header,children:[t.jsx(Et,{to:s??-1,className:cn.back,shouldReset:!!s,children:t.jsx(A.IconBack,{size:16})}),t.jsx("h1",{className:cn.title,children:e}),n]}),t.jsx(Fe,{children:r})]});function Qo(){const{initiaAddress:e,hexAddress:s}=xe(),n=vt(),r=ss();return o=>{const a=n(o);switch(r(a)){case"initia":return e;case"evm":return s;default:return""}}}function Go(){const e=vt(),s=ss();return(n,r)=>{const o=e(r);switch(s(o)){case"initia":return v.InitiaAddress.validate(n);case"evm":return We.isAddress(n);case"cosmos":try{return V.fromBech32(n).prefix===o.bech32_prefix}catch{return!1}default:return!1}}}function Sd(){const e=vt(),s=ss();return({initialAddress:n,initialChainId:r,chainId:o,fallbackAddress:a})=>{const i=e(r),c=s(i),l=e(o),d=s(l);if(c==="evm"&&d==="initia")return v.InitiaAddress(n).bech32;if(c==="initia"&&d==="evm")return v.InitiaAddress(n).hex;if(c===d)return n;if(a){if(d==="initia")return v.InitiaAddress(a).bech32;if(d==="evm")return v.InitiaAddress(a).hex}return""}}function Ad(){return _e().network_type==="testnet"}function ot(){return ue.useFormContext()}function kd(){const e=jt(),s=Ad(),n={quantity:"",slippagePercent:"0.5",sender:"",cosmosWalletName:"",recipient:""},r={...n,srcChainId:"initiation-2",srcDenom:"uusdc",dstChainId:"initiation-2",dstDenom:"uinit"},o={...n,srcChainId:"interwoven-1",srcDenom:"ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4",dstChainId:"interwoven-1",dstDenom:"uinit"},a=w.pickBy(i=>i!==null,{srcChainId:localStorage.getItem(U.BRIDGE_SRC_CHAIN_ID),srcDenom:localStorage.getItem(U.BRIDGE_SRC_DENOM),dstChainId:localStorage.getItem(U.BRIDGE_DST_CHAIN_ID),dstDenom:localStorage.getItem(U.BRIDGE_DST_DENOM),quantity:localStorage.getItem(U.BRIDGE_QUANTITY),slippagePercent:localStorage.getItem(U.BRIDGE_SLIPPAGE_PERCENT)});return{...s?r:o,...a,...e}}const $d="_root_ekn9t_1",Td="_header_ekn9t_6",Ed="_title_ekn9t_12",qd="_warning_ekn9t_18",Dd="_content_ekn9t_22",Pd="_footer_ekn9t_26",Rd="_secondary_ekn9t_36",dt={root:$d,header:Td,title:Ed,warning:qd,content:Dd,footer:Pd,secondary:Rd},Vo=e=>{const{type:s,icon:n,title:r,children:o,primaryButton:a,secondaryButton:i}=e;return t.jsxs(Fe,{className:dt.root,children:[t.jsxs("header",{className:D(dt.header,s&&dt[s]),children:[n,t.jsx("h1",{className:dt.title,children:r})]}),t.jsx("div",{className:dt.content,children:o}),t.jsxs("footer",{className:dt.footer,children:[t.jsx(J.White,{onClick:a.onClick,sm:!0,fullWidth:!0,children:a.label}),t.jsxs("button",{className:dt.secondary,onClick:i.onClick,children:[t.jsx("span",{children:i.label}),t.jsx(A.IconChevronRight,{size:14})]})]})]})},Bd="_list_k4n3k_1",Md="_row_k4n3k_9",Fd="_dt_k4n3k_20",Od="_asset_k4n3k_26",ls={list:Bd,row:Md,dt:Fd,asset:Od},Ud=({list:e,onNavigate:s,onDismiss:n})=>{const r=_e(),o=Te(),a=Ge(r);return t.jsx(Vo,{title:"Ready to claim",primaryButton:{label:"View withdrawal status",onClick:s},secondaryButton:{label:"Do not show again",onClick:n},children:t.jsx("div",{className:ls.list,children:e.toSorted((i,c)=>i.chainId.localeCompare(c.chainId)).map(({txHash:i,chainId:c,amount:l,denom:d})=>{const u=o(c),{decimals:h,symbol:m}=a(d),f=v.formatAmount(l,{decimals:h});return t.jsxs("div",{className:ls.row,children:[t.jsxs("div",{className:ls.dt,children:[t.jsx(Y,{src:u.logoUrl,width:16,height:16,logo:!0}),t.jsx("span",{children:u.name})]}),t.jsxs("span",{className:ls.asset,children:[f," ",m]})]},i)})})})};function ln(e,s){return e.chainId===s.chainId&&e.txHash===s.txHash}const ds=({chainId:e,txHash:s})=>`${U.OP_REMINDER}:${e}:${s}`,Ld=Sa.atomWithStorage(U.OP_REMINDER,[]);function Rt(){const e=ee(),[s=[],n]=H.useAtom(Ld),r=_.useMemo(()=>s.map(l=>{const d=localStorage.getItem(ds(l));return d?JSON.parse(d):null}).filter(l=>{if(!l)return!1;const{recipient:d,claimableAt:u}=l;return d!==e?!1:ke.isPast(u)}),[e,s]),o=_.useCallback((l,d)=>{s.some(u=>ln(u,l))||(n((u=[])=>[...u,l]),localStorage.setItem(ds(l),JSON.stringify(d)))},[s,n]),a=_.useCallback(l=>{n((d=[])=>d.filter(u=>!ln(u,l))),localStorage.removeItem(ds(l))},[n]),i=_.useCallback(l=>{const d=l.filter(u=>!s.some(h=>ln(h,u)));d.length!==0&&n((u=[])=>[...u,...d])},[s,n]),c=_.useCallback((l,d)=>{localStorage.setItem(ds(l),JSON.stringify(d)),n((u=[])=>[...u])},[n]);return{reminders:r,addReminder:o,removeReminder:a,syncReminders:i,setReminder:c}}function Yo(){const e=he(),{openModal:s,closeModal:n}=Ms(),{reminders:r,setReminder:o}=Rt();_.useEffect(()=>{const a=r.filter(l=>!l.dismissed);if(a.length===0)return;const i=()=>{const l=a.every(d=>d.chainId===a[0].chainId)?a[0].chainId:void 0;e("/op/withdrawals",{chainId:l}),c()},c=()=>{n();for(const l of a)o(l,{...l,dismissed:!0})};s({content:_.createElement(Ud,{list:a,onNavigate:i,onDismiss:c})})},[r,n,e,s,o])}const zd="_wrapper_5ssm8_1",Kd="_balance_5ssm8_11",Wd="_button_5ssm8_15",dn={wrapper:zd,balance:Kd,button:Wd},Jo=({onClick:e,children:s,disabled:n})=>t.jsxs("div",{className:dn.wrapper,children:[t.jsx(A.IconWallet,{size:16}),t.jsx("span",{className:dn.balance,children:s}),t.jsx("button",{type:"button",tabIndex:-1,className:dn.button,onClick:()=>e(),disabled:n,children:"MAX"})]}),Hd="_fieldset_up6fh_1",Qd="_upper_up6fh_9",Gd="_select_up6fh_14",Vd="_account_up6fh_20",Yd="_lower_up6fh_25",Jd="_wrapper_up6fh_26",Zd="_balance_up6fh_33",Xd="_value_up6fh_37",eu="_error_up6fh_50",ze={fieldset:Hd,upper:Qd,select:Gd,account:Vd,lower:Yd,wrapper:Jd,balance:Zd,value:Xd,error:eu},In=e=>{const{selectButton:s,accountButton:n,quantityInput:r,balanceButton:o,value:a,errorMessage:i,hideNumbers:c}=e;return t.jsxs("div",{className:ze.fieldset,children:[t.jsxs("div",{className:ze.upper,children:[t.jsx("div",{className:ze.select,children:s}),t.jsx("div",{className:ze.account,children:n})]}),!c&&t.jsxs("div",{className:ze.lower,children:[r,t.jsxs("div",{className:ze.wrapper,children:[t.jsx("div",{className:ze.balance,children:o}),a&&t.jsx("div",{className:ze.value,children:a})]}),i&&t.jsxs("footer",{className:ze.error,children:[t.jsx(A.IconWarningFilled,{size:12}),t.jsx("p",{children:i})]})]})]})};function ns(){const e=_.useRef(null),s=Ls();return _.useEffect(()=>{s||e.current?.focus()},[s]),e}const tu="_input_h8073_1",su={input:tu};function yr(e,s){const n=e.replace(/[^0-9.]/g,""),[r,...o]=n.split(".");return o.length===0?r:`${r}.${o.join("").slice(0,s)}`}function Zo(e){const{name:s,control:n,dp:r=6,className:o,rules:a,...i}=e,c=ns();return t.jsx(ue.Controller,{name:s,control:n,rules:a,render:({field:l})=>t.jsx("input",{...l,className:D(su.input,o),onChange:d=>l.onChange(yr(d.target.value,r)),onPaste:d=>{d.preventDefault();const u=d.clipboardData.getData("text");if(!/^[0-9,]+(\.[0-9]+)?$/.test(u))return;const m=u.replace(/,/g,""),f=yr(m,r);l.onChange(f)},placeholder:"0",inputMode:"decimal",autoComplete:"off",...i,ref:Wr.mergeRefs([l.ref,c])})})}const nu="_input_19r9r_1",ru="_placeholder_19r9r_18",Nn={input:nu,placeholder:ru},ou=({children:e})=>t.jsx("p",{className:D(Nn.input,{[Nn.placeholder]:F(e).isZero()}),children:e}),bs=({balance:e,decimals:s})=>{const{control:n}=ue.useFormContext(),r={required:"Enter amount",validate:o=>F(o).isZero()?"Enter amount":F(v.toBaseUnit(o,{decimals:s})).gt(e??0)?"Insufficient balance":!0};return t.jsx(Zo,{name:"quantity",control:n,className:Nn.input,rules:r})};bs.ReadOnly=ou;const Dt=({title:e,content:s,children:n,className:r})=>{const[o,a]=_.useState(!1),i=()=>a(!1);return t.jsx(Po,{title:e,trigger:n,className:r,open:o,onOpenChange:a,children:s(i)})},au="_tooltip_19kvs_1",iu="_arrow_19kvs_44",jr={tooltip:au,arrow:iu},rs=({label:e,children:s,small:n,...r})=>t.jsxs(se.Tooltip.Root,{...r,children:[t.jsx(se.Tooltip.Trigger,{asChild:!0,children:s}),t.jsx(se.Tooltip.Portal,{container:yt(),children:t.jsxs(se.Tooltip.Content,{className:D(jr.tooltip,{small:n}),collisionBoundary:yt(),collisionPadding:8,sideOffset:4,children:[e,t.jsx(se.Tooltip.Arrow,{className:jr.arrow})]})})]});function Qn(e,s){const n=Ye();return $.useQuery({queryKey:Re.balances(s,e).queryKey,queryFn:()=>n.post("v2/info/balances",{json:{chains:{[s]:{address:e,denoms:[]}}}}).json(),select:({chains:r})=>e?r?r[s].denoms??{}:{}:{},enabled:!!e,staleTime:Q.SECOND})}function cu(e,s,n){const{data:r={}}=Qn(e,s);return w.path([n],r)}const lu=[["d",1440*60],["h",3600],["m",60],["s",1]];function Sn(e){if(!e)return;const{formattedParts:s}=lu.reduce(({remainingSeconds:n,formattedParts:r},[o,a])=>{const i=Math.floor(n/a);return{remainingSeconds:n-i*a,formattedParts:i>0?[...r,`${i}${o}`]:r}},{remainingSeconds:e,formattedParts:[]});return s.join(" ")}function Xo(e){return e?.map(s=>{const{amount:n,origin_asset:r}=s;return`${v.formatAmount(n,{decimals:r.decimals??0})} ${r.symbol}`}).join(", ")}function vr(e,s){const{watch:n}=ot(),r=n(),o=Ye(),a=qs(),i={...r,quantity:e},c=$.useQueryClient();return $.useQuery({queryKey:Re.route(i,s?.isOpWithdraw).queryKey,queryFn:async()=>{const{srcChainId:l,srcDenom:d,quantity:u,dstChainId:h,dstDenom:m}=i,{decimals:f}=c.getQueryData(Re.asset(l,d).queryKey)??{decimals:0},g={amount_in:v.toBaseUnit(u,{decimals:f}),source_asset_chain_id:l,source_asset_denom:d,dest_asset_chain_id:h,dest_asset_denom:m,is_op_withdraw:s?.isOpWithdraw},p=await o.post("v2/fungible/route",{json:g}).json(),x={quantity:i.quantity,srcChainId:i.srcChainId,srcDenom:i.srcDenom,dstChainId:i.dstChainId,dstDenom:i.dstDenom};return a("Bridge Simulation Success",x),p},enabled:!!Number(i.quantity)&&!s?.disabled,staleTime:Q.MINUTE})}function du(e){return $.useQuery({queryKey:Re.routeErrorInfo(e||new Error).queryKey,queryFn:async()=>{if(!e||!(e instanceof L.HTTPError))return null;const{response:s}=e;return(s.headers.get("content-type")??"").includes("application/json")?(await s.json()).info??null:null}})}function uu(){const{watch:e}=ot(),{srcChainId:s,srcDenom:n,dstChainId:r,dstDenom:o}=e(),a=Be(s),i=Jt(a),c=Qe(n,s),l=Qe(o,r),d=_e(),u=ae();return i==="initia"&&r===d.chainId&&c.symbol===l.symbol&&u.find(h=>h.chainId===s)?.metadata?.op_denoms?.includes(l.denom)}const hu="_label_t93ix_1",mu="_wrapper_t93ix_7",fu="_input_t93ix_10",_u="_clear_t93ix_18",us={label:hu,wrapper:mu,input:fu,clear:_u},Gn=({mode:e="onChange",myAddress:s,...n})=>{const{validate:r=v.InitiaAddress.validate,chainType:o="initia",onApply:a,ref:i}=n,c=ns(),{control:l,getValues:d,setValue:u,formState:h}=ue.useFormContext(),m=d("recipient"),[f,g]=_.useState(m),p=to(),{data:x,isLoading:S,error:I}=$.useQuery({queryKey:$s.address(p.restUrl,f).queryKey,queryFn:()=>p.getAddress(f),staleTime:Q.MINUTE,enabled:p.validateUsername(f)}),N=x??(r(f)?f:""),C=s&&v.InitiaAddress.equals(N,s),T=async()=>{try{const B=await navigator.clipboard.readText();g(B.trim())}catch{}};_.useEffect(()=>{e==="onChange"&&(!f&&!h.dirtyFields.recipient||u("recipient",x??f,{shouldValidate:!0,shouldDirty:!0}))},[h.dirtyFields.recipient,f,e,u,x]);const P=()=>{S||I||(u("recipient",N,{shouldValidate:!0,shouldDirty:!0}),a?.())},R=()=>{if(S)return t.jsx(kt,{level:"loading",children:"Resolving username..."});if(I)return t.jsx(kt,{level:"error",children:I.message});if(x)return t.jsx(kt,{level:"success",className:"monospace",children:x});if(e==="onSubmit"&&f&&!N)return t.jsx(kt,{level:"error",children:"Invalid address"})};return t.jsxs("div",{children:[t.jsxs("label",{htmlFor:"recipient",className:us.label,children:[t.jsx("span",{children:"Recipient"}),t.jsx(J.Small,{type:"button",tabIndex:-1,onClick:T,children:"Paste"})]}),t.jsxs("div",{className:us.wrapper,children:[t.jsx(ue.Controller,{name:"recipient",control:l,rules:{required:"Recipient address is required",validate:B=>r(B)||"Invalid address"},render:()=>t.jsx("input",{id:"recipient",className:D(us.input,"monospace"),value:f,onChange:B=>g(B.target.value.trim()),placeholder:o==="initia"?"Address or username":"Enter address",autoComplete:"off","data-has-value":f?"true":void 0,ref:e==="onSubmit"?Wr.mergeRefs([i,c]):i})}),!!f&&t.jsx("button",{type:"button",className:us.clear,onClick:()=>g(""),"aria-label":"Clear recipient",children:t.jsx(A.IconCloseCircleFilled,{size:16})})]}),R(),C&&t.jsx(kt,{children:"This is my address"}),e==="onSubmit"&&t.jsx(ie,{extra:(!s||!!N&&!C)&&t.jsx(oe,{level:"warning",children:"Do not enter an exchange address. Tokens sent to an address that does not support bridge transfer will be irretrievable."}),children:t.jsx(J.White,{type:"button",onClick:P,disabled:S||!!I||!N,children:"Apply"})})]})},gu="_scrollable_vgj3r_1",pu="_list_vgj3r_5",xu="_item_vgj3r_9",yu="_name_vgj3r_22",hs={scrollable:gu,list:pu,item:xu,name:yu};function ea({onSelect:e,list:s,...n}){const{getImage:r,getName:o,getKey:a,getIsLoading:i,getDisabled:c}=n;return t.jsx(Fe,{className:hs.scrollable,children:t.jsx("div",{className:hs.list,children:s.map(l=>t.jsxs("button",{className:hs.item,onClick:()=>e(l),disabled:i?.(l)||c?.(l),children:[t.jsx(Y,{src:r(l),width:28,height:28}),t.jsx("span",{className:hs.name,children:o(l)}),i?.(l)&&t.jsx(wt,{size:16})]},a(l)))})})}function Ks(){const e=[{name:"Keplr",image:"https://assets.initia.xyz/images/wallets/Keplr.webp",getProvider:()=>window.keplr,fallbackUrl:"https://keplr.app/get"},{name:"Leap",image:"https://assets.initia.xyz/images/wallets/Leap.webp",getProvider:()=>window.leap,fallbackUrl:"https://leapwallet.io/download"}];return{list:e,find:n=>e.find(r=>r.name===n)}}const ju="_account_h04x1_8",vu="_clear_h04x1_28",wu="_white_h04x1_39",Ut={account:ju,clear:vu,white:wu},wr=({type:e})=>{const{watch:s,setValue:n}=ot(),{srcChainId:r,dstChainId:o,cosmosWalletName:a}=s(),c=s(e==="src"?"sender":"recipient"),l=Jt(Be(o)),{list:d,find:u}=Ks(),h=u(a),m=Qo(),f=Go(),g=m(o),p=v.InitiaAddress.equals(c,g),x=()=>t.jsx(Dt,{title:"Connect wallet",content:N=>t.jsx(ea,{onSelect:async C=>{const T=C.getProvider();if(!T)return window.open(C.fallbackUrl,"_blank");const P=T.getOfflineSigner(r),[{address:R}]=await P.getAccounts();n("sender",R),n("cosmosWalletName",C.name),N()},list:d,getImage:C=>C.image,getName:C=>C.name,getKey:C=>C.name}),className:D(Ut.account,{[Ut.white]:!c}),children:c?t.jsxs(t.Fragment,{children:[h&&t.jsx(Y,{src:h.image,width:18,height:18}),t.jsx("span",{className:"monospace",children:v.truncate(c)})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"Connect wallet"}),t.jsx(A.IconChevronRight,{size:14})]})}),S=N=>t.jsx(Dt,{title:"Recipient",content:C=>t.jsx(Fe,{children:t.jsx(Gn,{mode:"onSubmit",myAddress:g,chainType:l,validate:T=>f(T,o),onApply:C})}),className:Ut.account,children:N}),I=()=>{switch(l){case"initia":case"evm":return p?S(t.jsx(A.IconWallet,{size:14})):t.jsxs("div",{className:Ut.account,children:[t.jsx("span",{className:"monospace",children:v.truncate(c)}),t.jsx("button",{type:"button",className:Ut.clear,onClick:()=>n("recipient",g,{shouldValidate:!0}),"aria-label":"Reset to my address",children:t.jsx(A.IconCloseCircleFilled,{size:14})})]});case"cosmos":return S(t.jsxs(t.Fragment,{children:[c?t.jsx("span",{className:"monospace",children:v.truncate(c)}):t.jsx("span",{children:"Recipient"}),t.jsx(A.IconEdit,{size:14})]}))}};switch(e){case"src":return x();case"dst":return I()}},bu="_images_cj4xz_1",un={images:bu},Ws=({assetLogoUrl:e,assetLogoSize:s=36,chainLogoUrl:n,chainLogoSize:r=18,chainLogoOffset:o=6,className:a})=>t.jsxs("div",{className:D(un.images,a),style:{position:"relative"},children:[t.jsx(Y,{src:e,width:s,height:s,className:un.asset,logo:!0}),t.jsx(Y,{src:n,width:r,height:r,className:un.chain,style:{position:"absolute",bottom:0,right:-1*o},logo:!0})]}),Cu="_root_6187w_1",Iu="_content_6187w_10",Nu="_details_6187w_20",Su="_symbol_6187w_26",Au="_chain_6187w_34",ku="_chevron_6187w_43",ut={root:Cu,content:Iu,details:Nu,symbol:Su,chain:Au,chevron:ku},ta=({asset:e,chain:s,readOnly:n})=>{const r=t.jsxs("div",{className:ut.content,children:[t.jsx(Ws,{assetLogoUrl:e.logoUrl,chainLogoUrl:s.logoUrl}),t.jsxs("div",{className:ut.details,children:[t.jsx("div",{className:ut.symbol,children:e.symbol||e.denom}),t.jsxs("div",{className:ut.chain,children:["on ",s.name]})]})]});return n?t.jsx("div",{className:ut.root,children:r}):t.jsxs("div",{className:ut.root,children:[r,t.jsx(A.IconChevronDown,{size:16,className:ut.chevron})]})};function $u(e,s,n){return n.filter(r=>{const o=e.map(a=>r[a]).map(a=>String(a??"").toLowerCase());return w.any(w.includes(s.toLowerCase()),o)})}const Tu="_root_1sh27_1",Eu="_label_1sh27_8",qu="_input_1sh27_21",Du="_hasValue_1sh27_31",Pu="_clear_1sh27_35",Lt={root:Tu,label:Eu,input:qu,hasValue:Du,clear:Pu},Hs=e=>{const{rootClassName:s,padding:n=16,iconSize:r=16,onClear:o,ref:a,...i}=e;return t.jsxs("div",{className:D(Lt.root,s,{[Lt.hasValue]:i.value}),style:{"--search-input-padding":`${n}px`,"--search-input-icon-size":`${r}px`},children:[t.jsx("label",{htmlFor:"search",className:Lt.label,children:t.jsx(A.IconSearch,{size:r})}),t.jsx("input",{className:Lt.input,id:"search",type:"text",maxLength:100,ref:a,...i}),i.value&&t.jsx("button",{type:"button",className:Lt.clear,"aria-label":"Clear search",onMouseDown:c=>c.preventDefault(),onClick:o,children:t.jsx(A.IconCloseCircleFilled,{size:r})})]})},Ru="_container_1mzcj_1",Bu="_search_1mzcj_7",Mu="_list_1mzcj_11",Fu="_item_1mzcj_15",Ou="_logo_1mzcj_37",Uu="_info_1mzcj_41",Lu="_symbol_1mzcj_47",zu="_name_1mzcj_56",Ku="_balance_1mzcj_62",Wu="_value_1mzcj_69",Ce={container:Ru,search:Bu,list:Mu,item:Fu,logo:Ou,info:Uu,symbol:Lu,name:zu,balance:Ku,value:Wu},os=e=>{const{assets:s,onSelect:n,renderAsset:r=(c,l)=>l(c)}=e,[o,a]=_.useState(""),i=$u(["symbol"],o,s);return t.jsxs("div",{className:Ce.container,children:[t.jsx(Hs,{value:o,onChange:c=>a(c.target.value),onClear:()=>a(""),placeholder:"Search by symbol",rootClassName:Ce.search,padding:20,ref:ns()}),i.length===0?t.jsx(ne,{children:"No assets"}):t.jsx("div",{className:Ce.list,children:i.map(c=>t.jsx("button",{type:"button",className:Ce.item,onClick:()=>n(c.denom),children:r(c,l=>{const{denom:d,logoUrl:u,symbol:h,name:m,balance:f,decimals:g,value:p=0}=l;return t.jsxs(t.Fragment,{children:[t.jsx(Y,{src:u,width:32,height:32,className:Ce.logo,logo:!0}),t.jsxs("div",{className:Ce.info,children:[t.jsx("div",{className:Ce.symbol,children:h||d}),t.jsx("div",{className:Ce.name,children:m})]}),t.jsxs("div",{className:Ce.balance,children:[f&&t.jsx("div",{children:v.formatAmount(f,{decimals:g})}),p>0&&t.jsx("div",{className:Ce.value,children:$e(p)})]})]})})},c.denom))})]})},Hu=()=>t.jsxs("div",{className:Ce.container,children:[t.jsx(Hs,{rootClassName:Ce.search,padding:20,placeholder:"Search by symbol",readOnly:!0}),t.jsx(ne,{children:"Loading..."})]});os.Placeholder=Hu;const Qu="_stack_16oqn_1",Gu="_title_16oqn_9",Vu="_grid_16oqn_16",Yu="_item_16oqn_22",Ju="_button_16oqn_26",Zu="_active_16oqn_44",$t={stack:Qu,title:Gu,grid:Vu,item:Yu,button:Ju,active:Zu},xt=({label:e,chains:s,value:n,onSelect:r,getShowIndicator:o})=>t.jsxs("div",{children:[e&&t.jsx("h2",{className:$t.title,children:e}),t.jsx("div",{className:$t.grid,children:s.map(({chainId:a,name:i,logoUrl:c})=>t.jsx(Ho,{offset:-2,disabled:!o?.(a),className:$t.item,children:t.jsx(rs,{label:i,disableHoverableContent:!0,children:t.jsx("button",{type:"button",className:D($t.button,{[$t.active]:a===n}),onClick:()=>r(a),children:t.jsx(Y,{src:c,width:28,height:28,logo:!0})})})},a))})]}),Xu=({children:e})=>t.jsx("div",{className:$t.stack,children:e});xt.Stack=Xu;const eh=({address:e,chain:s,onSelect:n})=>{const r=qt(s.chain_id),{data:o={}}=Qn(e,s.chain_id);return t.jsx(os,{assets:w.sortWith([w.descend(a=>a.symbol==="INIT"),w.descend(a=>a.value),({balance:a="0"},{balance:i="0"})=>F(i).comparedTo(a)??0,w.ascend(a=>a.symbol.toLowerCase())],r.filter(a=>!a.hidden).map(a=>{const{denom:i,symbol:c=v.truncate(i),logo_uri:l}=a,d=o[i]??{};return{...a,symbol:c,decimals:a.decimals??0,logoUrl:l??"",name:a.name??"",balance:d.amount,value:Number(d.value_usd??0)}})),onSelect:n})},th=({type:e,afterSelect:s})=>{const n=e==="src"?"srcChainId":"dstChainId",r=e==="src"?"srcDenom":"dstDenom",o=e==="src"?"sender":"recipient",a=Pt(),i=Kn(),{watch:c,setValue:l}=ot(),d=c(o),u=c(n),h=c(r),[m,f]=_.useState(u),g=Be(m),p=Sd(),x=ko(),[S,I]=w.partition(C=>x(C.chain_id),i.filter(C=>!C.hidden)),N=C=>{if(u===m&&h===C){s();return}l(n,m),l(r,C),s()};return t.jsxs(t.Fragment,{children:[t.jsxs(xt.Stack,{children:[t.jsx(xt,{label:"Interwoven Economy",chains:S.map(({chain_id:C,chain_name:T,pretty_name:P,logo_uri:R})=>({chainId:C,name:P||T,logoUrl:R??""})),value:m,onSelect:f}),t.jsx(xt,{label:"Chains",chains:I.map(({chain_id:C,chain_name:T,pretty_name:P,logo_uri:R})=>({chainId:C,name:P||T,logoUrl:R??""})),value:m,onSelect:f})]}),t.jsx(ye,{suspenseFallback:t.jsx(os.Placeholder,{}),children:t.jsx(eh,{address:p({initialAddress:d,initialChainId:u,chainId:m,fallbackAddress:e==="src"?a:void 0}),chain:g,onSelect:N})},m)]})},br=({type:e})=>{const s=e==="src"?"srcChainId":"dstChainId",n=e==="src"?"srcDenom":"dstDenom",r=e==="src"?"Select source chain and asset":"Select destination chain and asset",{watch:o}=ot(),a=o(s),i=o(n),c=Be(a),l=Qe(i,a);return t.jsx(Dt,{title:r,content:d=>t.jsx(th,{type:e,afterSelect:d}),children:t.jsx(ta,{asset:{denom:l.denom,decimals:l.decimals??0,symbol:l.symbol,logoUrl:l.logo_uri??""},chain:{chainId:c.chain_id,name:c.pretty_name||c.chain_name,logoUrl:c.logo_uri??""}})})},sh="_skeleton_1l4jn_1",nh={skeleton:sh},hn=({width:e="100%",height:s})=>t.jsx("div",{className:nh.skeleton,style:{width:e,height:s}}),rh="_stack_oq1ir_1",oh="_button_oq1ir_6",ah="_isLoading_oq1ir_19",ih="_disabled_oq1ir_19",ch="_checked_oq1ir_23",lh="_header_oq1ir_37",dh="_title_oq1ir_43",uh="_duration_oq1ir_52",hh="_warning_oq1ir_62",mh="_amount_oq1ir_66",fh="_value_oq1ir_67",be={stack:rh,button:oh,isLoading:ah,disabled:ih,checked:ch,header:lh,title:dh,duration:uh,warning:hh,amount:mh,value:fh},_h=({children:e})=>t.jsx("div",{className:be.stack,children:e}),ps=({label:e,query:s,value:n,onSelect:r,...o})=>{const{data:a,isLoading:i}=s,{watch:c}=ot(),{dstChainId:l,dstDenom:d}=c(),u=Qe(d,l),h=!i&&o.checked,m=!i&&!a;return t.jsxs("button",{type:"button",className:D(be.button,{[be.isLoading]:i,[be.disabled]:m,[be.checked]:h}),onClick:()=>{i||m||r(n)},children:[t.jsxs("div",{className:be.header,children:[t.jsxs("div",{className:be.title,children:[t.jsx("span",{children:e}),h&&t.jsx(A.IconCheck,{size:14})]}),i?t.jsx(hn,{width:80,height:16}):a?t.jsxs("div",{className:D(be.duration,{[be.warning]:n==="op"}),children:[t.jsx(A.IconClockFilled,{size:12}),t.jsx("span",{children:Sn(a.estimated_route_duration_seconds)})]}):t.jsx("div",{className:be.duration,children:"Not available"})]}),(i||a)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:be.amount,children:i?t.jsx(hn,{width:260,height:40}):a?v.formatAmount(a.amount_out,{decimals:u.decimals}):null}),t.jsx("div",{className:be.value,children:i?t.jsx(hn,{width:120,height:16}):a?a.usd_amount_out?$e(a.usd_amount_out):"$-":null})]})]})};ps.Stack=_h;const gh="_description_nuyvt_1",ph="_presets_nuyvt_8",xh="_preset_nuyvt_8",yh="_active_nuyvt_29",jh="_custom_nuyvt_40",vh="_wrapper_nuyvt_47",wh="_percent_nuyvt_58",qe={description:gh,presets:ph,preset:xh,active:yh,custom:jh,wrapper:vh,percent:wh},Cr=["0.1","0.5","1.0"],bh=({afterConfirm:e})=>{const s=ot(),n=s.getValues("slippagePercent"),[r,o]=_.useState(null),{control:a,watch:i,getValues:c,setValue:l}=ue.useForm({defaultValues:{value:n}}),d=i("value");_.useEffect(()=>{const p=Cr.findIndex(x=>x===n);o(p>=0?p:null)},[n]);const u=(p,x)=>{l("value",p),o(x)},h=()=>{o(null)},m=_.useMemo(()=>Number(d)>100?{type:"error",text:"Slippage must be less than 100%"}:Number(d)>5?{type:"warning",text:"Your transaction may be frontrun"}:Number(d)<.1?{type:"warning",text:"Your transaction may fail"}:null,[d]),f=m?.type==="error",g=({value:p})=>{s.setValue("slippagePercent",p),e()};return t.jsxs(Fe,{children:[t.jsx("p",{className:qe.description,children:"Slippage is how much price movement you can tolerate between the time you send out a transaction and the time it's executed."}),t.jsxs("div",{className:qe.presets,children:[Cr.map((p,x)=>t.jsxs("button",{type:"button",className:D(qe.preset,{[qe.active]:r===x}),onClick:()=>u(p,x),children:[p,"%"]},p)),r!==null?t.jsx("button",{type:"button",className:D(qe.preset,qe.custom),onClick:()=>o(null),children:"Custom"}):t.jsxs("div",{className:qe.wrapper,children:[t.jsx(Zo,{name:"value",control:a,dp:2,onFocus:h,placeholder:"",className:D(qe.preset,qe.active)}),t.jsx("span",{className:qe.percent,children:"%"})]})]}),m&&t.jsx(oe,{level:m.type,children:m.text}),t.jsx(ie,{children:t.jsx(J.White,{type:"button",onClick:()=>g(c()),disabled:f,children:"Confirm"})})]})},Ch="_form_1owk5_1",Ih="_arrow_1owk5_5",Nh="_divider_1owk5_14",Sh="_flip_1owk5_23",Ah="_meta_1owk5_41",kh="_row_1owk5_54",$h="_title_1owk5_60",Th="_description_1owk5_64",Eh="_icon_1owk5_71",qh="_edit_1owk5_76",Dh="_warning_1owk5_99",pe={form:Ch,arrow:Ih,divider:Nh,flip:Sh,meta:Ah,row:kh,title:$h,description:Th,icon:Eh,edit:qh,warning:Dh},Ph=()=>{const e=he(),s=Ls(),[n,r]=Ie.useLocalStorage(U.BRIDGE_ROUTE_TYPE,"default"),{watch:o,setValue:a,handleSubmit:i,formState:c}=ot(),l=o(),{srcChainId:d,srcDenom:u,dstChainId:h,dstDenom:m,quantity:f,sender:g,slippagePercent:p}=l,x=Te(),S=Be(d),I=Jt(S),N=Be(h),C=Jt(N),T=Qe(u,d),P=Qe(m,h),{data:R}=Qn(g,d),B=cu(g,d,u),z=!B?.amount||F(B.amount).isZero(),[j]=Ie.useDebounceValue(f,300),b=I!=="initia"&&C!=="initia",y=uu(),k=vr(j,{disabled:b}),q=vr(j,{isOpWithdraw:!0,disabled:!y}),M=y&&n==="op"?q:k,{data:E,isLoading:G,isFetching:te,error:O}=M,{data:Z}=du(O),Ue=j&&(G||te),Je=()=>{a("srcChainId",h),a("srcDenom",m),a("dstChainId",d),a("dstDenom",u),a("quantity","",{shouldTouch:!1,shouldDirty:!1})},{openModal:at,closeModal:me}=Ms(),ge=i(K=>{if(E?.warning){const{type:ct="",message:Ys}=E.warning??{};at({content:t.jsx(Vo,{type:"warning",icon:t.jsx(A.IconWarningFilled,{size:40}),title:Ns.sentenceCase(ct),primaryButton:{label:"Cancel",onClick:me},secondaryButton:{label:"Proceed anyway",onClick:()=>{e("/bridge/preview",{route:E,values:K}),me()}},children:t.jsx("p",{className:pe.warning,children:Ys})})});return}e("/bridge/preview",{route:E,values:K})}),Ct=_.useMemo(()=>E?.estimated_fees?.filter(({fee_behavior:K})=>K==="FEE_BEHAVIOR_DEDUCTED")??[],[E]),it=_.useMemo(()=>E?.estimated_fees?.filter(({fee_behavior:K})=>K==="FEE_BEHAVIOR_ADDITIONAL")??[],[E]),Mt=_.useMemo(()=>{for(const K of it){const ct=R?.[K.origin_asset.denom]?.amount??"0",Ys=E?.source_asset_denom===K.origin_asset.denom?E.amount_in:"0";if(F(ct).lt(F(Ys).plus(K.amount??"0")))return`Insufficient ${K.origin_asset.symbol} for fees`}},[R,E,it]),er=_.useMemo(()=>{if(!l.sender)return"Connect wallet";if(!l.quantity||!j)return"Enter amount";if(!l.recipient)return"Enter recipient address";if(c.errors.quantity)return c.errors.quantity.message;if(!E)return"Route not found";if(Mt)return Mt},[j,Mt,c,E,l]),xa=E?v.formatAmount(E.amount_out,{decimals:P.decimals}):"0",ya=F(f).gt(0)&&F(f).isEqualTo(v.fromBaseUnit(B?.amount,{decimals:B?.decimals??0})),ja=(()=>{switch(I){case"initia":return x(d).fees.fee_tokens.some(({denom:K})=>K===u);case"cosmos":return S.fee_assets.some(({denom:K})=>K===u);case"evm":return!We.isAddress(u);default:return!1}})(),Vs=_.useCallback((K,ct)=>K.length?t.jsxs("div",{className:pe.description,children:[Xo(K),!s&&t.jsx(rs,{label:ct,children:t.jsx("span",{className:pe.icon,children:t.jsx(A.IconInfoFilled,{size:12})})})]}):null,[s]),as=F(f).gt(0)&&y,tr=_.useMemo(()=>E?[{condition:!!E.estimated_fees?.length,title:"Fees",content:t.jsxs("div",{children:[Vs(Ct,"Fee deducted from the amount you receive"),Vs(it,"Fee charged in addition to the amount you enter")]})},{condition:!as&&!!Sn(E.estimated_route_duration_seconds),title:"Estimated time",content:t.jsx("span",{className:pe.description,children:Sn(E.estimated_route_duration_seconds)})},{condition:E.does_swap,title:"Slippage",content:t.jsxs("span",{className:pe.description,children:[t.jsxs("span",{children:[p,"%"]}),t.jsx(Dt,{title:"Slippage tolerance",content:K=>t.jsx(bh,{afterConfirm:K}),className:pe.edit,children:t.jsx(A.IconSettingFilled,{size:12})})]})}].filter(K=>K.condition):[],[it,Ct,Vs,E,as,p]);return t.jsxs("form",{className:pe.form,onSubmit:ge,children:[t.jsx(In,{selectButton:t.jsx(br,{type:"src"}),accountButton:I==="cosmos"&&t.jsx(wr,{type:"src"}),quantityInput:t.jsx(bs,{balance:B?.amount,decimals:T?.decimals}),balanceButton:t.jsx(Jo,{onClick:()=>a("quantity",v.fromBaseUnit(B?.amount,{decimals:T?.decimals??0}),{shouldValidate:!0}),disabled:z,children:v.formatAmount(B?.amount??"0",{decimals:T.decimals})}),value:E?E.usd_amount_in?$e(E.usd_amount_in):"$-":"$0"}),t.jsxs("div",{className:pe.arrow,children:[t.jsx("div",{className:pe.divider}),t.jsx("button",{type:"button",className:pe.flip,onClick:()=>Je(),children:t.jsx(A.IconChevronDown,{size:16})})]}),t.jsx(In,{selectButton:t.jsx(br,{type:"dst"}),accountButton:t.jsx(wr,{type:"dst"}),quantityInput:t.jsx(bs.ReadOnly,{children:xa}),value:E?E.usd_amount_out?$e(E.usd_amount_out):"$-":"$0",hideNumbers:as}),t.jsx(bn,{children:as?t.jsxs(ps.Stack,{children:[t.jsx(ps,{label:"Fast",query:k,value:"default",onSelect:r,checked:n==="default"}),t.jsx(ps,{label:"Lossless",query:q,value:"op",onSelect:r,checked:n==="op"})]}):null}),t.jsx(ie,{extra:t.jsxs(t.Fragment,{children:[t.jsxs(oe.Stack,{children:[E?.extra_infos?.map(K=>t.jsx(oe,{level:"info",children:K},K)),Z&&t.jsx(oe,{level:"info",children:Z}),ya&&ja&&t.jsx(oe,{level:"warning",children:"Make sure to leave enough for transaction fee"}),E?.warning&&t.jsx(oe,{level:"warning",children:E.warning.message}),E?.extra_warnings?.map(K=>t.jsx(oe,{level:"warning",children:K},K))]}),t.jsx(bn,{children:tr.length>0&&t.jsx("div",{className:pe.meta,children:tr.map((K,ct)=>t.jsxs("div",{className:pe.row,children:[t.jsx("span",{className:pe.title,children:K.title}),K.content]},ct))})})]}),children:t.jsx(J.White,{loading:Ue&&"Simulating...",disabled:!!er,children:er??"Preview route"})})]})},Rh=()=>{Yo();const e=Ha(),s=he(),{closeDrawer:n}=Ve(),r=Pt(),o=kd(),a=ue.useForm({mode:"onChange",defaultValues:o}),{watch:i,setValue:c}=a,{srcChainId:l,dstChainId:d,srcDenom:u,dstDenom:h,quantity:m,slippagePercent:f,recipient:g}=i();i((j,{name:b})=>{(b==="srcChainId"||b==="srcDenom")&&c("quantity","",{shouldTouch:!1,shouldDirty:!1})});const p=Qo(),x=p(l),S=p(d),N=Go()(g,d);_.useEffect(()=>{c("cosmosWalletName",void 0),c("sender",x)},[l,x,c]),_.useEffect(()=>{N||c("recipient",S)},[S,N,c]);const C=qt(l),T=qt(d),P=_.useMemo(()=>{if(!C.find(j=>j.denom===u))return`${u} is not available for bridge/swap on ${l}`;if(!T.find(j=>j.denom===h))return`${h} is not available for bridge/swap on ${d}`},[T,d,h,C,l,u]);_.useEffect(()=>{P||(localStorage.setItem(U.BRIDGE_SRC_CHAIN_ID,l),localStorage.setItem(U.BRIDGE_SRC_DENOM,u),localStorage.setItem(U.BRIDGE_DST_CHAIN_ID,d),localStorage.setItem(U.BRIDGE_DST_DENOM,h),localStorage.setItem(U.BRIDGE_QUANTITY,m),localStorage.setItem(U.BRIDGE_SLIPPAGE_PERCENT,f))},[l,u,d,h,m,f,P]);const R=e[0].path==="/bridge",B=()=>t.jsxs(t.Fragment,{children:[t.jsx(ne,{error:!0,children:P}),t.jsx(ie,{children:R?t.jsx(J.White,{onClick:n,children:"Close"}):t.jsx(J.White,{onClick:()=>s(-1),children:"Go back"})})]}),{reminders:z}=Rt();return t.jsx(Oe,{title:"Bridge/Swap",backButton:R?"/":void 0,extra:t.jsxs(t.Fragment,{children:[t.jsx(J.Small,{onClick:()=>s("/bridge/history"),unpadded:!0,children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",width:"12",height:"12",children:[t.jsx("path",{d:"m0 9.818 1.414-1.414 L2 8.99 V8 a7 7 0 1 1 7 7 v-2 a5 5 0 1 0-5-5 v1.354 l.95-.95 1.414 1.414 L3.182 13 0 9.818 Z"}),t.jsx("path",{d:"M9 5.5 H7.5 v3.75 h3.75 v-1.5 H9 V5.5 Z"})]})}),t.jsx(Ho,{offset:0,disabled:z.length===0,children:t.jsx(J.Small,{onClick:()=>s("/op/withdrawals"),disabled:!r,children:t.jsx("span",{children:"Withdrawal status"})})})]}),children:P?B():t.jsx(ue.FormProvider,{...a,children:t.jsx(ye,{children:t.jsx(Ph,{})})})})},Bh="_button_1crvp_1",Mh="_checkbox_1crvp_11",Fh="_checked_1crvp_25",ms={button:Bh,checkbox:Mh,checked:Fh},Oh=({checked:e,onClick:s,label:n,className:r})=>t.jsxs("button",{type:"button",className:D(ms.button,r),onClick:s,children:[t.jsx("div",{className:D(ms.checkbox,{[ms.checked]:e}),children:e&&t.jsx(A.IconCheck,{size:12})}),t.jsx("span",{className:ms.label,children:n})]}),Uh="_button_aoxv2_1",Lh={button:Uh},sa=({onClick:e,disabled:s})=>{const{ref:n,inView:r}=Aa.useInView();return _.useEffect(()=>{r&&e()},[r,e]),t.jsxs("button",{className:Lh.button,onClick:e,disabled:s,ref:n,children:[t.jsx("span",{children:"Load more"}),t.jsx(A.IconChevronDown,{size:12})]})};function na(e,s){return e.reduce((n,r)=>{const o=s(r);if(!o)return n;const a=o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),i=n[a]||[];return{...n,[a]:[...i,r]}},{})}const xs=({chainId:e,txHash:s})=>`${U.BRIDGE_HISTORY}:${e}:${s}`,Cs=100,Ir=10;function ra(){const[e,s]=Ie.useLocalStorage(U.BRIDGE_HISTORY,[]),n=_.useCallback((o,a)=>{localStorage.setItem(xs(o),JSON.stringify(a));for(const i of e.slice(Cs-1))localStorage.removeItem(xs(i));s((i=[])=>[o,...i.slice(0,Cs-1)])},[e,s]),r=_.useCallback(o=>{const a=localStorage.getItem(xs(o));return a?JSON.parse(a):null},[]);return{history:e,addHistoryItem:n,getHistoryDetails:r}}function oa(e){return Ie.useLocalStorage(xs(e),null)}async function zh(e,s){const n=L.create({prefixUrl:s}),r=`cosmos/auth/v1beta1/account_info/${e}`;for(let o=1;o<=24;o++)try{return await n.get(r).json()}catch{await new Promise(a=>setTimeout(a,5e3))}throw new Error(`Timeout: ${e} not found`)}async function An(e,s){const{chain_type:n,chain_id:r,chain_name:o,evm_fee_asset:a,rpc:i}=s;if(n!=="evm")throw new Error(`Chain is not an EVM chain: ${o}`);try{await e.send("wallet_switchEthereumChain",[{chainId:`0x${Number(r).toString(16)}`}])}catch(c){if(w.path(["error","code"],c)!==4902)throw c;if(!a)throw new Error(`Fee asset is not defined for chain: ${o}`);await e.send("wallet_addEthereumChain",[{chainId:`0x${Number(r).toString(16)}`,chainName:o,nativeCurrency:a,rpcUrls:[i]}]),await e.send("wallet_switchEthereumChain",[{chainId:`0x${Number(r).toString(16)}`}])}}function Bt(){return jt()}function Kh(e){const s=he(),{showNotification:n,updateNotification:r,hideNotification:o}=Hn(),{addHistoryItem:a}=ra(),i=qs(),{route:c,values:l}=Bt(),{srcChainId:d,sender:u,recipient:h,cosmosWalletName:m}=l,f=fo(),{requestTxSync:g,waitForTxConfirmation:p}=xe(),{find:x}=Ks(),S=Xt(),I=Ds(),N=Be(d),C=Jt(N),T=Ao(d),P=$.useQueryClient(),{registryUrl:R}=X(),B=Te(),{addReminder:z}=Rt(),j=Ye();return $.useMutation({mutationFn:async()=>{try{if("cosmos_tx"in e){if(!e.cosmos_tx.msgs)throw new Error("Invalid transaction data");const b=e.cosmos_tx.msgs.map(({msg_type_url:me,msg:ge})=>{if(!(me&&ge))throw new Error("Invalid transaction data");return I.fromAmino({type:Ht.aminoConverters[me].aminoType,value:JSON.parse(ge)})});if(C==="initia"){const{srcDenom:me,quantity:ge}=l,{decimals:Ct}=T(me),it=await g({messages:b,chainId:d,internal:1,spendCoins:[{denom:me,amount:v.toBaseUnit(ge,{decimals:Ct})}]}),Mt=p({txHash:it,chainId:d});return{txHash:it,wait:Mt}}const y=x(m)?.getProvider();if(!y)throw new Error("Wallet not connected");const k=y.getOfflineSignerOnlyAmino(d),q=await Pe.SigningStargateClient.connectWithSigner(N.rpc,k,{registry:S,aminoTypes:I}),M=await q.getAllBalances(u),E=N.fee_assets.find(me=>M.some(ge=>ge.denom===me.denom&&F(ge.amount).gt(0)));if(!E){const ge=["Insufficient balance for fees.",`Available fee assets: ${N.fee_assets.map(Ct=>T(Ct.denom).symbol).join(", ")}`,"(note: asset symbols may refer to different tokens across chains)"].join(" ");throw new Error(ge)}const{denom:G,gas_price:te}=E;if(!te)throw new Error(`Gas price not found for ${G}`);const O=await q.simulate(u,b,""),Z=Pe.GasPrice.fromString(te.average+G),Ue=Pe.calculateFee(Math.ceil(O*Gt),Z),Je=await q.signAndBroadcastSync(u,b,Ue),at=Co({txHash:Je,client:q});return{txHash:Je,wait:at}}if("evm_tx"in e){const{chain_id:b,to:y,value:k,data:q}=e.evm_tx,M=await f(),E=await M.getSigner();await An(M,N);const G=await E.sendTransaction({chainId:b,to:y,value:k,data:`0x${q}`});return{txHash:G.hash,wait:G.wait()}}throw new Error("Unlisted chain type")}catch(b){throw await He(b)}},onSuccess:async({txHash:b,wait:y})=>{localStorage.removeItem(U.BRIDGE_QUANTITY),s(-1),n({type:"loading",title:"Transaction is pending..."});try{await y;const k=Vn(c)==="OP Bridge withdrawal",q=k?{success:!0,error:null}:await Vh(j,b,d);if(!q.success&&q.error){const O=q.error instanceof Error?q.error.message:String(q.error);n({type:"error",title:"Transaction tracking failed",description:`Failed to track transaction: ${O}. The transaction may still be processing.`,autoHide:!0})}const M=q.success,G=Qh({txHash:b,srcChainId:d,route:c,values:l,recipient:h},M);a(G.tx,G.details),r(Hh(o));const te=mn(l,b);if(i("Bridge Transaction Success",te),k){const O=Gh(G.tx,c,h);z(G.tx,O)}}catch(k){const q=k instanceof Error?k.message:String(k);r({type:"error",title:"Transaction not confirmed",description:q});const M={...mn(l,b),error:q};i("Bridge Confirmation Failed",M)}finally{P.invalidateQueries({queryKey:Re.balances(d,u).queryKey})}},onError:async b=>{const y=C==="initia"?await At(b,B(d),R):b;n({type:"error",title:"Transaction failed",description:y.message});const k=mn(l);i("Bridge Transaction Failed",{...k,error:y.message})}})}function Wh(){const e=Ye(),s=ee(),n=Ps(),{route:r,values:o}=Bt(),a=vt();return $.useMutation({mutationFn:async()=>{try{const{chain_id:i,hook:c}=await e.post("op-hook",{json:{source_address:s,source_asset_chain_id:r.source_asset_chain_id,source_asset_denom:r.source_asset_denom,dest_address:v.InitiaAddress(o.recipient).bech32,dest_asset_chain_id:r.dest_asset_chain_id,dest_asset_denom:r.dest_asset_denom}}).json();await zh(s,a(r.dest_asset_chain_id).rest);const l=c.map(({msg_type_url:h,msg:m})=>Ht.aminoTypes.fromAmino({type:Ht.aminoConverters[h].aminoType,value:JSON.parse(m)})),d=await n(i,s,l,{amount:[],gas:"1"},"",{incrementSequence:i===o.srcChainId?2:0}),u=st.Tx.fromPartial({body:st.TxBody.decode(d.bodyBytes),authInfo:st.AuthInfo.decode(d.authInfoBytes),signatures:d.signatures});return{signer:s,hook:V.toBase64(st.Tx.encode(u).finish())}}catch(i){throw await He(i)}}})}function Hh(e){return{type:"info",title:"Transaction submitted",description:_.createElement(_.Fragment,null,"Check ",_.createElement(Et,{to:"/bridge/history",onClick:e},"the activity page")," for transaction status"),autoHide:!0}}function mn(e,s){return{quantity:e.quantity,srcChainId:e.srcChainId,srcDenom:e.srcDenom,dstChainId:e.dstChainId,dstDenom:e.dstDenom,txHash:s}}function Qh(e,s){const{txHash:n,srcChainId:r,route:o,values:a}=e,i={chainId:r,txHash:n},c=Vn(o)==="OP Bridge withdrawal";return{tx:i,details:{...i,timestamp:Date.now(),route:o,values:a,state:c?"success":void 0,tracked:s},isOpWithdraw:c}}function Gh(e,s,n){return{...e,recipient:v.InitiaAddress(n).bech32,claimableAt:Date.now()+s.estimated_route_duration_seconds*1e3,amount:s.amount_out,denom:s.dest_asset_denom}}async function Vh(e,s,n){for(let a=0;a<=30;a++)try{return await e.post("v2/tx/track",{json:{tx_hash:s,chain_id:n}}).json(),{success:!0,error:null}}catch(i){if(a===30)return{success:!1,error:await He(i)};await new Promise(c=>setTimeout(c,1e3))}return{success:!1,error:new Error("Maximum retries exceeded")}}function Yh(e){const{chainId:s,txHash:n,tracked:r}=e,o=Ye();return $.useQuery({queryKey:Re.txTrack(s,n).queryKey,queryFn:async()=>{try{return await o.post("v2/tx/track",{json:{tx_hash:n,chain_id:s}}).json()}catch(a){throw await He(a)}},select:({tx_hash:a})=>a,retry:6,retryDelay:5e3,staleTime:Q.INFINITY,enabled:!r})}function Jh(e){const{timestamp:s,chainId:n,txHash:r,tracked:o,state:a}=e,i=Ye();return $.useQuery({queryKey:Re.txStatus(n,r).queryKey,queryFn:()=>i.get("v2/tx/status",{searchParams:{tx_hash:r,chain_id:n}}).json(),enabled:!!r&&o&&!a,refetchInterval:({state:{data:c}})=>{if(!c)return!1;const{status:l}=c;if(l==="STATE_COMPLETED")return!1;const d=s+e.route.estimated_route_duration_seconds*1e3,u=Date.now(),h=Math.floor((d-u)/1e3);return h<=0?1e3:h<=300?5e3:60*1e3},staleTime:Q.INFINITY})}var ys=(e=>(e.OP_WITHDRAW="OP Bridge withdrawal",e.SKIP="Skip",e))(ys||{});function Vn(e){const{operations:s,dest_asset_denom:n}=e;return w.has("op_init_transfer",w.head(s))&&n==="uinit"?"OP Bridge withdrawal":"Skip"}const Zh="_success_t4dfk_1",Xh="_error_t4dfk_5",Nr={success:Zh,error:Xh},em=({tx:e})=>{const[s,n]=oa(e);if(!s)throw new Error("Bridge history details not found");const{data:r}=Jh(s),o=s.state??tm(r);switch(_.useEffect(()=>{o!=="loading"&&n(a=>{if(!a)throw new Error("Bridge history details not found");return{...a,tracked:!0,state:o}})},[n,o]),o){case"error":return t.jsx("div",{className:Nr.error,children:t.jsx(A.IconCloseCircleFilled,{size:14})});case"success":return t.jsx("div",{className:Nr.success,children:t.jsx(A.IconCheckCircleFilled,{size:14})});default:return t.jsx(wt,{size:14})}};function tm(e){if(!e)return"loading";switch(e.state){case"STATE_ABANDONED":case"STATE_COMPLETED_ERROR":case"STATE_PENDING_ERROR":return"error";case"STATE_COMPLETED_SUCCESS":return"success";default:return"loading"}}const sm="_link_104m3_1",nm="_header_104m3_23",rm="_title_104m3_31",om="_date_104m3_37",am="_explorer_104m3_41",im="_fees_104m3_57",cm="_label_104m3_65",lm="_content_104m3_69",dm="_route_104m3_75",um="_row_104m3_80",hm="_asset_104m3_86",mm="_amount_104m3_94",fm="_chain_104m3_99",_m="_account_104m3_108",gm="_arrow_104m3_115",ce={link:sm,header:nm,title:rm,date:om,explorer:am,fees:im,label:cm,content:lm,route:dm,row:um,asset:hm,amount:mm,chain:fm,account:_m,arrow:gm},pm=({tx:e})=>{const[s,n]=oa(e);if(!s)throw new Error("Bridge history details not found");const{chainId:r,txHash:o,route:a,values:i,timestamp:c,tracked:l}=s,{data:d}=Yh(s),{address:u="",connector:h}=de.useAccount(),{find:m}=Ks();_.useEffect(()=>{d&&n(M=>{if(!M)throw new Error("Bridge history details not found");return{...M,tracked:!0}})},[n,d]);const{amount_in:f,amount_out:g,source_asset_chain_id:p,source_asset_denom:x,dest_asset_chain_id:S,dest_asset_denom:I,estimated_fees:N=[]}=a,C=Be(p),T=Be(S),P=Qe(x,p),R=Qe(I,S),B=(M,E)=>E?t.jsx(Y,{src:E,width:12,height:12}):v.InitiaAddress.equals(M,u)?t.jsx(Y,{src:h?.icon,width:12,height:12}):t.jsx(A.IconWallet,{size:12}),z=(M,{symbol:E,decimals:G,logo_uri:te},{chain_name:O,pretty_name:Z,...Ue},Je,at)=>t.jsxs("div",{className:ce.row,children:[t.jsx(Ws,{assetLogoUrl:te,chainLogoUrl:Ue.logo_uri??void 0}),t.jsxs("div",{children:[t.jsxs("div",{className:ce.asset,children:[t.jsx("span",{className:ce.amount,children:v.formatAmount(M,{decimals:G})}),t.jsx("span",{children:E})]}),t.jsxs("div",{className:ce.chain,children:[t.jsxs("span",{children:["on ",Z||O]}),t.jsxs("div",{className:ce.account,children:[at,t.jsx("span",{className:"monospace",children:v.truncate(Je)})]})]})]})]}),j=Vn(a),b=_.useMemo(()=>{switch(j){case ys.SKIP:return"Skip Explorer";case ys.OP_WITHDRAW:return"Initia Scan"}},[j]),y=t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:ce.header,children:[t.jsxs("div",{className:ce.title,children:[l?t.jsx(em,{tx:e}):t.jsx(wt,{size:14}),t.jsx("div",{className:ce.date,children:ke.format(new Date(c),"h:mm a")})]}),t.jsxs("div",{className:ce.explorer,children:[t.jsx("span",{children:b}),t.jsx(A.IconExternalLink,{size:12})]})]}),t.jsxs("div",{className:ce.route,children:[z(f,P,C,i.sender,B(i.sender,m(i.cosmosWalletName)?.image)),t.jsx("div",{className:ce.arrow,children:t.jsx(A.IconArrowDown,{size:12})}),z(g,R,T,i.recipient,B(i.recipient))]}),N.length>0&&t.jsxs("div",{className:ce.fees,children:[t.jsx("span",{className:ce.label,children:"Fees"}),t.jsx("span",{className:ce.content,children:Xo(N)})]})]});if(j===ys.OP_WITHDRAW)return t.jsx(zs,{chainId:r,txHash:o,className:ce.link,children:y});const k=new URLSearchParams({tx_hash:o,chain_id:r}),q=new URL(`?${k.toString()}`,"https://explorer.skip.build");return t.jsx("a",{href:q.toString(),className:ce.link,target:"_blank",children:y})},xm="_history_13u9z_1",ym="_header_13u9z_5",jm="_checkbox_13u9z_9",vm="_groups_13u9z_13",wm="_dateGroup_13u9z_21",bm="_dateHeader_13u9z_26",Cm="_list_13u9z_32",ht={history:xm,header:ym,checkbox:jm,groups:vm,dateGroup:wm,dateHeader:bm,list:Cm},Im=()=>{const{initiaAddress:e,hexAddress:s}=xe(),{history:n,getHistoryDetails:r}=ra(),o=n.filter(f=>r(f)),a=o.filter(f=>{const g=r(f);if(!g)return!1;const{values:p}=g,{sender:x,recipient:S}=p;return[x,S].some(I=>[e,s].includes(I))}),[i,c]=_.useState(1),[l,d]=Ie.useToggle(!a.length),u=l?o:a,h=u.slice(0,i*Ir),m=_.useMemo(()=>na(h,f=>{const g=r(f);if(g)return new Date(g.timestamp)}),[h,r]);return t.jsx(Oe,{title:"Bridge/Swap activity",children:t.jsxs("div",{className:ht.history,children:[o.length>0&&o.length!==a.length&&t.jsx("header",{className:ht.header,children:t.jsx(Oh,{checked:l,onClick:d,label:"Show all transactions stored in this browser",className:ht.checkbox})}),u.length===0?t.jsx(ne,{children:"No bridge/swap activity"}):t.jsx("div",{className:ht.groups,children:Object.entries(m).map(([f,g])=>t.jsxs("div",{className:ht.dateGroup,children:[t.jsx("div",{className:ht.dateHeader,children:f}),t.jsx("div",{className:ht.list,children:g.map(p=>t.jsx(ye,{children:t.jsx(pm,{tx:p})},p.txHash))})]},f))}),u.length>i*Ir?t.jsx(sa,{onClick:()=>c(f=>f+1)}):n.length>=Cs&&t.jsxs(ne,{children:["Only the latest ",Cs," items are stored. Older entries will be removed automatically."]})]})})},Nm=({tx:e})=>{const{mutate:s,isPending:n}=Kh(e);return t.jsx(ie,{children:t.jsx(J.White,{onClick:()=>s(),loading:n&&"Signing transaction...",children:"Confirm"})})},Sm="_content_1hzj2_1",Am="_info_1hzj2_6",km="_arrow_1hzj2_11",$m="_divider_1hzj2_19",Tm="_type_1hzj2_27",Em="_asset_1hzj2_47",qm="_amount_1hzj2_55",Dm="_lower_1hzj2_60",Pm="_chain_1hzj2_66",Rm="_address_1hzj2_72",ve={content:Sm,info:Am,arrow:km,divider:$m,type:Tm,asset:Em,amount:qm,lower:Dm,chain:Pm,address:Rm},aa=e=>{const{source:s,label:n,amount:r,denom:o,chainId:a,address:i,walletIcon:c}=e,{symbol:l=v.truncate(o),decimals:d=0,logo_uri:u=Rn}=e,{chain_name:h,pretty_name:m,...f}=Be(a);return t.jsxs("div",{children:[!s&&t.jsxs("div",{className:ve.arrow,children:[t.jsx("div",{className:ve.divider}),n?t.jsx(rs,{label:n,children:t.jsx("button",{className:ve.type,children:t.jsx(A.IconArrowDown,{size:12})})}):t.jsx("span",{className:ve.type,children:t.jsx(A.IconArrowDown,{size:12})}),t.jsx("div",{className:ve.divider})]}),t.jsxs("div",{className:ve.content,children:[t.jsx(Ws,{assetLogoUrl:u,chainLogoUrl:f.logo_uri??void 0}),t.jsxs("div",{className:ve.info,children:[t.jsxs("div",{className:ve.asset,children:[t.jsx("span",{className:ve.amount,children:v.formatAmount(r,{decimals:d})}),t.jsx("span",{children:l})]}),t.jsxs("div",{className:ve.lower,children:[t.jsxs("div",{className:ve.chain,children:["on ",m||h]}),i&&t.jsx(vs,{value:i,children:({copy:g,copied:p})=>t.jsxs("button",{className:ve.address,onClick:g,children:[c,p?t.jsx("span",{children:"Copied!"}):t.jsx("span",{className:"monospace",children:v.truncate(i)})]})})]})]})]})]})},Tt=e=>{const s=Qe(e.denom,e.chainId);return t.jsx(aa,{...e,...s})};Tt.Placeholder=aa;const Bm="_root_1hbar_1",Mm="_flexEnd_1hbar_6",Fm="_toggle_1hbar_11",Om="_route_1hbar_36",Um="_content_1hbar_43",zt={root:Bm,flexEnd:Mm,toggle:Fm,route:Om,content:Um};function Lm(e){const s=({name:n})=>n==="initia-dex"?"Initia DEX":Ns.capitalCase(w.head(n?.split("-")??[])??"");if("transfer"in e)return{label:"Bridge via IBC",...e,...e.transfer};if("bank_send"in e)return{label:"Send",...e,...e.bank_send};if("swap"in e){const n=e.swap?.swap_venues?.map(s).join(", ");return{label:n?`Swap on ${n}`:"Swap",...e,...e.swap}}if("axelar_transfer"in e)return{label:"Bridge via Axelar",...e,...e.axelar_transfer};if("cctp_transfer"in e)return{label:"Bridge via CCTP",...e,...e.cctp_transfer};if("hyperlane_transfer"in e)return{label:"Bridge via Hyperlane",...e,...e.hyperlane_transfer};if("evm_swap"in e){const n=e.evm_swap?.swap_venues?.map(s).join(", ");return{label:n?`Swap on ${n}`:"Swap",...e,...e.evm_swap}}if("op_init_transfer"in e)return{label:"Bridge via OP Bridge",...e,...e.op_init_transfer};if("go_fast_transfer"in e)return{label:"Bridge via Go Fast",...e,...e.go_fast_transfer};if("eureka_transfer"in e)return{label:"Bridge via Eureka",...e,...e.eureka_transfer};if("stargate_transfer"in e)return{label:"Bridge via Stargate",...e,...e.stargate_transfer};if("layer_zero_transfer"in e)return{label:"Bridge via LayerZero",...e,...e.layer_zero_transfer};throw new Error("Unknown operation type")}const zm=({addressList:e})=>{const{values:s,route:n}=Bt(),{source_asset_denom:r,source_asset_chain_id:o,amount_in:a,operations:i}=n,c=w.zipObj(n.required_chain_addresses,e),{find:l}=Ks(),{connector:d,address:u=""}=de.useAccount(),[h,m]=Ie.useToggle(!1),f=i.length>1,g=t.jsx(Y,{src:s.cosmosWalletName?l(s.cosmosWalletName)?.image:d?.icon,width:12,height:12}),p={amount:a,denom:r,chainId:o,address:s.sender,walletIcon:g},x=T=>v.InitiaAddress.equals(T,u)?g:t.jsx(A.IconWallet,{size:11}),S=T=>{const{label:P,amount_out:R,denom:B,denom_out:z=B,chain_id:j,from_chain_id:b,to_chain_id:y=j??b}=T,k=c[y];return{label:f&&!h?void 0:P,amount:R,denom:z,chainId:y,address:k,walletIcon:x(k)}},I=i.map(Lm).map(S),N=I.slice(0,-1),C=I[I.length-1];return t.jsxs(se.Collapsible.Root,{className:zt.root,open:h,onOpenChange:m,children:[f&&t.jsx("div",{className:zt.flexEnd,children:t.jsx(se.Collapsible.Trigger,{className:zt.toggle,children:h?t.jsxs(t.Fragment,{children:[t.jsx(A.IconMinus,{size:12}),t.jsx("span",{children:"Hide details"})]}):t.jsxs(t.Fragment,{children:[t.jsx(A.IconList,{size:12}),t.jsx("span",{children:"Show details"})]})})}),t.jsxs("div",{className:zt.route,children:[t.jsx(Tt,{...p,source:!0}),t.jsx(se.Collapsible.Content,{className:zt.content,children:N.map((T,P)=>t.jsx(ye,{suspenseFallback:t.jsx(Tt.Placeholder,{...T}),errorBoundaryProps:{fallback:t.jsx(Tt.Placeholder,{...T})},children:t.jsx(Tt,{...T})},P))}),t.jsx(Tt,{...C})]})]})},kn=({error:e})=>{const s=he();return t.jsx(ie,{extra:t.jsx(oe,{level:"error",children:e.message}),children:t.jsx(J.White,{onClick:()=>s("/bridge"),children:"Home"})})},Km=({children:e})=>{const s=Bt(),{route:n,values:r}=s,{required_chain_addresses:o}=n,{srcChainId:a,dstChainId:i,sender:c,recipient:l}=r,{initiaAddress:d,hexAddress:u}=xe(),h=es(),m=vt(),f=ss(),g=m(a),p=f(g),x=o.slice(0,-1).some(R=>{const B=m(R);return f(B)==="cosmos"})&&p!=="cosmos",[S,I]=_.useState(void 0),[N,C]=_.useState(!1),[T,P]=_.useState(null);if(_.useEffect(()=>{(async()=>{try{if(!x)return;if(!h)throw new Error("Wallet not connected");C(!0),P(null);const[{pubkey:B}]=await h.getAccounts();I(B)}catch(B){P(await He(B))}finally{C(!1)}})()},[x,h]),T)return t.jsx(kn,{error:T});if(N)return t.jsx(ie,{children:t.jsx(J.White,{loading:N&&"Generating intermediary addresses..."})});if(!x||S){const R=o.map((B,z)=>{if(z===o.length-1){const q=m(i);return f(q)==="initia"?v.InitiaAddress(l).bech32:l}const j=m(B),b=f(j),y=m(a),k=f(y);switch(b){case"initia":return d;case"evm":return u;case"cosmos":{if(k==="cosmos")return V.toBech32(j.bech32_prefix,V.fromBech32(c).data);if(!S)throw new Error("Pubkey not found");return Qt.pubkeyToAddress(Qt.encodeSecp256k1Pubkey(S),j.bech32_prefix)}default:throw new Error("Unlisted chain type")}});return e(R)}return null},Wm=({tx:e,children:s})=>{const n=fo(),r=vt(),{data:o,isLoading:a}=$.useQuery({queryKey:["erc20-approvals-needed",e],queryFn:async()=>{if(!("evm_tx"in e))return[];if(!e.evm_tx.required_erc20_approvals)return[];const{chain_id:u,signer_address:h}=e.evm_tx,m=await n();await An(m,r(u));const f=["function allowance(address owner, address spender) view returns (uint256)"];return(await Promise.all(e.evm_tx.required_erc20_approvals.map(async p=>{const{token_contract:x,spender:S}=p,N=await new We.ethers.Contract(x,f,m).allowance(h,S);return{approval:p,currentAllowance:BigInt(N.toString())}}))).filter(({approval:p,currentAllowance:x})=>x<BigInt(p.amount)).map(({approval:p})=>p)},enabled:!!e&&"evm_tx"in e&&!!e.evm_tx.required_erc20_approvals}),{mutate:i,data:c,isPending:l,error:d}=$.useMutation({mutationFn:async()=>{try{if(!("evm_tx"in e))throw new Error("Transaction is not EVM");if(!o||o.length===0)throw new Error("No approvals needed");const{chain_id:u}=e.evm_tx,h=await n(),m=await h.getSigner();await An(h,r(u));for(const f of o){const{token_contract:g,spender:p,amount:x}=f,S=["function approve(address spender, uint256 amount) external returns (bool)"];await(await new We.ethers.Contract(g,S,m).approve(p,x)).wait()}return!0}catch(u){throw await He(u)}}});return a?t.jsx(ie,{children:t.jsx(J.White,{loading:"Checking approvals..."})}):o&&o.length>0&&!c?t.jsx(ie,{extra:t.jsx(oe,{level:"error",children:d?.message}),children:t.jsx(J.White,{onClick:()=>i(),loading:l&&"Approving tokens...",children:"Approve tokens"})}):s},Hm=({addressList:e,signedOpHook:s,children:n})=>{const r=Ye(),{route:o,values:a}=Bt(),[i,c]=_.useState(void 0),[l,d]=_.useState(!1),[u,h]=_.useState(null);return _.useEffect(()=>{(async()=>{try{if(o.required_op_hook&&!s)throw new Error("Op hook is required");d(!0),h(null);const f={address_list:e,amount_in:o.amount_in,amount_out:o.amount_out,source_asset_chain_id:o.source_asset_chain_id,source_asset_denom:o.source_asset_denom,dest_asset_chain_id:o.dest_asset_chain_id,dest_asset_denom:o.dest_asset_denom,slippage_tolerance_percent:a.slippagePercent,operations:o.operations,signed_op_hook:s},{txs:g}=await r.post("v2/fungible/msgs",{json:f}).json();if(!g||g.length===0)throw new Error("No transaction data found");const[p]=g;c(p)}catch(f){h(f)}finally{d(!1)}})()},[o,a,e,s,r]),u?t.jsx(kn,{error:u}):l?t.jsx(ie,{children:t.jsx(J.White,{loading:l&&"Fetching messages..."})}):i?n(i):t.jsx(kn,{error:new Error("Failed to fetch messages")})},Qm=({children:e})=>{const{route:s}=Bt(),n=Wh();return s.required_op_hook&&!n.data?t.jsx(ie,{extra:t.jsx(oe,{level:"error",children:n.error?.message}),children:t.jsx(J.White,{onClick:()=>n.mutate(),loading:n.isPending&&"Awaiting signature...",children:"Authorize conversion"})}):e(n.data)},Gm=()=>t.jsx(Oe,{title:"Route preview",children:t.jsx(Km,{children:e=>t.jsxs(t.Fragment,{children:[t.jsx(zm,{addressList:e}),t.jsx(Qm,{children:s=>t.jsx(Hm,{addressList:e,signedOpHook:s,children:n=>t.jsx(Wm,{tx:n,children:t.jsx(Nm,{tx:n})})})})]})})}),ia=_.createContext(null);function Qs(){return _.useContext(ia)}const bt=Ne.createQueryKeys("interwovenkit:op",{bridge:e=>[e],withdrawals:(e,s)=>[e,s],latestOutput:e=>[e],output:(e,s)=>[e,s],outputResponse:(e,s)=>[e,s],withdrawalClaimed:(e,s)=>[e,s]});function Gs(){const{restUrl:e}=_e();return _.useMemo(()=>L.create({prefixUrl:e}),[e])}function Vm(e){const s=Gs(),{data:n}=$.useSuspenseQuery({queryKey:bt.bridge(e).queryKey,queryFn:()=>s.get(`opinit/ophost/v1/bridges/${e}`).json(),staleTime:Q.INFINITY});return n}const Sr=20;function Ym(e){const s=ee();return $.useSuspenseInfiniteQuery({queryKey:bt.withdrawals(e,s).queryKey,queryFn:async({pageParam:n})=>{if(!s)return[];const r={limit:Sr,offset:n,order:"desc"},{withdrawals:o}=await L.create({prefixUrl:e}).get(`withdrawals/${s}`,{searchParams:r}).json();return o},getNextPageParam:n=>{const r=w.last(n)?.sequence;return n.length<Sr||!r||r<=1?null:r-1},initialPageParam:0,staleTime:Q.SECOND})}function Jm(e){const s=Gs(),{data:n}=$.useSuspenseQuery({queryKey:bt.latestOutput(e).queryKey,queryFn:()=>s.get(`opinit/ophost/v1/bridges/${e}/outputs`,{searchParams:{"pagination.reverse":!0,"pagination.limit":1}}).json(),select:({output_proposals:r})=>{const[o]=r;return o||null},staleTime:Q.SECOND});return n}function Zm({bridge_id:e,output_index:s}){const n=Gs(),{data:r}=$.useSuspenseQuery({queryKey:bt.output(e,s).queryKey,queryFn:async()=>{try{return await n.get(`opinit/ophost/v1/bridges/${e}/outputs/${s}`).json()}catch{return null}},staleTime:Q.SECOND});return r}function Xm({bridge_id:e,sequence:s}){const r=ae().find(({metadata:l})=>l?.op_bridge_id===e.toString())?.chain_id;if(!r)throw new Error(`Chain not found for bridge_id: ${e}`);const a=Te()(r);if(!a)throw new Error(`Chain not found: ${r}`);const i=a.metadata?.executor_uri;if(!i)throw new Error(`Executor URL not found: ${r}`);const{data:c}=$.useSuspenseQuery({queryKey:bt.outputResponse(i,s).queryKey,queryFn:()=>L.create({prefixUrl:i}).get(`withdrawal/${s}`).json(),staleTime:Q.SECOND});return c}function ca(e,s){const{bridge_id:n}=e,r=Gs(),{data:o}=$.useSuspenseQuery({queryKey:bt.withdrawalClaimed(n,s).queryKey,queryFn:()=>r.get(`opinit/ophost/v1/bridges/${n}/withdrawals/claimed/by_hash`,{searchParams:{withdrawal_hash:s}}).json(),select:({claimed:a})=>a,staleTime:({state:{data:a}})=>a?.claimed?1/0:Q.SECOND});return o}function Kt(e){return ka.sha3_256.create().update(e).digest()}function fn(e,s){const n=new ArrayBuffer(s);return new DataView(n).setBigUint64(0,BigInt(e),!1),new Uint8Array(n)}function la(e){const{bridge_id:s,sequence:n,amount:r,from:o,to:a}=e,i=fn(s.toString(),8),c=fn(n.toString(),8),l=fn(r.amount,8),d=_t.concatBytes(i,c,Kt(_t.utf8ToBytes(o)),Kt(_t.utf8ToBytes(a)),Kt(_t.utf8ToBytes(r.denom)),l);return Kt(Kt(d))}const ef="_button_17r1o_1",tf="_claimed_17r1o_24",Ar={button:ef,claimed:tf},sf=()=>{const{withdrawalTx:e}=Qs(),{bridge_id:s,sequence:n,amount:r,output_index:o,withdrawal_proofs:a,storage_root:i,from:c,to:l,version:d}=e,u=_e(),h=ee(),{requestTxSync:m,waitForTxConfirmation:f}=xe(),g=Xm(e),p=V.toBase64(la(e)),x=ca(e,p),S=$.useQueryClient(),{mutate:I,isPending:N}=$.useMutation({mutationFn:async()=>{if(!g)throw new Error("Output not found");const{last_block_hash:C}=g;return m({chainId:u.chain_id,messages:[{typeUrl:"/opinit.ophost.v1.MsgFinalizeTokenWithdrawal",value:{sender:h,bridgeId:BigInt(s),outputIndex:BigInt(o),withdrawalProofs:a.map(V.fromBase64),from:c,to:l,sequence:BigInt(n),amount:r,version:V.fromBase64(d),storageRoot:V.fromBase64(i),lastBlockHash:V.fromBase64(C)}}],internal:!0})},onSuccess:async C=>{await f({chainId:u.chain_id,txHash:C}),S.invalidateQueries({queryKey:bt.withdrawalClaimed(s,p).queryKey})}});return x?t.jsxs("div",{className:Ar.claimed,children:[t.jsx(A.IconCheckCircleFilled,{size:14}),t.jsx("span",{children:"Claimed"})]}):t.jsx("button",{className:Ar.button,onClick:()=>I(),disabled:N,children:"Claim"})},nf=({children:e})=>{const{withdrawalTx:s}=Qs(),n=Vm(s.bridge_id),r=Zm(s),o=_.useMemo(()=>{if(!r)return null;const{bridge_config:a}=n,{output_proposal:i}=r;return ke.addSeconds(new Date(i.l1_block_time),parseFloat(a.finalization_period))},[n,r]);return e(o)},da=1e3,rf=60,of=60,af=24,$n=da*rf,Tn=$n*of,kr=Tn*af,cf=({date:e})=>{const s=_.useCallback(()=>{const d=new Date().getTime(),h=e.getTime()-d;if(h<=0)return{days:0,hours:0,minutes:0,seconds:0};const m=Math.floor(h/kr),f=Math.floor(h%kr/Tn),g=Math.floor(h%Tn/$n),p=Math.floor(h%$n/da);return{days:m,hours:f,minutes:g,seconds:p}},[e]),[n,r]=_.useState(s());_.useEffect(()=>{const d=window.setInterval(()=>{r(s())},1e3);return()=>window.clearInterval(d)},[s,e]);const o=d=>d.toString().padStart(2,"0"),{days:a,hours:i,minutes:c,seconds:l}=n;return t.jsx(rs,{label:e.toLocaleString(),children:t.jsxs("span",{className:"monospace",children:[a,"d ",o(i),"h ",o(c),"m ",o(l),"s"]})})},lf="_container_1lz3w_1",df="_title_1lz3w_5",$r={container:lf,title:df},uf=({date:e})=>t.jsxs("div",{className:$r.container,children:[t.jsx("div",{className:$r.title,children:"Claimable in"}),t.jsx(cf,{date:e})]}),hf="_container_1oldz_1",mf="_icon_1oldz_7",Tr={container:hf,icon:mf},ff="Withdrawal will begin within an hour",Er=()=>{const e=Ls();return t.jsxs("div",{className:Tr.container,children:[t.jsx("span",{children:"In progress"}),!e&&t.jsx(rs,{label:ff,children:t.jsx("span",{className:Tr.icon,children:t.jsx(A.IconInfoFilled,{size:12})})})]})},_f=({children:e})=>{const{withdrawalTx:s}=Qs(),n=Jm(s.bridge_id),r=s.output_index>Number(n?.output_index);return e(r)},gf=({date:e,children:s})=>{const{chainId:n,withdrawalTx:r}=Qs(),o=V.toBase64(la(r)),a=ca(r,o),{setReminder:i,removeReminder:c}=Rt();return _.useEffect(()=>{const l={chainId:n,txHash:r.tx_hash};a?c(l):i(l,{...l,recipient:r.to,claimableAt:e.getTime(),amount:r.amount.amount,denom:r.amount.denom,dismissed:ke.isPast(e.getTime())?!0:void 0})},[n,a,e,c,i,r]),s},pf=()=>t.jsx(_f,{children:e=>e?t.jsx(Er,{}):t.jsx(nf,{children:s=>s?t.jsx(gf,{date:s,children:ke.isFuture(s)?t.jsx(uf,{date:s}):t.jsx(sf,{})}):t.jsx(Er,{})})}),xf="_asset_6h8u2_1",yf="_info_6h8u2_7",jf="_symbol_6h8u2_11",_n={asset:xf,info:yf,symbol:jf},vf=({amount:e,denom:s})=>{const n=_e(),r=Zr(s,n),{symbol:o,logoUrl:a,decimals:i}=r;return t.jsxs("div",{className:_n.asset,children:[t.jsx(Y,{src:a,width:32,height:32,logo:!0}),t.jsxs("div",{className:_n.info,children:[t.jsx("span",{className:"monospace",children:v.formatAmount(e,{decimals:i})}),t.jsx("span",{className:_n.symbol,children:o})]})]})},wf="_item_km5w2_1",bf={item:wf},Cf=({chain:e})=>{const s=e.metadata?.executor_uri;if(!s)throw new Error("Executor URL is not defined");const{data:n,fetchNextPage:r,hasNextPage:o,isFetching:a}=Ym(s),i=_.useMemo(()=>n?.pages.flat()??[],[n]),{syncReminders:c}=Rt();return _.useEffect(()=>{const l=i.map(d=>({chainId:e.chainId,txHash:d.tx_hash}));c(l)},[e.chainId,i,c]),i.length?t.jsxs(t.Fragment,{children:[i.map(l=>{const{amount:d}=l;return t.jsxs("div",{className:bf.item,children:[t.jsx(vf,{...d}),t.jsx(ye,{suspenseFallback:null,children:t.jsx(ia.Provider,{value:{chainId:e.chainId,withdrawalTx:l},children:t.jsx(pf,{})})})]},l.sequence)}),o&&t.jsx(sa,{onClick:()=>r(),disabled:a})]}):t.jsx(ne,{children:"No withdrawals"})},If="_content_dj1qm_1",Nf="_title_dj1qm_5",qr={content:If,title:Nf},Sf=()=>{const{chainId:e}=jt(),s=ae(),n=Zt(),[r,o]=_.useState(e??(n.metadata?.is_l1?"":n.chainId)),a=Te(),{reminders:i}=Rt(),c=r?a(r):void 0;return t.jsxs(Oe,{title:"OP Bridge withdrawals",children:[t.jsx(xt,{chains:s.filter(({metadata:l})=>!l?.is_l1&&l?.op_denoms?.length),value:r,onSelect:o,getShowIndicator:l=>i.some(d=>d.chainId===l)}),t.jsx("div",{className:qr.content,children:c?t.jsxs(t.Fragment,{children:[t.jsx("h2",{className:qr.title,children:c.name}),t.jsx(ye,{children:t.jsx(Cf,{chain:c})},r)]}):t.jsx(oe,{level:"info",children:"Select a chain to display your OP Bridge withdrawals"})})]})},Af="_page_1g5uz_1",kf="_title_1g5uz_11",$f="_scrollable_1g5uz_18",Tf="_list_1g5uz_24",Ef="_item_1g5uz_35",qf="_name_1g5uz_59",Df="_dimmed_1g5uz_67",Pf="_recent_1g5uz_71",Rf="_installed_1g5uz_72",Se={page:Af,title:kf,scrollable:$f,list:Tf,item:Ef,name:qf,dimmed:Df,recent:Pf,installed:Rf},Bf=[{name:"Rabby",url:"https://rabby.io"},{name:"Phantom",url:"https://phantom.com"},{name:"Keplr",url:"https://keplr.app"},{name:"Leap",url:"https://leapwallet.io"}],Dr=({onSuccess:e})=>{const{connectors:s,connectAsync:n}=de.useConnect(),r=Ie.useReadLocalStorage("wagmi.recentConnectorId"),[o,a]=_.useState(null),{mutate:i,isPending:c}=$.useMutation({mutationFn:async l=>{a(l.id);try{await n({connector:l})}catch(d){throw await He(d)}},onSettled:()=>{a(null)},onSuccess:()=>{e?.()}});return t.jsxs("div",{className:Se.page,children:[t.jsx("h1",{className:Se.title,children:"Connect wallet"}),t.jsx(Fe,{className:Se.scrollable,children:t.jsxs("div",{className:Se.list,children:[s.toSorted(w.descend(l=>l.id===r)).map(l=>{const{name:d,icon:u,id:h}=l;return t.jsxs("button",{className:Se.item,onClick:()=>i(l),disabled:c,children:[t.jsx(Y,{src:u,width:24,height:24}),t.jsx("span",{className:Se.name,children:d}),o===h?t.jsx(wt,{size:16}):r===h?t.jsx("span",{className:Se.recent,children:"Recent"}):l.id===Ss.id?null:t.jsx("span",{className:Se.installed,children:"Installed"})]},h)}),Bf.filter(({name:l})=>!s.some(d=>d.name.includes(l))).map(({name:l,url:d})=>{const u=`https://assets.initia.xyz/images/wallets/${l}.webp`;return t.jsxs("a",{href:d,className:Se.item,target:"_blank",children:[t.jsx(Y,{src:u,width:24,height:24}),t.jsx("span",{className:D(Se.name,Se.dimmed),children:l}),t.jsx(A.IconExternalLink,{size:10})]},l)})]})})]})},Mf="_root_1lo0i_1",Ff="_address_1lo0i_9",Of="_copy_1lo0i_19",Uf="_labelWrapper_1lo0i_33",Lf="_labelCopy_1lo0i_43",zf="_labelCopied_1lo0i_47",Kf="_copied_1lo0i_55",Wf="_derived_1lo0i_65",Hf="_derivedLabel_1lo0i_79",Qf="_derivedAddress_1lo0i_83",Gf="_hexAddress_1lo0i_89",Vf="_derivedCopy_1lo0i_94",fe={root:Mf,address:Ff,copy:Of,labelWrapper:Uf,labelCopy:Lf,labelCopied:zf,copied:Kf,derived:Wf,derivedLabel:Hf,derivedAddress:Qf,hexAddress:Gf,derivedCopy:Vf},Yf=()=>{const e=_.useRef(null),s=_.useRef(null),{initiaAddress:n,hexAddress:r}=xe(),o=Eo("--gray-0");return _.useEffect(()=>{e.current&&(s.current?s.current.update({data:n}):(s.current=new $a({type:"canvas",width:400,height:400,margin:0,data:n,image:"https://registry.initia.xyz/images/INIT.png",qrOptions:{mode:"Byte",errorCorrectionLevel:"H"},imageOptions:{crossOrigin:"anonymous",margin:12},dotsOptions:{type:"dots",color:o},cornersSquareOptions:{type:"extra-rounded",color:o},cornersDotOptions:{type:"dot",color:o},backgroundOptions:{color:"transparent"}}),s.current.append(e.current)))},[n,o]),t.jsx(Oe,{title:"Receive",children:t.jsxs("div",{className:fe.root,children:[t.jsx("div",{ref:e,style:{width:200,height:200}}),t.jsx("span",{className:fe.address,children:n}),t.jsx(vs,{value:n,children:({copy:a,copied:i})=>t.jsxs("button",{className:D(fe.copy,{[fe.copied]:i}),onClick:a,children:[t.jsx(A.IconCopy,{size:12}),t.jsxs("div",{className:fe.labelWrapper,children:[t.jsx("span",{className:fe.labelCopy,children:"Copy address"}),t.jsx("span",{className:fe.labelCopied,children:"Copied!"})]})]})}),t.jsx(vs,{value:r,children:({copy:a,copied:i})=>t.jsxs("button",{className:D(fe.derived,{[fe.copied]:i}),onClick:a,children:[t.jsx("span",{className:fe.derivedLabel,children:"Derived from"}),t.jsxs("span",{className:fe.derivedAddress,children:[t.jsx("span",{className:fe.hexAddress,children:v.truncate(r)}),t.jsx(A.IconCopy,{size:12,className:fe.derivedCopy}),i&&t.jsx("span",{className:fe.copiedText,children:"Copied!"})]})]})})]})})};function Jf(){const e=ee(),s=ae();return $.useQueries({queries:s.map(n=>({queryKey:Yt.grants(n.chainId,e).queryKey,queryFn:async()=>{const{grants:r}=await L.create({prefixUrl:n.restUrl}).get(`cosmos/authz/v1beta1/grants/granter/${e}`).json();return{chainId:n.chainId,grants:r}},enabled:!!e,staleTime:Q.SECOND,retry:!1}))})}const Zf="_countdown_vfms8_1",Xf={countdown:Zf},e_=({expiration:e})=>{const s=()=>{const o=new Date,a=ke.differenceInSeconds(e,o),i=Math.floor(a/(1440*60)),c=Math.floor(a%(1440*60)/3600),l=Math.floor(a%3600/60),d=a%60,u=[];return i>0&&u.push(`${i}d`),(c>0||i>0)&&u.push(`${c}h`),(l>0||c>0||i>0)&&u.push(`${l}m`),u.push(`${d}s`),u.join(" ")},[n,r]=_.useState(s());return Ie.useInterval(()=>{r(s())},1e3),ke.isPast(e)?"Expired":t.jsxs(t.Fragment,{children:["Expires in ",t.jsx("span",{className:Xf.countdown,children:n})]})},t_="_container_1l528_1",s_="_info_1l528_11",n_="_header_1l528_17",r_="_chainName_1l528_23",o_="_expiration_1l528_29",a_="_revokeButton_1l528_35",St={container:t_,info:s_,header:n_,chainName:r_,expiration:o_,revokeButton:a_},i_=({chainId:e,grantee:s,messageTypes:n,expiration:r})=>{const o=Me(e),{mutate:a,isPending:i}=No({grantee:s,internal:!0});return t.jsxs("div",{className:St.container,children:[t.jsxs("div",{className:St.info,children:[t.jsxs("div",{className:St.header,children:[t.jsx(Y,{src:o.logoUrl,width:16,height:16,logo:!0}),t.jsx("div",{className:St.chainName,children:o.name})]}),t.jsx("div",{className:St.expiration,children:r?t.jsx(e_,{expiration:r}):"Until revoked"})]}),t.jsx("button",{className:St.revokeButton,onClick:()=>a(e),disabled:i,children:i?"Revoking...":"Revoke"})]})},c_=({chainId:e,grants:s})=>Object.values(s.reduce((r,o)=>{const a=r[o.grantee];return a?{...r,[o.grantee]:{...a,messageTypes:[...a.messageTypes,o.authorization.msg],expiration:Un([a.expiration,o.expiration?new Date(o.expiration):void 0])}}:{...r,[o.grantee]:{grantee:o.grantee,messageTypes:[o.authorization.msg],expiration:o.expiration?new Date(o.expiration):void 0}}},{})).map(r=>_.createElement(i_,{...r,chainId:e,key:r.grantee})),l_="_content_q36qs_1",d_={content:l_},u_=()=>{const e=Jf(),s=()=>{const n=e.filter(r=>r.data&&r.data.grants.length>0).map(r=>r.data);return n.length===0?t.jsx(ne,{children:"No permissions found"}):t.jsx("div",{className:d_.content,children:n.map(({chainId:r,grants:o})=>t.jsx(c_,{chainId:r,grants:o},r))})};return t.jsx(Oe,{title:"Manage auto-signing",backButton:"/settings",children:s()})},h_="2.1.1",m_="_version_1sf5y_1",f_={version:m_},__=()=>t.jsxs("aside",{className:f_.version,children:["v",h_]}),g_="_link_se23z_1",p_="_title_se23z_17",x_="_subtitle_se23z_23",y_="_icon_se23z_30",fs={link:g_,title:p_,subtitle:x_,icon:y_},ua=({title:e,subtitle:s,rightSection:n,onClick:r})=>t.jsxs("button",{className:fs.link,onClick:r,children:[t.jsxs("div",{children:[t.jsx("p",{className:fs.title,children:e}),s&&t.jsx("p",{className:fs.subtitle,children:s})]}),t.jsx("div",{className:fs.icon,children:n??t.jsx(A.IconChevronRight,{size:16})})]}),j_="https://export.initia.xyz/",v_=()=>{const e="width=600,height=768,scrollbars=yes,resizable=yes";return t.jsx(ua,{title:"Export private key",rightSection:t.jsx(A.IconExternalLink,{size:16}),onClick:()=>window.open(j_,"_blank",e)})},w_="_container_1vxr7_1",b_="_separator_1vxr7_7",Pr={container:w_,separator:b_},C_=()=>{const e=he(),{connector:s}=de.useAccount();return t.jsx(Oe,{title:"Settings",backButton:"/",children:t.jsxs("div",{className:Pr.container,children:[t.jsx(ua,{title:"Manage auto-signing",subtitle:"Manage chain auto-signing permissions by apps",onClick:()=>e("/settings/autosign")}),s?.id===Pn&&t.jsx(v_,{}),t.jsx(Ke.Separator,{className:Pr.separator}),t.jsx(__,{})]})})},I_="_trigger_1hs5b_1",N_="_icon_1hs5b_23",S_="_full_1hs5b_27",A_="_triggerContent_1hs5b_32",k_="_triggerText_1hs5b_40",$_="_popoverBackdrop_1hs5b_51",T_="_popoverPositioner_1hs5b_70",E_="_popoverPopup_1hs5b_74",q_="_search_1hs5b_99",D_="_viewport_1hs5b_105",P_="_item_1hs5b_111",R_="_highlighted_1hs5b_126",B_="_active_1hs5b_130",M_="_name_1hs5b_135",F_="_extra_1hs5b_139",le={trigger:I_,icon:N_,full:S_,triggerContent:A_,triggerText:k_,popoverBackdrop:$_,popoverPositioner:T_,popoverPopup:E_,search:q_,viewport:D_,item:P_,highlighted:R_,active:B_,name:M_,extra:F_},Yn=({value:e,onChange:s,chainIds:n,renderExtra:r,fullWidth:o})=>{const[a,i]=_.useState(""),[c,l]=_.useState(!1),[d,u]=_.useState(0),[h,m]=_.useState(),f=_.useRef([]),g=_.useRef(null),p=ae(),x=n.map(j=>p.find(b=>b.chainId===j)).filter(Boolean),S=j=>t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:j,height:j,viewBox:"0 0 14 14",children:[t.jsx("path",{fill:"var(--dimmed)",d:"M5.69625 12.04C8.47976 12.04 10.7362 9.78348 10.7362 6.99996C10.7362 4.21645 8.47976 1.95996 5.69625 1.95996C2.91273 1.95996 0.65625 4.21645 0.65625 6.99996C0.65625 9.78348 2.91273 12.04 5.69625 12.04Z"}),t.jsx("path",{fill:"var(--dimmed)",d:"M9.66003 2.63379C10.85 3.71879 11.6025 5.26754 11.6025 7.00004C11.6025 8.73254 10.85 10.2813 9.66003 11.3663C11.7513 10.99 13.3438 9.19629 13.3438 7.00004C13.3438 4.80379 11.7513 3.00129 9.66003 2.63379Z"})]}),I=_.useMemo(()=>({chainId:"",name:"All",logoUrl:S}),[]),N=_.useMemo(()=>{const j=[I,...x];if(!a)return j;const b=a.toLowerCase();return j.filter(y=>y.name.toLowerCase().includes(b)||y.chainId.toLowerCase().includes(b))},[x,a,I]),C=x.find(j=>j.chainId===e)||I,T=parseInt(Eo("--drawer-offset")),P=6,R=()=>{if(i(""),u(-1),g.current){const b=g.current.getBoundingClientRect().bottom+P,y=window.innerHeight-b-2*T;m(y)}l(!0)};_.useEffect(()=>{d>=0&&d<f.current.length&&f.current[d]?.scrollIntoView({block:"nearest",behavior:"auto"})},[d]);const B=_.useCallback(j=>{switch(j.key){case"ArrowDown":j.preventDefault(),u(b=>(b+1)%N.length);break;case"ArrowUp":j.preventDefault(),u(b=>(b-1+N.length)%N.length);break;case"Enter":j.preventDefault(),N[d]&&(s(N[d].chainId),l(!1));break;case"Escape":j.preventDefault(),l(!1);break}},[N,d,s,l]),z=j=>{s(j),l(!1)};return t.jsxs(It.Popover.Root,{open:c,onOpenChange:R,modal:"trap-focus",children:[t.jsx(It.Popover.Trigger,{render:t.jsxs("button",{className:D(le.trigger,{[le.full]:o}),"aria-expanded":c,role:"listbox",ref:g,children:[t.jsxs("div",{className:le.triggerContent,children:[typeof C.logoUrl=="string"?t.jsx(Y,{src:C.logoUrl,width:14,height:14,logo:!0}):C.logoUrl(14),t.jsx("span",{className:le.triggerText,children:C.name})]}),t.jsx(A.IconChevronDown,{size:16,className:le.icon})]})}),t.jsxs(It.Popover.Portal,{container:yt(),children:[t.jsx(It.Popover.Backdrop,{className:le.popoverBackdrop,onClick:()=>l(!1)}),t.jsx(It.Popover.Positioner,{className:le.popoverPositioner,align:"end",side:"bottom",sideOffset:P,collisionAvoidance:{side:"none"},children:t.jsxs(It.Popover.Popup,{className:D(le.popoverPopup,{[le.full]:o}),style:{maxHeight:h},children:[t.jsx(Hs,{value:a,onChange:j=>{i(j.target.value),u(0)},onClear:()=>i(""),onKeyDown:B,placeholder:"Search appchains",rootClassName:le.search,ref:ns()}),t.jsx("div",{className:le.viewport,role:"listbox",children:N.length===0?t.jsx(ne,{children:"No appchains found"}):N.map(({chainId:j,name:b,logoUrl:y},k)=>t.jsxs("div",{className:D(le.item,{[le.highlighted]:k===d,[le.active]:e===j}),onClick:()=>z(j),onKeyDown:q=>{(q.key==="Enter"||q.key===" ")&&(q.preventDefault(),z(j))},onMouseEnter:()=>u(k),role:"option","aria-selected":e===j,tabIndex:-1,ref:q=>{q&&(f.current[k]=q)},children:[typeof y=="string"?t.jsx(Y,{src:y,width:16,height:16,logo:!0}):y(16),t.jsx("span",{className:le.name,children:b}),r&&t.jsx("span",{className:le.extra,children:r(j)})]},j))})]})})]})]})},O_="_container_1nap1_1",U_="_controls_1nap1_7",L_="_search_1nap1_13",Jn={container:O_,controls:U_,search:L_},z_=({children:e})=>t.jsx("div",{className:Jn.container,children:e}),K_=({children:e})=>t.jsx("div",{className:Jn.controls,children:e}),W_=e=>t.jsx(Hs,{...e,rootClassName:Jn.search}),nt={Root:z_,Controls:K_,SearchInput:W_},H_=H.atom(""),Q_=H.atom(""),G_=H.atom(""),V_=H.atom(""),Y_=H.atom(""),J_="_change_1x9v4_1",Z_="_positive_1x9v4_10",X_="_negative_1x9v4_14",gn={change:J_,positive:Z_,negative:X_},ha=({amount:e,asset:s})=>{const{denom:n,symbol:r,decimals:o}=s,a=new F(e).isPositive(),i=new F(e).abs().toString();return t.jsxs("div",{className:D(gn.change,a?gn.positive:gn.negative),children:[a?"+":"-",v.formatAmount(i,{decimals:o})," ",r||n]})},eg=({changes:e,chain:s})=>{const n=Ge(s);return e.map(({amount:r,denom:o},a)=>t.jsx(ha,{amount:r,asset:n(o)},a))},tg=({changes:e,chain:s})=>{const n=Ge(s);return e.map(({amount:r,metadata:o},a)=>t.jsx(Lo,{metadata:o,chain:s,children:i=>t.jsx(ha,{amount:r,asset:n(i)})},a))},sg=({events:e,chain:s})=>{const{initiaAddress:n,hexAddress:r}=xe();return s.metadata?.is_l1||s.metadata?.minitia?.type==="minimove"?t.jsx(tg,{changes:Uo(e,r),chain:s}):t.jsx(eg,{changes:Oo(e,n),chain:s})},ng="_message_1g2hc_1",rg="_more_1g2hc_8",Rr={message:ng,more:rg},og=({messages:e})=>t.jsxs(t.Fragment,{children:[e.slice(0,3).map((s,n)=>t.jsx("p",{className:Rr.message,children:Ns.sentenceCase(s["@type"].split("Msg")[1])},n)),e.length>3&&t.jsx("footer",{className:Rr.more,children:`+${e.length-3} more`})]}),ag="_link_fuhbt_1",ig="_inner_fuhbt_16",cg="_header_fuhbt_21",lg="_time_fuhbt_30",dg="_error_fuhbt_36",ug="_timestamp_fuhbt_40",hg="_chainInfo_fuhbt_45",mg="_content_fuhbt_53",fg="_messages_fuhbt_61",_g="_changes_fuhbt_67",De={link:ag,inner:ig,header:cg,time:lg,error:dg,timestamp:ug,chainInfo:hg,content:mg,messages:fg,changes:_g},gg=({txItem:e,chain:s})=>t.jsx(zs,{txHash:e.txhash,chainId:s.chainId,className:De.link,children:t.jsxs("div",{className:De.inner,children:[t.jsxs("div",{className:De.header,children:[t.jsxs("div",{className:De.time,children:[e.code!==0&&t.jsx(A.IconWarningFilled,{size:14,className:De.error}),t.jsx("span",{className:De.timestamp,children:ke.format(new Date(e.timestamp),"h:mm a")})]}),t.jsxs("div",{className:De.chainInfo,children:[t.jsx(Y,{src:s.logoUrl,width:12,height:12,logo:!0}),t.jsx("span",{children:s.name})]})]}),t.jsxs("div",{className:De.content,children:[t.jsx("div",{className:De.messages,children:t.jsx(og,{messages:e.tx.body.messages})}),t.jsx("div",{className:De.changes,children:t.jsx(ye,{suspenseFallback:null,errorBoundaryProps:{fallback:null},children:t.jsx(sg,{...e,chain:s})})})]})]})}),pg="_list_1mv55_1",xg="_dateGroup_1mv55_7",yg="_dateHeader_1mv55_12",jg="_more_1mv55_18",_s={list:pg,dateGroup:xg,dateHeader:yg,more:jg},vg=({list:e,chainId:s})=>{const n=ee(),r=_.useMemo(()=>na(e,o=>{if(o.timestamp)return new Date(o.timestamp)}),[e]);return e.length===0?t.jsx(ne,{children:"No activity found"}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:_s.list,children:Object.entries(r).map(([o,a])=>t.jsxs("div",{className:_s.dateGroup,children:[t.jsx("div",{className:_s.dateHeader,children:o}),a.map(i=>t.jsx(ye,{errorBoundaryProps:{fallback:null},children:t.jsx(gg,{txItem:i,chain:i.chain})},i.txhash))]},o))}),t.jsx(zs,{chainId:s,accountAddress:n,pathSuffix:"/txs",className:_s.more,showIcon:!0,children:"View more on Initia Scan"})]})},wg=()=>{const{activities:e,isLoading:s}=Fc(),[n,r]=H.useAtom(Y_),o=_e(),a=_.useMemo(()=>Array.from(new Set(e.map(c=>c.chain.chainId))),[e]),i=_.useMemo(()=>n?e.filter(c=>c.chain.chainId===n):e,[e,n]);return s&&e.length===0?t.jsx(ne,{children:"Loading activities..."}):!e.length&&!s?t.jsx(ne,{children:"No activity yet"}):t.jsxs(nt.Root,{children:[t.jsx(nt.Controls,{children:t.jsx(Yn,{value:n,onChange:r,chainIds:a,fullWidth:!0})}),t.jsx(vg,{list:i,chainId:n||o.chainId})]})},ma=_.createContext(null);function fa(){return _.useContext(ma)}const bg="_popup_nbecp_1",Cg="_item_nbecp_19",gs={popup:bg,item:Cg},_a=({asset:e,children:s})=>{const{denom:n,decimals:r,symbol:o,logoUrl:a,unlisted:i,address:c,chain:l}=e,{chainId:d}=l,[u,h]=_.useState(!1),m=he(),f=fa(),{showNotification:g}=Hn(),{defaultChainId:p}=X(),{evm_chain_id:x}=Zt(),S=de.useChainId(),{switchChainAsync:I}=de.useSwitchChain(),{watchAssetAsync:N}=de.useWatchAsset(),C=()=>{h(!1),m("/send",{denom:n,chain:l})},T=()=>{h(!1),m("/bridge",{srcChainId:d,srcDenom:n,quantity:""})},P=$.useMutation({mutationFn:async()=>{if(!c)throw new Error("Address is required");const R=a;return await I({chainId:Number(x)}),N({type:"ERC20",options:{address:c,symbol:o,decimals:r,image:R}})},onSuccess:()=>{g({type:"success",title:"Asset added",description:"Asset added to wallet"})},onError:R=>{g({type:"error",title:"Asset addition failed",description:R.message})}});return t.jsxs(Ke.Menu.Root,{open:u,onOpenChange:h,modal:!1,children:[t.jsx(Ke.Menu.Trigger,{render:s}),t.jsx(Ke.Menu.Portal,{container:f,children:t.jsx(Ke.Menu.Positioner,{side:"bottom",sideOffset:-6,align:"end",children:t.jsxs(Ke.Menu.Popup,{className:gs.popup,children:[t.jsxs(Ke.Menu.Item,{className:gs.item,onClick:C,children:[t.jsx(A.IconArrowRight,{size:16}),t.jsx("span",{children:"Send"})]}),t.jsxs(Ke.Menu.Item,{className:gs.item,onClick:T,disabled:i,children:[t.jsx(A.IconSwap,{size:16}),t.jsx("span",{children:"Bridge/Swap"})]}),d===p&&x===S&&!!c&&t.jsxs(Ke.Menu.Item,{className:gs.item,onClick:()=>P.mutate(),disabled:P.isPending||P.data,children:[P.data?t.jsx(A.IconCheck,{size:16}):t.jsx(A.IconPlus,{size:16}),t.jsx("span",{children:"Add to Wallet"})]})]})})})]})},Ig="_item_38qhm_1",Ng="_info_38qhm_23",Sg="_images_38qhm_29",Ag="_name_38qhm_33",kg="_value_38qhm_39",$g="_amount_38qhm_47",Tg="_usd_38qhm_53",mt={item:Ig,info:Ng,images:Sg,name:Ag,value:kg,amount:$g,usd:Tg},Eg=({asset:e})=>{const{amount:s,value:n,logoUrl:r,chain:o}=e,a=v.formatAmount(s,{decimals:e.decimals});return t.jsx(_a,{asset:e,children:t.jsxs("button",{className:mt.item,children:[t.jsxs("div",{className:mt.info,children:[t.jsx(Ws,{assetLogoUrl:r,chainLogoUrl:o.logoUrl,assetLogoSize:24,chainLogoSize:14,chainLogoOffset:4,className:mt.images}),t.jsx("span",{className:mt.name,children:o.name})]}),t.jsxs("div",{className:mt.value,children:[t.jsx("span",{className:mt.amount,children:a}),Number(n)>0&&t.jsx("span",{className:mt.usd,children:$e(n)})]})]})})},qg="_container_10heg_1",Dg="_assetItem_10heg_6",Pg="_assetInfo_10heg_27",Rg="_logo_10heg_33",Bg="_symbol_10heg_37",Mg="_chainName_10heg_48",Fg="_chainInfos_10heg_54",Og="_chainLogos_10heg_60",Ug="_chainLogo_10heg_60",Lg="_moreChains_10heg_71",zg="_expandIcon_10heg_84",Kg="_expanded_10heg_88",Wg="_valueColumn_10heg_93",Hg="_amount_10heg_103",Qg="_value_10heg_93",Gg="_collapsibleContent_10heg_116",Vg="_chainsList_10heg_146",re={container:qg,assetItem:Dg,assetInfo:Pg,logo:Rg,symbol:Bg,chainName:Mg,chainInfos:Fg,chainLogos:Og,chainLogo:Ug,moreChains:Lg,expandIcon:zg,expanded:Kg,valueColumn:Wg,amount:Hg,value:Qg,collapsibleContent:Gg,chainsList:Vg},Yg=H.atom([]),ga=({assetGroup:e})=>{const{symbol:s,logoUrl:n,assets:r}=e,o=r.length===1,[a,i]=H.useAtom(Yg),c=_.useMemo(()=>fi(e),[e]),l=_.useMemo(()=>Ln(e),[e]),d=a.includes(s),u=()=>{i(m=>d?w.without([s],m):w.uniq([...m,s]))},h=()=>t.jsxs("button",{className:re.assetItem,children:[t.jsxs("div",{className:re.assetInfo,children:[n&&t.jsx(Y,{src:n,width:32,height:32,className:re.logo,logo:!0}),t.jsxs("div",{className:re.details,children:[t.jsx("div",{className:re.symbol,children:s}),o?t.jsx("div",{className:re.chainName,children:r[0].chain.name}):t.jsxs("div",{className:re.chainInfos,children:[t.jsx("div",{className:re.chainLogos,children:r.slice(0,5).map(({chain:m})=>t.jsx(Y,{src:m.logoUrl,width:16,height:16,className:re.chainLogo,logo:!0},m.chainId))}),r.length>5&&t.jsxs("span",{className:re.moreChains,children:["+",r.length-5]}),t.jsx(A.IconChevronDown,{size:16,className:D(re.expandIcon,{[re.expanded]:d})})]})]})]}),t.jsxs("div",{className:re.valueColumn,children:[t.jsx("div",{className:re.amount,children:v.formatNumber(c,{dp:r[0].unlisted?0:6})}),l>0&&t.jsx("div",{className:re.value,children:$e(l)})]})]});if(o){const[m]=r;return t.jsx("div",{className:re.container,children:t.jsx(_a,{asset:m,children:h()})})}return t.jsx("div",{className:re.container,children:t.jsxs(se.Collapsible.Root,{open:d,onOpenChange:u,children:[t.jsx(se.Collapsible.Trigger,{asChild:!0,children:h()}),t.jsx(se.Collapsible.Content,{className:re.collapsibleContent,children:t.jsx("div",{className:re.chainsList,children:r.map(m=>t.jsx(Eg,{asset:m},m.chain.chainId))})})]})})},Jg="_collapsible_1g7rh_1",Zg="_trigger_1g7rh_5",Xg="_divider_1g7rh_20",ep="_label_1g7rh_28",tp="_chevron_1g7rh_33",sp="_content_1g7rh_41",np="_list_1g7rh_45",tt={collapsible:Jg,trigger:Zg,divider:Xg,label:ep,chevron:tp,content:sp,list:np},rp=({unlistedAssets:e})=>{const[s,n]=_.useState(!0),r=fa(),o=_.useRef(null),[a,i]=_.useState(0);_.useEffect(()=>{if(o.current){const d=o.current.scrollHeight;i(d)}},[e]);const c=d=>{if(d&&!s&&r?.current){const u=r.current;u.scrollTo({top:u.scrollHeight,behavior:"auto"}),window.setTimeout(()=>{u.scrollTo({top:u.scrollHeight,behavior:"smooth"})},150)}n(d)},l=rt.useSpring({height:s?a:0,opacity:s?1:0,config:{tension:500,friction:30,clamp:!0}});return e.length===0?null:t.jsxs(se.Collapsible.Root,{open:s,onOpenChange:c,className:tt.collapsible,children:[t.jsxs(se.Collapsible.Trigger,{className:tt.trigger,children:[t.jsx("div",{className:tt.divider}),t.jsxs("span",{className:tt.label,children:["Unlisted assets (",e.length,")"]}),t.jsx(A.IconChevronDown,{className:tt.chevron,size:12,"data-state":s?"open":"closed"}),t.jsx("div",{className:tt.divider})]}),t.jsx(se.Collapsible.Content,{forceMount:!0,asChild:!0,children:t.jsx(rt.animated.div,{className:tt.content,style:l,children:t.jsx("div",{className:tt.list,ref:o,children:e.map(d=>t.jsx(ga,{assetGroup:{...d,assets:[d]}},d.denom))})})})]})},op="_list_szwvw_1",ap={list:op},ip=()=>{const[e,s]=H.useAtom(H_),[n,r]=H.useAtom(Q_),{assetGroups:o,unlistedAssets:a,chainsByValue:i,totalValue:c,isLoading:l}=zn(),d=i.map(({chainId:m})=>m),u=_.useMemo(()=>{const m=e?o.filter(g=>{const{symbol:p,assets:x}=g;return p.toLowerCase().includes(e.toLowerCase())||x.some(({denom:S,address:I})=>S.toLowerCase().includes(e.toLowerCase())||I?.toLowerCase().includes(e.toLowerCase()))}):o;return n?m.map(g=>({...g,assets:g.assets.filter(({chain:p})=>p.chainId===n)})).filter(g=>g.assets.length>0):m},[o,e,n]),h=_.useMemo(()=>{const m=e?a.filter(({denom:g,address:p})=>g.toLowerCase().includes(e.toLowerCase())||p?.toLowerCase().includes(e.toLowerCase())):a;return n?m.filter(({chain:g})=>g.chainId===n):m},[a,e,n]);return l&&o.length===0?t.jsx(ne,{children:"Loading assets..."}):!u.length&&!h.length&&!e&&!n&&!l?t.jsx(ne,{children:"No assets"}):t.jsxs(nt.Root,{children:[t.jsxs(nt.Controls,{children:[t.jsx(nt.SearchInput,{value:e,onChange:m=>s(m.target.value),onClear:()=>s(""),placeholder:"Search assets"}),t.jsx(Yn,{value:n,onChange:r,chainIds:d,renderExtra:m=>{if(!m)return $e(c);const f=i.find(g=>g.chainId===m);return f?$e(f.value):null}})]}),t.jsx("div",{children:u.length===0&&h.length===0?t.jsx(ne,{children:"No assets found"}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:ap.list,children:u.map(m=>t.jsx(ga,{assetGroup:m},m.symbol))}),t.jsx(rp,{unlistedAssets:h})]})})]})},cp="_thumbnail_1xyqw_1",lp="_placeholder_1xyqw_18",dp="_clickable_1xyqw_24",Wt={thumbnail:cp,placeholder:lp,clickable:dp},up=({nftInfo:e,size:s,onClick:n})=>{const{collection_addr:r,object_addr:o,nft:a,chain:i}=e,{glyphUrl:c}=X(),l=new URL(`/v1/${i.chainId}/${r}/${o||a.token_id}`,c).toString();return n?t.jsx("button",{className:D(Wt.thumbnail,Wt.clickable),onClick:n,style:{width:s,height:s},children:t.jsx(Y,{src:l,classNames:{placeholder:Wt.placeholder}})}):t.jsx("div",{className:Wt.thumbnail,style:{width:s,height:s},children:t.jsx(Y,{src:l,classNames:{placeholder:Wt.placeholder}})})},hp="_collectionName_qs5tw_1",mp="_nftName_qs5tw_6",fp="_chainInfo_qs5tw_10",pn={collectionName:hp,nftName:mp,chainInfo:fp},Zn=({normalizedNft:e,onThumbnailClick:s,thumbnailSize:n,chainIconSize:r=12,classNames:o})=>{const{collection_name:a,name:i,chain:c}=e;return t.jsxs("div",{className:o?.root,children:[t.jsx(up,{nftInfo:e,onClick:s,size:n}),t.jsxs("div",{children:[t.jsx("div",{className:D(pn.collectionName,o?.collectionName),children:a}),t.jsx("div",{className:D(pn.nftName,o?.nftName),children:i}),t.jsxs("div",{className:D(pn.chainInfo,o?.chainInfo),children:[t.jsx(Y,{src:c.logoUrl,width:r,height:r,logo:!0}),t.jsx("span",{children:c.name})]})]})]})},Xn=Ne.createQueryKeys("interwovenkit:nft",{nfts:(e,s)=>[e,s],metadata:e=>[e]});function _p(e,s){const{nft:n}=e,r=s.name??n.token_id;return{...e,...n,...s,name:r}}function gp(e,s){return e.flatMap((n,r)=>(s[r]??[]).map(a=>({...a,chain:n})))}const pp=()=>{const e=ee(),s=ae(),n=$.useQueries({queries:s.map(l=>({queryKey:Xn.nfts(l.indexerUrl,e).queryKey,queryFn:()=>eo(`indexer/nft/v1/tokens/by_account/${e}`,{prefixUrl:l.indexerUrl},"tokens"),staleTime:Q.SECOND}))}),r=n.map(w.prop("data")),o=gp(s,r),a=o.reduce((l,{chain:d})=>({...l,[d.chainId]:(l[d.chainId]||0)+1}),{}),i=Object.values(a).reduce((l,d)=>l+d,0),c=n.some(l=>l.isLoading);return{nftInfos:o,chainCounts:a,totalCount:i,isLoading:c}};function xp(e){const s=Br(e);return $.useQuery({queryKey:Xn.metadata(s).queryKey,queryFn:async()=>{try{if(!s)return{};const n=await L.get(s).json();return{...n,image:Br(n.image)}}catch{return{}}},staleTime:Q.INFINITY})}function Br(e){return e?.replace("ipfs://","https://ipfs.io/ipfs/")}const yp=({nftInfo:e,children:s})=>{const{data:n={}}=xp(e.nft.uri),r=_p(e,n);return s(r)},jp="_grid_1wwdn_1",vp="_root_1wwdn_7",wp="_collectionName_1wwdn_15",bp="_nftName_1wwdn_23",Cp="_chainInfo_1wwdn_32",Mr={grid:jp,root:vp,collectionName:wp,nftName:bp,chainInfo:Cp},Ip=()=>{const[e,s]=H.useAtom(G_),[n,r]=H.useAtom(V_),{nftInfos:o,chainCounts:a,totalCount:i,isLoading:c}=pp(),l=he(),d=_.useMemo(()=>o.filter(({collection_addr:h,collection_name:m,nft:f,object_addr:g,chain:p})=>{if(n&&p.chainId!==n)return!1;if(e){const x=e.trim().toLowerCase();return h.toLowerCase().includes(x)||m.toLowerCase().includes(x)||f.token_id.toLowerCase().includes(x)||g.toLowerCase().includes(x)}return!0}),[o,n,e]),u=_.useMemo(()=>Array.from(new Set(o.map(({chain:h})=>h.chainId))),[o]);return c&&o.length===0?t.jsx(ne,{children:"Loading NFTs..."}):!o.length&&!e&&!c?t.jsx(ne,{children:"No NFTs"}):t.jsxs(nt.Root,{children:[t.jsxs(nt.Controls,{children:[t.jsx(nt.SearchInput,{value:e,onChange:h=>s(h.target.value),onClear:()=>s(""),placeholder:"Search NFTs"}),t.jsx(Yn,{value:n,onChange:r,chainIds:u,renderExtra:h=>h?a[h]||0:i})]}),d.length===0?t.jsx(ne,{children:"No NFTs found"}):t.jsx("div",{className:Mr.grid,children:d.map(h=>{const{collection_addr:m,nft:f}=h;return t.jsx(yp,{nftInfo:h,children:g=>t.jsx(Zn,{normalizedNft:g,onThumbnailClick:()=>l("/nft",g),classNames:Mr})},m+f.token_id)})})]})},Np="_totalValue_znvjc_1",Sp="_totalLabel_znvjc_7",Ap="_totalAmount_znvjc_13",kp="_loading_znvjc_18",$p="_nav_znvjc_23",Tp="_item_znvjc_29",Ep="_tabs_znvjc_54",qp="_tab_znvjc_54",we={totalValue:Np,totalLabel:Sp,totalAmount:Ap,loading:kp,nav:$p,item:Tp,tabs:Ep,tab:qp},Dp=()=>{Yo();const e=he(),s=Es(),{totalValue:n,isLoading:r}=zn(),o=_.useRef(null);return t.jsx(ma.Provider,{value:o,children:t.jsxs(Fe,{ref:o,children:[t.jsxs("div",{className:we.totalValue,children:[t.jsx("div",{className:we.totalLabel,children:"Total value"}),t.jsx("div",{className:D(we.totalAmount,{[we.loading]:r}),children:$e(n)})]}),t.jsxs("div",{className:we.nav,children:[t.jsxs(Et,{to:"/send",className:we.item,children:[t.jsx(A.IconArrowRight,{size:16}),t.jsx("span",{children:"Send"})]}),t.jsxs(Et,{to:"/bridge",className:we.item,children:[t.jsx(A.IconSwap,{size:16}),t.jsx("span",{children:"Bridge/Swap"})]}),t.jsxs(Et,{to:"/receive",className:we.item,children:[t.jsx(A.IconQrCode,{size:16}),t.jsx("span",{children:"Receive"})]})]}),t.jsxs(Ze.Tabs.Root,{value:s,onValueChange:e,children:[t.jsxs(Ze.Tabs.List,{className:we.tabs,children:[t.jsx(Ze.Tabs.Tab,{className:we.tab,value:"/",children:"Assets"}),t.jsx(Ze.Tabs.Tab,{className:we.tab,value:"/nfts",children:"NFTs"}),t.jsx(Ze.Tabs.Tab,{className:we.tab,value:"/activity",children:"Activity"})]}),t.jsx(Ze.Tabs.Panel,{value:"/",children:t.jsx(ip,{})}),t.jsx(Ze.Tabs.Panel,{value:"/nfts",children:t.jsx(Ip,{})}),t.jsx(Ze.Tabs.Panel,{value:"/activity",children:t.jsx(wg,{})})]})]})})},Pp="_root_th990_1",Rp="_collectionName_th990_9",Bp="_nftName_th990_13",Mp="_chainInfo_th990_17",Fp="_attributes_th990_21",Op="_title_th990_24",Up="_count_th990_29",Lp="_item_th990_33",zp="_type_th990_39",Kp="_value_th990_45",ft={root:Pp,collectionName:Rp,nftName:Bp,chainInfo:Mp,attributes:Fp,title:Op,count:Up,item:Lp,type:zp,value:Kp},Wp=()=>{const e=he(),s=jt(),{attributes:n}=s;return t.jsxs(Oe,{title:"NFT details",children:[t.jsx(Zn,{normalizedNft:s,chainIconSize:14,classNames:ft}),t.jsx(ie,{children:t.jsx(J.White,{onClick:()=>e("/nft/send",s),sm:!0,children:"Send"})}),n&&t.jsxs("div",{className:ft.attributes,children:[t.jsxs("header",{className:ft.title,children:["Traits ",t.jsxs("span",{className:ft.count,children:["(",n.length,")"]})]}),t.jsx("div",{children:n.map(({trait_type:r,value:o})=>t.jsxs("div",{className:ft.item,children:[t.jsx("div",{className:ft.type,children:r}),t.jsx("div",{className:ft.value,children:o})]},r))})]})]})};function Hp({balances:e,gasPrices:s,gas:n}){return s.map(({denom:r,amount:o})=>{const a=F(o).times(n).toFixed(0,F.ROUND_CEIL),i=e.find(c=>c.denom===r)?.amount??"0";return{amount:a,denom:r,balance:i}}).filter(({amount:r,balance:o})=>F(o).gte(r))}function Qp({denom:e,balances:s,gasPrices:n,lastFeeDenom:r,gas:o}){const a=s.find(d=>d.denom===e)?.amount??"0",i=Hp({balances:s,gasPrices:n,gas:o}),c=i.find(d=>d.denom===r);if(i.length===0)return a;if(e===r&&c){const d=F(a).minus(c.amount);return F.max(d,0).toString()}const l=i.find(d=>d.denom!==e)||i[0];if(!c&&e===l.denom){const d=F(a).minus(l.amount);return F.max(d,0).toString()}return F(a).toString()}const Gp=({chain:e,onSelect:s})=>{const n=Wa(e);return t.jsx(os,{assets:n,onSelect:s})},Vp=({afterSelect:e})=>{const{watch:s,setValue:n}=ue.useFormContext(),{chainId:r,denom:o}=s(),{chainId:a}=s(),[i,c]=_.useState(a),l=Me(i),d=ae(),u=h=>{if(r===i&&o===h){e();return}n("chainId",i),n("denom",h),n("quantity","",{shouldTouch:!1,shouldDirty:!1}),e()};return t.jsxs(t.Fragment,{children:[t.jsx(xt.Stack,{children:t.jsx(xt,{chains:d,value:i,onSelect:c})}),t.jsx(ye,{suspenseFallback:t.jsx(os.Placeholder,{}),children:t.jsx(Gp,{chain:l,onSelect:u})},i)]})},Yp="_fields_brpej_1",Jp="_divider_brpej_11",Fr={fields:Yp,divider:Jp},Zp=Ne.createQueryKeys("interwovenkit:send",{gas:e=>[e]}),Xp=()=>{const{address:e,initiaAddress:s,estimateGas:n,requestTxSync:r}=xe(),{register:o,watch:a,setValue:i,handleSubmit:c,formState:l}=ue.useFormContext(),{errors:d}=l,{chainId:u,denom:h,recipient:m,quantity:f,memo:g}=a(),p=Me(u),x=Bn(p),S=Bo(p),I=Mo(p),N=Zr(h,p),{data:C}=ks(p),{decimals:T}=N,P=x.find(O=>O.denom===h)?.amount??"0",R=C?.find(({id:O})=>O===h)?.price,{data:B=0,isLoading:z}=$.useQuery({queryKey:Zp.gas({chainId:u,denom:h,recipient:m,initiaAddress:s}).queryKey,queryFn:()=>{const O=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:ir.MsgSend.fromPartial({fromAddress:s,toAddress:v.InitiaAddress(m).bech32,amount:[{denom:h,amount:"1"}]})}];return n({messages:O,chainId:u})},enabled:v.InitiaAddress.validate(m),staleTime:Q.INFINITY}),j=Math.ceil(B*Gt),b=Qp({denom:h,balances:x,gasPrices:S,lastFeeDenom:I,gas:j}),y=F(P).isZero(),q=S.some(({denom:O})=>O===h)&&z,M=y||q,{mutate:E,isPending:G}=$.useMutation({mutationFn:({chainId:O,denom:Z,quantity:Ue,recipient:Je,memo:at})=>{const me=v.toBaseUnit(Ue,{decimals:T}),ge=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:ir.MsgSend.fromPartial({fromAddress:s,toAddress:v.InitiaAddress(Je).bech32,amount:[{denom:Z,amount:me}]})}];return r({messages:ge,memo:at,chainId:O,gas:B,gasAdjustment:Gt,gasPrices:S,spendCoins:[{denom:Z,amount:me}],internal:"/"})}}),te=_.useMemo(()=>{if(!f)return"Enter amount";if(d.quantity)return d.quantity.message;if(!m)return"Enter recipient address";if(d.recipient)return d.recipient.message;if(d.memo)return d.memo.message},[f,m,d.quantity,d.recipient,d.memo]);return t.jsx(Oe,{title:"Send",children:t.jsxs("form",{onSubmit:c(O=>E(O)),children:[t.jsxs("div",{className:Fr.fields,children:[t.jsx(In,{selectButton:t.jsx(Dt,{title:"Select chain and asset",content:O=>t.jsx(Vp,{afterSelect:O}),children:t.jsx(ta,{asset:N,chain:p})}),quantityInput:t.jsx(bs,{balance:P,decimals:T}),balanceButton:t.jsx(Jo,{onClick:()=>i("quantity",v.fromBaseUnit(b,{decimals:T}),{shouldValidate:!0}),disabled:M,children:v.formatAmount(P??"0",{decimals:T})}),value:f?R?$e(F(f).times(R)):"$-":"$0"}),t.jsx("div",{className:Fr.divider}),t.jsx(Gn,{myAddress:e}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:"memo",children:"Memo (optional)"}),t.jsx("input",{...o("memo",{validate:O=>!O||new Blob([O]).size<=256||"Memo is too long"}),id:"memo",autoComplete:"off"})]}),t.jsx(oe.Stack,{children:!g&&t.jsx(oe,{level:"warning",children:"Check if the above transaction requires a memo"})})]}),t.jsx(ie,{children:t.jsx(J.White,{type:"submit",loading:(z?"Estimating gas...":!1)||G,disabled:!!te,children:te??"Confirm"})})]})})},ex=()=>{const e=jt(),s=Zt(),n=Vt(s),{chain:r=s}=e,o=w.head(n);if(!e.denom&&!o)throw new Error("Asset list not found. This occurs during local development when asset list is not configured. Use asset-specific send buttons instead of the default send button, or register chain in Initia Registry with at least one asset defined.");const a=e.denom??o?.denom,i=ue.useForm({mode:"onChange",defaultValues:{chainId:r.chainId,denom:a,quantity:"",recipient:"",memo:""}});return t.jsx(ue.FormProvider,{...i,children:t.jsx(Xp,{})})};async function En(e,s){const n=e.replace("ibc/",""),{class_trace:r}=await L.create({prefixUrl:s}).get(`ibc/apps/nft_transfer/v1/class_traces/${n}`).json();return r}async function tx(e,s){const n=new We.Interface([{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}]),{response:r}=await L.create({prefixUrl:s}).post("minievm/evm/v1/call",{json:{sender:v.InitiaAddress("0x1").bech32,contract_addr:v.InitiaAddress(e).hex,input:n.encodeFunctionData("name")}}).json();return n.decodeFunctionResult("name",r)[0]}async function sx(e,s,n){if(s.startsWith("evm/"))return e;const{token_infos:r}=await L.create({prefixUrl:n}).get(`minievm/evm/v1/erc721/origin_token_infos/${s}`,{searchParams:{token_ids:e.join(",")}}).json();return r.map(({token_origin_id:o})=>o)}async function nx({collection_addr:e},{restUrl:s}){const n=await tx(e,s);if(!n.startsWith("ibc/"))return{class_id:`evm/${v.InitiaAddress(e).rawHex}`,class_trace:void 0};const r=await En(n,s);return r?{class_id:n,class_trace:r}:{class_id:`evm/${v.InitiaAddress(e).rawHex}`,class_trace:void 0}}async function rx(e,s){const{data:n}=await L.create({prefixUrl:s}).post("initia/move/v1/view/json",{json:{address:"0x1",module_name:"collection",function_name:"name",type_args:["0x1::collection::Collection"],args:[JSON.stringify(e)]}}).json();return JSON.parse(n)}async function ox({object_addr:e,collection_addr:s},{restUrl:n}){const r=await rx(s,n);return r.startsWith("ibc/")?v.InitiaAddress.equals(v.createObjectAddress("0x1",r),s)?{class_id:r,class_trace:await En(r,n)}:{class_id:`move/${e.replace("0x","").padStart(64,"0")}`,class_trace:await En(r,n)}:{class_id:`move/${s.replace("0x","").padStart(64,"0")}`,class_trace:void 0}}async function ax(e,s){const n=V.toBase64(_t.utf8ToBytes(JSON.stringify({contract_info:{}}))),{data:r}=await L.create({prefixUrl:s}).get(`cosmwasm/wasm/v1/contract/${e}/smart/${n}`).json();return r.name}async function ix(e,s){const{collection:n}=await L.create({prefixUrl:s}).get(`indexer/nft/v1/collections/${e}`).json();return n.collection.creator}async function cx(e,s){const n=V.toBase64(_t.toBytes(JSON.stringify({outgoing_proxy:{}}))),{data:r}=await L.create({prefixUrl:s}).get(`cosmwasm/wasm/v1/contract/${e}/smart/${n}`).json();return r}function Or(e){const s=/^(.*channel-\d+)\/(.*)$/,n=e.match(s);if(!n)throw new Error("Pattern `channel-{number}/` not found.");const[,r,o]=n;return[r,o]}async function lx({collection_addr:e},s,n){const r=v.InitiaAddress(e).bech32,o=await ax(r,s.restUrl),a=s.metadata?.ibc_channels?.find(({chain_id:p,version:x})=>p===n.chain_id&&x.includes("ics721-1"));if(!a)throw new Error("Channel not found");const i=a.port_id,c=i.split(".")[1],l=V.toBase64(_t.toBytes(JSON.stringify({class_id:{contract:r}}))),{data:d}=await L.create({prefixUrl:s.restUrl}).get(`cosmwasm/wasm/v1/contract/${c}/smart/${l}`).json(),u=d??r,h=await cx(c,s.restUrl),m=await ix(r,s.indexerUrl);if(u===r)return{class_id:u,class_trace:void 0,outgoing_proxy:h};if(d&&m!==i.replace("wasm.","")){const[p,x]=Or(d);return{class_id:r,class_trace:{path:p,base_class_id:x},outgoing_proxy:h}}const[f,g]=Or(o);return{class_id:r,class_trace:{path:f,base_class_id:g},outgoing_proxy:h}}const dx={minimove:ox,minievm:nx,miniwasm:lx};async function ux({nft:e,srcChain:s,intermediaryChain:n}){const r=s.metadata?.is_l1?"minimove":s.metadata?.minitia?.type;if(!(r==="minimove"||r==="minievm"||r==="miniwasm"))throw new Error(`Unsupported minitia type: ${r}`);const o=await dx[r](e,s,n);return Object.assign(o,r==="minievm"&&{token_ids:await sx([e.token_id],o.class_id,s.restUrl)})}const hx="_root_1tyvn_1",mx="_collectionName_1tyvn_10",fx="_nftName_1tyvn_15",_x="_chainInfo_1tyvn_19",gx="_fields_1tyvn_24",px="_chain_1tyvn_19",xn={root:hx,collectionName:mx,nftName:fx,chainInfo:_x,fields:gx,chain:px},xx=Ne.createQueryKeys("interwovenkit:send-nft",{simulation:e=>[e]}),yx=()=>{const e=ae(),s=jt(),{chain:n,collection_addr:r}=s,{routerApiUrl:o}=X(),a=Ds(),i=_e(),{address:c,initiaAddress:l,requestTxSync:d}=xe(),{watch:u,setValue:h,handleSubmit:m,formState:f}=ue.useFormContext(),{errors:g}=f,p=u(),{recipient:x,dstChainId:S}=p,I=Me(S),N=$.useQuery({queryKey:xx.simulation({collection_addr:r,nft:s,sender:l,recipient:x,srcChain:n,dstChain:I,layer1:i,routerApiUrl:o}).queryKey,queryFn:async()=>{const b=Object.assign({from_address:l,from_chain_id:n.chainId,to_address:v.InitiaAddress(x).bech32,to_chain_id:I.chainId,collection_address:r,token_ids:[s.token_id],object_addresses:[s.object_addr]},n.chainId!==I.chainId&&await ux({nft:s,srcChain:n,intermediaryChain:i})),{msgs:y}=await L.create({prefixUrl:o}).post("nft",{json:b}).json();return y.map(k=>a.fromAmino(k))},enabled:v.InitiaAddress.validate(x)}),{data:C,isLoading:T,error:P}=N,R=$.useQueryClient(),{mutate:B,isPending:z}=$.useMutation({mutationFn:async()=>{if(!C)throw new Error("Route not found");await d({messages:C,chainId:n.chainId,internal:"/nfts"})},onSuccess:()=>{R.invalidateQueries({queryKey:Xn.nfts._def})}}),j=_.useMemo(()=>{if(!x)return"Enter recipient address";if(g.recipient)return g.recipient.message;if(P)return"Route not found"},[x,g.recipient,P]);return t.jsxs("form",{onSubmit:m(()=>B()),children:[t.jsx(Zn,{normalizedNft:s,thumbnailSize:80,classNames:xn}),t.jsxs("div",{className:xn.fields,children:[t.jsxs("div",{children:[t.jsx("div",{className:"label",children:"Destination appchain"}),t.jsxs(Dt,{title:"Destination appchain",content:b=>t.jsx(ea,{onSelect:({chainId:y})=>{h("dstChainId",y),b()},list:e,getImage:y=>y.logoUrl,getName:y=>y.name,getKey:y=>y.chainId}),className:D("input",xn.chain),children:[t.jsx(Y,{src:I.logoUrl,width:20,height:20,logo:!0}),t.jsx("span",{children:I.name})]})]}),t.jsx(Gn,{myAddress:c,ref:ns()})]}),t.jsx(ie,{children:t.jsx(J.White,{loading:(T?"Finding route...":!1)||z,disabled:!!j,children:j??"Confirm"})})]})},jx=()=>{const{chain:e}=jt(),s=ue.useForm({mode:"onChange",defaultValues:{dstChainId:e.chainId,recipient:""}});return t.jsx(Oe,{title:"Send NFT",children:t.jsx(ue.FormProvider,{...s,children:t.jsx(yx,{})})})},pa=()=>{const e=he(),s=Es(),n=Pt(),{closeDrawer:r}=Ve(),{closeModal:o}=Ms();_.useEffect(()=>{o(),s.startsWith("/bridge/")&&e("/bridge"),(s==="/collection"||s.startsWith("/nft"))&&e("/nfts")},[n]);const a=qs();if(_.useEffect(()=>{a("Page View")},[s,a]),s==="/connect")return n?null:t.jsx(Dr,{onSuccess:r});if(s==="/blank")return null;if(!n)return t.jsx(Dr,{});switch(s){case"/":case"/nfts":case"/activity":return t.jsx(Dp,{});case"/send":return t.jsx(ex,{},n);case"/receive":return t.jsx(Yf,{});case"/nft":return t.jsx(Wp,{});case"/nft/send":return t.jsx(jx,{},n);case"/bridge":return t.jsx(Rh,{},n);case"/bridge/preview":return t.jsx(Gm,{});case"/bridge/history":return t.jsx(Im,{});case"/op/withdrawals":return t.jsx(Sf,{});case"/tx":return t.jsx(Ko,{});case"/autosign/enable":return t.jsx(vd,{});case"/settings":return t.jsx(C_,{});case"/settings/autosign":return t.jsx(u_,{})}},vx="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@100..700&display=swap",wx=()=>t.jsxs(t.Fragment,{children:[t.jsx("link",{rel:"preconnect",href:"https://fonts.googleapis.com"}),t.jsx("link",{rel:"preconnect",href:"https://fonts.gstatic.com",crossOrigin:""}),t.jsx("link",{rel:"stylesheet",href:vx}),t.jsx("link",{rel:"stylesheet",href:"https://assets.initia.xyz/fonts/PilatWide.css"})]}),bx=()=>{Za(),oi(),ae();const e=_e();return Kn(),qt(localStorage.getItem(U.BRIDGE_SRC_CHAIN_ID)??e.chainId),qt(localStorage.getItem(U.BRIDGE_DST_CHAIN_ID)??e.chainId),null},Cx=({children:e,...s})=>(_.useEffect(()=>{bi()},[]),Ie.useIsClient()?t.jsxs(t.Fragment,{children:[t.jsx(wx,{}),t.jsx(Gr.Provider,{value:{...Qr,...s},children:t.jsx(ao,{children:t.jsx(Vl,{children:t.jsx(se.Tooltip.Provider,{delayDuration:0,skipDelayDuration:0,children:t.jsx(Gl,{children:t.jsxs(Rl,{children:[e,t.jsx(Ci,{}),t.jsx(ye,{suspenseFallback:null,errorBoundaryProps:{fallback:null},children:t.jsx(bx,{})}),t.jsx(dc,{children:t.jsx(pa,{})})]})})})})})})]}):null),Ix=({bridge:e})=>t.jsx(ao,{initialEntry:{path:e?"/bridge":"/",state:e},children:t.jsx("div",{className:"body",children:t.jsx(Do.Provider,{value:!!e,children:t.jsx(ye,{children:t.jsx(pa,{})})})})});exports.DEFAULT_GAS_ADJUSTMENT=Gt;exports.DEFAULT_GAS_PRICE_MULTIPLIER=Hr;exports.InterwovenKit=Ix;exports.InterwovenKitProvider=Cx;exports.MAINNET=Qr;exports.MoveError=jo;exports.PRIVY_APP_ID=Pn;exports.TESTNET=Ea;exports.initiaPrivyWallet=Da;exports.initiaPrivyWalletConnector=qa;exports.initiaPrivyWalletOptions=Ss;exports.injectStyles=Oi;exports.useAddress=Pt;exports.useHexAddress=Us;exports.useInitiaAddress=ee;exports.useInterwovenKit=xe;exports.usePortfolio=zn;exports.useUsernameQuery=So;
|