Merge pull request #45 from shocknet/onboarding-improvs

Onboarding improvs
This commit is contained in:
Daniel Lugo 2020-03-13 16:56:06 -04:00 committed by GitHub
commit d9186b066a
3 changed files with 72 additions and 103 deletions

View file

@ -5,7 +5,7 @@
"main": "src/server.js", "main": "src/server.js",
"scripts": { "scripts": {
"start": "node --experimental-modules src/server.js", "start": "node --experimental-modules src/server.js",
"dev": "node main.js -h 0.0.0.0", "dev": "node --trace-warnings main.js -h 0.0.0.0",
"dev:watch": "nodemon main.js -- -h 0.0.0.0", "dev:watch": "nodemon main.js -- -h 0.0.0.0",
"test": "jest --no-cache", "test": "jest --no-cache",
"test:watch": "jest --no-cache --watch", "test:watch": "jest --no-cache --watch",

View file

@ -13,8 +13,9 @@ const Encryption = require('../../../utils/encryptionStore')
/** @type {import('../contact-api/SimpleGUN').ISEA} */ /** @type {import('../contact-api/SimpleGUN').ISEA} */
// @ts-ignore // @ts-ignore
const SEAx = require('gun/sea') const SEAx = require('gun/sea')
// @ts-ignore // Re-enable in the future, when SEA errors inside user.auth/etc actually
SEAx.throw = true // propagate up.
// SEAx.throw = true
/** @type {import('../contact-api/SimpleGUN').ISEA} */ /** @type {import('../contact-api/SimpleGUN').ISEA} */
const mySEA = {} const mySEA = {}
@ -315,7 +316,10 @@ const authenticate = async (alias, pass, __user) => {
return ack.sea.pub return ack.sea.pub
} else { } else {
throw new Error('Unknown error.') logger.error(
`Unknown error, wrong password? Ack looks like: ${JSON.stringify(ack)}`
)
throw new Error(`Didn't work, bad password?`)
} }
} }

View file

@ -443,47 +443,6 @@ module.exports = async (
} }
}); });
app.post("/api/lnd/connect", (req, res) => {
const { lightning, walletUnlocker } = LightningServices.services;
const args = {
wallet_password: Buffer.from(req.body.password, "utf-8")
};
lightning.getInfo({}, async err => {
if (err) {
// try to unlock wallet
await recreateLnServices();
return walletUnlocker.unlockWallet(args, async unlockErr => {
if (unlockErr) {
unlockErr.error = unlockErr.message;
logger.error("Unlock Error:", unlockErr);
const health = await checkHealth();
if (health.LNDStatus.success) {
res.status(400);
res.json({ field: "WalletUnlocker", errorMessage: unlockErr.message });
} else {
res.status(500);
res.json({ errorMessage: "LND is down" });
}
} else {
await recreateLnServices();
mySocketsEvents.emit("updateLightning");
const token = await auth.generateToken();
res.json({
authorization: token
});
}
});
}
const token = await auth.generateToken();
return res.json({
authorization: token
});
});
});
app.post("/api/lnd/wallet", async (req, res) => { app.post("/api/lnd/wallet", async (req, res) => {
try { try {
const { walletUnlocker } = LightningServices.services; const { walletUnlocker } = LightningServices.services;
@ -640,6 +599,7 @@ module.exports = async (
}); });
app.post("/api/lnd/wallet/existing", async (req, res) => { app.post("/api/lnd/wallet/existing", async (req, res) => {
try {
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();
@ -700,6 +660,11 @@ module.exports = async (
publicKey publicKey
} }
}) })
} catch (err) {
return res.status(500).json({
errorMessage: err.message,
})
}
}); });
// get lnd info // get lnd info