2018-12-10 09:10:06 -08:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import eres from 'eres';
|
|
|
|
import { DashboardView } from '../views/dashboard';
|
|
|
|
import rpc from '../../services/api';
|
|
|
|
import { loadWalletSummary, loadWalletSummarySuccess, loadWalletSummaryError } from '../redux/modules/wallet';
|
|
|
|
|
|
|
|
import type { AppState } from '../types/app-state';
|
|
|
|
import type { Dispatch } from '../types/redux';
|
|
|
|
|
|
|
|
const mapStateToProps = ({ walletSummary }: AppState) => ({
|
|
|
|
total: walletSummary.total,
|
|
|
|
shielded: walletSummary.shielded,
|
|
|
|
transparent: walletSummary.transparent,
|
|
|
|
error: walletSummary.error,
|
|
|
|
isLoading: walletSummary.isLoading,
|
|
|
|
dollarValue: walletSummary.dollarValue,
|
2018-12-10 16:11:53 -08:00
|
|
|
addresses: walletSummary.addresses,
|
2018-12-10 09:10:06 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|
|
|
getSummary: async () => {
|
|
|
|
dispatch(loadWalletSummary());
|
|
|
|
|
|
|
|
const [err, walletSummary] = await eres(rpc.z_gettotalbalance());
|
|
|
|
|
|
|
|
if (err) return dispatch(loadWalletSummaryError({ error: err.message }));
|
|
|
|
|
2018-12-10 16:11:53 -08:00
|
|
|
const [addressesErr, addresses] = await eres(rpc.z_listaddresses());
|
|
|
|
|
|
|
|
if (addressesErr) return dispatch(loadWalletSummaryError({ error: addressesErr.message }));
|
|
|
|
|
2018-12-10 09:10:06 -08:00
|
|
|
dispatch(
|
|
|
|
loadWalletSummarySuccess({
|
|
|
|
transparent: walletSummary.transparent,
|
|
|
|
total: walletSummary.total,
|
|
|
|
shielded: walletSummary.private,
|
2018-12-10 16:11:53 -08:00
|
|
|
addresses,
|
2018-12-10 09:10:06 -08:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const DashboardContainer = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
)(DashboardView);
|