diff --git a/app/components/Onboarding/Onboarding.js b/app/components/Onboarding/Onboarding.js index 2fa4209c..357c6f4e 100644 --- a/app/components/Onboarding/Onboarding.js +++ b/app/components/Onboarding/Onboarding.js @@ -161,7 +161,10 @@ const Onboarding = ({ return ( diff --git a/app/containers/Root.js b/app/containers/Root.js index 2eaddd13..68b88f1f 100644 --- a/app/containers/Root.js +++ b/app/containers/Root.js @@ -127,6 +127,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { password: stateProps.onboarding.password, passwordIsValid: stateProps.passwordIsValid, hasSeed: stateProps.onboarding.hasSeed, + existingWalletDir: stateProps.onboarding.existingWalletDir, unlockingWallet: stateProps.onboarding.unlockingWallet, unlockWalletError: stateProps.onboarding.unlockWalletError, diff --git a/app/lnd/walletUnlockerMethods/index.js b/app/lnd/walletUnlockerMethods/index.js index d6a754af..9128a44d 100644 --- a/app/lnd/walletUnlockerMethods/index.js +++ b/app/lnd/walletUnlockerMethods/index.js @@ -1,13 +1,28 @@ +import { dirname } from 'path' import * as walletController from '../methods/walletController' +import config from '../config' export default function(walletUnlocker, log, event, msg, data) { + const lndConfig = config.lnd() + + const decorateError = error => { + switch (error.code) { + // wallet already exists + case 2: + error.context = { + lndDataDir: dirname(lndConfig.cert) + } + } + return error + } + log.info(`Calling walletUnlocker method '${msg}'`) switch (msg) { case 'genSeed': walletController .genSeed(walletUnlocker) .then(genSeedData => event.sender.send('receiveSeed', genSeedData)) - .catch(error => event.sender.send('receiveSeedError', error)) + .catch(error => event.sender.send('receiveSeedError', decorateError(error))) break case 'unlockWallet': walletController diff --git a/app/reducers/onboarding.js b/app/reducers/onboarding.js index 8280a0e7..6842643c 100644 --- a/app/reducers/onboarding.js +++ b/app/reducers/onboarding.js @@ -38,6 +38,8 @@ export const STARTING_LND = 'STARTING_LND' export const LND_STARTED = 'LND_STARTED' export const SET_START_LND_ERROR = 'SET_START_LND_ERROR' +export const LOADING_EXISTING_WALLET = 'LOADING_EXISTING_WALLET' + export const CREATING_NEW_WALLET = 'CREATING_NEW_WALLET' export const UNLOCKING_WALLET = 'UNLOCKING_WALLET' @@ -268,10 +270,14 @@ export const receiveSeed = (event, { cipher_seed_mnemonic }) => dispatch => { } // Listener for when LND throws an error on seed creation -export const receiveSeedError = () => dispatch => { +export const receiveSeedError = (event, error) => dispatch => { dispatch({ type: SET_HAS_SEED, hasSeed: true }) // there is already a seed, send user to the login component dispatch({ type: CHANGE_STEP, step: 3 }) + dispatch({ + type: LOADING_EXISTING_WALLET, + existingWalletDir: get(error, 'context.lndDataDir') + }) } // Unlock an existing wallet with a wallet password @@ -340,6 +346,8 @@ const ACTION_HANDLERS = { startLndMacaroonError: errors.macaroon }), + [LOADING_EXISTING_WALLET]: (state, { existingWalletDir }) => ({ ...state, existingWalletDir }), + [CREATING_NEW_WALLET]: state => ({ ...state, creatingNewWallet: true }), [UNLOCKING_WALLET]: state => ({ ...state, unlockingWallet: true }), @@ -464,6 +472,7 @@ const initialState = { createWalletPasswordConfirmation: '', creatingNewWallet: false, + existingWalletDir: null, unlockingWallet: false, unlockWalletError: { isError: false,