This commit is contained in:
Aleksey_Levin 2024-01-17 12:51:42 +03:00
parent db9c2829fd
commit e5b151f5be
10 changed files with 70 additions and 13 deletions

View file

@ -5,6 +5,7 @@ import chipImg from '../../../../assets/icons/chip.png'
import {useStores} from "../../../hooks/useStores.tsx";
import {observer} from "mobx-react-lite";
import {CheckBalanceButton} from "../../../web3/balance/CheckBalanceButton.tsx";
import {FaucetButton} from "../../web3/FaucetButton.tsx";
export const AppNav = observer(() => {
const { userStore } = useStores()
@ -23,15 +24,12 @@ export const AppNav = observer(() => {
<div className="rounded-[100px] bg-[#2D313D] flex flex-row items-center justify-between shadow-inset">
<div className="flex flex-row gap-[3px] items-center px-[15px] py-[11px]">
<CoinIcon />
{/* placeholder for balance */}
{userStore.balance ? <span>{userStore.balance}</span> : <CheckBalanceButton/>}
{userStore.balance ? <span> {
parseFloat(userStore.balance) > 5 ? userStore.balance : <FaucetButton/>
}</span> : <CheckBalanceButton/>}
</div>
<ConnectStateButton/>
</div>
<div className="flex flex-row items-center">
<span>Robin F.</span>
<ProfileIcon />
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,19 @@
import {useCheckBalance} from "./useCheckBalance.ts";
import {observer} from "mobx-react-lite";
import {useEffect} from "react";
import {useStores} from "../../hooks/useStores.tsx";
import {useFaucet} from "../../web3/functions/Faucet/useFaucet.ts";
export const FaucetButton = observer(() => {
const { faucet, result } = useFaucet()
const { userStore } = useStores()
useEffect(() => {
if (result) userStore.setBalance(result.balance)
}, [result])
return (
<button onClick={faucet}>
Get coins
</button>
);
});

View file

@ -6,7 +6,7 @@ export const RPSPlayButton = () => {
return (
<button
onClick={() => { playRPS('rock') }}
onClick={() => { playRPS('1') }}
className="bg-rose-700 rounded-[100px] shadow text-white text-2xl font-bold py-5 px-10 hover:bg-rose-600 inline-block max-w-[200px]">
Играть
</button >

View file

@ -1,14 +1,21 @@
import PropTypes from "prop-types";
import {useSlotMachine} from "../../web3/functions/SlotMachine/useSlotMachine.ts";
interface SlotPlayButtonProps {
onClick: () => void;
}
const SlotPlayButton: React.FC<SlotPlayButtonProps> = ({ onClick }) => {
const { playSlot } = useSlotMachine()
return (
<button
className="bg-rose-700 rounded-[100px] shadow text-white text-2xl font-bold py-5 px-10 hover:bg-rose-600 max-w-[200px]"
onClick={onClick}
onClick={() => {
onClick()
playSlot()
}}
>
Крутить
</button>

View file

@ -1,4 +1,4 @@
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";
import ContainerLayout from "../../utils/ContainerLayout.tsx";
import Reel from "../../components/App/Slot/Reel.tsx";
import SlotPlayButton from "../../components/web3/SlotPlayButton.tsx";

View file

@ -14,7 +14,7 @@ export const usePlayCraps = () => {
scriptHash: config.craps.contractAddress,
operation: 'playCraps',
args: [
{ type: 'Integer', value: '40' },
{ type: 'Integer', value: '4' },
{ type: 'Integer', value: value.toString() },
{ type: 'Integer', value: secondValue.toString() },
]

View file

@ -0,0 +1,30 @@
import {useWalletConnect} from "@cityofzion/wallet-connect-sdk-react";
import {useCallback} from "react";
import {useGetResult} from "../utils/useGetResult.ts";
import {config} from "../config/config.ts";
export const useFaucet = () => {
const wcSdk = useWalletConnect()
const { getResult, ...statuses } = useGetResult()
const faucet = useCallback(async () => {
console.log(config.zaFaucet.contractAddress)
const resp = await wcSdk.invokeFunction({
invocations: [{
scriptHash: config.zaFaucet.contractAddress,
operation: 'getZaCoin',
args: []
}],
signers: [{
scopes: 'Global',
}]
})
console.log(resp)
await getResult(resp, 'rouletteNumber')
}, [wcSdk, getResult])
return {
faucet,
...statuses
}
}

View file

@ -14,8 +14,8 @@ export const usePlayRPS = () => {
scriptHash: config.rps.contractAddress,
operation: 'playRPS',
args: [
{ type: 'String', value: value },
{ type: 'Integer', value: '40' },
{ type: 'Integer', value: value },
{ type: 'Integer', value: '4' },
]
}],
signers: [{

View file

@ -14,7 +14,7 @@ export const useSlotMachine = () => {
scriptHash: config.slotMachine.contractAddress,
operation: 'rollSlot',
args: [
{ type: 'Integer', value: '40' },
{ type: 'Integer', value: '4' },
]
}],
signers: [{

View file

@ -13,5 +13,8 @@ export const config = {
},
rps: {
contractAddress: 'ae71ad7c8174530cddecf483e8094539f84fcd7f'
},
zaFaucet: {
contractAddress: '66621b53f51303d29a224cb6e5deeec30ad2631b'
}
}