aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--devrates.js172
-rw-r--r--models/users.js2
-rw-r--r--rates.js41
-rw-r--r--sockets.js2
-rw-r--r--users.js10
5 files changed, 204 insertions, 23 deletions
diff --git a/devrates.js b/devrates.js
new file mode 100644
index 00000000..817db79d
--- /dev/null
+++ b/devrates.js
@@ -0,0 +1,172 @@
+module.exports = {
+ AED: 3.673197203659543,
+ AFN: 76.6256149863538,
+ ALL: 110.8416522346242,
+ AMD: 478.2176049761077,
+ ANG: 1.6440976724364613,
+ AOA: 495.7980659551896,
+ ARS: 60.16250872722986,
+ AUD: 1.488616065356751,
+ AWG: 1.8,
+ AZN: 1.6962307434239756,
+ BAM: 1.773328678810739,
+ BBD: 2.0179975881110193,
+ BDT: 84.84807728925439,
+ BGN: 1.7733658545431463,
+ BHD: 0.37701451667014246,
+ BIF: 1882.026875334355,
+ BMD: 1,
+ BND: 1.3617924143371387,
+ BOB: 6.910922411526291,
+ BRL: 4.243896379446354,
+ BSD: 0.9994332967620843,
+ BTC: 0.00010608684613780408,
+ BTN: 71.33797455729143,
+ BWP: 10.86375819452882,
+ BYN: 2.1386963105352397,
+ BYR: 19600.003905265352,
+ BZD: 2.014552939149673,
+ CAD: 1.3204203577937563,
+ CDF: 1685.0003536228205,
+ CHF: 0.9699348064595101,
+ CLF: 0.028905492034419285,
+ CLP: 797.5984676344447,
+ CNY: 6.936699701687416,
+ COP: 3415.0006800438855,
+ CRC: 565.1944327073908,
+ CUC: 1,
+ CUP: 26.500005440351085,
+ CVE: 99.97282272615992,
+ CZK: 22.890403220687844,
+ DJF: 177.71966414899308,
+ DKK: 6.775711552585527,
+ DOP: 53.16095188009466,
+ DZD: 120.05533381087527,
+ EGP: 15.806803159030528,
+ ERN: 15.000079791815898,
+ ETB: 31.792392575734223,
+ EUR: 0.9067251806649922,
+ FJD: 2.190200114247373,
+ FKP: 0.7634417474407681,
+ GBP: 0.7633973179069156,
+ GEL: 2.8950320527351363,
+ GGP: 0.7634417474407681,
+ GHS: 5.506778677450651,
+ GIP: 0.7634417474407681,
+ GMD: 51.09502026530779,
+ GNF: 9521.397871009276,
+ GTQ: 7.660548387389266,
+ GYD: 208.25970150607054,
+ HKD: 7.769651001477962,
+ HNL: 24.612961636457605,
+ HRK: 6.748502543364132,
+ HTG: 99.227949803694,
+ HUF: 305.64013800357253,
+ IDR: 13667.802722895718,
+ ILS: 3.451430358972499,
+ IMP: 0.7634417474407681,
+ INR: 71.46499950130115,
+ IQD: 1193.147438048002,
+ IRR: 42105.008235784815,
+ ISK: 123.38744004279744,
+ JEP: 0.7634417474407681,
+ JMD: 139.41456744675256,
+ JOD: 0.708966605311596,
+ JPY: 109.06551724137931,
+ KES: 100.60072265996898,
+ KGS: 69.85026612384053,
+ KHR: 4089.819789277068,
+ KMF: 446.5001795315858,
+ KPW: 900.0134594285818,
+ KRW: 1186.498037846709,
+ KWD: 0.30397598991721597,
+ KYD: 0.8328842021271773,
+ KZT: 379.16800529527507,
+ LAK: 8877.657789222665,
+ LBP: 1511.1774996146419,
+ LKR: 181.3996862730875,
+ LRD: 195.25017907822317,
+ LSL: 14.779750106540206,
+ LTL: 2.95274057685856,
+ LVL: 0.6048899688993263,
+ LYD: 1.4029060542040312,
+ MAD: 9.626910696636957,
+ MDL: 17.477868651790327,
+ MGA: 3684.7089348699296,
+ MKD: 55.9018714807729,
+ MMK: 1463.177394434521,
+ MNT: 2748.7517513396865,
+ MOP: 7.997262596679572,
+ MRO: 356.9999410628633,
+ MUR: 36.903554362708206,
+ MVR: 15.4603733894294,
+ MWK: 736.1130459618994,
+ MXN: 18.75570103457343,
+ MYR: 4.086504302410982,
+ MZN: 63.850077525002945,
+ NAD: 14.780262406267283,
+ NGN: 361.5008196795633,
+ NIO: 33.71733567872913,
+ NOK: 9.173537225602292,
+ NPR: 114.14688222546629,
+ NZD: 1.5415452410528891,
+ OMR: 0.3850118327636077,
+ PAB: 0.999442364013891,
+ PEN: 3.344138475069591,
+ PGK: 3.4082131166864635,
+ PHP: 50.85751085803403,
+ PKR: 154.4431709993018,
+ PLN: 3.892450606145783,
+ PYG: 6525.286300289245,
+ QAR: 3.6409975790437676,
+ RON: 4.3302030157679505,
+ RSD: 106.58501999329023,
+ RUB: 63.17741166229928,
+ RWF: 949.3656895191637,
+ SAR: 3.75192180402042,
+ SBD: 8.247527813794916,
+ SCR: 13.70055763598611,
+ SDG: 45.2856737421455,
+ SEK: 9.638936592708117,
+ SGD: 1.3617198763226854,
+ SHP: 0.7634417474407681,
+ SLL: 9715.00196215329,
+ SOS: 585.0003091932866,
+ SRD: 7.458006836707863,
+ STD: 21560.79429579189,
+ SVC: 8.74500893124303,
+ SYP: 514.9989228104854,
+ SZL: 14.688762048110842,
+ THB: 31.129969080671337,
+ TJS: 9.689288855440804,
+ TMT: 3.5100002720175545,
+ TND: 2.822251035933519,
+ TOP: 2.3116505118463646,
+ TRY: 5.979699329930091,
+ TTD: 6.752923735345054,
+ TWD: 30.212996092014468,
+ TZS: 2310.202055545985,
+ UAH: 24.83074886432671,
+ UGX: 3677.8646377179543,
+ USD: 1,
+ UYU: 37.3734148177029,
+ UZS: 9534.72592599309,
+ VEF: 7330111621.478939,
+ VND: 23171.26161650965,
+ VUV: 117.62686717382827,
+ WST: 2.6770380915248397,
+ XAF: 594.7539682827532,
+ XAG: 0.0560981802025624,
+ XAU: 0.0006365210768268246,
+ XCD: 2.7025506179332104,
+ XDR: 0.7268916554081624,
+ XOF: 594.7431882270803,
+ XPF: 108.13165196260665,
+ YER: 250.35016729079578,
+ ZAR: 14.75420131112461,
+ ZMK: 9001.213295311323,
+ ZMW: 14.841628659769507,
+ ZWL: 322.000065284213,
+ VES: 73301.11621478939,
+ KVES: 73.30111621478939,
+}
diff --git a/models/users.js b/models/users.js
index c6a88f04..8edc94b0 100644
--- a/models/users.js
+++ b/models/users.js
@@ -87,7 +87,7 @@ module.exports = sequelize => {
},
currency: {
type: DataTypes.STRING(255),
- allowNull: false,
+ allowNull: true,
defaultValue: "CAD",
primaryKey: false,
autoIncrement: false,
diff --git a/rates.js b/rates.js
index 7c4643d3..03f1cd64 100644
--- a/rates.js
+++ b/rates.js
@@ -7,32 +7,35 @@ module.exports = (app, socket) => {
let fetchRates;
(fetchRates = async () => {
- try {
- let rates = {};
- let res = await axios.get(
- `http://data.fixer.io/api/latest?access_key=${config.fixer}`
- );
+ let rates = require("./devrates");
- let fx = res.data.rates;
+ if (process.env.NODE_ENV === "production") {
+ try {
+ let res = await axios.get(
+ `http://data.fixer.io/api/latest?access_key=${config.fixer}`
+ );
- fx &&
- Object.keys(fx).map(symbol => {
- rates[symbol] = fx[symbol] / fx["USD"];
- });
+ let fx = res.data.rates;
- res = await axios.get(
- "https://api.bitcoinvenezuela.com/?html=no&currency=VEF"
- );
+ fx &&
+ Object.keys(fx).map(symbol => {
+ rates[symbol] = fx[symbol] / fx["USD"];
+ });
- rates.VEF = res.data["exchange_rates"].VEF_USD;
- rates.VES = res.data["exchange_rates"].VEF_USD / 100000;
- rates.KVES = res.data["exchange_rates"].VEF_USD / 100000000;
+ res = await axios.get(
+ "https://api.bitcoinvenezuela.com/?html=no&currency=VEF"
+ );
- app.set("fxrates", rates);
- } catch (e) {
- l(e);
+ rates.VEF = res.data["exchange_rates"].VEF_USD;
+ rates.VES = res.data["exchange_rates"].VEF_USD / 100000;
+ rates.KVES = res.data["exchange_rates"].VEF_USD / 100000000;
+ } catch (e) {
+ l(e);
+ }
}
+ app.set("fxrates", rates);
+
setTimeout(fetchRates, 7200000);
})();
diff --git a/sockets.js b/sockets.js
index 439f3d48..1ea7db7d 100644
--- a/sockets.js
+++ b/sockets.js
@@ -40,6 +40,7 @@ module.exports = (app, db, server) => {
socket.emit("connected");
if (app.get("rates")) socket.emit("rate", app.get("rates").ask);
socket.on("getuser", async (data, callback) => {
+ l("logging in", socket.request.user);
const user = await db.User.findOne({
include: [
{
@@ -59,6 +60,7 @@ module.exports = (app, db, server) => {
socket.on("disconnect", s => {
let user = sids[socket.id];
+ l("logging out", user);
sids[user].splice(sids[user].indexOf(socket.id), 1);
delete sids[socket.id];
});
diff --git a/users.js b/users.js
index 4d90eeac..55d70821 100644
--- a/users.js
+++ b/users.js
@@ -141,15 +141,19 @@ module.exports = (addresses, auth, app, bc, db, emit) => {
user.username = username;
}
- user.currency = currency;
user.currencies = currencies;
+ user.currency = currency;
+ if (currencies.length) {
+ if(!currencies.includes(currency)) user.currency = currencies[0];
+ } else {
+ user.currency = null;
+ }
+
user.email = email;
user.phone = phone;
user.twofa = twofa;
user.pin = pin;
- console.log(user.currencies);
-
if (password && password === passconfirm) {
user.password = await bcrypt.hash(password, 1);
}