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