@idosgames/wallet 0.5.0 → 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.
- package/dist/chunk-K3THMWU2.js +2 -0
- package/dist/chunk-MLIXKTS6.js +1 -0
- package/dist/{chunk-3VONNSCN.js → chunk-Q2E7DE4S.js} +1 -1
- package/dist/chunk-UMGI2JW7.js +1 -0
- package/dist/{chunk-FFBRTCQK.js → chunk-YTTVLBAW.js} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.js +1 -1
- package/dist/react/lazyIndex.cjs +2 -2
- package/dist/react/lazyIndex.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -2
- package/dist/react/solanaIndex.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-IEWZH6XD.js +0 -2
- package/dist/chunk-QST6UVX7.js +0 -1
- package/dist/chunk-ZL42KPPC.js +0 -1
|
@@ -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-
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=null;function n(e){t=e;}function r(){return t}function s(e,a){switch(e){case null:case void 0:case "":return a;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}}export{n as a,r as b,s as c};
|
|
@@ -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=
|
|
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-
|
|
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';
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var Y={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},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"}}},Ae={mainnet:Y,bsc:Q,polygon:Z,base:J,arbitrum:X,optimism:ee,sepolia:te,polygonAmoy:ne};function Ze(e){return Object.values(Ae).find(t=>t.id===e)}function xe(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var De=null;function Pe(e){De=e;}function ce(){return De}var We=[Y,Q,Z,J,X,ee,te,ne],de=new Map;function pe(e){let{chains:t=We,walletConnectProjectId:n,appName:r,appUrl:i,appIcon:o,transports:d,connectors:a}=e,s=n??"__extension_only__";if(!a){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=i??(typeof window<"u"?window.location.origin:""),m={name:r??"iDosGames",description:r??"iDosGames game",url:c,icons:o?[o]:[]};if(n&&!a){let y=t.map(xe),T=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:u});return Pe(react.createAppKit({adapters:[T],networks:y,projectId:n,metadata:m,features:{analytics:false,email:false,socials:false}})),de.set(s,T.wagmiConfig),T.wagmiConfig}let f=a??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})],b=wagmi.createConfig({chains:t,connectors:f,transports:u});return a||de.set(s,b),b}function U(e){let{wagmiConfig:t,queryClient:n,children:r}=e,[i]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,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"}]}],Te=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];function Se(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:i}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:i,chain:n.chain,value:t.value});if((await 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 Be="WALLET_USE_SITE_PANEL";function P(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function H(e){return p(e,Be)}function me(e){return A(e,Be)}function Re(e){let t=e.RewardPoolAddress;return t||null}async function Le(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:i,amount:o,titleID:d,category:a}=e;if(P())return H("approve");let s=t.auth.context?.userID;if(!s)return p("approve","Not logged in.");let u=Re(r);if(!u)return p("approve","Network has no RewardPoolAddress.");if(o<=0n)return p("approve","Amount must be positive.");try{await Le(n,i,u,o);}catch(f){return p("approve",D(f))}let c;try{c=await B(n,{address:u,abi:re,functionName:"depositERC20",args:[i,o,s,d,a??""]});}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:i,tokenId:o,amount:d,titleID:a,category:s}=e;if(P())return H("deposit-onchain");let u=t.auth.context?.userID;if(!u)return p("deposit-onchain","Not logged in.");let c=Re(r);if(!c)return p("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return p("deposit-onchain","Amount must be positive.");let m=Se(u,a,s),f;try{f=await B(n,{address:i,abi:Te,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 Fe(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function He(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"),Fe(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:Ne,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),Fe(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:i,walletAddress:o,amount:d,category:a}=e;if(P())return H("request");let s=await t.blockchain.requestTokenWithdrawal(r,i,o,d,a);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 Oe(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:i,walletAddress:o,amount:d,category:a}=e;if(P())return H("request");let s=await t.blockchain.requestNFTWithdrawal(r,i,o,d,a);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 Oe(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function Oe(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 K(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let i=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(i,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 a=await t.auth.loginWithWallet(i,r,d);return a.ok?{ok:true,data:a.data}:A("login",a.error)}async function he(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let i=e.walletAddress??n.account,o=await t.auth.linkWallet(i,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 a=await t.auth.linkWallet(i,r,d);return a.ok?{ok:true,data:a.data}:A("login",a.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 _="Wallet not connected.";function Ce(e,t){let n=oe();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,i)=>n?K({client:e,clients:n,networkID:r,walletAddress:i}):Promise.resolve(A("challenge",_)),depositToken:r=>n?fe({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("approve",_)),depositNft:r=>n?ge({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("deposit-onchain",_)),withdrawToken:r=>n?ye({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",_)),withdrawNft:r=>n?we({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",_))}}function bt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(U,{wagmiConfig:t,children:jsxRuntime.jsx(je,{...n})})}function vt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function kt(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 Et(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,i=a=>{r||(r=true,o(),clearTimeout(d),n(a));},o=actions.watchAccount(e,{onChange:a=>{a.isConnected&&i(true);}}),d=setTimeout(()=>i(false),t);})}function At(e,t=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(e).status)?new Promise(r=>{let i=false,o=()=>{i||(i=true,d(),clearTimeout(a),r());},d=actions.watchAccount(e,{onChange:s=>{n(s.status)||o();}}),a=setTimeout(o,t);}):Promise.resolve()}function xt(e){let t=i=>e.find(o=>o.id===i||o.type===i),n=t("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:t("walletConnect")??n??e[0]}var Ke=9e4;async function Dt(e){try{let r=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=r?.native||r?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function _e(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>r(new Error("The wallet request timed out.")),t);e.then(o=>{clearTimeout(i),n(o);},o=>{clearTimeout(i),r(o instanceof Error?o:new Error(String(o)));});})}function je(e){let{client:t,networkID:n,onAuthenticated:r,disabled:i,label:o,style:d,autoStart:a,mode:s="login",onLinked:u}=e,c=wagmi.useConfig(),{isConnected:m}=wagmi.useAccount(),{connectAsync:f,connectors:b}=wagmi.useConnect(),y=oe(),[T,x]=react$1.useState(false),[M,w]=react$1.useState(null),[O,L]=react$1.useState(false),j=react$1.useRef(0),S=react$1.useRef(false),W=async()=>{let I=++j.current,E=()=>j.current===I;x(true),w(null);try{if(await At(c),!E())return;if(!actions.getAccount(c).isConnected){let v=ce();if(v){if(await v.open(),!await Et(c)){w("No wallet was connected.");return}}else {let $=xt(b);if(!$){w("No wallet connector is configured.");return}try{await f({connector:$});}catch(G){if(!vt(G))throw G}}}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 _e(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.":v.error??"Could not link the wallet.");return}let V=await _e(K({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(V.ok){r();return}w(V.stage==="sign"?"Signature declined.":V.error??"Wallet sign-in failed.");}catch(h){if(!E())return;console.error("[idosgames/wallet] wallet sign-in failed:",h),w(kt(h));}finally{E()&&(x(false),L(false));}};react$1.useEffect(()=>{!a||S.current||(S.current=true,W());},[a]);let z=async()=>{await Dt(c)||await ce()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{O?z():W();},disabled:i,style:{...Pt,...i?{opacity:.6,cursor:"default"}:null,...d},children:O?"Waiting for signature \u2014 tap to open wallet":T?"Check your wallet\u2026":m?o??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),M&&jsxRuntime.jsx("span",{role:"alert",style:Wt,children:M})]})}var Pt={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Wt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Ht={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},ve={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},Ot={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},ae={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},ke={display:"flex",gap:8};function Gt(e){let{client:t,walletConnectProjectId:n,appName:r,onClose:i,style:o}=e,[d,a]=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&&a(m);})(),()=>{u=false;}},[t,n]);let s=react$1.useMemo(()=>pe({walletConnectProjectId:d||void 0,appName:r}),[d,r]);return jsxRuntime.jsx(U,{wagmiConfig:s,children:jsxRuntime.jsx(Ut,{client:t,appName:r,onClose:i,style:o})})}function Ut({client:e,onClose:t,style:n}){let r=Ce(e,e.titleID),{address:i,isConnected:o,chainId:d}=wagmi.useAccount(),{connect:a,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,T]=react$1.useState({}),[x,M]=react$1.useState(""),[w,O]=react$1.useState(""),[L,j]=react$1.useState(""),[S,W]=react$1.useState(false),[z,I]=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[Qe,Ee]of Object.entries(F))Ee.Type==="EVM"&&(le[Qe]=Ee);b(le),T(C.data.CryptoCurrencies??{});let Ye=Object.keys(le)[0]??"";M(Ye);})(),()=>{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]??"";O(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),$=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function G(){if(!h?.ChainID||d===h.ChainID)return true;try{return await c({chainId:h.ChainID}),!0}catch{return I({ok:false,stage:"approve",error:`Switch your wallet to chain ${h.ChainID} to continue.`}),false}}async function Ve(){if(!(!h||!v?.ContractAddress)){if(W(true),I(null),await G()){let l=v.Decimals??18,C;try{C=viem.parseUnits(L||"0",l);}catch{I({ok:false,stage:"approve",error:"Invalid amount."}),W(false);return}let F=await r.depositToken({network:h,tokenAddress:v.ContractAddress,amount:C});I(F),F.ok&&await e.blockchain.getUserState();}W(false);}}async function $e(){if(!(!h||!r.account)){if(W(true),I(null),await G()){let l=await r.withdrawToken({currencyID:w,networkID:x,walletAddress:r.account,amount:L||"0"});I(l),l.ok&&await e.blockchain.getUserState();}W(false);}}return jsxRuntime.jsxs("div",{style:{...Ht,...n},children:[jsxRuntime.jsxs("div",{style:{...ke,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Mt,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:ae,onClick:t,children:"\u2715"})]}),o?jsxRuntime.jsxs("div",{style:ke,children:[jsxRuntime.jsxs("span",{style:{...R,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:ae,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:ae,onClick:()=>a({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:ve,value:x,onChange:l=>M(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:ve,value:w,onChange:l=>O(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:$})," ",w]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Amount"}),jsxRuntime.jsx("input",{style:ve,inputMode:"decimal",placeholder:"0.0",value:L,onChange:l=>j(l.target.value)})]}),jsxRuntime.jsxs("div",{style:ke,children:[jsxRuntime.jsx("button",{type:"button",style:{...Ot,flex:1,opacity:S?.6:1},disabled:S||!o||!v?.ContractAddress,onClick:()=>{Ve();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...ae,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=We;exports.IDosGamesWalletProvider=
|
|
1
|
+
'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var $={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;
|
package/dist/react/index.js
CHANGED
|
@@ -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}from'../chunk-ZL42KPPC.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 ve=[j$1,k,l,m,n,o,p,q$1],re=new Map;function ie(e){let{chains:n=ve,walletConnectProjectId:t$1,appName:o,appUrl:i,appIcon:s,transports:y,connectors:l}=e,w=t$1??"__extension_only__";if(!l){let f=re.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}})),re.set(w,S.wagmiConfig),S.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:o??"iDosGames"})],I=createConfig({chains:n,connectors:D,transports:v});return l||re.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 se(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 Ze(e){let{wagmiConfig:n,...t}=e;return jsx(G,{wagmiConfig:n,children:jsx(Se,{...t})})}function et(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function tt(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 ke(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 nt(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 ot(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 rt(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 Pe=9e4;async function it(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 We(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 Se(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 ot(p),!C())return;if(!getAccount(p).isConnected){let m=b$1();if(m){if(await m.open(),!await nt(p)){c("No wallet was connected.");return}}else {let M=rt(I);if(!M){c("No wallet connector is configured.");return}try{await D({connector:M});}catch(B){if(!et(B))throw B}}}let d=f??await ke(p);if(!d&&getAccount(p).isConnected&&(await new Promise(m=>setTimeout(m,300)),d=await ke(p),!C()))return;if(!d){c("Wallet client is not available.");return}if(T(!0),w==="link"){let m=await We(r({client:n,clients:d,networkID:t}),Pe);if(!C())return;if(m.ok){v?.(m.data.PlayAccess??null);return}c(m.stage==="sign"?"Signature declined.":m.error??"Could not link the wallet.");return}let U=await We(q$2({client:n,clients:d,networkID:t}),Pe);if(!C())return;if(U.ok){o();return}c(U.stage==="sign"?"Signature declined.":U.error??"Wallet sign-in failed.");}catch(d){if(!C())return;console.error("[idosgames/wallet] wallet sign-in failed:",d),c(tt(d));}finally{C()&&(h(false),T(false));}};useEffect(()=>{!l||N.current||(N.current=true,k());},[l]);let _=async()=>{await it(p)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{R?_():k();},disabled:i,style:{...st,...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:at,children:A})]})}var st={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},at={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var yt={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"},wt={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},le={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},Ct={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"},ce={display:"flex",gap:8};function vt(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(()=>ie({walletConnectProjectId:y||void 0,appName:o}),[y,o]);return jsx(G,{wagmiConfig:w,children:jsx(ht,{client:n,appName:o,onClose:i,style:s})})}function ht({client:e,onClose:n,style:t}){let o=se(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[xe,de]of Object.entries(x))de.Type==="EVM"&&(V[xe]=de);I(V),S(u.data.CryptoCurrencies??{});let Te=Object.keys(V)[0]??"";A(Te);})(),()=>{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 Ee(){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 Ie(){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:{...yt,...t},children:[jsxs("div",{style:{...ce,justifyContent:"space-between"},children:[jsx("span",{style:wt,children:"Crypto wallet"}),n&&jsx("button",{type:"button",style:H,onClick:n,children:"\u2715"})]}),s?jsxs("div",{style:ce,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:le,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:le,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:le,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:ce,children:[jsx("button",{type:"button",style:{...Ct,flex:1,opacity:N?.6:1},disabled:N||!s||!m?.ContractAddress,onClick:()=>{Ee();},children:"Deposit"}),jsx("button",{type:"button",style:{...H,flex:1,opacity:N?.6:1},disabled:N||!s||!c,onClick:()=>{Ie();},children:"Withdraw"})]})]}),_&&jsx(bt,{result:_})]})}function bt({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{ve as DEFAULT_EVM_CHAINS,G as IDosGamesWalletProvider,Ze as WalletLogin,Se as WalletLoginButton,vt as WalletPanel,ie as createEvmWalletConfig,se 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};
|
package/dist/react/lazyIndex.cjs
CHANGED
|
@@ -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 pn=Object.defineProperty;var k=(e,t)=>()=>(e&&(t=e(e=0)),t);var at=(e,t)=>{for(var n in t)pn(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 A(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function st(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function H(e){return m(e,it)}function Z(e){return w(e,it)}var it,j=k(()=>{M();it="WALLET_USE_SITE_PANEL";});function Ie(e){return Object.values(exports.idosChains).find(t=>t.id===e)}function mt(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 ke(e){ft=e;}function se(){return ft}var ft,ue=k(()=>{ft=null;});function Ce(e){let{chains:t=Le,walletConnectProjectId:n,appName:o,appUrl:r,appIcon:a,transports:c,connectors:s}=e,i=n??"__extension_only__";if(!s){let y=Ne.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:""),p={name:o??"iDosGames",description:o??"iDosGames game",url:l,icons:a?[a]:[]};if(n&&!s){let y=t.map(mt),C=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:d});return ke(react$1.createAppKit({adapters:[C],networks:y,projectId:n,metadata:p,features:{analytics:false,email:false,socials:false}})),Ne.set(i,C.wagmiConfig),C.wagmiConfig}let u=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],h=wagmi.createConfig({chains:t,connectors:u,transports:d});return s||Ne.set(i,h),h}var Le,Ne,Re=k(()=>{ie();ue();Le=[exports.mainnet,exports.bsc,exports.polygon,exports.base,exports.arbitrum,exports.optimism,exports.sepolia,exports.polygonAmoy],Ne=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 be=k(()=>{});var ve,yt,Be,wt,Me=k(()=>{ve=[{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:[]}],yt=[{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:[]}],Be=[{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"}]}],wt=[{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 ht(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}var kt=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 Fe=k(()=>{});function Ct(e){let t=e.RewardPoolAddress;return t||null}async function bt(e,t,n,o){return await e.publicClient.readContract({address:t,abi:Be,functionName:"allowance",args:[e.account,n]})>=o?null:V(e,{address:t,abi:Be,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(A())return H("approve");let i=t.auth.context?.userID;if(!i)return m("approve","Not logged in.");let d=Ct(o);if(!d)return m("approve","Network has no RewardPoolAddress.");if(a<=0n)return m("approve","Amount must be positive.");try{await bt(n,r,d,a);}catch(u){return m("approve",E(u))}let l;try{l=await V(n,{address:d,abi:ve,functionName:"depositERC20",args:[r,a,i,c,s??""]});}catch(u){return m("deposit-onchain",E(u))}let p=await t.blockchain.depositToken(o.NetworkID??"",l);return p.ok?{ok:true,onChainTxHash:l,data:p.data}:m("report",p.error,{onChainTxHash:l})}async function _e(e){let{client:t,clients:n,network:o,nftContractAddress:r,tokenId:a,amount:c,titleID:s,category:i}=e;if(A())return H("deposit-onchain");let d=t.auth.context?.userID;if(!d)return m("deposit-onchain","Not logged in.");let l=Ct(o);if(!l)return m("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return m("deposit-onchain","Amount must be positive.");let p=ht(d,s,i),u;try{u=await V(n,{address:r,abi:wt,functionName:"safeTransferFrom",args:[n.account,l,a,c,p]});}catch(y){return m("deposit-onchain",E(y))}let h=await t.blockchain.depositNFT(o.NetworkID??"",u);return h.ok?{ok:true,onChainTxHash:u,data:h.data}:m("report",h.error,{onChainTxHash:u})}var vt=k(()=>{Me();kt();Fe();M();j();});function Wt(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function Pt(e,t){return V(e,{address:t.ContractAddress,abi:ve,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),Wt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function At(e,t){return V(e,{address:t.ContractAddress,abi:yt,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),Wt(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Ge(e){let{client:t,clients:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(A())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 p;try{p=await Pt(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let u=await St(t,l,p);return u.ok?{ok:true,onChainTxHash:p,data:i.data}:u}async function He(e){let{client:t,clients:n,itemID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(A())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 p;try{p=await At(n,d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}let u=await St(t,l,p);return u.ok?{ok:true,onChainTxHash:p,data:i.data}:u}async function St(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 Et=k(()=>{Me();Fe();M();j();});async function me(e){let{client:t,clients:n,networkID:o}=e;if(A())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(A())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 Tt=k(()=>{M();j();});var Ue=k(()=>{vt();Et();Tt();});function ge(){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=ge();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,r)=>n?me({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?_e({client:e,clients:n,titleID:t,...o}):Promise.resolve(m("deposit-onchain",fe)),withdrawToken:o=>n?Ge({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",fe)),withdrawNft:o=>n?He({client:e,clients:n,...o}):Promise.resolve(m("withdraw-onchain",fe))}}var fe,Pe=k(()=>{Ue();M();fe="Wallet not connected.";});function Rt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(le,{wagmiConfig:t,children:jsxRuntime.jsx(ze,{...n})})}function _n(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Gn(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 It(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 Hn(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 Kn(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 Un(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 qn(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 Nt(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 ze(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:p}=wagmi.useAccount(),{connectAsync:u,connectors:h}=wagmi.useConnect(),y=ge(),[C,g]=react.useState(false),[R,b]=react.useState(null),[K,O]=react.useState(false),_=react.useRef(0),B=react.useRef(false),T=async()=>{let D=++_.current,x=()=>_.current===D;g(true),b(null);try{if(await Kn(l),!x())return;if(!actions.getAccount(l).isConnected){let P=se();if(P){if(await P.open(),!await Hn(l)){b("No wallet was connected.");return}}else {let q=Un(h);if(!q){b("No wallet connector is configured.");return}try{await u({connector:q});}catch(N){if(!_n(N))throw N}}}let W=y??await It(l);if(!W&&actions.getAccount(l).isConnected&&(await new Promise(P=>setTimeout(P,300)),W=await It(l),!x()))return;if(!W){b("Wallet client is not available.");return}if(O(!0),i==="link"){let P=await Nt(Ke({client:t,clients:W,networkID:n}),Dt);if(!x())return;if(P.ok){d?.(P.data.PlayAccess??null);return}b(P.stage==="sign"?"Signature declined.":P.error??"Could not link the wallet.");return}let G=await Nt(me({client:t,clients:W,networkID:n}),Dt);if(!x())return;if(G.ok){o();return}b(G.stage==="sign"?"Signature declined.":G.error??"Wallet sign-in failed.");}catch(W){if(!x())return;console.error("[idosgames/wallet] wallet sign-in failed:",W),b(Gn(W));}finally{x()&&(g(false),O(false));}};react.useEffect(()=>{!s||B.current||(B.current=true,T());},[s]);let U=async()=>{await qn(l)||await se()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{K?U():T();},disabled:r,style:{...zn,...r?{opacity:.6,cursor:"default"}:null,...c},children:K?"Waiting for signature \u2014 tap to open wallet":C?"Check your wallet\u2026":p?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),R&&jsxRuntime.jsx("span",{role:"alert",style:jn,children:R})]})}var Dt,zn,jn,Bt=k(()=>{ue();Ue();be();Pe();Dt=9e4;zn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},jn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});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 p=l.data.Blockchain?.WalletLogin?.WalletConnectProjectId;p&&s(p);})(),()=>{d=false;}},[t,n]);let i=react.useMemo(()=>Ce({walletConnectProjectId:c||void 0,appName:o}),[c,o]);return jsxRuntime.jsx(le,{wagmiConfig:i,children:jsxRuntime.jsx(ro,{client:t,appName:o,onClose:r,style:a})})}function ro({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(),[,p]=react.useReducer(f=>f+1,0),[u,h]=react.useState({}),[y,C]=react.useState({}),[g,R]=react.useState(""),[b,K]=react.useState(""),[O,_]=react.useState(""),[B,T]=react.useState(false),[U,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 Y=S.data.Blockchain?.Networks??{},xe={};for(let[dn,rt]of Object.entries(Y))rt.Type==="EVM"&&(xe[dn]=rt);h(xe),C(S.data.CryptoCurrencies??{});let cn=Object.keys(xe)[0]??"";R(cn);})(),()=>{f=false;}},[e]),react.useEffect(()=>e.on("user:anyUpdated",p),[e]);let x=react.useMemo(()=>Object.entries(y).filter(([,f])=>f.Networks?.some(S=>S.NetworkID===g&&!!S.ContractAddress)),[y,g]);react.useEffect(()=>{let f=x[0]?.[0]??"";K(S=>x.some(([Y])=>Y===S)?S:f);},[x]);let W=g?u[g]:void 0,P=(b?y[b]:void 0)?.Networks?.find(f=>f.NetworkID===g),q=b?e.data.user.getCryptoCurrencyAmount(b):"0";async function N(){if(!W?.ChainID||c===W.ChainID)return true;try{return await l({chainId:W.ChainID}),!0}catch{return D({ok:false,stage:"approve",error:`Switch your wallet to chain ${W.ChainID} to continue.`}),false}}async function Q(){if(!(!W||!P?.ContractAddress)){if(T(true),D(null),await N()){let f=P.Decimals??18,S;try{S=viem.parseUnits(O||"0",f);}catch{D({ok:false,stage:"approve",error:"Invalid amount."}),T(false);return}let Y=await o.depositToken({network:W,tokenAddress:P.ContractAddress,amount:S});D(Y),Y.ok&&await e.blockchain.getUserState();}T(false);}}async function ln(){if(!(!W||!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:{...to,...n},children:[jsxRuntime.jsxs("div",{style:{...Ve,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:no,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:Se,onClick:t,children:"\u2715"})]}),a?jsxRuntime.jsxs("div",{style:Ve,children:[jsxRuntime.jsxs("span",{style:{...$,flex:1,alignSelf:"center"},children:[r?.slice(0,6),"\u2026",r?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:Se,onClick:()=>d(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:$,children:"Connect a browser or mobile wallet"}),i.map(f=>jsxRuntime.jsx("button",{type:"button",style:Se,onClick:()=>s({connector:f}),children:f.name},f.uid))]}),Object.keys(u).length===0?jsxRuntime.jsx("span",{style:$,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:$,children:"Network"}),jsxRuntime.jsx("select",{style:je,value:g,onChange:f=>R(f.target.value),children:Object.entries(u).map(([f,S])=>jsxRuntime.jsx("option",{value:f,children:S.DisplayName??f},f))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:$,children:"Token"}),jsxRuntime.jsxs("select",{style:je,value:b,onChange:f=>K(f.target.value),children:[x.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),x.map(([f,S])=>jsxRuntime.jsx("option",{value:f,children:S.DisplayName??f},f))]})]}),jsxRuntime.jsxs("div",{style:$,children:["In-game balance: ",jsxRuntime.jsx("b",{children:q})," ",b]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:$,children:"Amount"}),jsxRuntime.jsx("input",{style:je,inputMode:"decimal",placeholder:"0.0",value:O,onChange:f=>_(f.target.value)})]}),jsxRuntime.jsxs("div",{style:Ve,children:[jsxRuntime.jsx("button",{type:"button",style:{...oo,flex:1,opacity:B?.6:1},disabled:B||!a||!P?.ContractAddress,onClick:()=>{Q();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...Se,flex:1,opacity:B?.6:1},disabled:B||!a||!b,onClick:()=>{ln();},children:"Withdraw"})]})]}),U&&jsxRuntime.jsx(ao,{result:U})]})}function ao({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 to,no,$,je,oo,Se,Ve,Ot=k(()=>{Re();be();Pe();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",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},no={fontWeight:700,fontSize:16},$={fontSize:12,opacity:.7},je={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},oo={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},Se={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Ve={display:"flex",gap:8};});var $e={};at($e,{DEFAULT_EVM_CHAINS:()=>Le,IDosGamesWalletProvider:()=>le,WalletLogin:()=>Rt,WalletLoginButton:()=>ze,WalletPanel:()=>Ft,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>Ie,createEvmWalletConfig:()=>Ce,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>We,useEvmBridgeClients:()=>ge});var Qe=k(()=>{Re();ie();be();Pe();Bt();Ot();});function _t(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 ke(react$1.createAppKit({adapters:[d],networks:c,projectId:t,metadata:i,features:{analytics:false,email:false,socials:false}})),d}var Gt=k(()=>{ie();ue();});async function Ye(e){let{client:t,adapter:n,network:o,mint:r,amountRaw:a,titleID:c,category:s}=e;if(A())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(p){return m("deposit-onchain",E(p))}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 Ze(e){let{client:t,adapter:n,currencyID:o,networkID:r,walletAddress:a,amount:c,category:s}=e;if(A())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 p;try{p=await n.submitWithdrawal(d);}catch(h){return m("withdraw-onchain",E(h),{titleTransactionID:l})}if(!l)return m("confirm","Missing TitleTransactionID.",{onChainTxHash:p});let u=await t.blockchain.confirmWithdrawal(l,p);return u.ok?{ok:true,onChainTxHash:p,data:i.data}:m("confirm",u.error,{onChainTxHash:p,titleTransactionID:l})}var Ht=k(()=>{M();j();});async function we(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(A())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=Kt(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 Je(e){let{client:t,networkID:n,walletAddress:o,signMessage:r}=e;if(A())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=Kt(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 Kt(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}var Ut=k(()=>{M();j();});var Xe=k(()=>{Ht();Ut();});function zt(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?we({client:e,networkID:s,walletAddress:d,signMessage:c}):Promise.resolve(w("sign","The connected wallet does not support message signing.")):Promise.resolve(w("challenge",qt))},depositToken:s=>Ye({client:e,adapter:n,titleID:t,...s}),withdrawToken:s=>{let i=s.walletAddress??a;return i?Ze({client:e,adapter:n,...s,walletAddress:i}):Promise.resolve(m("request",qt))}}}var qt,jt=k(()=>{Xe();M();qt="Wallet not connected.";});function yo(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 $t(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 wo(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 Yt(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:p}=react$1.useAppKitAccount(),{walletProvider:u}=react$1.useAppKitProvider("solana"),[h,y]=react.useState(false),[C,g]=react.useState(null),[R,b]=react.useState(false),[K,O]=react.useState(false),_=react.useRef(null),B=react.useRef(0),T=react.useCallback(()=>{_.current&&clearTimeout(_.current),_.current=null;},[]);react.useEffect(()=>T,[T]);let U=react.useRef(false),D=react.useCallback(async()=>{let G=++B.current,P=()=>B.current===G,q=u?.signMessage?.bind(u);if(!l||!q){g("The connected wallet cannot sign messages."),y(false);return}y(true),g(null);try{if(O(!0),i==="link"){let Q=await $t(Je({client:t,networkID:n,walletAddress:l,signMessage:q}),Vt);if(!P())return;if(Q.ok){d?.(Q.data.PlayAccess??null);return}g(Q.stage==="sign"?"Signature declined.":Q.error??"Could not link the wallet.");return}let N=await $t(we({client:t,networkID:n,walletAddress:l,signMessage:q}),Vt);if(!P())return;if(N.ok){o();return}g(N.stage==="sign"?"Signature declined.":N.error??"Wallet sign-in failed.");}catch(N){if(!P())return;console.error("[idosgames/wallet] solana sign-in failed:",N),g(wo(N));}finally{P()&&(y(false),O(false));}},[l,u,t,n,o,i,d]),x=react.useCallback(()=>{yo(u)||se()?.open();},[u]);react.useEffect(()=>{!R||!p||!l||!u||(b(false),T(),D());},[R,p,l,u,D,T]);let W=()=>{if(K){x();return}if(g(null),U.current=true,p&&l&&u){D();return}let G=se();if(!G){g("Wallet sign-in is not configured for this title.");return}y(true),b(true),T(),_.current=setTimeout(()=>{b(false),y(false),g("No wallet was connected.");},go),G.open();};return react.useEffect(()=>{!s||U.current||(U.current=true,W());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:W,disabled:r,style:{...ho,...r?{opacity:.6,cursor:"default"}:null,...c},children:K?"Waiting for signature \u2014 tap to open wallet":h?"Check your wallet\u2026":p?a??(i==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:ko,children:C})]})}var go,Vt,ho,ko,Zt=k(()=>{Xe();ue();go=18e4,Vt=9e4;ho={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ko={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var Jt={};at(Jt,{SolanaWalletLogin:()=>Yt,createSolanaWalletConfig:()=>_t,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>zt});var Xt=k(()=>{Gt();jt();Zt();ie();});j();M();var ce={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"},de="PLATFORM_WALLET_UNAVAILABLE",fn=5e3,gn=18e4;function yn(){let e=[...core.PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!e.includes(t)&&core.isPlatformParentOrigin(t)&&e.push(t),e}function wn(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function lt(e,t,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:de});let o=window.parent;if(!o)return Promise.resolve({ok:false,error:de});let r=wn();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 p=l.data;if(!(!p||p.requestId!==r)){if(p.type===ce.ack){clearTimeout(s),s=setTimeout(()=>i({ok:false,error:"TIMEOUT"}),gn);return}p.type===t&&i({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,address:typeof p.address=="string"?p.address:void 0,signature:typeof p.signature=="string"?p.signature:void 0});}};s=setTimeout(()=>i({ok:false,error:de}),fn),window.addEventListener("message",d);for(let l of yn())try{o.postMessage({type:e,requestId:r,...n},l);}catch{}})}async function dt(e){let{client:t,networkID:n}=e;return ut(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 pt(e){let{client:t,networkID:n}=e;return ut(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 ut(e,t,n){let{client:o,family:r}=e,a=o.titleID,c=await lt(ce.addressRequest,ce.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 lt(ce.signRequest,ce.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 tn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},nn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function en(e){switch(e){case de: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 Wo(e){let{client:t,networkID:n,onAuthenticated:o,onLinked:r,mode:a="login",family:c,disabled:s,label:i,style:d}=e,[l,p]=react.useState(false),[u,h]=react.useState(null);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{p(true),h(null),(async()=>{if(a==="link"){let g=await pt({client:t,networkID:n,family:c});if(g.ok){p(false),r?.(g.data.PlayAccess??null);return}h(en(g.error)),p(false);return}let C=await dt({client:t,networkID:n,family:c});if(C.ok){o?.();return}h(en(C.error)),p(false);})();},disabled:s||l,style:{...tn,...s||l?{opacity:.6,cursor:"default"}:null,...d},children:l?"Waiting for the wallet\u2026":i??(a==="link"?"Link wallet":"Sign in with wallet")}),u&&jsxRuntime.jsx("span",{role:"alert",style:nn,children:u})]})}function on(e,t){return st()?null:jsxRuntime.jsx(Wo,{...e,family:t})}function rn(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:{...tn,...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:nn,children:a})]})}function Po(e){let{chains:t,walletConnectProjectId:n,appName:o,disabled:r,label:a,style:c,onAuthenticated:s,...i}=e,[d,l]=react.useState(null),[p,u]=react.useState(false),[h,y]=react.useState(null);if(A())return on(e,"evm");let C=()=>{u(true),y(null),(async()=>{try{let g=await Promise.resolve().then(()=>(Qe(),$e)),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{u(false);}})();};if(d){let{WalletLogin:g}=d.mod;return jsxRuntime.jsx(g,{...i,onAuthenticated:s??an,wagmiConfig:d.config,disabled:r,label:a,style:c,autoStart:true})}return jsxRuntime.jsx(rn,{loading:p,disabled:r,label:a??(e.mode==="link"?"Link wallet":void 0),style:c,error:h,onClick:C})}function an(){}function Ao(e){let{walletConnectProjectId:t,appName:n,disabled:o,label:r,style:a,onAuthenticated:c,...s}=e,[i,d]=react.useState(null),[l,p]=react.useState(false),[u,h]=react.useState(null);if(A())return on(e,"solana");let y=()=>{p(true),h(null),(async()=>{try{let C=await Promise.resolve().then(()=>(Xt(),Jt));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{p(false);}})();};if(i){let{SolanaWalletLogin:C}=i;return jsxRuntime.jsx(C,{...s,onAuthenticated:c??an,disabled:o,label:r,style:a,autoStart:true})}return jsxRuntime.jsx(rn,{loading:l,disabled:o,label:r??(e.mode==="link"?"Link wallet":void 0),style:a,error:u,onClick:y})}var So={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",fontSize:13};function Eo(e){let{onClose:t,style:n}=e,o=A(),[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(()=>(Qe(),$e));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:{...So,...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=
|
|
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;
|
package/dist/react/lazyIndex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {d,c,b}from'../chunk-
|
|
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
|
|
2
|
-
exports.SolanaWalletLogin=
|
|
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-
|
|
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.
|
|
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",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"//": "@idosgames/core не '*': опубликованный пакет обязан назвать диапазон, иначе установка wallet притянет любую версию core, включая будущую ломающую. На 0.x '^' даёт >=0.1.0 <0.2.0 — ровно ту зону, где core обещает совместимость (см. RELEASING.md). Поднимать при мажорном/минорном бампе core.",
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@idosgames/core": "^0.
|
|
73
|
+
"@idosgames/core": "^0.19.0",
|
|
74
74
|
"viem": "^2.55.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
package/dist/chunk-IEWZH6XD.js
DELETED
|
@@ -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};
|
package/dist/chunk-QST6UVX7.js
DELETED
|
@@ -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};
|
package/dist/chunk-ZL42KPPC.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=null;function e(p){t=p;}function i(){return t}export{e as a,i as b};
|