@betswirl/wagmi-provider
Version:
Wagmi client & wallet for Betswirl core SDK
2 lines • 8.08 kB
JavaScript
import {BetSwirlWallet,wrappedGasTokenById,BetSwirlClient,waitRolledBet,WEIGHTED_CASINO_GAME_TYPES,placeCoinTossBet,placeCoinTossFreebet,waitCoinTossRolledBet,placeDiceBet,placeDiceFreebet,waitDiceRolledBet,placeRouletteBet,placeRouletteFreebet,waitRouletteRolledBet,placeKenoBet,placeKenoFreebet,waitKenoRolledBet,placeWheelBet,placeWheelFreebet,waitWheelRolledBet,placePlinkoBet,placePlinkoFreebet,waitPlinkoRolledBet,placeWeightedGameBet,placeWeightedGameFreebet,getCasinoGames,getCasinoTokens,casinoChainById,getCasinoGameToken,getBetRequirements,getChainlinkVrfCost,getKenoConfiguration,getWeightedGameConfiguration,getClaimableAmount,claimLeaderboardRewards}from'@betswirl/sdk-core';import {getPublicClient,call,readContract,readContracts,getTransactionReceipt,watchContractEvent,simulateContract,writeContract,waitForTransactionReceipt,switchChain}from'@wagmi/core';var p=Object.defineProperty;var u=(s,n,e)=>n in s?p(s,n,{enumerable:true,configurable:true,writable:true,value:e}):s[n]=e;var l=(s,n,e)=>u(s,n+"",e);var r=class extends BetSwirlWallet{constructor(e){super();l(this,"wagmiConfig");this.wagmiConfig=e;}getChainId(){return this.wagmiConfig.state.chainId}getAccount(e){if(!(this.wagmiConfig.connectors.length>0))return this.wagmiConfig.getClient({chainId:e}).account}getPublicClient(e){return getPublicClient(this.wagmiConfig,{chainId:e})}async readContract(e,t){return t&&typeof t=="bigint"?call(this.wagmiConfig,{to:e.data.to,data:e.encodedData,gasPrice:t,gas:3000000n,account:wrappedGasTokenById[this.getChainId()]}):readContract(this.wagmiConfig,{address:e.data.to,abi:e.data.abi,functionName:e.data.functionName,args:e.data.args})}async readContracts(e){let t=e.map(a=>({address:a.data.to,abi:a.data.abi,functionName:a.data.functionName,args:a.data.args})),i=await readContracts(this.wagmiConfig,{contracts:t});if(i.some(a=>a.status==="failure"||a===void 0))throw new Error("[wagmiWallet] An error occured while reading contracts");return i.map(a=>a.result)}async getTransactionReceipt(e){return getTransactionReceipt(this.wagmiConfig,{hash:e})}watchContractEvent(e){return watchContractEvent(this.wagmiConfig,{address:e.data.to,abi:e.data.abi,eventName:e.data.eventName,args:e.data.args,pollingInterval:e.data.pollingInterval,onLogs:t=>e.callbacks.onLogs?.(t),onError:t=>e.callbacks.onError?.(t)})}async writeContract(e,t,i){let{request:a}=await simulateContract(this.wagmiConfig,{address:e.data.to,abi:e.data.abi,functionName:e.data.functionName,args:e.data.args,gasPrice:i,account:this.getAccount(),value:t});return await writeContract(this.wagmiConfig,a)}async waitTransaction(e,t){return await waitForTransactionReceipt(this.wagmiConfig,{hash:e,pollingInterval:t})}};var o=class s extends BetSwirlClient{constructor(e,t={}){super(new r(e),t);l(this,"wagmiConfig");this.wagmiConfig=e;}async waitRolledBet(e,t,i,a){return await this._switchChain(e.chainId),WEIGHTED_CASINO_GAME_TYPES.includes(e.game)?waitRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i,a):waitRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playCoinToss(e,t,i,a){return await this._switchChain(a),placeCoinTossBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetCoinToss(e,t,i){return await this._switchChain(e.freebet.chainId),placeCoinTossFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitCoinToss(e,t){return await this._switchChain(e.chainId),waitCoinTossRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playDice(e,t,i,a){return await this._switchChain(a),placeDiceBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetDice(e,t,i){return await this._switchChain(e.freebet.chainId),placeDiceFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitDice(e,t){return await this._switchChain(e.chainId),waitDiceRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playRoulette(e,t,i,a){return await this._switchChain(a),placeRouletteBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetRoulette(e,t,i){return await this._switchChain(e.freebet.chainId),placeRouletteFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitRoulette(e,t){return await this._switchChain(e.chainId),waitRouletteRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playKeno(e,t,i,a){return await this._switchChain(a),placeKenoBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetKeno(e,t,i){return await this._switchChain(e.freebet.chainId),placeKenoFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitKeno(e,t){return await this._switchChain(e.chainId),waitKenoRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playWheel(e,t,i,a){return await this._switchChain(a),placeWheelBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetWheel(e,t,i){return await this._switchChain(e.freebet.chainId),placeWheelFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitWheel(e,t,i,a){return await this._switchChain(e.chainId),waitWheelRolledBet(this.betSwirlWallet,e,t,i,{...this.betSwirlDefaultOptions,...a})}async playPlinko(e,t,i,a){return await this._switchChain(a),placePlinkoBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetPlinko(e,t,i){return await this._switchChain(e.freebet.chainId),placePlinkoFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitPlinko(e,t,i,a){return await this._switchChain(e.chainId),waitPlinkoRolledBet(this.betSwirlWallet,e,t,i,{...this.betSwirlDefaultOptions,...a})}async playWeightedGame(e,t,i,a){return await this._switchChain(a),placeWeightedGameBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetWeightedGame(e,t,i){return await this._switchChain(e.freebet.chainId),placeWeightedGameFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async getCasinoGames(e=false,t){return await this._switchChain(t),getCasinoGames(this.betSwirlWallet,e)}async getCasinoTokens(e=false,t){return await this._switchChain(t),getCasinoTokens(this.betSwirlWallet,e)}async getCasinoGameToken(e,t,i){let a=casinoChainById[e.chainId];return await this._switchChain(e.chainId),getCasinoGameToken(this.betSwirlWallet,e,t,i||a.defaultAffiliate)}async getBetRequirements(e,t,i,a){return await this._switchChain(a),getBetRequirements(this.betSwirlWallet,e,t,i)}async getChainlinkVrfCost(e,t,i,a,c,w){return await this._switchChain(w),getChainlinkVrfCost(this.betSwirlWallet,e,t,i,a||this.betSwirlDefaultOptions.gasPrice,c||this.betSwirlDefaultOptions.gasPriceType)}async getKenoConfiguration(e,t){return await this._switchChain(t),getKenoConfiguration(this.betSwirlWallet,e)}async getWeighedGameConfiguration(e,t){return await this._switchChain(t),getWeightedGameConfiguration(this.betSwirlWallet,e)}async getClaimableAmount(e,t,i){return await this._switchChain(i),getClaimableAmount(this.betSwirlWallet,e,t,i)}async claimLeaderboardRewards(e,t,i){return await this._switchChain(e.chainId),claimLeaderboardRewards(this.betSwirlWallet,e,t,this.betSwirlDefaultOptions.pollingInterval,i)}async _switchChain(e){let t=e||this.betSwirlDefaultOptions.chainId;t&&await this.betSwirlWallet.getChainId()!==t&&await switchChain(this.wagmiConfig,{chainId:t});}static init(e,t){return new s(e,t)}};function ue(s,n){return o.init(s,n)}export{o as WagmiBetSwirlClient,r as WagmiBetSwirlWallet,ue as initWagmiBetSwirlClient};//# sourceMappingURL=index.mjs.map
//# sourceMappingURL=index.mjs.map