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';
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,
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[],
2019-01-08 08:01:20 -08:00
transactions: TransactionsList,
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,
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,
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
};
2019-01-29 07:36:13 -08:00
// eslint-disable-next-line
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;
}
};