View on GitHub
File Changes
  AppState,
  Thunk,
  AccountKeys,
-
  AccountState,
-
  UnlockWalletPassword
+
  AccountState
} from '../reducers/types';
import type {
  Amount,
import routes from '../constants/routes.json';

                      
export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
-
export type SetKeysWithUnlockWalletPasswordAction = {
-
  type: 'SET_UNLOCK_WALLET_PASSWORD'
-
} & UnlockWalletPassword;
export const SET_KEYS = 'SET_KEYS';
-
export const SET_UNLOCK_WALLET_PASSWORD = 'SET_UNLOCK_WALLET_PASSWORD';

                      
export function setAccount(
  privateKey: string,
-
  unlockWalletPassword: ?string
+
  unlockWalletPassword: string
): Thunk<SetKeysAction> {
  return function setAccountThunk(dispatch) {
    return getAccountFromPrivateKey(privateKey).then(keys =>
}

                      
export function setKeysWithUnlockWalletPassword(
-
  unlockWalletPassword: ?string = ''
+
  unlockWalletPassword: string = ''
): Thunk<SetKeysAction> {
  return function setKeysWithUnlockWalletPasswordThunk(dispatch) {
    const accountKeys = readEncryptedAccountInfo(unlockWalletPassword);
const initializeKeysAndRedirect = (
  dispatch: Dispatch,
  keys: AccountKeys,
-
  unlockWalletPassword: ?string = ''
+
  unlockWalletPassword: string = ''
) => {
  dispatch({
    type: SET_KEYS,
export function setAccountFromMnemonic(
  mnemonicPhrase: string,
  mnemonicPassword: string,
-
  unlockWalletPassword: ?string
+
  unlockWalletPassword: string
): Thunk<SetKeysAction> {
  if (isValidMnemonic(mnemonicPhrase)) {
    const seed = createSeedFromMnemonic(mnemonicPhrase, mnemonicPassword);
              safer wallet seeds.
            </em>
          </Form.Text>
-
          <Form.Label className="mt-5">Unlock wallet (optional):</Form.Label>
+
          <Form.Label className="mt-5">Unlock wallet:</Form.Label>
          <Form.Group>
            <Form.Control
              type="password"
  identifier: Identifier
};

                      
-
export type UnlockWalletPassword = {
-
  unlockWalletPassword: string
-
};
-

                      
export type AccountState = {
  balance: Balance,
  counter: Counter,
}

                      
export function saveEncryptedAccountInfo(
-
  unlockWalletPassword: ?string,
+
  unlockWalletPassword: string,
  keys: AccountKeys
): void {
  const plainTextAccountInfo = JSON.stringify(keys);
-
  const spedingPwd: string = unlockWalletPassword || '';
-
  const encryptedTextAccountInfo = aesEncrypt(spedingPwd, plainTextAccountInfo);
+
  if (!unlockWalletPassword || unlockWalletPassword === '') {
+
    throw new Error('Invalid unlock password');
+
  }
+
  const encryptedTextAccountInfo = aesEncrypt(
+
    unlockWalletPassword,
+
    plainTextAccountInfo
+
  );
  localStorage.setItem(WALLET_ENCRYPTED_KEYS, encryptedTextAccountInfo);
}

                      
// eslint-disable-next-line flowtype/space-after-type-colon
export function readEncryptedAccountInfo(
-
  unlockWalletPassword: ?string
+
  unlockWalletPassword: string
): ?AccountKeys {
  const encryptedHex = localStorage.getItem(WALLET_ENCRYPTED_KEYS);
  try {