41 lines
804 B
JavaScript
Raw Normal View History

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