diff --git a/frontend/casino/src/app/components/web3/DicePlayButton.tsx b/frontend/casino/src/app/components/web3/DicePlayButton.tsx index ebaa673..f111e2a 100644 --- a/frontend/casino/src/app/components/web3/DicePlayButton.tsx +++ b/frontend/casino/src/app/components/web3/DicePlayButton.tsx @@ -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' } diff --git a/frontend/casino/src/app/pages/DiceGamePage/DiceGamePage.tsx b/frontend/casino/src/app/pages/DiceGamePage/DiceGamePage.tsx index 38e338e..8b2f511 100644 --- a/frontend/casino/src/app/pages/DiceGamePage/DiceGamePage.tsx +++ b/frontend/casino/src/app/pages/DiceGamePage/DiceGamePage.tsx @@ -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} diff --git a/frontend/casino/src/app/web3/functions/Craps/usePlayCraps.ts b/frontend/casino/src/app/web3/functions/Craps/usePlayCraps.ts index cf86b2b..78af54f 100644 --- a/frontend/casino/src/app/web3/functions/Craps/usePlayCraps.ts +++ b/frontend/casino/src/app/web3/functions/Craps/usePlayCraps.ts @@ -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, diff --git a/frontend/casino/src/app/web3/functions/config/config.ts b/frontend/casino/src/app/web3/functions/config/config.ts index f620989..67c82c5 100644 --- a/frontend/casino/src/app/web3/functions/config/config.ts +++ b/frontend/casino/src/app/web3/functions/config/config.ts @@ -1,6 +1,6 @@ export const config = { craps: { - contractAddress: '13f7312810758d0e2271e2c620ba93f3568e0e8c' + contractAddress: 'b068a57e65eb0cb13ab5409b70c1d43ccee7d1f5' }, roulette: { contractAddress: '9a8e8297364f134f29bafe1322323af73e5ab434'