@@ -6,7 +6,8 @@ import type {
6
6
AppState ,
7
7
Thunk ,
8
8
AccountKeys ,
9
- AccountState
9
+ AccountState ,
10
+ SpendingPassword
10
11
} from '../reducers/types' ;
11
12
import type {
12
13
Amount ,
@@ -30,12 +31,20 @@ import {
30
31
getTransactions
31
32
} from '../utils/nodeConnection' ;
32
33
import { isValidMnemonic , createSeedFromMnemonic } from '../utils/mnemonic' ;
33
- import { saveAccountInfoInDEN , saveSpendingPassword } from '../utils/storage' ;
34
+ import {
35
+ saveAccountInfoInDEN ,
36
+ saveSpendingPassword ,
37
+ readAccountKeysFromDEN
38
+ } from '../utils/storage' ;
34
39
35
40
import routes from '../constants/routes.json' ;
36
41
37
42
export type SetKeysAction = { type : 'SET_KEYS' } & AccountKeys ;
43
+ export type SetKeysWithSpendingPasswordAction = {
44
+ type : 'SET_SPENDING_PASSWORD'
45
+ } & SpendingPassword ;
38
46
export const SET_KEYS = 'SET_KEYS' ;
47
+ export const SET_SPENDING_PASSWORD = 'SET_SPENDING_PASSWORD' ;
39
48
40
49
export function setAccount (
41
50
privateKey : string ,
@@ -48,6 +57,29 @@ export function setAccount(
48
57
} ;
49
58
}
50
59
60
+ export function setKeysWithSpendingPassword (
61
+ spendingPassword : ?string = ''
62
+ ) : Thunk < SetKeysAction > {
63
+ return function setKeysWithSpendingPasswordThunk ( dispatch ) {
64
+ const accountKeys = readAccountKeysFromDEN ( spendingPassword ) ;
65
+ if ( accountKeys ) {
66
+ const spendingPasswordKeys = {
67
+ walletId : 'wallet01' ,
68
+ spendingPassword
69
+ } ;
70
+ dispatch ( {
71
+ type : SET_SPENDING_PASSWORD ,
72
+ ...spendingPasswordKeys
73
+ } ) ;
74
+
75
+ return getAccountFromPrivateKey ( accountKeys . privateKey ) . then ( keys =>
76
+ curry ( initializeKeysAndRedirect ) ( dispatch , keys , spendingPassword )
77
+ ) ;
78
+ }
79
+ throw new Error ( 'Invalid password' ) ;
80
+ } ;
81
+ }
82
+
51
83
export function setAccountFromPrivateKey (
52
84
privateKey : string
53
85
) : Thunk < SetKeysAction > {
0 commit comments