2017-09-25 02:06:28 +00:00
|
|
|
import {
|
|
|
|
DeterministicWalletAction,
|
|
|
|
DeterministicWalletData
|
2017-08-28 17:43:57 +00:00
|
|
|
} from 'actions/deterministicWallets';
|
2017-09-25 02:06:28 +00:00
|
|
|
import { TypeKeys } from 'actions/deterministicWallets/constants';
|
2017-08-28 17:43:57 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
export interface State {
|
|
|
|
wallets: DeterministicWalletData[];
|
|
|
|
desiredToken: string | undefined;
|
|
|
|
}
|
2017-08-28 17:43:57 +00:00
|
|
|
|
|
|
|
export const INITIAL_STATE: State = {
|
|
|
|
wallets: [],
|
|
|
|
desiredToken: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
export function deterministicWallets(
|
|
|
|
state: State = INITIAL_STATE,
|
|
|
|
action: DeterministicWalletAction
|
|
|
|
): State {
|
|
|
|
switch (action.type) {
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.DW_SET_WALLETS:
|
2017-08-28 17:43:57 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
wallets: action.payload
|
|
|
|
};
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.DW_SET_DESIRED_TOKEN:
|
2017-08-28 17:43:57 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
desiredToken: action.payload
|
|
|
|
};
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.DW_UPDATE_WALLET:
|
2017-08-28 17:43:57 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
wallets: updateWalletValues(state.wallets, action.payload)
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateWalletValues(wallets, newWallet) {
|
|
|
|
return wallets.map(w => {
|
|
|
|
if (w.address === newWallet.address) {
|
|
|
|
return {
|
|
|
|
...w,
|
|
|
|
...newWallet
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
});
|
|
|
|
}
|