Skip to content

Commit

Permalink
Loaders, error handlers, my bets and minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryanaMysak committed Oct 12, 2021
1 parent 820b2f1 commit 9ca8c5d
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 162 deletions.
81 changes: 21 additions & 60 deletions eleks/oracle/games-web-app/README.md
@@ -1,70 +1,31 @@
# Getting Started with Create React App
# Mutual Betting Platform

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
Frontend part of Mutual Betting Platform implementation.

## Available Scripts
## Installation

In the project directory, you can run:
Firstly, go to the directory below.

### `yarn start`
```bash
./eleks/oracle/games-web-app
```

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
Then run this command to install all needed for the project packages.

The page will reload if you make edits.\
You will also see any lint errors in the console.
```bash
npm install
```

### `yarn test`
## Run app
Run this command to launch the application. The app will run on **:3000** port.

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
```bash
npm start
```

### `yarn build`
## Open in browser
You need to enable cross-origin policies in the browser for local app development. For example, you can open Google Chrome with this command.

Builds the app for production to the `build` folder.\
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.\
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/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `yarn build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
```bash
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security
```
39 changes: 36 additions & 3 deletions eleks/oracle/games-web-app/src/actions/auth.js
@@ -1,10 +1,43 @@
import { LOGIN, LOGOUT } from '../helpers/actionTypes';
import { toast } from 'react-toastify';
import * as fromApi from '../api/auth';
import {
FETCH_LOGIN_START,
FETCH_LOGIN_SUCCESS,
FETCH_LOGIN_FAILED,
LOGOUT,
} from '../helpers/actionTypes';

export const login = (wallet) => ({
type: LOGIN,
export const fetchLoginStart = () => ({
type: FETCH_LOGIN_START,
});

export const fetchLoginSuccess = (wallet) => ({
type: FETCH_LOGIN_SUCCESS,
wallet,
});

export const fetchLoginFailed = (error) => ({
type: FETCH_LOGIN_FAILED,
error,
});

export const logout = () => ({
type: LOGOUT,
});

export const login = (wallet) => async (dispatch) => {
dispatch(fetchLoginStart());
const walletKey = await fromApi.login(wallet.value);
if (walletKey.error) {
dispatch(fetchLoginFailed(walletKey.error));
toast.error(walletKey.error);
} else {
const user = {
...wallet,
walletId: walletKey.walletId,
publicKey: walletKey.walletDataPubKeyHash.getPubKeyHash,
};
localStorage.setItem('currentUser', JSON.stringify(user));
dispatch(fetchLoginSuccess(user));
}
};
19 changes: 13 additions & 6 deletions eleks/oracle/games-web-app/src/actions/bets.js
@@ -1,4 +1,4 @@
// import { toast } from 'react-toastify';
import { toast } from 'react-toastify';
import * as fromApi from '../api/bets';
import { getGameContract, parseBetsResponse } from '../helpers/utils';
import {
Expand Down Expand Up @@ -60,7 +60,7 @@ export const fetchGameContract = (id, gameId) => async (dispatch) => {
const contracts = await fromApi.fetchContracts(id);
if (contracts.error) {
dispatch(fetchGameContractFailed(contracts.error));
// toast.error(contracts.error);
toast.error(contracts.error);
} else {
const contract = getGameContract(contracts, gameId);
dispatch(fetchGameContractSuccess(contract));
Expand All @@ -72,20 +72,27 @@ export const fetchGameBets = (id) => async (dispatch) => {
const bets = await fromApi.fetchGameBets(id);
if (bets.error) {
dispatch(fetchGameBetsFailed(bets.error));
// toast.error(contracts.error);
toast.error(bets.error);
} else {
const result = parseBetsResponse(bets);
dispatch(fetchGameBetsSuccess(result));
}
};

export const makeBet = (team, amount, gameId) => async (dispatch) => {
export const makeBet = (team, amount, gameId, wallet) => async (dispatch) => {
dispatch(fetchMakeBetStart());
const bet = await fromApi.makeBet(team, amount, gameId);
if (bet.error) {
dispatch(fetchMakeBetFailed(bet.error));
// toast.error(contracts.error);
toast.error(bet.error);
} else {
// dispatch(fetchMakeBetSuccess({team, amount}));
dispatch(
fetchMakeBetSuccess({
betBettor: { getPubKeyHash: wallet.publicKey },
betAmount: { getLovelace: amount },
betTeamId: team,
})
);
toast.success('Your bet has been accepted');
}
};
6 changes: 3 additions & 3 deletions eleks/oracle/games-web-app/src/actions/games.js
@@ -1,4 +1,4 @@
// import { toast } from 'react-toastify';
import { toast } from 'react-toastify';
import * as fromApi from '../api/games';
import {
FETCH_GAMES_START,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const fetchGames = () => async (dispatch) => {
const games = await fromApi.fetchGames();
if (games.error) {
dispatch(fetchGamesFailed(games.error));
// toast.error(games.error);
toast.error(games.error);
} else {
dispatch(fetchGamesSuccess(games));
}
Expand All @@ -53,7 +53,7 @@ export const fetchGame = (id) => async (dispatch) => {
const game = await fromApi.fetchGame(id);
if (game.error) {
dispatch(fetchGameFailed(game.error));
// toast.error(games.error);
toast.error(game.error);
} else {
dispatch(fetchGameSuccess(game));
}
Expand Down
16 changes: 16 additions & 0 deletions eleks/oracle/games-web-app/src/api/auth.js
@@ -0,0 +1,16 @@
export async function login(id) {
const response = await fetch(`http://localhost:8082/wallet/${id}`, {
method: 'GET',
headers: {
'Content-type': 'application/json',
},
});

if (response.status === 200) {
return response.json();
} else {
return {
error: 'Unable to fetch wallet key',
};
}
}
15 changes: 12 additions & 3 deletions eleks/oracle/games-web-app/src/components/Bets.js
@@ -1,11 +1,20 @@
import '../styles/Bets.scss';

const Bets = ({ bets }) => (
const Bets = ({ bets, currentUser }) => (
<div className='Bets'>
{bets.map((bet, i) => (
<div className='bet' key={i}>
<div
className={`bet ${
currentUser && bet.betBettor.getPubKeyHash === currentUser.publicKey
? 'myBet'
: ''
}`}
key={i}
>
<span className='hash'>{bet.betBettor.getPubKeyHash}</span>
<span className='amount'>{bet.betAmount.getLovelace} Lovelace</span>
<span className='amount'>
{bet.betAmount.getLovelace / 1000000} ADA
</span>
</div>
))}
</div>
Expand Down

0 comments on commit 9ca8c5d

Please sign in to comment.