Skip to content

Commit aaf6601

Browse files
committed
speding password input on restore key is added
1 parent 201703f commit aaf6601

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

examples/wallet/app/actions/account.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ import routes from '../constants/routes.json';
3737
export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
3838
export const SET_KEYS = 'SET_KEYS';
3939

40-
export function setAccount(privateKey: string): Thunk<SetKeysAction> {
40+
export function setAccount(
41+
privateKey: string,
42+
spendingPassword: ?string
43+
): Thunk<SetKeysAction> {
4144
return function setAccountThunk(dispatch) {
42-
return getAccountFromPrivateKey(privateKey).then(
43-
curry(initializeKeysAndRedirect)(dispatch)
45+
return getAccountFromPrivateKey(privateKey).then(keys =>
46+
curry(initializeKeysAndRedirect)(dispatch, keys, spendingPassword)
4447
);
4548
};
4649
}
@@ -84,16 +87,15 @@ export function setAccountFromPrivateKey(
8487
const initializeKeysAndRedirect = (
8588
dispatch: Dispatch,
8689
keys: AccountKeys,
87-
saveAccount?: boolean = true
90+
spendingPassword: ?string = ''
8891
) => {
8992
dispatch({
9093
type: SET_KEYS,
9194
...keys
9295
});
93-
if (saveAccount) {
94-
saveSpendingPassword('manteca');
95-
saveAccountInfoInDEN('manteca', keys);
96-
}
96+
97+
saveSpendingPassword(spendingPassword);
98+
saveAccountInfoInDEN(spendingPassword, keys);
9799

98100
return Promise.all([
99101
dispatch(updateAccountTransactions()),
@@ -109,13 +111,14 @@ const initializeKeysAndRedirect = (
109111

110112
export function setAccountFromMnemonic(
111113
mnemonicPhrase: string,
112-
mnemonicPassword?: string
114+
mnemonicPassword: string,
115+
spendingPassword: ?string
113116
): Thunk<SetKeysAction> {
114117
if (isValidMnemonic(mnemonicPhrase)) {
115118
const seed = createSeedFromMnemonic(mnemonicPhrase, mnemonicPassword);
116119
return function setAccountThunk(dispatch) {
117-
return getAccountFromSeed(seed).then(
118-
curry(initializeKeysAndRedirect)(dispatch)
120+
return getAccountFromSeed(seed).then(keys =>
121+
curry(initializeKeysAndRedirect)(dispatch, keys, spendingPassword)
119122
);
120123
};
121124
}

examples/wallet/app/components/RestoreWalletFromMnemonic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default ({ setAccountFromMnemonic }: Props) => {
2525
checkValidPassword(password, confirmPassword)
2626
) {
2727
return Promise.all([
28-
setAccountFromMnemonic(newMnemonicPhrase, newMnemonicPassword)
28+
setAccountFromMnemonic(newMnemonicPhrase, newMnemonicPassword, password)
2929
]);
3030
}
3131
setIsMnemonicValid(false);

examples/wallet/app/components/RestoreWalletFromPrivateKey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default ({ setAccount }: Props) => {
1818
) {
1919
event.preventDefault();
2020
if (checkValidPassword(password, confirmPassword)) {
21-
setAccount(newPrivateKey);
21+
setAccount(newPrivateKey, password);
2222
}
2323
};
2424

@@ -98,7 +98,7 @@ export default ({ setAccount }: Props) => {
9898
className="text-danger"
9999
hidden={arePasswordAndConfirmationEqual}
100100
>
101-
<code>password and confirmation must be the same.</code>
101+
<code>Password and confirmation must be the same.</code>
102102
</Form.Label>
103103
</Form.Group>
104104
<Row className="justify-content-center">

examples/wallet/app/utils/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
const WALLET_SPEDING_PASSWORD_KEY = 'wallet.spending.pwd';
1111
const WALLET_ENCRYPTED_KEYS = 'wallet.encrypted.account.info';
1212

13-
export function saveSpendingPassword(spendingPassword: string): void {
13+
export function saveSpendingPassword(spendingPassword: ?string = ''): void {
1414
const spendingHash = computeBlake2bHexWithSecret(spendingPassword);
1515
localStorage.setItem(WALLET_SPEDING_PASSWORD_KEY, spendingHash);
1616
}

0 commit comments

Comments
 (0)