@idosgames/wallet 0.5.1 → 0.5.2

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.
@@ -0,0 +1,2 @@
1
+ import {BaseError}from'viem';import {PLATFORM_ORIGINS}from'@idosgames/core';function w(e){return e instanceof BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function a(e,t,n){return {ok:false,stage:e,error:t,...n}}function r(e,t){return {ok:false,stage:e,error:t}}var o="WALLET_USE_SITE_PANEL",l=/^[a-z0-9]{8}-preview\.idos\.games$/;function p(e=typeof window>"u"?"":window.location.hostname){let t=e.toLowerCase();return l.test(t)?true:t!=="localhost"&&t!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function L(){if(typeof window>"u"||p())return false;try{return window.self!==window.top}catch{return true}}function v(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function T(e){return a(e,o)}function B(e){return r(e,o)}var c=PLATFORM_ORIGINS;function N(e){if(typeof window>"u")return ()=>{};let t=n=>{c.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&e();};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)}var u={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"}}},d={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"}}},m={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"}}},g={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"}}},h={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"}}},f={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"}}},E={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"}}},y={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"}}},b={mainnet:u,bsc:d,polygon:m,base:g,arbitrum:h,optimism:f,sepolia:E,polygonAmoy:y};function _(e){return Object.values(b).find(t=>t.id===e)}function F(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var W={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"},I={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"};
2
+ export{w as a,a as b,r as c,o as d,p as e,L as f,v as g,T as h,B as i,N as j,u as k,d as l,m,g as n,h as o,f as p,E as q,y as r,b as s,_ as t,F as u,W as v,I as w};
@@ -0,0 +1 @@
1
+ import {f,h,b,a,i,c}from'./chunk-K3THMWU2.js';import {normalizeBlockchainCategory}from'@idosgames/core';async function T(i){let{client:t,adapter:n,network:s,mint:d,amountRaw:a$1,titleID:l,category:r}=i;if(f())return h("deposit-onchain");let e=t.auth.context?.userID;if(!e)return b("deposit-onchain","Not logged in.");if(a$1<=0n)return b("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:d,amountRaw:a$1,userID:e,titleID:l,category:normalizeBlockchainCategory(r)});}catch(m){return b("deposit-onchain",a(m))}let c=await t.blockchain.depositToken(s.NetworkID??"",u);return c.ok?{ok:true,onChainTxHash:u,data:c.data}:b("report",c.error,{onChainTxHash:u})}async function D(i){let{client:t,adapter:n,currencyID:s,networkID:d,walletAddress:a$1,amount:l,category:r}=i;if(f())return h("request");let e=await t.blockchain.requestTokenWithdrawal(s,d,a$1,l,r);if(!e.ok)return b("request",e.error);let u=e.data.SolanaSignature,c=e.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no Solana signature.",{titleTransactionID:c});let m;try{m=await n.submitWithdrawal(u);}catch(W){return b("withdraw-onchain",a(W),{titleTransactionID:c})}if(!c)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:m});let w=await t.blockchain.confirmWithdrawal(c,m);return w.ok?{ok:true,onChainTxHash:m,data:e.data}:b("confirm",w.error,{onChainTxHash:m,titleTransactionID:c})}async function x(i$1){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i$1;if(f())return i("challenge");let a$1=await t.auth.requestWalletChallenge(s,n);if(!a$1.ok)return c("challenge",a$1.error);let l;try{let e=await d(new TextEncoder().encode(a$1.data.Message));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.loginWithWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}async function I(i$1){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i$1;if(f())return i("challenge");let a$1=await t.auth.linkWallet(s,n);if(!a$1.ok)return c("challenge",a$1.error);if(!a$1.data.Challenge)return c("challenge","No challenge was issued.");let l;try{let e=await d(new TextEncoder().encode(a$1.data.Challenge));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.linkWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}function S(i){let t="0x";for(let n of i)t+=n.toString(16).padStart(2,"0");return t}export{T as a,D as b,x as c,I as d};
@@ -1 +1 @@
1
- import {c as c$1}from'./chunk-IEWZH6XD.js';import {isPlatformParentOrigin,PLATFORM_ORIGINS}from'@idosgames/core';var c={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},m="PLATFORM_WALLET_UNAVAILABLE",P=5e3,S=18e4;function T(){let r=[...PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!r.includes(t)&&isPlatformParentOrigin(t)&&r.push(t),r}function R(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function L(r,t,i){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:m});let s=window.parent;if(!s)return Promise.resolve({ok:false,error:m});let e=R();return new Promise(f=>{let l=false,a,g=o=>{l||(l=true,window.removeEventListener("message",u),clearTimeout(a),f(o));},u=o=>{if(!isPlatformParentOrigin(o.origin))return;let n=o.data;if(!(!n||n.requestId!==e)){if(n.type===c.ack){clearTimeout(a),a=setTimeout(()=>g({ok:false,error:"TIMEOUT"}),S);return}n.type===t&&g({ok:n.ok===true,error:typeof n.error=="string"?n.error:void 0,address:typeof n.address=="string"?n.address:void 0,signature:typeof n.signature=="string"?n.signature:void 0});}};a=setTimeout(()=>g({ok:false,error:m}),P),window.addEventListener("message",u);for(let o of T())try{s.postMessage({type:r,requestId:e,...i},o);}catch{}})}async function p(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.requestWalletChallenge(s,i);return e.ok?{ok:true,message:e.data.Message}:{ok:false,error:e.error}},(s,e)=>t.auth.loginWithWallet(s,i,e))}async function E(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.linkWallet(s,i);return e.ok?e.data.Challenge?{ok:true,message:e.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:e.error}},(s,e)=>t.auth.linkWallet(s,i,e))}async function k(r,t,i){let{client:s,family:e}=r,f=s.titleID,l=await L(c.addressRequest,c.addressResponse,{titleID:f,family:e});if(!l.ok||!l.address)return c$1("challenge",l.error??"NO_WALLET");let a=l.address,g=await t(a);if(!g.ok)return c$1("challenge",g.error);let u=await L(c.signRequest,c.signResponse,{titleID:f,family:e,address:a,message:g.message});if(!u.ok||!u.signature)return c$1("sign",u.error??"SIGN_FAILED");let o=await i(a,u.signature);return o.ok?{ok:true,data:o.data}:c$1("login",o.error)}export{c as a,m as b,p as c,E as d};
1
+ import {c as c$1}from'./chunk-K3THMWU2.js';import {isPlatformParentOrigin,PLATFORM_ORIGINS}from'@idosgames/core';var c={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},m="PLATFORM_WALLET_UNAVAILABLE",P=5e3,S=18e4;function T(){let r=[...PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!r.includes(t)&&isPlatformParentOrigin(t)&&r.push(t),r}function R(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function L(r,t,i){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:m});let s=window.parent;if(!s)return Promise.resolve({ok:false,error:m});let e=R();return new Promise(f=>{let l=false,a,g=o=>{l||(l=true,window.removeEventListener("message",u),clearTimeout(a),f(o));},u=o=>{if(!isPlatformParentOrigin(o.origin))return;let n=o.data;if(!(!n||n.requestId!==e)){if(n.type===c.ack){clearTimeout(a),a=setTimeout(()=>g({ok:false,error:"TIMEOUT"}),S);return}n.type===t&&g({ok:n.ok===true,error:typeof n.error=="string"?n.error:void 0,address:typeof n.address=="string"?n.address:void 0,signature:typeof n.signature=="string"?n.signature:void 0});}};a=setTimeout(()=>g({ok:false,error:m}),P),window.addEventListener("message",u);for(let o of T())try{s.postMessage({type:r,requestId:e,...i},o);}catch{}})}async function p(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.requestWalletChallenge(s,i);return e.ok?{ok:true,message:e.data.Message}:{ok:false,error:e.error}},(s,e)=>t.auth.loginWithWallet(s,i,e))}async function E(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.linkWallet(s,i);return e.ok?e.data.Challenge?{ok:true,message:e.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:e.error}},(s,e)=>t.auth.linkWallet(s,i,e))}async function k(r,t,i){let{client:s,family:e}=r,f=s.titleID,l=await L(c.addressRequest,c.addressResponse,{titleID:f,family:e});if(!l.ok||!l.address)return c$1("challenge",l.error??"NO_WALLET");let a=l.address,g=await t(a);if(!g.ok)return c$1("challenge",g.error);let u=await L(c.signRequest,c.signResponse,{titleID:f,family:e,address:a,message:g.message});if(!u.ok||!u.signature)return c$1("sign",u.error??"SIGN_FAILED");let o=await i(a,u.signature);return o.ok?{ok:true,data:o.data}:c$1("login",o.error)}export{c as a,m as b,p as c,E as d};
@@ -1 +1 @@
1
- import {e,g,b,a,h as h$1,c}from'./chunk-IEWZH6XD.js';import {encodeAbiParameters,parseUnits}from'viem';import {normalizeBlockchainCategory}from'@idosgames/core';var k=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],I=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],v=[{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"}]}],E=[{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"}]}],x=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function D(e,t,n){return encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,normalizeBlockchainCategory(n)])}async function h(e,t){let{walletClient:n,publicClient:r,account:s}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:s,chain:n.chain,value:t.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function T(e){let t=e.RewardPoolAddress;return t||null}async function W(e,t,n,r){return await e.publicClient.readContract({address:t,abi:v,functionName:"allowance",args:[e.account,n]})>=r?null:h(e,{address:t,abi:v,functionName:"approve",args:[n,r]})}async function N(e$1){let{client:t,clients:n,network:r,tokenAddress:s,amount:o,titleID:m,category:d}=e$1;if(e())return g("approve");let i=t.auth.context?.userID;if(!i)return b("approve","Not logged in.");let u=T(r);if(!u)return b("approve","Network has no RewardPoolAddress.");if(o<=0n)return b("approve","Amount must be positive.");try{await W(n,s,u,o);}catch(l){return b("approve",a(l))}let c;try{c=await h(n,{address:u,abi:k,functionName:"depositERC20",args:[s,o,i,m,d??""]});}catch(l){return b("deposit-onchain",a(l))}let p=await t.blockchain.depositToken(r.NetworkID??"",c);return p.ok?{ok:true,onChainTxHash:c,data:p.data}:b("report",p.error,{onChainTxHash:c})}async function S(e$1){let{clients:t,poolAddress:n,tokenAddress:r,amount:s,userID:o,titleID:m,category:d}=e$1;if(e())return g("approve");if(!o)return b("approve","userID is required.");if(s<=0n)return b("approve","Amount must be positive.");try{await W(t,r,n,s);}catch(i){return b("approve",a(i))}try{let i=await h(t,{address:n,abi:k,functionName:"depositERC20",args:[r,s,o,m,d??""]});return {ok:!0,onChainTxHash:i,data:{txHash:i}}}catch(i){return b("deposit-onchain",a(i))}}async function L(e$1){let{client:t,clients:n,network:r,nftContractAddress:s,tokenId:o,amount:m,titleID:d,category:i}=e$1;if(e())return g("deposit-onchain");let u=t.auth.context?.userID;if(!u)return b("deposit-onchain","Not logged in.");let c=T(r);if(!c)return b("deposit-onchain","Network has no RewardPoolAddress.");if(m<=0n)return b("deposit-onchain","Amount must be positive.");let p=D(u,d,i),l;try{l=await h(n,{address:s,abi:E,functionName:"safeTransferFrom",args:[n.account,c,o,m,p]});}catch(A){return b("deposit-onchain",a(A))}let f=await t.blockchain.depositNFT(r.NetworkID??"",l);return f.ok?{ok:true,onChainTxHash:l,data:f.data}:b("report",f.error,{onChainTxHash:l})}async function O(e$1){let{client:t,clients:n,network:r,nftContractAddress:s,tokenId:o,titleID:m,category:d}=e$1;if(e())return g("deposit-onchain");let i=t.auth.context?.userID;if(!i)return b("deposit-onchain","Not logged in.");let u=T(r);if(!u)return b("deposit-onchain","Network has no RewardPoolAddress.");let c=D(i,m,d),p;try{p=await h(n,{address:s,abi:x,functionName:"safeTransferFrom",args:[n.account,u,o,c]});}catch(f){return b("deposit-onchain",a(f))}let l=await t.blockchain.depositNFT(r.NetworkID??"",p);return l.ok?{ok:true,onChainTxHash:p,data:l.data}:b("report",l.error,{onChainTxHash:p})}function P(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function B(e,t){return h(e,{address:t.ContractAddress,abi:k,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),P(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function R(e,t){return h(e,{address:t.ContractAddress,abi:I,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),P(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function q(e,t){return h(e,{address:t.ContractAddress,abi:I,functionName:"withdrawERC721Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function U(e$1){let{client:t,clients:n,currencyID:r,networkID:s,walletAddress:o,amount:m,category:d}=e$1;if(e())return g("request");let i=await t.blockchain.requestTokenWithdrawal(r,s,o,m,d);if(!i.ok)return b("request",i.error);let u=i.data.EvmSignature,c=i.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let p;try{p=await B(n,u);}catch(f){return b("withdraw-onchain",a(f),{titleTransactionID:c})}let l=await H(t,c,p);return l.ok?{ok:true,onChainTxHash:p,data:i.data}:l}async function $(e$1){let{client:t,clients:n,itemID:r,networkID:s,walletAddress:o,amount:m,category:d}=e$1;if(e())return g("request");let i=await t.blockchain.requestNFTWithdrawal(r,s,o,m,d);if(!i.ok)return b("request",i.error);let u=i.data.EvmSignature,c=i.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let p;try{p=await R(n,u);}catch(f){return b("withdraw-onchain",a(f),{titleTransactionID:c})}let l=await H(t,c,p);return l.ok?{ok:true,onChainTxHash:p,data:i.data}:l}async function H(e,t,n){if(!t)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await e.blockchain.confirmWithdrawal(t,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:b("confirm",r.error,{onChainTxHash:n,titleTransactionID:t})}async function V(e$1){let{client:t,clients:n,networkID:r}=e$1;if(e())return h$1("challenge");let s=e$1.walletAddress??n.account,o=await t.auth.requestWalletChallenge(s,r);if(!o.ok)return c("challenge",o.error);let m;try{m=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(i){return c("sign",a(i))}let d=await t.auth.loginWithWallet(s,r,m);return d.ok?{ok:true,data:d.data}:c("login",d.error)}async function z(e$1){let{client:t,clients:n,networkID:r}=e$1;if(e())return h$1("challenge");let s=e$1.walletAddress??n.account,o=await t.auth.linkWallet(s,r);if(!o.ok)return c("challenge",o.error);if(!o.data.Challenge)return c("challenge","No challenge was issued.");let m;try{m=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(i){return c("sign",a(i))}let d=await t.auth.linkWallet(s,r,m);return d.ok?{ok:true,data:d.data}:c("login",d.error)}async function J(e$1){let{client:t,clients:n,network:r,tokenAddress:s,decimals:o,titleID:m,shortfall:d,completePurchase:i,bufferRatio:u=0,category:c}=e$1;if(e())return g("approve");if(d.missing<=0)return b("approve","Nothing to deposit.");let p=d.missing*(1+Math.max(0,u)),l;try{l=parseUnits(K(p,o),o);}catch(F){return b("approve",a(F))}let f=await N({client:t,clients:n,network:r,tokenAddress:s,amount:l,titleID:m,category:c});if(!f.ok)return f;let A=await i();return A.ok?{ok:true,onChainTxHash:f.onChainTxHash,data:A.data}:b("report",A.error,{onChainTxHash:f.onChainTxHash})}function K(e,t){return e.toFixed(Math.min(t,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}export{k as a,v as b,E as c,x as d,D as e,h as f,W as g,N as h,S as i,L as j,O as k,B as l,R as m,q as n,U as o,$ as p,V as q,z as r,J as s};
1
+ import {f,h as h$1,b,a,i,c}from'./chunk-K3THMWU2.js';import {encodeAbiParameters,parseUnits}from'viem';import {normalizeBlockchainCategory}from'@idosgames/core';var k=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],I=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],v=[{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"}]}],E=[{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"}]}],x=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function D(e,t,n){return encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,normalizeBlockchainCategory(n)])}async function h(e,t){let{walletClient:n,publicClient:r,account:s}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:s,chain:n.chain,value:t.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function T(e){let t=e.RewardPoolAddress;return t||null}async function W(e,t,n,r){return await e.publicClient.readContract({address:t,abi:v,functionName:"allowance",args:[e.account,n]})>=r?null:h(e,{address:t,abi:v,functionName:"approve",args:[n,r]})}async function N(e){let{client:t,clients:n,network:r,tokenAddress:s,amount:o,titleID:m,category:d}=e;if(f())return h$1("approve");let i=t.auth.context?.userID;if(!i)return b("approve","Not logged in.");let u=T(r);if(!u)return b("approve","Network has no RewardPoolAddress.");if(o<=0n)return b("approve","Amount must be positive.");try{await W(n,s,u,o);}catch(l){return b("approve",a(l))}let c;try{c=await h(n,{address:u,abi:k,functionName:"depositERC20",args:[s,o,i,m,d??""]});}catch(l){return b("deposit-onchain",a(l))}let p=await t.blockchain.depositToken(r.NetworkID??"",c);return p.ok?{ok:true,onChainTxHash:c,data:p.data}:b("report",p.error,{onChainTxHash:c})}async function S(e){let{clients:t,poolAddress:n,tokenAddress:r,amount:s,userID:o,titleID:m,category:d}=e;if(f())return h$1("approve");if(!o)return b("approve","userID is required.");if(s<=0n)return b("approve","Amount must be positive.");try{await W(t,r,n,s);}catch(i){return b("approve",a(i))}try{let i=await h(t,{address:n,abi:k,functionName:"depositERC20",args:[r,s,o,m,d??""]});return {ok:!0,onChainTxHash:i,data:{txHash:i}}}catch(i){return b("deposit-onchain",a(i))}}async function L(e){let{client:t,clients:n,network:r,nftContractAddress:s,tokenId:o,amount:m,titleID:d,category:i}=e;if(f())return h$1("deposit-onchain");let u=t.auth.context?.userID;if(!u)return b("deposit-onchain","Not logged in.");let c=T(r);if(!c)return b("deposit-onchain","Network has no RewardPoolAddress.");if(m<=0n)return b("deposit-onchain","Amount must be positive.");let p=D(u,d,i),l;try{l=await h(n,{address:s,abi:E,functionName:"safeTransferFrom",args:[n.account,c,o,m,p]});}catch(A){return b("deposit-onchain",a(A))}let f$1=await t.blockchain.depositNFT(r.NetworkID??"",l);return f$1.ok?{ok:true,onChainTxHash:l,data:f$1.data}:b("report",f$1.error,{onChainTxHash:l})}async function O(e){let{client:t,clients:n,network:r,nftContractAddress:s,tokenId:o,titleID:m,category:d}=e;if(f())return h$1("deposit-onchain");let i=t.auth.context?.userID;if(!i)return b("deposit-onchain","Not logged in.");let u=T(r);if(!u)return b("deposit-onchain","Network has no RewardPoolAddress.");let c=D(i,m,d),p;try{p=await h(n,{address:s,abi:x,functionName:"safeTransferFrom",args:[n.account,u,o,c]});}catch(f){return b("deposit-onchain",a(f))}let l=await t.blockchain.depositNFT(r.NetworkID??"",p);return l.ok?{ok:true,onChainTxHash:p,data:l.data}:b("report",l.error,{onChainTxHash:p})}function P(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function B(e,t){return h(e,{address:t.ContractAddress,abi:k,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),P(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function R(e,t){return h(e,{address:t.ContractAddress,abi:I,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),P(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function q(e,t){return h(e,{address:t.ContractAddress,abi:I,functionName:"withdrawERC721Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function U(e){let{client:t,clients:n,currencyID:r,networkID:s,walletAddress:o,amount:m,category:d}=e;if(f())return h$1("request");let i=await t.blockchain.requestTokenWithdrawal(r,s,o,m,d);if(!i.ok)return b("request",i.error);let u=i.data.EvmSignature,c=i.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let p;try{p=await B(n,u);}catch(f){return b("withdraw-onchain",a(f),{titleTransactionID:c})}let l=await H(t,c,p);return l.ok?{ok:true,onChainTxHash:p,data:i.data}:l}async function $(e){let{client:t,clients:n,itemID:r,networkID:s,walletAddress:o,amount:m,category:d}=e;if(f())return h$1("request");let i=await t.blockchain.requestNFTWithdrawal(r,s,o,m,d);if(!i.ok)return b("request",i.error);let u=i.data.EvmSignature,c=i.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let p;try{p=await R(n,u);}catch(f){return b("withdraw-onchain",a(f),{titleTransactionID:c})}let l=await H(t,c,p);return l.ok?{ok:true,onChainTxHash:p,data:i.data}:l}async function H(e,t,n){if(!t)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await e.blockchain.confirmWithdrawal(t,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:b("confirm",r.error,{onChainTxHash:n,titleTransactionID:t})}async function V(e){let{client:t,clients:n,networkID:r}=e;if(f())return i("challenge");let s=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(s,r);if(!o.ok)return c("challenge",o.error);let m;try{m=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(i){return c("sign",a(i))}let d=await t.auth.loginWithWallet(s,r,m);return d.ok?{ok:true,data:d.data}:c("login",d.error)}async function z(e){let{client:t,clients:n,networkID:r}=e;if(f())return i("challenge");let s=e.walletAddress??n.account,o=await t.auth.linkWallet(s,r);if(!o.ok)return c("challenge",o.error);if(!o.data.Challenge)return c("challenge","No challenge was issued.");let m;try{m=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(i){return c("sign",a(i))}let d=await t.auth.linkWallet(s,r,m);return d.ok?{ok:true,data:d.data}:c("login",d.error)}async function J(e){let{client:t,clients:n,network:r,tokenAddress:s,decimals:o,titleID:m,shortfall:d,completePurchase:i,bufferRatio:u=0,category:c}=e;if(f())return h$1("approve");if(d.missing<=0)return b("approve","Nothing to deposit.");let p=d.missing*(1+Math.max(0,u)),l;try{l=parseUnits(K(p,o),o);}catch(F){return b("approve",a(F))}let f$1=await N({client:t,clients:n,network:r,tokenAddress:s,amount:l,titleID:m,category:c});if(!f$1.ok)return f$1;let A=await i();return A.ok?{ok:true,onChainTxHash:f$1.onChainTxHash,data:A.data}:b("report",A.error,{onChainTxHash:f$1.onChainTxHash})}function K(e,t){return e.toFixed(Math.min(t,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}export{k as a,v as b,E as c,x as d,D as e,h as f,W as g,N as h,S as i,L as j,O as k,B as l,R as m,q as n,U as o,$ as p,V as q,z as r,J as s};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var viem=require('viem'),core=require('@idosgames/core');function f(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 g(t,e){return {ok:false,stage:t,error:e}}var C="WALLET_USE_SITE_PANEL";function y(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function K(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function w(t){return s(t,C)}function A(t){return g(t,C)}var $=core.PLATFORM_ORIGINS;function Y(t){if(typeof window>"u")return ()=>{};let e=n=>{$.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&t();};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}var E={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},T="PLATFORM_WALLET_UNAVAILABLE",Z=5e3,J=18e4;function Q(){let t=[...core.PLATFORM_ORIGINS],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&core.isPlatformParentOrigin(e)&&t.push(e),t}function j(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function R(t,e,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:T});let r=window.parent;if(!r)return Promise.resolve({ok:false,error:T});let o=j();return new Promise(i=>{let p=false,l,a=d=>{p||(p=true,window.removeEventListener("message",u),clearTimeout(l),i(d));},u=d=>{if(!core.isPlatformParentOrigin(d.origin))return;let c=d.data;if(!(!c||c.requestId!==o)){if(c.type===E.ack){clearTimeout(l),l=setTimeout(()=>a({ok:false,error:"TIMEOUT"}),J);return}c.type===e&&a({ok:c.ok===true,error:typeof c.error=="string"?c.error:void 0,address:typeof c.address=="string"?c.address:void 0,signature:typeof c.signature=="string"?c.signature:void 0});}};l=setTimeout(()=>a({ok:false,error:T}),Z),window.addEventListener("message",u);for(let d of Q())try{r.postMessage({type:t,requestId:o,...n},d);}catch{}})}async function X(t){let{client:e,networkID:n}=t;return F(t,async r=>{let o=await e.auth.requestWalletChallenge(r,n);return o.ok?{ok:true,message:o.data.Message}:{ok:false,error:o.error}},(r,o)=>e.auth.loginWithWallet(r,n,o))}async function ee(t){let{client:e,networkID:n}=t;return F(t,async r=>{let o=await e.auth.linkWallet(r,n);return o.ok?o.data.Challenge?{ok:true,message:o.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:o.error}},(r,o)=>e.auth.linkWallet(r,n,o))}async function F(t,e,n){let{client:r,family:o}=t,i=r.titleID,p=await R(E.addressRequest,E.addressResponse,{titleID:i,family:o});if(!p.ok||!p.address)return g("challenge",p.error??"NO_WALLET");let l=p.address,a=await e(l);if(!a.ok)return g("challenge",a.error);let u=await R(E.signRequest,E.signResponse,{titleID:i,family:o,address:l,message:a.message});if(!u.ok||!u.signature)return g("sign",u.error??"SIGN_FAILED");let d=await n(l,u.signature);return d.ok?{ok:true,data:d.data}:g("login",d.error)}var te={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"}}},ne={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"}}},ae={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"}}},re={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"}}},oe={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"}}},ie={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"}}},se={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"}}},le={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"}}},de={mainnet:te,bsc:ne,polygon:ae,base:re,arbitrum:oe,optimism:ie,sepolia:se,polygonAmoy:le};function Fe(t){return Object.values(de).find(e=>e.id===t)}function Me(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var He={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"},Oe={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"};var b=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],D=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],x=[{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"}]}],v=[{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"}]}],P=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function I(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function k(t,e){let{walletClient:n,publicClient:r,account:o}=t,i=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:i})).status==="reverted")throw new Error(`On-chain transaction reverted (${i}).`);return i}function S(t){let e=t.RewardPoolAddress;return e||null}async function L(t,e,n,r){return await t.publicClient.readContract({address:e,abi:x,functionName:"allowance",args:[t.account,n]})>=r?null:k(t,{address:e,abi:x,functionName:"approve",args:[n,r]})}async function N(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:i,titleID:p,category:l}=t;if(y())return w("approve");let a=e.auth.context?.userID;if(!a)return s("approve","Not logged in.");let u=S(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(i<=0n)return s("approve","Amount must be positive.");try{await L(n,o,u,i);}catch(m){return s("approve",f(m))}let d;try{d=await k(n,{address:u,abi:b,functionName:"depositERC20",args:[o,i,a,p,l??""]});}catch(m){return s("deposit-onchain",f(m))}let c=await e.blockchain.depositToken(r.NetworkID??"",d);return c.ok?{ok:true,onChainTxHash:d,data:c.data}:s("report",c.error,{onChainTxHash:d})}async function ue(t){let{clients:e,poolAddress:n,tokenAddress:r,amount:o,userID:i,titleID:p,category:l}=t;if(y())return w("approve");if(!i)return s("approve","userID is required.");if(o<=0n)return s("approve","Amount must be positive.");try{await L(e,r,n,o);}catch(a){return s("approve",f(a))}try{let a=await k(e,{address:n,abi:b,functionName:"depositERC20",args:[r,o,i,p,l??""]});return {ok:!0,onChainTxHash:a,data:{txHash:a}}}catch(a){return s("deposit-onchain",f(a))}}async function me(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,amount:p,titleID:l,category:a}=t;if(y())return w("deposit-onchain");let u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let d=S(r);if(!d)return s("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return s("deposit-onchain","Amount must be positive.");let c=I(u,l,a),m;try{m=await k(n,{address:o,abi:v,functionName:"safeTransferFrom",args:[n.account,d,i,p,c]});}catch(W){return s("deposit-onchain",f(W))}let h=await e.blockchain.depositNFT(r.NetworkID??"",m);return h.ok?{ok:true,onChainTxHash:m,data:h.data}:s("report",h.error,{onChainTxHash:m})}async function ge(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");let u=S(r);if(!u)return s("deposit-onchain","Network has no RewardPoolAddress.");let d=I(a,p,l),c;try{c=await k(n,{address:o,abi:P,functionName:"safeTransferFrom",args:[n.account,u,i,d]});}catch(h){return s("deposit-onchain",f(h))}let m=await e.blockchain.depositNFT(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:s("report",m.error,{onChainTxHash:c})}function M(t){return (t.Splits??[]).map(e=>({to:e.To,amount:BigInt(e.Amount??"0")}))}async function H(t,e){return k(t,{address:e.ContractAddress,abi:b,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),M(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function O(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),M(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function fe(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC721Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function ye(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await H(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await _(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function he(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestNFTWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await O(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await _(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function _(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 we(t){let{client:e,clients:n,networkID:r}=t;if(y())return A("challenge");let o=t.walletAddress??n.account,i=await e.auth.requestWalletChallenge(o,r);if(!i.ok)return g("challenge",i.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Message});}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function ke(t){let{client:e,clients:n,networkID:r}=t;if(y())return A("challenge");let o=t.walletAddress??n.account,i=await e.auth.linkWallet(o,r);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Challenge});}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Ee(t){let{client:e,clients:n,network:r,tokenAddress:o,decimals:i,titleID:p,shortfall:l,completePurchase:a,bufferRatio:u=0,category:d}=t;if(y())return w("approve");if(l.missing<=0)return s("approve","Nothing to deposit.");let c=l.missing*(1+Math.max(0,u)),m;try{m=viem.parseUnits(be(c,i),i);}catch(U){return s("approve",f(U))}let h=await N({client:e,clients:n,network:r,tokenAddress:o,amount:m,titleID:p,category:d});if(!h.ok)return h;let W=await a();return W.ok?{ok:true,onChainTxHash:h.onChainTxHash,data:W.data}:s("report",W.error,{onChainTxHash:h.onChainTxHash})}function be(t,e){return t.toFixed(Math.min(e,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}async function Te(t){let{client:e,adapter:n,network:r,mint:o,amountRaw:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");if(i<=0n)return s("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:o,amountRaw:i,userID:a,titleID:p,category:core.normalizeBlockchainCategory(l)});}catch(c){return s("deposit-onchain",f(c))}let d=await e.blockchain.depositToken(r.NetworkID??"",u);return d.ok?{ok:true,onChainTxHash:u,data:d.data}:s("report",d.error,{onChainTxHash:u})}async function xe(t){let{client:e,adapter:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.SolanaSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no Solana signature.",{titleTransactionID:d});let c;try{c=await n.submitWithdrawal(u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}if(!d)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let m=await e.blockchain.confirmWithdrawal(d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:s("confirm",m.error,{onChainTxHash:c,titleTransactionID:d})}async function Ie(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return A("challenge");let i=await e.auth.requestWalletChallenge(r,n);if(!i.ok)return g("challenge",i.error);let p;try{let a=await o(new TextEncoder().encode(i.data.Message));p=G(a);}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Ce(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return A("challenge");let i=await e.auth.linkWallet(r,n);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{let a=await o(new TextEncoder().encode(i.data.Challenge));p=G(a);}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}function G(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}
2
- exports.PLATFORM_WALLET_MESSAGES=E;exports.PLATFORM_WALLET_UNAVAILABLE=T;exports.WALLET_USE_SITE_PANEL=C;exports.arbitrum=oe;exports.base=re;exports.bridgeFail=s;exports.bsc=ne;exports.chainById=Fe;exports.depositNftEvm=me;exports.depositNftEvm721=ge;exports.depositTokenEvm=N;exports.depositTokenOnChainEvm=ue;exports.depositTokenSolana=Te;exports.encodeNftDepositData=I;exports.ensureErc20Allowance=L;exports.erc1155Abi=v;exports.erc20Abi=x;exports.erc721Abi=P;exports.idosChains=de;exports.isEmbeddedInPlatform=y;exports.isEmbeddedOnForeignSite=K;exports.linkWalletEvm=ke;exports.linkWalletSolana=Ce;exports.linkWalletViaPlatform=ee;exports.loginWithWalletEvm=we;exports.loginWithWalletSolana=Ie;exports.loginWithWalletViaPlatform=X;exports.mainnet=te;exports.onWalletBalanceChanged=Y;exports.optimism=ie;exports.payWithWalletEvm=Ee;exports.polygon=ae;exports.polygonAmoy=le;exports.rewardPoolAbi=b;exports.sepolia=se;exports.solanaDevnet=Oe;exports.solanaMainnet=He;exports.submitEvmNftWithdrawal=O;exports.submitEvmNftWithdrawal721=fe;exports.submitEvmTokenWithdrawal=H;exports.toAppKitNetwork=Me;exports.toErrorMessage=f;exports.walletLoginFail=g;exports.withdrawNftEvm=he;exports.withdrawTokenEvm=ye;exports.withdrawTokenSolana=xe;exports.writeAndWait=k;
1
+ 'use strict';var viem=require('viem'),core=require('@idosgames/core');function f(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 g(t,e){return {ok:false,stage:t,error:e}}var C="WALLET_USE_SITE_PANEL",$=/^[a-z0-9]{8}-preview\.idos\.games$/;function N(t=typeof window>"u"?"":window.location.hostname){let e=t.toLowerCase();return $.test(e)?true:e!=="localhost"&&e!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function y(){if(typeof window>"u"||N())return false;try{return window.self!==window.top}catch{return true}}function Y(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function w(t){return s(t,C)}function E(t){return g(t,C)}var z=core.PLATFORM_ORIGINS;function Z(t){if(typeof window>"u")return ()=>{};let e=n=>{z.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&t();};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}var A={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},T="PLATFORM_WALLET_UNAVAILABLE",Q=5e3,j=18e4;function X(){let t=[...core.PLATFORM_ORIGINS],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&core.isPlatformParentOrigin(e)&&t.push(e),t}function ee(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function B(t,e,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:T});let r=window.parent;if(!r)return Promise.resolve({ok:false,error:T});let o=ee();return new Promise(i=>{let p=false,l,a=d=>{p||(p=true,window.removeEventListener("message",u),clearTimeout(l),i(d));},u=d=>{if(!core.isPlatformParentOrigin(d.origin))return;let c=d.data;if(!(!c||c.requestId!==o)){if(c.type===A.ack){clearTimeout(l),l=setTimeout(()=>a({ok:false,error:"TIMEOUT"}),j);return}c.type===e&&a({ok:c.ok===true,error:typeof c.error=="string"?c.error:void 0,address:typeof c.address=="string"?c.address:void 0,signature:typeof c.signature=="string"?c.signature:void 0});}};l=setTimeout(()=>a({ok:false,error:T}),Q),window.addEventListener("message",u);for(let d of X())try{r.postMessage({type:t,requestId:o,...n},d);}catch{}})}async function te(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.requestWalletChallenge(r,n);return o.ok?{ok:true,message:o.data.Message}:{ok:false,error:o.error}},(r,o)=>e.auth.loginWithWallet(r,n,o))}async function ne(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.linkWallet(r,n);return o.ok?o.data.Challenge?{ok:true,message:o.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:o.error}},(r,o)=>e.auth.linkWallet(r,n,o))}async function M(t,e,n){let{client:r,family:o}=t,i=r.titleID,p=await B(A.addressRequest,A.addressResponse,{titleID:i,family:o});if(!p.ok||!p.address)return g("challenge",p.error??"NO_WALLET");let l=p.address,a=await e(l);if(!a.ok)return g("challenge",a.error);let u=await B(A.signRequest,A.signResponse,{titleID:i,family:o,address:l,message:a.message});if(!u.ok||!u.signature)return g("sign",u.error??"SIGN_FAILED");let d=await n(l,u.signature);return d.ok?{ok:true,data:d.data}:g("login",d.error)}var ae={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"}}},re={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"}}},oe={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"}}},ie={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"}}},se={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"}}},le={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"}}},de={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"}}},ce={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"}}},pe={mainnet:ae,bsc:re,polygon:oe,base:ie,arbitrum:se,optimism:le,sepolia:de,polygonAmoy:ce};function _e(t){return Object.values(pe).find(e=>e.id===t)}function Oe(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var He={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"},Ge={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"};var b=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],D=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],x=[{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"}]}],P=[{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"}]}],v=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function I(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function k(t,e){let{walletClient:n,publicClient:r,account:o}=t,i=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:i})).status==="reverted")throw new Error(`On-chain transaction reverted (${i}).`);return i}function S(t){let e=t.RewardPoolAddress;return e||null}async function L(t,e,n,r){return await t.publicClient.readContract({address:e,abi:x,functionName:"allowance",args:[t.account,n]})>=r?null:k(t,{address:e,abi:x,functionName:"approve",args:[n,r]})}async function R(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:i,titleID:p,category:l}=t;if(y())return w("approve");let a=e.auth.context?.userID;if(!a)return s("approve","Not logged in.");let u=S(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(i<=0n)return s("approve","Amount must be positive.");try{await L(n,o,u,i);}catch(m){return s("approve",f(m))}let d;try{d=await k(n,{address:u,abi:b,functionName:"depositERC20",args:[o,i,a,p,l??""]});}catch(m){return s("deposit-onchain",f(m))}let c=await e.blockchain.depositToken(r.NetworkID??"",d);return c.ok?{ok:true,onChainTxHash:d,data:c.data}:s("report",c.error,{onChainTxHash:d})}async function ge(t){let{clients:e,poolAddress:n,tokenAddress:r,amount:o,userID:i,titleID:p,category:l}=t;if(y())return w("approve");if(!i)return s("approve","userID is required.");if(o<=0n)return s("approve","Amount must be positive.");try{await L(e,r,n,o);}catch(a){return s("approve",f(a))}try{let a=await k(e,{address:n,abi:b,functionName:"depositERC20",args:[r,o,i,p,l??""]});return {ok:!0,onChainTxHash:a,data:{txHash:a}}}catch(a){return s("deposit-onchain",f(a))}}async function fe(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,amount:p,titleID:l,category:a}=t;if(y())return w("deposit-onchain");let u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let d=S(r);if(!d)return s("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return s("deposit-onchain","Amount must be positive.");let c=I(u,l,a),m;try{m=await k(n,{address:o,abi:P,functionName:"safeTransferFrom",args:[n.account,d,i,p,c]});}catch(W){return s("deposit-onchain",f(W))}let h=await e.blockchain.depositNFT(r.NetworkID??"",m);return h.ok?{ok:true,onChainTxHash:m,data:h.data}:s("report",h.error,{onChainTxHash:m})}async function ye(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");let u=S(r);if(!u)return s("deposit-onchain","Network has no RewardPoolAddress.");let d=I(a,p,l),c;try{c=await k(n,{address:o,abi:v,functionName:"safeTransferFrom",args:[n.account,u,i,d]});}catch(h){return s("deposit-onchain",f(h))}let m=await e.blockchain.depositNFT(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:s("report",m.error,{onChainTxHash:c})}function _(t){return (t.Splits??[]).map(e=>({to:e.To,amount:BigInt(e.Amount??"0")}))}async function O(t,e){return k(t,{address:e.ContractAddress,abi:b,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function H(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function he(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC721Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function we(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await O(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function ke(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestNFTWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await H(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function G(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 Ee(t){let{client:e,clients:n,networkID:r}=t;if(y())return E("challenge");let o=t.walletAddress??n.account,i=await e.auth.requestWalletChallenge(o,r);if(!i.ok)return g("challenge",i.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Message});}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Ae(t){let{client:e,clients:n,networkID:r}=t;if(y())return E("challenge");let o=t.walletAddress??n.account,i=await e.auth.linkWallet(o,r);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Challenge});}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function We(t){let{client:e,clients:n,network:r,tokenAddress:o,decimals:i,titleID:p,shortfall:l,completePurchase:a,bufferRatio:u=0,category:d}=t;if(y())return w("approve");if(l.missing<=0)return s("approve","Nothing to deposit.");let c=l.missing*(1+Math.max(0,u)),m;try{m=viem.parseUnits(Te(c,i),i);}catch(q){return s("approve",f(q))}let h=await R({client:e,clients:n,network:r,tokenAddress:o,amount:m,titleID:p,category:d});if(!h.ok)return h;let W=await a();return W.ok?{ok:true,onChainTxHash:h.onChainTxHash,data:W.data}:s("report",W.error,{onChainTxHash:h.onChainTxHash})}function Te(t,e){return t.toFixed(Math.min(e,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}async function Ie(t){let{client:e,adapter:n,network:r,mint:o,amountRaw:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");if(i<=0n)return s("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:o,amountRaw:i,userID:a,titleID:p,category:core.normalizeBlockchainCategory(l)});}catch(c){return s("deposit-onchain",f(c))}let d=await e.blockchain.depositToken(r.NetworkID??"",u);return d.ok?{ok:true,onChainTxHash:u,data:d.data}:s("report",d.error,{onChainTxHash:u})}async function Ce(t){let{client:e,adapter:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.SolanaSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no Solana signature.",{titleTransactionID:d});let c;try{c=await n.submitWithdrawal(u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}if(!d)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let m=await e.blockchain.confirmWithdrawal(d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:s("confirm",m.error,{onChainTxHash:c,titleTransactionID:d})}async function De(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return E("challenge");let i=await e.auth.requestWalletChallenge(r,n);if(!i.ok)return g("challenge",i.error);let p;try{let a=await o(new TextEncoder().encode(i.data.Message));p=U(a);}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Pe(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return E("challenge");let i=await e.auth.linkWallet(r,n);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{let a=await o(new TextEncoder().encode(i.data.Challenge));p=U(a);}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}function U(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}
2
+ exports.PLATFORM_WALLET_MESSAGES=A;exports.PLATFORM_WALLET_UNAVAILABLE=T;exports.WALLET_USE_SITE_PANEL=C;exports.arbitrum=se;exports.base=ie;exports.bridgeFail=s;exports.bsc=re;exports.chainById=_e;exports.depositNftEvm=fe;exports.depositNftEvm721=ye;exports.depositTokenEvm=R;exports.depositTokenOnChainEvm=ge;exports.depositTokenSolana=Ie;exports.encodeNftDepositData=I;exports.ensureErc20Allowance=L;exports.erc1155Abi=P;exports.erc20Abi=x;exports.erc721Abi=v;exports.idosChains=pe;exports.isAiCoderPreview=N;exports.isEmbeddedInPlatform=y;exports.isEmbeddedOnForeignSite=Y;exports.linkWalletEvm=Ae;exports.linkWalletSolana=Pe;exports.linkWalletViaPlatform=ne;exports.loginWithWalletEvm=Ee;exports.loginWithWalletSolana=De;exports.loginWithWalletViaPlatform=te;exports.mainnet=ae;exports.onWalletBalanceChanged=Z;exports.optimism=le;exports.payWithWalletEvm=We;exports.polygon=oe;exports.polygonAmoy=ce;exports.rewardPoolAbi=b;exports.sepolia=de;exports.solanaDevnet=Ge;exports.solanaMainnet=He;exports.submitEvmNftWithdrawal=H;exports.submitEvmNftWithdrawal721=he;exports.submitEvmTokenWithdrawal=O;exports.toAppKitNetwork=Oe;exports.toErrorMessage=f;exports.walletLoginFail=g;exports.withdrawNftEvm=ke;exports.withdrawTokenEvm=we;exports.withdrawTokenSolana=Ce;exports.writeAndWait=k;
package/dist/index.d.cts CHANGED
@@ -13,6 +13,16 @@ export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as Withdraw
13
13
  * message instead of a generic failure.
14
14
  */
15
15
  declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
16
+ /**
17
+ * The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
18
+ *
19
+ * Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
20
+ * idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
21
+ * that host serves only the preview runtime and is framed only by the dashboard. The one extra case
22
+ * is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
23
+ * the preview runtime sets: on a developer's own machine there is nothing to protect.
24
+ */
25
+ declare function isAiCoderPreview(hostname?: string): boolean;
16
26
  /**
17
27
  * The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
18
28
  * check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
@@ -489,4 +499,4 @@ declare function loginWithWalletSolana(params: LoginWithWalletSolanaParams): Pro
489
499
  */
490
500
  declare function linkWalletSolana(params: LoginWithWalletSolanaParams): Promise<WalletLoginResult<WalletLinkResponse>>;
491
501
 
492
- export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
502
+ export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isAiCoderPreview, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,16 @@ export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as Withdraw
13
13
  * message instead of a generic failure.
14
14
  */
15
15
  declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
16
+ /**
17
+ * The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
18
+ *
19
+ * Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
20
+ * idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
21
+ * that host serves only the preview runtime and is framed only by the dashboard. The one extra case
22
+ * is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
23
+ * the preview runtime sets: on a developer's own machine there is nothing to protect.
24
+ */
25
+ declare function isAiCoderPreview(hostname?: string): boolean;
16
26
  /**
17
27
  * The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
18
28
  * check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
@@ -489,4 +499,4 @@ declare function loginWithWalletSolana(params: LoginWithWalletSolanaParams): Pro
489
499
  */
490
500
  declare function linkWalletSolana(params: LoginWithWalletSolanaParams): Promise<WalletLoginResult<WalletLinkResponse>>;
491
501
 
492
- export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
502
+ export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isAiCoderPreview, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{j as depositNftEvm,k as depositNftEvm721,h as depositTokenEvm,i as depositTokenOnChainEvm,e as encodeNftDepositData,g as ensureErc20Allowance,c as erc1155Abi,b as erc20Abi,d as erc721Abi,r as linkWalletEvm,q as loginWithWalletEvm,s as payWithWalletEvm,a as rewardPoolAbi,m as submitEvmNftWithdrawal,n as submitEvmNftWithdrawal721,l as submitEvmTokenWithdrawal,p as withdrawNftEvm,o as withdrawTokenEvm,f as writeAndWait}from'./chunk-FFBRTCQK.js';export{a as PLATFORM_WALLET_MESSAGES,b as PLATFORM_WALLET_UNAVAILABLE,d as linkWalletViaPlatform,c as loginWithWalletViaPlatform}from'./chunk-3VONNSCN.js';export{a as depositTokenSolana,d as linkWalletSolana,c as loginWithWalletSolana,b as withdrawTokenSolana}from'./chunk-QST6UVX7.js';export{d as WALLET_USE_SITE_PANEL,n as arbitrum,m as base,b as bridgeFail,k as bsc,s as chainById,r as idosChains,e as isEmbeddedInPlatform,f as isEmbeddedOnForeignSite,j as mainnet,i as onWalletBalanceChanged,o as optimism,l as polygon,q as polygonAmoy,p as sepolia,v as solanaDevnet,u as solanaMainnet,t as toAppKitNetwork,a as toErrorMessage,c as walletLoginFail}from'./chunk-IEWZH6XD.js';
1
+ export{j as depositNftEvm,k as depositNftEvm721,h as depositTokenEvm,i as depositTokenOnChainEvm,e as encodeNftDepositData,g as ensureErc20Allowance,c as erc1155Abi,b as erc20Abi,d as erc721Abi,r as linkWalletEvm,q as loginWithWalletEvm,s as payWithWalletEvm,a as rewardPoolAbi,m as submitEvmNftWithdrawal,n as submitEvmNftWithdrawal721,l as submitEvmTokenWithdrawal,p as withdrawNftEvm,o as withdrawTokenEvm,f as writeAndWait}from'./chunk-YTTVLBAW.js';export{a as PLATFORM_WALLET_MESSAGES,b as PLATFORM_WALLET_UNAVAILABLE,d as linkWalletViaPlatform,c as loginWithWalletViaPlatform}from'./chunk-Q2E7DE4S.js';export{a as depositTokenSolana,d as linkWalletSolana,c as loginWithWalletSolana,b as withdrawTokenSolana}from'./chunk-MLIXKTS6.js';export{d as WALLET_USE_SITE_PANEL,o as arbitrum,n as base,b as bridgeFail,l as bsc,t as chainById,s as idosChains,e as isAiCoderPreview,f as isEmbeddedInPlatform,g as isEmbeddedOnForeignSite,k as mainnet,j as onWalletBalanceChanged,p as optimism,m as polygon,r as polygonAmoy,q as sepolia,w as solanaDevnet,v as solanaMainnet,u as toAppKitNetwork,a as toErrorMessage,c as walletLoginFail}from'./chunk-K3THMWU2.js';
@@ -1,2 +1,2 @@
1
- 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var $={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},Q={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"}}},J={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"}}},X={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"}}},ee={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"}}},te={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"}}},ne={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"}}},xe={mainnet:$,bsc:Q,polygon:Z,base:J,arbitrum:X,optimism:ee,sepolia:te,polygonAmoy:ne};function Je(e){return Object.values(xe).find(t=>t.id===e)}function De(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var Te=null;function Ne(e){Te=e;}function ce(){return Te}var Pe=[$,Q,Z,J,X,ee,te,ne],de=new Map;function pe(e){let{chains:t=Pe,walletConnectProjectId:n,appName:r,appUrl:a,appIcon:o,transports:d,connectors:i}=e,s=n??"__extension_only__";if(!i){let y=de.get(s);if(y)return y}let u={};for(let y of t)u[y.id]=d?.[y.id]??wagmi.http();let c=a??(typeof window<"u"?window.location.origin:""),m={name:r??"iDosGames",description:r??"iDosGames game",url:c,icons:o?[o]:[]};if(n&&!i){let y=t.map(De),I=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:u});return Ne(react.createAppKit({adapters:[I],networks:y,projectId:n,metadata:m,features:{analytics:false,email:false,socials:false}})),de.set(s,I.wagmiConfig),I.wagmiConfig}let f=i??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})],b=wagmi.createConfig({chains:t,connectors:f,transports:u});return i||de.set(s,b),b}function G(e){let{wagmiConfig:t,queryClient:n,children:r}=e,[a]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:a,children:r})})}var re=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],Ie=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],ue=[{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"}]}],Se=[{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(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}async function B(e,t){let{walletClient:n,publicClient:r,account:a}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:a,chain:n.chain,value:t.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function D(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 A(e,t){return {ok:false,stage:e,error:t}}var Re="WALLET_USE_SITE_PANEL";function T(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function H(e){return p(e,Re)}function me(e){return A(e,Re)}function Le(e){let t=e.RewardPoolAddress;return t||null}async function Fe(e,t,n,r){return await e.publicClient.readContract({address:t,abi:ue,functionName:"allowance",args:[e.account,n]})>=r?null:B(e,{address:t,abi:ue,functionName:"approve",args:[n,r]})}async function fe(e){let{client:t,clients:n,network:r,tokenAddress:a,amount:o,titleID:d,category:i}=e;if(T())return H("approve");let s=t.auth.context?.userID;if(!s)return p("approve","Not logged in.");let u=Le(r);if(!u)return p("approve","Network has no RewardPoolAddress.");if(o<=0n)return p("approve","Amount must be positive.");try{await Fe(n,a,u,o);}catch(f){return p("approve",D(f))}let c;try{c=await B(n,{address:u,abi:re,functionName:"depositERC20",args:[a,o,s,d,i??""]});}catch(f){return p("deposit-onchain",D(f))}let m=await t.blockchain.depositToken(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:p("report",m.error,{onChainTxHash:c})}async function ge(e){let{client:t,clients:n,network:r,nftContractAddress:a,tokenId:o,amount:d,titleID:i,category:s}=e;if(T())return H("deposit-onchain");let u=t.auth.context?.userID;if(!u)return p("deposit-onchain","Not logged in.");let c=Le(r);if(!c)return p("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return p("deposit-onchain","Amount must be positive.");let m=Be(u,i,s),f;try{f=await B(n,{address:a,abi:Se,functionName:"safeTransferFrom",args:[n.account,c,o,d,m]});}catch(y){return p("deposit-onchain",D(y))}let b=await t.blockchain.depositNFT(r.NetworkID??"",f);return b.ok?{ok:true,onChainTxHash:f,data:b.data}:p("report",b.error,{onChainTxHash:f})}function He(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function Oe(e,t){return B(e,{address:t.ContractAddress,abi:re,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),He(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Me(e,t){return B(e,{address:t.ContractAddress,abi:Ie,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),He(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function ye(e){let{client:t,clients:n,currencyID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(T())return H("request");let s=await t.blockchain.requestTokenWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await Oe(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await _e(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function we(e){let{client:t,clients:n,itemID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(T())return H("request");let s=await t.blockchain.requestNFTWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await Me(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await _e(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function _e(e,t,n){if(!t)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await e.blockchain.confirmWithdrawal(t,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:p("confirm",r.error,{onChainTxHash:n,titleTransactionID:t})}async function U(e){let{client:t,clients:n,networkID:r}=e;if(T())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(a,r);if(!o.ok)return A("challenge",o.error);let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(s){return A("sign",D(s))}let i=await t.auth.loginWithWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}async function he(e){let{client:t,clients:n,networkID:r}=e;if(T())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.linkWallet(a,r);if(!o.ok)return A("challenge",o.error);if(!o.data.Challenge)return A("challenge","No challenge was issued.");let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(s){return A("sign",D(s))}let i=await t.auth.linkWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}function oe(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}var K="Wallet not connected.";function Ce(e,t){let n=oe();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,a)=>n?U({client:e,clients:n,networkID:r,walletAddress:a}):Promise.resolve(A("challenge",K)),depositToken:r=>n?fe({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("approve",K)),depositNft:r=>n?ge({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("deposit-onchain",K)),withdrawToken:r=>n?ye({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K)),withdrawNft:r=>n?we({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K))}}function be(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}function vt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(G,{wagmiConfig:t,children:jsxRuntime.jsx(ze,{...n})})}function kt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Et(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 Ue(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 At(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,a=i=>{r||(r=true,o(),clearTimeout(d),n(i));},o=actions.watchAccount(e,{onChange:i=>{i.isConnected&&a(true);}}),d=setTimeout(()=>a(false),t);})}function xt(e,t=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(e).status)?new Promise(r=>{let a=false,o=()=>{a||(a=true,d(),clearTimeout(i),r());},d=actions.watchAccount(e,{onChange:s=>{n(s.status)||o();}}),i=setTimeout(o,t);}):Promise.resolve()}function Dt(e){let t=a=>e.find(o=>o.id===a||o.type===a),n=t("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:t("walletConnect")??n??e[0]}var Ke=9e4;async function Tt(e){try{let r=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,a=r?.native||r?.universal;return !a||typeof window>"u"?!1:(window.location.href=a,!0)}catch{return false}}function qe(e,t){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),t);e.then(o=>{clearTimeout(a),n(o);},o=>{clearTimeout(a),r(o instanceof Error?o:new Error(String(o)));});})}function ze(e){let{client:t,networkID:n,onAuthenticated:r,disabled:a,label:o,style:d,autoStart:i,mode:s="login",onLinked:u}=e,c=wagmi.useConfig(),{isConnected:m}=wagmi.useAccount(),{connectAsync:f,connectors:b}=wagmi.useConnect(),y=oe(),[I,x]=react$1.useState(false),[O,w]=react$1.useState(null),[M,L]=react$1.useState(false),j=react$1.useRef(0),S=react$1.useRef(false),N=async()=>{let P=++j.current,E=()=>j.current===P;x(true),w(null);try{if(await xt(c),!E())return;if(!actions.getAccount(c).isConnected){let v=ce();if(v){if(await v.open(),!await At(c)){w("No wallet was connected.");return}}else {let V=Dt(b);if(!V){w("No wallet connector is configured.");return}try{await f({connector:V});}catch(_){if(!kt(_))throw _}}}let h=y??await Ue(c);if(!h&&actions.getAccount(c).isConnected&&(await new Promise(v=>setTimeout(v,300)),h=await Ue(c),!E()))return;if(!h){w("Wallet client is not available.");return}if(L(!0),s==="link"){let v=await qe(he({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(v.ok){u?.(v.data.PlayAccess??null);return}w(v.stage==="sign"?"Signature declined.":be(v.error,"Could not link the wallet."));return}let Y=await qe(U({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(Y.ok){r();return}w(Y.stage==="sign"?"Signature declined.":be(Y.error,"Wallet sign-in failed."));}catch(h){if(!E())return;console.error("[idosgames/wallet] wallet sign-in failed:",h),w(Et(h));}finally{E()&&(x(false),L(false));}};react$1.useEffect(()=>{!i||S.current||(S.current=true,N());},[i]);let z=async()=>{await Tt(c)||await ce()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{M?z():N();},disabled:a,style:{...Nt,...a?{opacity:.6,cursor:"default"}:null,...d},children:M?"Waiting for signature \u2014 tap to open wallet":I?"Check your wallet\u2026":m?o??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),O&&jsxRuntime.jsx("span",{role:"alert",style:Pt,children:O})]})}var Nt={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Pt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Ot={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"},Mt={fontWeight:700,fontSize:16},R={fontSize:12,opacity:.7},ke={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},_t={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},ie={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Ee={display:"flex",gap:8};function Gt(e){let{client:t,walletConnectProjectId:n,appName:r,onClose:a,style:o}=e,[d,i]=react$1.useState(n??"");react$1.useEffect(()=>{if(n)return;let u=true;return (async()=>{let c=await t.blockchain.getDefinitions();if(!u||!c.ok)return;let m=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;m&&i(m);})(),()=>{u=false;}},[t,n]);let s=react$1.useMemo(()=>pe({walletConnectProjectId:d||void 0,appName:r}),[d,r]);return jsxRuntime.jsx(G,{wagmiConfig:s,children:jsxRuntime.jsx(Ut,{client:t,appName:r,onClose:a,style:o})})}function Ut({client:e,onClose:t,style:n}){let r=Ce(e,e.titleID),{address:a,isConnected:o,chainId:d}=wagmi.useAccount(),{connect:i,connectors:s}=wagmi.useConnect(),{disconnect:u}=wagmi.useDisconnect(),{switchChainAsync:c}=wagmi.useSwitchChain(),[,m]=react$1.useReducer(l=>l+1,0),[f,b]=react$1.useState({}),[y,I]=react$1.useState({}),[x,O]=react$1.useState(""),[w,M]=react$1.useState(""),[L,j]=react$1.useState(""),[S,N]=react$1.useState(false),[z,P]=react$1.useState(null);react$1.useEffect(()=>{let l=true;return (async()=>{let C=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!l||!C.ok)return;let F=C.data.Blockchain?.Networks??{},le={};for(let[Ze,Ae]of Object.entries(F))Ae.Type==="EVM"&&(le[Ze]=Ae);b(le),I(C.data.CryptoCurrencies??{});let Qe=Object.keys(le)[0]??"";O(Qe);})(),()=>{l=false;}},[e]),react$1.useEffect(()=>e.on("user:anyUpdated",m),[e]);let E=react$1.useMemo(()=>Object.entries(y).filter(([,l])=>l.Networks?.some(C=>C.NetworkID===x&&!!C.ContractAddress)),[y,x]);react$1.useEffect(()=>{let l=E[0]?.[0]??"";M(C=>E.some(([F])=>F===C)?C:l);},[E]);let h=x?f[x]:void 0,v=(w?y[w]:void 0)?.Networks?.find(l=>l.NetworkID===x),V=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function _(){if(!h?.ChainID||d===h.ChainID)return true;try{return await c({chainId:h.ChainID}),!0}catch{return P({ok:false,stage:"approve",error:`Switch your wallet to chain ${h.ChainID} to continue.`}),false}}async function Ve(){if(!(!h||!v?.ContractAddress)){if(N(true),P(null),await _()){let l=v.Decimals??18,C;try{C=viem.parseUnits(L||"0",l);}catch{P({ok:false,stage:"approve",error:"Invalid amount."}),N(false);return}let F=await r.depositToken({network:h,tokenAddress:v.ContractAddress,amount:C});P(F),F.ok&&await e.blockchain.getUserState();}N(false);}}async function $e(){if(!(!h||!r.account)){if(N(true),P(null),await _()){let l=await r.withdrawToken({currencyID:w,networkID:x,walletAddress:r.account,amount:L||"0"});P(l),l.ok&&await e.blockchain.getUserState();}N(false);}}return jsxRuntime.jsxs("div",{style:{...Ot,...n},children:[jsxRuntime.jsxs("div",{style:{...Ee,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Mt,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:ie,onClick:t,children:"\u2715"})]}),o?jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsxs("span",{style:{...R,flex:1,alignSelf:"center"},children:[a?.slice(0,6),"\u2026",a?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>u(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:R,children:"Connect a browser or mobile wallet"}),s.map(l=>jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>i({connector:l}),children:l.name},l.uid))]}),Object.keys(f).length===0?jsxRuntime.jsx("span",{style:R,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Network"}),jsxRuntime.jsx("select",{style:ke,value:x,onChange:l=>O(l.target.value),children:Object.entries(f).map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Token"}),jsxRuntime.jsxs("select",{style:ke,value:w,onChange:l=>M(l.target.value),children:[E.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),E.map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))]})]}),jsxRuntime.jsxs("div",{style:R,children:["In-game balance: ",jsxRuntime.jsx("b",{children:V})," ",w]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Amount"}),jsxRuntime.jsx("input",{style:ke,inputMode:"decimal",placeholder:"0.0",value:L,onChange:l=>j(l.target.value)})]}),jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsx("button",{type:"button",style:{..._t,flex:1,opacity:S?.6:1},disabled:S||!o||!v?.ContractAddress,onClick:()=>{Ve();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...ie,flex:1,opacity:S?.6:1},disabled:S||!o||!w,onClick:()=>{$e();},children:"Withdraw"})]})]}),z&&jsxRuntime.jsx(Kt,{result:z})]})}function Kt({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=Pe;exports.IDosGamesWalletProvider=G;exports.WalletLogin=vt;exports.WalletLoginButton=ze;exports.WalletPanel=Gt;exports.arbitrum=X;exports.base=J;exports.bsc=Q;exports.chainById=Je;exports.createEvmWalletConfig=pe;exports.idosChains=xe;exports.mainnet=$;exports.optimism=ee;exports.polygon=Z;exports.polygonAmoy=ne;exports.sepolia=te;exports.useEvmBridge=Ce;exports.useEvmBridgeClients=oe;
1
+ 'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var $={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},Q={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"}}},J={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"}}},X={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"}}},ee={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"}}},te={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"}}},ne={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"}}},xe={mainnet:$,bsc:Q,polygon:Z,base:J,arbitrum:X,optimism:ee,sepolia:te,polygonAmoy:ne};function Je(e){return Object.values(xe).find(t=>t.id===e)}function De(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var Pe=null;function Te(e){Pe=e;}function ce(){return Pe}var We=[$,Q,Z,J,X,ee,te,ne],de=new Map;function pe(e){let{chains:t=We,walletConnectProjectId:n,appName:r,appUrl:a,appIcon:o,transports:d,connectors:i}=e,s=n??"__extension_only__";if(!i){let y=de.get(s);if(y)return y}let u={};for(let y of t)u[y.id]=d?.[y.id]??wagmi.http();let c=a??(typeof window<"u"?window.location.origin:""),m={name:r??"iDosGames",description:r??"iDosGames game",url:c,icons:o?[o]:[]};if(n&&!i){let y=t.map(De),N=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:u});return Te(react.createAppKit({adapters:[N],networks:y,projectId:n,metadata:m,features:{analytics:false,email:false,socials:false}})),de.set(s,N.wagmiConfig),N.wagmiConfig}let f=i??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})],b=wagmi.createConfig({chains:t,connectors:f,transports:u});return i||de.set(s,b),b}function G(e){let{wagmiConfig:t,queryClient:n,children:r}=e,[a]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:a,children:r})})}var re=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],ue=[{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"}]}],Se=[{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(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}async function B(e,t){let{walletClient:n,publicClient:r,account:a}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:a,chain:n.chain,value:t.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function D(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 A(e,t){return {ok:false,stage:e,error:t}}var Re="WALLET_USE_SITE_PANEL",ut=/^[a-z0-9]{8}-preview\.idos\.games$/;function mt(e=typeof window>"u"?"":window.location.hostname){let t=e.toLowerCase();return ut.test(t)?true:t!=="localhost"&&t!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function P(){if(typeof window>"u"||mt())return false;try{return window.self!==window.top}catch{return true}}function _(e){return p(e,Re)}function me(e){return A(e,Re)}function Le(e){let t=e.RewardPoolAddress;return t||null}async function Fe(e,t,n,r){return await e.publicClient.readContract({address:t,abi:ue,functionName:"allowance",args:[e.account,n]})>=r?null:B(e,{address:t,abi:ue,functionName:"approve",args:[n,r]})}async function fe(e){let{client:t,clients:n,network:r,tokenAddress:a,amount:o,titleID:d,category:i}=e;if(P())return _("approve");let s=t.auth.context?.userID;if(!s)return p("approve","Not logged in.");let u=Le(r);if(!u)return p("approve","Network has no RewardPoolAddress.");if(o<=0n)return p("approve","Amount must be positive.");try{await Fe(n,a,u,o);}catch(f){return p("approve",D(f))}let c;try{c=await B(n,{address:u,abi:re,functionName:"depositERC20",args:[a,o,s,d,i??""]});}catch(f){return p("deposit-onchain",D(f))}let m=await t.blockchain.depositToken(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:p("report",m.error,{onChainTxHash:c})}async function ge(e){let{client:t,clients:n,network:r,nftContractAddress:a,tokenId:o,amount:d,titleID:i,category:s}=e;if(P())return _("deposit-onchain");let u=t.auth.context?.userID;if(!u)return p("deposit-onchain","Not logged in.");let c=Le(r);if(!c)return p("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return p("deposit-onchain","Amount must be positive.");let m=Be(u,i,s),f;try{f=await B(n,{address:a,abi:Se,functionName:"safeTransferFrom",args:[n.account,c,o,d,m]});}catch(y){return p("deposit-onchain",D(y))}let b=await t.blockchain.depositNFT(r.NetworkID??"",f);return b.ok?{ok:true,onChainTxHash:f,data:b.data}:p("report",b.error,{onChainTxHash:f})}function _e(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function Oe(e,t){return B(e,{address:t.ContractAddress,abi:re,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),_e(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function He(e,t){return B(e,{address:t.ContractAddress,abi:Ne,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),_e(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function ye(e){let{client:t,clients:n,currencyID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(P())return _("request");let s=await t.blockchain.requestTokenWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await Oe(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await Me(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function we(e){let{client:t,clients:n,itemID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(P())return _("request");let s=await t.blockchain.requestNFTWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await He(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await Me(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function Me(e,t,n){if(!t)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await e.blockchain.confirmWithdrawal(t,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:p("confirm",r.error,{onChainTxHash:n,titleTransactionID:t})}async function U(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(a,r);if(!o.ok)return A("challenge",o.error);let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(s){return A("sign",D(s))}let i=await t.auth.loginWithWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}async function he(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.linkWallet(a,r);if(!o.ok)return A("challenge",o.error);if(!o.data.Challenge)return A("challenge","No challenge was issued.");let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(s){return A("sign",D(s))}let i=await t.auth.linkWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}function oe(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}var K="Wallet not connected.";function Ce(e,t){let n=oe();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,a)=>n?U({client:e,clients:n,networkID:r,walletAddress:a}):Promise.resolve(A("challenge",K)),depositToken:r=>n?fe({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("approve",K)),depositNft:r=>n?ge({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("deposit-onchain",K)),withdrawToken:r=>n?ye({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K)),withdrawNft:r=>n?we({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K))}}function be(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}function Et(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(G,{wagmiConfig:t,children:jsxRuntime.jsx(Ve,{...n})})}function At(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function xt(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 Ue(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 Dt(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,a=i=>{r||(r=true,o(),clearTimeout(d),n(i));},o=actions.watchAccount(e,{onChange:i=>{i.isConnected&&a(true);}}),d=setTimeout(()=>a(false),t);})}function Pt(e,t=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(e).status)?new Promise(r=>{let a=false,o=()=>{a||(a=true,d(),clearTimeout(i),r());},d=actions.watchAccount(e,{onChange:s=>{n(s.status)||o();}}),i=setTimeout(o,t);}):Promise.resolve()}function Tt(e){let t=a=>e.find(o=>o.id===a||o.type===a),n=t("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:t("walletConnect")??n??e[0]}var Ke=9e4;async function Wt(e){try{let r=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,a=r?.native||r?.universal;return !a||typeof window>"u"?!1:(window.location.href=a,!0)}catch{return false}}function qe(e,t){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),t);e.then(o=>{clearTimeout(a),n(o);},o=>{clearTimeout(a),r(o instanceof Error?o:new Error(String(o)));});})}function Ve(e){let{client:t,networkID:n,onAuthenticated:r,disabled:a,label:o,style:d,autoStart:i,mode:s="login",onLinked:u}=e,c=wagmi.useConfig(),{isConnected:m}=wagmi.useAccount(),{connectAsync:f,connectors:b}=wagmi.useConnect(),y=oe(),[N,x]=react$1.useState(false),[O,w]=react$1.useState(null),[H,L]=react$1.useState(false),j=react$1.useRef(0),S=react$1.useRef(false),T=async()=>{let W=++j.current,E=()=>j.current===W;x(true),w(null);try{if(await Pt(c),!E())return;if(!actions.getAccount(c).isConnected){let v=ce();if(v){if(await v.open(),!await Dt(c)){w("No wallet was connected.");return}}else {let Y=Tt(b);if(!Y){w("No wallet connector is configured.");return}try{await f({connector:Y});}catch(M){if(!At(M))throw M}}}let h=y??await Ue(c);if(!h&&actions.getAccount(c).isConnected&&(await new Promise(v=>setTimeout(v,300)),h=await Ue(c),!E()))return;if(!h){w("Wallet client is not available.");return}if(L(!0),s==="link"){let v=await qe(he({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(v.ok){u?.(v.data.PlayAccess??null);return}w(v.stage==="sign"?"Signature declined.":be(v.error,"Could not link the wallet."));return}let z=await qe(U({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(z.ok){r();return}w(z.stage==="sign"?"Signature declined.":be(z.error,"Wallet sign-in failed."));}catch(h){if(!E())return;console.error("[idosgames/wallet] wallet sign-in failed:",h),w(xt(h));}finally{E()&&(x(false),L(false));}};react$1.useEffect(()=>{!i||S.current||(S.current=true,T());},[i]);let V=async()=>{await Wt(c)||await ce()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{H?V():T();},disabled:a,style:{...It,...a?{opacity:.6,cursor:"default"}:null,...d},children:H?"Waiting for signature \u2014 tap to open wallet":N?"Check your wallet\u2026":m?o??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),O&&jsxRuntime.jsx("span",{role:"alert",style:Nt,children:O})]})}var It={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Nt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Mt={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"},Gt={fontWeight:700,fontSize:16},R={fontSize:12,opacity:.7},ke={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},Ut={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},ie={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Ee={display:"flex",gap:8};function Kt(e){let{client:t,walletConnectProjectId:n,appName:r,onClose:a,style:o}=e,[d,i]=react$1.useState(n??"");react$1.useEffect(()=>{if(n)return;let u=true;return (async()=>{let c=await t.blockchain.getDefinitions();if(!u||!c.ok)return;let m=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;m&&i(m);})(),()=>{u=false;}},[t,n]);let s=react$1.useMemo(()=>pe({walletConnectProjectId:d||void 0,appName:r}),[d,r]);return jsxRuntime.jsx(G,{wagmiConfig:s,children:jsxRuntime.jsx(qt,{client:t,appName:r,onClose:a,style:o})})}function qt({client:e,onClose:t,style:n}){let r=Ce(e,e.titleID),{address:a,isConnected:o,chainId:d}=wagmi.useAccount(),{connect:i,connectors:s}=wagmi.useConnect(),{disconnect:u}=wagmi.useDisconnect(),{switchChainAsync:c}=wagmi.useSwitchChain(),[,m]=react$1.useReducer(l=>l+1,0),[f,b]=react$1.useState({}),[y,N]=react$1.useState({}),[x,O]=react$1.useState(""),[w,H]=react$1.useState(""),[L,j]=react$1.useState(""),[S,T]=react$1.useState(false),[V,W]=react$1.useState(null);react$1.useEffect(()=>{let l=true;return (async()=>{let C=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!l||!C.ok)return;let F=C.data.Blockchain?.Networks??{},le={};for(let[Ze,Ae]of Object.entries(F))Ae.Type==="EVM"&&(le[Ze]=Ae);b(le),N(C.data.CryptoCurrencies??{});let Qe=Object.keys(le)[0]??"";O(Qe);})(),()=>{l=false;}},[e]),react$1.useEffect(()=>e.on("user:anyUpdated",m),[e]);let E=react$1.useMemo(()=>Object.entries(y).filter(([,l])=>l.Networks?.some(C=>C.NetworkID===x&&!!C.ContractAddress)),[y,x]);react$1.useEffect(()=>{let l=E[0]?.[0]??"";H(C=>E.some(([F])=>F===C)?C:l);},[E]);let h=x?f[x]:void 0,v=(w?y[w]:void 0)?.Networks?.find(l=>l.NetworkID===x),Y=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function M(){if(!h?.ChainID||d===h.ChainID)return true;try{return await c({chainId:h.ChainID}),!0}catch{return W({ok:false,stage:"approve",error:`Switch your wallet to chain ${h.ChainID} to continue.`}),false}}async function Ye(){if(!(!h||!v?.ContractAddress)){if(T(true),W(null),await M()){let l=v.Decimals??18,C;try{C=viem.parseUnits(L||"0",l);}catch{W({ok:false,stage:"approve",error:"Invalid amount."}),T(false);return}let F=await r.depositToken({network:h,tokenAddress:v.ContractAddress,amount:C});W(F),F.ok&&await e.blockchain.getUserState();}T(false);}}async function $e(){if(!(!h||!r.account)){if(T(true),W(null),await M()){let l=await r.withdrawToken({currencyID:w,networkID:x,walletAddress:r.account,amount:L||"0"});W(l),l.ok&&await e.blockchain.getUserState();}T(false);}}return jsxRuntime.jsxs("div",{style:{...Mt,...n},children:[jsxRuntime.jsxs("div",{style:{...Ee,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Gt,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:ie,onClick:t,children:"\u2715"})]}),o?jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsxs("span",{style:{...R,flex:1,alignSelf:"center"},children:[a?.slice(0,6),"\u2026",a?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>u(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:R,children:"Connect a browser or mobile wallet"}),s.map(l=>jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>i({connector:l}),children:l.name},l.uid))]}),Object.keys(f).length===0?jsxRuntime.jsx("span",{style:R,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Network"}),jsxRuntime.jsx("select",{style:ke,value:x,onChange:l=>O(l.target.value),children:Object.entries(f).map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Token"}),jsxRuntime.jsxs("select",{style:ke,value:w,onChange:l=>H(l.target.value),children:[E.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),E.map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))]})]}),jsxRuntime.jsxs("div",{style:R,children:["In-game balance: ",jsxRuntime.jsx("b",{children:Y})," ",w]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Amount"}),jsxRuntime.jsx("input",{style:ke,inputMode:"decimal",placeholder:"0.0",value:L,onChange:l=>j(l.target.value)})]}),jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsx("button",{type:"button",style:{...Ut,flex:1,opacity:S?.6:1},disabled:S||!o||!v?.ContractAddress,onClick:()=>{Ye();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...ie,flex:1,opacity:S?.6:1},disabled:S||!o||!w,onClick:()=>{$e();},children:"Withdraw"})]})]}),V&&jsxRuntime.jsx(jt,{result:V})]})}function jt({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=We;exports.IDosGamesWalletProvider=G;exports.WalletLogin=Et;exports.WalletLoginButton=Ve;exports.WalletPanel=Kt;exports.arbitrum=X;exports.base=J;exports.bsc=Q;exports.chainById=Je;exports.createEvmWalletConfig=pe;exports.idosChains=xe;exports.mainnet=$;exports.optimism=ee;exports.polygon=Z;exports.polygonAmoy=ne;exports.sepolia=te;exports.useEvmBridge=Ce;exports.useEvmBridgeClients=oe;
@@ -1 +1 @@
1
- import {p as p$1,o as o$1,j as j$2,h,q as q$2,r}from'../chunk-FFBRTCQK.js';import {a,b as b$1,c as c$1}from'../chunk-UMGI2JW7.js';import {j as j$1,k,l,m,n,o,p,q as q$1,t,b,c}from'../chunk-IEWZH6XD.js';export{n as arbitrum,m as base,k as bsc,s as chainById,r as idosChains,j as mainnet,o as optimism,l as polygon,q as polygonAmoy,p as sepolia}from'../chunk-IEWZH6XD.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 he=[j$1,k,l,m,n,o,p,q$1],ie=new Map;function se(e){let{chains:n=he,walletConnectProjectId:t$1,appName:o,appUrl:i,appIcon:s,transports:y,connectors:l}=e,w=t$1??"__extension_only__";if(!l){let f=ie.get(w);if(f)return f}let v={};for(let f of n)v[f.id]=y?.[f.id]??http();let p=i??(typeof window<"u"?window.location.origin:""),b={name:o??"iDosGames",description:o??"iDosGames game",url:p,icons:s?[s]:[]};if(t$1&&!l){let f=n.map(t),S=new WagmiAdapter({networks:f,projectId:t$1,transports:v});return a(createAppKit({adapters:[S],networks:f,projectId:t$1,metadata:b,features:{analytics:false,email:false,socials:false}})),ie.set(w,S.wagmiConfig),S.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:o??"iDosGames"})],I=createConfig({chains:n,connectors:D,transports:v});return l||ie.set(w,I),I}function G(e){let{wagmiConfig:n,queryClient:t,children:o}=e,[i]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:n,children:jsx(QueryClientProvider,{client:i,children:o})})}function q(){let{address:e}=useAccount(),n=usePublicClient(),{data:t}=useWalletClient();return !e||!n||!t?null:{account:e,publicClient:n,walletClient:t}}var j="Wallet not connected.";function ae(e,n){let t=q();return {connected:!!t,account:t?.account??null,loginWithWallet:(o,i)=>t?q$2({client:e,clients:t,networkID:o,walletAddress:i}):Promise.resolve(c("challenge",j)),depositToken:o=>t?h({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("approve",j)),depositNft:o=>t?j$2({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("deposit-onchain",j)),withdrawToken:o=>t?o$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j)),withdrawNft:o=>t?p$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j))}}function et(e){let{wagmiConfig:n,...t}=e;return jsx(G,{wagmiConfig:n,children:jsx(Ne,{...t})})}function tt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function nt(e){let n="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.":n:n}async function Pe(e){let n=await getWalletClient(e).catch(()=>null);if(!n)return null;let t=getPublicClient(e);return t?{account:n.account.address,publicClient:t,walletClient:n}:null}function ot(e,n=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let o=false,i=l=>{o||(o=true,s(),clearTimeout(y),t(l));},s=watchAccount(e,{onChange:l=>{l.isConnected&&i(true);}}),y=setTimeout(()=>i(false),n);})}function rt(e,n=8e3){let t=o=>o==="reconnecting"||o==="connecting";return t(getAccount(e).status)?new Promise(o=>{let i=false,s=()=>{i||(i=true,y(),clearTimeout(l),o());},y=watchAccount(e,{onChange:w=>{t(w.status)||s();}}),l=setTimeout(s,n);}):Promise.resolve()}function it(e){let n=i=>e.find(s=>s.id===i||s.type===i),t=n("injected"),o=typeof window<"u"&&window.ethereum!=null;return t&&o?t:n("walletConnect")??t??e[0]}var We=9e4;async function st(e){try{let o=(await 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 De(e,n){return new Promise((t,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),n);e.then(s=>{clearTimeout(i),t(s);},s=>{clearTimeout(i),o(s instanceof Error?s:new Error(String(s)));});})}function Ne(e){let{client:n,networkID:t,onAuthenticated:o,disabled:i,label:s,style:y,autoStart:l,mode:w="login",onLinked:v}=e,p=useConfig(),{isConnected:b}=useAccount(),{connectAsync:D,connectors:I}=useConnect(),f=q(),[S,h]=useState(false),[A,c]=useState(null),[R,T]=useState(false),F=useRef(0),N=useRef(false),k=async()=>{let P=++F.current,C=()=>F.current===P;h(true),c(null);try{if(await rt(p),!C())return;if(!getAccount(p).isConnected){let m=b$1();if(m){if(await m.open(),!await ot(p)){c("No wallet was connected.");return}}else {let M=it(I);if(!M){c("No wallet connector is configured.");return}try{await D({connector:M});}catch(B){if(!tt(B))throw B}}}let d=f??await Pe(p);if(!d&&getAccount(p).isConnected&&(await new Promise(m=>setTimeout(m,300)),d=await Pe(p),!C()))return;if(!d){c("Wallet client is not available.");return}if(T(!0),w==="link"){let m=await De(r({client:n,clients:d,networkID:t}),We);if(!C())return;if(m.ok){v?.(m.data.PlayAccess??null);return}c(m.stage==="sign"?"Signature declined.":c$1(m.error,"Could not link the wallet."));return}let U=await De(q$2({client:n,clients:d,networkID:t}),We);if(!C())return;if(U.ok){o();return}c(U.stage==="sign"?"Signature declined.":c$1(U.error,"Wallet sign-in failed."));}catch(d){if(!C())return;console.error("[idosgames/wallet] wallet sign-in failed:",d),c(nt(d));}finally{C()&&(h(false),T(false));}};useEffect(()=>{!l||N.current||(N.current=true,k());},[l]);let _=async()=>{await st(p)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{R?_():k();},disabled:i,style:{...at,...i?{opacity:.6,cursor:"default"}:null,...y},children:R?"Waiting for signature \u2014 tap to open wallet":S?"Check your wallet\u2026":b?s??(w==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),A&&jsx("span",{role:"alert",style:lt,children:A})]})}var at={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},lt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var wt={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"},Ct={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},ce={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},vt={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},H={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},de={display:"flex",gap:8};function ht(e){let{client:n,walletConnectProjectId:t,appName:o,onClose:i,style:s}=e,[y,l]=useState(t??"");useEffect(()=>{if(t)return;let v=true;return (async()=>{let p=await n.blockchain.getDefinitions();if(!v||!p.ok)return;let b=p.data.Blockchain?.WalletLogin?.WalletConnectProjectId;b&&l(b);})(),()=>{v=false;}},[n,t]);let w=useMemo(()=>se({walletConnectProjectId:y||void 0,appName:o}),[y,o]);return jsx(G,{wagmiConfig:w,children:jsx(bt,{client:n,appName:o,onClose:i,style:s})})}function bt({client:e,onClose:n,style:t}){let o=ae(e,e.titleID),{address:i,isConnected:s,chainId:y}=useAccount(),{connect:l,connectors:w}=useConnect(),{disconnect:v}=useDisconnect(),{switchChainAsync:p}=useSwitchChain(),[,b]=useReducer(r=>r+1,0),[D,I]=useState({}),[f,S]=useState({}),[h,A]=useState(""),[c,R]=useState(""),[T,F]=useState(""),[N,k]=useState(false),[_,P]=useState(null);useEffect(()=>{let r=true;return (async()=>{let u=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!r||!u.ok)return;let x=u.data.Blockchain?.Networks??{},V={};for(let[Ae,ue]of Object.entries(x))ue.Type==="EVM"&&(V[Ae]=ue);I(V),S(u.data.CryptoCurrencies??{});let xe=Object.keys(V)[0]??"";A(xe);})(),()=>{r=false;}},[e]),useEffect(()=>e.on("user:anyUpdated",b),[e]);let C=useMemo(()=>Object.entries(f).filter(([,r])=>r.Networks?.some(u=>u.NetworkID===h&&!!u.ContractAddress)),[f,h]);useEffect(()=>{let r=C[0]?.[0]??"";R(u=>C.some(([x])=>x===u)?u:r);},[C]);let d=h?D[h]:void 0,m=(c?f[c]:void 0)?.Networks?.find(r=>r.NetworkID===h),M=c?e.data.user.getCryptoCurrencyAmount(c):"0";async function B(){if(!d?.ChainID||y===d.ChainID)return true;try{return await p({chainId:d.ChainID}),!0}catch{return P({ok:false,stage:"approve",error:`Switch your wallet to chain ${d.ChainID} to continue.`}),false}}async function Ie(){if(!(!d||!m?.ContractAddress)){if(k(true),P(null),await B()){let r=m.Decimals??18,u;try{u=parseUnits(T||"0",r);}catch{P({ok:false,stage:"approve",error:"Invalid amount."}),k(false);return}let x=await o.depositToken({network:d,tokenAddress:m.ContractAddress,amount:u});P(x),x.ok&&await e.blockchain.getUserState();}k(false);}}async function Te(){if(!(!d||!o.account)){if(k(true),P(null),await B()){let r=await o.withdrawToken({currencyID:c,networkID:h,walletAddress:o.account,amount:T||"0"});P(r),r.ok&&await e.blockchain.getUserState();}k(false);}}return jsxs("div",{style:{...wt,...t},children:[jsxs("div",{style:{...de,justifyContent:"space-between"},children:[jsx("span",{style:Ct,children:"Crypto wallet"}),n&&jsx("button",{type:"button",style:H,onClick:n,children:"\u2715"})]}),s?jsxs("div",{style:de,children:[jsxs("span",{style:{...E,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsx("button",{type:"button",style:H,onClick:()=>v(),children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:E,children:"Connect a browser or mobile wallet"}),w.map(r=>jsx("button",{type:"button",style:H,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:ce,value:h,onChange:r=>A(r.target.value),children:Object.entries(D).map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))})]}),jsxs("div",{children:[jsx("div",{style:E,children:"Token"}),jsxs("select",{style:ce,value:c,onChange:r=>R(r.target.value),children:[C.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),C.map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))]})]}),jsxs("div",{style:E,children:["In-game balance: ",jsx("b",{children:M})," ",c]}),jsxs("div",{children:[jsx("div",{style:E,children:"Amount"}),jsx("input",{style:ce,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:de,children:[jsx("button",{type:"button",style:{...vt,flex:1,opacity:N?.6:1},disabled:N||!s||!m?.ContractAddress,onClick:()=>{Ie();},children:"Deposit"}),jsx("button",{type:"button",style:{...H,flex:1,opacity:N?.6:1},disabled:N||!s||!c,onClick:()=>{Te();},children:"Withdraw"})]})]}),_&&jsx(kt,{result:_})]})}function kt({result:e}){let n={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:n,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxs("div",{style:n,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{he as DEFAULT_EVM_CHAINS,G as IDosGamesWalletProvider,et as WalletLogin,Ne as WalletLoginButton,ht as WalletPanel,se as createEvmWalletConfig,ae as useEvmBridge,q as useEvmBridgeClients};
1
+ import {p as p$1,o as o$1,j as j$1,h,q as q$2,r as r$1}from'../chunk-YTTVLBAW.js';import {a,b as b$1,c as c$1}from'../chunk-UMGI2JW7.js';import {k,l,m,n,o,p,q as q$1,r,u,b,c}from'../chunk-K3THMWU2.js';export{o as arbitrum,n as base,l as bsc,t as chainById,s as idosChains,k as mainnet,p as optimism,m as polygon,r as polygonAmoy,q as sepolia}from'../chunk-K3THMWU2.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 he=[k,l,m,n,o,p,q$1,r],ie=new Map;function se(e){let{chains:n=he,walletConnectProjectId:t,appName:o,appUrl:i,appIcon:s,transports:y,connectors:l}=e,w=t??"__extension_only__";if(!l){let f=ie.get(w);if(f)return f}let v={};for(let f of n)v[f.id]=y?.[f.id]??http();let p=i??(typeof window<"u"?window.location.origin:""),b={name:o??"iDosGames",description:o??"iDosGames game",url:p,icons:s?[s]:[]};if(t&&!l){let f=n.map(u),S=new WagmiAdapter({networks:f,projectId:t,transports:v});return a(createAppKit({adapters:[S],networks:f,projectId:t,metadata:b,features:{analytics:false,email:false,socials:false}})),ie.set(w,S.wagmiConfig),S.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:o??"iDosGames"})],I=createConfig({chains:n,connectors:D,transports:v});return l||ie.set(w,I),I}function G(e){let{wagmiConfig:n,queryClient:t,children:o}=e,[i]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:n,children:jsx(QueryClientProvider,{client:i,children:o})})}function q(){let{address:e}=useAccount(),n=usePublicClient(),{data:t}=useWalletClient();return !e||!n||!t?null:{account:e,publicClient:n,walletClient:t}}var j="Wallet not connected.";function ae(e,n){let t=q();return {connected:!!t,account:t?.account??null,loginWithWallet:(o,i)=>t?q$2({client:e,clients:t,networkID:o,walletAddress:i}):Promise.resolve(c("challenge",j)),depositToken:o=>t?h({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("approve",j)),depositNft:o=>t?j$1({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("deposit-onchain",j)),withdrawToken:o=>t?o$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j)),withdrawNft:o=>t?p$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j))}}function et(e){let{wagmiConfig:n,...t}=e;return jsx(G,{wagmiConfig:n,children:jsx(Ne,{...t})})}function tt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function nt(e){let n="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.":n:n}async function Pe(e){let n=await getWalletClient(e).catch(()=>null);if(!n)return null;let t=getPublicClient(e);return t?{account:n.account.address,publicClient:t,walletClient:n}:null}function ot(e,n=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let o=false,i=l=>{o||(o=true,s(),clearTimeout(y),t(l));},s=watchAccount(e,{onChange:l=>{l.isConnected&&i(true);}}),y=setTimeout(()=>i(false),n);})}function rt(e,n=8e3){let t=o=>o==="reconnecting"||o==="connecting";return t(getAccount(e).status)?new Promise(o=>{let i=false,s=()=>{i||(i=true,y(),clearTimeout(l),o());},y=watchAccount(e,{onChange:w=>{t(w.status)||s();}}),l=setTimeout(s,n);}):Promise.resolve()}function it(e){let n=i=>e.find(s=>s.id===i||s.type===i),t=n("injected"),o=typeof window<"u"&&window.ethereum!=null;return t&&o?t:n("walletConnect")??t??e[0]}var We=9e4;async function st(e){try{let o=(await 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 De(e,n){return new Promise((t,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),n);e.then(s=>{clearTimeout(i),t(s);},s=>{clearTimeout(i),o(s instanceof Error?s:new Error(String(s)));});})}function Ne(e){let{client:n,networkID:t,onAuthenticated:o,disabled:i,label:s,style:y,autoStart:l,mode:w="login",onLinked:v}=e,p=useConfig(),{isConnected:b}=useAccount(),{connectAsync:D,connectors:I}=useConnect(),f=q(),[S,h]=useState(false),[A,c]=useState(null),[R,T]=useState(false),F=useRef(0),N=useRef(false),k=async()=>{let P=++F.current,C=()=>F.current===P;h(true),c(null);try{if(await rt(p),!C())return;if(!getAccount(p).isConnected){let m=b$1();if(m){if(await m.open(),!await ot(p)){c("No wallet was connected.");return}}else {let M=it(I);if(!M){c("No wallet connector is configured.");return}try{await D({connector:M});}catch(B){if(!tt(B))throw B}}}let d=f??await Pe(p);if(!d&&getAccount(p).isConnected&&(await new Promise(m=>setTimeout(m,300)),d=await Pe(p),!C()))return;if(!d){c("Wallet client is not available.");return}if(T(!0),w==="link"){let m=await De(r$1({client:n,clients:d,networkID:t}),We);if(!C())return;if(m.ok){v?.(m.data.PlayAccess??null);return}c(m.stage==="sign"?"Signature declined.":c$1(m.error,"Could not link the wallet."));return}let U=await De(q$2({client:n,clients:d,networkID:t}),We);if(!C())return;if(U.ok){o();return}c(U.stage==="sign"?"Signature declined.":c$1(U.error,"Wallet sign-in failed."));}catch(d){if(!C())return;console.error("[idosgames/wallet] wallet sign-in failed:",d),c(nt(d));}finally{C()&&(h(false),T(false));}};useEffect(()=>{!l||N.current||(N.current=true,k());},[l]);let _=async()=>{await st(p)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{R?_():k();},disabled:i,style:{...at,...i?{opacity:.6,cursor:"default"}:null,...y},children:R?"Waiting for signature \u2014 tap to open wallet":S?"Check your wallet\u2026":b?s??(w==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),A&&jsx("span",{role:"alert",style:lt,children:A})]})}var at={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},lt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var wt={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"},Ct={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},ce={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},vt={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},H={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},de={display:"flex",gap:8};function ht(e){let{client:n,walletConnectProjectId:t,appName:o,onClose:i,style:s}=e,[y,l]=useState(t??"");useEffect(()=>{if(t)return;let v=true;return (async()=>{let p=await n.blockchain.getDefinitions();if(!v||!p.ok)return;let b=p.data.Blockchain?.WalletLogin?.WalletConnectProjectId;b&&l(b);})(),()=>{v=false;}},[n,t]);let w=useMemo(()=>se({walletConnectProjectId:y||void 0,appName:o}),[y,o]);return jsx(G,{wagmiConfig:w,children:jsx(bt,{client:n,appName:o,onClose:i,style:s})})}function bt({client:e,onClose:n,style:t}){let o=ae(e,e.titleID),{address:i,isConnected:s,chainId:y}=useAccount(),{connect:l,connectors:w}=useConnect(),{disconnect:v}=useDisconnect(),{switchChainAsync:p}=useSwitchChain(),[,b]=useReducer(r=>r+1,0),[D,I]=useState({}),[f,S]=useState({}),[h,A]=useState(""),[c,R]=useState(""),[T,F]=useState(""),[N,k]=useState(false),[_,P]=useState(null);useEffect(()=>{let r=true;return (async()=>{let u=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!r||!u.ok)return;let x=u.data.Blockchain?.Networks??{},V={};for(let[Ae,ue]of Object.entries(x))ue.Type==="EVM"&&(V[Ae]=ue);I(V),S(u.data.CryptoCurrencies??{});let xe=Object.keys(V)[0]??"";A(xe);})(),()=>{r=false;}},[e]),useEffect(()=>e.on("user:anyUpdated",b),[e]);let C=useMemo(()=>Object.entries(f).filter(([,r])=>r.Networks?.some(u=>u.NetworkID===h&&!!u.ContractAddress)),[f,h]);useEffect(()=>{let r=C[0]?.[0]??"";R(u=>C.some(([x])=>x===u)?u:r);},[C]);let d=h?D[h]:void 0,m=(c?f[c]:void 0)?.Networks?.find(r=>r.NetworkID===h),M=c?e.data.user.getCryptoCurrencyAmount(c):"0";async function B(){if(!d?.ChainID||y===d.ChainID)return true;try{return await p({chainId:d.ChainID}),!0}catch{return P({ok:false,stage:"approve",error:`Switch your wallet to chain ${d.ChainID} to continue.`}),false}}async function Ie(){if(!(!d||!m?.ContractAddress)){if(k(true),P(null),await B()){let r=m.Decimals??18,u;try{u=parseUnits(T||"0",r);}catch{P({ok:false,stage:"approve",error:"Invalid amount."}),k(false);return}let x=await o.depositToken({network:d,tokenAddress:m.ContractAddress,amount:u});P(x),x.ok&&await e.blockchain.getUserState();}k(false);}}async function Te(){if(!(!d||!o.account)){if(k(true),P(null),await B()){let r=await o.withdrawToken({currencyID:c,networkID:h,walletAddress:o.account,amount:T||"0"});P(r),r.ok&&await e.blockchain.getUserState();}k(false);}}return jsxs("div",{style:{...wt,...t},children:[jsxs("div",{style:{...de,justifyContent:"space-between"},children:[jsx("span",{style:Ct,children:"Crypto wallet"}),n&&jsx("button",{type:"button",style:H,onClick:n,children:"\u2715"})]}),s?jsxs("div",{style:de,children:[jsxs("span",{style:{...E,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsx("button",{type:"button",style:H,onClick:()=>v(),children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:E,children:"Connect a browser or mobile wallet"}),w.map(r=>jsx("button",{type:"button",style:H,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:ce,value:h,onChange:r=>A(r.target.value),children:Object.entries(D).map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))})]}),jsxs("div",{children:[jsx("div",{style:E,children:"Token"}),jsxs("select",{style:ce,value:c,onChange:r=>R(r.target.value),children:[C.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),C.map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))]})]}),jsxs("div",{style:E,children:["In-game balance: ",jsx("b",{children:M})," ",c]}),jsxs("div",{children:[jsx("div",{style:E,children:"Amount"}),jsx("input",{style:ce,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:de,children:[jsx("button",{type:"button",style:{...vt,flex:1,opacity:N?.6:1},disabled:N||!s||!m?.ContractAddress,onClick:()=>{Ie();},children:"Deposit"}),jsx("button",{type:"button",style:{...H,flex:1,opacity:N?.6:1},disabled:N||!s||!c,onClick:()=>{Te();},children:"Withdraw"})]})]}),_&&jsx(kt,{result:_})]})}function kt({result:e}){let n={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:n,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxs("div",{style:n,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{he as DEFAULT_EVM_CHAINS,G as IDosGamesWalletProvider,et as WalletLogin,Ne as WalletLoginButton,ht as WalletPanel,se as createEvmWalletConfig,ae as useEvmBridge,q as useEvmBridgeClients};
@@ -1,2 +1,2 @@
1
- 'use strict';var viem=require('viem'),core=require('@idosgames/core'),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'),actions=require('wagmi/actions'),appkitAdapterSolana=require('@reown/appkit-adapter-solana');var mn=Object.defineProperty;var k=(e,t)=>()=>(e&&(t=e(e=0)),t);var st=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:true});};function E(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function m(e,t,n){return {ok:false,stage:e,error:t,...n}}function w(e,t){return {ok:false,stage:e,error:t}}var M=k(()=>{});function P(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function ct(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function H(e){return m(e,lt)}function Z(e){return w(e,lt)}var lt,j=k(()=>{M();lt="WALLET_USE_SITE_PANEL";});function De(e){return Object.values(exports.idosChains).find(t=>t.id===e)}function ft(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 ie=k(()=>{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 Ce(e){yt=e;}function se(){return yt}var yt,me=k(()=>{yt=null;});function be(e){let{chains:t=Re,walletConnectProjectId:n,appName:o,appUrl:r,appIcon:a,transports:c,connectors:s}=e,i=n??"__extension_only__";if(!s){let y=Le.get(i);if(y)return y}let d={};for(let y of t)d[y.id]=c?.[y.id]??wagmi.http();let l=r??(typeof window<"u"?window.location.origin:""),u={name:o??"iDosGames",description:o??"iDosGames game",url:l,icons:a?[a]:[]};if(n&&!s){let y=t.map(ft),C=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:d});return Ce(react$1.createAppKit({adapters:[C],networks:y,projectId:n,metadata:u,features:{analytics:false,email:false,socials:false}})),Le.set(i,C.wagmiConfig),C.wagmiConfig}let p=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],h=wagmi.createConfig({chains:t,connectors:p,transports:d});return s||Le.set(i,h),h}var Re,Le,Be=k(()=>{ie();me();Re=[exports.mainnet,exports.bsc,exports.polygon,exports.base,exports.arbitrum,exports.optimism,exports.sepolia,exports.polygonAmoy],Le=new Map;});function le(e){let{wagmiConfig:t,queryClient:n,children:o}=e,[r]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:r,children:o})})}var ve=k(()=>{});var Ae,ht,Me,kt,Fe=k(()=>{Ae=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],ht=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],Me=[{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"}]}],kt=[{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 Ct(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}var bt=k(()=>{});async function V(e,t){let{walletClient:n,publicClient:o,account:r}=e,a=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:a})).status==="reverted")throw new Error(`On-chain transaction reverted (${a}).`);return a}var _e=k(()=>{});function vt(e){let t=e.RewardPoolAddress;return t||null}async function At(e,t,n,o){return await e.publicClient.readContract({address:t,abi:Me,functionName:"allowance",args:[e.account,n]})>=o?null:V(e,{address:t,abi:Me,functionName:"approve",args:[n,o]})}async function Oe(e){let{client:t,clients:n,network:o,tokenAddress:r,amount:a,titleID:c,category:s}=e;if(P())return H("approve");let i=t.auth.context?.userID;if(!i)return m("approve","Not logged in.");let d=vt(o);if(!d)return m("approve","Network has no RewardPoolAddress.");if(a<=0n)return m("approve","Amount must be positive.");try{await At(n,r,d,a);}catch(p){return m("approve",E(p))}let l;try{l=await V(n,{address:d,abi:Ae,functionName:"depositERC20",args:[r,a,i,c,s??""]});}catch(p){return m("deposit-onchain",E(p))}let u=await t.blockchain.depositToken(o.NetworkID??"",l);return u.ok?{ok:true,onChainTxHash:l,data:u.data}:m("report",u.error,{onChainTxHash:l})}async function Ge(e){let{client:t,clients:n,network:o,nftContractAddress:r,tokenId:a,amount:c,titleID:s,category:i}=e;if(P())return H("deposit-onchain");let d=t.auth.context?.userID;if(!d)return m("deposit-onchain","Not logged in.");let l=vt(o);if(!l)return m("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return m("deposit-onchain","Amount must be positive.");let u=Ct(d,s,i),p;try{p=await V(n,{address:r,abi:kt,functionName:"safeTransferFrom",args:[n.account,l,a,c,u]});}catch(y){return m("deposit-onchain",E(y))}let h=await t.blockchain.depositNFT(o.NetworkID??"",p);return h.ok?{ok:true,onChainTxHash:p,data:h.data}:m("report",h.error,{onChainTxHash:p})}var Wt=k(()=>{Fe();bt();_e();M();j();});function Pt(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function St(e,t){return V(e,{address:t.ContractAddress,abi:Ae,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),Pt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Et(e,t){return V(e,{address:t.ContractAddress,abi:ht,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),Pt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function He(e){let{client:t,clients:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestTokenWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let u;try{u=await St(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let p=await Tt(t,l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:p}async function Ue(e){let{client:t,clients:n,itemID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestNFTWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let u;try{u=await Et(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let p=await Tt(t,l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:p}async function Tt(e,t,n){if(!t)return m("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await e.blockchain.confirmWithdrawal(t,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:m("confirm",o.error,{onChainTxHash:n,titleTransactionID:t})}var xt=k(()=>{Fe();_e();M();j();});async function ge(e){let{client:t,clients:n,networkID:o}=e;if(P())return Z("challenge");let r=e.walletAddress??n.account,a=await t.auth.requestWalletChallenge(r,o);if(!a.ok)return w("challenge",a.error);let c;try{c=await n.walletClient.signMessage({account:n.account,message:a.data.Message});}catch(i){return w("sign",E(i))}let s=await t.auth.loginWithWallet(r,o,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}async function Ke(e){let{client:t,clients:n,networkID:o}=e;if(P())return Z("challenge");let r=e.walletAddress??n.account,a=await t.auth.linkWallet(r,o);if(!a.ok)return w("challenge",a.error);if(!a.data.Challenge)return w("challenge","No challenge was issued.");let c;try{c=await n.walletClient.signMessage({account:n.account,message:a.data.Challenge});}catch(i){return w("sign",E(i))}let s=await t.auth.linkWallet(r,o,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}var It=k(()=>{M();j();});var qe=k(()=>{Wt();xt();It();});function ye(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}function We(e,t){let n=ye();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,r)=>n?ge({client:e,clients:n,networkID:o,walletAddress:r}):Promise.resolve(w("challenge",fe)),depositToken:o=>n?Oe({client:e,clients:n,titleID:t,...o}):Promise.resolve(m("approve",fe)),depositNft:o=>n?Ge({client:e,clients:n,titleID:t,...o}):Promise.resolve(m("deposit-onchain",fe)),withdrawToken:o=>n?He({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",fe)),withdrawNft:o=>n?Ue({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",fe))}}var fe,Pe=k(()=>{qe();M();fe="Wallet not connected.";});function ce(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}var ze=k(()=>{});function Mt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(le,{wagmiConfig:t,children:jsxRuntime.jsx(Ve,{...n})})}function Hn(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Un(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 Nt(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 Kn(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,r=s=>{o||(o=true,a(),clearTimeout(c),n(s));},a=actions.watchAccount(e,{onChange:s=>{s.isConnected&&r(true);}}),c=setTimeout(()=>r(false),t);})}function qn(e,t=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(e).status)?new Promise(o=>{let r=false,a=()=>{r||(r=true,c(),clearTimeout(s),o());},c=actions.watchAccount(e,{onChange:i=>{n(i.status)||a();}}),s=setTimeout(a,t);}):Promise.resolve()}function zn(e){let t=r=>e.find(a=>a.id===r||a.type===r),n=t("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:t("walletConnect")??n??e[0]}async function jn(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 Rt(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(a=>{clearTimeout(r),n(a);},a=>{clearTimeout(r),o(a instanceof Error?a:new Error(String(a)));});})}function Ve(e){let{client:t,networkID:n,onAuthenticated:o,disabled:r,label:a,style:c,autoStart:s,mode:i="login",onLinked:d}=e,l=wagmi.useConfig(),{isConnected:u}=wagmi.useAccount(),{connectAsync:p,connectors:h}=wagmi.useConnect(),y=ye(),[C,f]=react.useState(false),[R,b]=react.useState(null),[U,_]=react.useState(false),O=react.useRef(0),B=react.useRef(false),T=async()=>{let D=++O.current,x=()=>O.current===D;f(true),b(null);try{if(await qn(l),!x())return;if(!actions.getAccount(l).isConnected){let W=se();if(W){if(await W.open(),!await Kn(l)){b("No wallet was connected.");return}}else {let q=zn(h);if(!q){b("No wallet connector is configured.");return}try{await p({connector:q});}catch(N){if(!Hn(N))throw N}}}let A=y??await Nt(l);if(!A&&actions.getAccount(l).isConnected&&(await new Promise(W=>setTimeout(W,300)),A=await Nt(l),!x()))return;if(!A){b("Wallet client is not available.");return}if(_(!0),i==="link"){let W=await Rt(Ke({client:t,clients:A,networkID:n}),Lt);if(!x())return;if(W.ok){d?.(W.data.PlayAccess??null);return}b(W.stage==="sign"?"Signature declined.":ce(W.error,"Could not link the wallet."));return}let G=await Rt(ge({client:t,clients:A,networkID:n}),Lt);if(!x())return;if(G.ok){o();return}b(G.stage==="sign"?"Signature declined.":ce(G.error,"Wallet sign-in failed."));}catch(A){if(!x())return;console.error("[idosgames/wallet] wallet sign-in failed:",A),b(Un(A));}finally{x()&&(f(false),_(false));}};react.useEffect(()=>{!s||B.current||(B.current=true,T());},[s]);let K=async()=>{await jn(l)||await se()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{U?K():T();},disabled:r,style:{...Vn,...r?{opacity:.6,cursor:"default"}:null,...c},children:U?"Waiting for signature \u2014 tap to open wallet":C?"Check your wallet\u2026":u?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),R&&jsxRuntime.jsx("span",{role:"alert",style:Yn,children:R})]})}var Lt,Vn,Yn,Ft=k(()=>{me();ze();qe();ve();Pe();Lt=9e4;Vn={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 Ot(e){let{client:t,walletConnectProjectId:n,appName:o,onClose:r,style:a}=e,[c,s]=react.useState(n??"");react.useEffect(()=>{if(n)return;let d=true;return (async()=>{let l=await t.blockchain.getDefinitions();if(!d||!l.ok)return;let u=l.data.Blockchain?.WalletLogin?.WalletConnectProjectId;u&&s(u);})(),()=>{d=false;}},[t,n]);let i=react.useMemo(()=>be({walletConnectProjectId:c||void 0,appName:o}),[c,o]);return jsxRuntime.jsx(le,{wagmiConfig:i,children:jsxRuntime.jsx(io,{client:t,appName:o,onClose:r,style:a})})}function io({client:e,onClose:t,style:n}){let o=We(e,e.titleID),{address:r,isConnected:a,chainId:c}=wagmi.useAccount(),{connect:s,connectors:i}=wagmi.useConnect(),{disconnect:d}=wagmi.useDisconnect(),{switchChainAsync:l}=wagmi.useSwitchChain(),[,u]=react.useReducer(g=>g+1,0),[p,h]=react.useState({}),[y,C]=react.useState({}),[f,R]=react.useState(""),[b,U]=react.useState(""),[_,O]=react.useState(""),[B,T]=react.useState(false),[K,D]=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??{},Ie={};for(let[pn,it]of Object.entries(Q))it.Type==="EVM"&&(Ie[pn]=it);h(Ie),C(S.data.CryptoCurrencies??{});let un=Object.keys(Ie)[0]??"";R(un);})(),()=>{g=false;}},[e]),react.useEffect(()=>e.on("user:anyUpdated",u),[e]);let x=react.useMemo(()=>Object.entries(y).filter(([,g])=>g.Networks?.some(S=>S.NetworkID===f&&!!S.ContractAddress)),[y,f]);react.useEffect(()=>{let g=x[0]?.[0]??"";U(S=>x.some(([Q])=>Q===S)?S:g);},[x]);let A=f?p[f]:void 0,W=(b?y[b]:void 0)?.Networks?.find(g=>g.NetworkID===f),q=b?e.data.user.getCryptoCurrencyAmount(b):"0";async function N(){if(!A?.ChainID||c===A.ChainID)return true;try{return await l({chainId:A.ChainID}),!0}catch{return D({ok:false,stage:"approve",error:`Switch your wallet to chain ${A.ChainID} to continue.`}),false}}async function $(){if(!(!A||!W?.ContractAddress)){if(T(true),D(null),await N()){let g=W.Decimals??18,S;try{S=viem.parseUnits(_||"0",g);}catch{D({ok:false,stage:"approve",error:"Invalid amount."}),T(false);return}let Q=await o.depositToken({network:A,tokenAddress:W.ContractAddress,amount:S});D(Q),Q.ok&&await e.blockchain.getUserState();}T(false);}}async function dn(){if(!(!A||!o.account)){if(T(true),D(null),await N()){let g=await o.withdrawToken({currencyID:b,networkID:f,walletAddress:o.account,amount:_||"0"});D(g),g.ok&&await e.blockchain.getUserState();}T(false);}}return jsxRuntime.jsxs("div",{style:{...oo,...n},children:[jsxRuntime.jsxs("div",{style:{...$e,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:ro,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:t,children:"\u2715"})]}),a?jsxRuntime.jsxs("div",{style:$e,children:[jsxRuntime.jsxs("span",{style:{...Y,flex:1,alignSelf:"center"},children:[r?.slice(0,6),"\u2026",r?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:()=>d(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:Y,children:"Connect a browser or mobile wallet"}),i.map(g=>jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:()=>s({connector:g}),children:g.name},g.uid))]}),Object.keys(p).length===0?jsxRuntime.jsx("span",{style:Y,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Network"}),jsxRuntime.jsx("select",{style:Ye,value:f,onChange:g=>R(g.target.value),children:Object.entries(p).map(([g,S])=>jsxRuntime.jsx("option",{value:g,children:S.DisplayName??g},g))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Token"}),jsxRuntime.jsxs("select",{style:Ye,value:b,onChange:g=>U(g.target.value),children:[x.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),x.map(([g,S])=>jsxRuntime.jsx("option",{value:g,children:S.DisplayName??g},g))]})]}),jsxRuntime.jsxs("div",{style:Y,children:["In-game balance: ",jsxRuntime.jsx("b",{children:q})," ",b]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Amount"}),jsxRuntime.jsx("input",{style:Ye,inputMode:"decimal",placeholder:"0.0",value:_,onChange:g=>O(g.target.value)})]}),jsxRuntime.jsxs("div",{style:$e,children:[jsxRuntime.jsx("button",{type:"button",style:{...ao,flex:1,opacity:B?.6:1},disabled:B||!a||!W?.ContractAddress,onClick:()=>{$();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...Ee,flex:1,opacity:B?.6:1},disabled:B||!a||!b,onClick:()=>{dn();},children:"Withdraw"})]})]}),K&&jsxRuntime.jsx(so,{result:K})]})}function so({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 oo,ro,Y,Ye,ao,Ee,$e,Gt=k(()=>{Be();ve();Pe();oo={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"},ro={fontWeight:700,fontSize:16},Y={fontSize:12,opacity:.7},Ye={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},ao={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},Ee={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},$e={display:"flex",gap:8};});var Qe={};st(Qe,{DEFAULT_EVM_CHAINS:()=>Re,IDosGamesWalletProvider:()=>le,WalletLogin:()=>Mt,WalletLoginButton:()=>Ve,WalletPanel:()=>Ot,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>De,createEvmWalletConfig:()=>be,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>We,useEvmBridgeClients:()=>ye});var Ze=k(()=>{Be();ie();ve();Pe();Ft();Gt();});function Ht(e){let{walletConnectProjectId:t,appName:n,appUrl:o,appIcon:r,wallets:a}=e,c=e.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),i={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:r?[r]:[]},d=new appkitAdapterSolana.SolanaAdapter(a?{wallets:a}:{});return Ce(react$1.createAppKit({adapters:[d],networks:c,projectId:t,metadata:i,features:{analytics:false,email:false,socials:false}})),d}var Ut=k(()=>{ie();me();});async function Je(e){let{client:t,adapter:n,network:o,mint:r,amountRaw:a,titleID:c,category:s}=e;if(P())return H("deposit-onchain");let i=t.auth.context?.userID;if(!i)return m("deposit-onchain","Not logged in.");if(a<=0n)return m("deposit-onchain","Amount must be positive.");let d;try{d=await n.depositSpl({mint:r,amountRaw:a,userID:i,titleID:c,category:core.normalizeBlockchainCategory(s)});}catch(u){return m("deposit-onchain",E(u))}let l=await t.blockchain.depositToken(o.NetworkID??"",d);return l.ok?{ok:true,onChainTxHash:d,data:l.data}:m("report",l.error,{onChainTxHash:d})}async function Xe(e){let{client:t,adapter:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestTokenWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.SolanaSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let u;try{u=await n.submitWithdrawal(d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}if(!l)return m("confirm","Missing TitleTransactionID.",{onChainTxHash:u});let p=await t.blockchain.confirmWithdrawal(l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:m("confirm",p.error,{onChainTxHash:u,titleTransactionID:l})}var Kt=k(()=>{M();j();});async function he(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(P())return Z("challenge");let a=await t.auth.requestWalletChallenge(o,n);if(!a.ok)return w("challenge",a.error);let c;try{let i=await r(new TextEncoder().encode(a.data.Message));c=qt(i);}catch(i){return w("sign",E(i))}let s=await t.auth.loginWithWallet(o,n,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}async function et(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(P())return Z("challenge");let a=await t.auth.linkWallet(o,n);if(!a.ok)return w("challenge",a.error);if(!a.data.Challenge)return w("challenge","No challenge was issued.");let c;try{let i=await r(new TextEncoder().encode(a.data.Challenge));c=qt(i);}catch(i){return w("sign",E(i))}let s=await t.auth.linkWallet(o,n,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}function qt(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}var zt=k(()=>{M();j();});var tt=k(()=>{Kt();zt();});function Vt(e,t,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:r}=react$1.useAppKitProvider("solana"),a=o??null,c=r?.signMessage?.bind(r);return {connected:!!a,account:a,loginWithWallet:(s,i)=>{let d=i??a;return d?c?he({client:e,networkID:s,walletAddress:d,signMessage:c}):Promise.resolve(w("sign","The connected wallet does not support message signing.")):Promise.resolve(w("challenge",jt))},depositToken:s=>Je({client:e,adapter:n,titleID:t,...s}),withdrawToken:s=>{let i=s.walletAddress??a;return i?Xe({client:e,adapter:n,...s,walletAddress:i}):Promise.resolve(m("request",jt))}}}var jt,Yt=k(()=>{tt();M();jt="Wallet not connected.";});function ho(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 Qt(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(a=>{clearTimeout(r),n(a);},a=>{clearTimeout(r),o(a instanceof Error?a:new Error(String(a)));});})}function ko(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 Jt(e){let{client:t,networkID:n,onAuthenticated:o,disabled:r,label:a,style:c,autoStart:s,mode:i="login",onLinked:d}=e,{address:l,isConnected:u}=react$1.useAppKitAccount(),{walletProvider:p}=react$1.useAppKitProvider("solana"),[h,y]=react.useState(false),[C,f]=react.useState(null),[R,b]=react.useState(false),[U,_]=react.useState(false),O=react.useRef(null),B=react.useRef(0),T=react.useCallback(()=>{O.current&&clearTimeout(O.current),O.current=null;},[]);react.useEffect(()=>T,[T]);let K=react.useRef(false),D=react.useCallback(async()=>{let G=++B.current,W=()=>B.current===G,q=p?.signMessage?.bind(p);if(!l||!q){f("The connected wallet cannot sign messages."),y(false);return}y(true),f(null);try{if(_(!0),i==="link"){let $=await Qt(et({client:t,networkID:n,walletAddress:l,signMessage:q}),$t);if(!W())return;if($.ok){d?.($.data.PlayAccess??null);return}f($.stage==="sign"?"Signature declined.":ce($.error,"Could not link the wallet."));return}let N=await Qt(he({client:t,networkID:n,walletAddress:l,signMessage:q}),$t);if(!W())return;if(N.ok){o();return}f(N.stage==="sign"?"Signature declined.":ce(N.error,"Wallet sign-in failed."));}catch(N){if(!W())return;console.error("[idosgames/wallet] solana sign-in failed:",N),f(ko(N));}finally{W()&&(y(false),_(false));}},[l,p,t,n,o,i,d]),x=react.useCallback(()=>{ho(p)||se()?.open();},[p]);react.useEffect(()=>{!R||!u||!l||!p||(b(false),T(),D());},[R,u,l,p,D,T]);let A=()=>{if(U){x();return}if(f(null),K.current=true,u&&l&&p){D();return}let G=se();if(!G){f("Wallet sign-in is not configured for this title.");return}y(true),b(true),T(),O.current=setTimeout(()=>{b(false),y(false),f("No wallet was connected.");},wo),G.open();};return react.useEffect(()=>{!s||K.current||(K.current=true,A());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:A,disabled:r,style:{...Co,...r?{opacity:.6,cursor:"default"}:null,...c},children:U?"Waiting for signature \u2014 tap to open wallet":h?"Check your wallet\u2026":u?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:bo,children:C})]})}var wo,$t,Co,bo,Xt=k(()=>{ze();tt();me();wo=18e4,$t=9e4;Co={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},bo={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var en={};st(en,{SolanaWalletLogin:()=>Jt,createSolanaWalletConfig:()=>Ht,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>Vt});var tn=k(()=>{Ut();Yt();Xt();ie();});j();M();var de={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},ue="PLATFORM_WALLET_UNAVAILABLE",yn=5e3,wn=18e4;function hn(){let e=[...core.PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!e.includes(t)&&core.isPlatformParentOrigin(t)&&e.push(t),e}function kn(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function dt(e,t,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:ue});let o=window.parent;if(!o)return Promise.resolve({ok:false,error:ue});let r=kn();return new Promise(a=>{let c=false,s,i=l=>{c||(c=true,window.removeEventListener("message",d),clearTimeout(s),a(l));},d=l=>{if(!core.isPlatformParentOrigin(l.origin))return;let u=l.data;if(!(!u||u.requestId!==r)){if(u.type===de.ack){clearTimeout(s),s=setTimeout(()=>i({ok:false,error:"TIMEOUT"}),wn);return}u.type===t&&i({ok:u.ok===true,error:typeof u.error=="string"?u.error:void 0,address:typeof u.address=="string"?u.address:void 0,signature:typeof u.signature=="string"?u.signature:void 0});}};s=setTimeout(()=>i({ok:false,error:ue}),yn),window.addEventListener("message",d);for(let l of hn())try{o.postMessage({type:e,requestId:r,...n},l);}catch{}})}async function pt(e){let{client:t,networkID:n}=e;return gt(e,async o=>{let r=await t.auth.requestWalletChallenge(o,n);return r.ok?{ok:true,message:r.data.Message}:{ok:false,error:r.error}},(o,r)=>t.auth.loginWithWallet(o,n,r))}async function mt(e){let{client:t,networkID:n}=e;return gt(e,async o=>{let r=await t.auth.linkWallet(o,n);return r.ok?r.data.Challenge?{ok:true,message:r.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:r.error}},(o,r)=>t.auth.linkWallet(o,n,r))}async function gt(e,t,n){let{client:o,family:r}=e,a=o.titleID,c=await dt(de.addressRequest,de.addressResponse,{titleID:a,family:r});if(!c.ok||!c.address)return w("challenge",c.error??"NO_WALLET");let s=c.address,i=await t(s);if(!i.ok)return w("challenge",i.error);let d=await dt(de.signRequest,de.signResponse,{titleID:a,family:r,address:s,message:i.message});if(!d.ok||!d.signature)return w("sign",d.error??"SIGN_FAILED");let l=await n(s,d.signature);return l.ok?{ok:true,data:l.data}:w("login",l.error)}var on={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},rn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function nn(e){switch(e){case ue:return "Wallet sign-in is not available on this page.";case "NO_WALLET":case "CANCELLED":return "Connect a wallet on the page to sign in.";case "REJECTED":return "The signature was declined.";case "TIMEOUT":return "The wallet did not answer. Please try again.";default:return e}}function Po(e){let{client:t,networkID:n,onAuthenticated:o,onLinked:r,mode:a="login",family:c,disabled:s,label:i,style:d}=e,[l,u]=react.useState(false),[p,h]=react.useState(null);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{u(true),h(null),(async()=>{if(a==="link"){let f=await mt({client:t,networkID:n,family:c});if(f.ok){u(false),r?.(f.data.PlayAccess??null);return}h(nn(f.error)),u(false);return}let C=await pt({client:t,networkID:n,family:c});if(C.ok){o?.();return}h(nn(C.error)),u(false);})();},disabled:s||l,style:{...on,...s||l?{opacity:.6,cursor:"default"}:null,...d},children:l?"Waiting for the wallet\u2026":i??(a==="link"?"Link wallet":"Sign in with wallet")}),p&&jsxRuntime.jsx("span",{role:"alert",style:rn,children:p})]})}function an(e,t){return ct()?null:jsxRuntime.jsx(Po,{...e,family:t})}function sn(e){let{loading:t,disabled:n,label:o,style:r,error:a,onClick:c}=e;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:c,disabled:n||t,style:{...on,...n||t?{opacity:.6,cursor:"default"}:null,...r},children:t?"Loading wallet\u2026":o??"Sign in with wallet"}),a&&jsxRuntime.jsx("span",{role:"alert",style:rn,children:a})]})}function So(e){let{chains:t,walletConnectProjectId:n,appName:o,disabled:r,label:a,style:c,onAuthenticated:s,...i}=e,[d,l]=react.useState(null),[u,p]=react.useState(false),[h,y]=react.useState(null);if(P())return an(e,"evm");let C=()=>{p(true),y(null),(async()=>{try{let f=await Promise.resolve().then(()=>(Ze(),Qe)),R=f.createEvmWalletConfig({chains:t,walletConnectProjectId:n,appName:o});l({mod:f,config:R});}catch(f){console.error("[idosgames/wallet] failed to load the wallet module:",f),y("Could not load the wallet. Please try again.");}finally{p(false);}})();};if(d){let{WalletLogin:f}=d.mod;return jsxRuntime.jsx(f,{...i,onAuthenticated:s??ln,wagmiConfig:d.config,disabled:r,label:a,style:c,autoStart:true})}return jsxRuntime.jsx(sn,{loading:u,disabled:r,label:a??(e.mode==="link"?"Link wallet":void 0),style:c,error:h,onClick:C})}function ln(){}function Eo(e){let{walletConnectProjectId:t,appName:n,disabled:o,label:r,style:a,onAuthenticated:c,...s}=e,[i,d]=react.useState(null),[l,u]=react.useState(false),[p,h]=react.useState(null);if(P())return an(e,"solana");let y=()=>{u(true),h(null),(async()=>{try{let C=await Promise.resolve().then(()=>(tn(),en));t&&C.createSolanaWalletConfig({walletConnectProjectId:t,appName:n}),d(C);}catch(C){console.error("[idosgames/wallet] failed to load the wallet module:",C),h("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(i){let{SolanaWalletLogin:C}=i;return jsxRuntime.jsx(C,{...s,onAuthenticated:c??ln,disabled:o,label:r,style:a,autoStart:true})}return jsxRuntime.jsx(sn,{loading:l,disabled:o,label:r??(e.mode==="link"?"Link wallet":void 0),style:a,error:p,onClick:y})}var To={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 xo(e){let{onClose:t,style:n}=e,o=P(),[r,a]=react.useState(null),[c,s]=react.useState(null);return react.useEffect(()=>{if(o)return;let i=true;return (async()=>{try{let d=await Promise.resolve().then(()=>(Ze(),Qe));i&&a(d);}catch(d){console.error("[idosgames/wallet] failed to load the wallet panel:",d),i&&s("Could not load the wallet.");}})(),()=>{i=false;}},[o]),o?null:r?jsxRuntime.jsx(r.WalletPanel,{...e}):jsxRuntime.jsxs("div",{style:{...To,...n},children:[c??"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"})]})}ie();
2
- exports.LazySolanaWalletLogin=Eo;exports.LazyWalletLogin=So;exports.LazyWalletPanel=xo;exports.chainById=De;
1
+ 'use strict';var viem=require('viem'),core=require('@idosgames/core'),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'),actions=require('wagmi/actions'),appkitAdapterSolana=require('@reown/appkit-adapter-solana');var mn=Object.defineProperty;var k=(e,t)=>()=>(e&&(t=e(e=0)),t);var st=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:true});};function E(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function m(e,t,n){return {ok:false,stage:e,error:t,...n}}function w(e,t){return {ok:false,stage:e,error:t}}var _=k(()=>{});function yn(e=typeof window>"u"?"":window.location.hostname){let t=e.toLowerCase();return gn.test(t)?true:t!=="localhost"&&t!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function P(){if(typeof window>"u"||yn())return false;try{return window.self!==window.top}catch{return true}}function ct(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function H(e){return m(e,lt)}function Z(e){return w(e,lt)}var lt,gn,j=k(()=>{_();lt="WALLET_USE_SITE_PANEL",gn=/^[a-z0-9]{8}-preview\.idos\.games$/;});function De(e){return Object.values(exports.idosChains).find(t=>t.id===e)}function gt(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 ie=k(()=>{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 Ce(e){yt=e;}function se(){return yt}var yt,me=k(()=>{yt=null;});function be(e){let{chains:t=Re,walletConnectProjectId:n,appName:o,appUrl:r,appIcon:a,transports:c,connectors:s}=e,i=n??"__extension_only__";if(!s){let y=Le.get(i);if(y)return y}let d={};for(let y of t)d[y.id]=c?.[y.id]??wagmi.http();let l=r??(typeof window<"u"?window.location.origin:""),u={name:o??"iDosGames",description:o??"iDosGames game",url:l,icons:a?[a]:[]};if(n&&!s){let y=t.map(gt),C=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:d});return Ce(react$1.createAppKit({adapters:[C],networks:y,projectId:n,metadata:u,features:{analytics:false,email:false,socials:false}})),Le.set(i,C.wagmiConfig),C.wagmiConfig}let p=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],h=wagmi.createConfig({chains:t,connectors:p,transports:d});return s||Le.set(i,h),h}var Re,Le,Be=k(()=>{ie();me();Re=[exports.mainnet,exports.bsc,exports.polygon,exports.base,exports.arbitrum,exports.optimism,exports.sepolia,exports.polygonAmoy],Le=new Map;});function le(e){let{wagmiConfig:t,queryClient:n,children:o}=e,[r]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:r,children:o})})}var ve=k(()=>{});var Ae,ht,_e,kt,Me=k(()=>{Ae=[{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:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],ht=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{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:[]}],_e=[{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"}]}],kt=[{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 Ct(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}var bt=k(()=>{});async function V(e,t){let{walletClient:n,publicClient:o,account:r}=e,a=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:a})).status==="reverted")throw new Error(`On-chain transaction reverted (${a}).`);return a}var Oe=k(()=>{});function vt(e){let t=e.RewardPoolAddress;return t||null}async function At(e,t,n,o){return await e.publicClient.readContract({address:t,abi:_e,functionName:"allowance",args:[e.account,n]})>=o?null:V(e,{address:t,abi:_e,functionName:"approve",args:[n,o]})}async function Fe(e){let{client:t,clients:n,network:o,tokenAddress:r,amount:a,titleID:c,category:s}=e;if(P())return H("approve");let i=t.auth.context?.userID;if(!i)return m("approve","Not logged in.");let d=vt(o);if(!d)return m("approve","Network has no RewardPoolAddress.");if(a<=0n)return m("approve","Amount must be positive.");try{await At(n,r,d,a);}catch(p){return m("approve",E(p))}let l;try{l=await V(n,{address:d,abi:Ae,functionName:"depositERC20",args:[r,a,i,c,s??""]});}catch(p){return m("deposit-onchain",E(p))}let u=await t.blockchain.depositToken(o.NetworkID??"",l);return u.ok?{ok:true,onChainTxHash:l,data:u.data}:m("report",u.error,{onChainTxHash:l})}async function Ge(e){let{client:t,clients:n,network:o,nftContractAddress:r,tokenId:a,amount:c,titleID:s,category:i}=e;if(P())return H("deposit-onchain");let d=t.auth.context?.userID;if(!d)return m("deposit-onchain","Not logged in.");let l=vt(o);if(!l)return m("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return m("deposit-onchain","Amount must be positive.");let u=Ct(d,s,i),p;try{p=await V(n,{address:r,abi:kt,functionName:"safeTransferFrom",args:[n.account,l,a,c,u]});}catch(y){return m("deposit-onchain",E(y))}let h=await t.blockchain.depositNFT(o.NetworkID??"",p);return h.ok?{ok:true,onChainTxHash:p,data:h.data}:m("report",h.error,{onChainTxHash:p})}var Wt=k(()=>{Me();bt();Oe();_();j();});function Pt(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function St(e,t){return V(e,{address:t.ContractAddress,abi:Ae,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),Pt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Et(e,t){return V(e,{address:t.ContractAddress,abi:ht,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),Pt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function He(e){let{client:t,clients:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestTokenWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let u;try{u=await St(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let p=await Tt(t,l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:p}async function Ue(e){let{client:t,clients:n,itemID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestNFTWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.EvmSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no EVM signature.",{titleTransactionID:l});let u;try{u=await Et(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let p=await Tt(t,l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:p}async function Tt(e,t,n){if(!t)return m("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await e.blockchain.confirmWithdrawal(t,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:m("confirm",o.error,{onChainTxHash:n,titleTransactionID:t})}var It=k(()=>{Me();Oe();_();j();});async function fe(e){let{client:t,clients:n,networkID:o}=e;if(P())return Z("challenge");let r=e.walletAddress??n.account,a=await t.auth.requestWalletChallenge(r,o);if(!a.ok)return w("challenge",a.error);let c;try{c=await n.walletClient.signMessage({account:n.account,message:a.data.Message});}catch(i){return w("sign",E(i))}let s=await t.auth.loginWithWallet(r,o,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}async function Ke(e){let{client:t,clients:n,networkID:o}=e;if(P())return Z("challenge");let r=e.walletAddress??n.account,a=await t.auth.linkWallet(r,o);if(!a.ok)return w("challenge",a.error);if(!a.data.Challenge)return w("challenge","No challenge was issued.");let c;try{c=await n.walletClient.signMessage({account:n.account,message:a.data.Challenge});}catch(i){return w("sign",E(i))}let s=await t.auth.linkWallet(r,o,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}var xt=k(()=>{_();j();});var qe=k(()=>{Wt();It();xt();});function ye(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}function We(e,t){let n=ye();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,r)=>n?fe({client:e,clients:n,networkID:o,walletAddress:r}):Promise.resolve(w("challenge",ge)),depositToken:o=>n?Fe({client:e,clients:n,titleID:t,...o}):Promise.resolve(m("approve",ge)),depositNft:o=>n?Ge({client:e,clients:n,titleID:t,...o}):Promise.resolve(m("deposit-onchain",ge)),withdrawToken:o=>n?He({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",ge)),withdrawNft:o=>n?Ue({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",ge))}}var ge,Pe=k(()=>{qe();_();ge="Wallet not connected.";});function ce(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}var ze=k(()=>{});function _t(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(le,{wagmiConfig:t,children:jsxRuntime.jsx(Ve,{...n})})}function Kn(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function qn(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 Nt(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 zn(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,r=s=>{o||(o=true,a(),clearTimeout(c),n(s));},a=actions.watchAccount(e,{onChange:s=>{s.isConnected&&r(true);}}),c=setTimeout(()=>r(false),t);})}function jn(e,t=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(e).status)?new Promise(o=>{let r=false,a=()=>{r||(r=true,c(),clearTimeout(s),o());},c=actions.watchAccount(e,{onChange:i=>{n(i.status)||a();}}),s=setTimeout(a,t);}):Promise.resolve()}function Vn(e){let t=r=>e.find(a=>a.id===r||a.type===r),n=t("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:t("walletConnect")??n??e[0]}async function Yn(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 Rt(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(a=>{clearTimeout(r),n(a);},a=>{clearTimeout(r),o(a instanceof Error?a:new Error(String(a)));});})}function Ve(e){let{client:t,networkID:n,onAuthenticated:o,disabled:r,label:a,style:c,autoStart:s,mode:i="login",onLinked:d}=e,l=wagmi.useConfig(),{isConnected:u}=wagmi.useAccount(),{connectAsync:p,connectors:h}=wagmi.useConnect(),y=ye(),[C,g]=react.useState(false),[R,b]=react.useState(null),[U,O]=react.useState(false),F=react.useRef(0),B=react.useRef(false),T=async()=>{let D=++F.current,I=()=>F.current===D;g(true),b(null);try{if(await jn(l),!I())return;if(!actions.getAccount(l).isConnected){let W=se();if(W){if(await W.open(),!await zn(l)){b("No wallet was connected.");return}}else {let q=Vn(h);if(!q){b("No wallet connector is configured.");return}try{await p({connector:q});}catch(N){if(!Kn(N))throw N}}}let A=y??await Nt(l);if(!A&&actions.getAccount(l).isConnected&&(await new Promise(W=>setTimeout(W,300)),A=await Nt(l),!I()))return;if(!A){b("Wallet client is not available.");return}if(O(!0),i==="link"){let W=await Rt(Ke({client:t,clients:A,networkID:n}),Lt);if(!I())return;if(W.ok){d?.(W.data.PlayAccess??null);return}b(W.stage==="sign"?"Signature declined.":ce(W.error,"Could not link the wallet."));return}let G=await Rt(fe({client:t,clients:A,networkID:n}),Lt);if(!I())return;if(G.ok){o();return}b(G.stage==="sign"?"Signature declined.":ce(G.error,"Wallet sign-in failed."));}catch(A){if(!I())return;console.error("[idosgames/wallet] wallet sign-in failed:",A),b(qn(A));}finally{I()&&(g(false),O(false));}};react.useEffect(()=>{!s||B.current||(B.current=true,T());},[s]);let K=async()=>{await Yn(l)||await se()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{U?K():T();},disabled:r,style:{...$n,...r?{opacity:.6,cursor:"default"}:null,...c},children:U?"Waiting for signature \u2014 tap to open wallet":C?"Check your wallet\u2026":u?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),R&&jsxRuntime.jsx("span",{role:"alert",style:Qn,children:R})]})}var Lt,$n,Qn,Mt=k(()=>{me();ze();qe();ve();Pe();Lt=9e4;$n={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 Ft(e){let{client:t,walletConnectProjectId:n,appName:o,onClose:r,style:a}=e,[c,s]=react.useState(n??"");react.useEffect(()=>{if(n)return;let d=true;return (async()=>{let l=await t.blockchain.getDefinitions();if(!d||!l.ok)return;let u=l.data.Blockchain?.WalletLogin?.WalletConnectProjectId;u&&s(u);})(),()=>{d=false;}},[t,n]);let i=react.useMemo(()=>be({walletConnectProjectId:c||void 0,appName:o}),[c,o]);return jsxRuntime.jsx(le,{wagmiConfig:i,children:jsxRuntime.jsx(lo,{client:t,appName:o,onClose:r,style:a})})}function lo({client:e,onClose:t,style:n}){let o=We(e,e.titleID),{address:r,isConnected:a,chainId:c}=wagmi.useAccount(),{connect:s,connectors:i}=wagmi.useConnect(),{disconnect:d}=wagmi.useDisconnect(),{switchChainAsync:l}=wagmi.useSwitchChain(),[,u]=react.useReducer(f=>f+1,0),[p,h]=react.useState({}),[y,C]=react.useState({}),[g,R]=react.useState(""),[b,U]=react.useState(""),[O,F]=react.useState(""),[B,T]=react.useState(false),[K,D]=react.useState(null);react.useEffect(()=>{let f=true;return (async()=>{let S=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!f||!S.ok)return;let Q=S.data.Blockchain?.Networks??{},xe={};for(let[pn,it]of Object.entries(Q))it.Type==="EVM"&&(xe[pn]=it);h(xe),C(S.data.CryptoCurrencies??{});let un=Object.keys(xe)[0]??"";R(un);})(),()=>{f=false;}},[e]),react.useEffect(()=>e.on("user:anyUpdated",u),[e]);let I=react.useMemo(()=>Object.entries(y).filter(([,f])=>f.Networks?.some(S=>S.NetworkID===g&&!!S.ContractAddress)),[y,g]);react.useEffect(()=>{let f=I[0]?.[0]??"";U(S=>I.some(([Q])=>Q===S)?S:f);},[I]);let A=g?p[g]:void 0,W=(b?y[b]:void 0)?.Networks?.find(f=>f.NetworkID===g),q=b?e.data.user.getCryptoCurrencyAmount(b):"0";async function N(){if(!A?.ChainID||c===A.ChainID)return true;try{return await l({chainId:A.ChainID}),!0}catch{return D({ok:false,stage:"approve",error:`Switch your wallet to chain ${A.ChainID} to continue.`}),false}}async function $(){if(!(!A||!W?.ContractAddress)){if(T(true),D(null),await N()){let f=W.Decimals??18,S;try{S=viem.parseUnits(O||"0",f);}catch{D({ok:false,stage:"approve",error:"Invalid amount."}),T(false);return}let Q=await o.depositToken({network:A,tokenAddress:W.ContractAddress,amount:S});D(Q),Q.ok&&await e.blockchain.getUserState();}T(false);}}async function dn(){if(!(!A||!o.account)){if(T(true),D(null),await N()){let f=await o.withdrawToken({currencyID:b,networkID:g,walletAddress:o.account,amount:O||"0"});D(f),f.ok&&await e.blockchain.getUserState();}T(false);}}return jsxRuntime.jsxs("div",{style:{...ao,...n},children:[jsxRuntime.jsxs("div",{style:{...$e,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:io,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:t,children:"\u2715"})]}),a?jsxRuntime.jsxs("div",{style:$e,children:[jsxRuntime.jsxs("span",{style:{...Y,flex:1,alignSelf:"center"},children:[r?.slice(0,6),"\u2026",r?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:()=>d(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:Y,children:"Connect a browser or mobile wallet"}),i.map(f=>jsxRuntime.jsx("button",{type:"button",style:Ee,onClick:()=>s({connector:f}),children:f.name},f.uid))]}),Object.keys(p).length===0?jsxRuntime.jsx("span",{style:Y,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Network"}),jsxRuntime.jsx("select",{style:Ye,value:g,onChange:f=>R(f.target.value),children:Object.entries(p).map(([f,S])=>jsxRuntime.jsx("option",{value:f,children:S.DisplayName??f},f))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Token"}),jsxRuntime.jsxs("select",{style:Ye,value:b,onChange:f=>U(f.target.value),children:[I.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),I.map(([f,S])=>jsxRuntime.jsx("option",{value:f,children:S.DisplayName??f},f))]})]}),jsxRuntime.jsxs("div",{style:Y,children:["In-game balance: ",jsxRuntime.jsx("b",{children:q})," ",b]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:Y,children:"Amount"}),jsxRuntime.jsx("input",{style:Ye,inputMode:"decimal",placeholder:"0.0",value:O,onChange:f=>F(f.target.value)})]}),jsxRuntime.jsxs("div",{style:$e,children:[jsxRuntime.jsx("button",{type:"button",style:{...so,flex:1,opacity:B?.6:1},disabled:B||!a||!W?.ContractAddress,onClick:()=>{$();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...Ee,flex:1,opacity:B?.6:1},disabled:B||!a||!b,onClick:()=>{dn();},children:"Withdraw"})]})]}),K&&jsxRuntime.jsx(co,{result:K})]})}function co({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 ao,io,Y,Ye,so,Ee,$e,Gt=k(()=>{Be();ve();Pe();ao={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"},io={fontWeight:700,fontSize:16},Y={fontSize:12,opacity:.7},Ye={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},so={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},Ee={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},$e={display:"flex",gap:8};});var Qe={};st(Qe,{DEFAULT_EVM_CHAINS:()=>Re,IDosGamesWalletProvider:()=>le,WalletLogin:()=>_t,WalletLoginButton:()=>Ve,WalletPanel:()=>Ft,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>De,createEvmWalletConfig:()=>be,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>We,useEvmBridgeClients:()=>ye});var Ze=k(()=>{Be();ie();ve();Pe();Mt();Gt();});function Ht(e){let{walletConnectProjectId:t,appName:n,appUrl:o,appIcon:r,wallets:a}=e,c=e.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),i={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:r?[r]:[]},d=new appkitAdapterSolana.SolanaAdapter(a?{wallets:a}:{});return Ce(react$1.createAppKit({adapters:[d],networks:c,projectId:t,metadata:i,features:{analytics:false,email:false,socials:false}})),d}var Ut=k(()=>{ie();me();});async function Je(e){let{client:t,adapter:n,network:o,mint:r,amountRaw:a,titleID:c,category:s}=e;if(P())return H("deposit-onchain");let i=t.auth.context?.userID;if(!i)return m("deposit-onchain","Not logged in.");if(a<=0n)return m("deposit-onchain","Amount must be positive.");let d;try{d=await n.depositSpl({mint:r,amountRaw:a,userID:i,titleID:c,category:core.normalizeBlockchainCategory(s)});}catch(u){return m("deposit-onchain",E(u))}let l=await t.blockchain.depositToken(o.NetworkID??"",d);return l.ok?{ok:true,onChainTxHash:d,data:l.data}:m("report",l.error,{onChainTxHash:d})}async function Xe(e){let{client:t,adapter:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(P())return H("request");let i=await t.blockchain.requestTokenWithdrawal(o,r,a,c,s);if(!i.ok)return m("request",i.error);let d=i.data.SolanaSignature,l=i.data.TitleTransactionID??void 0;if(!d)return m("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let u;try{u=await n.submitWithdrawal(d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}if(!l)return m("confirm","Missing TitleTransactionID.",{onChainTxHash:u});let p=await t.blockchain.confirmWithdrawal(l,u);return p.ok?{ok:true,onChainTxHash:u,data:i.data}:m("confirm",p.error,{onChainTxHash:u,titleTransactionID:l})}var Kt=k(()=>{_();j();});async function he(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(P())return Z("challenge");let a=await t.auth.requestWalletChallenge(o,n);if(!a.ok)return w("challenge",a.error);let c;try{let i=await r(new TextEncoder().encode(a.data.Message));c=qt(i);}catch(i){return w("sign",E(i))}let s=await t.auth.loginWithWallet(o,n,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}async function et(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(P())return Z("challenge");let a=await t.auth.linkWallet(o,n);if(!a.ok)return w("challenge",a.error);if(!a.data.Challenge)return w("challenge","No challenge was issued.");let c;try{let i=await r(new TextEncoder().encode(a.data.Challenge));c=qt(i);}catch(i){return w("sign",E(i))}let s=await t.auth.linkWallet(o,n,c);return s.ok?{ok:true,data:s.data}:w("login",s.error)}function qt(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}var zt=k(()=>{_();j();});var tt=k(()=>{Kt();zt();});function Vt(e,t,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:r}=react$1.useAppKitProvider("solana"),a=o??null,c=r?.signMessage?.bind(r);return {connected:!!a,account:a,loginWithWallet:(s,i)=>{let d=i??a;return d?c?he({client:e,networkID:s,walletAddress:d,signMessage:c}):Promise.resolve(w("sign","The connected wallet does not support message signing.")):Promise.resolve(w("challenge",jt))},depositToken:s=>Je({client:e,adapter:n,titleID:t,...s}),withdrawToken:s=>{let i=s.walletAddress??a;return i?Xe({client:e,adapter:n,...s,walletAddress:i}):Promise.resolve(m("request",jt))}}}var jt,Yt=k(()=>{tt();_();jt="Wallet not connected.";});function Co(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 Qt(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(a=>{clearTimeout(r),n(a);},a=>{clearTimeout(r),o(a instanceof Error?a:new Error(String(a)));});})}function bo(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 Jt(e){let{client:t,networkID:n,onAuthenticated:o,disabled:r,label:a,style:c,autoStart:s,mode:i="login",onLinked:d}=e,{address:l,isConnected:u}=react$1.useAppKitAccount(),{walletProvider:p}=react$1.useAppKitProvider("solana"),[h,y]=react.useState(false),[C,g]=react.useState(null),[R,b]=react.useState(false),[U,O]=react.useState(false),F=react.useRef(null),B=react.useRef(0),T=react.useCallback(()=>{F.current&&clearTimeout(F.current),F.current=null;},[]);react.useEffect(()=>T,[T]);let K=react.useRef(false),D=react.useCallback(async()=>{let G=++B.current,W=()=>B.current===G,q=p?.signMessage?.bind(p);if(!l||!q){g("The connected wallet cannot sign messages."),y(false);return}y(true),g(null);try{if(O(!0),i==="link"){let $=await Qt(et({client:t,networkID:n,walletAddress:l,signMessage:q}),$t);if(!W())return;if($.ok){d?.($.data.PlayAccess??null);return}g($.stage==="sign"?"Signature declined.":ce($.error,"Could not link the wallet."));return}let N=await Qt(he({client:t,networkID:n,walletAddress:l,signMessage:q}),$t);if(!W())return;if(N.ok){o();return}g(N.stage==="sign"?"Signature declined.":ce(N.error,"Wallet sign-in failed."));}catch(N){if(!W())return;console.error("[idosgames/wallet] solana sign-in failed:",N),g(bo(N));}finally{W()&&(y(false),O(false));}},[l,p,t,n,o,i,d]),I=react.useCallback(()=>{Co(p)||se()?.open();},[p]);react.useEffect(()=>{!R||!u||!l||!p||(b(false),T(),D());},[R,u,l,p,D,T]);let A=()=>{if(U){I();return}if(g(null),K.current=true,u&&l&&p){D();return}let G=se();if(!G){g("Wallet sign-in is not configured for this title.");return}y(true),b(true),T(),F.current=setTimeout(()=>{b(false),y(false),g("No wallet was connected.");},ko),G.open();};return react.useEffect(()=>{!s||K.current||(K.current=true,A());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:A,disabled:r,style:{...vo,...r?{opacity:.6,cursor:"default"}:null,...c},children:U?"Waiting for signature \u2014 tap to open wallet":h?"Check your wallet\u2026":u?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:Ao,children:C})]})}var ko,$t,vo,Ao,Xt=k(()=>{ze();tt();me();ko=18e4,$t=9e4;vo={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Ao={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var en={};st(en,{SolanaWalletLogin:()=>Jt,createSolanaWalletConfig:()=>Ht,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>Vt});var tn=k(()=>{Ut();Yt();Xt();ie();});j();_();var de={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},ue="PLATFORM_WALLET_UNAVAILABLE",hn=5e3,kn=18e4;function Cn(){let e=[...core.PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!e.includes(t)&&core.isPlatformParentOrigin(t)&&e.push(t),e}function bn(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function dt(e,t,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:ue});let o=window.parent;if(!o)return Promise.resolve({ok:false,error:ue});let r=bn();return new Promise(a=>{let c=false,s,i=l=>{c||(c=true,window.removeEventListener("message",d),clearTimeout(s),a(l));},d=l=>{if(!core.isPlatformParentOrigin(l.origin))return;let u=l.data;if(!(!u||u.requestId!==r)){if(u.type===de.ack){clearTimeout(s),s=setTimeout(()=>i({ok:false,error:"TIMEOUT"}),kn);return}u.type===t&&i({ok:u.ok===true,error:typeof u.error=="string"?u.error:void 0,address:typeof u.address=="string"?u.address:void 0,signature:typeof u.signature=="string"?u.signature:void 0});}};s=setTimeout(()=>i({ok:false,error:ue}),hn),window.addEventListener("message",d);for(let l of Cn())try{o.postMessage({type:e,requestId:r,...n},l);}catch{}})}async function pt(e){let{client:t,networkID:n}=e;return ft(e,async o=>{let r=await t.auth.requestWalletChallenge(o,n);return r.ok?{ok:true,message:r.data.Message}:{ok:false,error:r.error}},(o,r)=>t.auth.loginWithWallet(o,n,r))}async function mt(e){let{client:t,networkID:n}=e;return ft(e,async o=>{let r=await t.auth.linkWallet(o,n);return r.ok?r.data.Challenge?{ok:true,message:r.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:r.error}},(o,r)=>t.auth.linkWallet(o,n,r))}async function ft(e,t,n){let{client:o,family:r}=e,a=o.titleID,c=await dt(de.addressRequest,de.addressResponse,{titleID:a,family:r});if(!c.ok||!c.address)return w("challenge",c.error??"NO_WALLET");let s=c.address,i=await t(s);if(!i.ok)return w("challenge",i.error);let d=await dt(de.signRequest,de.signResponse,{titleID:a,family:r,address:s,message:i.message});if(!d.ok||!d.signature)return w("sign",d.error??"SIGN_FAILED");let l=await n(s,d.signature);return l.ok?{ok:true,data:l.data}:w("login",l.error)}var on={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},rn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function nn(e){switch(e){case ue:return "Wallet sign-in is not available on this page.";case "NO_WALLET":case "CANCELLED":return "Connect a wallet on the page to sign in.";case "REJECTED":return "The signature was declined.";case "TIMEOUT":return "The wallet did not answer. Please try again.";default:return e}}function Eo(e){let{client:t,networkID:n,onAuthenticated:o,onLinked:r,mode:a="login",family:c,disabled:s,label:i,style:d}=e,[l,u]=react.useState(false),[p,h]=react.useState(null);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{u(true),h(null),(async()=>{if(a==="link"){let g=await mt({client:t,networkID:n,family:c});if(g.ok){u(false),r?.(g.data.PlayAccess??null);return}h(nn(g.error)),u(false);return}let C=await pt({client:t,networkID:n,family:c});if(C.ok){o?.();return}h(nn(C.error)),u(false);})();},disabled:s||l,style:{...on,...s||l?{opacity:.6,cursor:"default"}:null,...d},children:l?"Waiting for the wallet\u2026":i??(a==="link"?"Link wallet":"Sign in with wallet")}),p&&jsxRuntime.jsx("span",{role:"alert",style:rn,children:p})]})}function an(e,t){return ct()?null:jsxRuntime.jsx(Eo,{...e,family:t})}function sn(e){let{loading:t,disabled:n,label:o,style:r,error:a,onClick:c}=e;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:c,disabled:n||t,style:{...on,...n||t?{opacity:.6,cursor:"default"}:null,...r},children:t?"Loading wallet\u2026":o??"Sign in with wallet"}),a&&jsxRuntime.jsx("span",{role:"alert",style:rn,children:a})]})}function To(e){let{chains:t,walletConnectProjectId:n,appName:o,disabled:r,label:a,style:c,onAuthenticated:s,...i}=e,[d,l]=react.useState(null),[u,p]=react.useState(false),[h,y]=react.useState(null);if(P())return an(e,"evm");let C=()=>{p(true),y(null),(async()=>{try{let g=await Promise.resolve().then(()=>(Ze(),Qe)),R=g.createEvmWalletConfig({chains:t,walletConnectProjectId:n,appName:o});l({mod:g,config:R});}catch(g){console.error("[idosgames/wallet] failed to load the wallet module:",g),y("Could not load the wallet. Please try again.");}finally{p(false);}})();};if(d){let{WalletLogin:g}=d.mod;return jsxRuntime.jsx(g,{...i,onAuthenticated:s??ln,wagmiConfig:d.config,disabled:r,label:a,style:c,autoStart:true})}return jsxRuntime.jsx(sn,{loading:u,disabled:r,label:a??(e.mode==="link"?"Link wallet":void 0),style:c,error:h,onClick:C})}function ln(){}function Io(e){let{walletConnectProjectId:t,appName:n,disabled:o,label:r,style:a,onAuthenticated:c,...s}=e,[i,d]=react.useState(null),[l,u]=react.useState(false),[p,h]=react.useState(null);if(P())return an(e,"solana");let y=()=>{u(true),h(null),(async()=>{try{let C=await Promise.resolve().then(()=>(tn(),en));t&&C.createSolanaWalletConfig({walletConnectProjectId:t,appName:n}),d(C);}catch(C){console.error("[idosgames/wallet] failed to load the wallet module:",C),h("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(i){let{SolanaWalletLogin:C}=i;return jsxRuntime.jsx(C,{...s,onAuthenticated:c??ln,disabled:o,label:r,style:a,autoStart:true})}return jsxRuntime.jsx(sn,{loading:l,disabled:o,label:r??(e.mode==="link"?"Link wallet":void 0),style:a,error:p,onClick:y})}var xo={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 Do(e){let{onClose:t,style:n}=e,o=P(),[r,a]=react.useState(null),[c,s]=react.useState(null);return react.useEffect(()=>{if(o)return;let i=true;return (async()=>{try{let d=await Promise.resolve().then(()=>(Ze(),Qe));i&&a(d);}catch(d){console.error("[idosgames/wallet] failed to load the wallet panel:",d),i&&s("Could not load the wallet.");}})(),()=>{i=false;}},[o]),o?null:r?jsxRuntime.jsx(r.WalletPanel,{...e}):jsxRuntime.jsxs("div",{style:{...xo,...n},children:[c??"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"})]})}ie();
2
+ exports.LazySolanaWalletLogin=Io;exports.LazyWalletLogin=To;exports.LazyWalletPanel=Do;exports.chainById=De;
@@ -1 +1 @@
1
- import {d,c,b}from'../chunk-3VONNSCN.js';import {e,f}from'../chunk-IEWZH6XD.js';export{n as arbitrum,m as base,k as bsc,s as chainById,r as idosChains,j as mainnet,o as optimism,l as polygon,q as polygonAmoy,p as sepolia,v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var v={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},E={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function k(e){switch(e){case b:return "Wallet sign-in is not available on this page.";case "NO_WALLET":case "CANCELLED":return "Connect a wallet on the page to sign in.";case "REJECTED":return "The signature was declined.";case "TIMEOUT":return "The wallet did not answer. Please try again.";default:return e}}function K(e){let{client:t,networkID:a,onAuthenticated:l,onLinked:n,mode:o="login",family:i,disabled:p,label:c$1,style:r}=e,[m,y]=useState(false),[L,g]=useState(null);return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{y(true),g(null),(async()=>{if(o==="link"){let u=await d({client:t,networkID:a,family:i});if(u.ok){y(false),n?.(u.data.PlayAccess??null);return}g(k(u.error)),y(false);return}let s=await c({client:t,networkID:a,family:i});if(s.ok){l?.();return}g(k(s.error)),y(false);})();},disabled:p||m,style:{...v,...p||m?{opacity:.6,cursor:"default"}:null,...r},children:m?"Waiting for the wallet\u2026":c$1??(o==="link"?"Link wallet":"Sign in with wallet")}),L&&jsx("span",{role:"alert",style:E,children:L})]})}function z(e,t){return f()?null:jsx(K,{...e,family:t})}function x(e){let{loading:t,disabled:a,label:l,style:n,error:o,onClick:i}=e;return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:i,disabled:a||t,style:{...v,...a||t?{opacity:.6,cursor:"default"}:null,...n},children:t?"Loading wallet\u2026":l??"Sign in with wallet"}),o&&jsx("span",{role:"alert",style:E,children:o})]})}function q(e$1){let{chains:t,walletConnectProjectId:a,appName:l,disabled:n,label:o,style:i,onAuthenticated:p,...c}=e$1,[r,m]=useState(null),[y,L]=useState(false),[g,b]=useState(null);if(e())return z(e$1,"evm");let s=()=>{L(true),b(null),(async()=>{try{let u=await import('./index.js'),I=u.createEvmWalletConfig({chains:t,walletConnectProjectId:a,appName:l});m({mod:u,config:I});}catch(u){console.error("[idosgames/wallet] failed to load the wallet module:",u),b("Could not load the wallet. Please try again.");}finally{L(false);}})();};if(r){let{WalletLogin:u}=r.mod;return jsx(u,{...c,onAuthenticated:p??A,wagmiConfig:r.config,disabled:n,label:o,style:i,autoStart:true})}return jsx(x,{loading:y,disabled:n,label:o??(e$1.mode==="link"?"Link wallet":void 0),style:i,error:g,onClick:s})}function A(){}function H(e$1){let{walletConnectProjectId:t,appName:a,disabled:l,label:n,style:o,onAuthenticated:i,...p}=e$1,[c,r]=useState(null),[m,y]=useState(false),[L,g]=useState(null);if(e())return z(e$1,"solana");let b=()=>{y(true),g(null),(async()=>{try{let s=await import('./solanaIndex.js');t&&s.createSolanaWalletConfig({walletConnectProjectId:t,appName:a}),r(s);}catch(s){console.error("[idosgames/wallet] failed to load the wallet module:",s),g("Could not load the wallet. Please try again.");}finally{y(false);}})();};if(c){let{SolanaWalletLogin:s}=c;return jsx(s,{...p,onAuthenticated:i??A,disabled:l,label:n,style:o,autoStart:true})}return jsx(x,{loading:m,disabled:l,label:n??(e$1.mode==="link"?"Link wallet":void 0),style:o,error:L,onClick:b})}var Q={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 X(e$1){let{onClose:t,style:a}=e$1,l=e(),[n,o]=useState(null),[i,p]=useState(null);return useEffect(()=>{if(l)return;let c=true;return (async()=>{try{let r=await import('./index.js');c&&o(r);}catch(r){console.error("[idosgames/wallet] failed to load the wallet panel:",r),c&&p("Could not load the wallet.");}})(),()=>{c=false;}},[l]),l?null:n?jsx(n.WalletPanel,{...e$1}):jsxs("div",{style:{...Q,...a},children:[i??"Loading wallet\u2026",t&&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"})]})}export{H as LazySolanaWalletLogin,q as LazyWalletLogin,X as LazyWalletPanel};
1
+ import {d,c,b}from'../chunk-Q2E7DE4S.js';import {f,g}from'../chunk-K3THMWU2.js';export{o as arbitrum,n as base,l as bsc,t as chainById,s as idosChains,k as mainnet,p as optimism,m as polygon,r as polygonAmoy,q as sepolia,w as solanaDevnet,v as solanaMainnet}from'../chunk-K3THMWU2.js';import {useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var v={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},E={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function k(e){switch(e){case b:return "Wallet sign-in is not available on this page.";case "NO_WALLET":case "CANCELLED":return "Connect a wallet on the page to sign in.";case "REJECTED":return "The signature was declined.";case "TIMEOUT":return "The wallet did not answer. Please try again.";default:return e}}function K(e){let{client:t,networkID:a,onAuthenticated:l,onLinked:n,mode:o="login",family:i,disabled:p,label:c$1,style:r}=e,[m,y]=useState(false),[L,g]=useState(null);return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{y(true),g(null),(async()=>{if(o==="link"){let u=await d({client:t,networkID:a,family:i});if(u.ok){y(false),n?.(u.data.PlayAccess??null);return}g(k(u.error)),y(false);return}let s=await c({client:t,networkID:a,family:i});if(s.ok){l?.();return}g(k(s.error)),y(false);})();},disabled:p||m,style:{...v,...p||m?{opacity:.6,cursor:"default"}:null,...r},children:m?"Waiting for the wallet\u2026":c$1??(o==="link"?"Link wallet":"Sign in with wallet")}),L&&jsx("span",{role:"alert",style:E,children:L})]})}function z(e,t){return g()?null:jsx(K,{...e,family:t})}function x(e){let{loading:t,disabled:a,label:l,style:n,error:o,onClick:i}=e;return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:i,disabled:a||t,style:{...v,...a||t?{opacity:.6,cursor:"default"}:null,...n},children:t?"Loading wallet\u2026":l??"Sign in with wallet"}),o&&jsx("span",{role:"alert",style:E,children:o})]})}function q(e){let{chains:t,walletConnectProjectId:a,appName:l,disabled:n,label:o,style:i,onAuthenticated:p,...c}=e,[r,m]=useState(null),[y,L]=useState(false),[g,b]=useState(null);if(f())return z(e,"evm");let s=()=>{L(true),b(null),(async()=>{try{let u=await import('./index.js'),I=u.createEvmWalletConfig({chains:t,walletConnectProjectId:a,appName:l});m({mod:u,config:I});}catch(u){console.error("[idosgames/wallet] failed to load the wallet module:",u),b("Could not load the wallet. Please try again.");}finally{L(false);}})();};if(r){let{WalletLogin:u}=r.mod;return jsx(u,{...c,onAuthenticated:p??A,wagmiConfig:r.config,disabled:n,label:o,style:i,autoStart:true})}return jsx(x,{loading:y,disabled:n,label:o??(e.mode==="link"?"Link wallet":void 0),style:i,error:g,onClick:s})}function A(){}function H(e){let{walletConnectProjectId:t,appName:a,disabled:l,label:n,style:o,onAuthenticated:i,...p}=e,[c,r]=useState(null),[m,y]=useState(false),[L,g]=useState(null);if(f())return z(e,"solana");let b=()=>{y(true),g(null),(async()=>{try{let s=await import('./solanaIndex.js');t&&s.createSolanaWalletConfig({walletConnectProjectId:t,appName:a}),r(s);}catch(s){console.error("[idosgames/wallet] failed to load the wallet module:",s),g("Could not load the wallet. Please try again.");}finally{y(false);}})();};if(c){let{SolanaWalletLogin:s}=c;return jsx(s,{...p,onAuthenticated:i??A,disabled:l,label:n,style:o,autoStart:true})}return jsx(x,{loading:m,disabled:l,label:n??(e.mode==="link"?"Link wallet":void 0),style:o,error:L,onClick:b})}var Q={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 X(e){let{onClose:t,style:a}=e,l=f(),[n,o]=useState(null),[i,p]=useState(null);return useEffect(()=>{if(l)return;let c=true;return (async()=>{try{let r=await import('./index.js');c&&o(r);}catch(r){console.error("[idosgames/wallet] failed to load the wallet panel:",r),c&&p("Could not load the wallet.");}})(),()=>{c=false;}},[l]),l?null:n?jsx(n.WalletPanel,{...e}):jsxs("div",{style:{...Q,...a},children:[i??"Loading wallet\u2026",t&&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"})]})}export{H as LazySolanaWalletLogin,q as LazyWalletLogin,X as LazyWalletPanel};
@@ -1,2 +1,2 @@
1
- 'use strict';var appkitAdapterSolana=require('@reown/appkit-adapter-solana'),react=require('@reown/appkit/react'),core=require('@idosgames/core'),viem=require('viem'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime');var N={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"},re={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"};var V=null;function $(e){V=e;}function D(){return V}function se(e){let{walletConnectProjectId:t,appName:a,appUrl:i,appIcon:s,wallets:n}=e,c=e.networks??[N],o=i??(typeof window<"u"?window.location.origin:""),r={name:a??"iDosGames",description:a??"iDosGames game",url:o,icons:s?[s]:[]},p=new appkitAdapterSolana.SolanaAdapter(n?{wallets:n}:{});return $(react.createAppKit({adapters:[p],networks:c,projectId:t,metadata:r,features:{analytics:false,email:false,socials:false}})),p}function w(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function d(e,t,a){return {ok:false,stage:e,error:t,...a}}function u(e,t){return {ok:false,stage:e,error:t}}var J="WALLET_USE_SITE_PANEL";function y(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function B(e){return d(e,J)}function R(e){return u(e,J)}async function K(e){let{client:t,adapter:a,network:i,mint:s,amountRaw:n,titleID:c,category:o}=e;if(y())return B("deposit-onchain");let r=t.auth.context?.userID;if(!r)return d("deposit-onchain","Not logged in.");if(n<=0n)return d("deposit-onchain","Amount must be positive.");let p;try{p=await a.depositSpl({mint:s,amountRaw:n,userID:r,titleID:c,category:core.normalizeBlockchainCategory(o)});}catch(g){return d("deposit-onchain",w(g))}let l=await t.blockchain.depositToken(i.NetworkID??"",p);return l.ok?{ok:true,onChainTxHash:p,data:l.data}:d("report",l.error,{onChainTxHash:p})}async function _(e){let{client:t,adapter:a,currencyID:i,networkID:s,walletAddress:n,amount:c,category:o}=e;if(y())return B("request");let r=await t.blockchain.requestTokenWithdrawal(i,s,n,c,o);if(!r.ok)return d("request",r.error);let p=r.data.SolanaSignature,l=r.data.TitleTransactionID??void 0;if(!p)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let g;try{g=await a.submitWithdrawal(p);}catch(b){return d("withdraw-onchain",w(b),{titleTransactionID:l})}if(!l)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:g});let m=await t.blockchain.confirmWithdrawal(l,g);return m.ok?{ok:true,onChainTxHash:g,data:r.data}:d("confirm",m.error,{onChainTxHash:g,titleTransactionID:l})}async function T(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return R("challenge");let n=await t.auth.requestWalletChallenge(i,a);if(!n.ok)return u("challenge",n.error);let c;try{let r=await s(new TextEncoder().encode(n.data.Message));c=Q(r);}catch(r){return u("sign",w(r))}let o=await t.auth.loginWithWallet(i,a,c);return o.ok?{ok:true,data:o.data}:u("login",o.error)}async function O(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return R("challenge");let n=await t.auth.linkWallet(i,a);if(!n.ok)return u("challenge",n.error);if(!n.data.Challenge)return u("challenge","No challenge was issued.");let c;try{let r=await s(new TextEncoder().encode(n.data.Challenge));c=Q(r);}catch(r){return u("sign",w(r))}let o=await t.auth.linkWallet(i,a,c);return o.ok?{ok:true,data:o.data}:u("login",o.error)}function Q(e){let t="0x";for(let a of e)t+=a.toString(16).padStart(2,"0");return t}var X="Wallet not connected.";function ue(e,t,a){let{address:i}=react.useAppKitAccount(),{walletProvider:s}=react.useAppKitProvider("solana"),n=i??null,c=s?.signMessage?.bind(s);return {connected:!!n,account:n,loginWithWallet:(o,r)=>{let p=r??n;return p?c?T({client:e,networkID:o,walletAddress:p,signMessage:c}):Promise.resolve(u("sign","The connected wallet does not support message signing.")):Promise.resolve(u("challenge",X))},depositToken:o=>K({client:e,adapter:a,titleID:t,...o}),withdrawToken:o=>{let r=o.walletAddress??n;return r?_({client:e,adapter:a,...o,walletAddress:r}):Promise.resolve(d("request",X))}}}function U(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}var fe=18e4,ee=9e4;function he(e){try{let a=e?.session?.peer?.metadata?.redirect,i=a?.native||a?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function te(e,t){return new Promise((a,i)=>{let s=setTimeout(()=>i(new Error("The wallet request timed out.")),t);e.then(n=>{clearTimeout(s),a(n);},n=>{clearTimeout(s),i(n instanceof Error?n:new Error(String(n)));});})}function we(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 ye(e){let{client:t,networkID:a,onAuthenticated:i,disabled:s,label:n,style:c,autoStart:o,mode:r="login",onLinked:p}=e,{address:l,isConnected:g}=react.useAppKitAccount(),{walletProvider:m}=react.useAppKitProvider("solana"),[b,S]=react$1.useState(false),[q,f]=react$1.useState(null),[H,P]=react$1.useState(false),[Y,z]=react$1.useState(false),A=react$1.useRef(null),j=react$1.useRef(0),k=react$1.useCallback(()=>{A.current&&clearTimeout(A.current),A.current=null;},[]);react$1.useEffect(()=>k,[k]);let L=react$1.useRef(false),v=react$1.useCallback(async()=>{let W=++j.current,x=()=>j.current===W,I=m?.signMessage?.bind(m);if(!l||!I){f("The connected wallet cannot sign messages."),S(false);return}S(true),f(null);try{if(z(!0),r==="link"){let E=await te(O({client:t,networkID:a,walletAddress:l,signMessage:I}),ee);if(!x())return;if(E.ok){p?.(E.data.PlayAccess??null);return}f(E.stage==="sign"?"Signature declined.":U(E.error,"Could not link the wallet."));return}let h=await te(T({client:t,networkID:a,walletAddress:l,signMessage:I}),ee);if(!x())return;if(h.ok){i();return}f(h.stage==="sign"?"Signature declined.":U(h.error,"Wallet sign-in failed."));}catch(h){if(!x())return;console.error("[idosgames/wallet] solana sign-in failed:",h),f(we(h));}finally{x()&&(S(false),z(false));}},[l,m,t,a,i,r,p]),ae=react$1.useCallback(()=>{he(m)||D()?.open();},[m]);react$1.useEffect(()=>{!H||!g||!l||!m||(P(false),k(),v());},[H,g,l,m,v,k]);let Z=()=>{if(Y){ae();return}if(f(null),L.current=true,g&&l&&m){v();return}let W=D();if(!W){f("Wallet sign-in is not configured for this title.");return}S(true),P(true),k(),A.current=setTimeout(()=>{P(false),S(false),f("No wallet was connected.");},fe),W.open();};return react$1.useEffect(()=>{!o||L.current||(L.current=true,Z());},[o]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:Z,disabled:s,style:{...Se,...s?{opacity:.6,cursor:"default"}:null,...c},children:Y?"Waiting for signature \u2014 tap to open wallet":b?"Check your wallet\u2026":g?n??(r==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),q&&jsxRuntime.jsx("span",{role:"alert",style:ke,children:q})]})}var Se={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ke={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
2
- exports.SolanaWalletLogin=ye;exports.createSolanaWalletConfig=se;exports.solanaDevnet=re;exports.solanaMainnet=N;exports.useSolanaBridge=ue;
1
+ 'use strict';var appkitAdapterSolana=require('@reown/appkit-adapter-solana'),react=require('@reown/appkit/react'),core=require('@idosgames/core'),viem=require('viem'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime');var N={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"},re={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"};var Z=null;function $(e){Z=e;}function D(){return Z}function se(e){let{walletConnectProjectId:t,appName:a,appUrl:i,appIcon:s,wallets:n}=e,c=e.networks??[N],o=i??(typeof window<"u"?window.location.origin:""),r={name:a??"iDosGames",description:a??"iDosGames game",url:o,icons:s?[s]:[]},p=new appkitAdapterSolana.SolanaAdapter(n?{wallets:n}:{});return $(react.createAppKit({adapters:[p],networks:c,projectId:t,metadata:r,features:{analytics:false,email:false,socials:false}})),p}function w(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function d(e,t,a){return {ok:false,stage:e,error:t,...a}}function u(e,t){return {ok:false,stage:e,error:t}}var J="WALLET_USE_SITE_PANEL",ce=/^[a-z0-9]{8}-preview\.idos\.games$/;function pe(e=typeof window>"u"?"":window.location.hostname){let t=e.toLowerCase();return ce.test(t)?true:t!=="localhost"&&t!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function y(){if(typeof window>"u"||pe())return false;try{return window.self!==window.top}catch{return true}}function R(e){return d(e,J)}function B(e){return u(e,J)}async function _(e){let{client:t,adapter:a,network:i,mint:s,amountRaw:n,titleID:c,category:o}=e;if(y())return R("deposit-onchain");let r=t.auth.context?.userID;if(!r)return d("deposit-onchain","Not logged in.");if(n<=0n)return d("deposit-onchain","Amount must be positive.");let p;try{p=await a.depositSpl({mint:s,amountRaw:n,userID:r,titleID:c,category:core.normalizeBlockchainCategory(o)});}catch(g){return d("deposit-onchain",w(g))}let l=await t.blockchain.depositToken(i.NetworkID??"",p);return l.ok?{ok:true,onChainTxHash:p,data:l.data}:d("report",l.error,{onChainTxHash:p})}async function K(e){let{client:t,adapter:a,currencyID:i,networkID:s,walletAddress:n,amount:c,category:o}=e;if(y())return R("request");let r=await t.blockchain.requestTokenWithdrawal(i,s,n,c,o);if(!r.ok)return d("request",r.error);let p=r.data.SolanaSignature,l=r.data.TitleTransactionID??void 0;if(!p)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let g;try{g=await a.submitWithdrawal(p);}catch(b){return d("withdraw-onchain",w(b),{titleTransactionID:l})}if(!l)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:g});let m=await t.blockchain.confirmWithdrawal(l,g);return m.ok?{ok:true,onChainTxHash:g,data:r.data}:d("confirm",m.error,{onChainTxHash:g,titleTransactionID:l})}async function T(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return B("challenge");let n=await t.auth.requestWalletChallenge(i,a);if(!n.ok)return u("challenge",n.error);let c;try{let r=await s(new TextEncoder().encode(n.data.Message));c=Q(r);}catch(r){return u("sign",w(r))}let o=await t.auth.loginWithWallet(i,a,c);return o.ok?{ok:true,data:o.data}:u("login",o.error)}async function O(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return B("challenge");let n=await t.auth.linkWallet(i,a);if(!n.ok)return u("challenge",n.error);if(!n.data.Challenge)return u("challenge","No challenge was issued.");let c;try{let r=await s(new TextEncoder().encode(n.data.Challenge));c=Q(r);}catch(r){return u("sign",w(r))}let o=await t.auth.linkWallet(i,a,c);return o.ok?{ok:true,data:o.data}:u("login",o.error)}function Q(e){let t="0x";for(let a of e)t+=a.toString(16).padStart(2,"0");return t}var X="Wallet not connected.";function me(e,t,a){let{address:i}=react.useAppKitAccount(),{walletProvider:s}=react.useAppKitProvider("solana"),n=i??null,c=s?.signMessage?.bind(s);return {connected:!!n,account:n,loginWithWallet:(o,r)=>{let p=r??n;return p?c?T({client:e,networkID:o,walletAddress:p,signMessage:c}):Promise.resolve(u("sign","The connected wallet does not support message signing.")):Promise.resolve(u("challenge",X))},depositToken:o=>_({client:e,adapter:a,titleID:t,...o}),withdrawToken:o=>{let r=o.walletAddress??n;return r?K({client:e,adapter:a,...o,walletAddress:r}):Promise.resolve(d("request",X))}}}function U(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}var we=18e4,ee=9e4;function ye(e){try{let a=e?.session?.peer?.metadata?.redirect,i=a?.native||a?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function te(e,t){return new Promise((a,i)=>{let s=setTimeout(()=>i(new Error("The wallet request timed out.")),t);e.then(n=>{clearTimeout(s),a(n);},n=>{clearTimeout(s),i(n instanceof Error?n:new Error(String(n)));});})}function Se(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 ke(e){let{client:t,networkID:a,onAuthenticated:i,disabled:s,label:n,style:c,autoStart:o,mode:r="login",onLinked:p}=e,{address:l,isConnected:g}=react.useAppKitAccount(),{walletProvider:m}=react.useAppKitProvider("solana"),[b,S]=react$1.useState(false),[q,f]=react$1.useState(null),[H,P]=react$1.useState(false),[Y,z]=react$1.useState(false),A=react$1.useRef(null),V=react$1.useRef(0),k=react$1.useCallback(()=>{A.current&&clearTimeout(A.current),A.current=null;},[]);react$1.useEffect(()=>k,[k]);let L=react$1.useRef(false),I=react$1.useCallback(async()=>{let W=++V.current,E=()=>V.current===W,v=m?.signMessage?.bind(m);if(!l||!v){f("The connected wallet cannot sign messages."),S(false);return}S(true),f(null);try{if(z(!0),r==="link"){let x=await te(O({client:t,networkID:a,walletAddress:l,signMessage:v}),ee);if(!E())return;if(x.ok){p?.(x.data.PlayAccess??null);return}f(x.stage==="sign"?"Signature declined.":U(x.error,"Could not link the wallet."));return}let h=await te(T({client:t,networkID:a,walletAddress:l,signMessage:v}),ee);if(!E())return;if(h.ok){i();return}f(h.stage==="sign"?"Signature declined.":U(h.error,"Wallet sign-in failed."));}catch(h){if(!E())return;console.error("[idosgames/wallet] solana sign-in failed:",h),f(Se(h));}finally{E()&&(S(false),z(false));}},[l,m,t,a,i,r,p]),ae=react$1.useCallback(()=>{ye(m)||D()?.open();},[m]);react$1.useEffect(()=>{!H||!g||!l||!m||(P(false),k(),I());},[H,g,l,m,I,k]);let j=()=>{if(Y){ae();return}if(f(null),L.current=true,g&&l&&m){I();return}let W=D();if(!W){f("Wallet sign-in is not configured for this title.");return}S(true),P(true),k(),A.current=setTimeout(()=>{P(false),S(false),f("No wallet was connected.");},we),W.open();};return react$1.useEffect(()=>{!o||L.current||(L.current=true,j());},[o]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:j,disabled:s,style:{...Te,...s?{opacity:.6,cursor:"default"}:null,...c},children:Y?"Waiting for signature \u2014 tap to open wallet":b?"Check your wallet\u2026":g?n??(r==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),q&&jsxRuntime.jsx("span",{role:"alert",style:Ae,children:q})]})}var Te={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Ae={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
2
+ exports.SolanaWalletLogin=ke;exports.createSolanaWalletConfig=se;exports.solanaDevnet=re;exports.solanaMainnet=N;exports.useSolanaBridge=me;
@@ -1 +1 @@
1
- import {b,a as a$1,c,d}from'../chunk-QST6UVX7.js';import {a,c as c$2,b as b$2}from'../chunk-UMGI2JW7.js';import {u,b as b$1,c as c$1}from'../chunk-IEWZH6XD.js';export{v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {SolanaAdapter}from'@reown/appkit-adapter-solana';import {createAppKit,useAppKitAccount,useAppKitProvider}from'@reown/appkit/react';import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function ee(e){let{walletConnectProjectId:o,appName:n,appUrl:r,appIcon:a$1,wallets:t}=e,u$1=e.networks??[u],i=r??(typeof window<"u"?window.location.origin:""),s={name:n??"iDosGames",description:n??"iDosGames game",url:i,icons:a$1?[a$1]:[]},l=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[l],networks:u$1,projectId:o,metadata:s,features:{analytics:false,email:false,socials:false}})),l}var F="Wallet not connected.";function oe(e,o,n){let{address:r}=useAppKitAccount(),{walletProvider:a}=useAppKitProvider("solana"),t=r??null,u=a?.signMessage?.bind(a);return {connected:!!t,account:t,loginWithWallet:(i,s)=>{let l=s??t;return l?u?c({client:e,networkID:i,walletAddress:l,signMessage:u}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",F))},depositToken:i=>a$1({client:e,adapter:n,titleID:o,...i}),withdrawToken:i=>{let s=i.walletAddress??t;return s?b({client:e,adapter:n,...i,walletAddress:s}):Promise.resolve(b$1("request",F))}}}var ie=18e4,H=9e4;function se(e){try{let n=e?.session?.peer?.metadata?.redirect,r=n?.native||n?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function J(e,o){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),o);e.then(t=>{clearTimeout(a),n(t);},t=>{clearTimeout(a),r(t instanceof Error?t:new Error(String(t)));});})}function le(e){let o="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.":o:o}function pe(e){let{client:o,networkID:n,onAuthenticated:r,disabled:a,label:t,style:u,autoStart:i,mode:s="login",onLinked:l}=e,{address:c$1,isConnected:w}=useAppKitAccount(),{walletProvider:p}=useAppKitProvider("solana"),[V,g]=useState(false),[E,d$1]=useState(null),[B,W]=useState(false),[L,O]=useState(false),S=useRef(null),M=useRef(0),m=useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null;},[]);useEffect(()=>m,[m]);let h=useRef(false),C=useCallback(async()=>{let k=++M.current,y=()=>M.current===k,v=p?.signMessage?.bind(p);if(!c$1||!v){d$1("The connected wallet cannot sign messages."),g(false);return}g(true),d$1(null);try{if(O(!0),s==="link"){let A=await J(d({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(A.ok){l?.(A.data.PlayAccess??null);return}d$1(A.stage==="sign"?"Signature declined.":c$2(A.error,"Could not link the wallet."));return}let f=await J(c({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(f.ok){r();return}d$1(f.stage==="sign"?"Signature declined.":c$2(f.error,"Wallet sign-in failed."));}catch(f){if(!y())return;console.error("[idosgames/wallet] solana sign-in failed:",f),d$1(le(f));}finally{y()&&(g(false),O(false));}},[c$1,p,o,n,r,s,l]),X=useCallback(()=>{se(p)||b$2()?.open();},[p]);useEffect(()=>{!B||!w||!c$1||!p||(W(false),m(),C());},[B,w,c$1,p,C,m]);let G=()=>{if(L){X();return}if(d$1(null),h.current=true,w&&c$1&&p){C();return}let k=b$2();if(!k){d$1("Wallet sign-in is not configured for this title.");return}g(true),W(true),m(),S.current=setTimeout(()=>{W(false),g(false),d$1("No wallet was connected.");},ie),k.open();};return useEffect(()=>{!i||h.current||(h.current=true,G());},[i]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:G,disabled:a,style:{...de,...a?{opacity:.6,cursor:"default"}:null,...u},children:L?"Waiting for signature \u2014 tap to open wallet":V?"Check your wallet\u2026":w?t??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),E&&jsx("span",{role:"alert",style:ce,children:E})]})}var de={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ce={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{pe as SolanaWalletLogin,ee as createSolanaWalletConfig,oe as useSolanaBridge};
1
+ import {b,a as a$1,c,d}from'../chunk-MLIXKTS6.js';import {a,c as c$2,b as b$2}from'../chunk-UMGI2JW7.js';import {v,b as b$1,c as c$1}from'../chunk-K3THMWU2.js';export{w as solanaDevnet,v as solanaMainnet}from'../chunk-K3THMWU2.js';import {SolanaAdapter}from'@reown/appkit-adapter-solana';import {createAppKit,useAppKitAccount,useAppKitProvider}from'@reown/appkit/react';import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function ee(e){let{walletConnectProjectId:o,appName:n,appUrl:r,appIcon:a$1,wallets:t}=e,u=e.networks??[v],i=r??(typeof window<"u"?window.location.origin:""),s={name:n??"iDosGames",description:n??"iDosGames game",url:i,icons:a$1?[a$1]:[]},l=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[l],networks:u,projectId:o,metadata:s,features:{analytics:false,email:false,socials:false}})),l}var F="Wallet not connected.";function oe(e,o,n){let{address:r}=useAppKitAccount(),{walletProvider:a}=useAppKitProvider("solana"),t=r??null,u=a?.signMessage?.bind(a);return {connected:!!t,account:t,loginWithWallet:(i,s)=>{let l=s??t;return l?u?c({client:e,networkID:i,walletAddress:l,signMessage:u}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",F))},depositToken:i=>a$1({client:e,adapter:n,titleID:o,...i}),withdrawToken:i=>{let s=i.walletAddress??t;return s?b({client:e,adapter:n,...i,walletAddress:s}):Promise.resolve(b$1("request",F))}}}var ie=18e4,H=9e4;function se(e){try{let n=e?.session?.peer?.metadata?.redirect,r=n?.native||n?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function J(e,o){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),o);e.then(t=>{clearTimeout(a),n(t);},t=>{clearTimeout(a),r(t instanceof Error?t:new Error(String(t)));});})}function le(e){let o="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.":o:o}function pe(e){let{client:o,networkID:n,onAuthenticated:r,disabled:a,label:t,style:u,autoStart:i,mode:s="login",onLinked:l}=e,{address:c$1,isConnected:w}=useAppKitAccount(),{walletProvider:p}=useAppKitProvider("solana"),[V,g]=useState(false),[E,d$1]=useState(null),[B,W]=useState(false),[L,O]=useState(false),S=useRef(null),M=useRef(0),m=useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null;},[]);useEffect(()=>m,[m]);let h=useRef(false),C=useCallback(async()=>{let k=++M.current,y=()=>M.current===k,v=p?.signMessage?.bind(p);if(!c$1||!v){d$1("The connected wallet cannot sign messages."),g(false);return}g(true),d$1(null);try{if(O(!0),s==="link"){let A=await J(d({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(A.ok){l?.(A.data.PlayAccess??null);return}d$1(A.stage==="sign"?"Signature declined.":c$2(A.error,"Could not link the wallet."));return}let f=await J(c({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(f.ok){r();return}d$1(f.stage==="sign"?"Signature declined.":c$2(f.error,"Wallet sign-in failed."));}catch(f){if(!y())return;console.error("[idosgames/wallet] solana sign-in failed:",f),d$1(le(f));}finally{y()&&(g(false),O(false));}},[c$1,p,o,n,r,s,l]),X=useCallback(()=>{se(p)||b$2()?.open();},[p]);useEffect(()=>{!B||!w||!c$1||!p||(W(false),m(),C());},[B,w,c$1,p,C,m]);let G=()=>{if(L){X();return}if(d$1(null),h.current=true,w&&c$1&&p){C();return}let k=b$2();if(!k){d$1("Wallet sign-in is not configured for this title.");return}g(true),W(true),m(),S.current=setTimeout(()=>{W(false),g(false),d$1("No wallet was connected.");},ie),k.open();};return useEffect(()=>{!i||h.current||(h.current=true,G());},[i]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:G,disabled:a,style:{...de,...a?{opacity:.6,cursor:"default"}:null,...u},children:L?"Waiting for signature \u2014 tap to open wallet":V?"Check your wallet\u2026":w?t??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),E&&jsx("span",{role:"alert",style:ce,children:E})]})}var de={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ce={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{pe as SolanaWalletLogin,ee as createSolanaWalletConfig,oe as useSolanaBridge};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/wallet",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
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",
@@ -1,2 +0,0 @@
1
- import {BaseError}from'viem';import {PLATFORM_ORIGINS}from'@idosgames/core';function x(e){return e instanceof BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function a(e,t,n){return {ok:false,stage:e,error:t,...n}}function r(e,t){return {ok:false,stage:e,error:t}}var o="WALLET_USE_SITE_PANEL";function k(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function L(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function C(e){return a(e,o)}function v(e){return r(e,o)}var l=PLATFORM_ORIGINS;function B(e){if(typeof window>"u")return ()=>{};let t=n=>{l.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&e();};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)}var p={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"}}},c={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"}}},u={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"}}},d={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"}}},m={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"}}},g={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"}}},h={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"}}},f={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"}}},y={mainnet:p,bsc:c,polygon:u,base:d,arbitrum:m,optimism:g,sepolia:h,polygonAmoy:f};function T(e){return Object.values(y).find(t=>t.id===e)}function A(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var F={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"},W={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"};
2
- export{x as a,a as b,r as c,o as d,k as e,L as f,C as g,v as h,B as i,p as j,c as k,u as l,d as m,m as n,g as o,h as p,f as q,y as r,T as s,A as t,F as u,W as v};
@@ -1 +0,0 @@
1
- import {e,g,b,a,h,c}from'./chunk-IEWZH6XD.js';import {normalizeBlockchainCategory}from'@idosgames/core';async function T(i){let{client:t,adapter:n,network:s,mint:d,amountRaw:a$1,titleID:l,category:r}=i;if(e())return g("deposit-onchain");let e$1=t.auth.context?.userID;if(!e$1)return b("deposit-onchain","Not logged in.");if(a$1<=0n)return b("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:d,amountRaw:a$1,userID:e$1,titleID:l,category:normalizeBlockchainCategory(r)});}catch(m){return b("deposit-onchain",a(m))}let c=await t.blockchain.depositToken(s.NetworkID??"",u);return c.ok?{ok:true,onChainTxHash:u,data:c.data}:b("report",c.error,{onChainTxHash:u})}async function D(i){let{client:t,adapter:n,currencyID:s,networkID:d,walletAddress:a$1,amount:l,category:r}=i;if(e())return g("request");let e$1=await t.blockchain.requestTokenWithdrawal(s,d,a$1,l,r);if(!e$1.ok)return b("request",e$1.error);let u=e$1.data.SolanaSignature,c=e$1.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no Solana signature.",{titleTransactionID:c});let m;try{m=await n.submitWithdrawal(u);}catch(W){return b("withdraw-onchain",a(W),{titleTransactionID:c})}if(!c)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:m});let w=await t.blockchain.confirmWithdrawal(c,m);return w.ok?{ok:true,onChainTxHash:m,data:e$1.data}:b("confirm",w.error,{onChainTxHash:m,titleTransactionID:c})}async function x(i){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i;if(e())return h("challenge");let a$1=await t.auth.requestWalletChallenge(s,n);if(!a$1.ok)return c("challenge",a$1.error);let l;try{let e=await d(new TextEncoder().encode(a$1.data.Message));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.loginWithWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}async function I(i){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i;if(e())return h("challenge");let a$1=await t.auth.linkWallet(s,n);if(!a$1.ok)return c("challenge",a$1.error);if(!a$1.data.Challenge)return c("challenge","No challenge was issued.");let l;try{let e=await d(new TextEncoder().encode(a$1.data.Challenge));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.linkWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}function S(i){let t="0x";for(let n of i)t+=n.toString(16).padStart(2,"0");return t}export{T as a,D as b,x as c,I as d};