zepio/app/redux/modules/wallet.js

86 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-12-10 09:07:28 -08:00
// @flow
import type { Action } from '../../types/redux';
import type { Transaction } from '../../components/transaction-item';
2018-12-10 09:07:28 -08:00
// Actions
export const LOAD_WALLET_SUMMARY = 'LOAD_WALLET_SUMMARY';
export const LOAD_WALLET_SUMMARY_SUCCESS = 'LOAD_WALLET_SUMMARY_SUCCESS';
export const LOAD_WALLET_SUMMARY_ERROR = 'LOAD_WALLET_SUMMARY_ERROR';
// Actions Creators
export const loadWalletSummary = () => ({
type: LOAD_WALLET_SUMMARY,
payload: {},
});
export const loadWalletSummarySuccess = ({
total,
shielded,
transparent,
2018-12-10 16:11:53 -08:00
addresses,
transactions,
zecPrice,
2018-12-10 09:07:28 -08:00
}: {
total: number,
shielded: number,
transparent: number,
2018-12-10 16:11:53 -08:00
addresses: string[],
transactions: { [day: string]: Transaction[] },
zecPrice: number,
2018-12-10 09:07:28 -08:00
}) => ({
type: LOAD_WALLET_SUMMARY_SUCCESS,
2018-12-10 16:11:53 -08:00
payload: {
total,
shielded,
transparent,
addresses,
transactions,
zecPrice,
2018-12-10 16:11:53 -08:00
},
2018-12-10 09:07:28 -08:00
});
export const loadWalletSummaryError = ({ error }: { error: string }) => ({
type: LOAD_WALLET_SUMMARY_ERROR,
payload: { error },
});
export type State = {
total: number,
shielded: number,
transparent: number,
error: string | null,
isLoading: boolean,
zecPrice: number,
2018-12-10 16:11:53 -08:00
addresses: [],
transactions: { [day: string]: Transaction[] },
2018-12-10 09:07:28 -08:00
};
const initialState = {
total: 0,
shielded: 0,
transparent: 0,
error: null,
isLoading: false,
zecPrice: 0,
2018-12-10 16:11:53 -08:00
addresses: [],
transactions: {},
2018-12-10 09:07:28 -08:00
};
export default (state: State = initialState, action: Action) => {
switch (action.type) {
case LOAD_WALLET_SUMMARY:
return { ...state, isLoading: true };
case LOAD_WALLET_SUMMARY_SUCCESS:
return {
...state,
...action.payload,
isLoading: false,
error: null,
};
case LOAD_WALLET_SUMMARY_ERROR:
return { ...state, isLoading: false, error: action.payload.error };
default:
return state;
}
};