Skip to content

Commit

Permalink
Merge pull request #650 from ETCDEVTeam/fix/tokens
Browse files Browse the repository at this point in the history
Fix/tokens
  • Loading branch information
shanejonas authored Jun 22, 2018
2 parents ff9a32e + 055ed8a commit 24c8e8f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
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;
}

0 comments on commit 24c8e8f

Please sign in to comment.