UNPKG

@betswirl/wagmi-provider

Version:

Wagmi client & wallet for Betswirl core SDK

2 lines 7.63 kB
'use strict';var sdkCore=require('@betswirl/sdk-core'),core=require('@wagmi/core');var w=Object.defineProperty;var p=(s,n,e)=>n in s?w(s,n,{enumerable:true,configurable:true,writable:true,value:e}):s[n]=e;var l=(s,n,e)=>p(s,n+"",e);var r=class extends sdkCore.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 core.getPublicClient(this.wagmiConfig,{chainId:e})}async readContract(e,t){return t&&typeof t=="bigint"?core.call(this.wagmiConfig,{to:e.data.to,data:e.encodedData,gasPrice:t,gas:3000000n,account:sdkCore.wrappedGasTokenById[this.getChainId()]}):core.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 core.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 core.getTransactionReceipt(this.wagmiConfig,{hash:e})}watchContractEvent(e){return core.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 core.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 core.writeContract(this.wagmiConfig,a)}async waitTransaction(e,t){return await core.waitForTransactionReceipt(this.wagmiConfig,{hash:e,pollingInterval:t})}};var o=class s extends sdkCore.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),sdkCore.WEIGHTED_CASINO_GAME_TYPES.includes(e.game)?sdkCore.waitRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i,a):sdkCore.waitRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playCoinToss(e,t,i,a){return await this._switchChain(a),sdkCore.placeCoinTossBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetCoinToss(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeCoinTossFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitCoinToss(e,t){return await this._switchChain(e.chainId),sdkCore.waitCoinTossRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playDice(e,t,i,a){return await this._switchChain(a),sdkCore.placeDiceBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetDice(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeDiceFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitDice(e,t){return await this._switchChain(e.chainId),sdkCore.waitDiceRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playRoulette(e,t,i,a){return await this._switchChain(a),sdkCore.placeRouletteBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetRoulette(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeRouletteFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitRoulette(e,t){return await this._switchChain(e.chainId),sdkCore.waitRouletteRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playKeno(e,t,i,a){return await this._switchChain(a),sdkCore.placeKenoBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetKeno(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeKenoFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitKeno(e,t){return await this._switchChain(e.chainId),sdkCore.waitKenoRolledBet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t})}async playWheel(e,t,i,a){return await this._switchChain(a),sdkCore.placeWheelBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetWheel(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeWheelFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitWheel(e,t,i,a){return await this._switchChain(e.chainId),sdkCore.waitWheelRolledBet(this.betSwirlWallet,e,t,i,{...this.betSwirlDefaultOptions,...a})}async playPlinko(e,t,i,a){return await this._switchChain(a),sdkCore.placePlinkoBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetPlinko(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placePlinkoFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async waitPlinko(e,t,i,a){return await this._switchChain(e.chainId),sdkCore.waitPlinkoRolledBet(this.betSwirlWallet,e,t,i,{...this.betSwirlDefaultOptions,...a})}async playWeightedGame(e,t,i,a){return await this._switchChain(a),sdkCore.placeWeightedGameBet(this.betSwirlWallet,{...e,affiliate:this.betSwirlDefaultOptions.affiliate},{...this.betSwirlDefaultOptions,...t},i)}async playFreebetWeightedGame(e,t,i){return await this._switchChain(e.freebet.chainId),sdkCore.placeWeightedGameFreebet(this.betSwirlWallet,e,{...this.betSwirlDefaultOptions,...t},i)}async getCasinoGames(e=false,t){return await this._switchChain(t),sdkCore.getCasinoGames(this.betSwirlWallet,e)}async getCasinoTokens(e=false,t){return await this._switchChain(t),sdkCore.getCasinoTokens(this.betSwirlWallet,e)}async getCasinoGameToken(e,t,i){let a=sdkCore.casinoChainById[e.chainId];return await this._switchChain(e.chainId),sdkCore.getCasinoGameToken(this.betSwirlWallet,e,t,i||a.defaultAffiliate)}async getBetRequirements(e,t,i,a){return await this._switchChain(a),sdkCore.getBetRequirements(this.betSwirlWallet,e,t,i)}async getChainlinkVrfCost(e,t,i,a,c,C){return await this._switchChain(C),sdkCore.getChainlinkVrfCost(this.betSwirlWallet,e,t,i,a||this.betSwirlDefaultOptions.gasPrice,c||this.betSwirlDefaultOptions.gasPriceType)}async getKenoConfiguration(e,t){return await this._switchChain(t),sdkCore.getKenoConfiguration(this.betSwirlWallet,e)}async getWeighedGameConfiguration(e,t){return await this._switchChain(t),sdkCore.getWeightedGameConfiguration(this.betSwirlWallet,e)}async getClaimableAmount(e,t,i){return await this._switchChain(i),sdkCore.getClaimableAmount(this.betSwirlWallet,e,t,i)}async claimLeaderboardRewards(e,t,i){return await this._switchChain(e.chainId),sdkCore.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 core.switchChain(this.wagmiConfig,{chainId:t});}static init(e,t){return new s(e,t)}};function pe(s,n){return o.init(s,n)}exports.WagmiBetSwirlClient=o;exports.WagmiBetSwirlWallet=r;exports.initWagmiBetSwirlClient=pe;//# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map