@idosgames/wallet 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,12 +37,24 @@ Entry points:
37
37
  - `@idosgames/wallet/react/solana` — the Solana React bindings, kept off
38
38
  `/react` so an EVM-only game doesn't bundle the Solana adapters.
39
39
  - `@idosgames/wallet/react/lazy` — `LazyWalletLogin` /
40
- `LazySolanaWalletLogin`: the same sign-in button, but it fetches the wallet
41
- machinery on the player's first tap. This is the only entry with **no Reown
42
- AppKit in its module graph**, which is what makes it safe on a login screen
43
- in sandboxed/preview bundlers where AppKit isn't installable. It also
44
- re-exports the supported chains as plain objects, so a login screen never has
45
- to import the `wagmi/chains` / `viem/chains` barrel.
40
+ `LazySolanaWalletLogin` / `LazyWalletPanel`: the sign-in buttons and the
41
+ in-game deposit/withdraw panel, but each fetches the wallet machinery on
42
+ demand (`LazyWalletLogin` on the player's first tap; `LazyWalletPanel` on
43
+ mount). This is the only entry with **no Reown AppKit in its module graph**,
44
+ which is what makes it safe to render on a login screen or in-game in
45
+ sandboxed/preview bundlers where AppKit isn't installable. It also re-exports
46
+ the supported chains as plain objects, so you never have to import the
47
+ `wagmi/chains` / `viem/chains` barrel.
48
+
49
+ `createEvmWalletConfig` is **memoised per WalletConnect project id**: the
50
+ sign-in button and the wallet panel both call it and get the *same* wagmi
51
+ `Config` object, and a wagmi Config carries the connection in its own store. So
52
+ a wallet connected on the login screen is already connected in the in-game
53
+ panel — no reconnect, no second modal. For that to hold, keep both on the same
54
+ chain set; both default to `DEFAULT_EVM_CHAINS`, so the simplest correct thing
55
+ is to pass no `chains` to either. `LazyWalletPanel` takes the authenticated
56
+ `client` as a prop (like the login button), plus optional `appName` /
57
+ `onClose` / `style` / `walletConnectProjectId`.
46
58
 
47
59
  Every subpath declares a `browser` export condition pointing at the ESM build.
48
60
  That is load-bearing, not cosmetic: some browser bundlers (CodeSandbox's
@@ -1,2 +1,2 @@
1
- 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var _={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},z={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},Q={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},V={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},Z={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},$={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},J={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},X={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},ee={mainnet:_,bsc:z,polygon:Q,base:V,arbitrum:Z,optimism:$,sepolia:J,polygonAmoy:X};function Ce(t){return Object.values(ee).find(e=>e.id===t)}function te(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var ne=null;function re(t){ne=t;}function P(){return ne}function Te(t){let{chains:e,walletConnectProjectId:n,appName:r,appUrl:o,appIcon:a,transports:p,connectors:l}=t,i={};for(let c of e)i[c.id]=p?.[c.id]??wagmi.http();let u=o??(typeof window<"u"?window.location.origin:""),d={name:r??"iDosGames",description:r??"iDosGames game",url:u,icons:a?[a]:[]};if(n&&!l){let c=e.map(te),f=new appkitAdapterWagmi.WagmiAdapter({networks:c,projectId:n,transports:i});return re(react.createAppKit({adapters:[f],networks:c,projectId:n,metadata:d,features:{analytics:false,email:false,socials:false}})),f.wagmiConfig}let m=l??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})];return wagmi.createConfig({chains:e,connectors:m,transports:i})}function I(t){let{wagmiConfig:e,queryClient:n,children:r}=t,[o]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:e,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:o,children:r})})}var T=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],ae=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],B=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],ie=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];function se(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function w(t,e){let{walletClient:n,publicClient:r,account:o}=t,a=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:o,chain:n.chain,value:e.value});if((await r.waitForTransactionReceipt({hash:a})).status==="reverted")throw new Error(`On-chain transaction reverted (${a}).`);return a}function g(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function s(t,e,n){return {ok:false,stage:t,error:e,...n}}function C(t,e){return {ok:false,stage:t,error:e}}function le(t){let e=t.RewardPoolAddress;return e||null}async function ce(t,e,n,r){return await t.publicClient.readContract({address:e,abi:B,functionName:"allowance",args:[t.account,n]})>=r?null:w(t,{address:e,abi:B,functionName:"approve",args:[n,r]})}async function R(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:a,titleID:p,category:l}=t,i=e.auth.context?.userID;if(!i)return s("approve","Not logged in.");let u=le(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(a<=0n)return s("approve","Amount must be positive.");try{await ce(n,o,u,a);}catch(c){return s("approve",g(c))}let d;try{d=await w(n,{address:u,abi:T,functionName:"depositERC20",args:[o,a,i,p,l??""]});}catch(c){return s("deposit-onchain",g(c))}let m=await e.blockchain.depositToken(r.NetworkID??"",d);return m.ok?{ok:true,onChainTxHash:d,data:m.data}:s("report",m.error,{onChainTxHash:d})}async function S(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:a,amount:p,titleID:l,category:i}=t,u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let d=le(r);if(!d)return s("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return s("deposit-onchain","Amount must be positive.");let m=se(u,l,i),c;try{c=await w(n,{address:o,abi:ie,functionName:"safeTransferFrom",args:[n.account,d,a,p,m]});}catch(A){return s("deposit-onchain",g(A))}let f=await e.blockchain.depositNFT(r.NetworkID??"",c);return f.ok?{ok:true,onChainTxHash:c,data:f.data}:s("report",f.error,{onChainTxHash:c})}async function pe(t,e){return w(t,{address:e.ContractAddress,abi:T,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function de(t,e){return w(t,{address:e.ContractAddress,abi:ae,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function F(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:a,amount:p,category:l}=t,i=await e.blockchain.requestTokenWithdrawal(r,o,a,p,l);if(!i.ok)return s("request",i.error);let u=i.data.EvmSignature,d=i.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let m;try{m=await pe(n,u);}catch(f){return s("withdraw-onchain",g(f),{titleTransactionID:d})}let c=await me(e,d,m);return c.ok?{ok:true,onChainTxHash:m,data:i.data}:c}async function H(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:a,amount:p,category:l}=t,i=await e.blockchain.requestNFTWithdrawal(r,o,a,p,l);if(!i.ok)return s("request",i.error);let u=i.data.EvmSignature,d=i.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let m;try{m=await de(n,u);}catch(f){return s("withdraw-onchain",g(f),{titleTransactionID:d})}let c=await me(e,d,m);return c.ok?{ok:true,onChainTxHash:m,data:i.data}:c}async function me(t,e,n){if(!e)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:s("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function b(t){let{client:e,clients:n,networkID:r}=t,o=t.walletAddress??n.account,a=await e.auth.requestWalletChallenge(o,r);if(!a.ok)return C("challenge",a.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:a.data.Message});}catch(i){return C("sign",g(i))}let l=await e.auth.loginWithWallet(o,r,p);return l.ok?{ok:true,data:l.data}:C("login",l.error)}function W(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}var k="Wallet not connected.";function Me(t,e){let n=W();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,o)=>n?b({client:t,clients:n,networkID:r,walletAddress:o}):Promise.resolve(C("challenge",k)),depositToken:r=>n?R({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("approve",k)),depositNft:r=>n?S({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("deposit-onchain",k)),withdrawToken:r=>n?F({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",k)),withdrawNft:r=>n?H({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",k))}}function je(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(I,{wagmiConfig:e,children:jsxRuntime.jsx(ye,{...n})})}function Ye(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function _e(t){let e="Wallet sign-in failed. Please try again.";return t instanceof Error?t.name==="ProviderNotFoundError"||/provider not found/i.test(t.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":t.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(t.message)?"Request declined in the wallet.":/timed? ?out/i.test(t.message)?"The wallet did not respond. Open your wallet and try again.":e:e}async function fe(t){let e=await actions.getWalletClient(t).catch(()=>null);if(!e)return null;let n=actions.getPublicClient(t);return n?{account:e.account.address,publicClient:n,walletClient:e}:null}function ze(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,o=l=>{r||(r=true,a(),clearTimeout(p),n(l));},a=actions.watchAccount(t,{onChange:l=>{l.isConnected&&o(true);}}),p=setTimeout(()=>o(false),e);})}function Qe(t,e=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(t).status)?new Promise(r=>{let o=false,a=()=>{o||(o=true,p(),clearTimeout(l),r());},p=actions.watchAccount(t,{onChange:i=>{n(i.status)||a();}}),l=setTimeout(a,e);}):Promise.resolve()}function Ve(t){let e=o=>t.find(a=>a.id===o||a.type===o),n=e("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:e("walletConnect")??n??t[0]}var Ze=9e4;async function $e(t){try{let r=(await actions.getAccount(t).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,o=r?.native||r?.universal;return !o||typeof window>"u"?!1:(window.location.href=o,!0)}catch{return false}}function Je(t,e){return new Promise((n,r)=>{let o=setTimeout(()=>r(new Error("The wallet request timed out.")),e);t.then(a=>{clearTimeout(o),n(a);},a=>{clearTimeout(o),r(a instanceof Error?a:new Error(String(a)));});})}function ye(t){let{client:e,networkID:n,onAuthenticated:r,disabled:o,label:a,style:p,autoStart:l}=t,i=wagmi.useConfig(),{isConnected:u}=wagmi.useAccount(),{connectAsync:d,connectors:m}=wagmi.useConnect(),c=W(),[f,A]=react$1.useState(false),[L,h]=react$1.useState(null),[K,G]=react$1.useState(false),O=react$1.useRef(0),U=react$1.useRef(false),q=async()=>{let he=++O.current,v=()=>O.current===he;A(true),h(null);try{if(await Qe(i),!v())return;if(!actions.getAccount(i).isConnected){let x=P();if(x){if(await x.open(),!await ze(i)){h("No wallet was connected.");return}}else {let j=Ve(m);if(!j){h("No wallet connector is configured.");return}try{await d({connector:j});}catch(Y){if(!Ye(Y))throw Y}}}let y=c??await fe(i);if(!y&&actions.getAccount(i).isConnected&&(await new Promise(x=>setTimeout(x,300)),y=await fe(i),!v()))return;if(!y){h("Wallet client is not available.");return}G(!0);let D=await Je(b({client:e,clients:y,networkID:n}),Ze);if(!v())return;if(D.ok){r();return}h(D.stage==="sign"?"Signature declined.":D.error??"Wallet sign-in failed.");}catch(y){if(!v())return;console.error("[idosgames/wallet] wallet sign-in failed:",y),h(_e(y));}finally{v()&&(A(false),G(false));}};react$1.useEffect(()=>{!l||U.current||(U.current=true,q());},[l]);let we=async()=>{await $e(i)||await P()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{K?we():q();},disabled:o,style:{...Xe,...o?{opacity:.6,cursor:"default"}:null,...p},children:K?"Waiting for signature \u2014 tap to open wallet":f?"Check your wallet\u2026":u?a??"Sign in with wallet":"Connect wallet"}),L&&jsxRuntime.jsx("span",{role:"alert",style:et,children:L})]})}var Xe={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},et={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
2
- exports.IDosGamesWalletProvider=I;exports.WalletLogin=je;exports.WalletLoginButton=ye;exports.arbitrum=Z;exports.base=V;exports.bsc=z;exports.chainById=Ce;exports.createEvmWalletConfig=Te;exports.idosChains=ee;exports.mainnet=_;exports.optimism=$;exports.polygon=Q;exports.polygonAmoy=X;exports.sepolia=J;exports.useEvmBridge=Me;exports.useEvmBridgeClients=W;
1
+ 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var j={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},_={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},z={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},V={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},$={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},Y={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},Q={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},Z={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},Ce={mainnet:j,bsc:_,polygon:z,base:V,arbitrum:$,optimism:Y,sepolia:Q,polygonAmoy:Z};function qe(e){return Object.values(Ce).find(t=>t.id===e)}function be(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var ve=null;function ke(e){ve=e;}function ie(){return ve}var Ee=[j,_,z,V,$,Y,Q,Z],ae=new Map;function se(e){let{chains:t=Ee,walletConnectProjectId:n,appName:o,appUrl:r,appIcon:i,transports:p,connectors:l}=e,a=n??"__extension_only__";if(!l){let y=ae.get(a);if(y)return y}let u={};for(let y of t)u[y.id]=p?.[y.id]??wagmi.http();let d=r??(typeof window<"u"?window.location.origin:""),m={name:o??"iDosGames",description:o??"iDosGames game",url:d,icons:i?[i]:[]};if(n&&!l){let y=t.map(be),D=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:u});return ke(react.createAppKit({adapters:[D],networks:y,projectId:n,metadata:m,features:{analytics:false,email:false,socials:false}})),ae.set(a,D.wagmiConfig),D.wagmiConfig}let f=l??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],h=wagmi.createConfig({chains:t,connectors:f,transports:u});return l||ae.set(a,h),h}function G(e){let{wagmiConfig:t,queryClient:n,children:o}=e,[r]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:r,children:o})})}var J=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],Ae=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],le=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],De=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];function Ne(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}async function T(e,t){let{walletClient:n,publicClient:o,account:r}=e,i=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:r,chain:n.chain,value:t.value});if((await o.waitForTransactionReceipt({hash:i})).status==="reverted")throw new Error(`On-chain transaction reverted (${i}).`);return i}function A(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function c(e,t,n){return {ok:false,stage:e,error:t,...n}}function M(e,t){return {ok:false,stage:e,error:t}}function Pe(e){let t=e.RewardPoolAddress;return t||null}async function Ie(e,t,n,o){return await e.publicClient.readContract({address:t,abi:le,functionName:"allowance",args:[e.account,n]})>=o?null:T(e,{address:t,abi:le,functionName:"approve",args:[n,o]})}async function ce(e){let{client:t,clients:n,network:o,tokenAddress:r,amount:i,titleID:p,category:l}=e,a=t.auth.context?.userID;if(!a)return c("approve","Not logged in.");let u=Pe(o);if(!u)return c("approve","Network has no RewardPoolAddress.");if(i<=0n)return c("approve","Amount must be positive.");try{await Ie(n,r,u,i);}catch(f){return c("approve",A(f))}let d;try{d=await T(n,{address:u,abi:J,functionName:"depositERC20",args:[r,i,a,p,l??""]});}catch(f){return c("deposit-onchain",A(f))}let m=await t.blockchain.depositToken(o.NetworkID??"",d);return m.ok?{ok:true,onChainTxHash:d,data:m.data}:c("report",m.error,{onChainTxHash:d})}async function pe(e){let{client:t,clients:n,network:o,nftContractAddress:r,tokenId:i,amount:p,titleID:l,category:a}=e,u=t.auth.context?.userID;if(!u)return c("deposit-onchain","Not logged in.");let d=Pe(o);if(!d)return c("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return c("deposit-onchain","Amount must be positive.");let m=Ne(u,l,a),f;try{f=await T(n,{address:r,abi:De,functionName:"safeTransferFrom",args:[n.account,d,i,p,m]});}catch(y){return c("deposit-onchain",A(y))}let h=await t.blockchain.depositNFT(o.NetworkID??"",f);return h.ok?{ok:true,onChainTxHash:f,data:h.data}:c("report",h.error,{onChainTxHash:f})}async function We(e,t){return T(e,{address:t.ContractAddress,abi:J,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Te(e,t){return T(e,{address:t.ContractAddress,abi:Ae,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function de(e){let{client:t,clients:n,currencyID:o,networkID:r,walletAddress:i,amount:p,category:l}=e,a=await t.blockchain.requestTokenWithdrawal(o,r,i,p,l);if(!a.ok)return c("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return c("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let m;try{m=await We(n,u);}catch(h){return c("withdraw-onchain",A(h),{titleTransactionID:d})}let f=await Be(t,d,m);return f.ok?{ok:true,onChainTxHash:m,data:a.data}:f}async function ue(e){let{client:t,clients:n,itemID:o,networkID:r,walletAddress:i,amount:p,category:l}=e,a=await t.blockchain.requestNFTWithdrawal(o,r,i,p,l);if(!a.ok)return c("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return c("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let m;try{m=await Te(n,u);}catch(h){return c("withdraw-onchain",A(h),{titleTransactionID:d})}let f=await Be(t,d,m);return f.ok?{ok:true,onChainTxHash:m,data:a.data}:f}async function Be(e,t,n){if(!t)return c("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await e.blockchain.confirmWithdrawal(t,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:c("confirm",o.error,{onChainTxHash:n,titleTransactionID:t})}async function O(e){let{client:t,clients:n,networkID:o}=e,r=e.walletAddress??n.account,i=await t.auth.requestWalletChallenge(r,o);if(!i.ok)return M("challenge",i.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Message});}catch(a){return M("sign",A(a))}let l=await t.auth.loginWithWallet(r,o,p);return l.ok?{ok:true,data:l.data}:M("login",l.error)}function X(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}var U="Wallet not connected.";function me(e,t){let n=X();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,r)=>n?O({client:e,clients:n,networkID:o,walletAddress:r}):Promise.resolve(M("challenge",U)),depositToken:o=>n?ce({client:e,clients:n,titleID:t,...o}):Promise.resolve(c("approve",U)),depositNft:o=>n?pe({client:e,clients:n,titleID:t,...o}):Promise.resolve(c("deposit-onchain",U)),withdrawToken:o=>n?de({client:e,clients:n,...o}):Promise.resolve(c("withdraw-onchain",U)),withdrawNft:o=>n?ue({client:e,clients:n,...o}):Promise.resolve(c("withdraw-onchain",U))}}function ut(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(G,{wagmiConfig:t,children:jsxRuntime.jsx(Me,{...n})})}function mt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function ft(e){let t="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":t:t}async function Re(e){let t=await actions.getWalletClient(e).catch(()=>null);if(!t)return null;let n=actions.getPublicClient(e);return n?{account:t.account.address,publicClient:n,walletClient:t}:null}function gt(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,r=l=>{o||(o=true,i(),clearTimeout(p),n(l));},i=actions.watchAccount(e,{onChange:l=>{l.isConnected&&r(true);}}),p=setTimeout(()=>r(false),t);})}function yt(e,t=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(e).status)?new Promise(o=>{let r=false,i=()=>{r||(r=true,p(),clearTimeout(l),o());},p=actions.watchAccount(e,{onChange:a=>{n(a.status)||i();}}),l=setTimeout(i,t);}):Promise.resolve()}function wt(e){let t=r=>e.find(i=>i.id===r||i.type===r),n=t("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:t("walletConnect")??n??e[0]}var ht=9e4;async function Ct(e){try{let o=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,r=o?.native||o?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function bt(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(i=>{clearTimeout(r),n(i);},i=>{clearTimeout(r),o(i instanceof Error?i:new Error(String(i)));});})}function Me(e){let{client:t,networkID:n,onAuthenticated:o,disabled:r,label:i,style:p,autoStart:l}=e,a=wagmi.useConfig(),{isConnected:u}=wagmi.useAccount(),{connectAsync:d,connectors:m}=wagmi.useConnect(),f=X(),[h,y]=react$1.useState(false),[D,C]=react$1.useState(null),[H,E]=react$1.useState(false),L=react$1.useRef(0),S=react$1.useRef(false),q=async()=>{let I=++L.current,N=()=>L.current===I;y(true),C(null);try{if(await yt(a),!N())return;if(!actions.getAccount(a).isConnected){let k=ie();if(k){if(await k.open(),!await gt(a)){C("No wallet was connected.");return}}else {let oe=wt(m);if(!oe){C("No wallet connector is configured.");return}try{await d({connector:oe});}catch(W){if(!mt(W))throw W}}}let b=f??await Re(a);if(!b&&actions.getAccount(a).isConnected&&(await new Promise(k=>setTimeout(k,300)),b=await Re(a),!N()))return;if(!b){C("Wallet client is not available.");return}E(!0);let x=await bt(O({client:t,clients:b,networkID:n}),ht);if(!N())return;if(x.ok){o();return}C(x.stage==="sign"?"Signature declined.":x.error??"Wallet sign-in failed.");}catch(b){if(!N())return;console.error("[idosgames/wallet] wallet sign-in failed:",b),C(ft(b));}finally{N()&&(y(false),E(false));}};react$1.useEffect(()=>{!l||S.current||(S.current=true,q());},[l]);let R=async()=>{await Ct(a)||await ie()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{H?R():q();},disabled:r,style:{...vt,...r?{opacity:.6,cursor:"default"}:null,...p},children:H?"Waiting for signature \u2014 tap to open wallet":h?"Check your wallet\u2026":u?i??"Sign in with wallet":"Connect wallet"}),D&&jsxRuntime.jsx("span",{role:"alert",style:kt,children:D})]})}var vt={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},kt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Tt={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},Bt={fontWeight:700,fontSize:16},B={fontSize:12,opacity:.7},ge={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},St={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},te={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},ye={display:"flex",gap:8};function Rt(e){let{client:t,walletConnectProjectId:n,appName:o,onClose:r,style:i}=e,[p,l]=react$1.useState(n??"");react$1.useEffect(()=>{if(n)return;let u=true;return (async()=>{let d=await t.blockchain.getDefinitions();if(!u||!d.ok)return;let m=d.data.Blockchain?.WalletLogin?.WalletConnectProjectId;m&&l(m);})(),()=>{u=false;}},[t,n]);let a=react$1.useMemo(()=>se({walletConnectProjectId:p||void 0,appName:o}),[p,o]);return jsxRuntime.jsx(G,{wagmiConfig:a,children:jsxRuntime.jsx(Ft,{client:t,appName:o,onClose:r,style:i})})}function Ft({client:e,onClose:t,style:n}){let o=me(e,e.titleID),{address:r,isConnected:i,chainId:p}=wagmi.useAccount(),{connect:l,connectors:a}=wagmi.useConnect(),{disconnect:u}=wagmi.useDisconnect(),{switchChainAsync:d}=wagmi.useSwitchChain(),[,m]=react$1.useReducer(s=>s+1,0),[f,h]=react$1.useState({}),[y,D]=react$1.useState({}),[C,H]=react$1.useState(""),[E,L]=react$1.useState(""),[S,q]=react$1.useState(""),[R,I]=react$1.useState(false),[N,b]=react$1.useState(null);react$1.useEffect(()=>{let s=true;return (async()=>{let w=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!s||!w.ok)return;let F=w.data.Blockchain?.Networks??{},re={};for(let[Ke,he]of Object.entries(F))he.Type==="EVM"&&(re[Ke]=he);h(re),D(w.data.CryptoCurrencies??{});let Ue=Object.keys(re)[0]??"";H(Ue);})(),()=>{s=false;}},[e]),react$1.useEffect(()=>e.on("user:anyUpdated",m),[e]);let x=react$1.useMemo(()=>Object.entries(y).filter(([,s])=>s.Networks?.some(w=>w.NetworkID===C&&!!w.ContractAddress)),[y,C]);react$1.useEffect(()=>{let s=x[0]?.[0]??"";L(w=>x.some(([F])=>F===w)?w:s);},[x]);let k=C?f[C]:void 0,W=(E?y[E]:void 0)?.Networks?.find(s=>s.NetworkID===C),Le=E?e.data.user.getCryptoCurrencyAmount(E):"0";async function we(){if(!k?.ChainID||p===k.ChainID)return true;try{return await d({chainId:k.ChainID}),!0}catch{return b({ok:false,stage:"approve",error:`Switch your wallet to chain ${k.ChainID} to continue.`}),false}}async function Ge(){if(!(!k||!W?.ContractAddress)){if(I(true),b(null),await we()){let s=W.Decimals??18,w;try{w=viem.parseUnits(S||"0",s);}catch{b({ok:false,stage:"approve",error:"Invalid amount."}),I(false);return}let F=await o.depositToken({network:k,tokenAddress:W.ContractAddress,amount:w});b(F),F.ok&&await e.blockchain.getUserState();}I(false);}}async function Oe(){if(!(!k||!o.account)){if(I(true),b(null),await we()){let s=await o.withdrawToken({currencyID:E,networkID:C,walletAddress:o.account,amount:S||"0"});b(s),s.ok&&await e.blockchain.getUserState();}I(false);}}return jsxRuntime.jsxs("div",{style:{...Tt,...n},children:[jsxRuntime.jsxs("div",{style:{...ye,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Bt,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:te,onClick:t,children:"\u2715"})]}),i?jsxRuntime.jsxs("div",{style:ye,children:[jsxRuntime.jsxs("span",{style:{...B,flex:1,alignSelf:"center"},children:[r?.slice(0,6),"\u2026",r?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:te,onClick:()=>u(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:B,children:"Connect a browser or mobile wallet"}),a.map(s=>jsxRuntime.jsx("button",{type:"button",style:te,onClick:()=>l({connector:s}),children:s.name},s.uid))]}),Object.keys(f).length===0?jsxRuntime.jsx("span",{style:B,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:B,children:"Network"}),jsxRuntime.jsx("select",{style:ge,value:C,onChange:s=>H(s.target.value),children:Object.entries(f).map(([s,w])=>jsxRuntime.jsx("option",{value:s,children:w.DisplayName??s},s))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:B,children:"Token"}),jsxRuntime.jsxs("select",{style:ge,value:E,onChange:s=>L(s.target.value),children:[x.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),x.map(([s,w])=>jsxRuntime.jsx("option",{value:s,children:w.DisplayName??s},s))]})]}),jsxRuntime.jsxs("div",{style:B,children:["In-game balance: ",jsxRuntime.jsx("b",{children:Le})," ",E]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:B,children:"Amount"}),jsxRuntime.jsx("input",{style:ge,inputMode:"decimal",placeholder:"0.0",value:S,onChange:s=>q(s.target.value)})]}),jsxRuntime.jsxs("div",{style:ye,children:[jsxRuntime.jsx("button",{type:"button",style:{...St,flex:1,opacity:R?.6:1},disabled:R||!i||!W?.ContractAddress,onClick:()=>{Ge();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...te,flex:1,opacity:R?.6:1},disabled:R||!i||!E,onClick:()=>{Oe();},children:"Withdraw"})]})]}),N&&jsxRuntime.jsx(Mt,{result:N})]})}function Mt({result:e}){let t={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxRuntime.jsxs("div",{style:t,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxRuntime.jsxs("div",{style:t,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}
2
+ exports.DEFAULT_EVM_CHAINS=Ee;exports.IDosGamesWalletProvider=G;exports.WalletLogin=ut;exports.WalletLoginButton=Me;exports.WalletPanel=Rt;exports.arbitrum=$;exports.base=V;exports.bsc=_;exports.chainById=qe;exports.createEvmWalletConfig=se;exports.idosChains=Ce;exports.mainnet=j;exports.optimism=Y;exports.polygon=z;exports.polygonAmoy=Z;exports.sepolia=Q;exports.useEvmBridge=me;exports.useEvmBridgeClients=X;
@@ -8,9 +8,24 @@ import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalR
8
8
  import { b as DepositTokenEvmParams, a as DepositNftEvmParams, c as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-CwX4HY2X.cjs';
9
9
  import { W as WalletLoginResult, a as BridgeResult } from '../types-C11zAA05.cjs';
10
10
 
11
+ /**
12
+ * The EVM chains a game supports out of the box. Both the sign-in button and the in-game wallet
13
+ * panel default to this same list, on purpose: they must build the wallet config from an IDENTICAL
14
+ * chain set so the memoised config (below) is shared between them — otherwise the panel could not
15
+ * switch the wallet to a network the login screen never registered. Deposits/withdrawals still
16
+ * happen only on the title's configured networks; the extra chains just let the wallet switch to
17
+ * whichever one a token lives on. Plain objects (never the `viem/chains` barrel — see chains.ts).
18
+ */
19
+ declare const DEFAULT_EVM_CHAINS: readonly [Chain, ...Chain[]];
11
20
  interface EvmWalletConfigOptions {
12
- /** Chains the game supports, matching the EVM networks in the title's blockchain config. */
13
- chains: readonly [Chain, ...Chain[]];
21
+ /**
22
+ * Chains the game supports, matching the EVM networks in the title's blockchain config. Defaults
23
+ * to {@link DEFAULT_EVM_CHAINS}. Note: the config is memoised per project id, so the FIRST call for
24
+ * a given project id fixes the chain set; later calls (e.g. the wallet panel after the login
25
+ * button) reuse it and ignore their own `chains`. Keep the login and the panel on the same list —
26
+ * both default to {@link DEFAULT_EVM_CHAINS}, which is why leaving this unset is the safe choice.
27
+ */
28
+ chains?: readonly [Chain, ...Chain[]];
14
29
  /**
15
30
  * WalletConnect Cloud / Reown project id — required for MOBILE wallets. With it, the connect
16
31
  * button opens the Reown AppKit modal (wallet list, QR on desktop, deep-link on phones). Omit it
@@ -32,18 +47,6 @@ interface EvmWalletConfigOptions {
32
47
  */
33
48
  connectors?: CreateConnectorFn[];
34
49
  }
35
- /**
36
- * Builds a wagmi `Config` wired for both browser and mobile wallets, ready to hand to
37
- * {@link IDosGamesWalletProvider} (or a bare `WagmiProvider`).
38
- *
39
- * With a `walletConnectProjectId` this goes through **Reown AppKit** (the successor to
40
- * WalletConnect's own modal): AppKit owns the wallet picker, the QR/deep-link handshake and — the
41
- * part that matters on phones — re-opening the wallet app for every signature request. The bare
42
- * wagmi WalletConnect connector left that to the player, which is why signatures appeared to hang.
43
- *
44
- * Without a project id it falls back to a plain wagmi config with `injected()` + `coinbaseWallet()`:
45
- * browser extensions keep working, mobile wallets are simply unavailable.
46
- */
47
50
  declare function createEvmWalletConfig(options: EvmWalletConfigOptions): Config;
48
51
 
49
52
  interface IDosGamesWalletProviderProps {
@@ -140,4 +143,28 @@ type WalletLoginButtonProps = Omit<WalletLoginProps, "wagmiConfig">;
140
143
  /** The button itself. Must be rendered inside an {@link IDosGamesWalletProvider}. */
141
144
  declare function WalletLoginButton(props: WalletLoginButtonProps): ReactNode;
142
145
 
143
- export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
146
+ interface WalletPanelProps {
147
+ /** The authenticated shared client (a prop, like WalletLogin — never taken from a module context). */
148
+ client: IDosGamesClient;
149
+ /**
150
+ * WalletConnect Cloud / Reown project id — what lights up mobile wallets. Pass the title's
151
+ * `Blockchain.WalletLogin.WalletConnectProjectId`; without it only browser-extension wallets work.
152
+ * Omit to have the panel read it from the title's blockchain config once the client resolves.
153
+ */
154
+ walletConnectProjectId?: string;
155
+ /** App name shown in the wallet's connect prompt. */
156
+ appName?: string;
157
+ /** Called when the player closes the panel; the ✕ button only renders when provided. */
158
+ onClose?: () => void;
159
+ /** Overrides for the outer card container, merged over the defaults key by key. */
160
+ style?: CSSProperties;
161
+ }
162
+ /**
163
+ * Public entry: the in-game wallet panel wrapped in its own wagmi/react-query provider.
164
+ *
165
+ * The wagmi config is the memoised one shared with the sign-in button (see createEvmWalletConfig),
166
+ * so a wallet connected at login is already connected here.
167
+ */
168
+ declare function WalletPanel(props: WalletPanelProps): ReactNode;
169
+
170
+ export { DEFAULT_EVM_CHAINS, type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, WalletPanel, type WalletPanelProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
@@ -8,9 +8,24 @@ import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalR
8
8
  import { b as DepositTokenEvmParams, a as DepositNftEvmParams, c as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-C-sFNUnQ.js';
9
9
  import { W as WalletLoginResult, a as BridgeResult } from '../types-C11zAA05.js';
10
10
 
11
+ /**
12
+ * The EVM chains a game supports out of the box. Both the sign-in button and the in-game wallet
13
+ * panel default to this same list, on purpose: they must build the wallet config from an IDENTICAL
14
+ * chain set so the memoised config (below) is shared between them — otherwise the panel could not
15
+ * switch the wallet to a network the login screen never registered. Deposits/withdrawals still
16
+ * happen only on the title's configured networks; the extra chains just let the wallet switch to
17
+ * whichever one a token lives on. Plain objects (never the `viem/chains` barrel — see chains.ts).
18
+ */
19
+ declare const DEFAULT_EVM_CHAINS: readonly [Chain, ...Chain[]];
11
20
  interface EvmWalletConfigOptions {
12
- /** Chains the game supports, matching the EVM networks in the title's blockchain config. */
13
- chains: readonly [Chain, ...Chain[]];
21
+ /**
22
+ * Chains the game supports, matching the EVM networks in the title's blockchain config. Defaults
23
+ * to {@link DEFAULT_EVM_CHAINS}. Note: the config is memoised per project id, so the FIRST call for
24
+ * a given project id fixes the chain set; later calls (e.g. the wallet panel after the login
25
+ * button) reuse it and ignore their own `chains`. Keep the login and the panel on the same list —
26
+ * both default to {@link DEFAULT_EVM_CHAINS}, which is why leaving this unset is the safe choice.
27
+ */
28
+ chains?: readonly [Chain, ...Chain[]];
14
29
  /**
15
30
  * WalletConnect Cloud / Reown project id — required for MOBILE wallets. With it, the connect
16
31
  * button opens the Reown AppKit modal (wallet list, QR on desktop, deep-link on phones). Omit it
@@ -32,18 +47,6 @@ interface EvmWalletConfigOptions {
32
47
  */
33
48
  connectors?: CreateConnectorFn[];
34
49
  }
35
- /**
36
- * Builds a wagmi `Config` wired for both browser and mobile wallets, ready to hand to
37
- * {@link IDosGamesWalletProvider} (or a bare `WagmiProvider`).
38
- *
39
- * With a `walletConnectProjectId` this goes through **Reown AppKit** (the successor to
40
- * WalletConnect's own modal): AppKit owns the wallet picker, the QR/deep-link handshake and — the
41
- * part that matters on phones — re-opening the wallet app for every signature request. The bare
42
- * wagmi WalletConnect connector left that to the player, which is why signatures appeared to hang.
43
- *
44
- * Without a project id it falls back to a plain wagmi config with `injected()` + `coinbaseWallet()`:
45
- * browser extensions keep working, mobile wallets are simply unavailable.
46
- */
47
50
  declare function createEvmWalletConfig(options: EvmWalletConfigOptions): Config;
48
51
 
49
52
  interface IDosGamesWalletProviderProps {
@@ -140,4 +143,28 @@ type WalletLoginButtonProps = Omit<WalletLoginProps, "wagmiConfig">;
140
143
  /** The button itself. Must be rendered inside an {@link IDosGamesWalletProvider}. */
141
144
  declare function WalletLoginButton(props: WalletLoginButtonProps): ReactNode;
142
145
 
143
- export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
146
+ interface WalletPanelProps {
147
+ /** The authenticated shared client (a prop, like WalletLogin — never taken from a module context). */
148
+ client: IDosGamesClient;
149
+ /**
150
+ * WalletConnect Cloud / Reown project id — what lights up mobile wallets. Pass the title's
151
+ * `Blockchain.WalletLogin.WalletConnectProjectId`; without it only browser-extension wallets work.
152
+ * Omit to have the panel read it from the title's blockchain config once the client resolves.
153
+ */
154
+ walletConnectProjectId?: string;
155
+ /** App name shown in the wallet's connect prompt. */
156
+ appName?: string;
157
+ /** Called when the player closes the panel; the ✕ button only renders when provided. */
158
+ onClose?: () => void;
159
+ /** Overrides for the outer card container, merged over the defaults key by key. */
160
+ style?: CSSProperties;
161
+ }
162
+ /**
163
+ * Public entry: the in-game wallet panel wrapped in its own wagmi/react-query provider.
164
+ *
165
+ * The wagmi config is the memoised one shared with the sign-in button (see createEvmWalletConfig),
166
+ * so a wallet connected at login is already connected here.
167
+ */
168
+ declare function WalletPanel(props: WalletPanelProps): ReactNode;
169
+
170
+ export { DEFAULT_EVM_CHAINS, type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, WalletPanel, type WalletPanelProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
@@ -1 +1 @@
1
- import {o,n,i,h,p}from'../chunk-DMMHCUIU.js';import {a,b as b$1}from'../chunk-ZL42KPPC.js';import {b,c}from'../chunk-K62NMX3A.js';import {k as k$1}from'../chunk-HQNS6ZWL.js';export{e as arbitrum,d as base,b as bsc,j as chainById,i as idosChains,a as mainnet,f as optimism,c as polygon,h as polygonAmoy,g as sepolia}from'../chunk-HQNS6ZWL.js';import {http,createConfig,WagmiProvider,useAccount,usePublicClient,useWalletClient,useConfig,useConnect}from'wagmi';import {injected,coinbaseWallet}from'wagmi/connectors';import {WagmiAdapter}from'@reown/appkit-adapter-wagmi';import {createAppKit}from'@reown/appkit/react';import {QueryClient,QueryClientProvider}from'@tanstack/react-query';import {useState,useRef,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getAccount,watchAccount,getWalletClient,getPublicClient}from'wagmi/actions';function ue(e){let{chains:o,walletConnectProjectId:t,appName:n,appUrl:r,appIcon:i,transports:l,connectors:a$1}=e,s={};for(let c of o)s[c.id]=l?.[c.id]??http();let P=r??(typeof window<"u"?window.location.origin:""),W={name:n??"iDosGames",description:n??"iDosGames game",url:P,icons:i?[i]:[]};if(t&&!a$1){let c=o.map(k$1),w=new WagmiAdapter({networks:c,projectId:t,transports:s});return a(createAppKit({adapters:[w],networks:c,projectId:t,metadata:W,features:{analytics:false,email:false,socials:false}})),w.wagmiConfig}let E=a$1??[injected(),coinbaseWallet({appName:n??"iDosGames"})];return createConfig({chains:o,connectors:E,transports:s})}function k(e){let{wagmiConfig:o,queryClient:t,children:n}=e,[r]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:o,children:jsx(QueryClientProvider,{client:r,children:n})})}function y(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var f="Wallet not connected.";function Pe(e,o$1){let t=y();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,r)=>t?p({client:e,clients:t,networkID:n,walletAddress:r}):Promise.resolve(c("challenge",f)),depositToken:n=>t?h({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("approve",f)),depositNft:n=>t?i({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("deposit-onchain",f)),withdrawToken:n$1=>t?n({client:e,clients:t,...n$1}):Promise.resolve(b("withdraw-onchain",f)),withdrawNft:n=>t?o({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",f))}}function Ae(e){let{wagmiConfig:o,...t}=e;return jsx(k,{wagmiConfig:o,children:jsx(J,{...t})})}function De(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Re(e){let o="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":o:o}async function z(e){let o=await getWalletClient(e).catch(()=>null);if(!o)return null;let t=getPublicClient(e);return t?{account:o.account.address,publicClient:t,walletClient:o}:null}function Be(e,o=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let n=false,r=a=>{n||(n=true,i(),clearTimeout(l),t(a));},i=watchAccount(e,{onChange:a=>{a.isConnected&&r(true);}}),l=setTimeout(()=>r(false),o);})}function Ie(e,o=8e3){let t=n=>n==="reconnecting"||n==="connecting";return t(getAccount(e).status)?new Promise(n=>{let r=false,i=()=>{r||(r=true,l(),clearTimeout(a),n());},l=watchAccount(e,{onChange:s=>{t(s.status)||i();}}),a=setTimeout(i,o);}):Promise.resolve()}function Se(e){let o=r=>e.find(i=>i.id===r||i.type===r),t=o("injected"),n=typeof window<"u"&&window.ethereum!=null;return t&&n?t:o("walletConnect")??t??e[0]}var xe=9e4;async function Ge(e){try{let n=(await getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,r=n?.native||n?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function Le(e,o){return new Promise((t,n)=>{let r=setTimeout(()=>n(new Error("The wallet request timed out.")),o);e.then(i=>{clearTimeout(r),t(i);},i=>{clearTimeout(r),n(i instanceof Error?i:new Error(String(i)));});})}function J(e){let{client:o,networkID:t,onAuthenticated:n,disabled:r,label:i,style:l,autoStart:a}=e,s=useConfig(),{isConnected:P}=useAccount(),{connectAsync:W,connectors:E}=useConnect(),c=y(),[w,A]=useState(false),[D,m]=useState(null),[R,B]=useState(false),I=useRef(0),S=useRef(false),x=async()=>{let X=++I.current,d=()=>I.current===X;A(true),m(null);try{if(await Ie(s),!d())return;if(!getAccount(s).isConnected){let C=b$1();if(C){if(await C.open(),!await Be(s)){m("No wallet was connected.");return}}else {let G=Se(E);if(!G){m("No wallet connector is configured.");return}try{await W({connector:G});}catch(L){if(!De(L))throw L}}}let p$1=c??await z(s);if(!p$1&&getAccount(s).isConnected&&(await new Promise(C=>setTimeout(C,300)),p$1=await z(s),!d()))return;if(!p$1){m("Wallet client is not available.");return}B(!0);let T=await Le(p({client:o,clients:p$1,networkID:t}),xe);if(!d())return;if(T.ok){n();return}m(T.stage==="sign"?"Signature declined.":T.error??"Wallet sign-in failed.");}catch(p){if(!d())return;console.error("[idosgames/wallet] wallet sign-in failed:",p),m(Re(p));}finally{d()&&(A(false),B(false));}};useEffect(()=>{!a||S.current||(S.current=true,x());},[a]);let V=async()=>{await Ge(s)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{R?V():x();},disabled:r,style:{...Fe,...r?{opacity:.6,cursor:"default"}:null,...l},children:R?"Waiting for signature \u2014 tap to open wallet":w?"Check your wallet\u2026":P?i??"Sign in with wallet":"Connect wallet"}),D&&jsx("span",{role:"alert",style:Oe,children:D})]})}var Fe={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Oe={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{k as IDosGamesWalletProvider,Ae as WalletLogin,J as WalletLoginButton,ue as createEvmWalletConfig,Pe as useEvmBridge,y as useEvmBridgeClients};
1
+ import {o,n,i,h as h$1,p}from'../chunk-DMMHCUIU.js';import {a as a$1,b as b$2}from'../chunk-ZL42KPPC.js';import {b as b$1,c as c$1}from'../chunk-K62NMX3A.js';import {a,b,c,d,e,f,g,h,k}from'../chunk-HQNS6ZWL.js';export{e as arbitrum,d as base,b as bsc,j as chainById,i as idosChains,a as mainnet,f as optimism,c as polygon,h as polygonAmoy,g as sepolia}from'../chunk-HQNS6ZWL.js';import {http,createConfig,WagmiProvider,useAccount,usePublicClient,useWalletClient,useConfig,useConnect,useDisconnect,useSwitchChain}from'wagmi';import {injected,coinbaseWallet}from'wagmi/connectors';import {WagmiAdapter}from'@reown/appkit-adapter-wagmi';import {createAppKit}from'@reown/appkit/react';import {QueryClient,QueryClientProvider}from'@tanstack/react-query';import {useState,useRef,useEffect,useMemo,useReducer}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getAccount,watchAccount,getWalletClient,getPublicClient}from'wagmi/actions';import {parseUnits}from'viem';var we=[a,b,c,d,e,f,g,h],oe=new Map;function ne(e){let{chains:o=we,walletConnectProjectId:t,appName:n,appUrl:i,appIcon:s,transports:g,connectors:l}=e,c=t??"__extension_only__";if(!l){let p=oe.get(c);if(p)return p}let C={};for(let p of o)C[p.id]=g?.[p.id]??http();let h=i??(typeof window<"u"?window.location.origin:""),b={name:n??"iDosGames",description:n??"iDosGames game",url:h,icons:s?[s]:[]};if(t&&!l){let p=o.map(k),k$1=new WagmiAdapter({networks:p,projectId:t,transports:C});return a$1(createAppKit({adapters:[k$1],networks:p,projectId:t,metadata:b,features:{analytics:false,email:false,socials:false}})),oe.set(c,k$1.wagmiConfig),k$1.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:n??"iDosGames"})],I=createConfig({chains:o,connectors:D,transports:C});return l||oe.set(c,I),I}function j(e){let{wagmiConfig:o,queryClient:t,children:n}=e,[i]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:o,children:jsx(QueryClientProvider,{client:i,children:n})})}function U(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var L="Wallet not connected.";function re(e,o$1){let t=U();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,i)=>t?p({client:e,clients:t,networkID:n,walletAddress:i}):Promise.resolve(c$1("challenge",L)),depositToken:n=>t?h$1({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b$1("approve",L)),depositNft:n=>t?i({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b$1("deposit-onchain",L)),withdrawToken:n$1=>t?n({client:e,clients:t,...n$1}):Promise.resolve(b$1("withdraw-onchain",L)),withdrawNft:n=>t?o({client:e,clients:t,...n}):Promise.resolve(b$1("withdraw-onchain",L))}}function Je(e){let{wagmiConfig:o,...t}=e;return jsx(j,{wagmiConfig:o,children:jsx(ke,{...t})})}function Xe(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Ye(e){let o="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":o:o}async function he(e){let o=await getWalletClient(e).catch(()=>null);if(!o)return null;let t=getPublicClient(e);return t?{account:o.account.address,publicClient:t,walletClient:o}:null}function Ze(e,o=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let n=false,i=l=>{n||(n=true,s(),clearTimeout(g),t(l));},s=watchAccount(e,{onChange:l=>{l.isConnected&&i(true);}}),g=setTimeout(()=>i(false),o);})}function et(e,o=8e3){let t=n=>n==="reconnecting"||n==="connecting";return t(getAccount(e).status)?new Promise(n=>{let i=false,s=()=>{i||(i=true,g(),clearTimeout(l),n());},g=watchAccount(e,{onChange:c=>{t(c.status)||s();}}),l=setTimeout(s,o);}):Promise.resolve()}function tt(e){let o=i=>e.find(s=>s.id===i||s.type===i),t=o("injected"),n=typeof window<"u"&&window.ethereum!=null;return t&&n?t:o("walletConnect")??t??e[0]}var ot=9e4;async function nt(e){try{let n=(await getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=n?.native||n?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function rt(e,o){return new Promise((t,n)=>{let i=setTimeout(()=>n(new Error("The wallet request timed out.")),o);e.then(s=>{clearTimeout(i),t(s);},s=>{clearTimeout(i),n(s instanceof Error?s:new Error(String(s)));});})}function ke(e){let{client:o,networkID:t,onAuthenticated:n,disabled:i,label:s,style:g,autoStart:l}=e,c=useConfig(),{isConnected:C}=useAccount(),{connectAsync:h,connectors:b}=useConnect(),D=U(),[I,p$1]=useState(false),[k,u]=useState(null),[A,w]=useState(false),B=useRef(0),T=useRef(false),F=async()=>{let S=++B.current,P=()=>B.current===S;p$1(true),u(null);try{if(await et(c),!P())return;if(!getAccount(c).isConnected){let y=b$2();if(y){if(await y.open(),!await Ze(c)){u("No wallet was connected.");return}}else {let z=tt(b);if(!z){u("No wallet connector is configured.");return}try{await h({connector:z});}catch(N){if(!Xe(N))throw N}}}let f=D??await he(c);if(!f&&getAccount(c).isConnected&&(await new Promise(y=>setTimeout(y,300)),f=await he(c),!P()))return;if(!f){u("Wallet client is not available.");return}w(!0);let v=await rt(p({client:o,clients:f,networkID:t}),ot);if(!P())return;if(v.ok){n();return}u(v.stage==="sign"?"Signature declined.":v.error??"Wallet sign-in failed.");}catch(f){if(!P())return;console.error("[idosgames/wallet] wallet sign-in failed:",f),u(Ye(f));}finally{P()&&(p$1(false),w(false));}};useEffect(()=>{!l||T.current||(T.current=true,F());},[l]);let x=async()=>{await nt(c)||await b$2()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{A?x():F();},disabled:i,style:{...it,...i?{opacity:.6,cursor:"default"}:null,...g},children:A?"Waiting for signature \u2014 tap to open wallet":I?"Check your wallet\u2026":C?s??"Sign in with wallet":"Connect wallet"}),k&&jsx("span",{role:"alert",style:st,children:k})]})}var it={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},st={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var gt={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},yt={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},se={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},wt={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},K={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},ae={display:"flex",gap:8};function Ct(e){let{client:o,walletConnectProjectId:t,appName:n,onClose:i,style:s}=e,[g,l]=useState(t??"");useEffect(()=>{if(t)return;let C=true;return (async()=>{let h=await o.blockchain.getDefinitions();if(!C||!h.ok)return;let b=h.data.Blockchain?.WalletLogin?.WalletConnectProjectId;b&&l(b);})(),()=>{C=false;}},[o,t]);let c=useMemo(()=>ne({walletConnectProjectId:g||void 0,appName:n}),[g,n]);return jsx(j,{wagmiConfig:c,children:jsx(vt,{client:o,appName:n,onClose:i,style:s})})}function vt({client:e,onClose:o,style:t}){let n=re(e,e.titleID),{address:i,isConnected:s,chainId:g}=useAccount(),{connect:l,connectors:c}=useConnect(),{disconnect:C}=useDisconnect(),{switchChainAsync:h}=useSwitchChain(),[,b]=useReducer(r=>r+1,0),[D,I]=useState({}),[p,k]=useState({}),[u,A]=useState(""),[w,B]=useState(""),[T,F]=useState(""),[x,S]=useState(false),[P,f]=useState(null);useEffect(()=>{let r=true;return (async()=>{let d=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!r||!d.ok)return;let R=d.data.Blockchain?.Networks??{},H={};for(let[Ee,ce]of Object.entries(R))ce.Type==="EVM"&&(H[Ee]=ce);I(H),k(d.data.CryptoCurrencies??{});let Ne=Object.keys(H)[0]??"";A(Ne);})(),()=>{r=false;}},[e]),useEffect(()=>e.on("user:anyUpdated",b),[e]);let v=useMemo(()=>Object.entries(p).filter(([,r])=>r.Networks?.some(d=>d.NetworkID===u&&!!d.ContractAddress)),[p,u]);useEffect(()=>{let r=v[0]?.[0]??"";B(d=>v.some(([R])=>R===d)?d:r);},[v]);let y=u?D[u]:void 0,N=(w?p[w]:void 0)?.Networks?.find(r=>r.NetworkID===u),We=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function le(){if(!y?.ChainID||g===y.ChainID)return true;try{return await h({chainId:y.ChainID}),!0}catch{return f({ok:false,stage:"approve",error:`Switch your wallet to chain ${y.ChainID} to continue.`}),false}}async function De(){if(!(!y||!N?.ContractAddress)){if(S(true),f(null),await le()){let r=N.Decimals??18,d;try{d=parseUnits(T||"0",r);}catch{f({ok:false,stage:"approve",error:"Invalid amount."}),S(false);return}let R=await n.depositToken({network:y,tokenAddress:N.ContractAddress,amount:d});f(R),R.ok&&await e.blockchain.getUserState();}S(false);}}async function Se(){if(!(!y||!n.account)){if(S(true),f(null),await le()){let r=await n.withdrawToken({currencyID:w,networkID:u,walletAddress:n.account,amount:T||"0"});f(r),r.ok&&await e.blockchain.getUserState();}S(false);}}return jsxs("div",{style:{...gt,...t},children:[jsxs("div",{style:{...ae,justifyContent:"space-between"},children:[jsx("span",{style:yt,children:"Crypto wallet"}),o&&jsx("button",{type:"button",style:K,onClick:o,children:"\u2715"})]}),s?jsxs("div",{style:ae,children:[jsxs("span",{style:{...E,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsx("button",{type:"button",style:K,onClick:()=>C(),children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:E,children:"Connect a browser or mobile wallet"}),c.map(r=>jsx("button",{type:"button",style:K,onClick:()=>l({connector:r}),children:r.name},r.uid))]}),Object.keys(D).length===0?jsx("span",{style:E,children:"No EVM networks configured for this title."}):jsxs(Fragment,{children:[jsxs("div",{children:[jsx("div",{style:E,children:"Network"}),jsx("select",{style:se,value:u,onChange:r=>A(r.target.value),children:Object.entries(D).map(([r,d])=>jsx("option",{value:r,children:d.DisplayName??r},r))})]}),jsxs("div",{children:[jsx("div",{style:E,children:"Token"}),jsxs("select",{style:se,value:w,onChange:r=>B(r.target.value),children:[v.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),v.map(([r,d])=>jsx("option",{value:r,children:d.DisplayName??r},r))]})]}),jsxs("div",{style:E,children:["In-game balance: ",jsx("b",{children:We})," ",w]}),jsxs("div",{children:[jsx("div",{style:E,children:"Amount"}),jsx("input",{style:se,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:ae,children:[jsx("button",{type:"button",style:{...wt,flex:1,opacity:x?.6:1},disabled:x||!s||!N?.ContractAddress,onClick:()=>{De();},children:"Deposit"}),jsx("button",{type:"button",style:{...K,flex:1,opacity:x?.6:1},disabled:x||!s||!w,onClick:()=>{Se();},children:"Withdraw"})]})]}),P&&jsx(ht,{result:P})]})}function ht({result:e}){let o={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxs("div",{style:o,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxs("div",{style:o,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{we as DEFAULT_EVM_CHAINS,j as IDosGamesWalletProvider,Je as WalletLogin,ke as WalletLoginButton,Ct as WalletPanel,ne as createEvmWalletConfig,re as useEvmBridge,U as useEvmBridgeClients};
@@ -1,2 +1,2 @@
1
- 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react$1=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions'),appkitAdapterSolana=require('@reown/appkit-adapter-solana');var ut=Object.defineProperty;var f=(t,e)=>()=>(t&&(e=t(t=0)),e);var Se=(t,e)=>{for(var n in e)ut(t,n,{get:e[n],enumerable:true});};function se(t){return Object.values(exports.idosChains).find(e=>e.id===t)}function xe(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}exports.mainnet=void 0;exports.bsc=void 0;exports.polygon=void 0;exports.base=void 0;exports.arbitrum=void 0;exports.optimism=void 0;exports.sepolia=void 0;exports.polygonAmoy=void 0;exports.idosChains=void 0;exports.solanaMainnet=void 0;exports.solanaDevnet=void 0;var D=f(()=>{exports.mainnet={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},exports.bsc={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},exports.polygon={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},exports.base={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},exports.arbitrum={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},exports.optimism={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},exports.sepolia={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},exports.polygonAmoy={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},exports.idosChains={mainnet:exports.mainnet,bsc:exports.bsc,polygon:exports.polygon,base:exports.base,arbitrum:exports.arbitrum,optimism:exports.optimism,sepolia:exports.sepolia,polygonAmoy:exports.polygonAmoy};exports.solanaMainnet={id:"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",name:"Solana",network:"solana-mainnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.mainnet-beta.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:false,chainNamespace:"solana",caipNetworkId:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"},exports.solanaDevnet={id:"EtWTRABZaYq6iMfeYKouRu166VU2xqa1",name:"Solana Devnet",network:"solana-devnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.devnet.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:true,chainNamespace:"solana",caipNetworkId:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"};});function ne(t){Ee=t;}function I(){return Ee}var Ee,O=f(()=>{Ee=null;});function De(t){let{chains:e,walletConnectProjectId:n,appName:o,appUrl:i,appIcon:r,transports:c,connectors:s}=t,a={};for(let u of e)a[u.id]=c?.[u.id]??wagmi.http();let p=i??(typeof window<"u"?window.location.origin:""),l={name:o??"iDosGames",description:o??"iDosGames game",url:p,icons:r?[r]:[]};if(n&&!s){let u=e.map(xe),g=new appkitAdapterWagmi.WagmiAdapter({networks:u,projectId:n,transports:a});return ne(react$1.createAppKit({adapters:[g],networks:u,projectId:n,metadata:l,features:{analytics:false,email:false,socials:false}})),g.wagmiConfig}let m=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})];return wagmi.createConfig({chains:e,connectors:m,transports:a})}var Ie=f(()=>{D();O();});function oe(t){let{wagmiConfig:e,queryClient:n,children:o}=t,[i]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:e,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,children:o})})}var ce=f(()=>{});var re,Re,pe,Be,de=f(()=>{re=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],Re=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],pe=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],Be=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];});function Le(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}var Me=f(()=>{});async function E(t,e){let{walletClient:n,publicClient:o,account:i}=t,r=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:i,chain:n.chain,value:e.value});if((await o.waitForTransactionReceipt({hash:r})).status==="reverted")throw new Error(`On-chain transaction reverted (${r}).`);return r}var ue=f(()=>{});function w(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function d(t,e,n){return {ok:false,stage:t,error:e,...n}}function h(t,e){return {ok:false,stage:t,error:e}}var P=f(()=>{});function Fe(t){let e=t.RewardPoolAddress;return e||null}async function Ke(t,e,n,o){return await t.publicClient.readContract({address:e,abi:pe,functionName:"allowance",args:[t.account,n]})>=o?null:E(t,{address:e,abi:pe,functionName:"approve",args:[n,o]})}async function me(t){let{client:e,clients:n,network:o,tokenAddress:i,amount:r,titleID:c,category:s}=t,a=e.auth.context?.userID;if(!a)return d("approve","Not logged in.");let p=Fe(o);if(!p)return d("approve","Network has no RewardPoolAddress.");if(r<=0n)return d("approve","Amount must be positive.");try{await Ke(n,i,p,r);}catch(u){return d("approve",w(u))}let l;try{l=await E(n,{address:p,abi:re,functionName:"depositERC20",args:[i,r,a,c,s??""]});}catch(u){return d("deposit-onchain",w(u))}let m=await e.blockchain.depositToken(o.NetworkID??"",l);return m.ok?{ok:true,onChainTxHash:l,data:m.data}:d("report",m.error,{onChainTxHash:l})}async function ge(t){let{client:e,clients:n,network:o,nftContractAddress:i,tokenId:r,amount:c,titleID:s,category:a}=t,p=e.auth.context?.userID;if(!p)return d("deposit-onchain","Not logged in.");let l=Fe(o);if(!l)return d("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return d("deposit-onchain","Amount must be positive.");let m=Le(p,s,a),u;try{u=await E(n,{address:i,abi:Be,functionName:"safeTransferFrom",args:[n.account,l,r,c,m]});}catch(y){return d("deposit-onchain",w(y))}let g=await e.blockchain.depositNFT(o.NetworkID??"",u);return g.ok?{ok:true,onChainTxHash:u,data:g.data}:d("report",g.error,{onChainTxHash:u})}var He=f(()=>{de();Me();ue();P();});async function Ge(t,e){return E(t,{address:e.ContractAddress,abi:re,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function Oe(t,e){return E(t,{address:e.ContractAddress,abi:Re,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function fe(t){let{client:e,clients:n,currencyID:o,networkID:i,walletAddress:r,amount:c,category:s}=t,a=await e.blockchain.requestTokenWithdrawal(o,i,r,c,s);if(!a.ok)return d("request",a.error);let p=a.data.EvmSignature,l=a.data.TitleTransactionID??void 0;if(!p)return d("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let m;try{m=await Ge(n,p);}catch(g){return d("withdraw-onchain",w(g),{titleTransactionID:l})}let u=await Ue(e,l,m);return u.ok?{ok:true,onChainTxHash:m,data:a.data}:u}async function ye(t){let{client:e,clients:n,itemID:o,networkID:i,walletAddress:r,amount:c,category:s}=t,a=await e.blockchain.requestNFTWithdrawal(o,i,r,c,s);if(!a.ok)return d("request",a.error);let p=a.data.EvmSignature,l=a.data.TitleTransactionID??void 0;if(!p)return d("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let m;try{m=await Oe(n,p);}catch(g){return d("withdraw-onchain",w(g),{titleTransactionID:l})}let u=await Ue(e,l,m);return u.ok?{ok:true,onChainTxHash:m,data:a.data}:u}async function Ue(t,e,n){if(!e)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await t.blockchain.confirmWithdrawal(e,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:d("confirm",o.error,{onChainTxHash:n,titleTransactionID:e})}var qe=f(()=>{de();ue();P();});async function U(t){let{client:e,clients:n,networkID:o}=t,i=t.walletAddress??n.account,r=await e.auth.requestWalletChallenge(i,o);if(!r.ok)return h("challenge",r.error);let c;try{c=await n.walletClient.signMessage({account:n.account,message:r.data.Message});}catch(a){return h("sign",w(a))}let s=await e.auth.loginWithWallet(i,o,c);return s.ok?{ok:true,data:s.data}:h("login",s.error)}var ze=f(()=>{P();});var we=f(()=>{He();qe();ze();});function z(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}function je(t,e){let n=z();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,i)=>n?U({client:t,clients:n,networkID:o,walletAddress:i}):Promise.resolve(h("challenge",q)),depositToken:o=>n?me({client:t,clients:n,titleID:e,...o}):Promise.resolve(d("approve",q)),depositNft:o=>n?ge({client:t,clients:n,titleID:e,...o}):Promise.resolve(d("deposit-onchain",q)),withdrawToken:o=>n?fe({client:t,clients:n,...o}):Promise.resolve(d("withdraw-onchain",q)),withdrawNft:o=>n?ye({client:t,clients:n,...o}):Promise.resolve(d("withdraw-onchain",q))}}var q,he=f(()=>{we();P();q="Wallet not connected.";});function Ve(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(oe,{wagmiConfig:e,children:jsxRuntime.jsx(be,{...n})})}function Lt(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function Mt(t){let e="Wallet sign-in failed. Please try again.";return t instanceof Error?t.name==="ProviderNotFoundError"||/provider not found/i.test(t.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":t.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(t.message)?"Request declined in the wallet.":/timed? ?out/i.test(t.message)?"The wallet did not respond. Open your wallet and try again.":e:e}async function Ye(t){let e=await actions.getWalletClient(t).catch(()=>null);if(!e)return null;let n=actions.getPublicClient(t);return n?{account:e.account.address,publicClient:n,walletClient:e}:null}function Ft(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,i=s=>{o||(o=true,r(),clearTimeout(c),n(s));},r=actions.watchAccount(t,{onChange:s=>{s.isConnected&&i(true);}}),c=setTimeout(()=>i(false),e);})}function Kt(t,e=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(t).status)?new Promise(o=>{let i=false,r=()=>{i||(i=true,c(),clearTimeout(s),o());},c=actions.watchAccount(t,{onChange:a=>{n(a.status)||r();}}),s=setTimeout(r,e);}):Promise.resolve()}function Ht(t){let e=i=>t.find(r=>r.id===i||r.type===i),n=e("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:e("walletConnect")??n??t[0]}async function Ot(t){try{let o=(await actions.getAccount(t).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=o?.native||o?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function Ut(t,e){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),e);t.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function be(t){let{client:e,networkID:n,onAuthenticated:o,disabled:i,label:r,style:c,autoStart:s}=t,a=wagmi.useConfig(),{isConnected:p}=wagmi.useAccount(),{connectAsync:l,connectors:m}=wagmi.useConnect(),u=z(),[g,y]=react.useState(false),[C,b]=react.useState(null),[B,L]=react.useState(false),S=react.useRef(0),M=react.useRef(false),W=async()=>{let K=++S.current,x=()=>S.current===K;y(true),b(null);try{if(await Kt(a),!x())return;if(!actions.getAccount(a).isConnected){let A=I();if(A){if(await A.open(),!await Ft(a)){b("No wallet was connected.");return}}else {let H=Ht(m);if(!H){b("No wallet connector is configured.");return}try{await l({connector:H});}catch(v){if(!Lt(v))throw v}}}let k=u??await Ye(a);if(!k&&actions.getAccount(a).isConnected&&(await new Promise(A=>setTimeout(A,300)),k=await Ye(a),!x()))return;if(!k){b("Wallet client is not available.");return}L(!0);let T=await Ut(U({client:e,clients:k,networkID:n}),Gt);if(!x())return;if(T.ok){o();return}b(T.stage==="sign"?"Signature declined.":T.error??"Wallet sign-in failed.");}catch(k){if(!x())return;console.error("[idosgames/wallet] wallet sign-in failed:",k),b(Mt(k));}finally{x()&&(y(false),L(false));}};react.useEffect(()=>{!s||M.current||(M.current=true,W());},[s]);let F=async()=>{await Ot(a)||await I()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{B?F():W();},disabled:i,style:{...qt,...i?{opacity:.6,cursor:"default"}:null,...c},children:B?"Waiting for signature \u2014 tap to open wallet":g?"Check your wallet\u2026":p?r??"Sign in with wallet":"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:zt,children:C})]})}var Gt,qt,zt,Ze=f(()=>{O();we();ce();he();Gt=9e4;qt={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},zt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var $e={};Se($e,{IDosGamesWalletProvider:()=>oe,WalletLogin:()=>Ve,WalletLoginButton:()=>be,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>se,createEvmWalletConfig:()=>De,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>je,useEvmBridgeClients:()=>z});var Je=f(()=>{Ie();D();ce();he();Ze();});function Xe(t){let{walletConnectProjectId:e,appName:n,appUrl:o,appIcon:i,wallets:r}=t,c=t.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),a={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:i?[i]:[]},p=new appkitAdapterSolana.SolanaAdapter(r?{wallets:r}:{});return ne(react$1.createAppKit({adapters:[p],networks:c,projectId:e,metadata:a,features:{analytics:false,email:false,socials:false}})),p}var et=f(()=>{D();O();});async function ke(t){let{client:e,adapter:n,network:o,mint:i,amountRaw:r,titleID:c,category:s}=t,a=e.auth.context?.userID;if(!a)return d("deposit-onchain","Not logged in.");if(r<=0n)return d("deposit-onchain","Amount must be positive.");let p;try{p=await n.depositSpl({mint:i,amountRaw:r,userID:a,titleID:c,category:core.normalizeBlockchainCategory(s)});}catch(m){return d("deposit-onchain",w(m))}let l=await e.blockchain.depositToken(o.NetworkID??"",p);return l.ok?{ok:true,onChainTxHash:p,data:l.data}:d("report",l.error,{onChainTxHash:p})}async function ve(t){let{client:e,adapter:n,currencyID:o,networkID:i,walletAddress:r,amount:c,category:s}=t,a=await e.blockchain.requestTokenWithdrawal(o,i,r,c,s);if(!a.ok)return d("request",a.error);let p=a.data.SolanaSignature,l=a.data.TitleTransactionID??void 0;if(!p)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let m;try{m=await n.submitWithdrawal(p);}catch(g){return d("withdraw-onchain",w(g),{titleTransactionID:l})}if(!l)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:m});let u=await e.blockchain.confirmWithdrawal(l,m);return u.ok?{ok:true,onChainTxHash:m,data:a.data}:d("confirm",u.error,{onChainTxHash:m,titleTransactionID:l})}var tt=f(()=>{P();});async function _(t){let{client:e,networkID:n,walletAddress:o,signMessage:i}=t,r=await e.auth.requestWalletChallenge(o,n);if(!r.ok)return h("challenge",r.error);let c;try{let a=await i(new TextEncoder().encode(r.data.Message));c=Zt(a);}catch(a){return h("sign",w(a))}let s=await e.auth.loginWithWallet(o,n,c);return s.ok?{ok:true,data:s.data}:h("login",s.error)}function Zt(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}var nt=f(()=>{P();});var We=f(()=>{tt();nt();});function rt(t,e,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:i}=react$1.useAppKitProvider("solana"),r=o??null,c=i?.signMessage?.bind(i);return {connected:!!r,account:r,loginWithWallet:(s,a)=>{let p=a??r;return p?c?_({client:t,networkID:s,walletAddress:p,signMessage:c}):Promise.resolve(h("sign","The connected wallet does not support message signing.")):Promise.resolve(h("challenge",ot))},depositToken:s=>ke({client:t,adapter:n,titleID:e,...s}),withdrawToken:s=>{let a=s.walletAddress??r;return a?ve({client:t,adapter:n,...s,walletAddress:a}):Promise.resolve(d("request",ot))}}}var ot,at=f(()=>{We();P();ot="Wallet not connected.";});function on(t){try{let n=t?.session?.peer?.metadata?.redirect,o=n?.native||n?.universal;return !o||typeof window>"u"?!1:(window.location.href=o,!0)}catch{return false}}function rn(t,e){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),e);t.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function an(t){let e="Wallet sign-in failed. Please try again.";return t instanceof Error?/user (rejected|denied|cancelled|canceled)|rejected the request/i.test(t.message)?"Request declined in the wallet.":/timed? ?out/i.test(t.message)?"The wallet did not respond. Open your wallet and try again.":e:e}function st(t){let{client:e,networkID:n,onAuthenticated:o,disabled:i,label:r,style:c,autoStart:s}=t,{address:a,isConnected:p}=react$1.useAppKitAccount(),{walletProvider:l}=react$1.useAppKitProvider("solana"),[m,u]=react.useState(false),[g,y]=react.useState(null),[C,b]=react.useState(false),[B,L]=react.useState(false),S=react.useRef(null),M=react.useRef(0),W=react.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null;},[]);react.useEffect(()=>W,[W]);let F=react.useRef(false),K=react.useCallback(async()=>{let T=++M.current,A=()=>M.current===T,H=l?.signMessage?.bind(l);if(!a||!H){y("The connected wallet cannot sign messages."),u(false);return}u(true),y(null);try{L(!0);let v=await rn(_({client:e,networkID:n,walletAddress:a,signMessage:H}),nn);if(!A())return;if(v.ok){o();return}y(v.stage==="sign"?"Signature declined.":v.error??"Wallet sign-in failed.");}catch(v){if(!A())return;console.error("[idosgames/wallet] solana sign-in failed:",v),y(an(v));}finally{A()&&(u(false),L(false));}},[a,l,e,n,o]),x=react.useCallback(()=>{on(l)||I()?.open();},[l]);react.useEffect(()=>{!C||!p||!a||!l||(b(false),W(),K());},[C,p,a,l,K,W]);let k=()=>{if(B){x();return}if(y(null),F.current=true,p&&a&&l){K();return}let T=I();if(!T){y("Wallet sign-in is not configured for this title.");return}u(true),b(true),W(),S.current=setTimeout(()=>{b(false),u(false),y("No wallet was connected.");},tn),T.open();};return react.useEffect(()=>{!s||F.current||(F.current=true,k());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:k,disabled:i,style:{...sn,...i?{opacity:.6,cursor:"default"}:null,...c},children:B?"Waiting for signature \u2014 tap to open wallet":m?"Check your wallet\u2026":p?r??"Sign in with wallet":"Connect wallet"}),g&&jsxRuntime.jsx("span",{role:"alert",style:ln,children:g})]})}var tn,nn,sn,ln,lt=f(()=>{We();O();tn=18e4,nn=9e4;sn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ln={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var ct={};Se(ct,{SolanaWalletLogin:()=>st,createSolanaWalletConfig:()=>Xe,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>rt});var pt=f(()=>{et();at();lt();D();});var dn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},un={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function dt(t){let{loading:e,disabled:n,label:o,style:i,error:r,onClick:c}=t;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:c,disabled:n||e,style:{...dn,...n||e?{opacity:.6,cursor:"default"}:null,...i},children:e?"Loading wallet\u2026":o??"Sign in with wallet"}),r&&jsxRuntime.jsx("span",{role:"alert",style:un,children:r})]})}function mn(t){let{chains:e,walletConnectProjectId:n,appName:o,disabled:i,label:r,style:c,...s}=t,[a,p]=react.useState(null),[l,m]=react.useState(false),[u,g]=react.useState(null),y=()=>{m(true),g(null),(async()=>{try{let C=await Promise.resolve().then(()=>(Je(),$e)),b=C.createEvmWalletConfig({chains:e,walletConnectProjectId:n,appName:o});p({mod:C,config:b});}catch(C){console.error("[idosgames/wallet] failed to load the wallet module:",C),g("Could not load the wallet. Please try again.");}finally{m(false);}})();};if(a){let{WalletLogin:C}=a.mod;return jsxRuntime.jsx(C,{...s,wagmiConfig:a.config,disabled:i,label:r,style:c,autoStart:true})}return jsxRuntime.jsx(dt,{loading:l,disabled:i,label:r,style:c,error:u,onClick:y})}function gn(t){let{walletConnectProjectId:e,appName:n,disabled:o,label:i,style:r,...c}=t,[s,a]=react.useState(null),[p,l]=react.useState(false),[m,u]=react.useState(null),g=()=>{l(true),u(null),(async()=>{try{let y=await Promise.resolve().then(()=>(pt(),ct));e&&y.createSolanaWalletConfig({walletConnectProjectId:e,appName:n}),a(y);}catch(y){console.error("[idosgames/wallet] failed to load the wallet module:",y),u("Could not load the wallet. Please try again.");}finally{l(false);}})();};if(s){let{SolanaWalletLogin:y}=s;return jsxRuntime.jsx(y,{...c,disabled:o,label:i,style:r,autoStart:true})}return jsxRuntime.jsx(dt,{loading:p,disabled:o,label:i,style:r,error:m,onClick:g})}D();
2
- exports.LazySolanaWalletLogin=gn;exports.LazyWalletLogin=mn;exports.chainById=se;
1
+ 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react$1=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions'),appkitAdapterSolana=require('@reown/appkit-adapter-solana');var Ft=Object.defineProperty;var w=(e,t)=>()=>(e&&(t=e(e=0)),t);var $e=(e,t)=>{for(var n in t)Ft(e,n,{get:t[n],enumerable:true});};function ke(e){return Object.values(exports.idosChains).find(t=>t.id===e)}function Ye(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}exports.mainnet=void 0;exports.bsc=void 0;exports.polygon=void 0;exports.base=void 0;exports.arbitrum=void 0;exports.optimism=void 0;exports.sepolia=void 0;exports.polygonAmoy=void 0;exports.idosChains=void 0;exports.solanaMainnet=void 0;exports.solanaDevnet=void 0;var X=w(()=>{exports.mainnet={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},exports.bsc={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},exports.polygon={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},exports.base={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},exports.arbitrum={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},exports.optimism={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},exports.sepolia={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},exports.polygonAmoy={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},exports.idosChains={mainnet:exports.mainnet,bsc:exports.bsc,polygon:exports.polygon,base:exports.base,arbitrum:exports.arbitrum,optimism:exports.optimism,sepolia:exports.sepolia,polygonAmoy:exports.polygonAmoy};exports.solanaMainnet={id:"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",name:"Solana",network:"solana-mainnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.mainnet-beta.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:false,chainNamespace:"solana",caipNetworkId:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"},exports.solanaDevnet={id:"EtWTRABZaYq6iMfeYKouRu166VU2xqa1",name:"Solana Devnet",network:"solana-devnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.devnet.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:true,chainNamespace:"solana",caipNetworkId:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"};});function de(e){Qe=e;}function ee(){return Qe}var Qe,oe=w(()=>{Qe=null;});function pe(e){let{chains:t=Pe,walletConnectProjectId:n,appName:o,appUrl:i,appIcon:r,transports:l,connectors:s}=e,a=n??"__extension_only__";if(!s){let f=Se.get(a);if(f)return f}let d={};for(let f of t)d[f.id]=l?.[f.id]??wagmi.http();let c=i??(typeof window<"u"?window.location.origin:""),u={name:o??"iDosGames",description:o??"iDosGames game",url:c,icons:r?[r]:[]};if(n&&!s){let f=t.map(Ye),b=new appkitAdapterWagmi.WagmiAdapter({networks:f,projectId:n,transports:d});return de(react$1.createAppKit({adapters:[b],networks:f,projectId:n,metadata:u,features:{analytics:false,email:false,socials:false}})),Se.set(a,b.wagmiConfig),b.wagmiConfig}let m=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],y=wagmi.createConfig({chains:t,connectors:m,transports:d});return s||Se.set(a,y),y}var Pe,Se,We=w(()=>{X();oe();Pe=[exports.mainnet,exports.bsc,exports.polygon,exports.base,exports.arbitrum,exports.optimism,exports.sepolia,exports.polygonAmoy],Se=new Map;});function te(e){let{wagmiConfig:t,queryClient:n,children:o}=e,[i]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,children:o})})}var ue=w(()=>{});var me,Je,xe,Xe,Ae=w(()=>{me=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],Je=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],xe=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],Xe=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];});function et(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}var tt=w(()=>{});async function O(e,t){let{walletClient:n,publicClient:o,account:i}=e,r=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:i,chain:n.chain,value:t.value});if((await o.waitForTransactionReceipt({hash:r})).status==="reverted")throw new Error(`On-chain transaction reverted (${r}).`);return r}var Te=w(()=>{});function A(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function p(e,t,n){return {ok:false,stage:e,error:t,...n}}function D(e,t){return {ok:false,stage:e,error:t}}var F=w(()=>{});function nt(e){let t=e.RewardPoolAddress;return t||null}async function ot(e,t,n,o){return await e.publicClient.readContract({address:t,abi:xe,functionName:"allowance",args:[e.account,n]})>=o?null:O(e,{address:t,abi:xe,functionName:"approve",args:[n,o]})}async function De(e){let{client:t,clients:n,network:o,tokenAddress:i,amount:r,titleID:l,category:s}=e,a=t.auth.context?.userID;if(!a)return p("approve","Not logged in.");let d=nt(o);if(!d)return p("approve","Network has no RewardPoolAddress.");if(r<=0n)return p("approve","Amount must be positive.");try{await ot(n,i,d,r);}catch(m){return p("approve",A(m))}let c;try{c=await O(n,{address:d,abi:me,functionName:"depositERC20",args:[i,r,a,l,s??""]});}catch(m){return p("deposit-onchain",A(m))}let u=await t.blockchain.depositToken(o.NetworkID??"",c);return u.ok?{ok:true,onChainTxHash:c,data:u.data}:p("report",u.error,{onChainTxHash:c})}async function Ee(e){let{client:t,clients:n,network:o,nftContractAddress:i,tokenId:r,amount:l,titleID:s,category:a}=e,d=t.auth.context?.userID;if(!d)return p("deposit-onchain","Not logged in.");let c=nt(o);if(!c)return p("deposit-onchain","Network has no RewardPoolAddress.");if(l<=0n)return p("deposit-onchain","Amount must be positive.");let u=et(d,s,a),m;try{m=await O(n,{address:i,abi:Xe,functionName:"safeTransferFrom",args:[n.account,c,r,l,u]});}catch(f){return p("deposit-onchain",A(f))}let y=await t.blockchain.depositNFT(o.NetworkID??"",m);return y.ok?{ok:true,onChainTxHash:m,data:y.data}:p("report",y.error,{onChainTxHash:m})}var rt=w(()=>{Ae();tt();Te();F();});async function at(e,t){return O(e,{address:t.ContractAddress,abi:me,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function it(e,t){return O(e,{address:t.ContractAddress,abi:Je,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Ie(e){let{client:t,clients:n,currencyID:o,networkID:i,walletAddress:r,amount:l,category:s}=e,a=await t.blockchain.requestTokenWithdrawal(o,i,r,l,s);if(!a.ok)return p("request",a.error);let d=a.data.EvmSignature,c=a.data.TitleTransactionID??void 0;if(!d)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let u;try{u=await at(n,d);}catch(y){return p("withdraw-onchain",A(y),{titleTransactionID:c})}let m=await st(t,c,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:m}async function Ne(e){let{client:t,clients:n,itemID:o,networkID:i,walletAddress:r,amount:l,category:s}=e,a=await t.blockchain.requestNFTWithdrawal(o,i,r,l,s);if(!a.ok)return p("request",a.error);let d=a.data.EvmSignature,c=a.data.TitleTransactionID??void 0;if(!d)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let u;try{u=await it(n,d);}catch(y){return p("withdraw-onchain",A(y),{titleTransactionID:c})}let m=await st(t,c,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:m}async function st(e,t,n){if(!t)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await e.blockchain.confirmWithdrawal(t,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:p("confirm",o.error,{onChainTxHash:n,titleTransactionID:t})}var lt=w(()=>{Ae();Te();F();});async function re(e){let{client:t,clients:n,networkID:o}=e,i=e.walletAddress??n.account,r=await t.auth.requestWalletChallenge(i,o);if(!r.ok)return D("challenge",r.error);let l;try{l=await n.walletClient.signMessage({account:n.account,message:r.data.Message});}catch(a){return D("sign",A(a))}let s=await t.auth.loginWithWallet(i,o,l);return s.ok?{ok:true,data:s.data}:D("login",s.error)}var ct=w(()=>{F();});var Re=w(()=>{rt();lt();ct();});function ie(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}function fe(e,t){let n=ie();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,i)=>n?re({client:e,clients:n,networkID:o,walletAddress:i}):Promise.resolve(D("challenge",ae)),depositToken:o=>n?De({client:e,clients:n,titleID:t,...o}):Promise.resolve(p("approve",ae)),depositNft:o=>n?Ee({client:e,clients:n,titleID:t,...o}):Promise.resolve(p("deposit-onchain",ae)),withdrawToken:o=>n?Ie({client:e,clients:n,...o}):Promise.resolve(p("withdraw-onchain",ae)),withdrawNft:o=>n?Ne({client:e,clients:n,...o}):Promise.resolve(p("withdraw-onchain",ae))}}var ae,ge=w(()=>{Re();F();ae="Wallet not connected.";});function mt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(te,{wagmiConfig:t,children:jsxRuntime.jsx(Le,{...n})})}function sn(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function ln(e){let t="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":t:t}async function pt(e){let t=await actions.getWalletClient(e).catch(()=>null);if(!t)return null;let n=actions.getPublicClient(e);return n?{account:t.account.address,publicClient:n,walletClient:t}:null}function cn(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,i=s=>{o||(o=true,r(),clearTimeout(l),n(s));},r=actions.watchAccount(e,{onChange:s=>{s.isConnected&&i(true);}}),l=setTimeout(()=>i(false),t);})}function dn(e,t=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(e).status)?new Promise(o=>{let i=false,r=()=>{i||(i=true,l(),clearTimeout(s),o());},l=actions.watchAccount(e,{onChange:a=>{n(a.status)||r();}}),s=setTimeout(r,t);}):Promise.resolve()}function pn(e){let t=i=>e.find(r=>r.id===i||r.type===i),n=t("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:t("walletConnect")??n??e[0]}async function mn(e){try{let o=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=o?.native||o?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function fn(e,t){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function Le(e){let{client:t,networkID:n,onAuthenticated:o,disabled:i,label:r,style:l,autoStart:s}=e,a=wagmi.useConfig(),{isConnected:d}=wagmi.useAccount(),{connectAsync:c,connectors:u}=wagmi.useConnect(),m=ie(),[y,f]=react.useState(false),[b,h]=react.useState(null),[M,P]=react.useState(false),I=react.useRef(0),L=react.useRef(false),N=async()=>{let E=++I.current,B=()=>I.current===E;f(true),h(null);try{if(await dn(a),!B())return;if(!actions.getAccount(a).isConnected){let v=ee();if(v){if(await v.open(),!await cn(a)){h("No wallet was connected.");return}}else {let z=pn(u);if(!z){h("No wallet connector is configured.");return}try{await c({connector:z});}catch(x){if(!sn(x))throw x}}}let k=m??await pt(a);if(!k&&actions.getAccount(a).isConnected&&(await new Promise(v=>setTimeout(v,300)),k=await pt(a),!B()))return;if(!k){h("Wallet client is not available.");return}P(!0);let W=await fn(re({client:t,clients:k,networkID:n}),un);if(!B())return;if(W.ok){o();return}h(W.stage==="sign"?"Signature declined.":W.error??"Wallet sign-in failed.");}catch(k){if(!B())return;console.error("[idosgames/wallet] wallet sign-in failed:",k),h(ln(k));}finally{B()&&(f(false),P(false));}};react.useEffect(()=>{!s||L.current||(L.current=true,N());},[s]);let R=async()=>{await mn(a)||await ee()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{M?R():N();},disabled:i,style:{...gn,...i?{opacity:.6,cursor:"default"}:null,...l},children:M?"Waiting for signature \u2014 tap to open wallet":y?"Check your wallet\u2026":d?r??"Sign in with wallet":"Connect wallet"}),b&&jsxRuntime.jsx("span",{role:"alert",style:yn,children:b})]})}var un,gn,yn,ft=w(()=>{oe();Re();ue();ge();un=9e4;gn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},yn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});function yt(e){let{client:t,walletConnectProjectId:n,appName:o,onClose:i,style:r}=e,[l,s]=react.useState(n??"");react.useEffect(()=>{if(n)return;let d=true;return (async()=>{let c=await t.blockchain.getDefinitions();if(!d||!c.ok)return;let u=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;u&&s(u);})(),()=>{d=false;}},[t,n]);let a=react.useMemo(()=>pe({walletConnectProjectId:l||void 0,appName:o}),[l,o]);return jsxRuntime.jsx(te,{wagmiConfig:a,children:jsxRuntime.jsx(Tn,{client:t,appName:o,onClose:i,style:r})})}function Tn({client:e,onClose:t,style:n}){let o=fe(e,e.titleID),{address:i,isConnected:r,chainId:l}=wagmi.useAccount(),{connect:s,connectors:a}=wagmi.useConnect(),{disconnect:d}=wagmi.useDisconnect(),{switchChainAsync:c}=wagmi.useSwitchChain(),[,u]=react.useReducer(g=>g+1,0),[m,y]=react.useState({}),[f,b]=react.useState({}),[h,M]=react.useState(""),[P,I]=react.useState(""),[L,N]=react.useState(""),[R,E]=react.useState(false),[B,k]=react.useState(null);react.useEffect(()=>{let g=true;return (async()=>{let S=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!g||!S.ok)return;let q=S.data.Blockchain?.Networks??{},be={};for(let[Mt,Ve]of Object.entries(q))Ve.Type==="EVM"&&(be[Mt]=Ve);y(be),b(S.data.CryptoCurrencies??{});let Lt=Object.keys(be)[0]??"";M(Lt);})(),()=>{g=false;}},[e]),react.useEffect(()=>e.on("user:anyUpdated",u),[e]);let W=react.useMemo(()=>Object.entries(f).filter(([,g])=>g.Networks?.some(S=>S.NetworkID===h&&!!S.ContractAddress)),[f,h]);react.useEffect(()=>{let g=W[0]?.[0]??"";I(S=>W.some(([q])=>q===S)?S:g);},[W]);let v=h?m[h]:void 0,x=(P?f[P]:void 0)?.Networks?.find(g=>g.NetworkID===h),Nt=P?e.data.user.getCryptoCurrencyAmount(P):"0";async function _e(){if(!v?.ChainID||l===v.ChainID)return true;try{return await c({chainId:v.ChainID}),!0}catch{return k({ok:false,stage:"approve",error:`Switch your wallet to chain ${v.ChainID} to continue.`}),false}}async function Rt(){if(!(!v||!x?.ContractAddress)){if(E(true),k(null),await _e()){let g=x.Decimals??18,S;try{S=viem.parseUnits(L||"0",g);}catch{k({ok:false,stage:"approve",error:"Invalid amount."}),E(false);return}let q=await o.depositToken({network:v,tokenAddress:x.ContractAddress,amount:S});k(q),q.ok&&await e.blockchain.getUserState();}E(false);}}async function Bt(){if(!(!v||!o.account)){if(E(true),k(null),await _e()){let g=await o.withdrawToken({currencyID:P,networkID:h,walletAddress:o.account,amount:L||"0"});k(g),g.ok&&await e.blockchain.getUserState();}E(false);}}return jsxRuntime.jsxs("div",{style:{...Wn,...n},children:[jsxRuntime.jsxs("div",{style:{...Fe,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:xn,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:we,onClick:t,children:"\u2715"})]}),r?jsxRuntime.jsxs("div",{style:Fe,children:[jsxRuntime.jsxs("span",{style:{...U,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:we,onClick:()=>d(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:U,children:"Connect a browser or mobile wallet"}),a.map(g=>jsxRuntime.jsx("button",{type:"button",style:we,onClick:()=>s({connector:g}),children:g.name},g.uid))]}),Object.keys(m).length===0?jsxRuntime.jsx("span",{style:U,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:U,children:"Network"}),jsxRuntime.jsx("select",{style:Me,value:h,onChange:g=>M(g.target.value),children:Object.entries(m).map(([g,S])=>jsxRuntime.jsx("option",{value:g,children:S.DisplayName??g},g))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:U,children:"Token"}),jsxRuntime.jsxs("select",{style:Me,value:P,onChange:g=>I(g.target.value),children:[W.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),W.map(([g,S])=>jsxRuntime.jsx("option",{value:g,children:S.DisplayName??g},g))]})]}),jsxRuntime.jsxs("div",{style:U,children:["In-game balance: ",jsxRuntime.jsx("b",{children:Nt})," ",P]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:U,children:"Amount"}),jsxRuntime.jsx("input",{style:Me,inputMode:"decimal",placeholder:"0.0",value:L,onChange:g=>N(g.target.value)})]}),jsxRuntime.jsxs("div",{style:Fe,children:[jsxRuntime.jsx("button",{type:"button",style:{...An,flex:1,opacity:R?.6:1},disabled:R||!r||!x?.ContractAddress,onClick:()=>{Rt();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...we,flex:1,opacity:R?.6:1},disabled:R||!r||!P,onClick:()=>{Bt();},children:"Withdraw"})]})]}),B&&jsxRuntime.jsx(Dn,{result:B})]})}function Dn({result:e}){let t={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxRuntime.jsxs("div",{style:t,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxRuntime.jsxs("div",{style:t,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}var Wn,xn,U,Me,An,we,Fe,wt=w(()=>{We();ue();ge();Wn={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},xn={fontWeight:700,fontSize:16},U={fontSize:12,opacity:.7},Me={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},An={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},we={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Fe={display:"flex",gap:8};});var He={};$e(He,{DEFAULT_EVM_CHAINS:()=>Pe,IDosGamesWalletProvider:()=>te,WalletLogin:()=>mt,WalletLoginButton:()=>Le,WalletPanel:()=>yt,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>ke,createEvmWalletConfig:()=>pe,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>fe,useEvmBridgeClients:()=>ie});var Ke=w(()=>{We();X();ue();ge();ft();wt();});function ht(e){let{walletConnectProjectId:t,appName:n,appUrl:o,appIcon:i,wallets:r}=e,l=e.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),a={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:i?[i]:[]},d=new appkitAdapterSolana.SolanaAdapter(r?{wallets:r}:{});return de(react$1.createAppKit({adapters:[d],networks:l,projectId:t,metadata:a,features:{analytics:false,email:false,socials:false}})),d}var Ct=w(()=>{X();oe();});async function Ge(e){let{client:t,adapter:n,network:o,mint:i,amountRaw:r,titleID:l,category:s}=e,a=t.auth.context?.userID;if(!a)return p("deposit-onchain","Not logged in.");if(r<=0n)return p("deposit-onchain","Amount must be positive.");let d;try{d=await n.depositSpl({mint:i,amountRaw:r,userID:a,titleID:l,category:core.normalizeBlockchainCategory(s)});}catch(u){return p("deposit-onchain",A(u))}let c=await t.blockchain.depositToken(o.NetworkID??"",d);return c.ok?{ok:true,onChainTxHash:d,data:c.data}:p("report",c.error,{onChainTxHash:d})}async function Oe(e){let{client:t,adapter:n,currencyID:o,networkID:i,walletAddress:r,amount:l,category:s}=e,a=await t.blockchain.requestTokenWithdrawal(o,i,r,l,s);if(!a.ok)return p("request",a.error);let d=a.data.SolanaSignature,c=a.data.TitleTransactionID??void 0;if(!d)return p("request","Withdrawal response carried no Solana signature.",{titleTransactionID:c});let u;try{u=await n.submitWithdrawal(d);}catch(y){return p("withdraw-onchain",A(y),{titleTransactionID:c})}if(!c)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:u});let m=await t.blockchain.confirmWithdrawal(c,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:p("confirm",m.error,{onChainTxHash:u,titleTransactionID:c})}var bt=w(()=>{F();});async function le(e){let{client:t,networkID:n,walletAddress:o,signMessage:i}=e,r=await t.auth.requestWalletChallenge(o,n);if(!r.ok)return D("challenge",r.error);let l;try{let a=await i(new TextEncoder().encode(r.data.Message));l=Bn(a);}catch(a){return D("sign",A(a))}let s=await t.auth.loginWithWallet(o,n,l);return s.ok?{ok:true,data:s.data}:D("login",s.error)}function Bn(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}var kt=w(()=>{F();});var Ue=w(()=>{bt();kt();});function St(e,t,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:i}=react$1.useAppKitProvider("solana"),r=o??null,l=i?.signMessage?.bind(i);return {connected:!!r,account:r,loginWithWallet:(s,a)=>{let d=a??r;return d?l?le({client:e,networkID:s,walletAddress:d,signMessage:l}):Promise.resolve(D("sign","The connected wallet does not support message signing.")):Promise.resolve(D("challenge",vt))},depositToken:s=>Ge({client:e,adapter:n,titleID:t,...s}),withdrawToken:s=>{let a=s.walletAddress??r;return a?Oe({client:e,adapter:n,...s,walletAddress:a}):Promise.resolve(p("request",vt))}}}var vt,Pt=w(()=>{Ue();F();vt="Wallet not connected.";});function On(e){try{let n=e?.session?.peer?.metadata?.redirect,o=n?.native||n?.universal;return !o||typeof window>"u"?!1:(window.location.href=o,!0)}catch{return false}}function Un(e,t){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function zn(e){let t="Wallet sign-in failed. Please try again.";return e instanceof Error?/user (rejected|denied|cancelled|canceled)|rejected the request/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":t:t}function xt(e){let{client:t,networkID:n,onAuthenticated:o,disabled:i,label:r,style:l,autoStart:s}=e,{address:a,isConnected:d}=react$1.useAppKitAccount(),{walletProvider:c}=react$1.useAppKitProvider("solana"),[u,m]=react.useState(false),[y,f]=react.useState(null),[b,h]=react.useState(false),[M,P]=react.useState(false),I=react.useRef(null),L=react.useRef(0),N=react.useCallback(()=>{I.current&&clearTimeout(I.current),I.current=null;},[]);react.useEffect(()=>N,[N]);let R=react.useRef(false),E=react.useCallback(async()=>{let W=++L.current,v=()=>L.current===W,z=c?.signMessage?.bind(c);if(!a||!z){f("The connected wallet cannot sign messages."),m(false);return}m(true),f(null);try{P(!0);let x=await Un(le({client:t,networkID:n,walletAddress:a,signMessage:z}),Gn);if(!v())return;if(x.ok){o();return}f(x.stage==="sign"?"Signature declined.":x.error??"Wallet sign-in failed.");}catch(x){if(!v())return;console.error("[idosgames/wallet] solana sign-in failed:",x),f(zn(x));}finally{v()&&(m(false),P(false));}},[a,c,t,n,o]),B=react.useCallback(()=>{On(c)||ee()?.open();},[c]);react.useEffect(()=>{!b||!d||!a||!c||(h(false),N(),E());},[b,d,a,c,E,N]);let k=()=>{if(M){B();return}if(f(null),R.current=true,d&&a&&c){E();return}let W=ee();if(!W){f("Wallet sign-in is not configured for this title.");return}m(true),h(true),N(),I.current=setTimeout(()=>{h(false),m(false),f("No wallet was connected.");},Kn),W.open();};return react.useEffect(()=>{!s||R.current||(R.current=true,k());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:k,disabled:i,style:{...qn,...i?{opacity:.6,cursor:"default"}:null,...l},children:M?"Waiting for signature \u2014 tap to open wallet":u?"Check your wallet\u2026":d?r??"Sign in with wallet":"Connect wallet"}),y&&jsxRuntime.jsx("span",{role:"alert",style:jn,children:y})]})}var Kn,Gn,qn,jn,At=w(()=>{Ue();oe();Kn=18e4,Gn=9e4;qn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},jn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var Tt={};$e(Tt,{SolanaWalletLogin:()=>xt,createSolanaWalletConfig:()=>ht,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>St});var Dt=w(()=>{Ct();Pt();At();X();});var Yn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Qn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function Et(e){let{loading:t,disabled:n,label:o,style:i,error:r,onClick:l}=e;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:l,disabled:n||t,style:{...Yn,...n||t?{opacity:.6,cursor:"default"}:null,...i},children:t?"Loading wallet\u2026":o??"Sign in with wallet"}),r&&jsxRuntime.jsx("span",{role:"alert",style:Qn,children:r})]})}function Zn(e){let{chains:t,walletConnectProjectId:n,appName:o,disabled:i,label:r,style:l,...s}=e,[a,d]=react.useState(null),[c,u]=react.useState(false),[m,y]=react.useState(null),f=()=>{u(true),y(null),(async()=>{try{let b=await Promise.resolve().then(()=>(Ke(),He)),h=b.createEvmWalletConfig({chains:t,walletConnectProjectId:n,appName:o});d({mod:b,config:h});}catch(b){console.error("[idosgames/wallet] failed to load the wallet module:",b),y("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(a){let{WalletLogin:b}=a.mod;return jsxRuntime.jsx(b,{...s,wagmiConfig:a.config,disabled:i,label:r,style:l,autoStart:true})}return jsxRuntime.jsx(Et,{loading:c,disabled:i,label:r,style:l,error:m,onClick:f})}function Jn(e){let{walletConnectProjectId:t,appName:n,disabled:o,label:i,style:r,...l}=e,[s,a]=react.useState(null),[d,c]=react.useState(false),[u,m]=react.useState(null),y=()=>{c(true),m(null),(async()=>{try{let f=await Promise.resolve().then(()=>(Dt(),Tt));t&&f.createSolanaWalletConfig({walletConnectProjectId:t,appName:n}),a(f);}catch(f){console.error("[idosgames/wallet] failed to load the wallet module:",f),m("Could not load the wallet. Please try again.");}finally{c(false);}})();};if(s){let{SolanaWalletLogin:f}=s;return jsxRuntime.jsx(f,{...l,disabled:o,label:i,style:r,autoStart:true})}return jsxRuntime.jsx(Et,{loading:d,disabled:o,label:i,style:r,error:u,onClick:y})}var Xn={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",fontSize:13};function eo(e){let{onClose:t,style:n}=e,[o,i]=react.useState(null),[r,l]=react.useState(null);return react.useEffect(()=>{let s=true;return (async()=>{try{let a=await Promise.resolve().then(()=>(Ke(),He));s&&i(a);}catch(a){console.error("[idosgames/wallet] failed to load the wallet panel:",a),s&&l("Could not load the wallet.");}})(),()=>{s=false;}},[]),o?jsxRuntime.jsx(o.WalletPanel,{...e}):jsxRuntime.jsxs("div",{style:{...Xn,...n},children:[r??"Loading wallet\u2026",t&&jsxRuntime.jsx("button",{type:"button",onClick:t,style:{background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer",marginLeft:10},children:"\u2715"})]})}X();
2
+ exports.LazySolanaWalletLogin=Jn;exports.LazyWalletLogin=Zn;exports.LazyWalletPanel=eo;exports.chainById=ke;
@@ -22,10 +22,30 @@ interface LazyLoginCommonProps {
22
22
  style?: CSSProperties;
23
23
  }
24
24
  interface LazyWalletLoginProps extends LazyLoginCommonProps {
25
- /** Chains the title supports, e.g. `[bsc]` — import them from this same subpath. */
26
- chains: readonly [Chain, ...Chain[]];
25
+ /**
26
+ * Chains the title supports, e.g. `[bsc]` — import them from this same subpath. Optional: leave it
27
+ * unset to use the SDK's default EVM chain set, which is also what the in-game wallet panel uses.
28
+ * Keeping both on the same list lets them share one wallet config, so a wallet connected here stays
29
+ * connected in the panel.
30
+ */
31
+ chains?: readonly [Chain, ...Chain[]];
27
32
  }
28
33
  type LazySolanaWalletLoginProps = LazyLoginCommonProps;
34
+ interface LazyWalletPanelProps {
35
+ /** The authenticated shared client. */
36
+ client: IDosGamesClient;
37
+ /**
38
+ * WalletConnect Cloud / Reown project id — what lights up mobile wallets. Comes from the title's
39
+ * blockchain config; the panel also reads it from the client if omitted.
40
+ */
41
+ walletConnectProjectId?: string;
42
+ /** App name shown in the wallet's connect prompt. */
43
+ appName?: string;
44
+ /** Called when the player closes the panel; the ✕ button only renders when provided. */
45
+ onClose?: () => void;
46
+ /** Overrides for the outer card container. */
47
+ style?: CSSProperties;
48
+ }
29
49
  /**
30
50
  * "Sign in with wallet" for **EVM** titles that loads its machinery on demand.
31
51
  *
@@ -38,5 +58,14 @@ declare function LazyWalletLogin(props: LazyWalletLoginProps): ReactNode;
38
58
  * {@link LazyWalletLogin}; Solana needs no chain list, only the WalletConnect project id.
39
59
  */
40
60
  declare function LazySolanaWalletLogin(props: LazySolanaWalletLoginProps): ReactNode;
61
+ /**
62
+ * The in-game "crypto wallet" panel (deposit/withdraw) that loads its machinery on demand.
63
+ *
64
+ * Same contract as {@link LazyWalletLogin}: it keeps Reown AppKit out of the page's initial module
65
+ * graph — the panel is fetched with `await import()` on mount, so the live preview boots. Because
66
+ * the wallet config is memoised per project id, a wallet connected via {@link LazyWalletLogin} on
67
+ * the sign-in screen is already connected here — same store, no second tap, no second modal.
68
+ */
69
+ declare function LazyWalletPanel(props: LazyWalletPanelProps): ReactNode;
41
70
 
42
- export { LazySolanaWalletLogin, type LazySolanaWalletLoginProps, LazyWalletLogin, type LazyWalletLoginProps };
71
+ export { LazySolanaWalletLogin, type LazySolanaWalletLoginProps, LazyWalletLogin, type LazyWalletLoginProps, LazyWalletPanel, type LazyWalletPanelProps };
@@ -22,10 +22,30 @@ interface LazyLoginCommonProps {
22
22
  style?: CSSProperties;
23
23
  }
24
24
  interface LazyWalletLoginProps extends LazyLoginCommonProps {
25
- /** Chains the title supports, e.g. `[bsc]` — import them from this same subpath. */
26
- chains: readonly [Chain, ...Chain[]];
25
+ /**
26
+ * Chains the title supports, e.g. `[bsc]` — import them from this same subpath. Optional: leave it
27
+ * unset to use the SDK's default EVM chain set, which is also what the in-game wallet panel uses.
28
+ * Keeping both on the same list lets them share one wallet config, so a wallet connected here stays
29
+ * connected in the panel.
30
+ */
31
+ chains?: readonly [Chain, ...Chain[]];
27
32
  }
28
33
  type LazySolanaWalletLoginProps = LazyLoginCommonProps;
34
+ interface LazyWalletPanelProps {
35
+ /** The authenticated shared client. */
36
+ client: IDosGamesClient;
37
+ /**
38
+ * WalletConnect Cloud / Reown project id — what lights up mobile wallets. Comes from the title's
39
+ * blockchain config; the panel also reads it from the client if omitted.
40
+ */
41
+ walletConnectProjectId?: string;
42
+ /** App name shown in the wallet's connect prompt. */
43
+ appName?: string;
44
+ /** Called when the player closes the panel; the ✕ button only renders when provided. */
45
+ onClose?: () => void;
46
+ /** Overrides for the outer card container. */
47
+ style?: CSSProperties;
48
+ }
29
49
  /**
30
50
  * "Sign in with wallet" for **EVM** titles that loads its machinery on demand.
31
51
  *
@@ -38,5 +58,14 @@ declare function LazyWalletLogin(props: LazyWalletLoginProps): ReactNode;
38
58
  * {@link LazyWalletLogin}; Solana needs no chain list, only the WalletConnect project id.
39
59
  */
40
60
  declare function LazySolanaWalletLogin(props: LazySolanaWalletLoginProps): ReactNode;
61
+ /**
62
+ * The in-game "crypto wallet" panel (deposit/withdraw) that loads its machinery on demand.
63
+ *
64
+ * Same contract as {@link LazyWalletLogin}: it keeps Reown AppKit out of the page's initial module
65
+ * graph — the panel is fetched with `await import()` on mount, so the live preview boots. Because
66
+ * the wallet config is memoised per project id, a wallet connected via {@link LazyWalletLogin} on
67
+ * the sign-in screen is already connected here — same store, no second tap, no second modal.
68
+ */
69
+ declare function LazyWalletPanel(props: LazyWalletPanelProps): ReactNode;
41
70
 
42
- export { LazySolanaWalletLogin, type LazySolanaWalletLoginProps, LazyWalletLogin, type LazyWalletLoginProps };
71
+ export { LazySolanaWalletLogin, type LazySolanaWalletLoginProps, LazyWalletLogin, type LazyWalletLoginProps, LazyWalletPanel, type LazyWalletPanelProps };
@@ -1 +1 @@
1
- export{e as arbitrum,d as base,b as bsc,j as chainById,i as idosChains,a as mainnet,f as optimism,c as polygon,h as polygonAmoy,g as sepolia,m as solanaDevnet,l as solanaMainnet}from'../chunk-HQNS6ZWL.js';import {useState}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var E={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},R={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function L(c){let{loading:o,disabled:a,label:n,style:t,error:e,onClick:r}=c;return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:r,disabled:a||o,style:{...E,...a||o?{opacity:.6,cursor:"default"}:null,...t},children:o?"Loading wallet\u2026":n??"Sign in with wallet"}),e&&jsx("span",{role:"alert",style:R,children:e})]})}function A(c){let{chains:o,walletConnectProjectId:a,appName:n,disabled:t,label:e,style:r,...y}=c,[p,b]=useState(null),[g,u]=useState(false),[m,f]=useState(null),l=()=>{u(true),f(null),(async()=>{try{let i=await import('./index.js'),C=i.createEvmWalletConfig({chains:o,walletConnectProjectId:a,appName:n});b({mod:i,config:C});}catch(i){console.error("[idosgames/wallet] failed to load the wallet module:",i),f("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(p){let{WalletLogin:i}=p.mod;return jsx(i,{...y,wagmiConfig:p.config,disabled:t,label:e,style:r,autoStart:true})}return jsx(L,{loading:g,disabled:t,label:e,style:r,error:m,onClick:l})}function D(c){let{walletConnectProjectId:o,appName:a,disabled:n,label:t,style:e,...r}=c,[y,p]=useState(null),[b,g]=useState(false),[u,m]=useState(null),f=()=>{g(true),m(null),(async()=>{try{let l=await import('./solanaIndex.js');o&&l.createSolanaWalletConfig({walletConnectProjectId:o,appName:a}),p(l);}catch(l){console.error("[idosgames/wallet] failed to load the wallet module:",l),m("Could not load the wallet. Please try again.");}finally{g(false);}})();};if(y){let{SolanaWalletLogin:l}=y;return jsx(l,{...r,disabled:n,label:t,style:e,autoStart:true})}return jsx(L,{loading:b,disabled:n,label:t,style:e,error:u,onClick:f})}export{D as LazySolanaWalletLogin,A as LazyWalletLogin};
1
+ export{e as arbitrum,d as base,b as bsc,j as chainById,i as idosChains,a as mainnet,f as optimism,c as polygon,h as polygonAmoy,g as sepolia,m as solanaDevnet,l as solanaMainnet}from'../chunk-HQNS6ZWL.js';import {useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var D={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},A={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function L(n){let{loading:e,disabled:r,label:t,style:l,error:o,onClick:i}=n;return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:i,disabled:r||e,style:{...D,...r||e?{opacity:.6,cursor:"default"}:null,...l},children:e?"Loading wallet\u2026":t??"Sign in with wallet"}),o&&jsx("span",{role:"alert",style:A,children:o})]})}function j(n){let{chains:e,walletConnectProjectId:r,appName:t,disabled:l,label:o,style:i,...s}=n,[a,b]=useState(null),[u,g]=useState(false),[f,m]=useState(null),d=()=>{g(true),m(null),(async()=>{try{let y=await import('./index.js'),S=y.createEvmWalletConfig({chains:e,walletConnectProjectId:r,appName:t});b({mod:y,config:S});}catch(y){console.error("[idosgames/wallet] failed to load the wallet module:",y),m("Could not load the wallet. Please try again.");}finally{g(false);}})();};if(a){let{WalletLogin:y}=a.mod;return jsx(y,{...s,wagmiConfig:a.config,disabled:l,label:o,style:i,autoStart:true})}return jsx(L,{loading:u,disabled:l,label:o,style:i,error:f,onClick:d})}function B(n){let{walletConnectProjectId:e,appName:r,disabled:t,label:l,style:o,...i}=n,[s,a]=useState(null),[b,u]=useState(false),[g,f]=useState(null),m=()=>{u(true),f(null),(async()=>{try{let d=await import('./solanaIndex.js');e&&d.createSolanaWalletConfig({walletConnectProjectId:e,appName:r}),a(d);}catch(d){console.error("[idosgames/wallet] failed to load the wallet module:",d),f("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(s){let{SolanaWalletLogin:d}=s;return jsx(d,{...i,disabled:t,label:l,style:o,autoStart:true})}return jsx(L,{loading:b,disabled:t,label:l,style:o,error:g,onClick:m})}var G={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",fontSize:13};function T(n){let{onClose:e,style:r}=n,[t,l]=useState(null),[o,i]=useState(null);return useEffect(()=>{let s=true;return (async()=>{try{let a=await import('./index.js');s&&l(a);}catch(a){console.error("[idosgames/wallet] failed to load the wallet panel:",a),s&&i("Could not load the wallet.");}})(),()=>{s=false;}},[]),t?jsx(t.WalletPanel,{...n}):jsxs("div",{style:{...G,...r},children:[o??"Loading wallet\u2026",e&&jsx("button",{type:"button",onClick:e,style:{background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer",marginLeft:10},children:"\u2715"})]})}export{B as LazySolanaWalletLogin,j as LazyWalletLogin,T as LazyWalletPanel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/wallet",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Wallet-bridge companion to @idosgames/core: connect browser & mobile wallets (EVM via wagmi/viem/WalletConnect, Solana via wallet-adapter) and move tokens/NFTs in and out of the game through client.blockchain.",
5
5
  "type": "module",
6
6
  "license": "MIT",