MyCrypto/common/reducers/generateWallet.js

68 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-06-26 15:27:55 -07:00
// @flow
import {
GENERATE_WALLET_SHOW_PASSWORD,
GENERATE_WALLET_FILE,
GENERATE_WALLET_DOWNLOAD_FILE,
GENERATE_WALLET_CONFIRM_CONTINUE_TO_PAPER,
RESET_GENERATE_WALLET
} from 'actions/generateWalletConstants';
import type PrivateKeyWallet from 'libs/wallet/privkey';
2017-06-26 15:27:55 -07:00
export type State = {
activeStep: string,
2017-07-01 22:49:06 -07:00
hasDownloadedWalletFile: boolean,
wallet: ?PrivateKeyWallet,
password: ?string
2017-07-01 22:49:06 -07:00
};
2017-06-26 15:27:55 -07:00
const initialState: State = {
activeStep: 'password',
hasDownloadedWalletFile: false,
wallet: null,
password: null
};
2017-06-26 15:27:55 -07:00
export function generateWallet(state: State = initialState, action): State {
switch (action.type) {
case GENERATE_WALLET_SHOW_PASSWORD: {
return {
...state,
activeStep: 'password'
};
}
case GENERATE_WALLET_FILE: {
return {
...state,
wallet: action.wallet,
password: action.password,
activeStep: 'download'
};
}
case GENERATE_WALLET_DOWNLOAD_FILE: {
return {
...state,
hasDownloadedWalletFile: true
};
}
case GENERATE_WALLET_CONFIRM_CONTINUE_TO_PAPER: {
return {
...state,
activeStep: 'paper'
};
}
case RESET_GENERATE_WALLET: {
return {
...state,
...initialState
};
}
default:
return state;
}
}