@idosgames/wallet 0.1.10 → 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 +18 -6
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +42 -15
- package/dist/react/index.d.ts +42 -15
- package/dist/react/index.js +1 -1
- package/dist/react/lazyIndex.cjs +2 -2
- package/dist/react/lazyIndex.d.cts +32 -3
- package/dist/react/lazyIndex.d.ts +32 -3
- package/dist/react/lazyIndex.js +1 -1
- package/package.json +1 -1
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
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
package/dist/react/index.cjs
CHANGED
|
@@ -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 Y={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"}}},_={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"}}},Q={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"}}},V={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"}}},Z={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"}}},$={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"}}},J={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"}}},X={mainnet:Y,bsc:z,polygon:_,base:Q,arbitrum:V,optimism:Z,sepolia:$,polygonAmoy:J};function we(t){return Object.values(X).find(e=>e.id===t)}function ee(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var te=null;function ne(t){te=t;}function N(){return te}function Ae(t){let{chains:e,walletConnectProjectId:n,appName:r,appUrl:o,appIcon:a,transports:d,connectors:c}=t,i={};for(let l of e)i[l.id]=d?.[l.id]??wagmi.http();let m=o??(typeof window<"u"?window.location.origin:""),p={name:r??"iDosGames",description:r??"iDosGames game",url:m,icons:a?[a]:[]};if(n&&!c){let l=e.map(ee),f=new appkitAdapterWagmi.WagmiAdapter({networks:l,projectId:n,transports:i});return ne(react.createAppKit({adapters:[f],networks:l,projectId:n,metadata:p,features:{analytics:false,email:false,socials:false}})),f.wagmiConfig}let u=c??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})];return wagmi.createConfig({chains:e,connectors:u,transports:i})}function D(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 E=[{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:[]}],oe=[{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:[]}],P=[{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"}]}],ae=[{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 ie(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function y(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 h(t,e){return {ok:false,stage:t,error:e}}function se(t){let e=t.RewardPoolAddress;return e||null}async function le(t,e,n,r){return await t.publicClient.readContract({address:e,abi:P,functionName:"allowance",args:[t.account,n]})>=r?null:y(t,{address:e,abi:P,functionName:"approve",args:[n,r]})}async function I(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:a,titleID:d,category:c}=t,i=e.auth.context?.userID;if(!i)return s("approve","Not logged in.");let m=se(r);if(!m)return s("approve","Network has no RewardPoolAddress.");if(a<=0n)return s("approve","Amount must be positive.");try{await le(n,o,m,a);}catch(l){return s("approve",g(l))}let p;try{p=await y(n,{address:m,abi:E,functionName:"depositERC20",args:[o,a,i,d,c??""]});}catch(l){return s("deposit-onchain",g(l))}let u=await e.blockchain.depositToken(r.NetworkID??"",p);return u.ok?{ok:true,onChainTxHash:p,data:u.data}:s("report",u.error,{onChainTxHash:p})}async function B(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:a,amount:d,titleID:c,category:i}=t,m=e.auth.context?.userID;if(!m)return s("deposit-onchain","Not logged in.");let p=se(r);if(!p)return s("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return s("deposit-onchain","Amount must be positive.");let u=ie(m,c,i),l;try{l=await y(n,{address:o,abi:ae,functionName:"safeTransferFrom",args:[n.account,p,a,d,u]});}catch(k){return s("deposit-onchain",g(k))}let f=await e.blockchain.depositNFT(r.NetworkID??"",l);return f.ok?{ok:true,onChainTxHash:l,data:f.data}:s("report",f.error,{onChainTxHash:l})}async function ce(t,e){return y(t,{address:e.ContractAddress,abi:E,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 pe(t,e){return y(t,{address:e.ContractAddress,abi:oe,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 R(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:a,amount:d,category:c}=t,i=await e.blockchain.requestTokenWithdrawal(r,o,a,d,c);if(!i.ok)return s("request",i.error);let m=i.data.EvmSignature,p=i.data.TitleTransactionID??void 0;if(!m)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let u;try{u=await ce(n,m);}catch(f){return s("withdraw-onchain",g(f),{titleTransactionID:p})}let l=await de(e,p,u);return l.ok?{ok:true,onChainTxHash:u,data:i.data}:l}async function S(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:a,amount:d,category:c}=t,i=await e.blockchain.requestNFTWithdrawal(r,o,a,d,c);if(!i.ok)return s("request",i.error);let m=i.data.EvmSignature,p=i.data.TitleTransactionID??void 0;if(!m)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let u;try{u=await pe(n,m);}catch(f){return s("withdraw-onchain",g(f),{titleTransactionID:p})}let l=await de(e,p,u);return l.ok?{ok:true,onChainTxHash:u,data:i.data}:l}async function de(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 h("challenge",a.error);let d;try{d=await n.walletClient.signMessage({account:n.account,message:a.data.Message});}catch(i){return h("sign",g(i))}let c=await e.auth.loginWithWallet(o,r,d);return c.ok?{ok:true,data:c.data}:h("login",c.error)}function A(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}var v="Wallet not connected.";function Fe(t,e){let n=A();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,o)=>n?b({client:t,clients:n,networkID:r,walletAddress:o}):Promise.resolve(h("challenge",v)),depositToken:r=>n?I({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("approve",v)),depositNft:r=>n?B({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("deposit-onchain",v)),withdrawToken:r=>n?R({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",v)),withdrawNft:r=>n?S({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",v))}}function qe(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(D,{wagmiConfig:e,children:jsxRuntime.jsx(fe,{...n})})}function je(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function Ye(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 ze(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 _e(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,o=c=>{r||(r=true,a(),clearTimeout(d),n(c));},a=actions.watchAccount(t,{onChange:c=>{c.isConnected&&o(true);}}),d=setTimeout(()=>o(false),e);})}function Qe(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 Ve=9e4;async function Ze(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 $e(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 fe(t){let{client:e,networkID:n,onAuthenticated:r,disabled:o,label:a,style:d,autoStart:c}=t,i=wagmi.useConfig(),{isConnected:m}=wagmi.useAccount(),{connectAsync:p,connectors:u}=wagmi.useConnect(),l=A(),[f,k]=react$1.useState(false),[H,w]=react$1.useState(null),[M,L]=react$1.useState(false),K=react$1.useRef(0),G=react$1.useRef(false),O=async()=>{let ye=++K.current,T=()=>K.current===ye;k(true),w(null);try{if(!m){let U=N();if(U){if(await U.open(),!await _e(i)){w("No wallet was connected.");return}}else {let q=Qe(u);if(!q){w("No wallet connector is configured.");return}try{await p({connector:q});}catch(j){if(!je(j))throw j}}}let C=l??await ze(i);if(!C){w("Wallet client is not available.");return}L(!0);let W=await $e(b({client:e,clients:C,networkID:n}),Ve);if(!T())return;if(W.ok){r();return}w(W.stage==="sign"?"Signature declined.":W.error??"Wallet sign-in failed.");}catch(C){if(!T())return;console.error("[idosgames/wallet] wallet sign-in failed:",C),w(Ye(C));}finally{T()&&(k(false),L(false));}};react$1.useEffect(()=>{!c||G.current||(G.current=true,O());},[c]);let ge=async()=>{await Ze(i)||await N()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{M?ge():O();},disabled:o,style:{...Je,...o?{opacity:.6,cursor:"default"}:null,...d},children:M?"Waiting for signature \u2014 tap to open wallet":f?"Check your wallet\u2026":m?a??"Sign in with wallet":"Connect wallet"}),H&&jsxRuntime.jsx("span",{role:"alert",style:Xe,children:H})]})}var Je={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Xe={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
|
|
2
|
-
exports.IDosGamesWalletProvider=
|
|
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;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -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
|
-
/**
|
|
13
|
-
|
|
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
|
-
|
|
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 };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
13
|
-
|
|
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
|
-
|
|
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 };
|
package/dist/react/index.js
CHANGED
|
@@ -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}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 me(e){let{chains:o,walletConnectProjectId:t,appName:n,appUrl:r,appIcon:i,transports:p,connectors:s}=e,a$1={};for(let l of o)a$1[l.id]=p?.[l.id]??http();let f=r??(typeof window<"u"?window.location.origin:""),v={name:n??"iDosGames",description:n??"iDosGames game",url:f,icons:i?[i]:[]};if(t&&!s){let l=o.map(k),g=new WagmiAdapter({networks:l,projectId:t,transports:a$1});return a(createAppKit({adapters:[g],networks:l,projectId:t,metadata:v,features:{analytics:false,email:false,socials:false}})),g.wagmiConfig}let h=s??[injected(),coinbaseWallet({appName:n??"iDosGames"})];return createConfig({chains:o,connectors:h,transports:a$1})}function T(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 C(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var u="Wallet not connected.";function ve(e,o$1){let t=C();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,r)=>t?p({client:e,clients:t,networkID:n,walletAddress:r}):Promise.resolve(c("challenge",u)),depositToken:n=>t?h({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("approve",u)),depositNft:n=>t?i({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("deposit-onchain",u)),withdrawToken:n$1=>t?n({client:e,clients:t,...n$1}):Promise.resolve(b("withdraw-onchain",u)),withdrawNft:n=>t?o({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",u))}}function Ne(e){let{wagmiConfig:o,...t}=e;return jsx(T,{wagmiConfig:o,children:jsx(z,{...t})})}function De(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Ae(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 Re(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=s=>{n||(n=true,i(),clearTimeout(p),t(s));},i=watchAccount(e,{onChange:s=>{s.isConnected&&r(true);}}),p=setTimeout(()=>r(false),o);})}function Ie(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 Se=9e4;async function xe(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 Ge(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 z(e){let{client:o,networkID:t,onAuthenticated:n,disabled:r,label:i,style:p$1,autoStart:s}=e,a=useConfig(),{isConnected:f}=useAccount(),{connectAsync:v,connectors:h}=useConnect(),l=C(),[g,k]=useState(false),[N,c]=useState(null),[D,A]=useState(false),R=useRef(0),B=useRef(false),I=async()=>{let J=++R.current,P=()=>R.current===J;k(true),c(null);try{if(!f){let S=b$1();if(S){if(await S.open(),!await Be(a)){c("No wallet was connected.");return}}else {let x=Ie(h);if(!x){c("No wallet connector is configured.");return}try{await v({connector:x});}catch(G){if(!De(G))throw G}}}let m=l??await Re(a);if(!m){c("Wallet client is not available.");return}A(!0);let W=await Ge(p({client:o,clients:m,networkID:t}),Se);if(!P())return;if(W.ok){n();return}c(W.stage==="sign"?"Signature declined.":W.error??"Wallet sign-in failed.");}catch(m){if(!P())return;console.error("[idosgames/wallet] wallet sign-in failed:",m),c(Ae(m));}finally{P()&&(k(false),A(false));}};useEffect(()=>{!s||B.current||(B.current=true,I());},[s]);let H=async()=>{await xe(a)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{D?H():I();},disabled:r,style:{...Le,...r?{opacity:.6,cursor:"default"}:null,...p$1},children:D?"Waiting for signature \u2014 tap to open wallet":g?"Check your wallet\u2026":f?i??"Sign in with wallet":"Connect wallet"}),N&&jsx("span",{role:"alert",style:Oe,children:N})]})}var Le={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{T as IDosGamesWalletProvider,Ne as WalletLogin,z as WalletLoginButton,me as createEvmWalletConfig,ve as useEvmBridge,C 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};
|
package/dist/react/lazyIndex.cjs
CHANGED
|
@@ -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 pt=Object.defineProperty;var f=(t,e)=>()=>(t&&(e=t(t=0)),e);var Pe=(t,e)=>{for(var n in e)pt(t,n,{get:e[n],enumerable:true});};function ie(t){return Object.values(exports.idosChains).find(e=>e.id===t)}function Se(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 E=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 te(t){xe=t;}function D(){return xe}var xe,O=f(()=>{xe=null;});function Ee(t){let{chains:e,walletConnectProjectId:n,appName:o,appUrl:a,appIcon:r,transports:p,connectors:s}=t,i={};for(let u of e)i[u.id]=p?.[u.id]??wagmi.http();let c=a??(typeof window<"u"?window.location.origin:""),l={name:o??"iDosGames",description:o??"iDosGames game",url:c,icons:r?[r]:[]};if(n&&!s){let u=e.map(Se),g=new appkitAdapterWagmi.WagmiAdapter({networks:u,projectId:n,transports:i});return te(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:i})}var De=f(()=>{E();O();});function ne(t){let{wagmiConfig:e,queryClient:n,children:o}=t,[a]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:e,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:a,children:o})})}var le=f(()=>{});var oe,Ne,ce,Re,pe=f(()=>{oe=[{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:[]}],Ne=[{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:[]}],ce=[{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"}]}],Re=[{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 Be(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}var Le=f(()=>{});async function S(t,e){let{walletClient:n,publicClient:o,account:a}=t,r=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:a,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 de=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 T=f(()=>{});function Me(t){let e=t.RewardPoolAddress;return e||null}async function Fe(t,e,n,o){return await t.publicClient.readContract({address:e,abi:ce,functionName:"allowance",args:[t.account,n]})>=o?null:S(t,{address:e,abi:ce,functionName:"approve",args:[n,o]})}async function ue(t){let{client:e,clients:n,network:o,tokenAddress:a,amount:r,titleID:p,category:s}=t,i=e.auth.context?.userID;if(!i)return d("approve","Not logged in.");let c=Me(o);if(!c)return d("approve","Network has no RewardPoolAddress.");if(r<=0n)return d("approve","Amount must be positive.");try{await Fe(n,a,c,r);}catch(u){return d("approve",w(u))}let l;try{l=await S(n,{address:c,abi:oe,functionName:"depositERC20",args:[a,r,i,p,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 me(t){let{client:e,clients:n,network:o,nftContractAddress:a,tokenId:r,amount:p,titleID:s,category:i}=t,c=e.auth.context?.userID;if(!c)return d("deposit-onchain","Not logged in.");let l=Me(o);if(!l)return d("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return d("deposit-onchain","Amount must be positive.");let m=Be(c,s,i),u;try{u=await S(n,{address:a,abi:Re,functionName:"safeTransferFrom",args:[n.account,l,r,p,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 Ke=f(()=>{pe();Le();de();T();});async function He(t,e){return S(t,{address:e.ContractAddress,abi:oe,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 Ge(t,e){return S(t,{address:e.ContractAddress,abi:Ne,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 ge(t){let{client:e,clients:n,currencyID:o,networkID:a,walletAddress:r,amount:p,category:s}=t,i=await e.blockchain.requestTokenWithdrawal(o,a,r,p,s);if(!i.ok)return d("request",i.error);let c=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!c)return d("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let m;try{m=await He(n,c);}catch(g){return d("withdraw-onchain",w(g),{titleTransactionID:l})}let u=await Oe(e,l,m);return u.ok?{ok:true,onChainTxHash:m,data:i.data}:u}async function fe(t){let{client:e,clients:n,itemID:o,networkID:a,walletAddress:r,amount:p,category:s}=t,i=await e.blockchain.requestNFTWithdrawal(o,a,r,p,s);if(!i.ok)return d("request",i.error);let c=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!c)return d("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let m;try{m=await Ge(n,c);}catch(g){return d("withdraw-onchain",w(g),{titleTransactionID:l})}let u=await Oe(e,l,m);return u.ok?{ok:true,onChainTxHash:m,data:i.data}:u}async function Oe(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 Ue=f(()=>{pe();de();T();});async function U(t){let{client:e,clients:n,networkID:o}=t,a=t.walletAddress??n.account,r=await e.auth.requestWalletChallenge(a,o);if(!r.ok)return h("challenge",r.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:r.data.Message});}catch(i){return h("sign",w(i))}let s=await e.auth.loginWithWallet(a,o,p);return s.ok?{ok:true,data:s.data}:h("login",s.error)}var qe=f(()=>{T();});var ye=f(()=>{Ke();Ue();qe();});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 ze(t,e){let n=z();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,a)=>n?U({client:t,clients:n,networkID:o,walletAddress:a}):Promise.resolve(h("challenge",q)),depositToken:o=>n?ue({client:t,clients:n,titleID:e,...o}):Promise.resolve(d("approve",q)),depositNft:o=>n?me({client:t,clients:n,titleID:e,...o}):Promise.resolve(d("deposit-onchain",q)),withdrawToken:o=>n?ge({client:t,clients:n,...o}):Promise.resolve(d("withdraw-onchain",q)),withdrawNft:o=>n?fe({client:t,clients:n,...o}):Promise.resolve(d("withdraw-onchain",q))}}var q,we=f(()=>{ye();T();q="Wallet not connected.";});function Ye(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(ne,{wagmiConfig:e,children:jsxRuntime.jsx(Ce,{...n})})}function Bt(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function Lt(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 Mt(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,a=s=>{o||(o=true,r(),clearTimeout(p),n(s));},r=actions.watchAccount(t,{onChange:s=>{s.isConnected&&a(true);}}),p=setTimeout(()=>a(false),e);})}function Kt(t){let e=a=>t.find(r=>r.id===a||r.type===a),n=e("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:e("walletConnect")??n??t[0]}async function Gt(t){try{let o=(await actions.getAccount(t).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,a=o?.native||o?.universal;return !a||typeof window>"u"?!1:(window.location.href=a,!0)}catch{return false}}function Ot(t,e){return new Promise((n,o)=>{let a=setTimeout(()=>o(new Error("The wallet request timed out.")),e);t.then(r=>{clearTimeout(a),n(r);},r=>{clearTimeout(a),o(r instanceof Error?r:new Error(String(r)));});})}function Ce(t){let{client:e,networkID:n,onAuthenticated:o,disabled:a,label:r,style:p,autoStart:s}=t,i=wagmi.useConfig(),{isConnected:c}=wagmi.useAccount(),{connectAsync:l,connectors:m}=wagmi.useConnect(),u=z(),[g,y]=react.useState(false),[C,b]=react.useState(null),[R,B]=react.useState(false),P=react.useRef(0),L=react.useRef(false),v=async()=>{let F=++P.current,K=()=>P.current===F;y(true),b(null);try{if(!c){let x=D();if(x){if(await x.open(),!await Ft(i)){b("No wallet was connected.");return}}else {let H=Kt(m);if(!H){b("No wallet connector is configured.");return}try{await l({connector:H});}catch(k){if(!Bt(k))throw k}}}let W=u??await Mt(i);if(!W){b("Wallet client is not available.");return}B(!0);let A=await Ot(U({client:e,clients:W,networkID:n}),Ht);if(!K())return;if(A.ok){o();return}b(A.stage==="sign"?"Signature declined.":A.error??"Wallet sign-in failed.");}catch(W){if(!K())return;console.error("[idosgames/wallet] wallet sign-in failed:",W),b(Lt(W));}finally{K()&&(y(false),B(false));}};react.useEffect(()=>{!s||L.current||(L.current=true,v());},[s]);let M=async()=>{await Gt(i)||await D()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{R?M():v();},disabled:a,style:{...Ut,...a?{opacity:.6,cursor:"default"}:null,...p},children:R?"Waiting for signature \u2014 tap to open wallet":g?"Check your wallet\u2026":c?r??"Sign in with wallet":"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:qt,children:C})]})}var Ht,Ut,qt,Qe=f(()=>{O();ye();le();we();Ht=9e4;Ut={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},qt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var Ve={};Pe(Ve,{IDosGamesWalletProvider:()=>ne,WalletLogin:()=>Ye,WalletLoginButton:()=>Ce,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>ie,createEvmWalletConfig:()=>Ee,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>ze,useEvmBridgeClients:()=>z});var Ze=f(()=>{De();E();le();we();Qe();});function $e(t){let{walletConnectProjectId:e,appName:n,appUrl:o,appIcon:a,wallets:r}=t,p=t.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),i={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:a?[a]:[]},c=new appkitAdapterSolana.SolanaAdapter(r?{wallets:r}:{});return te(react$1.createAppKit({adapters:[c],networks:p,projectId:e,metadata:i,features:{analytics:false,email:false,socials:false}})),c}var Je=f(()=>{E();O();});async function be(t){let{client:e,adapter:n,network:o,mint:a,amountRaw:r,titleID:p,category:s}=t,i=e.auth.context?.userID;if(!i)return d("deposit-onchain","Not logged in.");if(r<=0n)return d("deposit-onchain","Amount must be positive.");let c;try{c=await n.depositSpl({mint:a,amountRaw:r,userID:i,titleID:p,category:core.normalizeBlockchainCategory(s)});}catch(m){return d("deposit-onchain",w(m))}let l=await e.blockchain.depositToken(o.NetworkID??"",c);return l.ok?{ok:true,onChainTxHash:c,data:l.data}:d("report",l.error,{onChainTxHash:c})}async function ke(t){let{client:e,adapter:n,currencyID:o,networkID:a,walletAddress:r,amount:p,category:s}=t,i=await e.blockchain.requestTokenWithdrawal(o,a,r,p,s);if(!i.ok)return d("request",i.error);let c=i.data.SolanaSignature,l=i.data.TitleTransactionID??void 0;if(!c)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let m;try{m=await n.submitWithdrawal(c);}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:i.data}:d("confirm",u.error,{onChainTxHash:m,titleTransactionID:l})}var Xe=f(()=>{T();});async function j(t){let{client:e,networkID:n,walletAddress:o,signMessage:a}=t,r=await e.auth.requestWalletChallenge(o,n);if(!r.ok)return h("challenge",r.error);let p;try{let i=await a(new TextEncoder().encode(r.data.Message));p=Vt(i);}catch(i){return h("sign",w(i))}let s=await e.auth.loginWithWallet(o,n,p);return s.ok?{ok:true,data:s.data}:h("login",s.error)}function Vt(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}var et=f(()=>{T();});var ve=f(()=>{Xe();et();});function nt(t,e,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:a}=react$1.useAppKitProvider("solana"),r=o??null,p=a?.signMessage?.bind(a);return {connected:!!r,account:r,loginWithWallet:(s,i)=>{let c=i??r;return c?p?j({client:t,networkID:s,walletAddress:c,signMessage:p}):Promise.resolve(h("sign","The connected wallet does not support message signing.")):Promise.resolve(h("challenge",tt))},depositToken:s=>be({client:t,adapter:n,titleID:e,...s}),withdrawToken:s=>{let i=s.walletAddress??r;return i?ke({client:t,adapter:n,...s,walletAddress:i}):Promise.resolve(d("request",tt))}}}var tt,ot=f(()=>{ve();T();tt="Wallet not connected.";});function nn(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 on(t,e){return new Promise((n,o)=>{let a=setTimeout(()=>o(new Error("The wallet request timed out.")),e);t.then(r=>{clearTimeout(a),n(r);},r=>{clearTimeout(a),o(r instanceof Error?r:new Error(String(r)));});})}function rn(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 at(t){let{client:e,networkID:n,onAuthenticated:o,disabled:a,label:r,style:p,autoStart:s}=t,{address:i,isConnected:c}=react$1.useAppKitAccount(),{walletProvider:l}=react$1.useAppKitProvider("solana"),[m,u]=react.useState(false),[g,y]=react.useState(null),[C,b]=react.useState(false),[R,B]=react.useState(false),P=react.useRef(null),L=react.useRef(0),v=react.useCallback(()=>{P.current&&clearTimeout(P.current),P.current=null;},[]);react.useEffect(()=>v,[v]);let M=react.useRef(false),F=react.useCallback(async()=>{let A=++L.current,x=()=>L.current===A,H=l?.signMessage?.bind(l);if(!i||!H){y("The connected wallet cannot sign messages."),u(false);return}u(true),y(null);try{B(!0);let k=await on(j({client:e,networkID:n,walletAddress:i,signMessage:H}),tn);if(!x())return;if(k.ok){o();return}y(k.stage==="sign"?"Signature declined.":k.error??"Wallet sign-in failed.");}catch(k){if(!x())return;console.error("[idosgames/wallet] solana sign-in failed:",k),y(rn(k));}finally{x()&&(u(false),B(false));}},[i,l,e,n,o]),K=react.useCallback(()=>{nn(l)||D()?.open();},[l]);react.useEffect(()=>{!C||!c||!i||!l||(b(false),v(),F());},[C,c,i,l,F,v]);let W=()=>{if(R){K();return}if(y(null),M.current=true,c&&i&&l){F();return}let A=D();if(!A){y("Wallet sign-in is not configured for this title.");return}u(true),b(true),v(),P.current=setTimeout(()=>{b(false),u(false),y("No wallet was connected.");},en),A.open();};return react.useEffect(()=>{!s||M.current||(M.current=true,W());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:W,disabled:a,style:{...an,...a?{opacity:.6,cursor:"default"}:null,...p},children:R?"Waiting for signature \u2014 tap to open wallet":m?"Check your wallet\u2026":c?r??"Sign in with wallet":"Connect wallet"}),g&&jsxRuntime.jsx("span",{role:"alert",style:sn,children:g})]})}var en,tn,an,sn,it=f(()=>{ve();O();en=18e4,tn=9e4;an={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},sn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var st={};Pe(st,{SolanaWalletLogin:()=>at,createSolanaWalletConfig:()=>$e,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>nt});var lt=f(()=>{Je();ot();it();E();});var pn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},dn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function ct(t){let{loading:e,disabled:n,label:o,style:a,error:r,onClick:p}=t;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:p,disabled:n||e,style:{...pn,...n||e?{opacity:.6,cursor:"default"}:null,...a},children:e?"Loading wallet\u2026":o??"Sign in with wallet"}),r&&jsxRuntime.jsx("span",{role:"alert",style:dn,children:r})]})}function un(t){let{chains:e,walletConnectProjectId:n,appName:o,disabled:a,label:r,style:p,...s}=t,[i,c]=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(()=>(Ze(),Ve)),b=C.createEvmWalletConfig({chains:e,walletConnectProjectId:n,appName:o});c({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(i){let{WalletLogin:C}=i.mod;return jsxRuntime.jsx(C,{...s,wagmiConfig:i.config,disabled:a,label:r,style:p,autoStart:true})}return jsxRuntime.jsx(ct,{loading:l,disabled:a,label:r,style:p,error:u,onClick:y})}function mn(t){let{walletConnectProjectId:e,appName:n,disabled:o,label:a,style:r,...p}=t,[s,i]=react.useState(null),[c,l]=react.useState(false),[m,u]=react.useState(null),g=()=>{l(true),u(null),(async()=>{try{let y=await Promise.resolve().then(()=>(lt(),st));e&&y.createSolanaWalletConfig({walletConnectProjectId:e,appName:n}),i(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,{...p,disabled:o,label:a,style:r,autoStart:true})}return jsxRuntime.jsx(ct,{loading:c,disabled:o,label:a,style:r,error:m,onClick:g})}E();
|
|
2
|
-
exports.LazySolanaWalletLogin=
|
|
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
|
-
/**
|
|
26
|
-
|
|
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
|
-
/**
|
|
26
|
-
|
|
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 };
|
package/dist/react/lazyIndex.js
CHANGED
|
@@ -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
|
|
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.
|
|
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",
|