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