MyCrypto/common/reducers/wallet.js

37 lines
852 B
JavaScript
Raw Normal View History

2017-06-29 16:03:11 -07:00
// @flow
2017-07-03 16:59:27 -07:00
import type { WalletAction, SaveWalletAction, InitWalletAction } from 'actions/wallet';
2017-06-29 16:03:11 -07:00
import BaseWallet from 'libs/wallet/base';
2017-07-03 16:59:27 -07:00
export type State = {
inst: ?BaseWallet,
balance: number,
tokens: {
[string]: number
}
};
2017-06-29 16:03:11 -07:00
2017-07-03 16:59:27 -07:00
const initialState: State = {
inst: null,
balance: 0,
tokens: {}
};
2017-06-29 16:03:11 -07:00
function saveWallet(state: State, action: SaveWalletAction): State {
2017-07-03 16:59:27 -07:00
return { ...state, inst: action.payload };
}
function initWallet(state: State): State {
return { ...state, balance: 0, tokens: {} };
2017-06-29 16:03:11 -07:00
}
export function wallet(state: State = initialState, action: WalletAction): State {
switch (action.type) {
case 'WALLET_SAVE':
return saveWallet(state, action);
2017-07-03 16:59:27 -07:00
case 'WALLET_INIT':
return initWallet(state);
2017-06-29 16:03:11 -07:00
default:
return state;
}
}