Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
faizov committed May 21, 2024
1 parent c6e8a66 commit 929bb34
Show file tree
Hide file tree
Showing 15 changed files with 1,443 additions and 1,648 deletions.
60 changes: 30 additions & 30 deletions frontend/apps/vara-man/src/app/consts.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { HexString } from '@polkadot/util/types'
import { HexString } from '@polkadot/util/types';

export const LOCAL_STORAGE = {
ACCOUNT: 'account',
WALLET: 'wallet',
}
ACCOUNT: 'account',
WALLET: 'wallet',
};

export const ENV = {
NODE: import.meta.env.VITE_NODE_ADDRESS,
GAME: import.meta.env.VITE_CONTRACT_ADDRESS,
BACK: import.meta.env.VITE_BACKEND_ADDRESS ,
}
NODE: import.meta.env.VITE_NODE_ADDRESS,
GAME: import.meta.env.VITE_CONTRACT_ADDRESS,
BACK: import.meta.env.VITE_BACKEND_ADDRESS,
};

export type IRegisterForm = {
wallet: HexString | ''
nickname: string
}
wallet: HexString | '';
nickname: string;
};
export const initialRegister: IRegisterForm = {
wallet: '',
nickname: '',
}
wallet: '',
nickname: '',
};

export const initialCreateTournament = {
bid: 0,
DifficultyLevel: '',
TournamentName: '',
YourName: '',
TournamentDuration: '',
}
bid: 0,
DifficultyLevel: '',
TournamentName: '',
YourName: '',
TournamentDuration: '',
};

export const SIGNLESS_ALLOWED_ACTIONS = [
'DeletePlayer',
'StartTournament',
'CancelTournament',
'CancelRegister',
'LeaveGame',
'RegisterForTournament',
'RecordTournamentResult',
'FinishSingleGame',
'CreateNewTournament',
]
'DeletePlayer',
'StartTournament',
'CancelTournament',
'CancelRegister',
'LeaveGame',
'RegisterForTournament',
'RecordTournamentResult',
'FinishSingleGame',
'CreateNewTournament',
];
15 changes: 7 additions & 8 deletions frontend/apps/vara-man/src/app/hooks/use-game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useSignlessSendMessage } from '@dapps-frontend/ez-transactions';
import { ENV } from '../consts';

export const useInitGame = () => {
const navigate = useNavigate()
const navigate = useNavigate();
const { account } = useAccount();
const { setIsSettled } = useApp();
const { allState, config, admins, tournament } = useGameState();
Expand All @@ -38,24 +38,23 @@ export const useInitGame = () => {

useEffect(() => {
if (tournament?.Tournament) {
navigate("/")
navigate('/');
setTournamentGame(tournament.Tournament);
setPreviousGame(tournament.Tournament)
setPreviousGame(tournament.Tournament);
} else {
setTournamentGame(undefined)
setTournamentGame(undefined);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tournament?.Tournament, account?.decodedAddress])
}, [tournament?.Tournament, account?.decodedAddress]);

useEffect(() => {
if (allState) {
setAllGames(allState.All.tournaments)
setAllGames(allState.All.tournaments);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [allState, account?.decodedAddress])

}, [allState, account?.decodedAddress]);
};

export function useGameMessage() {
Expand Down
128 changes: 59 additions & 69 deletions frontend/apps/vara-man/src/components/layout/header/header-admin.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,68 @@
import { Icons } from '@/components/ui/icons'
import { useGame } from '@/app/context/ctx-game'
import { useGameMessage } from '@/app/hooks/use-game'
import { useApp } from '@/app/context/ctx-app'
import { useCheckBalance } from '@dapps-frontend/hooks'
import { useEzTransactions } from '@dapps-frontend/ez-transactions'
import { Icons } from '@/components/ui/icons';
import { useGame } from '@/app/context/ctx-game';
import { useGameMessage } from '@/app/hooks/use-game';
import { useApp } from '@/app/context/ctx-app';
import { useCheckBalance } from '@dapps-frontend/hooks';
import { useEzTransactions } from '@dapps-frontend/ez-transactions';

type HeaderAdminProps = BaseComponentProps & {}
type HeaderAdminProps = BaseComponentProps & {};

export function HeaderAdmin({}: HeaderAdminProps) {
const { isPending, setIsPending } = useApp()
const { status } = useGame()
const { isPending, setIsPending } = useApp();
const { status } = useGame();

const { gasless, signless } = useEzTransactions()
const handleMessage = useGameMessage()
const { checkBalance } = useCheckBalance({
signlessPairVoucherId: signless.voucher?.id,
gaslessVoucherId: gasless.voucherId,
})
const gasLimit = 120000000000
const { gasless, signless } = useEzTransactions();
const handleMessage = useGameMessage();
const { checkBalance } = useCheckBalance({
signlessPairVoucherId: signless.voucher?.id,
gaslessVoucherId: gasless.voucherId,
});
const gasLimit = 120000000000;

const onSuccess = () => setIsPending(false)
const onSuccess = () => setIsPending(false);

const onActivateGame = () => {
if (!gasless.isLoading) {
checkBalance(gasLimit, () =>
handleMessage({
payload: { ChangeStatus: { Started: null } },
voucherId: gasless.voucherId,
gasLimit,
onSuccess,
onError: onSuccess,
})
)
}
}
const onActivateGame = () => {
if (!gasless.isLoading) {
checkBalance(gasLimit, () =>
handleMessage({
payload: { ChangeStatus: { Started: null } },
voucherId: gasless.voucherId,
gasLimit,
onSuccess,
onError: onSuccess,
}),
);
}
};

const onDeactivateGame = () => {
if (!gasless.isLoading) {
checkBalance(gasLimit, () =>
handleMessage({
payload: { ChangeStatus: { Paused: null } },
voucherId: gasless.voucherId,
gasLimit,
onSuccess,
onError: onSuccess,
})
)
}
}
const onDeactivateGame = () => {
if (!gasless.isLoading) {
checkBalance(gasLimit, () =>
handleMessage({
payload: { ChangeStatus: { Paused: null } },
voucherId: gasless.voucherId,
gasLimit,
onSuccess,
onError: onSuccess,
}),
);
}
};

return (
<>
{status === 'Paused' && (
<button
type="button"
className="btn btn--primary px-6"
disabled={isPending}
onClick={onActivateGame}
>
<Icons.gameJoystick className="w-5 h-5 mr-2" />
<span>Activate game</span>
</button>
)}
{status === 'Started' && (
<button
type="button"
className="btn btn--theme-red px-6"
disabled={isPending}
onClick={onDeactivateGame}
>
<Icons.gameJoystick className="w-5 h-5 mr-2" />
<span>Deactivate game</span>
</button>
)}
</>
)
return (
<>
{status === 'Paused' && (
<button type="button" className="btn btn--primary px-6" disabled={isPending} onClick={onActivateGame}>
<Icons.gameJoystick className="w-5 h-5 mr-2" />
<span>Activate game</span>
</button>
)}
{status === 'Started' && (
<button type="button" className="btn btn--theme-red px-6" disabled={isPending} onClick={onDeactivateGame}>
<Icons.gameJoystick className="w-5 h-5 mr-2" />
<span>Deactivate game</span>
</button>
)}
</>
);
}
84 changes: 38 additions & 46 deletions frontend/apps/vara-man/src/components/layout/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
import { Link } from 'react-router-dom'
import { useGame } from '@/app/context/ctx-game'
import { HeaderAdmin } from '@/components/layout/header/header-admin'
import { Icons } from '@/components/ui/icons'
import { Link } from 'react-router-dom';
import { useGame } from '@/app/context/ctx-game';
import { HeaderAdmin } from '@/components/layout/header/header-admin';
import { Icons } from '@/components/ui/icons';

import { Header as CommonHeader, MenuHandler } from '@dapps-frontend/ui'
import {
EzGaslessTransactions,
EzSignlessTransactions,
} from '@dapps-frontend/ez-transactions'
import { Header as CommonHeader, MenuHandler } from '@dapps-frontend/ui';
import { EzGaslessTransactions, EzSignlessTransactions } from '@dapps-frontend/ez-transactions';

import styles from './Header.module.scss'
import { SIGNLESS_ALLOWED_ACTIONS } from '@/app/consts'
import styles from './Header.module.scss';
import { SIGNLESS_ALLOWED_ACTIONS } from '@/app/consts';

export const Header = () => {
const { isAdmin } = useGame()
const { isAdmin } = useGame();

return (
<CommonHeader
logo={
<Link to="/">
<Icons.logo className="h-15" />
</Link>
}
menu={
<MenuHandler
className={{
wallet: {
balance: styles.walletBalance,
},
icon: styles.menuIcon,
}}
customItems={[
{
key: 'signless',
option: (
<EzSignlessTransactions
allowedActions={SIGNLESS_ALLOWED_ACTIONS}
/>
),
},
{ key: 'gasless', option: <EzGaslessTransactions /> },
]}
/>
}
className={{ header: styles.header, content: styles.container }}
>
{isAdmin && <HeaderAdmin />}
</CommonHeader>
)
}
return (
<CommonHeader
logo={
<Link to="/">
<Icons.logo className="h-15" />
</Link>
}
menu={
<MenuHandler
className={{
wallet: {
balance: styles.walletBalance,
},
icon: styles.menuIcon,
}}
customItems={[
{
key: 'signless',
option: <EzSignlessTransactions allowedActions={SIGNLESS_ALLOWED_ACTIONS} />,
},
{ key: 'gasless', option: <EzGaslessTransactions /> },
]}
/>
}
className={{ header: styles.header, content: styles.container }}>
{isAdmin && <HeaderAdmin />}
</CommonHeader>
);
};
Loading

0 comments on commit 929bb34

Please sign in to comment.