Skip to content

Commit

Permalink
Slim down mobidex
Browse files Browse the repository at this point in the history
  • Loading branch information
generalpiston committed Feb 14, 2018
1 parent dc857b6 commit 63076c2
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 123 deletions.
14 changes: 2 additions & 12 deletions App/Main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React, { Component } from "react";
import { addNavigationHelpers } from "react-navigation";
import { createReduxBoundAddListener } from "react-navigation-redux-helpers";
import { connect } from "react-redux";
import Navigator from "../navigation";

const addListener = createReduxBoundAddListener("root");

class Main extends Component {
export default class Main extends Component {
render() {
return (
<Navigator navigation={addNavigationHelpers({
dispatch: this.props.dispatch,
state: this.props.navigation,
addListener
})} />
<Navigator />
);
}
}

export default connect((state) => ({ ...state.device.layout, navigation: state.navigation }), dispatch => ({ dispatch }))(Main);
2 changes: 1 addition & 1 deletion App/components/AssetList/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class AssetList extends Component {
}
}

export default connect((state) => ({ ...state.device.layout, ...state.settings, tokens: state.tokens, assets: state.assets }), (dispatch) => ({ dispatch }))(AssetList);
export default connect((state) => ({ ...state.device.layout, ...state.settings, assets: state.assets }), (dispatch) => ({ dispatch }))(AssetList);
2 changes: 1 addition & 1 deletion App/components/OrderList/Ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class AskItem extends Component {
}
}

export default connect((state) => ({ ...state.settings, tokens: state.tokens }), (dispatch) => ({ dispatch }))(AskItem);
export default connect((state) => ({ ...state.settings }), (dispatch) => ({ dispatch }))(AskItem);
2 changes: 1 addition & 1 deletion App/components/OrderList/Bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class BidItem extends Component {
}
}

export default connect((state) => ({ ...state.settings, tokens: state.tokens }), (dispatch) => ({ dispatch }))(BidItem);
export default connect((state) => ({ ...state.settings }), (dispatch) => ({ dispatch }))(BidItem);
2 changes: 1 addition & 1 deletion App/components/TokenDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class TokenDropdown extends Component {
}
}

export default connect(state => ({ tokens: state.tokens, ...state.device.layout }), dispatch => ({ dispatch }))(TokenDropdown);
export default connect(state => ({ tokens: state.settings.tokens, ...state.device.layout }), dispatch => ({ dispatch }))(TokenDropdown);
2 changes: 1 addition & 1 deletion App/screens/OrderDetailsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class OrderDetailsScreen extends Component {
}
}

export default connect(state => ({ wallet: state.wallet, orders: state.orders }), dispatch => ({ dispatch }))(OrderDetailsScreen);
export default connect(state => ({ wallet: state.wallet, orders: state.relayer.orders }), dispatch => ({ dispatch }))(OrderDetailsScreen);
2 changes: 1 addition & 1 deletion App/screens/PortfolioScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class PortfolioScreen extends Component {
}
}

export default connect(state => ({ address: state.wallet.address, tokens: state.tokens }), dispatch => ({ dispatch }))(PortfolioScreen);
export default connect(state => ({ address: state.wallet.address, tokens: state.settings.tokens }), dispatch => ({ dispatch }))(PortfolioScreen);
2 changes: 1 addition & 1 deletion App/screens/TradingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class TradingScreen extends Component {
}
}

export default connect((state) => ({ ...state.device, orders: state.orders }), (dispatch) => ({ dispatch }))(TradingScreen);
export default connect((state) => ({ ...state.device, orders: state.relayer.orders }), (dispatch) => ({ dispatch }))(TradingScreen);
2 changes: 1 addition & 1 deletion App/screens/TransactionHistoryScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class TransactionHistoryScreen extends Component {
}
}

export default connect((state) => ({ ...state.device, transactions: state.transactions }), (dispatch) => ({ dispatch }))(TransactionHistoryScreen);
export default connect((state) => ({ ...state.device, transactions: state.wallet.transactions }), (dispatch) => ({ dispatch }))(TransactionHistoryScreen);
1 change: 1 addition & 0 deletions actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Actions from "../constants/actions";
export const addErrors = createAction(Actions.ADD_ERRORS);
export const addOrders = createAction(Actions.ADD_ORDERS);
export const addTransactions = createAction(Actions.ADD_TRANSACTIONS);
export const addAssets = createAction(Actions.ADD_ASSETS);
export const finishedLoadingTokens = createAction(Actions.FINISHED_LOADING_TOKENS);
export const finishedLoadingWallet = createAction(Actions.FINISHED_LOADING_WALLET);
export const setWallet = createAction(Actions.SET_WALLET);
Expand Down
1 change: 1 addition & 0 deletions constants/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const ADD_ERRORS = "ADD_ERRORS";
export const ADD_ORDERS = "ADD_ORDERS";
export const ADD_TRANSACTIONS = "ADD_TRANSACTIONS";
export const ADD_ASSETS = "ADD_ASSETS";
export const FINISHED_LOADING_WALLET = "FINISHED_LOADING_WALLET";
export const FINISHED_LOADING_TOKENS = "FINISHED_LOADING_TOKENS";
export const SET_WALLET = "SET_WALLET";
Expand Down
3 changes: 2 additions & 1 deletion navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TradingHeader from "./App/headers/Trading";
import WalletHeader from "./App/headers/Wallet";
import SettingsHeader from "./App/headers/Settings";
import TransactionsHeader from "./App/headers/Transactions";
import PortfolioScreen from "./App/screens/PortfolioScreen";
import ReceiveTokensScreen from "./App/screens/ReceiveTokensScreen";
import SendTokensScreen from "./App/screens/SendTokensScreen";
import TokenSettingsScreen from "./App/screens/TokenSettingsScreen";
Expand All @@ -32,7 +33,7 @@ const TradingStack = StackNavigator({
CreateOrder: { screen: CreateOrderScreen },
OrderDetails: { screen: OrderDetailsScreen }
}, {
initialRouteName: "CreateOrder",
initialRouteName: "Trading",
navigationOptions: ({ navigation }) => {
const params = navigation.state.params || {};

Expand Down
12 changes: 0 additions & 12 deletions reducers/assets.js

This file was deleted.

12 changes: 2 additions & 10 deletions reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { combineReducers } from "redux";
import assets from "./assets";
import device from "./device";
import errors from "./errors";
import navigation from "./navigation";
import settings from "./settings";
import orders from "./orders";
import relayer from "./relayer";
import startup from "./startup";
import tokens from "./tokens";
import transactions from "./transactions";
import wallet from "./wallet";

export default combineReducers({
assets,
device,
errors,
navigation,
orders,
relayer,
settings,
startup,
tokens,
transactions,
wallet
});
9 changes: 0 additions & 9 deletions reducers/navigation.js

This file was deleted.

8 changes: 6 additions & 2 deletions reducers/orders.js → reducers/relayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import * as _ from "lodash";
import { handleActions } from "redux-actions";
import * as Actions from "../constants/actions";

const initialState = {
orders: []
};

export default handleActions({
[Actions.ADD_ORDERS]: (state, action) => {
return _.unionBy(state, action.payload, "orderHash");
return { ...state, orders: _.unionBy(state.orders, action.payload, "orderHash") };
}
}, []);
}, initialState);
9 changes: 8 additions & 1 deletion reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const BASE_URL = "http://localhost:8000/relayer/v0";
const initialState = {
quoteToken: null,
baseToken: null,
relayerEndpoint: BASE_URL
relayerEndpoint: BASE_URL,
tokens: []
};

export default handleActions({
Expand All @@ -23,5 +24,11 @@ export default handleActions({
...state,
baseToken: action.payload
};
},
[Actions.SET_TOKENS]: (state, action) => {
return {
...state,
tokens: action.payload
};
}
}, initialState);
9 changes: 0 additions & 9 deletions reducers/tokens.js

This file was deleted.

9 changes: 0 additions & 9 deletions reducers/transactions.js

This file was deleted.

26 changes: 17 additions & 9 deletions reducers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ function getWeb3(privateKey, address) {
return new Web3(engine);
}

function getInitialState() {
return {
privateKey: null,
address: null,
web3: null
};
}
const initialState = {
web3: null,
privateKey: null,
address: null,
assets: [],
transactions: []
};

export default handleActions({
[Actions.SET_WALLET]: (state, action) => {
let privateKey = `0x${ethUtil.stripHexPrefix(action.payload.getPrivateKey().toString("hex"))}`;
let address = `0x${ethUtil.stripHexPrefix(action.payload.getAddress().toString("hex"))}`;
let web3 = getWeb3(privateKey, address);
return { privateKey, address, web3 };
return { ...state, privateKey, address, web3 };
},
[Actions.ADD_TRANSACTIONS]: (state, action) => {
let transactions = _.unionBy(state.transactions, action.payload, "transactionId");
return { ...state, transactions: transactions };
},
[Actions.ADD_ASSETS]: (state, action) => {
let assets = _.unionBy(state.assets, action.payload, "address");
return { ...state, assets: assets };
}
}, getInitialState());
}, initialState);
4 changes: 1 addition & 3 deletions store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createStore, applyMiddleware, Store } from "redux";
import thunk from "redux-thunk";
import logger from "redux-logger";
import { createReactNavigationReduxMiddleware } from "react-navigation-redux-helpers";
import rootReducer from "./reducers";

const navigationMiddleware = createReactNavigationReduxMiddleware("root", state => state.navigation);
export default function configureStore(initialState) {
return createStore(rootReducer, initialState, applyMiddleware(thunk, logger, navigationMiddleware));
return createStore(rootReducer, initialState, applyMiddleware(thunk, logger));
}
5 changes: 2 additions & 3 deletions thunks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./trade";
export * from "./transactions";
export * from "./tokens";
export * from "./relayer";
export * from "./settings";
export * from "./wallet";
2 changes: 1 addition & 1 deletion thunks/trade.js → thunks/relayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function submitOrder(signedOrder) {

export function createSignSubmitOrder(price, amount) {
return async (dispatch, getState) => {
let { wallet, trade, settings } = getState();
let { wallet, settings } = getState();
let web3 = wallet.web3;
let address = wallet.address.toLowerCase();
let order = {
Expand Down
File renamed without changes.
33 changes: 0 additions & 33 deletions thunks/transactions.js

This file was deleted.

29 changes: 28 additions & 1 deletion thunks/wallet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import * as _ from "lodash";
import { AsyncStorage } from "react-native";
import Wallet from "ethereumjs-wallet";
import { setWallet, setTokens, setQuoteToken, setBaseToken, finishedLoadingTokens, finishedLoadingWallet } from "../actions";
import {
addTransactions,
setWallet,
setTokens,
setQuoteToken,
setBaseToken,
finishedLoadingTokens,
finishedLoadingWallet
} from "../actions";
import { getZeroExClient } from "../utils/ethereum";

// Would like to password protect using Ethereum Secret Storage
Expand All @@ -27,3 +35,22 @@ export function loadWallet() {
}
};
}

export function loadTransactions() {
return async (dispatch, getState) => {
// Need index of 0x.
// let client = new HttpClient(BASE_URL);

// try {
// dispatch(addOrders(await client.getOrdersAsync()));
// return true;
// } catch(err) {
// dispatch(addErrors([err]));
// return false;
// }
};
}

export function saveTransactions() {

}

0 comments on commit 63076c2

Please sign in to comment.