Simplify existing-lnd new alias flow
This commit is contained in:
parent
b5b6a1350a
commit
2a72f2df9d
1 changed files with 11 additions and 20 deletions
|
|
@ -890,15 +890,15 @@ module.exports = async (
|
||||||
|
|
||||||
app.post('/api/lnd/wallet/existing', async (req, res) => {
|
app.post('/api/lnd/wallet/existing', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const trustedKeys = await Storage.get('trustedPKs')
|
||||||
const { password, alias } = req.body
|
const { password, alias } = req.body
|
||||||
const healthResponse = await checkHealth()
|
const healthResponse = await checkHealth()
|
||||||
const exists = await walletExists()
|
const exists = await walletExists()
|
||||||
const allowUnlockedLND = process.env.ALLOW_UNLOCKED_LND === 'true'
|
const allowUnlockedLND = process.env.ALLOW_UNLOCKED_LND === 'true'
|
||||||
|
const isLocked = healthResponse.LNDStatus.service === 'walletUnlocker'
|
||||||
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return res.status(500).json({
|
throw new Error('LND wallet does not exist, please create a new one')
|
||||||
field: 'wallet',
|
|
||||||
errorMessage: 'LND wallet does not exist, please create a new one'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!alias) {
|
if (!alias) {
|
||||||
|
|
@ -923,32 +923,23 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!isLocked && !allowUnlockedLND) {
|
||||||
healthResponse.LNDStatus.service !== 'walletUnlocker' &&
|
throw new Error(
|
||||||
!allowUnlockedLND
|
'Wallet is already unlocked. Please restart your LND instance and try again.'
|
||||||
) {
|
)
|
||||||
return res.status(400).json({
|
|
||||||
field: 'wallet',
|
|
||||||
errorMessage:
|
|
||||||
'Wallet is already unlocked. Please restart your LND instance and try again.'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (healthResponse.LNDStatus.service === 'walletUnlocker') {
|
if (isLocked) {
|
||||||
await unlockWallet(password)
|
await unlockWallet(password)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (_) {
|
||||||
return res.status(401).json({
|
throw new Error('Invalid LND wallet password')
|
||||||
field: 'wallet',
|
|
||||||
errorMessage: 'Invalid LND wallet password'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register user after verifying wallet password
|
// Register user after verifying wallet password
|
||||||
const publicKey = await GunDB.register(alias, password)
|
const publicKey = await GunDB.register(alias, password)
|
||||||
|
|
||||||
const trustedKeys = await Storage.get('trustedPKs')
|
|
||||||
await Storage.setItem('trustedPKs', [...(trustedKeys || []), publicKey])
|
await Storage.setItem('trustedPKs', [...(trustedKeys || []), publicKey])
|
||||||
|
|
||||||
// Generate Access Token
|
// Generate Access Token
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue