@idosgames/wallet 0.5.2 → 0.6.1
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 +16 -0
- package/dist/{bridge-BSTHFExV.d.ts → bridge-CcNWVuIE.d.ts} +1 -1
- package/dist/{bridge-f3pZbjqs.d.cts → bridge-ZHrosWG-.d.cts} +1 -1
- package/dist/{types-CeUVf1tr.d.cts → chains-B2jQ-L0B.d.cts} +64 -1
- package/dist/{types-CeUVf1tr.d.ts → chains-B2jQ-L0B.d.ts} +64 -1
- package/dist/chunk-D2ZPJ33L.js +1 -0
- package/dist/chunk-XJV2C5QX.js +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +8 -100
- package/dist/index.d.ts +8 -100
- package/dist/index.js +1 -1
- package/dist/platformWalletLogin-DNC2Ajle.d.ts +106 -0
- package/dist/platformWalletLogin-Ysdf-Tt8.d.cts +106 -0
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +1 -1
- package/dist/react/lazyIndex.cjs +2 -2
- package/dist/react/lazyIndex.d.cts +7 -4
- package/dist/react/lazyIndex.d.ts +7 -4
- package/dist/react/lazyIndex.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -2
- package/dist/react/solanaIndex.d.cts +46 -13
- package/dist/react/solanaIndex.d.ts +46 -13
- package/dist/react/solanaIndex.js +1 -1
- package/dist/{withdraw-BKVcklPB.d.ts → withdraw-BPbJQVNt.d.ts} +1 -1
- package/dist/{withdraw-C5y67V7i.d.cts → withdraw-DttqktSS.d.cts} +1 -1
- package/package.json +12 -2
- package/dist/chains-B_P3u8_S.d.cts +0 -64
- package/dist/chains-B_P3u8_S.d.ts +0 -64
- package/dist/chunk-Q2E7DE4S.js +0 -1
- package/dist/chunk-UMGI2JW7.js +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { IDosGamesClient, WalletLinkResponse, ClientState } from '@idosgames/core';
|
|
2
|
+
import { W as WalletLoginResult } from './chains-B2jQ-L0B.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `error`/`stage` every wallet flow in this package refuses with when the page is embedded — a
|
|
6
|
+
* game can `if (result.error === WALLET_USE_SITE_PANEL)` to show its own "use the site panel"
|
|
7
|
+
* message instead of a generic failure.
|
|
8
|
+
*/
|
|
9
|
+
declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
|
|
10
|
+
/**
|
|
11
|
+
* The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
|
|
12
|
+
*
|
|
13
|
+
* Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
|
|
14
|
+
* idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
|
|
15
|
+
* that host serves only the preview runtime and is framed only by the dashboard. The one extra case
|
|
16
|
+
* is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
|
|
17
|
+
* the preview runtime sets: on a developer's own machine there is nothing to protect.
|
|
18
|
+
*/
|
|
19
|
+
declare function isAiCoderPreview(hostname?: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
|
|
22
|
+
* check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
|
|
23
|
+
* the same whether the parent is idosgames.com or (in an exotic embedding this package cannot and
|
|
24
|
+
* should not try to distinguish) anything else. Any iframe means "don't prompt for a signature
|
|
25
|
+
* here" — that is a reasonable default even outside the platform's own embedding.
|
|
26
|
+
*/
|
|
27
|
+
declare function isEmbeddedInPlatform(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The page is embedded on SOMEBODY ELSE'S site, not on a platform page of our own.
|
|
30
|
+
*
|
|
31
|
+
* The platform offers a game to other sites through `idosgames.com/embed/{id}`, a thin page that
|
|
32
|
+
* frames the game — so on a foreign site the game sits TWO frames deep (their page → our embed page
|
|
33
|
+
* → the game), while on the platform's own app page it sits exactly one (`/app/{id}` → the game).
|
|
34
|
+
* `window.parent !== window.top` is that difference, and it is the only signal available here: both
|
|
35
|
+
* are cross-origin Window proxies, so they can be compared but not read.
|
|
36
|
+
*
|
|
37
|
+
* Why it matters (owner's decision, 2026-09-22): the "deposit and withdraw on idosgames.com" notice
|
|
38
|
+
* belongs next to the site's own wallet panel — on OUR page, where that panel is right there on
|
|
39
|
+
* screen. On a stranger's blog there is no panel, nothing the player can act on, and a wallet
|
|
40
|
+
* message inside a small embedded window is noise at best. So there the wallet UI shows nothing at
|
|
41
|
+
* all. Nothing about the actual barrier changes: wallet flows refuse in every iframe either way
|
|
42
|
+
* ({@link isEmbeddedInPlatform}).
|
|
43
|
+
*/
|
|
44
|
+
declare function isEmbeddedOnForeignSite(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The site's wallet panel is the ONLY place a player can deposit/withdraw while this game is
|
|
47
|
+
* embedded (see the module docblock above). After it completes an operation it posts
|
|
48
|
+
* `{type: "IDOS_WALLET_BALANCE_CHANGED"}` to this page — a game that wants its on-screen balance
|
|
49
|
+
* to update without the player reloading should call this once (e.g. in its HUD/wallet-display
|
|
50
|
+
* setup) and refresh from `client.blockchain.getUserState()` when it fires. A no-op when not
|
|
51
|
+
* embedded (the site panel doesn't exist there to send it) or outside the browser.
|
|
52
|
+
*
|
|
53
|
+
* Returns an unsubscribe function.
|
|
54
|
+
*/
|
|
55
|
+
declare function onWalletBalanceChanged(callback: () => void): () => void;
|
|
56
|
+
|
|
57
|
+
/** Message names. Shared with `GameWalletLoginBridge` on the website — keep both in step. */
|
|
58
|
+
declare const PLATFORM_WALLET_MESSAGES: {
|
|
59
|
+
readonly addressRequest: "IDOS_PLATFORM_WALLET_ADDRESS_REQUEST";
|
|
60
|
+
readonly addressResponse: "IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE";
|
|
61
|
+
readonly signRequest: "IDOS_PLATFORM_WALLET_SIGN_REQUEST";
|
|
62
|
+
readonly signResponse: "IDOS_PLATFORM_WALLET_SIGN_RESPONSE";
|
|
63
|
+
/** Sent by the site the moment it receives a request — "I am here, the player is choosing". */
|
|
64
|
+
readonly ack: "IDOS_PLATFORM_WALLET_ACK";
|
|
65
|
+
/** "Show the player your wallet card" — the lobby's wallet button inside the site's frame. */
|
|
66
|
+
readonly openRequest: "IDOS_PLATFORM_WALLET_OPEN_REQUEST";
|
|
67
|
+
readonly openResponse: "IDOS_PLATFORM_WALLET_OPEN_RESPONSE";
|
|
68
|
+
};
|
|
69
|
+
/** Which of the site's wallets signs: its EVM connection or its Solana adapter. */
|
|
70
|
+
type PlatformWalletFamily = "evm" | "solana";
|
|
71
|
+
/**
|
|
72
|
+
* The page around the game did not answer at all — an old site build without the bridge, or a
|
|
73
|
+
* parent that is not the platform. The button shows a plain "not available here" for it.
|
|
74
|
+
*/
|
|
75
|
+
declare const PLATFORM_WALLET_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
|
|
76
|
+
interface LoginWithWalletViaPlatformParams {
|
|
77
|
+
/** The (not yet authenticated) shared client. */
|
|
78
|
+
client: IDosGamesClient;
|
|
79
|
+
/** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. */
|
|
80
|
+
networkID: string;
|
|
81
|
+
/** Which of the site's wallets to use. */
|
|
82
|
+
family: PlatformWalletFamily;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Asks the idosgames.com page around the game to show its own wallet card (deposit / withdraw).
|
|
86
|
+
* Inside the site's frame crypto goes through that card only (owner, 2026-09-17), so a game's
|
|
87
|
+
* "wallet" button calls this instead of opening a wallet of its own. Resolves `true` once the site
|
|
88
|
+
* answered, `false` when nobody did (an old site build, or a parent that is not the platform).
|
|
89
|
+
*/
|
|
90
|
+
declare function openPlatformWalletPanel(): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Full wallet sign-in for a game embedded on idosgames.com, signed by the site's own wallet
|
|
93
|
+
* connection. Same result shape and stages as `loginWithWalletEvm` / `loginWithWalletSolana`:
|
|
94
|
+
* `challenge` covers getting the address and the engine's message, `sign` the site's signature,
|
|
95
|
+
* `login` the exchange for a session.
|
|
96
|
+
*/
|
|
97
|
+
declare function loginWithWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<ClientState>>;
|
|
98
|
+
/**
|
|
99
|
+
* Attach a wallet to the LOGGED-IN account inside the idosgames.com frame — the site's wallet signs
|
|
100
|
+
* the engine's link challenge (same message template as login, so the site's check accepts it). Used
|
|
101
|
+
* by the play-access screen of a gated title; `data.PlayAccess` is the pass checked against this
|
|
102
|
+
* wallet.
|
|
103
|
+
*/
|
|
104
|
+
declare function linkWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<WalletLinkResponse>>;
|
|
105
|
+
|
|
106
|
+
export { type LoginWithWalletViaPlatformParams as L, PLATFORM_WALLET_MESSAGES as P, WALLET_USE_SITE_PANEL as W, PLATFORM_WALLET_UNAVAILABLE as a, type PlatformWalletFamily as b, isEmbeddedInPlatform as c, isEmbeddedOnForeignSite as d, loginWithWalletViaPlatform as e, openPlatformWalletPanel as f, isAiCoderPreview as i, linkWalletViaPlatform as l, onWalletBalanceChanged as o };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { IDosGamesClient, WalletLinkResponse, ClientState } from '@idosgames/core';
|
|
2
|
+
import { W as WalletLoginResult } from './chains-B2jQ-L0B.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `error`/`stage` every wallet flow in this package refuses with when the page is embedded — a
|
|
6
|
+
* game can `if (result.error === WALLET_USE_SITE_PANEL)` to show its own "use the site panel"
|
|
7
|
+
* message instead of a generic failure.
|
|
8
|
+
*/
|
|
9
|
+
declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
|
|
10
|
+
/**
|
|
11
|
+
* The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
|
|
12
|
+
*
|
|
13
|
+
* Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
|
|
14
|
+
* idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
|
|
15
|
+
* that host serves only the preview runtime and is framed only by the dashboard. The one extra case
|
|
16
|
+
* is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
|
|
17
|
+
* the preview runtime sets: on a developer's own machine there is nothing to protect.
|
|
18
|
+
*/
|
|
19
|
+
declare function isAiCoderPreview(hostname?: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
|
|
22
|
+
* check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
|
|
23
|
+
* the same whether the parent is idosgames.com or (in an exotic embedding this package cannot and
|
|
24
|
+
* should not try to distinguish) anything else. Any iframe means "don't prompt for a signature
|
|
25
|
+
* here" — that is a reasonable default even outside the platform's own embedding.
|
|
26
|
+
*/
|
|
27
|
+
declare function isEmbeddedInPlatform(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The page is embedded on SOMEBODY ELSE'S site, not on a platform page of our own.
|
|
30
|
+
*
|
|
31
|
+
* The platform offers a game to other sites through `idosgames.com/embed/{id}`, a thin page that
|
|
32
|
+
* frames the game — so on a foreign site the game sits TWO frames deep (their page → our embed page
|
|
33
|
+
* → the game), while on the platform's own app page it sits exactly one (`/app/{id}` → the game).
|
|
34
|
+
* `window.parent !== window.top` is that difference, and it is the only signal available here: both
|
|
35
|
+
* are cross-origin Window proxies, so they can be compared but not read.
|
|
36
|
+
*
|
|
37
|
+
* Why it matters (owner's decision, 2026-09-22): the "deposit and withdraw on idosgames.com" notice
|
|
38
|
+
* belongs next to the site's own wallet panel — on OUR page, where that panel is right there on
|
|
39
|
+
* screen. On a stranger's blog there is no panel, nothing the player can act on, and a wallet
|
|
40
|
+
* message inside a small embedded window is noise at best. So there the wallet UI shows nothing at
|
|
41
|
+
* all. Nothing about the actual barrier changes: wallet flows refuse in every iframe either way
|
|
42
|
+
* ({@link isEmbeddedInPlatform}).
|
|
43
|
+
*/
|
|
44
|
+
declare function isEmbeddedOnForeignSite(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The site's wallet panel is the ONLY place a player can deposit/withdraw while this game is
|
|
47
|
+
* embedded (see the module docblock above). After it completes an operation it posts
|
|
48
|
+
* `{type: "IDOS_WALLET_BALANCE_CHANGED"}` to this page — a game that wants its on-screen balance
|
|
49
|
+
* to update without the player reloading should call this once (e.g. in its HUD/wallet-display
|
|
50
|
+
* setup) and refresh from `client.blockchain.getUserState()` when it fires. A no-op when not
|
|
51
|
+
* embedded (the site panel doesn't exist there to send it) or outside the browser.
|
|
52
|
+
*
|
|
53
|
+
* Returns an unsubscribe function.
|
|
54
|
+
*/
|
|
55
|
+
declare function onWalletBalanceChanged(callback: () => void): () => void;
|
|
56
|
+
|
|
57
|
+
/** Message names. Shared with `GameWalletLoginBridge` on the website — keep both in step. */
|
|
58
|
+
declare const PLATFORM_WALLET_MESSAGES: {
|
|
59
|
+
readonly addressRequest: "IDOS_PLATFORM_WALLET_ADDRESS_REQUEST";
|
|
60
|
+
readonly addressResponse: "IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE";
|
|
61
|
+
readonly signRequest: "IDOS_PLATFORM_WALLET_SIGN_REQUEST";
|
|
62
|
+
readonly signResponse: "IDOS_PLATFORM_WALLET_SIGN_RESPONSE";
|
|
63
|
+
/** Sent by the site the moment it receives a request — "I am here, the player is choosing". */
|
|
64
|
+
readonly ack: "IDOS_PLATFORM_WALLET_ACK";
|
|
65
|
+
/** "Show the player your wallet card" — the lobby's wallet button inside the site's frame. */
|
|
66
|
+
readonly openRequest: "IDOS_PLATFORM_WALLET_OPEN_REQUEST";
|
|
67
|
+
readonly openResponse: "IDOS_PLATFORM_WALLET_OPEN_RESPONSE";
|
|
68
|
+
};
|
|
69
|
+
/** Which of the site's wallets signs: its EVM connection or its Solana adapter. */
|
|
70
|
+
type PlatformWalletFamily = "evm" | "solana";
|
|
71
|
+
/**
|
|
72
|
+
* The page around the game did not answer at all — an old site build without the bridge, or a
|
|
73
|
+
* parent that is not the platform. The button shows a plain "not available here" for it.
|
|
74
|
+
*/
|
|
75
|
+
declare const PLATFORM_WALLET_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
|
|
76
|
+
interface LoginWithWalletViaPlatformParams {
|
|
77
|
+
/** The (not yet authenticated) shared client. */
|
|
78
|
+
client: IDosGamesClient;
|
|
79
|
+
/** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. */
|
|
80
|
+
networkID: string;
|
|
81
|
+
/** Which of the site's wallets to use. */
|
|
82
|
+
family: PlatformWalletFamily;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Asks the idosgames.com page around the game to show its own wallet card (deposit / withdraw).
|
|
86
|
+
* Inside the site's frame crypto goes through that card only (owner, 2026-09-17), so a game's
|
|
87
|
+
* "wallet" button calls this instead of opening a wallet of its own. Resolves `true` once the site
|
|
88
|
+
* answered, `false` when nobody did (an old site build, or a parent that is not the platform).
|
|
89
|
+
*/
|
|
90
|
+
declare function openPlatformWalletPanel(): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Full wallet sign-in for a game embedded on idosgames.com, signed by the site's own wallet
|
|
93
|
+
* connection. Same result shape and stages as `loginWithWalletEvm` / `loginWithWalletSolana`:
|
|
94
|
+
* `challenge` covers getting the address and the engine's message, `sign` the site's signature,
|
|
95
|
+
* `login` the exchange for a session.
|
|
96
|
+
*/
|
|
97
|
+
declare function loginWithWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<ClientState>>;
|
|
98
|
+
/**
|
|
99
|
+
* Attach a wallet to the LOGGED-IN account inside the idosgames.com frame — the site's wallet signs
|
|
100
|
+
* the engine's link challenge (same message template as login, so the site's check accepts it). Used
|
|
101
|
+
* by the play-access screen of a gated title; `data.PlayAccess` is the pass checked against this
|
|
102
|
+
* wallet.
|
|
103
|
+
*/
|
|
104
|
+
declare function linkWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<WalletLinkResponse>>;
|
|
105
|
+
|
|
106
|
+
export { type LoginWithWalletViaPlatformParams as L, PLATFORM_WALLET_MESSAGES as P, WALLET_USE_SITE_PANEL as W, PLATFORM_WALLET_UNAVAILABLE as a, type PlatformWalletFamily as b, isEmbeddedInPlatform as c, isEmbeddedOnForeignSite as d, loginWithWalletViaPlatform as e, openPlatformWalletPanel as f, isAiCoderPreview as i, linkWalletViaPlatform as l, onWalletBalanceChanged as o };
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var $={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},Q={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},Z={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},J={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},X={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},ee={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},te={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},ne={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},xe={mainnet:$,bsc:Q,polygon:Z,base:J,arbitrum:X,optimism:ee,sepolia:te,polygonAmoy:ne};function Je(e){return Object.values(xe).find(t=>t.id===e)}function De(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var Pe=null;function Te(e){Pe=e;}function ce(){return Pe}var We=[$,Q,Z,J,X,ee,te,ne],de=new Map;function pe(e){let{chains:t=We,walletConnectProjectId:n,appName:r,appUrl:a,appIcon:o,transports:d,connectors:i}=e,s=n??"__extension_only__";if(!i){let y=de.get(s);if(y)return y}let u={};for(let y of t)u[y.id]=d?.[y.id]??wagmi.http();let c=a??(typeof window<"u"?window.location.origin:""),m={name:r??"iDosGames",description:r??"iDosGames game",url:c,icons:o?[o]:[]};if(n&&!i){let y=t.map(De),N=new appkitAdapterWagmi.WagmiAdapter({networks:y,projectId:n,transports:u});return Te(react.createAppKit({adapters:[N],networks:y,projectId:n,metadata:m,features:{analytics:false,email:false,socials:false}})),de.set(s,N.wagmiConfig),N.wagmiConfig}let f=i??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})],b=wagmi.createConfig({chains:t,connectors:f,transports:u});return i||de.set(s,b),b}function G(e){let{wagmiConfig:t,queryClient:n,children:r}=e,[a]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:t,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:a,children:r})})}var re=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],Ne=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],ue=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],Se=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];function Be(e,t,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}async function B(e,t){let{walletClient:n,publicClient:r,account:a}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:a,chain:n.chain,value:t.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function D(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function p(e,t,n){return {ok:false,stage:e,error:t,...n}}function A(e,t){return {ok:false,stage:e,error:t}}var Re="WALLET_USE_SITE_PANEL",ut=/^[a-z0-9]{8}-preview\.idos\.games$/;function mt(e=typeof window>"u"?"":window.location.hostname){let t=e.toLowerCase();return ut.test(t)?true:t!=="localhost"&&t!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function P(){if(typeof window>"u"||mt())return false;try{return window.self!==window.top}catch{return true}}function _(e){return p(e,Re)}function me(e){return A(e,Re)}function Le(e){let t=e.RewardPoolAddress;return t||null}async function Fe(e,t,n,r){return await e.publicClient.readContract({address:t,abi:ue,functionName:"allowance",args:[e.account,n]})>=r?null:B(e,{address:t,abi:ue,functionName:"approve",args:[n,r]})}async function fe(e){let{client:t,clients:n,network:r,tokenAddress:a,amount:o,titleID:d,category:i}=e;if(P())return _("approve");let s=t.auth.context?.userID;if(!s)return p("approve","Not logged in.");let u=Le(r);if(!u)return p("approve","Network has no RewardPoolAddress.");if(o<=0n)return p("approve","Amount must be positive.");try{await Fe(n,a,u,o);}catch(f){return p("approve",D(f))}let c;try{c=await B(n,{address:u,abi:re,functionName:"depositERC20",args:[a,o,s,d,i??""]});}catch(f){return p("deposit-onchain",D(f))}let m=await t.blockchain.depositToken(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:p("report",m.error,{onChainTxHash:c})}async function ge(e){let{client:t,clients:n,network:r,nftContractAddress:a,tokenId:o,amount:d,titleID:i,category:s}=e;if(P())return _("deposit-onchain");let u=t.auth.context?.userID;if(!u)return p("deposit-onchain","Not logged in.");let c=Le(r);if(!c)return p("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return p("deposit-onchain","Amount must be positive.");let m=Be(u,i,s),f;try{f=await B(n,{address:a,abi:Se,functionName:"safeTransferFrom",args:[n.account,c,o,d,m]});}catch(y){return p("deposit-onchain",D(y))}let b=await t.blockchain.depositNFT(r.NetworkID??"",f);return b.ok?{ok:true,onChainTxHash:f,data:b.data}:p("report",b.error,{onChainTxHash:f})}function _e(e){return (e.Splits??[]).map(t=>({to:t.To,amount:BigInt(t.Amount??"0")}))}async function Oe(e,t){return B(e,{address:t.ContractAddress,abi:re,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),_e(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function He(e,t){return B(e,{address:t.ContractAddress,abi:Ne,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),_e(t),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function ye(e){let{client:t,clients:n,currencyID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(P())return _("request");let s=await t.blockchain.requestTokenWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await Oe(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await Me(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function we(e){let{client:t,clients:n,itemID:r,networkID:a,walletAddress:o,amount:d,category:i}=e;if(P())return _("request");let s=await t.blockchain.requestNFTWithdrawal(r,a,o,d,i);if(!s.ok)return p("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return p("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let m;try{m=await He(n,u);}catch(b){return p("withdraw-onchain",D(b),{titleTransactionID:c})}let f=await Me(t,c,m);return f.ok?{ok:true,onChainTxHash:m,data:s.data}:f}async function Me(e,t,n){if(!t)return p("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await e.blockchain.confirmWithdrawal(t,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:p("confirm",r.error,{onChainTxHash:n,titleTransactionID:t})}async function U(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(a,r);if(!o.ok)return A("challenge",o.error);let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(s){return A("sign",D(s))}let i=await t.auth.loginWithWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}async function he(e){let{client:t,clients:n,networkID:r}=e;if(P())return me("challenge");let a=e.walletAddress??n.account,o=await t.auth.linkWallet(a,r);if(!o.ok)return A("challenge",o.error);if(!o.data.Challenge)return A("challenge","No challenge was issued.");let d;try{d=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(s){return A("sign",D(s))}let i=await t.auth.linkWallet(a,r,d);return i.ok?{ok:true,data:i.data}:A("login",i.error)}function oe(){let{address:e}=wagmi.useAccount(),t=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !e||!t||!n?null:{account:e,publicClient:t,walletClient:n}}var K="Wallet not connected.";function Ce(e,t){let n=oe();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,a)=>n?U({client:e,clients:n,networkID:r,walletAddress:a}):Promise.resolve(A("challenge",K)),depositToken:r=>n?fe({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("approve",K)),depositNft:r=>n?ge({client:e,clients:n,titleID:t,...r}):Promise.resolve(p("deposit-onchain",K)),withdrawToken:r=>n?ye({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K)),withdrawNft:r=>n?we({client:e,clients:n,...r}):Promise.resolve(p("withdraw-onchain",K))}}function be(e,t){switch(e){case null:case void 0:case "":return t;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}function Et(e){let{wagmiConfig:t,...n}=e;return jsxRuntime.jsx(G,{wagmiConfig:t,children:jsxRuntime.jsx(Ve,{...n})})}function At(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function xt(e){let t="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":t:t}async function Ue(e){let t=await actions.getWalletClient(e).catch(()=>null);if(!t)return null;let n=actions.getPublicClient(e);return n?{account:t.account.address,publicClient:n,walletClient:t}:null}function Dt(e,t=18e4){return actions.getAccount(e).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,a=i=>{r||(r=true,o(),clearTimeout(d),n(i));},o=actions.watchAccount(e,{onChange:i=>{i.isConnected&&a(true);}}),d=setTimeout(()=>a(false),t);})}function Pt(e,t=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(e).status)?new Promise(r=>{let a=false,o=()=>{a||(a=true,d(),clearTimeout(i),r());},d=actions.watchAccount(e,{onChange:s=>{n(s.status)||o();}}),i=setTimeout(o,t);}):Promise.resolve()}function Tt(e){let t=a=>e.find(o=>o.id===a||o.type===a),n=t("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:t("walletConnect")??n??e[0]}var Ke=9e4;async function Wt(e){try{let r=(await actions.getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,a=r?.native||r?.universal;return !a||typeof window>"u"?!1:(window.location.href=a,!0)}catch{return false}}function qe(e,t){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),t);e.then(o=>{clearTimeout(a),n(o);},o=>{clearTimeout(a),r(o instanceof Error?o:new Error(String(o)));});})}function Ve(e){let{client:t,networkID:n,onAuthenticated:r,disabled:a,label:o,style:d,autoStart:i,mode:s="login",onLinked:u}=e,c=wagmi.useConfig(),{isConnected:m}=wagmi.useAccount(),{connectAsync:f,connectors:b}=wagmi.useConnect(),y=oe(),[N,x]=react$1.useState(false),[O,w]=react$1.useState(null),[H,L]=react$1.useState(false),j=react$1.useRef(0),S=react$1.useRef(false),T=async()=>{let W=++j.current,E=()=>j.current===W;x(true),w(null);try{if(await Pt(c),!E())return;if(!actions.getAccount(c).isConnected){let v=ce();if(v){if(await v.open(),!await Dt(c)){w("No wallet was connected.");return}}else {let Y=Tt(b);if(!Y){w("No wallet connector is configured.");return}try{await f({connector:Y});}catch(M){if(!At(M))throw M}}}let h=y??await Ue(c);if(!h&&actions.getAccount(c).isConnected&&(await new Promise(v=>setTimeout(v,300)),h=await Ue(c),!E()))return;if(!h){w("Wallet client is not available.");return}if(L(!0),s==="link"){let v=await qe(he({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(v.ok){u?.(v.data.PlayAccess??null);return}w(v.stage==="sign"?"Signature declined.":be(v.error,"Could not link the wallet."));return}let z=await qe(U({client:t,clients:h,networkID:n}),Ke);if(!E())return;if(z.ok){r();return}w(z.stage==="sign"?"Signature declined.":be(z.error,"Wallet sign-in failed."));}catch(h){if(!E())return;console.error("[idosgames/wallet] wallet sign-in failed:",h),w(xt(h));}finally{E()&&(x(false),L(false));}};react$1.useEffect(()=>{!i||S.current||(S.current=true,T());},[i]);let V=async()=>{await Wt(c)||await ce()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{H?V():T();},disabled:a,style:{...It,...a?{opacity:.6,cursor:"default"}:null,...d},children:H?"Waiting for signature \u2014 tap to open wallet":N?"Check your wallet\u2026":m?o??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),O&&jsxRuntime.jsx("span",{role:"alert",style:Nt,children:O})]})}var It={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Nt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Mt={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},Gt={fontWeight:700,fontSize:16},R={fontSize:12,opacity:.7},ke={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},Ut={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},ie={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},Ee={display:"flex",gap:8};function Kt(e){let{client:t,walletConnectProjectId:n,appName:r,onClose:a,style:o}=e,[d,i]=react$1.useState(n??"");react$1.useEffect(()=>{if(n)return;let u=true;return (async()=>{let c=await t.blockchain.getDefinitions();if(!u||!c.ok)return;let m=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;m&&i(m);})(),()=>{u=false;}},[t,n]);let s=react$1.useMemo(()=>pe({walletConnectProjectId:d||void 0,appName:r}),[d,r]);return jsxRuntime.jsx(G,{wagmiConfig:s,children:jsxRuntime.jsx(qt,{client:t,appName:r,onClose:a,style:o})})}function qt({client:e,onClose:t,style:n}){let r=Ce(e,e.titleID),{address:a,isConnected:o,chainId:d}=wagmi.useAccount(),{connect:i,connectors:s}=wagmi.useConnect(),{disconnect:u}=wagmi.useDisconnect(),{switchChainAsync:c}=wagmi.useSwitchChain(),[,m]=react$1.useReducer(l=>l+1,0),[f,b]=react$1.useState({}),[y,N]=react$1.useState({}),[x,O]=react$1.useState(""),[w,H]=react$1.useState(""),[L,j]=react$1.useState(""),[S,T]=react$1.useState(false),[V,W]=react$1.useState(null);react$1.useEffect(()=>{let l=true;return (async()=>{let C=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!l||!C.ok)return;let F=C.data.Blockchain?.Networks??{},le={};for(let[Ze,Ae]of Object.entries(F))Ae.Type==="EVM"&&(le[Ze]=Ae);b(le),N(C.data.CryptoCurrencies??{});let Qe=Object.keys(le)[0]??"";O(Qe);})(),()=>{l=false;}},[e]),react$1.useEffect(()=>e.on("user:anyUpdated",m),[e]);let E=react$1.useMemo(()=>Object.entries(y).filter(([,l])=>l.Networks?.some(C=>C.NetworkID===x&&!!C.ContractAddress)),[y,x]);react$1.useEffect(()=>{let l=E[0]?.[0]??"";H(C=>E.some(([F])=>F===C)?C:l);},[E]);let h=x?f[x]:void 0,v=(w?y[w]:void 0)?.Networks?.find(l=>l.NetworkID===x),Y=w?e.data.user.getCryptoCurrencyAmount(w):"0";async function M(){if(!h?.ChainID||d===h.ChainID)return true;try{return await c({chainId:h.ChainID}),!0}catch{return W({ok:false,stage:"approve",error:`Switch your wallet to chain ${h.ChainID} to continue.`}),false}}async function Ye(){if(!(!h||!v?.ContractAddress)){if(T(true),W(null),await M()){let l=v.Decimals??18,C;try{C=viem.parseUnits(L||"0",l);}catch{W({ok:false,stage:"approve",error:"Invalid amount."}),T(false);return}let F=await r.depositToken({network:h,tokenAddress:v.ContractAddress,amount:C});W(F),F.ok&&await e.blockchain.getUserState();}T(false);}}async function $e(){if(!(!h||!r.account)){if(T(true),W(null),await M()){let l=await r.withdrawToken({currencyID:w,networkID:x,walletAddress:r.account,amount:L||"0"});W(l),l.ok&&await e.blockchain.getUserState();}T(false);}}return jsxRuntime.jsxs("div",{style:{...Mt,...n},children:[jsxRuntime.jsxs("div",{style:{...Ee,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Gt,children:"Crypto wallet"}),t&&jsxRuntime.jsx("button",{type:"button",style:ie,onClick:t,children:"\u2715"})]}),o?jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsxs("span",{style:{...R,flex:1,alignSelf:"center"},children:[a?.slice(0,6),"\u2026",a?.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>u(),children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:R,children:"Connect a browser or mobile wallet"}),s.map(l=>jsxRuntime.jsx("button",{type:"button",style:ie,onClick:()=>i({connector:l}),children:l.name},l.uid))]}),Object.keys(f).length===0?jsxRuntime.jsx("span",{style:R,children:"No EVM networks configured for this title."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Network"}),jsxRuntime.jsx("select",{style:ke,value:x,onChange:l=>O(l.target.value),children:Object.entries(f).map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Token"}),jsxRuntime.jsxs("select",{style:ke,value:w,onChange:l=>H(l.target.value),children:[E.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),E.map(([l,C])=>jsxRuntime.jsx("option",{value:l,children:C.DisplayName??l},l))]})]}),jsxRuntime.jsxs("div",{style:R,children:["In-game balance: ",jsxRuntime.jsx("b",{children:Y})," ",w]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:R,children:"Amount"}),jsxRuntime.jsx("input",{style:ke,inputMode:"decimal",placeholder:"0.0",value:L,onChange:l=>j(l.target.value)})]}),jsxRuntime.jsxs("div",{style:Ee,children:[jsxRuntime.jsx("button",{type:"button",style:{...Ut,flex:1,opacity:S?.6:1},disabled:S||!o||!v?.ContractAddress,onClick:()=>{Ye();},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...ie,flex:1,opacity:S?.6:1},disabled:S||!o||!w,onClick:()=>{$e();},children:"Withdraw"})]})]}),V&&jsxRuntime.jsx(jt,{result:V})]})}function jt({result:e}){let t={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxRuntime.jsxs("div",{style:t,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxRuntime.jsxs("div",{style:t,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}
|
|
2
|
-
exports.DEFAULT_EVM_CHAINS=
|
|
1
|
+
'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var q={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"}}},j={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"}}},V={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"}}},z={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"}}},Y={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},$={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},Q={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},Z={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},ve={mainnet:q,bsc:j,polygon:V,base:z,arbitrum:Y,optimism:$,sepolia:Q,polygonAmoy:Z};function qe(t){return Object.values(ve).find(e=>e.id===t)}function ke(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var Ee=null;function Ae(t){Ee=t;}function ne(){return Ee}var Pe=[q,j,V,z,Y,$,Q,Z],re=new Map;function oe(t){let{chains:e=Pe,walletConnectProjectId:n,appName:r,appUrl:i,appIcon:o,transports:f,connectors:a}=t,s=n??"__extension_only__";if(!a){let w=re.get(s);if(w)return w}let u={};for(let w of e)u[w.id]=f?.[w.id]??wagmi.http();let c=i??(typeof window<"u"?window.location.origin:""),d={name:r??"iDosGames",description:r??"iDosGames game",url:c,icons:o?[o]:[]};if(n&&!a){let w=e.map(ke),b=new appkitAdapterWagmi.WagmiAdapter({networks:w,projectId:n,transports:u});return Ae(react.createAppKit({adapters:[b],networks:w,projectId:n,metadata:d,features:{analytics:false,email:false,socials:false}})),re.set(s,b.wagmiConfig),b.wagmiConfig}let g=a??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})],m=wagmi.createConfig({chains:e,connectors:g,transports:u});return a||re.set(s,m),m}function O(t){let{wagmiConfig:e,queryClient:n,children:r}=t,[i]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:e,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,children:r})})}var J=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"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:[]}],We=[{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:[]}],ie=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],De=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];function Te(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function N(t,e){let{walletClient:n,publicClient:r,account:i}=t,o=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:i,chain:n.chain,value:e.value});if((await r.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function x(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function l(t,e,n){return {ok:false,stage:t,error:e,...n}}function E(t,e){return {ok:false,stage:t,error:e}}var Ie="WALLET_USE_SITE_PANEL",ot=/^[a-z0-9]{8}-preview\.idos\.games$/;function it(t=typeof window>"u"?"":window.location.hostname){let e=t.toLowerCase();return ot.test(e)?true:e!=="localhost"&&e!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function W(){if(typeof window>"u"||it())return false;try{return window.self!==window.top}catch{return true}}function L(t){return l(t,Ie)}function ae(t){return E(t,Ie)}function Ne(t){let e=t.RewardPoolAddress;return e||null}async function Se(t,e,n,r){return await t.publicClient.readContract({address:e,abi:ie,functionName:"allowance",args:[t.account,n]})>=r?null:N(t,{address:e,abi:ie,functionName:"approve",args:[n,r]})}async function se(t){let{client:e,clients:n,network:r,tokenAddress:i,amount:o,titleID:f,category:a}=t;if(W())return L("approve");let s=e.auth.context?.userID;if(!s)return l("approve","Not logged in.");let u=Ne(r);if(!u)return l("approve","Network has no RewardPoolAddress.");if(o<=0n)return l("approve","Amount must be positive.");try{await Se(n,i,u,o);}catch(g){return l("approve",x(g))}let c;try{c=await N(n,{address:u,abi:J,functionName:"depositERC20",args:[i,o,s,f,a??""]});}catch(g){return l("deposit-onchain",x(g))}let d=await e.blockchain.depositToken(r.NetworkID??"",c);return d.ok?{ok:true,onChainTxHash:c,data:d.data}:l("report",d.error,{onChainTxHash:c})}async function le(t){let{client:e,clients:n,network:r,nftContractAddress:i,tokenId:o,amount:f,titleID:a,category:s}=t;if(W())return L("deposit-onchain");let u=e.auth.context?.userID;if(!u)return l("deposit-onchain","Not logged in.");let c=Ne(r);if(!c)return l("deposit-onchain","Network has no RewardPoolAddress.");if(f<=0n)return l("deposit-onchain","Amount must be positive.");let d=Te(u,a,s),g;try{g=await N(n,{address:i,abi:De,functionName:"safeTransferFrom",args:[n.account,c,o,f,d]});}catch(w){return l("deposit-onchain",x(w))}let m=await e.blockchain.depositNFT(r.NetworkID??"",g);return m.ok?{ok:true,onChainTxHash:g,data:m.data}:l("report",m.error,{onChainTxHash:g})}function Be(t){return (t.Splits??[]).map(e=>({to:e.To,amount:BigInt(e.Amount??"0")}))}async function Re(t,e){return N(t,{address:e.ContractAddress,abi:J,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),Be(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function Le(t,e){return N(t,{address:e.ContractAddress,abi:We,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),Be(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function ce(t){let{client:e,clients:n,currencyID:r,networkID:i,walletAddress:o,amount:f,category:a}=t;if(W())return L("request");let s=await e.blockchain.requestTokenWithdrawal(r,i,o,f,a);if(!s.ok)return l("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return l("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let d;try{d=await Re(n,u);}catch(m){return l("withdraw-onchain",x(m),{titleTransactionID:c})}let g=await Fe(e,c,d);return g.ok?{ok:true,onChainTxHash:d,data:s.data}:g}async function de(t){let{client:e,clients:n,itemID:r,networkID:i,walletAddress:o,amount:f,category:a}=t;if(W())return L("request");let s=await e.blockchain.requestNFTWithdrawal(r,i,o,f,a);if(!s.ok)return l("request",s.error);let u=s.data.EvmSignature,c=s.data.TitleTransactionID??void 0;if(!u)return l("request","Withdrawal response carried no EVM signature.",{titleTransactionID:c});let d;try{d=await Le(n,u);}catch(m){return l("withdraw-onchain",x(m),{titleTransactionID:c})}let g=await Fe(e,c,d);return g.ok?{ok:true,onChainTxHash:d,data:s.data}:g}async function Fe(t,e,n){if(!e)return l("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:l("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function H(t){let{client:e,clients:n,networkID:r}=t;if(W())return ae("challenge");let i=t.walletAddress??n.account,o=await e.auth.requestWalletChallenge(i,r);if(!o.ok)return E("challenge",o.error);let f;try{f=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(s){return E("sign",x(s))}let a=await e.auth.loginWithWallet(i,r,f);return a.ok?{ok:true,data:a.data}:E("login",a.error)}async function pe(t){let{client:e,clients:n,networkID:r}=t;if(W())return ae("challenge");let i=t.walletAddress??n.account,o=await e.auth.linkWallet(i,r);if(!o.ok)return E("challenge",o.error);if(!o.data.Challenge)return E("challenge","No challenge was issued.");let f;try{f=await n.walletClient.signMessage({account:n.account,message:o.data.Challenge});}catch(s){return E("sign",x(s))}let a=await e.auth.linkWallet(i,r,f);return a.ok?{ok:true,data:a.data}:E("login",a.error)}function X(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}var M="Wallet not connected.";function ue(t,e){let n=X();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,i)=>n?H({client:t,clients:n,networkID:r,walletAddress:i}):Promise.resolve(E("challenge",M)),depositToken:r=>n?se({client:t,clients:n,titleID:e,...r}):Promise.resolve(l("approve",M)),depositNft:r=>n?le({client:t,clients:n,titleID:e,...r}):Promise.resolve(l("deposit-onchain",M)),withdrawToken:r=>n?ce({client:t,clients:n,...r}):Promise.resolve(l("withdraw-onchain",M)),withdrawNft:r=>n?de({client:t,clients:n,...r}):Promise.resolve(l("withdraw-onchain",M))}}function me(t,e){switch(t){case null:case void 0:case "":return e;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return t}}function gt(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(O,{wagmiConfig:e,children:jsxRuntime.jsx(Ue,{...n})})}function yt(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function wt(t){let e="Wallet sign-in failed. Please try again.";return t instanceof Error?t.name==="ProviderNotFoundError"||/provider not found/i.test(t.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":t.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(t.message)?"Request declined in the wallet.":/timed? ?out/i.test(t.message)?"The wallet did not respond. Open your wallet and try again.":e:e}async function Oe(t){let e=await actions.getWalletClient(t).catch(()=>null);if(!e)return null;let n=actions.getPublicClient(t);return n?{account:e.account.address,publicClient:n,walletClient:e}:null}function ht(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,i=a=>{r||(r=true,o(),clearTimeout(f),n(a));},o=actions.watchAccount(t,{onChange:a=>{a.isConnected&&i(true);}}),f=setTimeout(()=>i(false),e);})}function Ct(t,e=8e3){let n=r=>r==="reconnecting"||r==="connecting";return n(actions.getAccount(t).status)?new Promise(r=>{let i=false,o=()=>{i||(i=true,f(),clearTimeout(a),r());},f=actions.watchAccount(t,{onChange:s=>{n(s.status)||o();}}),a=setTimeout(o,e);}):Promise.resolve()}function bt(t){let e=i=>t.find(o=>o.id===i||o.type===i),n=e("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:e("walletConnect")??n??t[0]}var He=9e4;async function vt(t){try{let r=(await actions.getAccount(t).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=r?.native||r?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function Me(t,e){return new Promise((n,r)=>{let i=setTimeout(()=>r(new Error("The wallet request timed out.")),e);t.then(o=>{clearTimeout(i),n(o);},o=>{clearTimeout(i),r(o instanceof Error?o:new Error(String(o)));});})}function Ue(t){let{client:e,networkID:n,onAuthenticated:r,disabled:i,label:o,style:f,autoStart:a,mode:s="login",onLinked:u}=t,c=wagmi.useConfig(),{isConnected:d}=wagmi.useAccount(),{connectAsync:g,connectors:m}=wagmi.useConnect(),w=X(),[b,A]=react$1.useState(false),[F,P]=react$1.useState(null),[D,I]=react$1.useState(false),B=react$1.useRef(0),U=react$1.useRef(false),R=async()=>{let p=++B.current,y=()=>B.current===p;A(true),P(null);try{if(await Ct(c),!y())return;if(!actions.getAccount(c).isConnected){let k=ne();if(k){if(await k.open(),!await ht(c)){P("No wallet was connected.");return}}else {let Ce=bt(m);if(!Ce){P("No wallet connector is configured.");return}try{await g({connector:Ce});}catch(be){if(!yt(be))throw be}}}let v=w??await Oe(c);if(!v&&actions.getAccount(c).isConnected&&(await new Promise(k=>setTimeout(k,300)),v=await Oe(c),!y()))return;if(!v){P("Wallet client is not available.");return}if(I(!0),s==="link"){let k=await Me(pe({client:e,clients:v,networkID:n}),He);if(!y())return;if(k.ok){u?.(k.data.PlayAccess??null);return}P(k.stage==="sign"?"Signature declined.":me(k.error,"Could not link the wallet."));return}let _=await Me(H({client:e,clients:v,networkID:n}),He);if(!y())return;if(_.ok){r();return}P(_.stage==="sign"?"Signature declined.":me(_.error,"Wallet sign-in failed."));}catch(v){if(!y())return;console.error("[idosgames/wallet] wallet sign-in failed:",v),P(wt(v));}finally{y()&&(A(false),I(false));}};react$1.useEffect(()=>{!a||U.current||(U.current=true,R());},[a]);let K=async()=>{await vt(c)||await ne()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{D?K():R();},disabled:i,style:{...kt,...i?{opacity:.6,cursor:"default"}:null,...f},children:D?"Waiting for signature \u2014 tap to open wallet":b?"Check your wallet\u2026":d?o??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),F&&jsxRuntime.jsx("span",{role:"alert",style:Et,children:F})]})}var kt={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Et={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Dt={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"},Tt={fontWeight:700,fontSize:16},T={fontSize:12,opacity:.7},ye={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},It={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},te={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},we={display:"flex",gap:8};function Ke({client:t,engine:e,onClose:n,style:r}){let[,i]=react$1.useReducer(p=>p+1,0),[o,f]=react$1.useState({}),[a,s]=react$1.useState({}),[u,c]=react$1.useState(""),[d,g]=react$1.useState(""),[m,w]=react$1.useState(""),[b,A]=react$1.useState(false),[F,P]=react$1.useState(null);react$1.useEffect(()=>{let p=true;return (async()=>{let y=await t.blockchain.getDefinitions();if(await t.blockchain.getUserState(),!p||!y.ok)return;let v={};for(let[_,k]of Object.entries(y.data.Blockchain?.Networks??{}))k.Type===e.networkType&&(v[_]=k);f(v),s(y.data.CryptoCurrencies??{}),c(Object.keys(v)[0]??"");})(),()=>{p=false;}},[t,e.networkType]),react$1.useEffect(()=>t.on("user:anyUpdated",i),[t]);let D=react$1.useMemo(()=>Object.entries(a).filter(([,p])=>p.Networks?.some(y=>y.NetworkID===u&&!!y.ContractAddress)),[a,u]);react$1.useEffect(()=>{let p=D[0]?.[0]??"";g(y=>D.some(([v])=>v===y)?y:p);},[D]);let I=u?o[u]:void 0,B=d?a[d]?.Networks?.find(p=>p.NetworkID===u):void 0,U=d?t.data.user.getCryptoCurrencyAmount(d):"0",R=!!e.address;async function K(p){A(true),P(null);try{let y=await p();P(y),y.ok&&await t.blockchain.getUserState();}finally{A(false);}}return jsxRuntime.jsxs("div",{style:{...Dt,...r},children:[jsxRuntime.jsxs("div",{style:{...we,justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{style:Tt,children:"Crypto wallet"}),n&&jsxRuntime.jsx("button",{type:"button",style:te,onClick:n,children:"\u2715"})]}),R?jsxRuntime.jsxs("div",{style:we,children:[jsxRuntime.jsxs("span",{style:{...T,flex:1,alignSelf:"center"},children:[e.address.slice(0,6),"\u2026",e.address.slice(-4)]}),jsxRuntime.jsx("button",{type:"button",style:te,onClick:e.disconnect,children:"Disconnect"})]}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsx("span",{style:T,children:"Connect a browser or mobile wallet"}),e.connectChoices.length===0?jsxRuntime.jsx("span",{style:T,children:"Wallet connection is not configured for this title."}):e.connectChoices.map(p=>jsxRuntime.jsx("button",{type:"button",style:te,onClick:p.connect,children:p.label},p.key))]}),Object.keys(o).length===0?jsxRuntime.jsxs("span",{style:T,children:["No ",e.networkType," networks configured for this title."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:T,children:"Network"}),jsxRuntime.jsx("select",{style:ye,value:u,onChange:p=>c(p.target.value),children:Object.entries(o).map(([p,y])=>jsxRuntime.jsx("option",{value:p,children:y.DisplayName??p},p))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:T,children:"Token"}),jsxRuntime.jsxs("select",{style:ye,value:d,onChange:p=>g(p.target.value),children:[D.length===0&&jsxRuntime.jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),D.map(([p,y])=>jsxRuntime.jsx("option",{value:p,children:y.DisplayName??p},p))]})]}),jsxRuntime.jsxs("div",{style:T,children:["In-game balance: ",jsxRuntime.jsx("b",{children:U})," ",d]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:T,children:"Amount"}),jsxRuntime.jsx("input",{style:ye,inputMode:"decimal",placeholder:"0.0",value:m,onChange:p=>w(p.target.value)})]}),jsxRuntime.jsxs("div",{style:we,children:[jsxRuntime.jsx("button",{type:"button",style:{...It,flex:1,opacity:b?.6:1},disabled:b||!R||!B?.ContractAddress,onClick:()=>{!I||!B||K(()=>e.deposit({network:I,binding:B,currencyID:d,amount:m||"0"}));},children:"Deposit"}),jsxRuntime.jsx("button",{type:"button",style:{...te,flex:1,opacity:b?.6:1},disabled:b||!R||!d,onClick:()=>{I&&K(()=>e.withdraw({network:I,networkID:u,currencyID:d,amount:m||"0"}));},children:"Withdraw"})]})]}),F&&jsxRuntime.jsx(Nt,{result:F})]})}function Nt({result:t}){let e={fontSize:12,borderRadius:8,padding:"8px 10px",background:t.ok?"#1e3a2a":"#3a1e28",color:t.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return t.ok?jsxRuntime.jsxs("div",{style:e,children:["\u2713 Done \xB7 tx ",t.onChainTxHash]}):jsxRuntime.jsxs("div",{style:e,children:["\u2715 [",t.stage,"] ",t.error,t.titleTransactionID?` \xB7 already debited (tx ${t.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}function Gt(t){let{client:e,walletConnectProjectId:n,appName:r,onClose:i,style:o}=t,[f,a]=react$1.useState(n??"");react$1.useEffect(()=>{if(n)return;let u=true;return (async()=>{let c=await e.blockchain.getDefinitions();if(!u||!c.ok)return;let d=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;d&&a(d);})(),()=>{u=false;}},[e,n]);let s=react$1.useMemo(()=>oe({walletConnectProjectId:f||void 0,appName:r}),[f,r]);return jsxRuntime.jsx(O,{wagmiConfig:s,children:jsxRuntime.jsx(Ut,{client:e,onClose:i,style:o})})}function Ut({client:t,onClose:e,style:n}){let r=ue(t,t.titleID),{address:i,isConnected:o,chainId:f}=wagmi.useAccount(),{connect:a,connectors:s}=wagmi.useConnect(),{disconnect:u}=wagmi.useDisconnect(),{switchChainAsync:c}=wagmi.useSwitchChain();async function d(m){if(!m||f===m)return true;try{return await c({chainId:m}),!0}catch{return false}}let g={networkType:"EVM",address:o&&i?i:null,connectChoices:s.map(m=>({key:m.uid,label:m.name,connect:()=>a({connector:m})})),disconnect:()=>u(),deposit:async({network:m,binding:w,amount:b})=>{if(!w.ContractAddress)return l("approve","This token cannot be deposited.");if(!await d(m.ChainID))return l("approve",`Switch your wallet to chain ${m.ChainID} to continue.`);let A;try{A=viem.parseUnits(b,w.Decimals??18);}catch{return l("approve","Invalid amount.")}return r.depositToken({network:m,tokenAddress:w.ContractAddress,amount:A})},withdraw:async({network:m,networkID:w,currencyID:b,amount:A})=>r.account?await d(m.ChainID)?r.withdrawToken({currencyID:b,networkID:w,walletAddress:r.account,amount:A}):l("request",`Switch your wallet to chain ${m.ChainID} to continue.`):l("request","Wallet not connected.")};return jsxRuntime.jsx(Ke,{client:t,engine:g,onClose:e,style:n})}
|
|
2
|
+
exports.DEFAULT_EVM_CHAINS=Pe;exports.IDosGamesWalletProvider=O;exports.WalletLogin=gt;exports.WalletLoginButton=Ue;exports.WalletPanel=Gt;exports.arbitrum=Y;exports.base=z;exports.bsc=j;exports.chainById=qe;exports.createEvmWalletConfig=oe;exports.idosChains=ve;exports.mainnet=q;exports.optimism=$;exports.polygon=V;exports.polygonAmoy=Z;exports.sepolia=Q;exports.useEvmBridge=ue;exports.useEvmBridgeClients=X;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CreateConnectorFn, Config } from 'wagmi';
|
|
2
2
|
import { Chain, Transport } from 'viem';
|
|
3
|
-
|
|
3
|
+
import { W as WalletLoginResult, B as BridgeResult } from '../chains-B2jQ-L0B.cjs';
|
|
4
|
+
export { h as arbitrum, i as base, k as bsc, l as chainById, m as idosChains, n as mainnet, o as optimism, p as polygon, q as polygonAmoy, s as sepolia } from '../chains-B2jQ-L0B.cjs';
|
|
4
5
|
import * as react from 'react';
|
|
5
6
|
import { ReactNode, CSSProperties } from 'react';
|
|
6
7
|
import { QueryClient } from '@tanstack/react-query';
|
|
7
8
|
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
8
|
-
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, d as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-
|
|
9
|
-
import { W as WalletLoginResult, B as BridgeResult } from '../types-CeUVf1tr.cjs';
|
|
9
|
+
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, d as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-DttqktSS.cjs';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The EVM chains a game supports out of the box. Both the sign-in button and the in-game wallet
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CreateConnectorFn, Config } from 'wagmi';
|
|
2
2
|
import { Chain, Transport } from 'viem';
|
|
3
|
-
|
|
3
|
+
import { W as WalletLoginResult, B as BridgeResult } from '../chains-B2jQ-L0B.js';
|
|
4
|
+
export { h as arbitrum, i as base, k as bsc, l as chainById, m as idosChains, n as mainnet, o as optimism, p as polygon, q as polygonAmoy, s as sepolia } from '../chains-B2jQ-L0B.js';
|
|
4
5
|
import * as react from 'react';
|
|
5
6
|
import { ReactNode, CSSProperties } from 'react';
|
|
6
7
|
import { QueryClient } from '@tanstack/react-query';
|
|
7
8
|
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient, PlayAccessStatus } from '@idosgames/core';
|
|
8
|
-
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, d as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-
|
|
9
|
-
import { W as WalletLoginResult, B as BridgeResult } from '../types-CeUVf1tr.js';
|
|
9
|
+
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, d as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-BPbJQVNt.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The EVM chains a game supports out of the box. Both the sign-in button and the in-game wallet
|
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {p as p$1,o as o$1,j as j$1,h,q as q$2,r as r$1}from'../chunk-YTTVLBAW.js';import {a,b as b$1,c as c$1}from'../chunk-UMGI2JW7.js';import {k,l,m,n,o,p,q as q$1,r,u,b,c}from'../chunk-K3THMWU2.js';export{o as arbitrum,n as base,l as bsc,t as chainById,s as idosChains,k as mainnet,p as optimism,m as polygon,r as polygonAmoy,q as sepolia}from'../chunk-K3THMWU2.js';import {http,createConfig,WagmiProvider,useAccount,usePublicClient,useWalletClient,useConfig,useConnect,useDisconnect,useSwitchChain}from'wagmi';import {injected,coinbaseWallet}from'wagmi/connectors';import {WagmiAdapter}from'@reown/appkit-adapter-wagmi';import {createAppKit}from'@reown/appkit/react';import {QueryClient,QueryClientProvider}from'@tanstack/react-query';import {useState,useRef,useEffect,useMemo,useReducer}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getAccount,watchAccount,getWalletClient,getPublicClient}from'wagmi/actions';import {parseUnits}from'viem';var he=[k,l,m,n,o,p,q$1,r],ie=new Map;function se(e){let{chains:n=he,walletConnectProjectId:t,appName:o,appUrl:i,appIcon:s,transports:y,connectors:l}=e,w=t??"__extension_only__";if(!l){let f=ie.get(w);if(f)return f}let v={};for(let f of n)v[f.id]=y?.[f.id]??http();let p=i??(typeof window<"u"?window.location.origin:""),b={name:o??"iDosGames",description:o??"iDosGames game",url:p,icons:s?[s]:[]};if(t&&!l){let f=n.map(u),S=new WagmiAdapter({networks:f,projectId:t,transports:v});return a(createAppKit({adapters:[S],networks:f,projectId:t,metadata:b,features:{analytics:false,email:false,socials:false}})),ie.set(w,S.wagmiConfig),S.wagmiConfig}let D=l??[injected(),coinbaseWallet({appName:o??"iDosGames"})],I=createConfig({chains:n,connectors:D,transports:v});return l||ie.set(w,I),I}function G(e){let{wagmiConfig:n,queryClient:t,children:o}=e,[i]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:n,children:jsx(QueryClientProvider,{client:i,children:o})})}function q(){let{address:e}=useAccount(),n=usePublicClient(),{data:t}=useWalletClient();return !e||!n||!t?null:{account:e,publicClient:n,walletClient:t}}var j="Wallet not connected.";function ae(e,n){let t=q();return {connected:!!t,account:t?.account??null,loginWithWallet:(o,i)=>t?q$2({client:e,clients:t,networkID:o,walletAddress:i}):Promise.resolve(c("challenge",j)),depositToken:o=>t?h({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("approve",j)),depositNft:o=>t?j$1({client:e,clients:t,titleID:n,...o}):Promise.resolve(b("deposit-onchain",j)),withdrawToken:o=>t?o$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j)),withdrawNft:o=>t?p$1({client:e,clients:t,...o}):Promise.resolve(b("withdraw-onchain",j))}}function et(e){let{wagmiConfig:n,...t}=e;return jsx(G,{wagmiConfig:n,children:jsx(Ne,{...t})})}function tt(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function nt(e){let n="Wallet sign-in failed. Please try again.";return e instanceof Error?e.name==="ProviderNotFoundError"||/provider not found/i.test(e.message)?"No crypto wallet found in this browser. Install a wallet extension (e.g. MetaMask) or open this page in your wallet's browser, then try again.":e.name==="UserRejectedRequestError"||/user (rejected|denied|cancelled|canceled)/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":n:n}async function Pe(e){let n=await getWalletClient(e).catch(()=>null);if(!n)return null;let t=getPublicClient(e);return t?{account:n.account.address,publicClient:t,walletClient:n}:null}function ot(e,n=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let o=false,i=l=>{o||(o=true,s(),clearTimeout(y),t(l));},s=watchAccount(e,{onChange:l=>{l.isConnected&&i(true);}}),y=setTimeout(()=>i(false),n);})}function rt(e,n=8e3){let t=o=>o==="reconnecting"||o==="connecting";return t(getAccount(e).status)?new Promise(o=>{let i=false,s=()=>{i||(i=true,y(),clearTimeout(l),o());},y=watchAccount(e,{onChange:w=>{t(w.status)||s();}}),l=setTimeout(s,n);}):Promise.resolve()}function it(e){let n=i=>e.find(s=>s.id===i||s.type===i),t=n("injected"),o=typeof window<"u"&&window.ethereum!=null;return t&&o?t:n("walletConnect")??t??e[0]}var We=9e4;async function st(e){try{let o=(await getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,i=o?.native||o?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function De(e,n){return new Promise((t,o)=>{let i=setTimeout(()=>o(new Error("The wallet request timed out.")),n);e.then(s=>{clearTimeout(i),t(s);},s=>{clearTimeout(i),o(s instanceof Error?s:new Error(String(s)));});})}function Ne(e){let{client:n,networkID:t,onAuthenticated:o,disabled:i,label:s,style:y,autoStart:l,mode:w="login",onLinked:v}=e,p=useConfig(),{isConnected:b}=useAccount(),{connectAsync:D,connectors:I}=useConnect(),f=q(),[S,h]=useState(false),[A,c]=useState(null),[R,T]=useState(false),F=useRef(0),N=useRef(false),k=async()=>{let P=++F.current,C=()=>F.current===P;h(true),c(null);try{if(await rt(p),!C())return;if(!getAccount(p).isConnected){let m=b$1();if(m){if(await m.open(),!await ot(p)){c("No wallet was connected.");return}}else {let M=it(I);if(!M){c("No wallet connector is configured.");return}try{await D({connector:M});}catch(B){if(!tt(B))throw B}}}let d=f??await Pe(p);if(!d&&getAccount(p).isConnected&&(await new Promise(m=>setTimeout(m,300)),d=await Pe(p),!C()))return;if(!d){c("Wallet client is not available.");return}if(T(!0),w==="link"){let m=await De(r$1({client:n,clients:d,networkID:t}),We);if(!C())return;if(m.ok){v?.(m.data.PlayAccess??null);return}c(m.stage==="sign"?"Signature declined.":c$1(m.error,"Could not link the wallet."));return}let U=await De(q$2({client:n,clients:d,networkID:t}),We);if(!C())return;if(U.ok){o();return}c(U.stage==="sign"?"Signature declined.":c$1(U.error,"Wallet sign-in failed."));}catch(d){if(!C())return;console.error("[idosgames/wallet] wallet sign-in failed:",d),c(nt(d));}finally{C()&&(h(false),T(false));}};useEffect(()=>{!l||N.current||(N.current=true,k());},[l]);let _=async()=>{await st(p)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{R?_():k();},disabled:i,style:{...at,...i?{opacity:.6,cursor:"default"}:null,...y},children:R?"Waiting for signature \u2014 tap to open wallet":S?"Check your wallet\u2026":b?s??(w==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),A&&jsx("span",{role:"alert",style:lt,children:A})]})}var at={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},lt={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var wt={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},Ct={fontWeight:700,fontSize:16},E={fontSize:12,opacity:.7},ce={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},vt={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},H={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},de={display:"flex",gap:8};function ht(e){let{client:n,walletConnectProjectId:t,appName:o,onClose:i,style:s}=e,[y,l]=useState(t??"");useEffect(()=>{if(t)return;let v=true;return (async()=>{let p=await n.blockchain.getDefinitions();if(!v||!p.ok)return;let b=p.data.Blockchain?.WalletLogin?.WalletConnectProjectId;b&&l(b);})(),()=>{v=false;}},[n,t]);let w=useMemo(()=>se({walletConnectProjectId:y||void 0,appName:o}),[y,o]);return jsx(G,{wagmiConfig:w,children:jsx(bt,{client:n,appName:o,onClose:i,style:s})})}function bt({client:e,onClose:n,style:t}){let o=ae(e,e.titleID),{address:i,isConnected:s,chainId:y}=useAccount(),{connect:l,connectors:w}=useConnect(),{disconnect:v}=useDisconnect(),{switchChainAsync:p}=useSwitchChain(),[,b]=useReducer(r=>r+1,0),[D,I]=useState({}),[f,S]=useState({}),[h,A]=useState(""),[c,R]=useState(""),[T,F]=useState(""),[N,k]=useState(false),[_,P]=useState(null);useEffect(()=>{let r=true;return (async()=>{let u=await e.blockchain.getDefinitions();if(await e.blockchain.getUserState(),!r||!u.ok)return;let x=u.data.Blockchain?.Networks??{},V={};for(let[Ae,ue]of Object.entries(x))ue.Type==="EVM"&&(V[Ae]=ue);I(V),S(u.data.CryptoCurrencies??{});let xe=Object.keys(V)[0]??"";A(xe);})(),()=>{r=false;}},[e]),useEffect(()=>e.on("user:anyUpdated",b),[e]);let C=useMemo(()=>Object.entries(f).filter(([,r])=>r.Networks?.some(u=>u.NetworkID===h&&!!u.ContractAddress)),[f,h]);useEffect(()=>{let r=C[0]?.[0]??"";R(u=>C.some(([x])=>x===u)?u:r);},[C]);let d=h?D[h]:void 0,m=(c?f[c]:void 0)?.Networks?.find(r=>r.NetworkID===h),M=c?e.data.user.getCryptoCurrencyAmount(c):"0";async function B(){if(!d?.ChainID||y===d.ChainID)return true;try{return await p({chainId:d.ChainID}),!0}catch{return P({ok:false,stage:"approve",error:`Switch your wallet to chain ${d.ChainID} to continue.`}),false}}async function Ie(){if(!(!d||!m?.ContractAddress)){if(k(true),P(null),await B()){let r=m.Decimals??18,u;try{u=parseUnits(T||"0",r);}catch{P({ok:false,stage:"approve",error:"Invalid amount."}),k(false);return}let x=await o.depositToken({network:d,tokenAddress:m.ContractAddress,amount:u});P(x),x.ok&&await e.blockchain.getUserState();}k(false);}}async function Te(){if(!(!d||!o.account)){if(k(true),P(null),await B()){let r=await o.withdrawToken({currencyID:c,networkID:h,walletAddress:o.account,amount:T||"0"});P(r),r.ok&&await e.blockchain.getUserState();}k(false);}}return jsxs("div",{style:{...wt,...t},children:[jsxs("div",{style:{...de,justifyContent:"space-between"},children:[jsx("span",{style:Ct,children:"Crypto wallet"}),n&&jsx("button",{type:"button",style:H,onClick:n,children:"\u2715"})]}),s?jsxs("div",{style:de,children:[jsxs("span",{style:{...E,flex:1,alignSelf:"center"},children:[i?.slice(0,6),"\u2026",i?.slice(-4)]}),jsx("button",{type:"button",style:H,onClick:()=>v(),children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:E,children:"Connect a browser or mobile wallet"}),w.map(r=>jsx("button",{type:"button",style:H,onClick:()=>l({connector:r}),children:r.name},r.uid))]}),Object.keys(D).length===0?jsx("span",{style:E,children:"No EVM networks configured for this title."}):jsxs(Fragment,{children:[jsxs("div",{children:[jsx("div",{style:E,children:"Network"}),jsx("select",{style:ce,value:h,onChange:r=>A(r.target.value),children:Object.entries(D).map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))})]}),jsxs("div",{children:[jsx("div",{style:E,children:"Token"}),jsxs("select",{style:ce,value:c,onChange:r=>R(r.target.value),children:[C.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),C.map(([r,u])=>jsx("option",{value:r,children:u.DisplayName??r},r))]})]}),jsxs("div",{style:E,children:["In-game balance: ",jsx("b",{children:M})," ",c]}),jsxs("div",{children:[jsx("div",{style:E,children:"Amount"}),jsx("input",{style:ce,inputMode:"decimal",placeholder:"0.0",value:T,onChange:r=>F(r.target.value)})]}),jsxs("div",{style:de,children:[jsx("button",{type:"button",style:{...vt,flex:1,opacity:N?.6:1},disabled:N||!s||!m?.ContractAddress,onClick:()=>{Ie();},children:"Deposit"}),jsx("button",{type:"button",style:{...H,flex:1,opacity:N?.6:1},disabled:N||!s||!c,onClick:()=>{Te();},children:"Withdraw"})]})]}),_&&jsx(kt,{result:_})]})}function kt({result:e}){let n={fontSize:12,borderRadius:8,padding:"8px 10px",background:e.ok?"#1e3a2a":"#3a1e28",color:e.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return e.ok?jsxs("div",{style:n,children:["\u2713 Done \xB7 tx ",e.onChainTxHash]}):jsxs("div",{style:n,children:["\u2715 [",e.stage,"] ",e.error,e.titleTransactionID?` \xB7 already debited (tx ${e.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{he as DEFAULT_EVM_CHAINS,G as IDosGamesWalletProvider,et as WalletLogin,Ne as WalletLoginButton,ht as WalletPanel,se as createEvmWalletConfig,ae as useEvmBridge,q as useEvmBridgeClients};
|
|
1
|
+
import {p as p$1,o as o$1,j as j$1,h,q as q$1,r as r$1}from'../chunk-YTTVLBAW.js';import {a,d,b as b$2,c as c$1}from'../chunk-XJV2C5QX.js';import {k,l,m,n,o,p,q,r,u,b as b$1,c}from'../chunk-K3THMWU2.js';export{o as arbitrum,n as base,l as bsc,t as chainById,s as idosChains,k as mainnet,p as optimism,m as polygon,r as polygonAmoy,q as sepolia}from'../chunk-K3THMWU2.js';import {http,createConfig,WagmiProvider,useAccount,usePublicClient,useWalletClient,useConfig,useConnect,useDisconnect,useSwitchChain}from'wagmi';import {injected,coinbaseWallet}from'wagmi/connectors';import {WagmiAdapter}from'@reown/appkit-adapter-wagmi';import {createAppKit}from'@reown/appkit/react';import {QueryClient,QueryClientProvider}from'@tanstack/react-query';import {useState,useRef,useEffect,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getAccount,watchAccount,getWalletClient,getPublicClient}from'wagmi/actions';import {parseUnits}from'viem';var ae=[k,l,m,n,o,p,q,r],j=new Map;function O(e){let{chains:o=ae,walletConnectProjectId:t,appName:n,appUrl:r,appIcon:i,transports:d,connectors:a$1}=e,p=t??"__extension_only__";if(!a$1){let l=j.get(p);if(l)return l}let u$1={};for(let l of o)u$1[l.id]=d?.[l.id]??http();let c=r??(typeof window<"u"?window.location.origin:""),f={name:n??"iDosGames",description:n??"iDosGames game",url:c,icons:i?[i]:[]};if(t&&!a$1){let l=o.map(u),g=new WagmiAdapter({networks:l,projectId:t,transports:u$1});return a(createAppKit({adapters:[g],networks:l,projectId:t,metadata:f,features:{analytics:false,email:false,socials:false}})),j.set(p,g.wagmiConfig),g.wagmiConfig}let P=a$1??[injected(),coinbaseWallet({appName:n??"iDosGames"})],s=createConfig({chains:o,connectors:P,transports:u$1});return a$1||j.set(p,s),s}function W(e){let{wagmiConfig:o,queryClient:t,children:n}=e,[r]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:o,children:jsx(QueryClientProvider,{client:r,children:n})})}function b(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var E="Wallet not connected.";function K(e,o){let t=b();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,r)=>t?q$1({client:e,clients:t,networkID:n,walletAddress:r}):Promise.resolve(c("challenge",E)),depositToken:n=>t?h({client:e,clients:t,titleID:o,...n}):Promise.resolve(b$1("approve",E)),depositNft:n=>t?j$1({client:e,clients:t,titleID:o,...n}):Promise.resolve(b$1("deposit-onchain",E)),withdrawToken:n=>t?o$1({client:e,clients:t,...n}):Promise.resolve(b$1("withdraw-onchain",E)),withdrawNft:n=>t?p$1({client:e,clients:t,...n}):Promise.resolve(b$1("withdraw-onchain",E))}}function _e(e){let{wagmiConfig:o,...t}=e;return jsx(W,{wagmiConfig:o,children:jsx(fe,{...t})})}function je(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function Oe(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 de(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 Ke(e,o=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let n=false,r=a=>{n||(n=true,i(),clearTimeout(d),t(a));},i=watchAccount(e,{onChange:a=>{a.isConnected&&r(true);}}),d=setTimeout(()=>r(false),o);})}function Me(e,o=8e3){let t=n=>n==="reconnecting"||n==="connecting";return t(getAccount(e).status)?new Promise(n=>{let r=false,i=()=>{r||(r=true,d(),clearTimeout(a),n());},d=watchAccount(e,{onChange:p=>{t(p.status)||i();}}),a=setTimeout(i,o);}):Promise.resolve()}function qe(e){let o=r=>e.find(i=>i.id===r||i.type===r),t=o("injected"),n=typeof window<"u"&&window.ethereum!=null;return t&&n?t:o("walletConnect")??t??e[0]}var pe=9e4;async function Ue(e){try{let n=(await getAccount(e).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,r=n?.native||n?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function me(e,o){return new Promise((t,n)=>{let r=setTimeout(()=>n(new Error("The wallet request timed out.")),o);e.then(i=>{clearTimeout(r),t(i);},i=>{clearTimeout(r),n(i instanceof Error?i:new Error(String(i)));});})}function fe(e){let{client:o,networkID:t,onAuthenticated:n,disabled:r,label:i,style:d,autoStart:a,mode:p="login",onLinked:u}=e,c=useConfig(),{isConnected:f}=useAccount(),{connectAsync:P,connectors:s}=useConnect(),l=b(),[g,y]=useState(false),[U,h]=useState(null),[Q,V]=useState(false),$=useRef(0),z=useRef(false),H=async()=>{let we=++$.current,v=()=>$.current===we;y(true),h(null);try{if(await Me(c),!v())return;if(!getAccount(c).isConnected){let w=b$2();if(w){if(await w.open(),!await Ke(c)){h("No wallet was connected.");return}}else {let J=qe(s);if(!J){h("No wallet connector is configured.");return}try{await P({connector:J});}catch(X){if(!je(X))throw X}}}let C=l??await de(c);if(!C&&getAccount(c).isConnected&&(await new Promise(w=>setTimeout(w,300)),C=await de(c),!v()))return;if(!C){h("Wallet client is not available.");return}if(V(!0),p==="link"){let w=await me(r$1({client:o,clients:C,networkID:t}),pe);if(!v())return;if(w.ok){u?.(w.data.PlayAccess??null);return}h(w.stage==="sign"?"Signature declined.":c$1(w.error,"Could not link the wallet."));return}let A=await me(q$1({client:o,clients:C,networkID:t}),pe);if(!v())return;if(A.ok){n();return}h(A.stage==="sign"?"Signature declined.":c$1(A.error,"Wallet sign-in failed."));}catch(C){if(!v())return;console.error("[idosgames/wallet] wallet sign-in failed:",C),h(Oe(C));}finally{v()&&(y(false),V(false));}};useEffect(()=>{!a||z.current||(z.current=true,H());},[a]);let ge=async()=>{await Ue(c)||await b$2()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{Q?ge():H();},disabled:r,style:{...Qe,...r?{opacity:.6,cursor:"default"}:null,...d},children:Q?"Waiting for signature \u2014 tap to open wallet":g?"Check your wallet\u2026":f?i??(p==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),U&&jsx("span",{role:"alert",style:Ve,children:U})]})}var Qe={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Ve={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function ot(e){let{client:o,walletConnectProjectId:t,appName:n,onClose:r,style:i}=e,[d,a]=useState(t??"");useEffect(()=>{if(t)return;let u=true;return (async()=>{let c=await o.blockchain.getDefinitions();if(!u||!c.ok)return;let f=c.data.Blockchain?.WalletLogin?.WalletConnectProjectId;f&&a(f);})(),()=>{u=false;}},[o,t]);let p=useMemo(()=>O({walletConnectProjectId:d||void 0,appName:n}),[d,n]);return jsx(W,{wagmiConfig:p,children:jsx(rt,{client:o,onClose:r,style:i})})}function rt({client:e,onClose:o,style:t}){let n=K(e,e.titleID),{address:r,isConnected:i,chainId:d$1}=useAccount(),{connect:a,connectors:p}=useConnect(),{disconnect:u}=useDisconnect(),{switchChainAsync:c}=useSwitchChain();async function f(s){if(!s||d$1===s)return true;try{return await c({chainId:s}),!0}catch{return false}}let P={networkType:"EVM",address:i&&r?r:null,connectChoices:p.map(s=>({key:s.uid,label:s.name,connect:()=>a({connector:s})})),disconnect:()=>u(),deposit:async({network:s,binding:l,amount:g})=>{if(!l.ContractAddress)return b$1("approve","This token cannot be deposited.");if(!await f(s.ChainID))return b$1("approve",`Switch your wallet to chain ${s.ChainID} to continue.`);let y;try{y=parseUnits(g,l.Decimals??18);}catch{return b$1("approve","Invalid amount.")}return n.depositToken({network:s,tokenAddress:l.ContractAddress,amount:y})},withdraw:async({network:s,networkID:l,currencyID:g,amount:y})=>n.account?await f(s.ChainID)?n.withdrawToken({currencyID:g,networkID:l,walletAddress:n.account,amount:y}):b$1("request",`Switch your wallet to chain ${s.ChainID} to continue.`):b$1("request","Wallet not connected.")};return jsx(d,{client:e,engine:P,onClose:o,style:t})}export{ae as DEFAULT_EVM_CHAINS,W as IDosGamesWalletProvider,_e as WalletLogin,fe as WalletLoginButton,ot as WalletPanel,O as createEvmWalletConfig,K as useEvmBridge,b as useEvmBridgeClients};
|