mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Remove deprecated app-react package (#219)
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
"docker:start": "docker-compose up --build -d",
|
||||
"docker:stop": "docker-compose down",
|
||||
"docker:clean": "docker-compose down -v",
|
||||
"app:start": "CI=true lerna run start --parallel --scope @metafam/app-react --scope @metafam/utils",
|
||||
"app:build": "lerna run build --scope @metafam/app-react --include-dependencies --stream",
|
||||
"web:dev": "lerna run dev --parallel --scope @metafam/web --include-dependencies",
|
||||
"web:build": "lerna run build --scope @metafam/web --include-dependencies --stream",
|
||||
"backend:dev": "lerna run dev --parallel --scope @metafam/backend --include-dependencies",
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
## DEPRECATED, PLEASE SEE packages/web insteaed
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.<br />
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br />
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br />
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.<br />
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.<br />
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
@@ -1,51 +0,0 @@
|
||||
{
|
||||
"name": "@metafam/app-react",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"dev": "yarn start",
|
||||
"eject": "react-scripts eject",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"precommit": "yarn lint-staged"
|
||||
},
|
||||
"dependencies": {
|
||||
"3box": "^1.20.3",
|
||||
"@apollo/client": "^3.0.0-beta.43",
|
||||
"@apollo/react-hooks": "^3.1.5",
|
||||
"@material-ui/core": "^4.9.10",
|
||||
"@metafam/utils": "1.0.0",
|
||||
"@testing-library/jest-dom": "^5.11.3",
|
||||
"@testing-library/react": "^11.0.2",
|
||||
"@testing-library/user-event": "^12.1.8",
|
||||
"@walletconnect/web3-provider": "^1.0.0-beta.47",
|
||||
"apollo-boost": "^0.4.7",
|
||||
"ethers": "^5.0.8",
|
||||
"graphql": "^15.0.0",
|
||||
"graphql-codegen-hasura-core": "^4.8.4",
|
||||
"graphql-tag": "^2.10.4",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-router-dom": "^5.1.2",
|
||||
"react-scripts": "3.4.3",
|
||||
"web3": "^1.2.6",
|
||||
"web3modal": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.13",
|
||||
"@types/react-router-dom": "^5.1.5"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="The Meta Game"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<title>The Game</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -1,25 +0,0 @@
|
||||
import { ApolloProvider } from '@apollo/react-hooks';
|
||||
import { CssBaseline } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
|
||||
import { createApolloClient } from './apollo';
|
||||
import { Header } from './components/Header';
|
||||
import { Web3ContextProvider } from './contexts/Web3';
|
||||
import { Routes } from './Routes';
|
||||
|
||||
const apolloClient = createApolloClient();
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<ApolloProvider client={apolloClient}>
|
||||
<Web3ContextProvider>
|
||||
<CssBaseline />
|
||||
<Router>
|
||||
<Header />
|
||||
<Routes />
|
||||
</Router>
|
||||
</Web3ContextProvider>
|
||||
</ApolloProvider>
|
||||
);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import React from 'react';
|
||||
import { Redirect, Route, Switch } from 'react-router-dom';
|
||||
|
||||
import { Home } from './containers/Home';
|
||||
import { Player } from './containers/Player';
|
||||
|
||||
export const Routes: React.FC = () => (
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<Home />
|
||||
</Route>
|
||||
<Route path="/player/:playerId">
|
||||
<Player />
|
||||
</Route>
|
||||
<Redirect to="/" />
|
||||
</Switch>
|
||||
);
|
||||
@@ -1,58 +0,0 @@
|
||||
import { GetPlayerFromAddress } from '../graphql/queries';
|
||||
|
||||
const STORAGE_KEY = 'auth-token';
|
||||
|
||||
export function getTokenFromStore() {
|
||||
return localStorage.getItem(STORAGE_KEY);
|
||||
}
|
||||
|
||||
function setTokenInStore(token) {
|
||||
return localStorage.setItem(STORAGE_KEY, token);
|
||||
}
|
||||
|
||||
function clearToken() {
|
||||
return localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
|
||||
export function loginLoading(client, loading = true) {
|
||||
client.writeData({
|
||||
data: {
|
||||
authState: loading ? 'loading' : 'anonymous',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function login(client, token, ethAddress) {
|
||||
loginLoading(client);
|
||||
client.writeData({
|
||||
data: {
|
||||
authToken: token,
|
||||
},
|
||||
});
|
||||
return client
|
||||
.query({
|
||||
query: GetPlayerFromAddress,
|
||||
variables: { ethereum_address: ethAddress },
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.data.Player.length === 0) {
|
||||
throw new Error('Impossible to fetch player, not found.');
|
||||
}
|
||||
client.writeData({
|
||||
data: {
|
||||
authState: 'logged',
|
||||
playerId: res.data.Player[0].id,
|
||||
},
|
||||
});
|
||||
setTokenInStore(token);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logout(client);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
export function logout(client) {
|
||||
clearToken();
|
||||
client.resetStore();
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import ApolloClient from 'apollo-boost';
|
||||
|
||||
import { CONFIG } from '../config';
|
||||
import { logout } from './auth';
|
||||
import * as localQueries from './localQueries';
|
||||
|
||||
export function createApolloClient() {
|
||||
let client;
|
||||
|
||||
const defaultClientState = {
|
||||
authState: 'anonymous',
|
||||
authToken: null,
|
||||
playerId: null,
|
||||
};
|
||||
|
||||
async function authMiddleware(operation) {
|
||||
const queryLogin = client.readQuery({ query: localQueries.GetAuthState });
|
||||
|
||||
if (queryLogin.authToken) {
|
||||
operation.setContext({
|
||||
headers: {
|
||||
authorization: `Bearer ${queryLogin.authToken}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onErrorMiddleware({
|
||||
networkError = {},
|
||||
graphQLErrors = {},
|
||||
operation,
|
||||
}) {
|
||||
if (
|
||||
networkError.statusCode === 401 ||
|
||||
graphQLErrors[0]?.extensions?.code === 'invalid-jwt'
|
||||
) {
|
||||
console.error('Authentication error, login out');
|
||||
logout(client);
|
||||
} else {
|
||||
console.error('GraphQL request error:', networkError);
|
||||
}
|
||||
}
|
||||
|
||||
client = new ApolloClient({
|
||||
uri: CONFIG.graphqlURL,
|
||||
request: authMiddleware,
|
||||
onError: onErrorMiddleware,
|
||||
clientState: {
|
||||
defaults: defaultClientState,
|
||||
resolvers: {},
|
||||
},
|
||||
});
|
||||
|
||||
client.onResetStore(() => {
|
||||
client.writeData({ data: defaultClientState });
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
import { createApolloClient } from './client';
|
||||
import * as localQueries from './localQueries';
|
||||
|
||||
export { localQueries, createApolloClient };
|
||||
@@ -1,9 +0,0 @@
|
||||
import { gql } from 'apollo-boost';
|
||||
|
||||
export const GetAuthState = gql`
|
||||
query AuthState {
|
||||
authState @client
|
||||
authToken @client
|
||||
playerId @client
|
||||
}
|
||||
`;
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Login } from '../containers/Login';
|
||||
|
||||
export const Header: React.FC = () => (
|
||||
<Box>
|
||||
<Link to="/">
|
||||
<button type="button">Home</button>
|
||||
</Link>
|
||||
<Login />
|
||||
</Box>
|
||||
);
|
||||
@@ -1,90 +0,0 @@
|
||||
import { useMutation } from '@apollo/react-hooks';
|
||||
import { Box } from '@material-ui/core';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
|
||||
import { useMyPlayer } from '../graphql/hooks';
|
||||
import { UpdateBoxProfiles, UpdateUsername } from '../graphql/mutations';
|
||||
|
||||
export const PlayerDetails: React.FC<{ player: any }> = ({ player }) => {
|
||||
const myPlayer = useMyPlayer();
|
||||
const isMyPlayer = myPlayer && myPlayer.id === player.id;
|
||||
const [usernameInput, setUsernameInput] = useState<string>(player.username);
|
||||
const [updateBoxProfiles] = useMutation(UpdateBoxProfiles);
|
||||
const [updateUsername] = useMutation(UpdateUsername);
|
||||
|
||||
const ethAddress = player.ethereum_address;
|
||||
const boxProfile = player.box_profile;
|
||||
|
||||
const goToEditBoxProfile = useCallback(() => {
|
||||
window.open(`https://3box.io/${ethAddress}/edit`);
|
||||
}, [ethAddress]);
|
||||
|
||||
const editUserName = useCallback(() => {
|
||||
// TODO Apollo does not updates caches as it expects that the mutation returns an object with id, but hasura returns { returning: [{id}] }
|
||||
updateUsername({
|
||||
variables: {
|
||||
username: usernameInput,
|
||||
},
|
||||
}).then((res) => console.log('updated username', res.data));
|
||||
}, [usernameInput, updateUsername]);
|
||||
|
||||
const updateAccounts = useCallback(() => {
|
||||
updateBoxProfiles().then((res) =>
|
||||
console.log(
|
||||
'updated verified profiles',
|
||||
res.data.updateBoxProfile.updatedProfiles,
|
||||
),
|
||||
);
|
||||
}, [updateBoxProfiles]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<h3>{player.username}</h3>
|
||||
<h4>{player.id}</h4>
|
||||
{isMyPlayer && (
|
||||
<button type="button" onClick={goToEditBoxProfile}>
|
||||
Edit profile
|
||||
</button>
|
||||
)}
|
||||
{isMyPlayer && (
|
||||
<div>
|
||||
<input
|
||||
value={usernameInput}
|
||||
onChange={(e) => setUsernameInput(e.target.value)}
|
||||
/>
|
||||
<button type="button" onClick={editUserName}>
|
||||
Change username
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{boxProfile ? (
|
||||
<div>
|
||||
<p>
|
||||
<b>Name:</b> {boxProfile.name}
|
||||
</p>
|
||||
<p>
|
||||
<b>Description:</b> {boxProfile.description}
|
||||
</p>
|
||||
<img src={boxProfile.imageUrl} width={100} alt="profile" />
|
||||
</div>
|
||||
) : (
|
||||
<p>Loading box profile</p>
|
||||
)}
|
||||
<div>
|
||||
<h4>External accounts</h4>
|
||||
<ul>
|
||||
{player.Accounts.map((account: any) => (
|
||||
<li key={account.type}>
|
||||
<b>{account.type}</b>: {account.identifier}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{isMyPlayer && (
|
||||
<button type="button" onClick={updateAccounts}>
|
||||
Update accounts
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
export const PlayerListItem: React.FC<{ player: any }> = ({ player }) => (
|
||||
<Box>
|
||||
{player.username}
|
||||
<Link to={`/player/${player.id}`}>
|
||||
<button type="button">View player</button>
|
||||
</Link>
|
||||
</Box>
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
export const CONFIG = {
|
||||
graphqlURL:
|
||||
process.env.REACT_APP_GRAPHQL_URL || 'http://localhost:8080/v1/graphql',
|
||||
infuraId:
|
||||
process.env.REACT_APP_INFURA_ID || '781d8466252d47508e177b8637b1c2fd',
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
|
||||
import { PlayerList } from './PlayerList';
|
||||
|
||||
export const Home: React.FC = () => {
|
||||
return (
|
||||
<Box>
|
||||
<PlayerList />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
import { useQuery } from '@apollo/react-hooks';
|
||||
import { Box } from '@material-ui/core';
|
||||
import React, { useCallback, useContext } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { localQueries } from '../apollo';
|
||||
import { Web3Context } from '../contexts/Web3';
|
||||
|
||||
export const Login: React.FC = () => {
|
||||
const { data, loading } = useQuery(localQueries.GetAuthState);
|
||||
|
||||
const { connectWeb3, disconnect } = useContext(Web3Context);
|
||||
|
||||
const connect = useCallback(() => {
|
||||
connectWeb3().catch(console.error);
|
||||
}, [connectWeb3]);
|
||||
|
||||
if (loading || data?.authState === 'loading') {
|
||||
return <Box>Connecting...</Box>;
|
||||
}
|
||||
if (data?.authState === 'logged') {
|
||||
const { playerId } = data;
|
||||
return (
|
||||
<Box>
|
||||
Connected
|
||||
<Link to={`/player/${playerId}`}>
|
||||
<button type="button">View my player</button>
|
||||
</Link>
|
||||
<button type="button" onClick={disconnect}>
|
||||
Logout
|
||||
</button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Box>
|
||||
<button type="button" onClick={connect}>
|
||||
Connect
|
||||
</button>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
import { useQuery } from '@apollo/react-hooks';
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { PlayerDetails } from '../components/PlayerDetails';
|
||||
import { GetPlayerFromId } from '../graphql/queries';
|
||||
|
||||
export const Player: React.FC = () => {
|
||||
const { playerId } = useParams<{ playerId: string }>();
|
||||
const { data, loading, error } = useQuery(GetPlayerFromId, {
|
||||
variables: {
|
||||
player_id: playerId,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return <div>error</div>;
|
||||
}
|
||||
if (loading) {
|
||||
return <div>loading</div>;
|
||||
}
|
||||
|
||||
const myPlayer = data.Player[0];
|
||||
return (
|
||||
<Box>
|
||||
<h4>Player</h4>
|
||||
<PlayerDetails player={myPlayer} />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { useQuery } from '@apollo/react-hooks';
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
|
||||
import { PlayerListItem } from '../components/PlayerListItem';
|
||||
import { GetPlayerFromId } from '../graphql/queries';
|
||||
|
||||
export const PlayerList: React.FC = () => {
|
||||
const { data, loading, error } = useQuery(GetPlayerFromId);
|
||||
|
||||
if (error) {
|
||||
return <div>error: {error.message}</div>;
|
||||
}
|
||||
if (loading) {
|
||||
return <div>loading</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<h4>Player list</h4>
|
||||
{data.Player.map((player: any) => (
|
||||
<PlayerListItem key={player.id} player={player} />
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,97 +0,0 @@
|
||||
import { useApolloClient } from '@apollo/react-hooks';
|
||||
import { did } from '@metafam/utils';
|
||||
import WalletConnectProvider from '@walletconnect/web3-provider';
|
||||
import { providers } from 'ethers';
|
||||
import React, { createContext, useCallback, useEffect, useState } from 'react';
|
||||
import Web3 from 'web3';
|
||||
import Web3Modal from 'web3modal';
|
||||
|
||||
import { getTokenFromStore, login, loginLoading, logout } from '../apollo/auth';
|
||||
import { CONFIG } from '../config';
|
||||
|
||||
type Web3ContextType = {
|
||||
ethersProvider: providers.Web3Provider | null;
|
||||
connectWeb3: () => Promise<void>;
|
||||
disconnect: () => void;
|
||||
};
|
||||
|
||||
export const Web3Context = createContext<Web3ContextType>({
|
||||
ethersProvider: null,
|
||||
connectWeb3: async () => {},
|
||||
disconnect: () => undefined,
|
||||
});
|
||||
|
||||
const providerOptions = {
|
||||
walletconnect: {
|
||||
package: WalletConnectProvider,
|
||||
options: {
|
||||
infuraId: CONFIG.infuraId,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const web3Modal = new Web3Modal({
|
||||
network: 'mainnet',
|
||||
cacheProvider: true,
|
||||
providerOptions,
|
||||
});
|
||||
|
||||
export const Web3ContextProvider: React.FC = ({ children }) => {
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const [
|
||||
ethersProvider,
|
||||
setEthersProvider,
|
||||
] = useState<providers.Web3Provider | null>(null);
|
||||
|
||||
const connectDID = useCallback(
|
||||
async (provider: providers.Web3Provider) => {
|
||||
let token = getTokenFromStore();
|
||||
|
||||
if (!token) {
|
||||
token = await did.createToken(provider);
|
||||
}
|
||||
|
||||
const signer = provider.getSigner();
|
||||
const address = await signer.getAddress();
|
||||
await login(apolloClient, token, address);
|
||||
},
|
||||
[apolloClient],
|
||||
);
|
||||
|
||||
const connectWeb3 = useCallback(async () => {
|
||||
try {
|
||||
loginLoading(apolloClient);
|
||||
|
||||
const modalProvider = await web3Modal.connect();
|
||||
|
||||
const web3Provider = new Web3(modalProvider);
|
||||
const provider = new providers.Web3Provider(
|
||||
web3Provider.currentProvider as providers.ExternalProvider,
|
||||
);
|
||||
await connectDID(provider);
|
||||
|
||||
setEthersProvider(provider);
|
||||
} catch (e) {
|
||||
loginLoading(apolloClient, false);
|
||||
throw e;
|
||||
}
|
||||
}, [apolloClient, connectDID]);
|
||||
|
||||
const disconnect = useCallback(async () => {
|
||||
web3Modal.clearCachedProvider();
|
||||
logout(apolloClient);
|
||||
}, [apolloClient]);
|
||||
|
||||
useEffect(() => {
|
||||
if (web3Modal.cachedProvider) {
|
||||
connectWeb3().catch(console.error);
|
||||
}
|
||||
}, [connectWeb3]);
|
||||
|
||||
return (
|
||||
<Web3Context.Provider value={{ ethersProvider, connectWeb3, disconnect }}>
|
||||
{children}
|
||||
</Web3Context.Provider>
|
||||
);
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
export const PlayerFragment = `
|
||||
fragment PlayerFragment on Player {
|
||||
id
|
||||
username
|
||||
ethereum_address
|
||||
}
|
||||
`;
|
||||
|
||||
export const BoxProfileFragment = `
|
||||
fragment BoxProfileFragment on BoxProfile {
|
||||
ethereumAddress
|
||||
name
|
||||
description
|
||||
location
|
||||
job
|
||||
emoji
|
||||
imageUrl
|
||||
}
|
||||
`;
|
||||
|
||||
export const AccountFragment = `
|
||||
fragment AccountFragment on Account {
|
||||
identifier
|
||||
type
|
||||
}
|
||||
`;
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useLazyQuery, useQuery } from '@apollo/react-hooks';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { localQueries } from '../apollo';
|
||||
import { GetPlayerFromId } from './queries';
|
||||
|
||||
export function useMyPlayer() {
|
||||
const authStateQuery = useQuery(localQueries.GetAuthState);
|
||||
const [getMyPlayer, myPlayerQuery] = useLazyQuery(GetPlayerFromId);
|
||||
|
||||
const playerId = authStateQuery.data?.playerId;
|
||||
|
||||
useEffect(() => {
|
||||
if (playerId) {
|
||||
getMyPlayer({
|
||||
variables: {
|
||||
player_id: playerId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [getMyPlayer, playerId]);
|
||||
|
||||
return myPlayerQuery.data?.Player[0];
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
export const UpdateBoxProfiles = gql`
|
||||
mutation UpdateBoxProfiles {
|
||||
updateBoxProfile {
|
||||
success
|
||||
updatedProfiles
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UpdateUsername = gql`
|
||||
mutation UpdateUsername($username: String!) {
|
||||
update_Player(where: {}, _set: { username: $username }) {
|
||||
affected_rows
|
||||
returning {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -1,33 +0,0 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import {
|
||||
AccountFragment,
|
||||
BoxProfileFragment,
|
||||
PlayerFragment,
|
||||
} from './fragments';
|
||||
|
||||
export const GetPlayerFromId = gql`
|
||||
query GetPlayer($player_id: uuid) {
|
||||
Player(where: { id: { _eq: $player_id } }) {
|
||||
...PlayerFragment
|
||||
box_profile {
|
||||
...BoxProfileFragment
|
||||
}
|
||||
Accounts {
|
||||
...AccountFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
${PlayerFragment}
|
||||
${AccountFragment}
|
||||
${BoxProfileFragment}
|
||||
`;
|
||||
|
||||
export const GetPlayerFromAddress = gql`
|
||||
query GetMyPlayer($ethereum_address: String) {
|
||||
Player(where: { ethereum_address: { _eq: $ethereum_address } }) {
|
||||
...PlayerFragment
|
||||
}
|
||||
}
|
||||
${PlayerFragment}
|
||||
`;
|
||||
@@ -1,9 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { App } from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
|
||||
serviceWorker.unregister();
|
||||
1
packages/app-react/src/react-app-env.d.ts
vendored
1
packages/app-react/src/react-app-env.d.ts
vendored
@@ -1 +0,0 @@
|
||||
/// <reference types="react-scripts" />
|
||||
@@ -1,150 +0,0 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
|
||||
),
|
||||
);
|
||||
|
||||
type Config = {
|
||||
onSuccess?: (registration: ServiceWorkerRegistration) => void;
|
||||
onUpdate?: (registration: ServiceWorkerRegistration) => void;
|
||||
};
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL || '',
|
||||
window.location.href,
|
||||
);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA',
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then((registration) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then((registration) => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"isolatedModules": true,
|
||||
"allowJs": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../utils/tsconfig.json"
|
||||
}
|
||||
],
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user