commit
4cd62bca4f
4 changed files with 17 additions and 28 deletions
|
@ -1,14 +1,16 @@
|
||||||
import {usePlayRoulette} from "../../web3/functions/Roulette/usePlayRoulette.ts";
|
import {usePlayRoulette} from "../../web3/functions/Roulette/usePlayRoulette.ts";
|
||||||
import {FC, useEffect} from "react";
|
import {FC, useEffect} from "react";
|
||||||
|
import {usePlayCraps} from "../../web3/functions/Craps/usePlayCraps.ts";
|
||||||
|
|
||||||
interface DicePlayButtonProps {
|
interface DicePlayButtonProps {
|
||||||
value: number
|
value: number
|
||||||
onSuccess: (result: unknown) => void
|
onSuccess: (result: unknown) => void
|
||||||
onLoading: () => void
|
onLoading: () => void
|
||||||
|
secondValue: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DicePlayButton: FC<DicePlayButtonProps> = ({ value, onSuccess, onLoading }) => {
|
export const DicePlayButton: FC<DicePlayButtonProps> = ({ value, onSuccess, onLoading, secondValue }) => {
|
||||||
const { playRoulette, result, isLoading } = usePlayRoulette()
|
const { playCraps, result, isLoading } = usePlayCraps()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (result) onSuccess(result)
|
if (result) onSuccess(result)
|
||||||
|
@ -19,7 +21,7 @@ export const DicePlayButton: FC<DicePlayButtonProps> = ({ value, onSuccess, onLo
|
||||||
}, [isLoading])
|
}, [isLoading])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button onClick={() => { playRoulette(value) }} className="bg-rose-700 rounded-[100px] shadow text-white text-2xl font-bold py-5 px-10 hover:bg-rose-600">
|
<button onClick={() => { playCraps(value, secondValue) }} className="bg-rose-700 rounded-[100px] shadow text-white text-2xl font-bold py-5 px-10 hover:bg-rose-600">
|
||||||
{
|
{
|
||||||
isLoading && 'Loading'
|
isLoading && 'Loading'
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,10 @@ export const DiceGamePage = observer(() => {
|
||||||
<img src={diceImg} alt="Dice" />
|
<img src={diceImg} alt="Dice" />
|
||||||
</div>
|
</div>
|
||||||
{/* Кнопка для бека */}
|
{/* Кнопка для бека */}
|
||||||
<DicePlayButton onLoading={onLoading} onSuccess={onSuccess} value={5}/>
|
<DicePlayButton onLoading={onLoading} onSuccess={onSuccess} value={5} secondValue={6}/>
|
||||||
<div className="flex flex-row justify-around w-full font-semibold">
|
<div className="flex flex-row justify-around w-full font-semibold">
|
||||||
<div className="bg-gray-500 rounded-[30px] py-5 px-10 text-2xl">
|
<div className="bg-gray-500 rounded-[30px] py-5 px-10 text-2xl">
|
||||||
Вы загадали: 5
|
Вы загадали: 5 и 6
|
||||||
</div>
|
</div>
|
||||||
{(diceValue && !isLoading) && <div className="bg-gray-800 rounded-[30px] py-5 px-10 text-2xl">
|
{(diceValue && !isLoading) && <div className="bg-gray-800 rounded-[30px] py-5 px-10 text-2xl">
|
||||||
Выпало число: {diceValue}
|
Выпало число: {diceValue}
|
||||||
|
|
|
@ -1,34 +1,22 @@
|
||||||
import {useWalletConnect} from "@cityofzion/wallet-connect-sdk-react";
|
import {useWalletConnect} from "@cityofzion/wallet-connect-sdk-react";
|
||||||
import {useCallback} from "react";
|
import {useCallback} from "react";
|
||||||
import {useGetResult} from "../utils/useGetResult.ts";
|
import {useGetResult} from "../utils/useGetResult.ts";
|
||||||
import {useStatusState} from "../../../hooks/useStatusState.ts";
|
import {config} from "../config/config.ts";
|
||||||
import { config } from "../config/config.ts";
|
|
||||||
|
|
||||||
export const usePlayCraps = () => {
|
export const usePlayCraps = () => {
|
||||||
const wcSdk = useWalletConnect()
|
const wcSdk = useWalletConnect()
|
||||||
const { getResult } = useGetResult()
|
const { getResult, ...statuses } = useGetResult()
|
||||||
const { statuses, wrapPromise } = useStatusState()
|
|
||||||
|
|
||||||
const playCraps = useCallback(wrapPromise(async () => {
|
const playCraps = useCallback(async (value: number, secondValue: number) => {
|
||||||
// const resp = await wcSdk.invokeFunction({
|
console.log(config.craps.contractAddress)
|
||||||
// invocations: [{
|
|
||||||
// scriptHash: '270c825a5ac041e18be45074bbb942255164a214',
|
|
||||||
// operation: 'balanceOf',
|
|
||||||
// args: [
|
|
||||||
// { type: 'Hash160', value: 'NQCLAHuu4umnR99KB5m7U8ppJFtWqhw6DS' },
|
|
||||||
// ]
|
|
||||||
// }],
|
|
||||||
// signers: [{
|
|
||||||
// scopes: 'Global',
|
|
||||||
// }]
|
|
||||||
// })
|
|
||||||
const resp = await wcSdk.invokeFunction({
|
const resp = await wcSdk.invokeFunction({
|
||||||
invocations: [{
|
invocations: [{
|
||||||
scriptHash: config.craps.contractAddress,
|
scriptHash: config.craps.contractAddress,
|
||||||
operation: 'playRoulette',
|
operation: 'playCraps',
|
||||||
args: [
|
args: [
|
||||||
{ type: 'Integer', value: '40' },
|
{ type: 'Integer', value: '40' },
|
||||||
{ type: 'Integer', value: '3' },
|
{ type: 'Integer', value: value.toString() },
|
||||||
|
{ type: 'Integer', value: secondValue.toString() },
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
signers: [{
|
signers: [{
|
||||||
|
@ -36,9 +24,8 @@ export const usePlayCraps = () => {
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
console.log(resp)
|
console.log(resp)
|
||||||
const result = await getResult(resp)
|
await getResult(resp, 'rouletteNumber')
|
||||||
console.log(result)
|
}, [wcSdk, getResult])
|
||||||
}), [wcSdk, getResult, wrapPromise])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
playCraps,
|
playCraps,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export const config = {
|
export const config = {
|
||||||
craps: {
|
craps: {
|
||||||
contractAddress: '13f7312810758d0e2271e2c620ba93f3568e0e8c'
|
contractAddress: 'b068a57e65eb0cb13ab5409b70c1d43ccee7d1f5'
|
||||||
},
|
},
|
||||||
roulette: {
|
roulette: {
|
||||||
contractAddress: '9a8e8297364f134f29bafe1322323af73e5ab434'
|
contractAddress: '9a8e8297364f134f29bafe1322323af73e5ab434'
|
||||||
|
|
Loading…
Reference in a new issue