From a1b56680e999bf70a5a7b2e9e00b4df236d1684f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 30 Apr 2020 23:14:35 -0700 Subject: configurable asset settings --- db/schema.sql | 11 ++++++----- routes/users.js | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index 1d839016..2b40caf5 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -57,7 +57,7 @@ CREATE TABLE `accounts` ( `ticker` varchar(255) DEFAULT NULL, `precision` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3545 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=3547 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -81,7 +81,7 @@ CREATE TABLE `invoices` ( `tip` double DEFAULT NULL, `network` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4083 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=4145 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -107,8 +107,9 @@ CREATE TABLE `payments` ( `fee` double DEFAULT NULL, `network` varchar(255) DEFAULT NULL, `account_id` int(11) DEFAULT NULL, + `preimage` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3612 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=3710 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -148,7 +149,7 @@ CREATE TABLE `users` ( `currencies` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, `otpsecret` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=499 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=500 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -160,4 +161,4 @@ CREATE TABLE `users` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2020-04-28 22:33:38 +-- Dump completed on 2020-04-30 23:14:12 diff --git a/routes/users.js b/routes/users.js index 6b814e81..4497949c 100644 --- a/routes/users.js +++ b/routes/users.js @@ -259,7 +259,7 @@ app.post("/login", async (req, res) => { user = pick(user, ...whitelist); res.send({ user, token }); } catch (e) { - l.error("login error", e); + l.error("login error", e.message); res.status(401).end(); } }); @@ -371,6 +371,30 @@ app.post("/address", auth, async (req, res) => { res.send(user.address); }); +app.post("/account", auth, async (req, res) => { + let { user } = req; + let { asset, precision, name, ticker, user_id } = req.body; + + try { + const account = await db.Account.findOne({ + where: { user_id, asset } + }); + + account.name = name; + account.ticker = ticker; + account.precision = precision; + + await account.save(); + + user = await getUser(user.username); + emit(user.username, "user", user); + res.send(account); + } catch(e) { + l.error(e.message); + return res.status(500).send("There was a problem updating the account"); + } +}); + app.post("/shiftAccount", auth, async (req, res) => { let { user } = req; let { asset } = req.body; -- cgit v1.2.3