Skip to content

Commit

Permalink
First version using react + api
Browse files Browse the repository at this point in the history
  • Loading branch information
mcortesi committed May 7, 2019
1 parent 3baa3e1 commit dbb1257
Show file tree
Hide file tree
Showing 78 changed files with 11,605 additions and 335 deletions.
23 changes: 23 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
44 changes: 44 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm 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.

### `npm 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.

### `npm run 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.

### `npm run 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/).
48 changes: 48 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@auth0/auth0-spa-js": "^0.0.1-alpha.19",
"@types/auth0-js": "^9.10.2",
"@types/classnames": "^2.2.7",
"@types/jest": "24.0.12",
"@types/node": "12.0.0",
"@types/react": "16.8.16",
"@types/react-dom": "16.8.4",
"auth0-js": "^9.10.2",
"classnames": "^2.2.6",
"formik": "^1.5.4",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.0",
"react-scripts": "3.0.0",
"typescript": "3.4.5",
"yup": "^0.27.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/react-router-dom": "^4.3.3",
"@types/yup": "^0.26.13"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
77 changes: 77 additions & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>POAP: Proof of Attendance Protocol</title>
<meta
name="description"
content="POAP is a protocol for issuing and displaying cool crypto-badges built in the EthDenver 2019 hackathon."
/>

<meta property="og:title" content="POAP: Proof of Attendance Protocol" />
<meta
property="og:description"
content="POAP is a protocol for issuing and displaying cool crypto-badges built in the EthDenver 2019 hackathon."
/>
<meta property="og:url" content="https://poap.xyz" />
<meta property="og:site_name" content="POAP" />
<meta property="og:image" content="https://poap.xyz/images/preview.jpg" />

<meta name="twitter:title" content="POAP: Proof of Attendance Protocol" />
<meta
name="twitter:description"
content="POAP is a protocol for issuing and displaying cool crypto-badges built in the EthDenver 2019 hackathon."
/>
<meta name="twitter:card" value="POAP - Proof of Attendance Protocol" />
<meta name="twitter:site" content="@poapxyz" />
<meta name="twitter:creator" content="@poapxyz" />
<meta name="twitter:image" content="https://poap.xyz/images/preview.jpg" />

<meta itemprop="name" content="POAP: Proof of Attendance Protocol" />
<meta
itemprop="description"
content="POAP is a protocol for issuing and displaying cool crypto-badges built in the EthDenver 2019 hackathon."
/>
<meta itemprop="image" content="https://poap.xyz/images/preview.jpg" />

<link rel="shortcut icon" href="/favicon.ico" />
<link rel="canonical" href="https://xyz.io" />

<link rel="apple-touch-icon" sizes="57x57" href="/images/apple-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="60x60" href="/images/apple-icon-60x60.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152x152.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-icon-180x180.png" />
<link rel="icon" type="image/png" sizes="192x192" href="/images/android-icon-192x192.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicon-96x96.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png" />
<link rel="manifest" href="/manifest.json" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png" />
<meta name="theme-color" content="#ffffff" />

<link rel="stylesheet" href="/css/basics.css" />
<link rel="stylesheet" href="/css/poap.css" />
<link rel="stylesheet" href="/css/badges.css" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" />
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous"
/>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
15 changes: 15 additions & 0 deletions client/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
24 changes: 24 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { AuthProvider, AuthService } from './auth';
import { Callback } from './auth/Callback';
import { Login } from './auth/Login';
import { PrivateRoute } from './auth/PrivateRoute';
import { BackOffice } from './components/BackOffice';
import { ScanPage } from './components/ScanPage';

type AppProps = { auth: AuthService };
const App: React.FC<AppProps> = ({ auth }) => (
<AuthProvider value={auth}>
<Router>
<Switch>
<Route exact path="/" component={ScanPage} />
<Route exact path="/callback" component={Callback} />
<Route exact path="/login" component={Login} />
<PrivateRoute path="/admin" component={BackOffice} />
</Switch>
</Router>
</AuthProvider>
);

export default App;
58 changes: 58 additions & 0 deletions client/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { authClient } from './auth';

export interface PoapEvent {
id: number;
name: string;
description: string;
city: string;
country: string;
event_url: string;
image_url: string;
year: number;
start_date: Date;
end_date: Date;

metadata: Object;
active: boolean;
}

const API_BASE = 'http://localhost:8080';

export async function getEvents(): Promise<PoapEvent[]> {
const bearer = 'Bearer ' + (await authClient.getAPIToken());

const res = await fetch(`${API_BASE}/api/events`, {
headers: {
Authorization: bearer,
'Content-Type': 'application/json',
},
});
if (res.ok) {
return await res.json();
} else {
console.error(res);
throw new Error(`Error with request statusCode: ${res.status}`);
}
}

export async function mintTokenBatch(eventId: number, addresses: string[]): Promise<any> {
const bearer = 'Bearer ' + (await authClient.getAPIToken());

const res = await fetch(`${API_BASE}/api/mintTokenBatch`, {
method: 'POST',
body: JSON.stringify({
eventId,
addresses,
}),
headers: {
Authorization: bearer,
'Content-Type': 'application/json',
},
});
if (res.ok) {
return await res.json();
} else {
console.error(res);
throw new Error(`Error with request statusCode: ${res.status}`);
}
}
18 changes: 18 additions & 0 deletions client/src/auth/Callback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { History } from 'history';
import { AuthService, withAuth } from '.';
import React from 'react';
import { withRouter } from 'react-router';

class Callback_ extends React.Component<{ auth: AuthService; history: History }> {
async componentDidMount() {
const path = await this.props.auth.handleCallback();
this.props.history.push(path);
}

render() {
return <div>Loading user profile.</div>;
}
}

// @ts-ignore
export const Callback = withRouter(withAuth(Callback_));
17 changes: 17 additions & 0 deletions client/src/auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { History } from 'history';
import { AuthService, withAuth } from '.';
import React from 'react';
import { withRouter } from 'react-router';

class Login_ extends React.Component<{ history: History; auth: AuthService; from: string }> {
async componentDidMount() {
await this.props.auth.login(this.props.from);
}

render() {
return null;
}
}

// @ts-ignore
export const Login = withRouter(withAuth(Login_));
26 changes: 26 additions & 0 deletions client/src/auth/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { Redirect, Route, RouteProps } from 'react-router-dom';
import { withAuth } from '.';

export interface PrivateRouteProps extends RouteProps {
component: React.ComponentType<any>;
}

export const PrivateRoute: React.FC<PrivateRouteProps> = withAuth(
({ auth, component: Component, ...rest }) => {
return (
<Route
{...rest}
render={props => {
if (auth.isAuthenticated()) {
return <Component {...props} />;
} else {
return (
<Redirect to={{ pathname: '/login', state: { from: props.location.pathname } }} />
);
}
}}
/>
);
}
);
Loading

0 comments on commit dbb1257

Please sign in to comment.