Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/tokens #650

Merged
merged 4 commits into from
Jun 22, 2018
Merged
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
1 change: 1 addition & 0 deletions src/components/tokens/AddToken/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function mapDispatchToProps(dispatch, ownProps) {
.then(dispatch(reset('addToken')))
.then(dispatch(tokens.actions.loadTokenBalances(data)));
}

return dispatch(tokens.actions.fetchTokenDetails(data.address))
.then((result) => {
return dispatch(change('addToken', 'token', result));
Expand Down
16 changes: 11 additions & 5 deletions src/components/tokens/TokensList/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Immutable from 'immutable';
import { IconButton } from 'material-ui';
import { Trash as DeleteIcon } from 'emerald-js-ui/lib/icons3';
import { Input } from 'emerald-js-ui';
import tokensStore from '../../../store/vault/tokens';

import styles from './list.scss';

Expand Down Expand Up @@ -34,7 +35,7 @@ const Token = (props) => {
/>
</div>
<div>
<IconButton iconStyle={ deleteIconStyle }>
<IconButton onClick={ () => props.onDelete(token) } iconStyle={ deleteIconStyle }>
<DeleteIcon/>
</IconButton>
</div>
Expand All @@ -46,11 +47,11 @@ Token.propTypes = {
token: PropTypes.object.isRequired,
};

const TokensList = ({ tokens }) => {
const TokensList = ({ tokens, onDelete }) => {
return (
<div>
{ tokens.map((token) =>
<Token key={ token.get('address') } token={ token }/>)}
<Token {...{onDelete}} key={ token.get('address') } {...{token}}/>)}
</div>
);
};
Expand All @@ -61,8 +62,13 @@ function mapStateToProps(state, ownProps) {
};
}

const mapDispatchToProps = (dispatch, ownProps) => ({
onDelete: (token) => {
dispatch(tokensStore.actions.removeToken(token.get('address')));
},
});

export default connect(
mapStateToProps,
null
mapDispatchToProps
)(TokensList);

1 change: 1 addition & 0 deletions src/store/vault/tokens/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const ActionTypes = {
RESET_BALANCES: 'TOKEN/RESET_BALANCES',
SET_INFO: 'TOKEN/SET_INFO',
ADD_TOKEN: 'TOKEN/ADD_TOKEN',
REMOVE_TOKEN: 'TOKEN/REMOVE_TOKEN',
SET_LIST: 'TOKEN/SET_LIST',
LOADING: 'TOKEN/LOADING',
};
Expand Down
12 changes: 9 additions & 3 deletions src/store/vault/tokens/tokenActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ export function loadTokenDetails(tokenAddress: string): () => Promise<any> {

export function fetchTokenDetails(tokenAddress: string): () => Promise<any> {
return (dispatch, getState, api) => {
const contractCallBase = {to: tokenAddress};

return Promise.all([
api.geth.eth.call(tokenAddress, tokenContract.functionToData('totalSupply')),
api.geth.eth.call(tokenAddress, tokenContract.functionToData('decimals')),
api.geth.eth.call(tokenAddress, tokenContract.functionToData('symbol')),
api.geth.eth.call({ ...contractCallBase, data: tokenContract.functionToData('totalSupply') }),
api.geth.eth.call({ ...contractCallBase, data: tokenContract.functionToData('decimals') }),
api.geth.eth.call({ ...contractCallBase, data: tokenContract.functionToData('symbol') }),
]).then((results) => {
return {
address: tokenAddress,
Expand Down Expand Up @@ -189,6 +191,10 @@ export function addToken(token: TokenInfo) {
};
}

export function removeToken(address: string) {
return (dispatch, getState, api) => dispatch({ type: ActionTypes.REMOVE_TOKEN, address });
}

// FIXME: deprecated
export function traceCall(from: string, to: string, gas: string, gasPrice: string, value: string, data: string) {
return (dispatch, getState, api) => {
Expand Down
12 changes: 11 additions & 1 deletion src/store/vault/tokens/tokenReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const initialToken = Map({
});

// ----- UTILITY FUNCTIONS

function addToken(state, address, name) {
return state.update('tokens', (tokens) => {
const pos = tokens.findKey((tok) => tok.get('address') === address);
Expand Down Expand Up @@ -69,6 +68,16 @@ function updateToken(state, id, f) {

// ----- REDUCERS

function onRemoveToken(state, action) {
if (action.type === ActionTypes.REMOVE_TOKEN) {
return state.set(
'tokens',
state.get('tokens').filterNot((token) => token.get('address') === action.address)
);
}
return state;
}

function onLoading(state, action) {
switch (action.type) {
case ActionTypes.LOADING:
Expand Down Expand Up @@ -169,5 +178,6 @@ export default function tokenReducers(state, action) {
state = onSetTokenBalance(state, action);
state = onSetTokensBalances(state, action);
state = onResetBalances(state, action);
state = onRemoveToken(state, action);
return state;
}