Skip to content

Commit

Permalink
Merge branch 'master' into #633-load-open-orders
Browse files Browse the repository at this point in the history
  • Loading branch information
priecint committed Aug 5, 2016
2 parents 51f0dbd + 981c7b7 commit cc6d555
Show file tree
Hide file tree
Showing 15 changed files with 721 additions and 137 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"partial:index_filename": "[ $NODE_ENV != production ] && echo './build/index.html' || echo \"./build/index-$npm_package_version.html\""
},
"dependencies": {
"augur-ui-react-components": "3.0.31",
"augur.js": "1.9.23",
"augur-ui-react-components": "3.0.33",
"augur.js": "1.9.27",
"bignumber.js": "2.4.0",
"memoizerific": "1.8.4",
"npm-check-updates": "^2.7.1",
Expand Down
38 changes: 38 additions & 0 deletions src/modules/auth/actions/import-account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as AugurJS from '../../../services/augurjs';
import {
loadLoginAccountDependents,
loadLoginAccountLocalStorage
} from '../../auth/actions/load-login-account';
import { authError } from '../../auth/actions/auth-error';
import { updateLoginAccount } from '../../auth/actions/update-login-account';

export function importAccount(name, password, rememberMe, keystore) {
return (dispatch, getState) => {
const { links } = require('../../../selectors');
const localStorageRef = typeof window !== 'undefined' && window.localStorage;

AugurJS.importAccount(name, password, keystore, (err, loginAccount) => {
if (err) {
dispatch(authError(err));
return;
}
if (!loginAccount || !loginAccount.id) {
return;
}
if (rememberMe && localStorageRef && localStorageRef.setItem) {
const persistentAccount = Object.assign({}, loginAccount);
if (Buffer.isBuffer(persistentAccount.privateKey)) {
persistentAccount.privateKey = persistentAccount.privateKey.toString('hex');
}
localStorageRef.setItem('account', JSON.stringify(persistentAccount));
}
dispatch(loadLoginAccountLocalStorage(loginAccount.id));
dispatch(updateLoginAccount(loginAccount));
dispatch(loadLoginAccountDependents());
if (links && links.marketsLink) {
links.marketsLink.onClick(links.marketsLink.href);
}
return;
});
};
}
7 changes: 3 additions & 4 deletions src/modules/auth/actions/load-login-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { clearReports } from '../../reports/actions/update-reports';
import { updateFavorites } from '../../markets/actions/update-favorites';
import { updateAccountTradesData } from '../../positions/actions/update-account-trades-data';
import { updateTransactionsData } from '../../transactions/actions/update-transactions-data';
import env from '../../../env.json';

// import { commitReports } from '../../reports/actions/commit-reports';
import { penalizeWrongReports } from '../../reports/actions/penalize-wrong-reports';
Expand Down Expand Up @@ -69,10 +68,10 @@ export function loadLoginAccountLocalStorage(accountID) {
}

export function loadLoginAccount() {
return (dispatch) => {
return (dispatch, getState) => {
const localStorageRef = typeof window !== 'undefined' && window.localStorage;
console.log('in load login, env:');
console.log(env);
const { env } = getState();

AugurJS.loadLoginAccount(env, (err, loginAccount) => {
let localLoginAccount = loginAccount;

Expand Down
2 changes: 2 additions & 0 deletions src/modules/auth/constants/auth-types.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const REGISTER = 'register';
export const LOGIN = 'login';
export const IMPORT = 'import';

export const AUTH_TYPES = {
[REGISTER]: REGISTER,
[LOGIN]: LOGIN,
[IMPORT]: IMPORT
};

export const DEFAULT_AUTH_TYPE = REGISTER;
42 changes: 41 additions & 1 deletion src/modules/auth/selectors/auth-form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import memoizerific from 'memoizerific';
import { REGISTER, LOGIN } from '../../auth/constants/auth-types';
import { REGISTER, LOGIN, IMPORT } from '../../auth/constants/auth-types';
import {
INVALID_USERNAME_OR_PASSWORD,
USERNAME_REQUIRED,
Expand All @@ -9,6 +9,7 @@ import {
} from '../../auth/constants/form-errors';
import store from '../../../store';
import { register } from '../../auth/actions/register';
import { importAccount } from '../../auth/actions/import-account';
import { login } from '../../auth/actions/login';
import { selectAuthLink } from '../../link/selectors/links';

Expand Down Expand Up @@ -49,10 +50,14 @@ export const selectRegister = (auth, dispatch) => {
isVisiblePassword: true,
isVisiblePassword2: true,
isVisibleRememberMe: false,
isVisibleFileInput: false,

topLinkText: 'Login',
topLink: selectAuthLink(LOGIN, false, dispatch),

bottomLinkText: 'Import Account',
bottomLink: selectAuthLink(IMPORT, false, dispatch),

msg: errMsg,
msgClass: errMsg ? 'error' : 'success',

Expand All @@ -77,10 +82,15 @@ export const selectLogin = (auth, loginAccount, dispatch) => {
isVisiblePassword: true,
isVisiblePassword2: false,
isVisibleRememberMe: true,
isVisibleFileInput: false,

topLinkText: 'Sign Up',
topLink: selectAuthLink(REGISTER, false, dispatch),

bottomLinkText: 'Import Account',
bottomLink: selectAuthLink(IMPORT, false, dispatch),


secureLoginID: loginAccount.secureLoginID,
msg: errMsg || newAccountMessage,
msgClass: errMsg ? 'error' : 'success',
Expand All @@ -92,12 +102,42 @@ export const selectLogin = (auth, loginAccount, dispatch) => {
};
};

export const selectImportAccount = (auth, dispatch) => {
const errMsg = selectErrMsg(auth.err);
return {
title: 'Import Account',

isVisibleName: true,
isVisibleID: false,
isVisiblePassword: true,
isVisiblePassword2: false,
isVisibleRememberMe: true,
isVisibleFileInput: true,

topLinkText: 'Login',
topLink: selectAuthLink(LOGIN, false, dispatch),

bottomLinkText: 'Sign Up',
bottomLink: selectAuthLink(REGISTER, false, dispatch),

msg: errMsg,
msgClass: errMsg ? 'error' : 'success',

submitButtonText: 'Import Account',
submitButtonClass: 'register-button',

onSubmit: (name, password, password2, secureLoginID, rememberMe, keystore) => dispatch(importAccount(name, password, rememberMe, keystore))
};
};

export const selectAuthType = (auth, loginAccount, dispatch) => {
switch (auth.selectedAuthType) {
case REGISTER:
return selectRegister(auth, dispatch);
case LOGIN:
return selectLogin(auth, loginAccount, dispatch);
case IMPORT:
return selectImportAccount(auth, dispatch);
default:
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/selectors/login-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const setupLoginAccount = (loginAccount, dispatch) => {
const accountData = encodeURIComponent(JSON.stringify({
...loginAccount.keystore
}));
const downloadAccountDataString = `data:application/octet-stream;charset=utf-8;base64,${accountData}`;
const downloadAccountDataString = `data:,${accountData}`;

return {
...loginAccount,
Expand Down
14 changes: 8 additions & 6 deletions src/modules/create-market/actions/submit-new-market.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ export function createMarket(transactionID, newMarket) {
if (res.status === SUCCESS) {
dispatch(clearMakeInProgress());

const updatedNewMarket = {
...newMarket,
id: res.marketID,
tx: res.tx
};
if (newMarket.isCreatingOrderBook) {
const updatedNewMarket = {
...newMarket,
id: res.marketID,
tx: res.tx
};

dispatch(submitGenerateOrderBook(updatedNewMarket));
dispatch(submitGenerateOrderBook(updatedNewMarket));
}
}
}
});
Expand Down
70 changes: 40 additions & 30 deletions src/modules/create-market/selectors/form-steps/step-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ import validateStartingQuantity from '../../validators/validate-starting-quantit
import validatePriceWidth from '../../validators/validate-price-width';

export const select = (formState) => {
const obj = {
let obj = {
takerFee: formState.takerFee || TAKER_FEE_DEFAULT,
makerFee: formState.makerFee || MAKER_FEE_DEFAULT,
initialLiquidity: formState.initialLiquidity || INITIAL_LIQUIDITY_DEFAULT,
initialFairPrices: !!formState.initialFairPrices.raw.length ? formState.initialFairPrices : { ...formState.initialFairPrices, ...initialFairPrices(formState) },
startingQuantity: formState.startingQuantity || STARTING_QUANTITY_DEFAULT,
bestStartingQuantity: formState.bestStartingQuantity || BEST_STARTING_QUANTITY_DEFAULT,
priceWidth: formState.priceWidth || PRICE_WIDTH_DEFAULT,
halfPriceWidth: !!formState.priceWidth ? parseFloat(formState.priceWidth) / 2 : PRICE_WIDTH_DEFAULT / 2,
priceDepth: PRICE_DEPTH_DEFAULT,
isSimulation: formState.isSimulation || IS_SIMULATION
makerFee: formState.makerFee || MAKER_FEE_DEFAULT
};

if (formState.isCreatingOrderBook) {
obj = {
...obj,
initialLiquidity: formState.initialLiquidity || INITIAL_LIQUIDITY_DEFAULT,
initialFairPrices: !!formState.initialFairPrices.raw.length ? formState.initialFairPrices : { ...formState.initialFairPrices, ...initialFairPrices(formState) },
startingQuantity: formState.startingQuantity || STARTING_QUANTITY_DEFAULT,
bestStartingQuantity: formState.bestStartingQuantity || BEST_STARTING_QUANTITY_DEFAULT,
priceWidth: formState.priceWidth || PRICE_WIDTH_DEFAULT,
halfPriceWidth: !!formState.priceWidth ? parseFloat(formState.priceWidth) / 2 : PRICE_WIDTH_DEFAULT / 2,
priceDepth: PRICE_DEPTH_DEFAULT,
isSimulation: formState.isSimulation || IS_SIMULATION
};
}

return obj;
};

Expand Down Expand Up @@ -83,28 +89,32 @@ export const initialFairPrices = (formState) => {
export const isValid = (formState) => {
if (validateTakerFee(formState.takerFee) ||
validateMakerFee(formState.makerFee, formState.takerFee) ||
validateInitialLiquidity(
formState.type,
formState.initialLiquidity,
formState.startingQuantity,
formState.bestStartingQuantity,
formState.halfPriceWidth,
formState.scalarSmallNum,
formState.scalarBigNum
) ||
validateInitialFairPrices(
formState.type,
formState.initialFairPrices.raw,
formState.priceWidth,
formState.halfPriceWidth,
formState.scalarSmallNum,
formState.scalarBigNum
) ||
validateBestStartingQuantity(formState.bestStartingQuantity) ||
validateStartingQuantity(formState.startingQuantity) ||
validatePriceWidth(formState.priceWidth)) {
(!!formState.isCreatingOrderBook && (
validateInitialLiquidity(
formState.type,
formState.initialLiquidity,
formState.startingQuantity,
formState.bestStartingQuantity,
formState.halfPriceWidth,
formState.scalarSmallNum,
formState.scalarBigNum
) ||
validateInitialFairPrices(
formState.type,
formState.initialFairPrices.raw,
formState.priceWidth,
formState.halfPriceWidth,
formState.scalarSmallNum,
formState.scalarBigNum
) ||
validateBestStartingQuantity(formState.bestStartingQuantity) ||
validateStartingQuantity(formState.startingQuantity) ||
validatePriceWidth(formState.priceWidth)
))
) {
return false;
}

return true;
};

Expand Down
27 changes: 15 additions & 12 deletions src/modules/create-market/selectors/form-steps/step-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ export const select = (formState, currentBlockNumber, currentBlockMillisSinceEpo
formState.scalarBigNum);
o.isFavorite = false;

const formattedFairPrices = [];
if (!!o.isCreatingOrderBook) {
const formattedFairPrices = [];

o.initialFairPrices.values.map((cV, i) => {
formattedFairPrices[i] = formatNumber(cV.value, { decimals: 2, minimized: true, denomination: `ETH | ${cV.label}` });
return formattedFairPrices;
});
o.initialFairPrices.values.map((cV, i) => {
formattedFairPrices[i] = formatNumber(cV.value, { decimals: 2, minimized: true, denomination: `ETH | ${cV.label}` });
return formattedFairPrices;
});

o.initialFairPrices = {
...o.initialFairPrices,
formatted: formattedFairPrices
};
o.initialFairPrices = {
...o.initialFairPrices,
formatted: formattedFairPrices
};

o.bestStartingQuantityFormatted = formatNumber(o.bestStartingQuantity, { denomination: 'Shares' });
o.startingQuantityFormatted = formatNumber(o.startingQuantity, { denomination: 'Shares' });
o.priceWidthFormatted = formatNumber(o.priceWidth, { decimals: 2, minimized: true, denomination: 'ETH' });
o.initialLiquidityFormatted = formatNumber(o.initialLiquidity, { denomination: 'ETH' });
o.bestStartingQuantityFormatted = formatNumber(o.bestStartingQuantity, { denomination: 'Shares' });
o.startingQuantityFormatted = formatNumber(o.startingQuantity, { denomination: 'Shares' });
o.priceWidthFormatted = formatNumber(o.priceWidth, { decimals: 2, minimized: true, denomination: 'ETH' });
}

o.onSubmit = () => dispatch(submitNewMarket(o));

Expand Down
6 changes: 3 additions & 3 deletions src/modules/link/constants/paths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ACCOUNT, MARKETS, MAKE, POSITIONS, TRANSACTIONS, M } from '../../app/constants/pages';
import { NEW_REGISTER, REGISTER, LOGIN } from '../../auth/constants/auth-types';
import { IMPORT, REGISTER, LOGIN } from '../../auth/constants/auth-types';

export const PATHS_PAGES = {
'/': MARKETS,
Expand All @@ -10,7 +10,7 @@ export const PATHS_PAGES = {
'/login': LOGIN,
'/m': M,
'/account': ACCOUNT,
'/newRegister': NEW_REGISTER,
'/import': IMPORT,
};

export const PAGES_PATHS = Object.keys(PATHS_PAGES).reduce(
Expand All @@ -22,7 +22,7 @@ export const PAGES_PATHS = Object.keys(PATHS_PAGES).reduce(
export const PATHS_AUTH = {
'/register': REGISTER,
'/login': LOGIN,
'/newRegister': NEW_REGISTER,
'/import': IMPORT,
};

export const AUTH_PATHS = Object.keys(PATHS_AUTH).reduce(
Expand Down
6 changes: 2 additions & 4 deletions src/modules/link/selectors/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { makeLocation } from '../../../utils/parse-url';

import { PAGES_PATHS } from '../../link/constants/paths';
import { ACCOUNT, M, MARKETS, MAKE, POSITIONS, TRANSACTIONS } from '../../app/constants/pages';
import { LOGIN, REGISTER } from '../../auth/constants/auth-types';

import { SEARCH_PARAM_NAME, SORT_PARAM_NAME, PAGE_PARAM_NAME, TAGS_PARAM_NAME, FILTERS_PARAM_NAME } from '../../link/constants/param-names';
import { DEFAULT_SORT_PROP, DEFAULT_IS_SORT_DESC } from '../../markets/constants/sort';
Expand All @@ -16,11 +15,10 @@ import store from '../../../store';
// import * as selectors from '../../../selectors';

export default function () {
const { keywords, selectedFilters, selectedSort, selectedTags, pagination, loginAccount } = store.getState();
const { keywords, selectedFilters, selectedSort, selectedTags, pagination, loginAccount, auth } = store.getState();
const { market } = require('../../../selectors');

return {
authLink: selectAuthLink(loginAccount.id ? LOGIN : REGISTER, !!loginAccount.id, store.dispatch),
authLink: selectAuthLink(auth.selectedAuthType, !!loginAccount.id, store.dispatch),
createMarketLink: selectCreateMarketLink(store.dispatch),
marketsLink: selectMarketsLink(keywords, selectedFilters, selectedSort, selectedTags, pagination.selectedPageNum, store.dispatch),
positionsLink: selectPositionsLink(store.dispatch),
Expand Down
Loading

0 comments on commit cc6d555

Please sign in to comment.