Skip to content

Commit

Permalink
Tic-tac-toe: add salis (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-nayaka authored Sep 9, 2024
1 parent 556f1c9 commit 9f414c0
Show file tree
Hide file tree
Showing 249 changed files with 5,740 additions and 412 deletions.
2 changes: 2 additions & 0 deletions frontend/apps/tic-tac-toe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

React application of [Tic-Tac-Toe](https://wiki.gear-tech.io/docs/examples/Gaming/tictactoe) based on [Rust smart-contract](https://github.com/gear-foundation/dapps/tree/master/contracts/tic-tac-toe).

This is a frontend implementation for programs created using the [Sails Library](https://wiki.vara.network/docs/build/sails/). For programs built with [Gear library](https://wiki.vara.network/docs/build/gstd/), refer to the implementation [here](https://github.com/gear-foundation/dapps/tree/master/frontend/dev/gstd-tic-tac-toe).

## Getting started

### Install packages:
Expand Down
13 changes: 5 additions & 8 deletions frontend/apps/tic-tac-toe/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import './app.scss';
import { withProviders } from '@/app/hocs';
import { useInitGame, useInitGameSync } from '@/features/tic-tac-toe/hooks';
import meta from '@/features/tic-tac-toe/assets/meta/tic_tac_toe.meta.txt';
import { Loader, LoadingError, MainLayout } from '@/components';
import '@gear-js/vara-ui/dist/style.css';
import { Routing } from '@/pages';
import { useProgramMetadata } from './app/hooks';

function Component() {
const metadata = useProgramMetadata(meta);
const { isGameReady } = useInitGame();
const { errorGame: hasError } = useInitGameSync(metadata);
const { errorGame } = useInitGameSync();

return (
<MainLayout>
{!!hasError && (
{!!errorGame && (
<LoadingError>
<p>Error in the Game contract :(</p>
<pre>
<small>Error message:</small> <code>{hasError}</code>
<small>Error message:</small> <code>{errorGame.message}</code>
</pre>
</LoadingError>
)}
{!hasError && isGameReady && <Routing />}
{!hasError && !isGameReady && <Loader />}
{!errorGame && isGameReady && <Routing />}
{!errorGame && !isGameReady && <Loader />}
</MainLayout>
);
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/apps/tic-tac-toe/src/app/hocs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
EzTransactionsProvider,
} from '@dapps-frontend/ez-transactions';

import metaTxt from '@/features/tic-tac-toe/assets/meta/tic_tac_toe.meta.txt';
import { ADDRESS } from '@/app/consts';
import { Alert, alertStyles } from '@/components/ui/alert';
import { QueryProvider } from './query-provider';
import { useProgram } from '../utils';

function ApiProvider({ children }: ProviderProps) {
return <GearApiProvider initialArgs={{ endpoint: ADDRESS.NODE }}>{children}</GearApiProvider>;
Expand Down Expand Up @@ -53,8 +54,9 @@ function GaslessTransactionsProvider({ children }: ProviderProps) {

function SignlessTransactionsProvider({ children }: ProviderProps) {
const { programId } = useDnsProgramIds();
const program = useProgram();
return (
<SharedSignlessTransactionsProvider programId={programId} metadataSource={metaTxt}>
<SharedSignlessTransactionsProvider programId={programId} program={program}>
{children}
</SharedSignlessTransactionsProvider>
);
Expand All @@ -66,6 +68,7 @@ const providers = [
AccountProvider,
AlertProvider,
DnsProvider,
QueryProvider,
GaslessTransactionsProvider,
SignlessTransactionsProvider,
EzTransactionsProvider,
Expand Down
23 changes: 23 additions & 0 deletions frontend/apps/tic-tac-toe/src/app/hocs/query-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactNode } from 'react';

const queryClient = new QueryClient({
defaultOptions: {
queries: {
gcTime: 0,
staleTime: Infinity,
refetchOnWindowFocus: false,
retry: false,
},
},
});

type Props = {
children: ReactNode;
};

const QueryProvider = ({ children }: Props) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

export { QueryProvider };
5 changes: 0 additions & 5 deletions frontend/apps/tic-tac-toe/src/app/hooks/use-is-app-ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export function useIsAppReadySync() {
const { setIsAppReady } = useIsAppReady();

useAccountAvailableBalanceSync();
console.log('----------------');
console.log(isApiReady);
console.log(isAccountReady);
console.log(isAvailableBalanceReady);
console.log(isAuthReady);
useEffect(() => {
setIsAppReady(isApiReady && isAccountReady && isAvailableBalanceReady && isAuthReady);
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
1 change: 1 addition & 0 deletions frontend/apps/tic-tac-toe/src/app/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sails';
2 changes: 2 additions & 0 deletions frontend/apps/tic-tac-toe/src/app/utils/sails/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './sails';
export * from './lib';
Loading

0 comments on commit 9f414c0

Please sign in to comment.