MyCrypto/common/reducers/deterministicWallets.js
William O'Beirne 1d235cf67a Trezor Unlock + Deterministic Wallet Groundwork (#137)
* Basic reducer / action / saga setup, rendering wallets.

* Better address rows, with values.

* Styling + back and next buttons.

* Formatting, dpath changing.

* Derived -> Deterministic

* Set wallet on confirm.

* Flesh out Trezor wallet, add transaction signing.

* Custom dpath, better handling of canceled switches and over-rendering / prop calling.

* Token empty string value.

* Move DPaths to config file.

* Clarifying comments.
2017-08-28 12:43:57 -05:00

56 lines
1017 B
JavaScript

import type {
DeterministicWalletData,
DeterministicWalletAction
} from 'actions/deterministicWallets';
export type State = {
wallets: DeterministicWalletData[],
desiredToken: string
};
export const INITIAL_STATE: State = {
wallets: [],
desiredToken: ''
};
export function deterministicWallets(
state: State = INITIAL_STATE,
action: DeterministicWalletAction
): State {
switch (action.type) {
case 'DW_SET_WALLETS':
return {
...state,
wallets: action.payload
};
case 'DW_SET_DESIRED_TOKEN':
return {
...state,
desiredToken: action.payload
};
case 'DW_UPDATE_WALLET':
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;
});
}