@idosgames/wallet 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -14
- package/dist/chunk-3VONNSCN.js +1 -0
- package/dist/chunk-FFBRTCQK.js +1 -0
- package/dist/chunk-QST6UVX7.js +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +56 -2
- package/dist/index.d.ts +56 -2
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +9 -1
- package/dist/react/index.d.ts +9 -1
- package/dist/react/index.js +1 -1
- package/dist/react/lazyIndex.cjs +2 -2
- package/dist/react/lazyIndex.d.cts +11 -3
- package/dist/react/lazyIndex.d.ts +11 -3
- package/dist/react/lazyIndex.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -2
- package/dist/react/solanaIndex.d.cts +9 -1
- package/dist/react/solanaIndex.d.ts +9 -1
- package/dist/react/solanaIndex.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-2PEE5F3U.js +0 -1
- package/dist/chunk-RTP7IL25.js +0 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { b as arbitrum, c as base, d as bsc, e as chainById, i as idosChains, m
|
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode, CSSProperties } from 'react';
|
|
6
6
|
import { QueryClient } from '@tanstack/react-query';
|
|
7
|
-
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
7
|
+
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
8
8
|
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, d as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-BKVcklPB.js';
|
|
9
9
|
import { W as WalletLoginResult, B as BridgeResult } from '../types-CeUVf1tr.js';
|
|
10
10
|
|
|
@@ -126,6 +126,14 @@ interface WalletLoginProps {
|
|
|
126
126
|
* which already consumed the player's click to load this module — a second tap would be a bug.
|
|
127
127
|
*/
|
|
128
128
|
autoStart?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* `"login"` (default) — sign in. `"link"` — attach the wallet to the LOGGED-IN account by
|
|
131
|
+
* signature (play-access screen of a gated title); `onLinked` then receives the pass checked
|
|
132
|
+
* against this wallet, and `onAuthenticated` is not called.
|
|
133
|
+
*/
|
|
134
|
+
mode?: "login" | "link";
|
|
135
|
+
/** Link mode: the pass checked against the linked wallet (null on an Open title). */
|
|
136
|
+
onLinked?: (playAccess: PlayAccessStatus | null) => void;
|
|
129
137
|
}
|
|
130
138
|
/**
|
|
131
139
|
* Ready-made "sign in with wallet" button: connect → sign the challenge → session.
|
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$1}from'../chunk-RTP7IL25.js';import {a,b as b$1}from'../chunk-ZL42KPPC.js';import {j as j$1,k,l,m,n,o,p,q,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 we=[j$1,k,l,m,n,o,p,q],oe=new Map;function ne(e){let{chains:o=we,walletConnectProjectId:t$1,appName:n,appUrl:i,appIcon:s,transports:g,connectors:l}=e,c=t$1??"__extension_only__";if(!l){let p=oe.get(c);if(p)return p}let C={};for(let p of o)C[p.id]=g?.[p.id]??http();let h=i??(typeof window<"u"?window.location.origin:""),b={name:n??"iDosGames",description:n??"iDosGames game",url:h,icons:s?[s]:[]};if(t$1&&!l){let p=o.map(t),k=new WagmiAdapter({networks:p,projectId:t$1,transports:C});return a(createAppKit({adapters:[k],networks:p,projectId:t$1,metadata:b,features:{analytics:false,email:false,socials:false}})),oe.set(c,k.wagmiConfig),k.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:n??"iDosGames"})],I=createConfig({chains:o,connectors:D,transports:C});return l||oe.set(c,I),I}function j(e){let{wagmiConfig:o,queryClient:t,children:n}=e,[i]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:o,children:jsx(QueryClientProvider,{client:i,children:n})})}function U(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var L="Wallet not connected.";function re(e,o){let t=U();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,i)=>t?q$1({client:e,clients:t,networkID:n,walletAddress:i}):Promise.resolve(c("challenge",L)),depositToken:n=>t?h({client:e,clients:t,titleID:o,...n}):Promise.resolve(b("approve",L)),depositNft:n=>t?j$2({client:e,clients:t,titleID:o,...n}):Promise.resolve(b("deposit-onchain",L)),withdrawToken:n=>t?o$1({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",L)),withdrawNft:n=>t?p$1({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",L))}}function Je(e){let{wagmiConfig:o,...t}=e;return jsx(j,{wagmiConfig:o,children:jsx(ke,{...t})})}function Xe(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Ye(e){let o="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":o:o}async function he(e){let o=await getWalletClient(e).catch(()=>null);if(!o)return null;let t=getPublicClient(e);return t?{account:o.account.address,publicClient:t,walletClient:o}:null}function Ze(e,o=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let n=false,i=l=>{n||(n=true,s(),clearTimeout(g),t(l));},s=watchAccount(e,{onChange:l=>{l.isConnected&&i(true);}}),g=setTimeout(()=>i(false),o);})}function et(e,o=8e3){let t=n=>n==="reconnecting"||n==="connecting";return t(getAccount(e).status)?new Promise(n=>{let i=false,s=()=>{i||(i=true,g(),clearTimeout(l),n());},g=watchAccount(e,{onChange:c=>{t(c.status)||s();}}),l=setTimeout(s,o);}):Promise.resolve()}function tt(e){let o=i=>e.find(s=>s.id===i||s.type===i),t=o("injected"),n=typeof window<"u"&&window.ethereum!=null;return t&&n?t:o("walletConnect")??t??e[0]}var ot=9e4;async function nt(e){try{let n=(await getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=n?.native||n?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function rt(e,o){return new Promise((t,n)=>{let i=setTimeout(()=>n(new Error("The wallet request timed out.")),o);e.then(s=>{clearTimeout(i),t(s);},s=>{clearTimeout(i),n(s instanceof Error?s:new Error(String(s)));});})}function ke(e){let{client:o,networkID:t,onAuthenticated:n,disabled:i,label:s,style:g,autoStart:l}=e,c=useConfig(),{isConnected:C}=useAccount(),{connectAsync:h,connectors:b}=useConnect(),D=U(),[I,p]=useState(false),[k,u]=useState(null),[A,w]=useState(false),B=useRef(0),T=useRef(false),F=async()=>{let S=++B.current,P=()=>B.current===S;p(true),u(null);try{if(await et(c),!P())return;if(!getAccount(c).isConnected){let y=b$1();if(y){if(await y.open(),!await Ze(c)){u("No wallet was connected.");return}}else {let z=tt(b);if(!z){u("No wallet connector is configured.");return}try{await h({connector:z});}catch(N){if(!Xe(N))throw N}}}let f=D??await he(c);if(!f&&getAccount(c).isConnected&&(await new Promise(y=>setTimeout(y,300)),f=await he(c),!P()))return;if(!f){u("Wallet client is not available.");return}w(!0);let v=await rt(q$1({client:o,clients:f,networkID:t}),ot);if(!P())return;if(v.ok){n();return}u(v.stage==="sign"?"Signature declined.":v.error??"Wallet sign-in failed.");}catch(f){if(!P())return;console.error("[idosgames/wallet] wallet sign-in failed:",f),u(Ye(f));}finally{P()&&(p(false),w(false));}};useEffect(()=>{!l||T.current||(T.current=true,F());},[l]);let x=async()=>{await nt(c)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{A?x():F();},disabled:i,style:{...it,...i?{opacity:.6,cursor:"default"}:null,...g},children:A?"Waiting for signature \u2014 tap to open wallet":I?"Check your wallet\u2026":C?s??"Sign in with wallet":"Connect wallet"}),k&&jsx("span",{role:"alert",style:st,children:k})]})}var it={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},st={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var gt={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},yt={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},se={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},wt={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},K={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},ae={display:"flex",gap:8};function Ct(e){let{client:o,walletConnectProjectId:t,appName:n,onClose:i,style:s}=e,[g,l]=useState(t??"");useEffect(()=>{if(t)return;let C=true;return (async()=>{let h=await o.blockchain.getDefinitions();if(!C||!h.ok)return;let b=h.data.Blockchain?.WalletLogin?.WalletConnectProjectId;b&&l(b);})(),()=>{C=false;}},[o,t]);let c=useMemo(()=>ne({walletConnectProjectId:g||void 0,appName:n}),[g,n]);return jsx(j,{wagmiConfig:c,children:jsx(vt,{client:o,appName:n,onClose:i,style:s})})}function vt({client:e,onClose:o,style:t}){let n=re(e,e.titleID),{address:i,isConnected:s,chainId:g}=useAccount(),{connect:l,connectors:c}=useConnect(),{disconnect:C}=useDisconnect(),{switchChainAsync:h}=useSwitchChain(),[,b]=useReducer(r=>r+1,0),[D,I]=useState({}),[p,k]=useState({}),[u,A]=useState(""),[w,B]=useState(""),[T,F]=useState(""),[x,S]=useState(false),[P,f]=useState(null);useEffect(()=>{let r=true;return (async()=>{let d=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!r||!d.ok)return;let R=d.data.Blockchain?.Networks??{},H={};for(let[Ee,ce]of Object.entries(R))ce.Type==="EVM"&&(H[Ee]=ce);I(H),k(d.data.CryptoCurrencies??{});let Ne=Object.keys(H)[0]??"";A(Ne);})(),()=>{r=false;}},[e]),useEffect(()=>e.on("user:anyUpdated",b),[e]);let v=useMemo(()=>Object.entries(p).filter(([,r])=>r.Networks?.some(d=>d.NetworkID===u&&!!d.ContractAddress)),[p,u]);useEffect(()=>{let r=v[0]?.[0]??"";B(d=>v.some(([R])=>R===d)?d:r);},[v]);let y=u?D[u]:void 0,N=(w?p[w]:void 0)?.Networks?.find(r=>r.NetworkID===u),We=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function le(){if(!y?.ChainID||g===y.ChainID)return true;try{return await h({chainId:y.ChainID}),!0}catch{return f({ok:false,stage:"approve",error:`Switch your wallet to chain ${y.ChainID} to continue.`}),false}}async function De(){if(!(!y||!N?.ContractAddress)){if(S(true),f(null),await le()){let r=N.Decimals??18,d;try{d=parseUnits(T||"0",r);}catch{f({ok:false,stage:"approve",error:"Invalid amount."}),S(false);return}let R=await n.depositToken({network:y,tokenAddress:N.ContractAddress,amount:d});f(R),R.ok&&await e.blockchain.getUserState();}S(false);}}async function Se(){if(!(!y||!n.account)){if(S(true),f(null),await le()){let r=await n.withdrawToken({currencyID:w,networkID:u,walletAddress:n.account,amount:T||"0"});f(r),r.ok&&await e.blockchain.getUserState();}S(false);}}return jsxs("div",{style:{...gt,...t},children:[jsxs("div",{style:{...ae,justifyContent:"space-between"},children:[jsx("span",{style:yt,children:"Crypto wallet"}),o&&jsx("button",{type:"button",style:K,onClick:o,children:"\u2715"})]}),s?jsxs("div",{style:ae,children:[jsxs("span",{style:{...E,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsx("button",{type:"button",style:K,onClick:()=>C(),children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:E,children:"Connect a browser or mobile wallet"}),c.map(r=>jsx("button",{type:"button",style:K,onClick:()=>l({connector:r}),children:r.name},r.uid))]}),Object.keys(D).length===0?jsx("span",{style:E,children:"No EVM networks configured for this title."}):jsxs(Fragment,{children:[jsxs("div",{children:[jsx("div",{style:E,children:"Network"}),jsx("select",{style:se,value:u,onChange:r=>A(r.target.value),children:Object.entries(D).map(([r,d])=>jsx("option",{value:r,children:d.DisplayName??r},r))})]}),jsxs("div",{children:[jsx("div",{style:E,children:"Token"}),jsxs("select",{style:se,value:w,onChange:r=>B(r.target.value),children:[v.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),v.map(([r,d])=>jsx("option",{value:r,children:d.DisplayName??r},r))]})]}),jsxs("div",{style:E,children:["In-game balance: ",jsx("b",{children:We})," ",w]}),jsxs("div",{children:[jsx("div",{style:E,children:"Amount"}),jsx("input",{style:se,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:ae,children:[jsx("button",{type:"button",style:{...wt,flex:1,opacity:x?.6:1},disabled:x||!s||!N?.ContractAddress,onClick:()=>{De();},children:"Deposit"}),jsx("button",{type:"button",style:{...K,flex:1,opacity:x?.6:1},disabled:x||!s||!w,onClick:()=>{Se();},children:"Withdraw"})]})]}),P&&jsx(ht,{result:P})]})}function ht({result:e}){let o={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxs("div",{style:o,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxs("div",{style:o,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{we as DEFAULT_EVM_CHAINS,j as IDosGamesWalletProvider,Je as WalletLogin,ke as WalletLoginButton,Ct as WalletPanel,ne as createEvmWalletConfig,re as useEvmBridge,U as useEvmBridgeClients};
|
|
1
|
+
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};
|
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 _t=Object.defineProperty;var w=(e,t)=>()=>(e&&(t=e(e=0)),t);var Xe=(e,t)=>{for(var n in t)_t(e,n,{get:t[n],enumerable:true});};function T(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 W(e,t){return {ok:false,stage:e,error:t}}var G=w(()=>{});function v(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function tt(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function H(e){return p(e,et)}function ue(e){return W(e,et)}var et,z=w(()=>{G();et="WALLET_USE_SITE_PANEL";});function We(e){return Object.values(exports.idosChains).find(t=>t.id===e)}function nt(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 ne=w(()=>{exports.mainnet={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},exports.bsc={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},exports.polygon={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},exports.base={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},exports.arbitrum={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},exports.optimism={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},exports.sepolia={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},exports.polygonAmoy={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},exports.idosChains={mainnet:exports.mainnet,bsc:exports.bsc,polygon:exports.polygon,base:exports.base,arbitrum:exports.arbitrum,optimism:exports.optimism,sepolia:exports.sepolia,polygonAmoy:exports.polygonAmoy};exports.solanaMainnet={id:"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",name:"Solana",network:"solana-mainnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.mainnet-beta.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:false,chainNamespace:"solana",caipNetworkId:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"},exports.solanaDevnet={id:"EtWTRABZaYq6iMfeYKouRu166VU2xqa1",name:"Solana Devnet",network:"solana-devnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.devnet.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:true,chainNamespace:"solana",caipNetworkId:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"};});function fe(e){ot=e;}function oe(){return ot}var ot,ie=w(()=>{ot=null;});function ge(e){let{chains:t=Ee,walletConnectProjectId:n,appName:o,appUrl:i,appIcon:r,transports:c,connectors:s}=e,a=n??"__extension_only__";if(!s){let f=xe.get(a);if(f)return f}let l={};for(let f of t)l[f.id]=c?.[f.id]??wagmi.http();let d=i??(typeof window<"u"?window.location.origin:""),u={name:o??"iDosGames",description:o??"iDosGames game",url:d,icons:r?[r]:[]};if(n&&!s){let f=t.map(nt),C=new appkitAdapterWagmi.WagmiAdapter({networks:f,projectId:n,transports:l});return fe(react$1.createAppKit({adapters:[C],networks:f,projectId:n,metadata:u,features:{analytics:false,email:false,socials:false}})),xe.set(a,C.wagmiConfig),C.wagmiConfig}let m=s??[connectors.injected(),connectors.coinbaseWallet({appName:o??"iDosGames"})],y=wagmi.createConfig({chains:t,connectors:m,transports:l});return s||xe.set(a,y),y}var Ee,xe,Te=w(()=>{ne();ie();Ee=[exports.mainnet,exports.bsc,exports.polygon,exports.base,exports.arbitrum,exports.optimism,exports.sepolia,exports.polygonAmoy],xe=new Map;});function re(e){let{wagmiConfig:t,queryClient:n,children:o}=e,[i]=react.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,children:o})})}var ye=w(()=>{});var we,at,De,it,Ie=w(()=>{we=[{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:[]}],at=[{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:[]}],De=[{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"}]}],it=[{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 st(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}var lt=w(()=>{});async function q(e,t){let{walletClient:n,publicClient:o,account:i}=e,r=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:i,chain:n.chain,value:t.value});if((await o.waitForTransactionReceipt({hash:r})).status==="reverted")throw new Error(`On-chain transaction reverted (${r}).`);return r}var Ne=w(()=>{});function ct(e){let t=e.RewardPoolAddress;return t||null}async function dt(e,t,n,o){return await e.publicClient.readContract({address:t,abi:De,functionName:"allowance",args:[e.account,n]})>=o?null:q(e,{address:t,abi:De,functionName:"approve",args:[n,o]})}async function Re(e){let{client:t,clients:n,network:o,tokenAddress:i,amount:r,titleID:c,category:s}=e;if(v())return H("approve");let a=t.auth.context?.userID;if(!a)return p("approve","Not logged in.");let l=ct(o);if(!l)return p("approve","Network has no RewardPoolAddress.");if(r<=0n)return p("approve","Amount must be positive.");try{await dt(n,i,l,r);}catch(m){return p("approve",T(m))}let d;try{d=await q(n,{address:l,abi:we,functionName:"depositERC20",args:[i,r,a,c,s??""]});}catch(m){return p("deposit-onchain",T(m))}let u=await t.blockchain.depositToken(o.NetworkID??"",d);return u.ok?{ok:true,onChainTxHash:d,data:u.data}:p("report",u.error,{onChainTxHash:d})}async function Be(e){let{client:t,clients:n,network:o,nftContractAddress:i,tokenId:r,amount:c,titleID:s,category:a}=e;if(v())return H("deposit-onchain");let l=t.auth.context?.userID;if(!l)return p("deposit-onchain","Not logged in.");let d=ct(o);if(!d)return p("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return p("deposit-onchain","Amount must be positive.");let u=st(l,s,a),m;try{m=await q(n,{address:i,abi:it,functionName:"safeTransferFrom",args:[n.account,d,r,c,u]});}catch(f){return p("deposit-onchain",T(f))}let y=await t.blockchain.depositNFT(o.NetworkID??"",m);return y.ok?{ok:true,onChainTxHash:m,data:y.data}:p("report",y.error,{onChainTxHash:m})}var pt=w(()=>{Ie();lt();Ne();G();z();});function ut(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function mt(e,t){return q(e,{address:t.ContractAddress,abi:we,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),ut(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function ft(e,t){return q(e,{address:t.ContractAddress,abi:at,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),ut(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function Le(e){let{client:t,clients:n,currencyID:o,networkID:i,walletAddress:r,amount:c,category:s}=e;if(v())return H("request");let a=await t.blockchain.requestTokenWithdrawal(o,i,r,c,s);if(!a.ok)return p("request",a.error);let l=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!l)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let u;try{u=await mt(n,l);}catch(y){return p("withdraw-onchain",T(y),{titleTransactionID:d})}let m=await gt(t,d,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:m}async function Me(e){let{client:t,clients:n,itemID:o,networkID:i,walletAddress:r,amount:c,category:s}=e;if(v())return H("request");let a=await t.blockchain.requestNFTWithdrawal(o,i,r,c,s);if(!a.ok)return p("request",a.error);let l=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!l)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let u;try{u=await ft(n,l);}catch(y){return p("withdraw-onchain",T(y),{titleTransactionID:d})}let m=await gt(t,d,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:m}async function gt(e,t,n){if(!t)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let o=await e.blockchain.confirmWithdrawal(t,n);return o.ok?{ok:true,onChainTxHash:n,data:o.data}:p("confirm",o.error,{onChainTxHash:n,titleTransactionID:t})}var yt=w(()=>{Ie();Ne();G();z();});async function se(e){let{client:t,clients:n,networkID:o}=e;if(v())return ue("challenge");let i=e.walletAddress??n.account,r=await t.auth.requestWalletChallenge(i,o);if(!r.ok)return W("challenge",r.error);let c;try{c=await n.walletClient.signMessage({account:n.account,message:r.data.Message});}catch(a){return W("sign",T(a))}let s=await t.auth.loginWithWallet(i,o,c);return s.ok?{ok:true,data:s.data}:W("login",s.error)}var wt=w(()=>{G();z();});var Fe=w(()=>{pt();yt();wt();});function ce(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}function he(e,t){let n=ce();return {connected:!!n,account:n?.account??null,loginWithWallet:(o,i)=>n?se({client:e,clients:n,networkID:o,walletAddress:i}):Promise.resolve(W("challenge",le)),depositToken:o=>n?Re({client:e,clients:n,titleID:t,...o}):Promise.resolve(p("approve",le)),depositNft:o=>n?Be({client:e,clients:n,titleID:t,...o}):Promise.resolve(p("deposit-onchain",le)),withdrawToken:o=>n?Le({client:e,clients:n,...o}):Promise.resolve(p("withdraw-onchain",le)),withdrawNft:o=>n?Me({client:e,clients:n,...o}):Promise.resolve(p("withdraw-onchain",le))}}var le,be=w(()=>{Fe();G();le="Wallet not connected.";});function kt(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(re,{wagmiConfig:t,children:jsxRuntime.jsx(He,{...n})})}function gn(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function yn(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 bt(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 wn(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let o=false,i=s=>{o||(o=true,r(),clearTimeout(c),n(s));},r=actions.watchAccount(e,{onChange:s=>{s.isConnected&&i(true);}}),c=setTimeout(()=>i(false),t);})}function hn(e,t=8e3){let n=o=>o==="reconnecting"||o==="connecting";return n(actions.getAccount(e).status)?new Promise(o=>{let i=false,r=()=>{i||(i=true,c(),clearTimeout(s),o());},c=actions.watchAccount(e,{onChange:a=>{n(a.status)||r();}}),s=setTimeout(r,t);}):Promise.resolve()}function bn(e){let t=i=>e.find(r=>r.id===i||r.type===i),n=t("injected"),o=typeof window<"u"&&window.ethereum!=null;return n&&o?n:t("walletConnect")??n??e[0]}async function kn(e){try{let o=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=o?.native||o?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function vn(e,t){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function He(e){let{client:t,networkID:n,onAuthenticated:o,disabled:i,label:r,style:c,autoStart:s}=e,a=wagmi.useConfig(),{isConnected:l}=wagmi.useAccount(),{connectAsync:d,connectors:u}=wagmi.useConnect(),m=ce(),[y,f]=react.useState(false),[C,h]=react.useState(null),[O,A]=react.useState(false),N=react.useRef(0),F=react.useRef(false),R=async()=>{let I=++N.current,L=()=>N.current===I;f(true),h(null);try{if(await hn(a),!L())return;if(!actions.getAccount(a).isConnected){let S=oe();if(S){if(await S.open(),!await wn(a)){h("No wallet was connected.");return}}else {let j=bn(u);if(!j){h("No wallet connector is configured.");return}try{await d({connector:j});}catch(E){if(!gn(E))throw E}}}let k=m??await bt(a);if(!k&&actions.getAccount(a).isConnected&&(await new Promise(S=>setTimeout(S,300)),k=await bt(a),!L()))return;if(!k){h("Wallet client is not available.");return}A(!0);let x=await vn(se({client:t,clients:k,networkID:n}),Cn);if(!L())return;if(x.ok){o();return}h(x.stage==="sign"?"Signature declined.":x.error??"Wallet sign-in failed.");}catch(k){if(!L())return;console.error("[idosgames/wallet] wallet sign-in failed:",k),h(yn(k));}finally{L()&&(f(false),A(false));}};react.useEffect(()=>{!s||F.current||(F.current=true,R());},[s]);let B=async()=>{await kn(a)||await oe()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{O?B():R();},disabled:i,style:{...Sn,...i?{opacity:.6,cursor:"default"}:null,...c},children:O?"Waiting for signature \u2014 tap to open wallet":y?"Check your wallet\u2026":l?r??"Sign in with wallet":"Connect wallet"}),C&&jsxRuntime.jsx("span",{role:"alert",style:Pn,children:C})]})}var Cn,Sn,Pn,vt=w(()=>{ie();Fe();ye();be();Cn=9e4;Sn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Pn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});function Pt(e){let{client:t,walletConnectProjectId:n,appName:o,onClose:i,style:r}=e,[c,s]=react.useState(n??"");react.useEffect(()=>{if(n)return;let l=true;return (async()=>{let d=await t.blockchain.getDefinitions();if(!l||!d.ok)return;let u=d.data.Blockchain?.WalletLogin?.WalletConnectProjectId;u&&s(u);})(),()=>{l=false;}},[t,n]);let a=react.useMemo(()=>ge({walletConnectProjectId:c||void 0,appName:o}),[c,o]);return jsxRuntime.jsx(re,{wagmiConfig:a,children:jsxRuntime.jsx(Mn,{client:t,appName:o,onClose:i,style:r})})}function Mn({client:e,onClose:t,style:n}){let o=he(e,e.titleID),{address:i,isConnected:r,chainId:c}=wagmi.useAccount(),{connect:s,connectors:a}=wagmi.useConnect(),{disconnect:l}=wagmi.useDisconnect(),{switchChainAsync:d}=wagmi.useSwitchChain(),[,u]=react.useReducer(g=>g+1,0),[m,y]=react.useState({}),[f,C]=react.useState({}),[h,O]=react.useState(""),[A,N]=react.useState(""),[F,R]=react.useState(""),[B,I]=react.useState(false),[L,k]=react.useState(null);react.useEffect(()=>{let g=true;return (async()=>{let P=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!g||!P.ok)return;let V=P.data.Blockchain?.Networks??{},Pe={};for(let[qt,Je]of Object.entries(V))Je.Type==="EVM"&&(Pe[qt]=Je);y(Pe),C(P.data.CryptoCurrencies??{});let zt=Object.keys(Pe)[0]??"";O(zt);})(),()=>{g=false;}},[e]),react.useEffect(()=>e.on("user:anyUpdated",u),[e]);let x=react.useMemo(()=>Object.entries(f).filter(([,g])=>g.Networks?.some(P=>P.NetworkID===h&&!!P.ContractAddress)),[f,h]);react.useEffect(()=>{let g=x[0]?.[0]??"";N(P=>x.some(([V])=>V===P)?P:g);},[x]);let S=h?m[h]:void 0,E=(A?f[A]:void 0)?.Networks?.find(g=>g.NetworkID===h),Ot=A?e.data.user.getCryptoCurrencyAmount(A):"0";async function Ze(){if(!S?.ChainID||c===S.ChainID)return true;try{return await d({chainId:S.ChainID}),!0}catch{return k({ok:false,stage:"approve",error:`Switch your wallet to chain ${S.ChainID} to continue.`}),false}}async function Kt(){if(!(!S||!E?.ContractAddress)){if(I(true),k(null),await Ze()){let g=E.Decimals??18,P;try{P=viem.parseUnits(F||"0",g);}catch{k({ok:false,stage:"approve",error:"Invalid amount."}),I(false);return}let V=await o.depositToken({network:S,tokenAddress:E.ContractAddress,amount:P});k(V),V.ok&&await e.blockchain.getUserState();}I(false);}}async function Ut(){if(!(!S||!o.account)){if(I(true),k(null),await Ze()){let g=await o.withdrawToken({currencyID:A,networkID:h,walletAddress:o.account,amount:F||"0"});k(g),g.ok&&await e.blockchain.getUserState();}I(false);}}return jsxRuntime.jsxs("div",{style:{...Rn,...n},children:[jsxRuntime.jsxs("div",{style:{...Ke,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Bn,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:ke,onClick:t,children:"\u2715"})]}),r?jsxRuntime.jsxs("div",{style:Ke,children:[jsxRuntime.jsxs("span",{style:{..._,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:ke,onClick:()=>l(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:_,children:"Connect a browser or mobile wallet"}),a.map(g=>jsxRuntime.jsx("button",{type:"button",style:ke,onClick:()=>s({connector:g}),children:g.name},g.uid))]}),Object.keys(m).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:Oe,value:h,onChange:g=>O(g.target.value),children:Object.entries(m).map(([g,P])=>jsxRuntime.jsx("option",{value:g,children:P.DisplayName??g},g))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:_,children:"Token"}),jsxRuntime.jsxs("select",{style:Oe,value:A,onChange:g=>N(g.target.value),children:[x.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),x.map(([g,P])=>jsxRuntime.jsx("option",{value:g,children:P.DisplayName??g},g))]})]}),jsxRuntime.jsxs("div",{style:_,children:["In-game balance: ",jsxRuntime.jsx("b",{children:Ot})," ",A]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:_,children:"Amount"}),jsxRuntime.jsx("input",{style:Oe,inputMode:"decimal",placeholder:"0.0",value:F,onChange:g=>R(g.target.value)})]}),jsxRuntime.jsxs("div",{style:Ke,children:[jsxRuntime.jsx("button",{type:"button",style:{...Ln,flex:1,opacity:B?.6:1},disabled:B||!r||!E?.ContractAddress,onClick:()=>{Kt();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...ke,flex:1,opacity:B?.6:1},disabled:B||!r||!A,onClick:()=>{Ut();},children:"Withdraw"})]})]}),L&&jsxRuntime.jsx(Fn,{result:L})]})}function Fn({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 Rn,Bn,_,Oe,Ln,ke,Ke,Wt=w(()=>{Te();ye();be();Rn={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"},Bn={fontWeight:700,fontSize:16},_={fontSize:12,opacity:.7},Oe={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},Ln={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},ke={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Ke={display:"flex",gap:8};});var Ue={};Xe(Ue,{DEFAULT_EVM_CHAINS:()=>Ee,IDosGamesWalletProvider:()=>re,WalletLogin:()=>kt,WalletLoginButton:()=>He,WalletPanel:()=>Pt,arbitrum:()=>exports.arbitrum,base:()=>exports.base,bsc:()=>exports.bsc,chainById:()=>We,createEvmWalletConfig:()=>ge,idosChains:()=>exports.idosChains,mainnet:()=>exports.mainnet,optimism:()=>exports.optimism,polygon:()=>exports.polygon,polygonAmoy:()=>exports.polygonAmoy,sepolia:()=>exports.sepolia,useEvmBridge:()=>he,useEvmBridgeClients:()=>ce});var ze=w(()=>{Te();ne();ye();be();vt();Wt();});function At(e){let{walletConnectProjectId:t,appName:n,appUrl:o,appIcon:i,wallets:r}=e,c=e.networks??[exports.solanaMainnet],s=o??(typeof window<"u"?window.location.origin:""),a={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:i?[i]:[]},l=new appkitAdapterSolana.SolanaAdapter(r?{wallets:r}:{});return fe(react$1.createAppKit({adapters:[l],networks:c,projectId:t,metadata:a,features:{analytics:false,email:false,socials:false}})),l}var xt=w(()=>{ne();ie();});async function qe(e){let{client:t,adapter:n,network:o,mint:i,amountRaw:r,titleID:c,category:s}=e;if(v())return H("deposit-onchain");let a=t.auth.context?.userID;if(!a)return p("deposit-onchain","Not logged in.");if(r<=0n)return p("deposit-onchain","Amount must be positive.");let l;try{l=await n.depositSpl({mint:i,amountRaw:r,userID:a,titleID:c,category:core.normalizeBlockchainCategory(s)});}catch(u){return p("deposit-onchain",T(u))}let d=await t.blockchain.depositToken(o.NetworkID??"",l);return d.ok?{ok:true,onChainTxHash:l,data:d.data}:p("report",d.error,{onChainTxHash:l})}async function _e(e){let{client:t,adapter:n,currencyID:o,networkID:i,walletAddress:r,amount:c,category:s}=e;if(v())return H("request");let a=await t.blockchain.requestTokenWithdrawal(o,i,r,c,s);if(!a.ok)return p("request",a.error);let l=a.data.SolanaSignature,d=a.data.TitleTransactionID??void 0;if(!l)return p("request","Withdrawal response carried no Solana signature.",{titleTransactionID:d});let u;try{u=await n.submitWithdrawal(l);}catch(y){return p("withdraw-onchain",T(y),{titleTransactionID:d})}if(!d)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:u});let m=await t.blockchain.confirmWithdrawal(d,u);return m.ok?{ok:true,onChainTxHash:u,data:a.data}:p("confirm",m.error,{onChainTxHash:u,titleTransactionID:d})}var Et=w(()=>{G();z();});async function pe(e){let{client:t,networkID:n,walletAddress:o,signMessage:i}=e;if(v())return ue("challenge");let r=await t.auth.requestWalletChallenge(o,n);if(!r.ok)return W("challenge",r.error);let c;try{let a=await i(new TextEncoder().encode(r.data.Message));c=Un(a);}catch(a){return W("sign",T(a))}let s=await t.auth.loginWithWallet(o,n,c);return s.ok?{ok:true,data:s.data}:W("login",s.error)}function Un(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}var Tt=w(()=>{G();z();});var je=w(()=>{Et();Tt();});function It(e,t,n){let{address:o}=react$1.useAppKitAccount(),{walletProvider:i}=react$1.useAppKitProvider("solana"),r=o??null,c=i?.signMessage?.bind(i);return {connected:!!r,account:r,loginWithWallet:(s,a)=>{let l=a??r;return l?c?pe({client:e,networkID:s,walletAddress:l,signMessage:c}):Promise.resolve(W("sign","The connected wallet does not support message signing.")):Promise.resolve(W("challenge",Dt))},depositToken:s=>qe({client:e,adapter:n,titleID:t,...s}),withdrawToken:s=>{let a=s.walletAddress??r;return a?_e({client:e,adapter:n,...s,walletAddress:a}):Promise.resolve(p("request",Dt))}}}var Dt,Nt=w(()=>{je();G();Dt="Wallet not connected.";});function Yn(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 Qn(e,t){return new Promise((n,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),t);e.then(r=>{clearTimeout(i),n(r);},r=>{clearTimeout(i),o(r instanceof Error?r:new Error(String(r)));});})}function Zn(e){let t="Wallet sign-in failed. Please try again.";return e instanceof Error?/user (rejected|denied|cancelled|canceled)|rejected the request/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":t:t}function Bt(e){let{client:t,networkID:n,onAuthenticated:o,disabled:i,label:r,style:c,autoStart:s}=e,{address:a,isConnected:l}=react$1.useAppKitAccount(),{walletProvider:d}=react$1.useAppKitProvider("solana"),[u,m]=react.useState(false),[y,f]=react.useState(null),[C,h]=react.useState(false),[O,A]=react.useState(false),N=react.useRef(null),F=react.useRef(0),R=react.useCallback(()=>{N.current&&clearTimeout(N.current),N.current=null;},[]);react.useEffect(()=>R,[R]);let B=react.useRef(false),I=react.useCallback(async()=>{let x=++F.current,S=()=>F.current===x,j=d?.signMessage?.bind(d);if(!a||!j){f("The connected wallet cannot sign messages."),m(false);return}m(true),f(null);try{A(!0);let E=await Qn(pe({client:t,networkID:n,walletAddress:a,signMessage:j}),$n);if(!S())return;if(E.ok){o();return}f(E.stage==="sign"?"Signature declined.":E.error??"Wallet sign-in failed.");}catch(E){if(!S())return;console.error("[idosgames/wallet] solana sign-in failed:",E),f(Zn(E));}finally{S()&&(m(false),A(false));}},[a,d,t,n,o]),L=react.useCallback(()=>{Yn(d)||oe()?.open();},[d]);react.useEffect(()=>{!C||!l||!a||!d||(h(false),R(),I());},[C,l,a,d,I,R]);let k=()=>{if(O){L();return}if(f(null),B.current=true,l&&a&&d){I();return}let x=oe();if(!x){f("Wallet sign-in is not configured for this title.");return}m(true),h(true),R(),N.current=setTimeout(()=>{h(false),m(false),f("No wallet was connected.");},Vn),x.open();};return react.useEffect(()=>{!s||B.current||(B.current=true,k());},[s]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:k,disabled:i,style:{...Jn,...i?{opacity:.6,cursor:"default"}:null,...c},children:O?"Waiting for signature \u2014 tap to open wallet":u?"Check your wallet\u2026":l?r??"Sign in with wallet":"Connect wallet"}),y&&jsxRuntime.jsx("span",{role:"alert",style:Xn,children:y})]})}var Vn,$n,Jn,Xn,Lt=w(()=>{je();ie();Vn=18e4,$n=9e4;Jn={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Xn={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};});var Mt={};Xe(Mt,{SolanaWalletLogin:()=>Bt,createSolanaWalletConfig:()=>At,solanaDevnet:()=>exports.solanaDevnet,solanaMainnet:()=>exports.solanaMainnet,useSolanaBridge:()=>It});var Ft=w(()=>{xt();Nt();Lt();ne();});z();var oo={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ro={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"},ao={display:"block",padding:"10px 12px",borderRadius:"8px",background:"#04276bf5",border:"1px solid #1e59c8",color:"#fff",fontSize:"13px",textAlign:"center"};function io(e){return jsxRuntime.jsx("span",{role:"status",style:{...ao,...e.style},children:"Deposit and withdraw on idosgames.com \u2014 the wallet connects there, not inside the game."})}function Qe(e){return tt()?null:jsxRuntime.jsx(io,{style:e})}function Gt(e){let{loading:t,disabled:n,label:o,style:i,error:r,onClick:c}=e;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:c,disabled:n||t,style:{...oo,...n||t?{opacity:.6,cursor:"default"}:null,...i},children:t?"Loading wallet\u2026":o??"Sign in with wallet"}),r&&jsxRuntime.jsx("span",{role:"alert",style:ro,children:r})]})}function so(e){let{chains:t,walletConnectProjectId:n,appName:o,disabled:i,label:r,style:c,...s}=e,[a,l]=react.useState(null),[d,u]=react.useState(false),[m,y]=react.useState(null);if(v())return Qe(c);let f=()=>{u(true),y(null),(async()=>{try{let C=await Promise.resolve().then(()=>(ze(),Ue)),h=C.createEvmWalletConfig({chains:t,walletConnectProjectId:n,appName:o});l({mod:C,config:h});}catch(C){console.error("[idosgames/wallet] failed to load the wallet module:",C),y("Could not load the wallet. Please try again.");}finally{u(false);}})();};if(a){let{WalletLogin:C}=a.mod;return jsxRuntime.jsx(C,{...s,wagmiConfig:a.config,disabled:i,label:r,style:c,autoStart:true})}return jsxRuntime.jsx(Gt,{loading:d,disabled:i,label:r,style:c,error:m,onClick:f})}function lo(e){let{walletConnectProjectId:t,appName:n,disabled:o,label:i,style:r,...c}=e,[s,a]=react.useState(null),[l,d]=react.useState(false),[u,m]=react.useState(null);if(v())return Qe(r);let y=()=>{d(true),m(null),(async()=>{try{let f=await Promise.resolve().then(()=>(Ft(),Mt));t&&f.createSolanaWalletConfig({walletConnectProjectId:t,appName:n}),a(f);}catch(f){console.error("[idosgames/wallet] failed to load the wallet module:",f),m("Could not load the wallet. Please try again.");}finally{d(false);}})();};if(s){let{SolanaWalletLogin:f}=s;return jsxRuntime.jsx(f,{...c,disabled:o,label:i,style:r,autoStart:true})}return jsxRuntime.jsx(Gt,{loading:l,disabled:o,label:i,style:r,error:u,onClick:y})}var co={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 po(e){let{onClose:t,style:n}=e,o=v(),[i,r]=react.useState(null),[c,s]=react.useState(null);return react.useEffect(()=>{if(o)return;let a=true;return (async()=>{try{let l=await Promise.resolve().then(()=>(ze(),Ue));a&&r(l);}catch(l){console.error("[idosgames/wallet] failed to load the wallet panel:",l),a&&s("Could not load the wallet.");}})(),()=>{a=false;}},[o]),o?Qe(n):i?jsxRuntime.jsx(i.WalletPanel,{...e}):jsxRuntime.jsxs("div",{style:{...co,...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"})]})}ne();
|
|
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 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=Ao;exports.LazyWalletLogin=Po;exports.LazyWalletPanel=Eo;exports.chainById=Ie;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import { Chain } from 'viem';
|
|
3
|
-
import { IDosGamesClient } from '@idosgames/core';
|
|
3
|
+
import { IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
4
4
|
export { a as AppKitSolanaNetwork, b as arbitrum, c as base, d as bsc, e as chainById, i as idosChains, m as mainnet, o as optimism, p as polygon, f as polygonAmoy, s as sepolia, g as solanaDevnet, h as solanaMainnet } from '../chains-B_P3u8_S.cjs';
|
|
5
5
|
|
|
6
6
|
interface LazyLoginCommonProps {
|
|
@@ -8,8 +8,16 @@ interface LazyLoginCommonProps {
|
|
|
8
8
|
client: IDosGamesClient;
|
|
9
9
|
/** NetworkID the challenge is issued for — one of the title's configured networks. */
|
|
10
10
|
networkID: string;
|
|
11
|
-
/** Called once the wallet signature has been exchanged for a session. */
|
|
12
|
-
onAuthenticated
|
|
11
|
+
/** Called once the wallet signature has been exchanged for a session (login mode). */
|
|
12
|
+
onAuthenticated?: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* `"login"` (default) — sign in with the wallet. `"link"` — attach the wallet to the LOGGED-IN
|
|
15
|
+
* account by signature: the play-access screen of a gated title (`cfg.Blockchain.PlayAccess`).
|
|
16
|
+
* Inside the idosgames.com frame the site's wallet signs, exactly as for login.
|
|
17
|
+
*/
|
|
18
|
+
mode?: "login" | "link";
|
|
19
|
+
/** Link mode: the pass checked against the linked wallet (null on an Open title). */
|
|
20
|
+
onLinked?: (playAccess: PlayAccessStatus | null) => void;
|
|
13
21
|
/**
|
|
14
22
|
* WalletConnect Cloud / Reown project id — what makes phone wallets reachable. Comes from the
|
|
15
23
|
* title's blockchain config; without it only browser-extension wallets are offered.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import { Chain } from 'viem';
|
|
3
|
-
import { IDosGamesClient } from '@idosgames/core';
|
|
3
|
+
import { IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
4
4
|
export { a as AppKitSolanaNetwork, b as arbitrum, c as base, d as bsc, e as chainById, i as idosChains, m as mainnet, o as optimism, p as polygon, f as polygonAmoy, s as sepolia, g as solanaDevnet, h as solanaMainnet } from '../chains-B_P3u8_S.js';
|
|
5
5
|
|
|
6
6
|
interface LazyLoginCommonProps {
|
|
@@ -8,8 +8,16 @@ interface LazyLoginCommonProps {
|
|
|
8
8
|
client: IDosGamesClient;
|
|
9
9
|
/** NetworkID the challenge is issued for — one of the title's configured networks. */
|
|
10
10
|
networkID: string;
|
|
11
|
-
/** Called once the wallet signature has been exchanged for a session. */
|
|
12
|
-
onAuthenticated
|
|
11
|
+
/** Called once the wallet signature has been exchanged for a session (login mode). */
|
|
12
|
+
onAuthenticated?: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* `"login"` (default) — sign in with the wallet. `"link"` — attach the wallet to the LOGGED-IN
|
|
15
|
+
* account by signature: the play-access screen of a gated title (`cfg.Blockchain.PlayAccess`).
|
|
16
|
+
* Inside the idosgames.com frame the site's wallet signs, exactly as for login.
|
|
17
|
+
*/
|
|
18
|
+
mode?: "login" | "link";
|
|
19
|
+
/** Link mode: the pass checked against the linked wallet (null on an Open title). */
|
|
20
|
+
onLinked?: (playAccess: PlayAccessStatus | null) => void;
|
|
13
21
|
/**
|
|
14
22
|
* WalletConnect Cloud / Reown project id — what makes phone wallets reachable. Comes from the
|
|
15
23
|
* title's blockchain config; without it only browser-extension wallets are offered.
|
package/dist/react/lazyIndex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {e,f}from'../chunk-IEWZH6XD.js';export{n as arbitrum,m as base,k as bsc,s as chainById,r as idosChains,j as mainnet,o as optimism,l as polygon,q as polygonAmoy,p as sepolia,v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var
|
|
1
|
+
import {d,c,b}from'../chunk-3VONNSCN.js';import {e,f}from'../chunk-IEWZH6XD.js';export{n as arbitrum,m as base,k as bsc,s as chainById,r as idosChains,j as mainnet,o as optimism,l as polygon,q as polygonAmoy,p as sepolia,v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var v={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},E={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function k(e){switch(e){case b:return "Wallet sign-in is not available on this page.";case "NO_WALLET":case "CANCELLED":return "Connect a wallet on the page to sign in.";case "REJECTED":return "The signature was declined.";case "TIMEOUT":return "The wallet did not answer. Please try again.";default:return e}}function K(e){let{client:t,networkID:a,onAuthenticated:l,onLinked:n,mode:o="login",family:i,disabled:p,label:c$1,style:r}=e,[m,y]=useState(false),[L,g]=useState(null);return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{y(true),g(null),(async()=>{if(o==="link"){let u=await d({client:t,networkID:a,family:i});if(u.ok){y(false),n?.(u.data.PlayAccess??null);return}g(k(u.error)),y(false);return}let s=await c({client:t,networkID:a,family:i});if(s.ok){l?.();return}g(k(s.error)),y(false);})();},disabled:p||m,style:{...v,...p||m?{opacity:.6,cursor:"default"}:null,...r},children:m?"Waiting for the wallet\u2026":c$1??(o==="link"?"Link wallet":"Sign in with wallet")}),L&&jsx("span",{role:"alert",style:E,children:L})]})}function z(e,t){return f()?null:jsx(K,{...e,family:t})}function x(e){let{loading:t,disabled:a,label:l,style:n,error:o,onClick:i}=e;return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:i,disabled:a||t,style:{...v,...a||t?{opacity:.6,cursor:"default"}:null,...n},children:t?"Loading wallet\u2026":l??"Sign in with wallet"}),o&&jsx("span",{role:"alert",style:E,children:o})]})}function q(e$1){let{chains:t,walletConnectProjectId:a,appName:l,disabled:n,label:o,style:i,onAuthenticated:p,...c}=e$1,[r,m]=useState(null),[y,L]=useState(false),[g,b]=useState(null);if(e())return z(e$1,"evm");let s=()=>{L(true),b(null),(async()=>{try{let u=await import('./index.js'),I=u.createEvmWalletConfig({chains:t,walletConnectProjectId:a,appName:l});m({mod:u,config:I});}catch(u){console.error("[idosgames/wallet] failed to load the wallet module:",u),b("Could not load the wallet. Please try again.");}finally{L(false);}})();};if(r){let{WalletLogin:u}=r.mod;return jsx(u,{...c,onAuthenticated:p??A,wagmiConfig:r.config,disabled:n,label:o,style:i,autoStart:true})}return jsx(x,{loading:y,disabled:n,label:o??(e$1.mode==="link"?"Link wallet":void 0),style:i,error:g,onClick:s})}function A(){}function H(e$1){let{walletConnectProjectId:t,appName:a,disabled:l,label:n,style:o,onAuthenticated:i,...p}=e$1,[c,r]=useState(null),[m,y]=useState(false),[L,g]=useState(null);if(e())return z(e$1,"solana");let b=()=>{y(true),g(null),(async()=>{try{let s=await import('./solanaIndex.js');t&&s.createSolanaWalletConfig({walletConnectProjectId:t,appName:a}),r(s);}catch(s){console.error("[idosgames/wallet] failed to load the wallet module:",s),g("Could not load the wallet. Please try again.");}finally{y(false);}})();};if(c){let{SolanaWalletLogin:s}=c;return jsx(s,{...p,onAuthenticated:i??A,disabled:l,label:n,style:o,autoStart:true})}return jsx(x,{loading:m,disabled:l,label:n??(e$1.mode==="link"?"Link wallet":void 0),style:o,error:L,onClick:b})}var Q={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",fontSize:13};function X(e$1){let{onClose:t,style:a}=e$1,l=e(),[n,o]=useState(null),[i,p]=useState(null);return useEffect(()=>{if(l)return;let c=true;return (async()=>{try{let r=await import('./index.js');c&&o(r);}catch(r){console.error("[idosgames/wallet] failed to load the wallet panel:",r),c&&p("Could not load the wallet.");}})(),()=>{c=false;}},[l]),l?null:n?jsx(n.WalletPanel,{...e$1}):jsxs("div",{style:{...Q,...a},children:[i??"Loading wallet\u2026",t&&jsx("button",{type:"button",onClick:t,style:{background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer",marginLeft:10},children:"\u2715"})]})}export{H as LazySolanaWalletLogin,q as LazyWalletLogin,X as LazyWalletPanel};
|
|
@@ -1,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 D={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"},ae={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 N(){return Z}function ie(e){let{walletConnectProjectId:t,appName:a,appUrl:i,appIcon:s,wallets:n}=e,p=e.networks??[D],o=i??(typeof window<"u"?window.location.origin:""),r={name:a??"iDosGames",description:a??"iDosGames game",url:o,icons:s?[s]:[]},c=new appkitAdapterSolana.SolanaAdapter(n?{wallets:n}:{});return $(react.createAppKit({adapters:[c],networks:p,projectId:t,metadata:r,features:{analytics:false,email:false,socials:false}})),c}function w(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function d(e,t,a){return {ok:false,stage:e,error:t,...a}}function u(e,t){return {ok:false,stage:e,error:t}}var J="WALLET_USE_SITE_PANEL";function y(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function B(e){return d(e,J)}function R(e){return u(e,J)}async function K(e){let{client:t,adapter:a,network:i,mint:s,amountRaw:n,titleID:p,category:o}=e;if(y())return B("deposit-onchain");let r=t.auth.context?.userID;if(!r)return d("deposit-onchain","Not logged in.");if(n<=0n)return d("deposit-onchain","Amount must be positive.");let c;try{c=await a.depositSpl({mint:s,amountRaw:n,userID:r,titleID:p,category:core.normalizeBlockchainCategory(o)});}catch(g){return d("deposit-onchain",w(g))}let l=await t.blockchain.depositToken(i.NetworkID??"",c);return l.ok?{ok:true,onChainTxHash:c,data:l.data}:d("report",l.error,{onChainTxHash:c})}async function F(e){let{client:t,adapter:a,currencyID:i,networkID:s,walletAddress:n,amount:p,category:o}=e;if(y())return B("request");let r=await t.blockchain.requestTokenWithdrawal(i,s,n,p,o);if(!r.ok)return d("request",r.error);let c=r.data.SolanaSignature,l=r.data.TitleTransactionID??void 0;if(!c)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:l});let g;try{g=await a.submitWithdrawal(c);}catch(P){return d("withdraw-onchain",w(P),{titleTransactionID:l})}if(!l)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:g});let m=await t.blockchain.confirmWithdrawal(l,g);return m.ok?{ok:true,onChainTxHash:g,data:r.data}:d("confirm",m.error,{onChainTxHash:g,titleTransactionID:l})}async function T(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return R("challenge");let n=await t.auth.requestWalletChallenge(i,a);if(!n.ok)return u("challenge",n.error);let p;try{let r=await s(new TextEncoder().encode(n.data.Message));p=V(r);}catch(r){return u("sign",w(r))}let o=await t.auth.loginWithWallet(i,a,p);return o.ok?{ok:true,data:o.data}:u("login",o.error)}async function M(e){let{client:t,networkID:a,walletAddress:i,signMessage:s}=e;if(y())return R("challenge");let n=await t.auth.linkWallet(i,a);if(!n.ok)return u("challenge",n.error);if(!n.data.Challenge)return u("challenge","No challenge was issued.");let p;try{let r=await s(new TextEncoder().encode(n.data.Challenge));p=V(r);}catch(r){return u("sign",w(r))}let o=await t.auth.linkWallet(i,a,p);return o.ok?{ok:true,data:o.data}:u("login",o.error)}function V(e){let t="0x";for(let a of e)t+=a.toString(16).padStart(2,"0");return t}var Q="Wallet not connected.";function de(e,t,a){let{address:i}=react.useAppKitAccount(),{walletProvider:s}=react.useAppKitProvider("solana"),n=i??null,p=s?.signMessage?.bind(s);return {connected:!!n,account:n,loginWithWallet:(o,r)=>{let c=r??n;return c?p?T({client:e,networkID:o,walletAddress:c,signMessage:p}):Promise.resolve(u("sign","The connected wallet does not support message signing.")):Promise.resolve(u("challenge",Q))},depositToken:o=>K({client:e,adapter:a,titleID:t,...o}),withdrawToken:o=>{let r=o.walletAddress??n;return r?F({client:e,adapter:a,...o,walletAddress:r}):Promise.resolve(d("request",Q))}}}var me=18e4,X=9e4;function fe(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 ee(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 he(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 we(e){let{client:t,networkID:a,onAuthenticated:i,disabled:s,label:n,style:p,autoStart:o,mode:r="login",onLinked:c}=e,{address:l,isConnected:g}=react.useAppKitAccount(),{walletProvider:m}=react.useAppKitProvider("solana"),[P,k]=react$1.useState(false),[q,f]=react$1.useState(null),[_,E]=react$1.useState(false),[H,Y]=react$1.useState(false),A=react$1.useRef(null),z=react$1.useRef(0),S=react$1.useCallback(()=>{A.current&&clearTimeout(A.current),A.current=null;},[]);react$1.useEffect(()=>S,[S]);let v=react$1.useRef(false),L=react$1.useCallback(async()=>{let W=++z.current,x=()=>z.current===W,I=m?.signMessage?.bind(m);if(!l||!I){f("The connected wallet cannot sign messages."),k(false);return}k(true),f(null);try{if(Y(!0),r==="link"){let b=await ee(M({client:t,networkID:a,walletAddress:l,signMessage:I}),X);if(!x())return;if(b.ok){c?.(b.data.PlayAccess??null);return}f(b.stage==="sign"?"Signature declined.":b.error??"Could not link the wallet.");return}let h=await ee(T({client:t,networkID:a,walletAddress:l,signMessage:I}),X);if(!x())return;if(h.ok){i();return}f(h.stage==="sign"?"Signature declined.":h.error??"Wallet sign-in failed.");}catch(h){if(!x())return;console.error("[idosgames/wallet] solana sign-in failed:",h),f(he(h));}finally{x()&&(k(false),Y(false));}},[l,m,t,a,i,r,c]),ne=react$1.useCallback(()=>{fe(m)||N()?.open();},[m]);react$1.useEffect(()=>{!_||!g||!l||!m||(E(false),S(),L());},[_,g,l,m,L,S]);let j=()=>{if(H){ne();return}if(f(null),v.current=true,g&&l&&m){L();return}let W=N();if(!W){f("Wallet sign-in is not configured for this title.");return}k(true),E(true),S(),A.current=setTimeout(()=>{E(false),k(false),f("No wallet was connected.");},me),W.open();};return react$1.useEffect(()=>{!o||v.current||(v.current=true,j());},[o]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:j,disabled:s,style:{...ye,...s?{opacity:.6,cursor:"default"}:null,...p},children:H?"Waiting for signature \u2014 tap to open wallet":P?"Check your wallet\u2026":g?n??(r==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),q&&jsxRuntime.jsx("span",{role:"alert",style:ke,children:q})]})}var ye={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ke={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
|
|
2
|
+
exports.SolanaWalletLogin=we;exports.createSolanaWalletConfig=ie;exports.solanaDevnet=ae;exports.solanaMainnet=D;exports.useSolanaBridge=de;
|
|
@@ -2,7 +2,7 @@ import { SolanaAdapter } from '@reown/appkit-adapter-solana';
|
|
|
2
2
|
import { BaseWalletAdapter } from '@solana/wallet-adapter-base';
|
|
3
3
|
import { a as AppKitSolanaNetwork } from '../chains-B_P3u8_S.cjs';
|
|
4
4
|
export { g as solanaDevnet, h as solanaMainnet } from '../chains-B_P3u8_S.cjs';
|
|
5
|
-
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
5
|
+
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
6
6
|
import { D as DepositTokenSolanaParams, W as WithdrawTokenSolanaParams, S as SolanaProgramAdapter } from '../bridge-f3pZbjqs.cjs';
|
|
7
7
|
import { W as WalletLoginResult, B as BridgeResult } from '../types-CeUVf1tr.cjs';
|
|
8
8
|
import { CSSProperties, ReactNode } from 'react';
|
|
@@ -81,6 +81,14 @@ interface SolanaWalletLoginProps {
|
|
|
81
81
|
* which already consumed the player's click to load this module — a second tap would be a bug.
|
|
82
82
|
*/
|
|
83
83
|
autoStart?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* `"login"` (default) — sign in. `"link"` — attach the wallet to the LOGGED-IN account by
|
|
86
|
+
* signature (play-access screen of a gated title); `onLinked` then receives the pass checked
|
|
87
|
+
* against this wallet, and `onAuthenticated` is not called.
|
|
88
|
+
*/
|
|
89
|
+
mode?: "login" | "link";
|
|
90
|
+
/** Link mode: the pass checked against the linked wallet (null on an Open title). */
|
|
91
|
+
onLinked?: (playAccess: PlayAccessStatus | null) => void;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
94
|
* Ready-made "sign in with wallet" button for **Solana** titles: connect → sign the challenge →
|
|
@@ -2,7 +2,7 @@ import { SolanaAdapter } from '@reown/appkit-adapter-solana';
|
|
|
2
2
|
import { BaseWalletAdapter } from '@solana/wallet-adapter-base';
|
|
3
3
|
import { a as AppKitSolanaNetwork } from '../chains-B_P3u8_S.js';
|
|
4
4
|
export { g as solanaDevnet, h as solanaMainnet } from '../chains-B_P3u8_S.js';
|
|
5
|
-
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
5
|
+
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
6
6
|
import { D as DepositTokenSolanaParams, W as WithdrawTokenSolanaParams, S as SolanaProgramAdapter } from '../bridge-BSTHFExV.js';
|
|
7
7
|
import { W as WalletLoginResult, B as BridgeResult } from '../types-CeUVf1tr.js';
|
|
8
8
|
import { CSSProperties, ReactNode } from 'react';
|
|
@@ -81,6 +81,14 @@ interface SolanaWalletLoginProps {
|
|
|
81
81
|
* which already consumed the player's click to load this module — a second tap would be a bug.
|
|
82
82
|
*/
|
|
83
83
|
autoStart?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* `"login"` (default) — sign in. `"link"` — attach the wallet to the LOGGED-IN account by
|
|
86
|
+
* signature (play-access screen of a gated title); `onLinked` then receives the pass checked
|
|
87
|
+
* against this wallet, and `onAuthenticated` is not called.
|
|
88
|
+
*/
|
|
89
|
+
mode?: "login" | "link";
|
|
90
|
+
/** Link mode: the pass checked against the linked wallet (null on an Open title). */
|
|
91
|
+
onLinked?: (playAccess: PlayAccessStatus | null) => void;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
94
|
* Ready-made "sign in with wallet" button for **Solana** titles: connect → sign the challenge →
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,a as a$1,c}from'../chunk-
|
|
1
|
+
import {b,a as a$1,c,d}from'../chunk-QST6UVX7.js';import {a,b as b$2}from'../chunk-ZL42KPPC.js';import {u,b as b$1,c as c$1}from'../chunk-IEWZH6XD.js';export{v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {SolanaAdapter}from'@reown/appkit-adapter-solana';import {createAppKit,useAppKitAccount,useAppKitProvider}from'@reown/appkit/react';import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function $(e){let{walletConnectProjectId:o,appName:n,appUrl:r,appIcon:a$1,wallets:t}=e,u$1=e.networks??[u],i=r??(typeof window<"u"?window.location.origin:""),s={name:n??"iDosGames",description:n??"iDosGames game",url:i,icons:a$1?[a$1]:[]},l=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[l],networks:u$1,projectId:o,metadata:s,features:{analytics:false,email:false,socials:false}})),l}var z="Wallet not connected.";function ne(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",z))},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",z))}}}var ae=18e4,F=9e4;function ie(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 H(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 se(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 le(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"),[Q,g]=useState(false),[N,d$1]=useState(null),[E,W]=useState(false),[B,L]=useState(false),S=useRef(null),O=useRef(0),m=useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null;},[]);useEffect(()=>m,[m]);let h=useRef(false),C=useCallback(async()=>{let k=++O.current,y=()=>O.current===k,b=p?.signMessage?.bind(p);if(!c$1||!b){d$1("The connected wallet cannot sign messages."),g(false);return}g(true),d$1(null);try{if(L(!0),s==="link"){let A=await H(d({client:o,networkID:n,walletAddress:c$1,signMessage:b}),F);if(!y())return;if(A.ok){l?.(A.data.PlayAccess??null);return}d$1(A.stage==="sign"?"Signature declined.":A.error??"Could not link the wallet.");return}let f=await H(c({client:o,networkID:n,walletAddress:c$1,signMessage:b}),F);if(!y())return;if(f.ok){r();return}d$1(f.stage==="sign"?"Signature declined.":f.error??"Wallet sign-in failed.");}catch(f){if(!y())return;console.error("[idosgames/wallet] solana sign-in failed:",f),d$1(se(f));}finally{y()&&(g(false),L(false));}},[c$1,p,o,n,r,s,l]),V=useCallback(()=>{ie(p)||b$2()?.open();},[p]);useEffect(()=>{!E||!w||!c$1||!p||(W(false),m(),C());},[E,w,c$1,p,C,m]);let M=()=>{if(B){V();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.");},ae),k.open();};return useEffect(()=>{!i||h.current||(h.current=true,M());},[i]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:M,disabled:a,style:{...pe,...a?{opacity:.6,cursor:"default"}:null,...u},children:B?"Waiting for signature \u2014 tap to open wallet":Q?"Check your wallet\u2026":w?t??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),N&&jsx("span",{role:"alert",style:de,children:N})]})}var pe={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},de={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{le as SolanaWalletLogin,$ as createSolanaWalletConfig,ne as useSolanaBridge};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idosgames/wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.18.0",
|
|
74
74
|
"viem": "^2.55.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
package/dist/chunk-2PEE5F3U.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:g$1,mint:m,amountRaw:o,titleID:d,category:s}=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(o<=0n)return b("deposit-onchain","Amount must be positive.");let l;try{l=await n.depositSpl({mint:m,amountRaw:o,userID:e$1,titleID:d,category:normalizeBlockchainCategory(s)});}catch(c){return b("deposit-onchain",a(c))}let r=await t.blockchain.depositToken(g$1.NetworkID??"",l);return r.ok?{ok:true,onChainTxHash:l,data:r.data}:b("report",r.error,{onChainTxHash:l})}async function D(i){let{client:t,adapter:n,currencyID:g$1,networkID:m,walletAddress:o,amount:d,category:s}=i;if(e())return g("request");let e$1=await t.blockchain.requestTokenWithdrawal(g$1,m,o,d,s);if(!e$1.ok)return b("request",e$1.error);let l=e$1.data.SolanaSignature,r=e$1.data.TitleTransactionID??void 0;if(!l)return b("request","Withdrawal response carried no Solana signature.",{titleTransactionID:r});let c;try{c=await n.submitWithdrawal(l);}catch(S){return b("withdraw-onchain",a(S),{titleTransactionID:r})}if(!r)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let w=await t.blockchain.confirmWithdrawal(r,c);return w.ok?{ok:true,onChainTxHash:c,data:e$1.data}:b("confirm",w.error,{onChainTxHash:c,titleTransactionID:r})}async function W(i){let{client:t,networkID:n,walletAddress:g,signMessage:m}=i;if(e())return h("challenge");let o=await t.auth.requestWalletChallenge(g,n);if(!o.ok)return c("challenge",o.error);let d;try{let e=await m(new TextEncoder().encode(o.data.Message));d=I(e);}catch(e){return c("sign",a(e))}let s=await t.auth.loginWithWallet(g,n,d);return s.ok?{ok:true,data:s.data}:c("login",s.error)}function I(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,W as c};
|