-
+const AccList = ({
+ accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown,
+}) => (
+
+ {!isLoading ?
+
+
+
+
+
+
+
+
+ : Loading...
}
+
+);
- }
+AccList.propTypes = {
+ accounts: arrayOf(shape({ address: string, balance: string })).isRequired,
+ defaultAccount: string,
+ changeAccount: func.isRequired,
+ isLoading: bool.isRequired,
+ classNameNavDropdown: string
+}
- export default AccList;
\ No newline at end of file
+const mapStateToProps = state => ({
+ accounts: getAccounts(state),
+ defaultAccount: getDefaultAccount(state),
+ isLoading: accountsIsLoading(state),
+});
+
+const mapDispatchToProps = dispatch => ({
+ changeAccount(address) {
+ web3.eth.defaultAccount = address;
+ dispatch(accountActions.updateDefaultAccount(address));
+ },
+});
+
+export default connect(mapStateToProps, mapDispatchToProps)(AccList);
diff --git a/app/reducers/accounts.js b/app/reducers/accounts.js
index 8c06e66..4e7795d 100644
--- a/app/reducers/accounts.js
+++ b/app/reducers/accounts.js
@@ -1,15 +1,17 @@
import { createTypes, actionCreator } from 'redux-action-creator'
export const types = createTypes([
- 'RECEIVE_ACCOUNTS'
+ 'RECEIVE_ACCOUNTS',
+ 'UPDATE_DEFAULT_ACCOUNT'
], 'ACCOUNTS')
export const actions = {
- receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts')
+ receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts'),
+ updateDefaultAccount: actionCreator(types.UPDATE_DEFAULT_ACCOUNT, 'defaultAccount')
}
export default function(state = { loading: true, accounts: [] }, action) {
switch (action.type) {
- case types.RECEIVE_ACCOUNTS:
+ case types.RECEIVE_ACCOUNTS: {
const { defaultAccount, accounts } = action.payload
return {
...state,
@@ -17,10 +19,17 @@ export default function(state = { loading: true, accounts: [] }, action) {
defaultAccount,
accounts
}
+ }
+ case types.UPDATE_DEFAULT_ACCOUNT: {
+ const { defaultAccount } = action.payload
+ return { ...state, defaultAccount }
+ }
default:
return state;
}
}
+export const getAccountState = state => state.acounts;
export const getAccounts = state => state.accounts.accounts;
+export const getDefaultAccount = state => state.accounts.defaultAccount;
export const accountsIsLoading = state => state.accounts.loading;
diff --git a/package.json b/package.json
index 33f8d11..18b3c28 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
},
"homepage": "https://github.com/status-im/contracts#readme",
"dependencies": {
+ "prop-types": "^15.6.1",
"react": "^16.3.2",
"react-blockies": "^1.3.0",
"react-bootstrap": "^0.32.1",