@idosgames/wallet 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge-BEEkIeZj.d.cts +70 -0
- package/dist/bridge-BzZmMMxK.d.ts +70 -0
- package/dist/chains-DMjdV7VV.d.cts +120 -0
- package/dist/chains-DMjdV7VV.d.ts +120 -0
- package/dist/chunk-ACZSIOFR.js +1 -0
- package/dist/chunk-NDNNLWPS.js +1 -0
- package/dist/chunk-XFMDEOHO.js +2 -0
- package/dist/chunk-ZL42KPPC.js +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +8 -53
- package/dist/react/index.d.ts +8 -53
- package/dist/react/index.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -0
- package/dist/react/solanaIndex.d.cts +93 -0
- package/dist/react/solanaIndex.d.ts +93 -0
- package/dist/react/solanaIndex.js +1 -0
- package/dist/withdraw-DTHssYc9.d.ts +148 -0
- package/dist/withdraw-DgTjKpSf.d.cts +148 -0
- package/package.json +7 -7
- package/dist/bridge-DvafuXl9.d.cts +0 -304
- package/dist/bridge-DvafuXl9.d.ts +0 -304
- package/dist/chunk-ZPNBMRUO.js +0 -2
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'),walletAdapterReact=require('@solana/wallet-adapter-react');var G={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"}}},O={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"}}},q={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"}}},U={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"}}},K={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"}}},j={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"}}},z={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"}}},Q={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"}}},_={mainnet:G,bsc:O,polygon:q,base:U,arbitrum:K,optimism:j,sepolia:z,polygonAmoy:Q};function de(t){return Object.values(_).find(e=>e.id===t)}function $(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var V=null;function J(){return V}function he(t){let{chains:e,walletConnectProjectId:n,appName:r,appUrl:i,appIcon:o,transports:c,connectors:l}=t,a={};for(let d of e)a[d.id]=c?.[d.id]??wagmi.http();let u=i??(typeof window<"u"?window.location.origin:""),p={name:r??"iDosGames",description:r??"iDosGames game",url:u,icons:o?[o]:[]};if(n&&!l){let d=e.map($),g=new appkitAdapterWagmi.WagmiAdapter({networks:d,projectId:n,transports:a});return V=react.createAppKit({adapters:[g],networks:d,projectId:n,metadata:p,features:{analytics:false,email:false,socials:false}}),g.wagmiConfig}let m=l??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})];return wagmi.createConfig({chains:e,connectors:m,transports:a})}function E(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 W=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],Y=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],x=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],Z=[{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 ee(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function w(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 f(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function s(t,e,n){return {ok:false,stage:t,error:e,...n}}function y(t,e){return {ok:false,stage:t,error:e}}function te(t){let e=t.RewardPoolAddress;return e||null}async function ne(t,e,n,r){return await t.publicClient.readContract({address:e,abi:x,functionName:"allowance",args:[t.account,n]})>=r?null:w(t,{address:e,abi:x,functionName:"approve",args:[n,r]})}async function P(t){let{client:e,clients:n,network:r,tokenAddress:i,amount:o,titleID:c,category:l}=t,a=e.auth.context?.userID;if(!a)return s("approve","Not logged in.");let u=te(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(o<=0n)return s("approve","Amount must be positive.");try{await ne(n,i,u,o);}catch(d){return s("approve",f(d))}let p;try{p=await w(n,{address:u,abi:W,functionName:"depositERC20",args:[i,o,a,c,l??""]});}catch(d){return s("deposit-onchain",f(d))}let m=await e.blockchain.depositToken(r.NetworkID??"",p);return m.ok?{ok:true,onChainTxHash:p,data:m.data}:s("report",m.error,{onChainTxHash:p})}async function I(t){let{client:e,clients:n,network:r,nftContractAddress:i,tokenId:o,amount:c,titleID:l,category:a}=t,u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let p=te(r);if(!p)return s("deposit-onchain","Network has no RewardPoolAddress.");if(c<=0n)return s("deposit-onchain","Amount must be positive.");let m=ee(u,l,a),d;try{d=await w(n,{address:i,abi:Z,functionName:"safeTransferFrom",args:[n.account,p,o,c,m]});}catch(v){return s("deposit-onchain",f(v))}let g=await e.blockchain.depositNFT(r.NetworkID??"",d);return g.ok?{ok:true,onChainTxHash:d,data:g.data}:s("report",g.error,{onChainTxHash:d})}async function re(t,e){return w(t,{address:e.ContractAddress,abi:W,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function oe(t,e){return w(t,{address:e.ContractAddress,abi:Y,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function N(t){let{client:e,clients:n,currencyID:r,networkID:i,walletAddress:o,amount:c,category:l}=t,a=await e.blockchain.requestTokenWithdrawal(r,i,o,c,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,p=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let m;try{m=await re(n,u);}catch(g){return s("withdraw-onchain",f(g),{titleTransactionID:p})}let d=await ae(e,p,m);return d.ok?{ok:true,onChainTxHash:m,data:a.data}:d}async function B(t){let{client:e,clients:n,itemID:r,networkID:i,walletAddress:o,amount:c,category:l}=t,a=await e.blockchain.requestNFTWithdrawal(r,i,o,c,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,p=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let m;try{m=await oe(n,u);}catch(g){return s("withdraw-onchain",f(g),{titleTransactionID:p})}let d=await ae(e,p,m);return d.ok?{ok:true,onChainTxHash:m,data:a.data}:d}async function ae(t,e,n){if(!e)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:s("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function k(t){let{client:e,clients:n,networkID:r}=t,i=t.walletAddress??n.account,o=await e.auth.requestWalletChallenge(i,r);if(!o.ok)return y("challenge",o.error);let c;try{c=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(a){return y("sign",f(a))}let l=await e.auth.loginWithWallet(i,r,c);return l.ok?{ok:true,data:l.data}:y("login",l.error)}function T(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}var b="Wallet not connected.";function Pe(t,e){let n=T();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,i)=>n?k({client:t,clients:n,networkID:r,walletAddress:i}):Promise.resolve(y("challenge",b)),depositToken:r=>n?P({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("approve",b)),depositNft:r=>n?I({client:t,clients:n,titleID:e,...r}):Promise.resolve(s("deposit-onchain",b)),withdrawToken:r=>n?N({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",b)),withdrawNft:r=>n?B({client:t,clients:n,...r}):Promise.resolve(s("withdraw-onchain",b))}}function Le(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(E,{wagmiConfig:e,children:jsxRuntime.jsx(se,{...n})})}function Me(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function Ge(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 qe(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,i=l=>{r||(r=true,o(),clearTimeout(c),n(l));},o=actions.watchAccount(t,{onChange:l=>{l.isConnected&&i(true);}}),c=setTimeout(()=>i(false),e);})}function Ue(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]}function se(t){let{client:e,networkID:n,onAuthenticated:r,disabled:i,label:o,style:c}=t,l=wagmi.useConfig(),{isConnected:a}=wagmi.useAccount(),{connectAsync:u,connectors:p}=wagmi.useConnect(),m=T(),[d,g]=react$1.useState(false),[v,h]=react$1.useState(null),pe=async()=>{g(true),h(null);try{if(!a){let H=J();if(H){if(await H.open(),!await qe(l)){h("No wallet was connected.");return}}else {let L=Ue(p);if(!L){h("No wallet connector is configured.");return}try{await u({connector:L});}catch(M){if(!Me(M))throw M}}}let C=m??await Oe(l);if(!C){h("Wallet client is not available.");return}let D=await k({client:e,clients:C,networkID:n});if(D.ok){r();return}h(D.stage==="sign"?"Signature declined.":D.error??"Wallet sign-in failed.");}catch(C){console.error("[idosgames/wallet] wallet sign-in failed:",C),h(Ge(C));}finally{g(false);}};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{pe();},disabled:i||d,style:{...Ke,...i||d?{opacity:.6,cursor:"default"}:null,...c},children:d?"Check your wallet\u2026":a?o??"Sign in with wallet":"Connect wallet"}),v&&jsxRuntime.jsx("span",{role:"alert",style:je,children:v})]})}var Ke={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},je={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};function Ve(t){let{endpoint:e,wallets:n,autoConnect:r=true,children:i}=t;return jsxRuntime.jsx(walletAdapterReact.ConnectionProvider,{endpoint:e,children:jsxRuntime.jsx(walletAdapterReact.WalletProvider,{wallets:n,autoConnect:r,children:i})})}async function S(t){let{client:e,adapter:n,network:r,mint:i,amountRaw:o,titleID:c,category:l}=t,a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");if(o<=0n)return s("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:i,amountRaw:o,userID:a,titleID:c,category:core.normalizeBlockchainCategory(l)});}catch(m){return s("deposit-onchain",f(m))}let p=await e.blockchain.depositToken(r.NetworkID??"",u);return p.ok?{ok:true,onChainTxHash:u,data:p.data}:s("report",p.error,{onChainTxHash:u})}async function R(t){let{client:e,adapter:n,currencyID:r,networkID:i,walletAddress:o,amount:c,category:l}=t,a=await e.blockchain.requestTokenWithdrawal(r,i,o,c,l);if(!a.ok)return s("request",a.error);let u=a.data.SolanaSignature,p=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no Solana signature.",{titleTransactionID:p});let m;try{m=await n.submitWithdrawal(u);}catch(g){return s("withdraw-onchain",f(g),{titleTransactionID:p})}if(!p)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:m});let d=await e.blockchain.confirmWithdrawal(p,m);return d.ok?{ok:true,onChainTxHash:m,data:a.data}:s("confirm",d.error,{onChainTxHash:m,titleTransactionID:p})}async function F(t){let{client:e,networkID:n,walletAddress:r,signMessage:i}=t,o=await e.auth.requestWalletChallenge(r,n);if(!o.ok)return y("challenge",o.error);let c;try{let a=await i(new TextEncoder().encode(o.data.Message));c=Xe(a);}catch(a){return y("sign",f(a))}let l=await e.auth.loginWithWallet(r,n,c);return l.ok?{ok:true,data:l.data}:y("login",l.error)}function Xe(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}var ce="Wallet not connected.";function Ze(t,e,n){let{publicKey:r,signMessage:i}=walletAdapterReact.useWallet(),o=r?.toBase58()??null;return {connected:!!o,account:o,loginWithWallet:(c,l)=>{let a=l??o;return a?i?F({client:t,networkID:c,walletAddress:a,signMessage:i}):Promise.resolve(y("sign","The connected wallet does not support message signing.")):Promise.resolve(y("challenge",ce))},depositToken:c=>S({client:t,adapter:n,titleID:e,...c}),withdrawToken:c=>{let l=c.walletAddress??o;return l?R({client:t,adapter:n,...c,walletAddress:l}):Promise.resolve(s("request",ce))}}}
|
|
2
|
-
exports.IDosGamesWalletProvider=
|
|
1
|
+
'use strict';var wagmi=require('wagmi'),connectors=require('wagmi/connectors'),appkitAdapterWagmi=require('@reown/appkit-adapter-wagmi'),react=require('@reown/appkit/react'),reactQuery=require('@tanstack/react-query'),react$1=require('react'),jsxRuntime=require('react/jsx-runtime'),viem=require('viem'),core=require('@idosgames/core'),actions=require('wagmi/actions');var U={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},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"}}},j={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"}}},Y={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"}}},z={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"}}},V={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"}}},Z={mainnet:U,bsc:q,polygon:j,base:Y,arbitrum:z,optimism:_,sepolia:Q,polygonAmoy:V};function fe(t){return Object.values(Z).find(e=>e.id===t)}function $(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var J=null;function X(t){J=t;}function N(){return J}function ve(t){let{chains:e,walletConnectProjectId:n,appName:r,appUrl:o,appIcon:a,transports:d,connectors:l}=t,s={};for(let c of e)s[c.id]=d?.[c.id]??wagmi.http();let u=o??(typeof window<"u"?window.location.origin:""),p={name:r??"iDosGames",description:r??"iDosGames game",url:u,icons:a?[a]:[]};if(n&&!l){let c=e.map($),f=new appkitAdapterWagmi.WagmiAdapter({networks:c,projectId:n,transports:s});return X(react.createAppKit({adapters:[f],networks:c,projectId:n,metadata:p,features:{analytics:false,email:false,socials:false}})),f.wagmiConfig}let m=l??[connectors.injected(),connectors.coinbaseWallet({appName:r??"iDosGames"})];return wagmi.createConfig({chains:e,connectors:m,transports:s})}function D(t){let{wagmiConfig:e,queryClient:n,children:r}=t,[o]=react$1.useState(()=>n??new reactQuery.QueryClient);return jsxRuntime.jsx(wagmi.WagmiProvider,{config:e,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:o,children:r})})}var E=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],te=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],P=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],ne=[{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 re(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function y(t,e){let{walletClient:n,publicClient:r,account:o}=t,a=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:o,chain:n.chain,value:e.value});if((await r.waitForTransactionReceipt({hash:a})).status==="reverted")throw new Error(`On-chain transaction reverted (${a}).`);return a}function g(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function i(t,e,n){return {ok:false,stage:t,error:e,...n}}function h(t,e){return {ok:false,stage:t,error:e}}function oe(t){let e=t.RewardPoolAddress;return e||null}async function ae(t,e,n,r){return await t.publicClient.readContract({address:e,abi:P,functionName:"allowance",args:[t.account,n]})>=r?null:y(t,{address:e,abi:P,functionName:"approve",args:[n,r]})}async function I(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:a,titleID:d,category:l}=t,s=e.auth.context?.userID;if(!s)return i("approve","Not logged in.");let u=oe(r);if(!u)return i("approve","Network has no RewardPoolAddress.");if(a<=0n)return i("approve","Amount must be positive.");try{await ae(n,o,u,a);}catch(c){return i("approve",g(c))}let p;try{p=await y(n,{address:u,abi:E,functionName:"depositERC20",args:[o,a,s,d,l??""]});}catch(c){return i("deposit-onchain",g(c))}let m=await e.blockchain.depositToken(r.NetworkID??"",p);return m.ok?{ok:true,onChainTxHash:p,data:m.data}:i("report",m.error,{onChainTxHash:p})}async function B(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:a,amount:d,titleID:l,category:s}=t,u=e.auth.context?.userID;if(!u)return i("deposit-onchain","Not logged in.");let p=oe(r);if(!p)return i("deposit-onchain","Network has no RewardPoolAddress.");if(d<=0n)return i("deposit-onchain","Amount must be positive.");let m=re(u,l,s),c;try{c=await y(n,{address:o,abi:ne,functionName:"safeTransferFrom",args:[n.account,p,a,d,m]});}catch(k){return i("deposit-onchain",g(k))}let f=await e.blockchain.depositNFT(r.NetworkID??"",c);return f.ok?{ok:true,onChainTxHash:c,data:f.data}:i("report",f.error,{onChainTxHash:c})}async function ie(t,e){return y(t,{address:e.ContractAddress,abi:E,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function se(t,e){return y(t,{address:e.ContractAddress,abi:te,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function R(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:a,amount:d,category:l}=t,s=await e.blockchain.requestTokenWithdrawal(r,o,a,d,l);if(!s.ok)return i("request",s.error);let u=s.data.EvmSignature,p=s.data.TitleTransactionID??void 0;if(!u)return i("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let m;try{m=await ie(n,u);}catch(f){return i("withdraw-onchain",g(f),{titleTransactionID:p})}let c=await le(e,p,m);return c.ok?{ok:true,onChainTxHash:m,data:s.data}:c}async function S(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:a,amount:d,category:l}=t,s=await e.blockchain.requestNFTWithdrawal(r,o,a,d,l);if(!s.ok)return i("request",s.error);let u=s.data.EvmSignature,p=s.data.TitleTransactionID??void 0;if(!u)return i("request","Withdrawal response carried no EVM signature.",{titleTransactionID:p});let m;try{m=await se(n,u);}catch(f){return i("withdraw-onchain",g(f),{titleTransactionID:p})}let c=await le(e,p,m);return c.ok?{ok:true,onChainTxHash:m,data:s.data}:c}async function le(t,e,n){if(!e)return i("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:i("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function b(t){let{client:e,clients:n,networkID:r}=t,o=t.walletAddress??n.account,a=await e.auth.requestWalletChallenge(o,r);if(!a.ok)return h("challenge",a.error);let d;try{d=await n.walletClient.signMessage({account:n.account,message:a.data.Message});}catch(s){return h("sign",g(s))}let l=await e.auth.loginWithWallet(o,r,d);return l.ok?{ok:true,data:l.data}:h("login",l.error)}function A(){let{address:t}=wagmi.useAccount(),e=wagmi.usePublicClient(),{data:n}=wagmi.useWalletClient();return !t||!e||!n?null:{account:t,publicClient:e,walletClient:n}}var v="Wallet not connected.";function Be(t,e){let n=A();return {connected:!!n,account:n?.account??null,loginWithWallet:(r,o)=>n?b({client:t,clients:n,networkID:r,walletAddress:o}):Promise.resolve(h("challenge",v)),depositToken:r=>n?I({client:t,clients:n,titleID:e,...r}):Promise.resolve(i("approve",v)),depositNft:r=>n?B({client:t,clients:n,titleID:e,...r}):Promise.resolve(i("deposit-onchain",v)),withdrawToken:r=>n?R({client:t,clients:n,...r}):Promise.resolve(i("withdraw-onchain",v)),withdrawNft:r=>n?S({client:t,clients:n,...r}):Promise.resolve(i("withdraw-onchain",v))}}function Ge(t){let{wagmiConfig:e,...n}=t;return jsxRuntime.jsx(D,{wagmiConfig:e,children:jsxRuntime.jsx(pe,{...n})})}function Oe(t){return t instanceof Error&&(t.name==="ConnectorAlreadyConnectedError"||t.message.includes("already connected"))}function Ue(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 qe(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 je(t,e=18e4){return actions.getAccount(t).isConnected?Promise.resolve(true):new Promise(n=>{let r=false,o=l=>{r||(r=true,a(),clearTimeout(d),n(l));},a=actions.watchAccount(t,{onChange:l=>{l.isConnected&&o(true);}}),d=setTimeout(()=>o(false),e);})}function Ye(t){let e=o=>t.find(a=>a.id===o||a.type===o),n=e("injected"),r=typeof window<"u"&&window.ethereum!=null;return n&&r?n:e("walletConnect")??n??t[0]}var ze=9e4;async function _e(t){try{let r=(await actions.getAccount(t).connector?.getProvider?.())?.session?.peer?.metadata?.redirect,o=r?.native||r?.universal;return !o||typeof window>"u"?!1:(window.location.href=o,!0)}catch{return false}}function Qe(t,e){return new Promise((n,r)=>{let o=setTimeout(()=>r(new Error("The wallet request timed out.")),e);t.then(a=>{clearTimeout(o),n(a);},a=>{clearTimeout(o),r(a instanceof Error?a:new Error(String(a)));});})}function pe(t){let{client:e,networkID:n,onAuthenticated:r,disabled:o,label:a,style:d}=t,l=wagmi.useConfig(),{isConnected:s}=wagmi.useAccount(),{connectAsync:u,connectors:p}=wagmi.useConnect(),m=A(),[c,f]=react$1.useState(false),[k,w]=react$1.useState(null),[H,M]=react$1.useState(false),L=react$1.useRef(0),de=async()=>{let ue=++L.current,T=()=>L.current===ue;f(true),w(null);try{if(!s){let K=N();if(K){if(await K.open(),!await je(l)){w("No wallet was connected.");return}}else {let G=Ye(p);if(!G){w("No wallet connector is configured.");return}try{await u({connector:G});}catch(O){if(!Oe(O))throw O}}}let C=m??await qe(l);if(!C){w("Wallet client is not available.");return}M(!0);let W=await Qe(b({client:e,clients:C,networkID:n}),ze);if(!T())return;if(W.ok){r();return}w(W.stage==="sign"?"Signature declined.":W.error??"Wallet sign-in failed.");}catch(C){if(!T())return;console.error("[idosgames/wallet] wallet sign-in failed:",C),w(Ue(C));}finally{T()&&(f(false),M(false));}},me=async()=>{await _e(l)||await N()?.open();};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{H?me():de();},disabled:o,style:{...Ve,...o?{opacity:.6,cursor:"default"}:null,...d},children:H?"Waiting for signature \u2014 tap to open wallet":c?"Check your wallet\u2026":s?a??"Sign in with wallet":"Connect wallet"}),k&&jsxRuntime.jsx("span",{role:"alert",style:Ze,children:k})]})}var Ve={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Ze={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
|
|
2
|
+
exports.IDosGamesWalletProvider=D;exports.WalletLogin=Ge;exports.WalletLoginButton=pe;exports.arbitrum=z;exports.base=Y;exports.bsc=q;exports.chainById=fe;exports.createEvmWalletConfig=ve;exports.idosChains=Z;exports.mainnet=U;exports.optimism=_;exports.polygon=j;exports.polygonAmoy=V;exports.sepolia=Q;exports.useEvmBridge=Be;exports.useEvmBridgeClients=A;
|
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
|
-
import { W as WalletLoginResult,
|
|
4
|
-
export {
|
|
3
|
+
import { W as WalletLoginResult, b as BridgeResult } from '../chains-DMjdV7VV.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-DMjdV7VV.cjs';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode, CSSProperties } from 'react';
|
|
7
7
|
import { QueryClient } from '@tanstack/react-query';
|
|
8
8
|
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
9
|
-
import {
|
|
9
|
+
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, c as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-DgTjKpSf.cjs';
|
|
10
10
|
|
|
11
11
|
interface EvmWalletConfigOptions {
|
|
12
12
|
/** Chains the game supports, matching the EVM networks in the title's blockchain config. */
|
|
@@ -73,9 +73,9 @@ declare function IDosGamesWalletProvider(props: IDosGamesWalletProviderProps): r
|
|
|
73
73
|
* wallet is connected / the wallet client isn't ready yet.
|
|
74
74
|
*/
|
|
75
75
|
declare function useEvmBridgeClients(): EvmBridgeClients | null;
|
|
76
|
-
type DepositTokenArgs
|
|
76
|
+
type DepositTokenArgs = Omit<DepositTokenEvmParams, "client" | "clients" | "titleID">;
|
|
77
77
|
type DepositNftArgs = Omit<DepositNftEvmParams, "client" | "clients" | "titleID">;
|
|
78
|
-
type WithdrawTokenArgs
|
|
78
|
+
type WithdrawTokenArgs = Omit<WithdrawTokenEvmParams, "client" | "clients">;
|
|
79
79
|
type WithdrawNftArgs = Omit<WithdrawNftEvmParams, "client" | "clients">;
|
|
80
80
|
interface EvmBridge {
|
|
81
81
|
/** Whether a wallet is connected and its client is ready. */
|
|
@@ -88,9 +88,9 @@ interface EvmBridge {
|
|
|
88
88
|
* to the connected account. On success the core client is logged in and its ClientState returned.
|
|
89
89
|
*/
|
|
90
90
|
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
91
|
-
depositToken(args: DepositTokenArgs
|
|
91
|
+
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
92
92
|
depositNft(args: DepositNftArgs): Promise<BridgeResult<DepositNFTResponse>>;
|
|
93
|
-
withdrawToken(args: WithdrawTokenArgs
|
|
93
|
+
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
94
94
|
withdrawNft(args: WithdrawNftArgs): Promise<BridgeResult<NFTWithdrawalResponse>>;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -135,49 +135,4 @@ type WalletLoginButtonProps = Omit<WalletLoginProps, "wagmiConfig">;
|
|
|
135
135
|
/** The button itself. Must be rendered inside an {@link IDosGamesWalletProvider}. */
|
|
136
136
|
declare function WalletLoginButton(props: WalletLoginButtonProps): ReactNode;
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
/** RPC endpoint for the Solana network the title uses (matches its blockchain config). */
|
|
140
|
-
endpoint: string;
|
|
141
|
-
/**
|
|
142
|
-
* Wallet adapters to offer (e.g. `new PhantomWalletAdapter()` from
|
|
143
|
-
* `@solana/wallet-adapter-wallets`). Mobile support comes from adapters that implement it
|
|
144
|
-
* (Mobile Wallet Adapter on Android, or a WalletConnect adapter).
|
|
145
|
-
*/
|
|
146
|
-
wallets: Adapter[];
|
|
147
|
-
/** Auto-reconnect the last-used wallet on mount. */
|
|
148
|
-
autoConnect?: boolean;
|
|
149
|
-
children: ReactNode;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Thin wrapper over wallet-adapter's `ConnectionProvider` + `WalletProvider` so the
|
|
153
|
-
* {@link useSolanaBridge} hook has a connected wallet. Compose it alongside
|
|
154
|
-
* {@link IDosGamesWalletProvider} when a title supports both EVM and Solana networks.
|
|
155
|
-
*/
|
|
156
|
-
declare function SolanaWalletBridgeProvider(props: SolanaWalletBridgeProviderProps): react.JSX.Element;
|
|
157
|
-
|
|
158
|
-
type DepositTokenArgs = Omit<DepositTokenSolanaParams, "client" | "adapter" | "titleID">;
|
|
159
|
-
/** `walletAddress` defaults to the connected wallet if omitted. */
|
|
160
|
-
type WithdrawTokenArgs = Omit<WithdrawTokenSolanaParams, "client" | "adapter" | "walletAddress"> & {
|
|
161
|
-
walletAddress?: string;
|
|
162
|
-
};
|
|
163
|
-
interface SolanaBridge {
|
|
164
|
-
connected: boolean;
|
|
165
|
-
account: string | null;
|
|
166
|
-
/**
|
|
167
|
-
* Logs into the game with the connected Solana wallet by signing a server challenge (no tx, no
|
|
168
|
-
* fee). `networkID` is the cfg.Blockchain.Networks key; `walletAddress` defaults to the connected
|
|
169
|
-
* account. Requires a wallet that supports `signMessage`. Returns the fresh ClientState.
|
|
170
|
-
*/
|
|
171
|
-
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
172
|
-
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
173
|
-
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* The ergonomic Solana bridge hook: binds the connected wallet-adapter wallet + your
|
|
177
|
-
* {@link SolanaProgramAdapter} to the deposit/withdraw flows against a core client + title.
|
|
178
|
-
* The on-chain instruction building lives in the adapter (it owns the program IDL); this hook
|
|
179
|
-
* just wires the connected address and threads the request → submit → confirm lifecycle.
|
|
180
|
-
*/
|
|
181
|
-
declare function useSolanaBridge(client: IDosGamesClient, titleID: string, adapter: SolanaProgramAdapter): SolanaBridge;
|
|
182
|
-
|
|
183
|
-
export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, type SolanaBridge, SolanaWalletBridgeProvider, type SolanaWalletBridgeProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients, useSolanaBridge };
|
|
138
|
+
export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
|
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
|
-
import { W as WalletLoginResult,
|
|
4
|
-
export {
|
|
3
|
+
import { W as WalletLoginResult, b as BridgeResult } from '../chains-DMjdV7VV.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-DMjdV7VV.js';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode, CSSProperties } from 'react';
|
|
7
7
|
import { QueryClient } from '@tanstack/react-query';
|
|
8
8
|
import { ClientState, DepositTokenResponse, DepositNFTResponse, TokenWithdrawalResponse, NFTWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
9
|
-
import {
|
|
9
|
+
import { b as DepositTokenEvmParams, a as DepositNftEvmParams, c as WithdrawTokenEvmParams, W as WithdrawNftEvmParams, E as EvmBridgeClients } from '../withdraw-DTHssYc9.js';
|
|
10
10
|
|
|
11
11
|
interface EvmWalletConfigOptions {
|
|
12
12
|
/** Chains the game supports, matching the EVM networks in the title's blockchain config. */
|
|
@@ -73,9 +73,9 @@ declare function IDosGamesWalletProvider(props: IDosGamesWalletProviderProps): r
|
|
|
73
73
|
* wallet is connected / the wallet client isn't ready yet.
|
|
74
74
|
*/
|
|
75
75
|
declare function useEvmBridgeClients(): EvmBridgeClients | null;
|
|
76
|
-
type DepositTokenArgs
|
|
76
|
+
type DepositTokenArgs = Omit<DepositTokenEvmParams, "client" | "clients" | "titleID">;
|
|
77
77
|
type DepositNftArgs = Omit<DepositNftEvmParams, "client" | "clients" | "titleID">;
|
|
78
|
-
type WithdrawTokenArgs
|
|
78
|
+
type WithdrawTokenArgs = Omit<WithdrawTokenEvmParams, "client" | "clients">;
|
|
79
79
|
type WithdrawNftArgs = Omit<WithdrawNftEvmParams, "client" | "clients">;
|
|
80
80
|
interface EvmBridge {
|
|
81
81
|
/** Whether a wallet is connected and its client is ready. */
|
|
@@ -88,9 +88,9 @@ interface EvmBridge {
|
|
|
88
88
|
* to the connected account. On success the core client is logged in and its ClientState returned.
|
|
89
89
|
*/
|
|
90
90
|
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
91
|
-
depositToken(args: DepositTokenArgs
|
|
91
|
+
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
92
92
|
depositNft(args: DepositNftArgs): Promise<BridgeResult<DepositNFTResponse>>;
|
|
93
|
-
withdrawToken(args: WithdrawTokenArgs
|
|
93
|
+
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
94
94
|
withdrawNft(args: WithdrawNftArgs): Promise<BridgeResult<NFTWithdrawalResponse>>;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -135,49 +135,4 @@ type WalletLoginButtonProps = Omit<WalletLoginProps, "wagmiConfig">;
|
|
|
135
135
|
/** The button itself. Must be rendered inside an {@link IDosGamesWalletProvider}. */
|
|
136
136
|
declare function WalletLoginButton(props: WalletLoginButtonProps): ReactNode;
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
/** RPC endpoint for the Solana network the title uses (matches its blockchain config). */
|
|
140
|
-
endpoint: string;
|
|
141
|
-
/**
|
|
142
|
-
* Wallet adapters to offer (e.g. `new PhantomWalletAdapter()` from
|
|
143
|
-
* `@solana/wallet-adapter-wallets`). Mobile support comes from adapters that implement it
|
|
144
|
-
* (Mobile Wallet Adapter on Android, or a WalletConnect adapter).
|
|
145
|
-
*/
|
|
146
|
-
wallets: Adapter[];
|
|
147
|
-
/** Auto-reconnect the last-used wallet on mount. */
|
|
148
|
-
autoConnect?: boolean;
|
|
149
|
-
children: ReactNode;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Thin wrapper over wallet-adapter's `ConnectionProvider` + `WalletProvider` so the
|
|
153
|
-
* {@link useSolanaBridge} hook has a connected wallet. Compose it alongside
|
|
154
|
-
* {@link IDosGamesWalletProvider} when a title supports both EVM and Solana networks.
|
|
155
|
-
*/
|
|
156
|
-
declare function SolanaWalletBridgeProvider(props: SolanaWalletBridgeProviderProps): react.JSX.Element;
|
|
157
|
-
|
|
158
|
-
type DepositTokenArgs = Omit<DepositTokenSolanaParams, "client" | "adapter" | "titleID">;
|
|
159
|
-
/** `walletAddress` defaults to the connected wallet if omitted. */
|
|
160
|
-
type WithdrawTokenArgs = Omit<WithdrawTokenSolanaParams, "client" | "adapter" | "walletAddress"> & {
|
|
161
|
-
walletAddress?: string;
|
|
162
|
-
};
|
|
163
|
-
interface SolanaBridge {
|
|
164
|
-
connected: boolean;
|
|
165
|
-
account: string | null;
|
|
166
|
-
/**
|
|
167
|
-
* Logs into the game with the connected Solana wallet by signing a server challenge (no tx, no
|
|
168
|
-
* fee). `networkID` is the cfg.Blockchain.Networks key; `walletAddress` defaults to the connected
|
|
169
|
-
* account. Requires a wallet that supports `signMessage`. Returns the fresh ClientState.
|
|
170
|
-
*/
|
|
171
|
-
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
172
|
-
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
173
|
-
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* The ergonomic Solana bridge hook: binds the connected wallet-adapter wallet + your
|
|
177
|
-
* {@link SolanaProgramAdapter} to the deposit/withdraw flows against a core client + title.
|
|
178
|
-
* The on-chain instruction building lives in the adapter (it owns the program IDL); this hook
|
|
179
|
-
* just wires the connected address and threads the request → submit → confirm lifecycle.
|
|
180
|
-
*/
|
|
181
|
-
declare function useSolanaBridge(client: IDosGamesClient, titleID: string, adapter: SolanaProgramAdapter): SolanaBridge;
|
|
182
|
-
|
|
183
|
-
export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, type SolanaBridge, SolanaWalletBridgeProvider, type SolanaWalletBridgeProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients, useSolanaBridge };
|
|
138
|
+
export { type EvmBridge, type EvmWalletConfigOptions, IDosGamesWalletProvider, type IDosGamesWalletProviderProps, WalletLogin, WalletLoginButton, type WalletLoginButtonProps, type WalletLoginProps, createEvmWalletConfig, useEvmBridge, useEvmBridgeClients };
|
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {n
|
|
1
|
+
import {o,n as n$1,i,h,p}from'../chunk-NDNNLWPS.js';import {a,b as b$1}from'../chunk-ZL42KPPC.js';import {n,b,c}from'../chunk-XFMDEOHO.js';export{h as arbitrum,g as base,e as bsc,m as chainById,l as idosChains,d as mainnet,i as optimism,f as polygon,k as polygonAmoy,j as sepolia}from'../chunk-XFMDEOHO.js';import {http,createConfig,WagmiProvider,useAccount,usePublicClient,useWalletClient,useConfig,useConnect}from'wagmi';import {injected,coinbaseWallet}from'wagmi/connectors';import {WagmiAdapter}from'@reown/appkit-adapter-wagmi';import {createAppKit}from'@reown/appkit/react';import {QueryClient,QueryClientProvider}from'@tanstack/react-query';import {useState,useRef}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getAccount,watchAccount,getWalletClient,getPublicClient}from'wagmi/actions';function le(e){let{chains:o,walletConnectProjectId:t,appName:n$1,appUrl:r,appIcon:i,transports:p,connectors:s}=e,l={};for(let a of o)l[a.id]=p?.[a.id]??http();let y=r??(typeof window<"u"?window.location.origin:""),v={name:n$1??"iDosGames",description:n$1??"iDosGames game",url:y,icons:i?[i]:[]};if(t&&!s){let a$1=o.map(n),m=new WagmiAdapter({networks:a$1,projectId:t,transports:l});return a(createAppKit({adapters:[m],networks:a$1,projectId:t,metadata:v,features:{analytics:false,email:false,socials:false}})),m.wagmiConfig}let h=s??[injected(),coinbaseWallet({appName:n$1??"iDosGames"})];return createConfig({chains:o,connectors:h,transports:l})}function T(e){let{wagmiConfig:o,queryClient:t,children:n}=e,[r]=useState(()=>t??new QueryClient);return jsx(WagmiProvider,{config:o,children:jsx(QueryClientProvider,{client:r,children:n})})}function w(){let{address:e}=useAccount(),o=usePublicClient(),{data:t}=useWalletClient();return !e||!o||!t?null:{account:e,publicClient:o,walletClient:t}}var f="Wallet not connected.";function we(e,o$1){let t=w();return {connected:!!t,account:t?.account??null,loginWithWallet:(n,r)=>t?p({client:e,clients:t,networkID:n,walletAddress:r}):Promise.resolve(c("challenge",f)),depositToken:n=>t?h({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("approve",f)),depositNft:n=>t?i({client:e,clients:t,titleID:o$1,...n}):Promise.resolve(b("deposit-onchain",f)),withdrawToken:n=>t?n$1({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",f)),withdrawNft:n=>t?o({client:e,clients:t,...n}):Promise.resolve(b("withdraw-onchain",f))}}function Te(e){let{wagmiConfig:o,...t}=e;return jsx(T,{wagmiConfig:o,children:jsx(U,{...t})})}function be(e){return e instanceof Error&&(e.name==="ConnectorAlreadyConnectedError"||e.message.includes("already connected"))}function ke(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 Ne(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 De(e,o=18e4){return getAccount(e).isConnected?Promise.resolve(true):new Promise(t=>{let n=false,r=s=>{n||(n=true,i(),clearTimeout(p),t(s));},i=watchAccount(e,{onChange:s=>{s.isConnected&&r(true);}}),p=setTimeout(()=>r(false),o);})}function Ae(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 Re=9e4;async function Be(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 Ie(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 U(e){let{client:o,networkID:t,onAuthenticated:n,disabled:r,label:i,style:p$1}=e,s=useConfig(),{isConnected:l}=useAccount(),{connectAsync:y,connectors:v}=useConnect(),h=w(),[a,m]=useState(false),[k,c]=useState(null),[N,D]=useState(false),A=useRef(0),_=async()=>{let Q=++A.current,P=()=>A.current===Q;m(true),c(null);try{if(!l){let R=b$1();if(R){if(await R.open(),!await De(s)){c("No wallet was connected.");return}}else {let B=Ae(v);if(!B){c("No wallet connector is configured.");return}try{await y({connector:B});}catch(I){if(!be(I))throw I}}}let d=h??await Ne(s);if(!d){c("Wallet client is not available.");return}D(!0);let W=await Ie(p({client:o,clients:d,networkID:t}),Re);if(!P())return;if(W.ok){n();return}c(W.stage==="sign"?"Signature declined.":W.error??"Wallet sign-in failed.");}catch(d){if(!P())return;console.error("[idosgames/wallet] wallet sign-in failed:",d),c(ke(d));}finally{P()&&(m(false),D(false));}},M=async()=>{await Be(s)||await b$1()?.open();};return jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{N?M():_();},disabled:r,style:{...Se,...r?{opacity:.6,cursor:"default"}:null,...p$1},children:N?"Waiting for signature \u2014 tap to open wallet":a?"Check your wallet\u2026":l?i??"Sign in with wallet":"Connect wallet"}),k&&jsx("span",{role:"alert",style:xe,children:k})]})}var Se={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},xe={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{T as IDosGamesWalletProvider,Te as WalletLogin,U as WalletLoginButton,le as createEvmWalletConfig,we as useEvmBridge,w as useEvmBridgeClients};
|
|
@@ -0,0 +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 C={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"},G={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 L=null;function M(e){L=e;}function P(){return L}function z(e){let{walletConnectProjectId:t,appName:a,appUrl:s,appIcon:l,wallets:n}=e,p=e.networks??[C],o=s??(typeof window<"u"?window.location.origin:""),r={name:a??"iDosGames",description:a??"iDosGames game",url:o,icons:l?[l]:[]},i=new appkitAdapterSolana.SolanaAdapter(n?{wallets:n}:{});return M(react.createAppKit({adapters:[i],networks:p,projectId:t,metadata:r,features:{analytics:false,email:false,socials:false}})),i}function y(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 g(e,t){return {ok:false,stage:e,error:t}}async function v(e){let{client:t,adapter:a,network:s,mint:l,amountRaw:n,titleID:p,category:o}=e,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 i;try{i=await a.depositSpl({mint:l,amountRaw:n,userID:r,titleID:p,category:core.normalizeBlockchainCategory(o)});}catch(c){return d("deposit-onchain",y(c))}let u=await t.blockchain.depositToken(s.NetworkID??"",i);return u.ok?{ok:true,onChainTxHash:i,data:u.data}:d("report",u.error,{onChainTxHash:i})}async function E(e){let{client:t,adapter:a,currencyID:s,networkID:l,walletAddress:n,amount:p,category:o}=e,r=await t.blockchain.requestTokenWithdrawal(s,l,n,p,o);if(!r.ok)return d("request",r.error);let i=r.data.SolanaSignature,u=r.data.TitleTransactionID??void 0;if(!i)return d("request","Withdrawal response carried no Solana signature.",{titleTransactionID:u});let c;try{c=await a.submitWithdrawal(i);}catch(m){return d("withdraw-onchain",y(m),{titleTransactionID:u})}if(!u)return d("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let h=await t.blockchain.confirmWithdrawal(u,c);return h.ok?{ok:true,onChainTxHash:c,data:r.data}:d("confirm",h.error,{onChainTxHash:c,titleTransactionID:u})}async function S(e){let{client:t,networkID:a,walletAddress:s,signMessage:l}=e,n=await t.auth.requestWalletChallenge(s,a);if(!n.ok)return g("challenge",n.error);let p;try{let r=await l(new TextEncoder().encode(n.data.Message));p=$(r);}catch(r){return g("sign",y(r))}let o=await t.auth.loginWithWallet(s,a,p);return o.ok?{ok:true,data:o.data}:g("login",o.error)}function $(e){let t="0x";for(let a of e)t+=a.toString(16).padStart(2,"0");return t}var U="Wallet not connected.";function Q(e,t,a){let{address:s}=react.useAppKitAccount(),{walletProvider:l}=react.useAppKitProvider("solana"),n=s??null,p=l?.signMessage?.bind(l);return {connected:!!n,account:n,loginWithWallet:(o,r)=>{let i=r??n;return i?p?S({client:e,networkID:o,walletAddress:i,signMessage:p}):Promise.resolve(g("sign","The connected wallet does not support message signing.")):Promise.resolve(g("challenge",U))},depositToken:o=>v({client:e,adapter:a,titleID:t,...o}),withdrawToken:o=>{let r=o.walletAddress??n;return r?E({client:e,adapter:a,...o,walletAddress:r}):Promise.resolve(d("request",U))}}}var te=18e4,ae=9e4;function ne(e){try{let a=e?.session?.peer?.metadata?.redirect,s=a?.native||a?.universal;return !s||typeof window>"u"?!1:(window.location.href=s,!0)}catch{return false}}function re(e,t){return new Promise((a,s)=>{let l=setTimeout(()=>s(new Error("The wallet request timed out.")),t);e.then(n=>{clearTimeout(l),a(n);},n=>{clearTimeout(l),s(n instanceof Error?n:new Error(String(n)));});})}function oe(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 ie(e){let{client:t,networkID:a,onAuthenticated:s,disabled:l,label:n,style:p}=e,{address:o,isConnected:r}=react.useAppKitAccount(),{walletProvider:i}=react.useAppKitProvider("solana"),[u,c]=react$1.useState(false),[h,m]=react$1.useState(null),[I,b]=react$1.useState(false),[B,N]=react$1.useState(false),k=react$1.useRef(null),R=react$1.useRef(0),w=react$1.useCallback(()=>{k.current&&clearTimeout(k.current),k.current=null;},[]);react$1.useEffect(()=>w,[w]);let A=react$1.useCallback(async()=>{let T=++R.current,W=()=>R.current===T,K=i?.signMessage?.bind(i);if(!o||!K){m("The connected wallet cannot sign messages."),c(false);return}c(true),m(null);try{N(!0);let f=await re(S({client:t,networkID:a,walletAddress:o,signMessage:K}),ae);if(!W())return;if(f.ok){s();return}m(f.stage==="sign"?"Signature declined.":f.error??"Wallet sign-in failed.");}catch(f){if(!W())return;console.error("[idosgames/wallet] solana sign-in failed:",f),m(oe(f));}finally{W()&&(c(false),N(false));}},[o,i,t,a,s]),H=react$1.useCallback(()=>{ne(i)||P()?.open();},[i]);return react$1.useEffect(()=>{!I||!r||!o||!i||(b(false),w(),A());},[I,r,o,i,A,w]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{if(B){H();return}if(m(null),r&&o&&i){A();return}let T=P();if(!T){m("Wallet sign-in is not configured for this title.");return}c(true),b(true),w(),k.current=setTimeout(()=>{b(false),c(false),m("No wallet was connected.");},te),T.open();},disabled:l,style:{...se,...l?{opacity:.6,cursor:"default"}:null,...p},children:B?"Waiting for signature \u2014 tap to open wallet":u?"Check your wallet\u2026":r?n??"Sign in with wallet":"Connect wallet"}),h&&jsxRuntime.jsx("span",{role:"alert",style:le,children:h})]})}var se={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},le={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};
|
|
2
|
+
exports.SolanaWalletLogin=ie;exports.createSolanaWalletConfig=z;exports.solanaDevnet=G;exports.solanaMainnet=C;exports.useSolanaBridge=Q;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SolanaAdapter } from '@reown/appkit-adapter-solana';
|
|
2
|
+
import { BaseWalletAdapter } from '@solana/wallet-adapter-base';
|
|
3
|
+
import { a as AppKitSolanaNetwork, W as WalletLoginResult, b as BridgeResult } from '../chains-DMjdV7VV.cjs';
|
|
4
|
+
export { r as solanaDevnet, t as solanaMainnet } from '../chains-DMjdV7VV.cjs';
|
|
5
|
+
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
6
|
+
import { D as DepositTokenSolanaParams, W as WithdrawTokenSolanaParams, S as SolanaProgramAdapter } from '../bridge-BEEkIeZj.cjs';
|
|
7
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
8
|
+
import 'viem';
|
|
9
|
+
|
|
10
|
+
interface SolanaWalletConfigOptions {
|
|
11
|
+
/**
|
|
12
|
+
* WalletConnect Cloud / Reown project id. Required: it is what gives phones a working wallet at
|
|
13
|
+
* all. Solana's own Mobile Wallet Adapter is Android-only — on iOS a plain web page cannot reach
|
|
14
|
+
* a wallet app except through WalletConnect deep-links (or the wallet's in-app browser).
|
|
15
|
+
*/
|
|
16
|
+
walletConnectProjectId: string;
|
|
17
|
+
/** Networks the title supports. Defaults to Solana mainnet. */
|
|
18
|
+
networks?: [AppKitSolanaNetwork, ...AppKitSolanaNetwork[]];
|
|
19
|
+
/** App name/metadata shown in the wallet's connect prompt. */
|
|
20
|
+
appName?: string;
|
|
21
|
+
appUrl?: string;
|
|
22
|
+
appIcon?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Extra standard Solana wallet adapters (Phantom, Solflare, Mobile Wallet Adapter…).
|
|
25
|
+
*
|
|
26
|
+
* These do NOT replace the WalletConnect path — AppKit runs both: adapters cover browser
|
|
27
|
+
* extensions, wallet in-app browsers and Android's MWA, while WalletConnect covers iOS and any
|
|
28
|
+
* wallet the player has not installed as an extension. Wallet Standard already auto-detects most
|
|
29
|
+
* installed wallets, so this is only needed for ones that do not announce themselves.
|
|
30
|
+
*/
|
|
31
|
+
wallets?: BaseWalletAdapter[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds the Solana wallet stack for a title, on **Reown AppKit** — the same modal, session and
|
|
35
|
+
* deep-link machinery the EVM side uses, so both chains behave identically on a phone.
|
|
36
|
+
*
|
|
37
|
+
* A title is EVM or Solana, so exactly one of {@link createEvmWalletConfig} /
|
|
38
|
+
* `createSolanaWalletConfig` runs per game; both register the shared AppKit instance the sign-in
|
|
39
|
+
* button opens.
|
|
40
|
+
*/
|
|
41
|
+
declare function createSolanaWalletConfig(options: SolanaWalletConfigOptions): SolanaAdapter;
|
|
42
|
+
|
|
43
|
+
type DepositTokenArgs = Omit<DepositTokenSolanaParams, "client" | "adapter" | "titleID">;
|
|
44
|
+
/** `walletAddress` defaults to the connected wallet if omitted. */
|
|
45
|
+
type WithdrawTokenArgs = Omit<WithdrawTokenSolanaParams, "client" | "adapter" | "walletAddress"> & {
|
|
46
|
+
walletAddress?: string;
|
|
47
|
+
};
|
|
48
|
+
interface SolanaBridge {
|
|
49
|
+
connected: boolean;
|
|
50
|
+
account: string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Logs into the game with the connected Solana wallet by signing a server challenge (no tx, no
|
|
53
|
+
* fee). `networkID` is the cfg.Blockchain.Networks key; `walletAddress` defaults to the connected
|
|
54
|
+
* account. Requires a wallet that supports `signMessage`. Returns the fresh ClientState.
|
|
55
|
+
*/
|
|
56
|
+
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
57
|
+
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
58
|
+
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The ergonomic Solana bridge hook: binds the connected wallet-adapter wallet + your
|
|
62
|
+
* {@link SolanaProgramAdapter} to the deposit/withdraw flows against a core client + title.
|
|
63
|
+
* The on-chain instruction building lives in the adapter (it owns the program IDL); this hook
|
|
64
|
+
* just wires the connected address and threads the request → submit → confirm lifecycle.
|
|
65
|
+
*/
|
|
66
|
+
declare function useSolanaBridge(client: IDosGamesClient, titleID: string, adapter: SolanaProgramAdapter): SolanaBridge;
|
|
67
|
+
|
|
68
|
+
interface SolanaWalletLoginProps {
|
|
69
|
+
/** The (not yet authenticated) shared client. */
|
|
70
|
+
client: IDosGamesClient;
|
|
71
|
+
/** NetworkID the challenge is issued for — one of the title's configured networks. */
|
|
72
|
+
networkID: string;
|
|
73
|
+
/** Called once the wallet signature has been exchanged for a session. */
|
|
74
|
+
onAuthenticated: () => void;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
label?: string;
|
|
77
|
+
style?: CSSProperties;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Ready-made "sign in with wallet" button for **Solana** titles: connect → sign the challenge →
|
|
81
|
+
* session. The EVM twin is {@link WalletLogin}; a title is one or the other.
|
|
82
|
+
*
|
|
83
|
+
* Unlike the EVM button this needs no provider wrapper — AppKit is a global instance created by
|
|
84
|
+
* `createSolanaWalletConfig`, and the wallet is read through its hooks.
|
|
85
|
+
*
|
|
86
|
+
* Connecting and signing are one action for the player, but on a phone they are separated by an app
|
|
87
|
+
* switch: `appKit.open()` returns as soon as the modal is on screen, long before a wallet is picked
|
|
88
|
+
* and the deep-link round trip completes. So the click only *arms* the flow, and an effect fires the
|
|
89
|
+
* signature once the account actually appears — no polling, no second tap.
|
|
90
|
+
*/
|
|
91
|
+
declare function SolanaWalletLogin(props: SolanaWalletLoginProps): ReactNode;
|
|
92
|
+
|
|
93
|
+
export { AppKitSolanaNetwork, type SolanaBridge, type SolanaWalletConfigOptions, SolanaWalletLogin, type SolanaWalletLoginProps, createSolanaWalletConfig, useSolanaBridge };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SolanaAdapter } from '@reown/appkit-adapter-solana';
|
|
2
|
+
import { BaseWalletAdapter } from '@solana/wallet-adapter-base';
|
|
3
|
+
import { a as AppKitSolanaNetwork, W as WalletLoginResult, b as BridgeResult } from '../chains-DMjdV7VV.js';
|
|
4
|
+
export { r as solanaDevnet, t as solanaMainnet } from '../chains-DMjdV7VV.js';
|
|
5
|
+
import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
|
|
6
|
+
import { D as DepositTokenSolanaParams, W as WithdrawTokenSolanaParams, S as SolanaProgramAdapter } from '../bridge-BzZmMMxK.js';
|
|
7
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
8
|
+
import 'viem';
|
|
9
|
+
|
|
10
|
+
interface SolanaWalletConfigOptions {
|
|
11
|
+
/**
|
|
12
|
+
* WalletConnect Cloud / Reown project id. Required: it is what gives phones a working wallet at
|
|
13
|
+
* all. Solana's own Mobile Wallet Adapter is Android-only — on iOS a plain web page cannot reach
|
|
14
|
+
* a wallet app except through WalletConnect deep-links (or the wallet's in-app browser).
|
|
15
|
+
*/
|
|
16
|
+
walletConnectProjectId: string;
|
|
17
|
+
/** Networks the title supports. Defaults to Solana mainnet. */
|
|
18
|
+
networks?: [AppKitSolanaNetwork, ...AppKitSolanaNetwork[]];
|
|
19
|
+
/** App name/metadata shown in the wallet's connect prompt. */
|
|
20
|
+
appName?: string;
|
|
21
|
+
appUrl?: string;
|
|
22
|
+
appIcon?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Extra standard Solana wallet adapters (Phantom, Solflare, Mobile Wallet Adapter…).
|
|
25
|
+
*
|
|
26
|
+
* These do NOT replace the WalletConnect path — AppKit runs both: adapters cover browser
|
|
27
|
+
* extensions, wallet in-app browsers and Android's MWA, while WalletConnect covers iOS and any
|
|
28
|
+
* wallet the player has not installed as an extension. Wallet Standard already auto-detects most
|
|
29
|
+
* installed wallets, so this is only needed for ones that do not announce themselves.
|
|
30
|
+
*/
|
|
31
|
+
wallets?: BaseWalletAdapter[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds the Solana wallet stack for a title, on **Reown AppKit** — the same modal, session and
|
|
35
|
+
* deep-link machinery the EVM side uses, so both chains behave identically on a phone.
|
|
36
|
+
*
|
|
37
|
+
* A title is EVM or Solana, so exactly one of {@link createEvmWalletConfig} /
|
|
38
|
+
* `createSolanaWalletConfig` runs per game; both register the shared AppKit instance the sign-in
|
|
39
|
+
* button opens.
|
|
40
|
+
*/
|
|
41
|
+
declare function createSolanaWalletConfig(options: SolanaWalletConfigOptions): SolanaAdapter;
|
|
42
|
+
|
|
43
|
+
type DepositTokenArgs = Omit<DepositTokenSolanaParams, "client" | "adapter" | "titleID">;
|
|
44
|
+
/** `walletAddress` defaults to the connected wallet if omitted. */
|
|
45
|
+
type WithdrawTokenArgs = Omit<WithdrawTokenSolanaParams, "client" | "adapter" | "walletAddress"> & {
|
|
46
|
+
walletAddress?: string;
|
|
47
|
+
};
|
|
48
|
+
interface SolanaBridge {
|
|
49
|
+
connected: boolean;
|
|
50
|
+
account: string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Logs into the game with the connected Solana wallet by signing a server challenge (no tx, no
|
|
53
|
+
* fee). `networkID` is the cfg.Blockchain.Networks key; `walletAddress` defaults to the connected
|
|
54
|
+
* account. Requires a wallet that supports `signMessage`. Returns the fresh ClientState.
|
|
55
|
+
*/
|
|
56
|
+
loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
|
|
57
|
+
depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
|
|
58
|
+
withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The ergonomic Solana bridge hook: binds the connected wallet-adapter wallet + your
|
|
62
|
+
* {@link SolanaProgramAdapter} to the deposit/withdraw flows against a core client + title.
|
|
63
|
+
* The on-chain instruction building lives in the adapter (it owns the program IDL); this hook
|
|
64
|
+
* just wires the connected address and threads the request → submit → confirm lifecycle.
|
|
65
|
+
*/
|
|
66
|
+
declare function useSolanaBridge(client: IDosGamesClient, titleID: string, adapter: SolanaProgramAdapter): SolanaBridge;
|
|
67
|
+
|
|
68
|
+
interface SolanaWalletLoginProps {
|
|
69
|
+
/** The (not yet authenticated) shared client. */
|
|
70
|
+
client: IDosGamesClient;
|
|
71
|
+
/** NetworkID the challenge is issued for — one of the title's configured networks. */
|
|
72
|
+
networkID: string;
|
|
73
|
+
/** Called once the wallet signature has been exchanged for a session. */
|
|
74
|
+
onAuthenticated: () => void;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
label?: string;
|
|
77
|
+
style?: CSSProperties;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Ready-made "sign in with wallet" button for **Solana** titles: connect → sign the challenge →
|
|
81
|
+
* session. The EVM twin is {@link WalletLogin}; a title is one or the other.
|
|
82
|
+
*
|
|
83
|
+
* Unlike the EVM button this needs no provider wrapper — AppKit is a global instance created by
|
|
84
|
+
* `createSolanaWalletConfig`, and the wallet is read through its hooks.
|
|
85
|
+
*
|
|
86
|
+
* Connecting and signing are one action for the player, but on a phone they are separated by an app
|
|
87
|
+
* switch: `appKit.open()` returns as soon as the modal is on screen, long before a wallet is picked
|
|
88
|
+
* and the deep-link round trip completes. So the click only *arms* the flow, and an effect fires the
|
|
89
|
+
* signature once the account actually appears — no polling, no second tap.
|
|
90
|
+
*/
|
|
91
|
+
declare function SolanaWalletLogin(props: SolanaWalletLoginProps): ReactNode;
|
|
92
|
+
|
|
93
|
+
export { AppKitSolanaNetwork, type SolanaBridge, type SolanaWalletConfigOptions, SolanaWalletLogin, type SolanaWalletLoginProps, createSolanaWalletConfig, useSolanaBridge };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b,a as a$1,c}from'../chunk-ACZSIOFR.js';import {a,b as b$2}from'../chunk-ZL42KPPC.js';import {o,b as b$1,c as c$1}from'../chunk-XFMDEOHO.js';export{p as solanaDevnet,o as solanaMainnet}from'../chunk-XFMDEOHO.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 z(e){let{walletConnectProjectId:a$1,appName:r,appUrl:i,appIcon:s,wallets:t}=e,d=e.networks??[o],n=i??(typeof window<"u"?window.location.origin:""),l={name:r??"iDosGames",description:r??"iDosGames game",url:n,icons:s?[s]:[]},o$1=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[o$1],networks:d,projectId:a$1,metadata:l,features:{analytics:false,email:false,socials:false}})),o$1}var B="Wallet not connected.";function J(e,a,r){let{address:i}=useAppKitAccount(),{walletProvider:s}=useAppKitProvider("solana"),t=i??null,d=s?.signMessage?.bind(s);return {connected:!!t,account:t,loginWithWallet:(n,l)=>{let o=l??t;return o?d?c({client:e,networkID:n,walletAddress:o,signMessage:d}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",B))},depositToken:n=>a$1({client:e,adapter:r,titleID:a,...n}),withdrawToken:n=>{let l=n.walletAddress??t;return l?b({client:e,adapter:r,...n,walletAddress:l}):Promise.resolve(b$1("request",B))}}}var X=18e4,Y=9e4;function Z(e){try{let r=e?.session?.peer?.metadata?.redirect,i=r?.native||r?.universal;return !i||typeof window>"u"?!1:(window.location.href=i,!0)}catch{return false}}function $(e,a){return new Promise((r,i)=>{let s=setTimeout(()=>i(new Error("The wallet request timed out.")),a);e.then(t=>{clearTimeout(s),r(t);},t=>{clearTimeout(s),i(t instanceof Error?t:new Error(String(t)));});})}function ee(e){let a="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.":a:a}function te(e){let{client:a,networkID:r,onAuthenticated:i,disabled:s,label:t,style:d}=e,{address:n,isConnected:l}=useAppKitAccount(),{walletProvider:o}=useAppKitProvider("solana"),[G,u]=useState(false),[C,p]=useState(null),[b,T]=useState(false),[v,D]=useState(false),g=useRef(null),R=useRef(0),f=useCallback(()=>{g.current&&clearTimeout(g.current),g.current=null;},[]);useEffect(()=>f,[f]);let y=useCallback(async()=>{let m=++R.current,k=()=>R.current===m,I=o?.signMessage?.bind(o);if(!n||!I){p("The connected wallet cannot sign messages."),u(false);return}u(true),p(null);try{D(!0);let c$1=await $(c({client:a,networkID:r,walletAddress:n,signMessage:I}),Y);if(!k())return;if(c$1.ok){i();return}p(c$1.stage==="sign"?"Signature declined.":c$1.error??"Wallet sign-in failed.");}catch(c){if(!k())return;console.error("[idosgames/wallet] solana sign-in failed:",c),p(ee(c));}finally{k()&&(u(false),D(false));}},[n,o,a,r,i]),_=useCallback(()=>{Z(o)||b$2()?.open();},[o]);return useEffect(()=>{!b||!l||!n||!o||(T(false),f(),y());},[b,l,n,o,y,f]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:()=>{if(v){_();return}if(p(null),l&&n&&o){y();return}let m=b$2();if(!m){p("Wallet sign-in is not configured for this title.");return}u(true),T(true),f(),g.current=setTimeout(()=>{T(false),u(false),p("No wallet was connected.");},X),m.open();},disabled:s,style:{...ne,...s?{opacity:.6,cursor:"default"}:null,...d},children:v?"Waiting for signature \u2014 tap to open wallet":G?"Check your wallet\u2026":l?t??"Sign in with wallet":"Connect wallet"}),C&&jsx("span",{role:"alert",style:oe,children:C})]})}var ne={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},oe={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{te as SolanaWalletLogin,z as createSolanaWalletConfig,J as useSolanaBridge};
|