forked from gear-foundation/dapps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,443 additions
and
1,648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 59 additions & 69 deletions
128
frontend/apps/vara-man/src/components/layout/header/header-admin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
frontend/apps/vara-man/src/components/layout/header/header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.