Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

BATTLESTARCONCORDIA_WEB_HOUR3 #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Web skeleton

## Team : BattleStar Concordia
hour 1 : Tobi Decary-Larocque
hour 2 : Lance Lafontaine

Web application is deployed at http://concordia-at-csgames.com.

- [ ] (1pt) Create wallet in an account
- [x] (1pt) Display wallets of an account
- [ ] (1pt) Deposit PGG or CAD to a wallet
- [x] (1pt) Display wallet currency and amount
- [ ] (1pt) Display the PGG/CAD current price (price of the latest trade)
- [x] (2pt) Display your account value CAD + PGG of all wallets (need to have a current PGG/CAD price)
- [/] (3pt) Implement all hour 1 features with PWG/CAD
- [ ] (3pt) Implement all hour 2 features with PWG/CAD
- [/] (3pt) Implement all hour 1 features with PWG/PGG

## Quick start
check in package.json engines to test with good version of node.
use node version manager.
Expand Down
21 changes: 21 additions & 0 deletions app/api/tradesFetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import trades from './trades.json';

const delay = (ms) => (
new Promise((resolve) => setTimeout(resolve, ms))
);

export const fakeFetch = (urlGetter, options) => (
delay(300).then(() => {
//ugly hack to create immutable copy of file.
const tradesCopied = JSON.parse(JSON.stringify(trades));
switch (urlGetter) {
case "/api/trades":
switch (true) {
default:
return tradesCopied;
}
default:
throw new Error('Unknown urlGetter:');
}
})
);
12 changes: 10 additions & 2 deletions app/containers/Wallet/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { LOAD_WALLETS } from './constants';
import { LOAD_WALLETS, ADD_TO_WALLET } from './constants';

export function loadWallets() {
export function loadWallets(filter) {
return {
type: LOAD_WALLETS,
username: filter
};
}

export function addToWallet(amt = 0) {
return {
type: ADD_TO_WALLET,
amt
};
}
1 change: 1 addition & 0 deletions app/containers/Wallet/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const LOAD_WALLETS = 'crypto_exchange/App/LOAD_WALLETS';
export const WALLETS = 'wallets';
export const ADD_TO_WALLET = 'add_to_wallets';
38 changes: 37 additions & 1 deletion app/containers/Wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,32 @@ const styles = () => ({
});

class Wallet extends React.Component { // eslint-disable-line react/prefer-stateless-function

constructor(props){
super(props);
this.exchange = 1.25;
this.exchangePwg = 2000;
this.state = {
filter: undefined
};
this.filter = (term) => {
this.props.onLoadWallets();
this.setState({...this.state, filter: term });
};
}

render() {
return (
<div>
<button onClick={this.props.onLoadWallets} className={this.props.classes.test}>
<h1> Current CDN Exchange Rate: {this.exchange}x</h1>
<h1> Current PWG Exchange Rate: {this.exchangePwg}x</h1>
<button onClick={this.filter.bind(null, "flying-penguin")} className={this.props.classes.test}>
Only flying-penguin
</button>
<button onClick={this.filter.bind(null, "dying-penguin")} className={this.props.classes.test}>
Only dying-penguin
</button>
<button onClick={() => {this.setState({filter: undefined }); this.props.onLoadWallets();}} className={this.props.classes.test}>
click here to load wallets
</button>
<LoadingError
Expand All @@ -36,11 +58,25 @@ class Wallet extends React.Component { // eslint-disable-line react/prefer-state
>
<div>
{this.props.wallets.map((wallet, index) => (
(this.state.filter === undefined || wallet.username === this.state.filter) &&
<div key={wallet.address}>
<h3>wallet {index}:</h3>
<div>
<div><span>address: </span><span>{wallet.address}</span></div>
<div><span>username: </span><span>{wallet.username }</span></div>
<div><span>amount: </span><span>{wallet.currency} {wallet.amount}</span></div>
<div><span>converted PGG/CDN: </span>{
wallet.currency === 'PGG' ?
<span>CDN {wallet.amount * this.exchange}</span> : <span>PGG {wallet.amount / this.exchange}</span>
}</div>
<div><span>converted PGG/PGW: </span>{
wallet.currency === 'PGG' ?
<span>CDN {wallet.amount * this.exchangePwg}</span> : <span>PGG {wallet.amount / this.exchangePwg}</span>
}</div>
<div><span>converted CDN/PGW: </span>{
wallet.currency === 'CDN' ?
<span>CDN {wallet.amount * this.exchangePwg}</span> : <span>PGG {wallet.amount / this.exchangePwg}</span>
}</div>
</div>
</div>
))}
Expand Down
15 changes: 14 additions & 1 deletion app/containers/Wallet/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { call, put, takeLatest } from 'redux-saga/effects';

import request from '../../api/request';
import { errorAction, successAction } from '../../asyncDisplayer/containers/actions';
import { LOAD_WALLETS } from './constants';
import {ADD_TO_WALLET, LOAD_WALLETS} from './constants';

export function* fetchWallets(url, data) {
try {
Expand All @@ -13,10 +13,23 @@ export function* fetchWallets(url, data) {
}
}

export function* addToWalletFetch(url, data) {
try {
const wallets = yield call(request, url, data);
yield put(successAction(ADD_TO_WALLET, wallets));
} catch (err) {
yield put(errorAction(ADD_TO_WALLET, err));
}
}

export function* getWallets(data) {
yield fetchWallets("/api/wallets", data);
}

export function* addToWalletsFetch(data) {
yield addToWalletsFetch("/api/wallets", data);
}

export default function* instrumentResultData() {
yield takeLatest(LOAD_WALLETS, getWallets);
}
8 changes: 8 additions & 0 deletions nginx_configuration/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80;
server_name concordia-at-csgames.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}