2017-06-26 22:27:55 +00:00
|
|
|
// @flow
|
2017-04-27 06:13:33 +00:00
|
|
|
import {
|
2017-06-20 03:15:38 +00:00
|
|
|
GENERATE_WALLET_SHOW_PASSWORD,
|
|
|
|
GENERATE_WALLET_FILE,
|
2017-06-20 05:59:54 +00:00
|
|
|
GENERATE_WALLET_DOWNLOAD_FILE,
|
2017-07-16 21:02:13 +00:00
|
|
|
GENERATE_WALLET_CONFIRM_CONTINUE_TO_PAPER,
|
|
|
|
RESET_GENERATE_WALLET
|
2017-06-20 03:15:38 +00:00
|
|
|
} from 'actions/generateWalletConstants';
|
2017-07-16 21:02:13 +00:00
|
|
|
import type PrivateKeyWallet from 'libs/wallet/privkey';
|
2017-04-18 23:34:24 +00:00
|
|
|
|
2017-06-26 22:27:55 +00:00
|
|
|
export type State = {
|
2017-07-16 21:02:13 +00:00
|
|
|
activeStep: string,
|
2017-07-02 05:49:06 +00:00
|
|
|
hasDownloadedWalletFile: boolean,
|
2017-07-16 21:02:13 +00:00
|
|
|
wallet: ?PrivateKeyWallet,
|
|
|
|
password: ?string
|
2017-07-02 05:49:06 +00:00
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
|
|
|
const initialState: State = {
|
2017-07-16 21:02:13 +00:00
|
|
|
activeStep: 'password',
|
2017-06-20 03:15:38 +00:00
|
|
|
hasDownloadedWalletFile: false,
|
2017-07-16 21:02:13 +00:00
|
|
|
wallet: null,
|
|
|
|
password: null
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
2017-04-18 23:34:24 +00:00
|
|
|
|
2017-06-26 22:27:55 +00:00
|
|
|
export function generateWallet(state: State = initialState, action): State {
|
2017-06-20 03:15:38 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case GENERATE_WALLET_SHOW_PASSWORD: {
|
|
|
|
return {
|
|
|
|
...state,
|
2017-07-16 21:02:13 +00:00
|
|
|
activeStep: 'password'
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
|
|
|
}
|
2017-04-18 23:34:24 +00:00
|
|
|
|
2017-06-20 03:15:38 +00:00
|
|
|
case GENERATE_WALLET_FILE: {
|
|
|
|
return {
|
|
|
|
...state,
|
2017-07-16 21:02:13 +00:00
|
|
|
wallet: action.wallet,
|
|
|
|
password: action.password,
|
|
|
|
activeStep: 'download'
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
|
|
|
}
|
2017-04-27 06:13:33 +00:00
|
|
|
|
2017-06-20 05:59:54 +00:00
|
|
|
case GENERATE_WALLET_DOWNLOAD_FILE: {
|
2017-06-20 03:15:38 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hasDownloadedWalletFile: true
|
|
|
|
};
|
|
|
|
}
|
2017-04-27 06:13:33 +00:00
|
|
|
|
2017-06-20 05:59:54 +00:00
|
|
|
case GENERATE_WALLET_CONFIRM_CONTINUE_TO_PAPER: {
|
2017-06-20 03:15:38 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-07-16 21:02:13 +00:00
|
|
|
activeStep: 'paper'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case RESET_GENERATE_WALLET: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...initialState
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
2017-04-18 23:34:24 +00:00
|
|
|
}
|
2017-06-20 03:15:38 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-04-18 23:34:24 +00:00
|
|
|
}
|