2018-12-10 09:07:28 -08:00
|
|
|
// @flow
|
|
|
|
import type { Action } from '../../types/redux';
|
2019-01-08 08:01:20 -08:00
|
|
|
import type { TransactionsList } from './transactions';
|
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
|
2019-01-28 16:34:07 -08:00
|
|
|
export const loadWalletSummary: () => Action = () => ({
|
2018-12-10 09:07:28 -08:00
|
|
|
type: LOAD_WALLET_SUMMARY,
|
|
|
|
payload: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const loadWalletSummarySuccess = ({
|
|
|
|
total,
|
|
|
|
shielded,
|
|
|
|
transparent,
|
2018-12-10 16:11:53 -08:00
|
|
|
addresses,
|
2018-12-13 12:21:08 -08:00
|
|
|
transactions,
|
2018-12-13 13:37:15 -08:00
|
|
|
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[],
|
2019-01-08 08:01:20 -08:00
|
|
|
transactions: TransactionsList,
|
2018-12-13 13:37:15 -08:00
|
|
|
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,
|
2018-12-13 12:21:08 -08:00
|
|
|
transactions,
|
2018-12-13 13:37:15 -08:00
|
|
|
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,
|
2018-12-13 13:37:15 -08:00
|
|
|
zecPrice: number,
|
2019-01-21 16:08:35 -08:00
|
|
|
addresses: string[],
|
2019-01-08 08:01:20 -08:00
|
|
|
transactions: TransactionsList,
|
2018-12-10 09:07:28 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
total: 0,
|
|
|
|
shielded: 0,
|
|
|
|
transparent: 0,
|
|
|
|
error: null,
|
|
|
|
isLoading: false,
|
2018-12-13 13:37:15 -08:00
|
|
|
zecPrice: 0,
|
2018-12-10 16:11:53 -08:00
|
|
|
addresses: [],
|
2019-01-08 08:01:20 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|