Skip to content

Commit

Permalink
Add asset item
Browse files Browse the repository at this point in the history
  • Loading branch information
generalpiston committed Feb 14, 2018
1 parent 775a336 commit dc857b6
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 31 deletions.
16 changes: 16 additions & 0 deletions App/components/AssetList/Item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { Component } from "react";
import { View } from "react-native";
import { Text } from "react-native-elements";

export default class AssetItem extends Component {
render() {
let { token, balance } = this.props;

return (
<View style={[{ flex: 1, flexDirection: "row", justifyContent: "flex-start", alignItems: "center", }]}>
<Text>{token.symbol.toString()}</Text>
<Text>{balance}</Text>
</View>
);
}
}
33 changes: 33 additions & 0 deletions App/components/AssetList/List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import PropTypes from "prop-types";
import React, { Component } from "react";
import { View, TouchableOpacity } from "react-native";
import { List, ListItem } from "react-native-elements";
import { connect } from "react-redux";
import AssetItem from "./Item";

class AssetList extends Component {
render() {
return (
<List containerStyle={{
marginBottom: 20,
flex: 1,
width: this.props.width
}}>
{
this.props.tokens
.filter(({ address }) => (Boolean(this.props.assets[token.address])))
.map((token, index) => (
<TouchableOpacity key={`asset-${index}`} onPress={() => (this.props.onPress(order))}>
<ListItem
title={<AssetItem token={token} balance={this.props.assets[token.address]} />}
leftIcon={{ name: "add" }}
/>
</TouchableOpacity>
))
}
</List>
);
}
}

export default connect((state) => ({ ...state.device.layout, ...state.settings, tokens: state.tokens, assets: state.assets }), (dispatch) => ({ dispatch }))(AssetList);
3 changes: 3 additions & 0 deletions App/components/AssetList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AssetList from "./List";

export default AssetList;
2 changes: 1 addition & 1 deletion App/screens/OrderDetailsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OrderDetailsScreen extends Component {
return {
header: <NormalHeader navigation={navigation} />
};
};
};

constructor(props) {
super(props);
Expand Down
15 changes: 15 additions & 0 deletions App/screens/PortfolioScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { Component } from "react";
import { View, Text, TouchableHighlight } from "react-native";
import { Card, Header, Icon } from "react-native-elements";
import { connect } from "react-redux";
import NormalHeader from "../headers/Normal";

class PortfolioScreen extends Component {
render() {
return (
<AssetList tokens={this.props.tokens} />
);
}
}

export default connect(state => ({ address: state.wallet.address, tokens: state.tokens }), dispatch => ({ dispatch }))(PortfolioScreen);
7 changes: 7 additions & 0 deletions App/screens/SendTokensScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import React, { Component } from "react";
import { View, Text, TouchableHighlight } from "react-native";
import { Card, Header, Icon } from "react-native-elements";
import { connect } from "react-redux";
import NormalHeader from "../headers/Normal";

class SendTokensScreen extends Component {
static navigationOptions = ({ navigation }) => {
return {
header: <NormalHeader navigation={navigation} />
};
};

render() {
return (
<Card title={this.props.address} />
Expand Down
1 change: 1 addition & 0 deletions constants/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const SET_WALLET = "SET_WALLET";
export const SET_BASE_TOKEN = "SET_BASE_TOKEN";
export const SET_QUOTE_TOKEN = "SET_QUOTE_TOKEN";
export const SET_TOKENS = "SET_TOKENS";
export const SET_BALANCE = "SET_BALANCE";
export const SET_NETWORK = "SET_NETWORK";
3 changes: 2 additions & 1 deletion navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const TradingStack = StackNavigator({
const WalletStack = StackNavigator({
ReceiveTokens: { screen: ReceiveTokensScreen },
SendTokens: { screen: SendTokensScreen },
Portfolio: { screen: PortfolioScreen },
}, {
initialRouteName: "ReceiveTokens",
navigationOptions: ({ navigation }) => {
Expand Down Expand Up @@ -75,7 +76,7 @@ export default TabNavigator({
Trading: { screen: TradingStack },
Transactions: { screen: TransactionsStack }
}, {
initialRouteName: "Trading",
initialRouteName: "Wallet",
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
Expand Down
12 changes: 12 additions & 0 deletions reducers/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as _ from "lodash";
import { handleActions } from "redux-actions";
import * as Actions from "../constants/actions";

export default handleActions({
[Actions.SET_BALANCE]: (state, action) => {
return {
...state,
[ action.payload.address ]: action.payload.balance
}
}
}, {});
2 changes: 2 additions & 0 deletions reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from "redux";
import assets from "./assets";
import device from "./device";
import errors from "./errors";
import navigation from "./navigation";
Expand All @@ -10,6 +11,7 @@ import transactions from "./transactions";
import wallet from "./wallet";

export default combineReducers({
assets,
device,
errors,
navigation,
Expand Down
13 changes: 0 additions & 13 deletions thunks/ethereum.js

This file was deleted.

5 changes: 3 additions & 2 deletions thunks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./ethereum";
export * from "./startup";
export * from "./trade";
export * from "./transactions";
export * from "./tokens";
export * from "./wallet";
14 changes: 0 additions & 14 deletions thunks/startup.js → thunks/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ import Wallet from "ethereumjs-wallet";
import { setWallet, setTokens, setQuoteToken, setBaseToken, finishedLoadingTokens, finishedLoadingWallet } from "../actions";
import { getZeroExClient } from "../utils/ethereum";

export function loadWallet() {
return async (dispatch) => {
let privateKey = await AsyncStorage.getItem("wallet");
if (privateKey) {
let wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, "hex"));
dispatch(setWallet(wallet));
dispatch(finishedLoadingWallet());
return wallet;
} else {
return null;
}
};
}

export function loadTokens() {
return async (dispatch, getState) => {
let { wallet: { web3 } } = getState();
Expand Down
29 changes: 29 additions & 0 deletions thunks/wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as _ from "lodash";
import { AsyncStorage } from "react-native";
import Wallet from "ethereumjs-wallet";
import { setWallet, setTokens, setQuoteToken, setBaseToken, finishedLoadingTokens, finishedLoadingWallet } from "../actions";
import { getZeroExClient } from "../utils/ethereum";

// Would like to password protect using Ethereum Secret Storage
// `wallet.toV3("nopass")` is very expensive.
export function generateWallet() {
return async (dispatch) => {
let wallet = await Wallet.generate();
await AsyncStorage.setItem("wallet", wallet.getPrivateKey().toString("hex"));
dispatch(setWallet(wallet));
};
}

export function loadWallet() {
return async (dispatch) => {
let privateKey = await AsyncStorage.getItem("wallet");
if (privateKey) {
let wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, "hex"));
dispatch(setWallet(wallet));
dispatch(finishedLoadingWallet());
return wallet;
} else {
return null;
}
};
}

0 comments on commit dc857b6

Please sign in to comment.