Skip to content

Commit

Permalink
Merge pull request #634 from bitholla/testnet
Browse files Browse the repository at this point in the history
Testnet
  • Loading branch information
abeikverdi authored Mar 26, 2021
2 parents 6349e7e + fe2302e commit 22c5f1c
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 142 deletions.
2 changes: 1 addition & 1 deletion server/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
swagger: "2.0"
info:
version: "2.0.12"
version: "2.0.13"
title: HollaEx Kit
host: api.hollaex.com
basePath: /v2
Expand Down
15 changes: 15 additions & 0 deletions server/db/migrations/20210323030530-change-web_view-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const TABLE = 'Plugins';
const COLUMN = 'web_view';

module.exports = {
up: (queryInterface) =>
queryInterface
.changeColumn(TABLE, COLUMN, { type: `jsonb USING '[]'::jsonb;` }),
down: () => {
return new Promise(resolve => {
resolve();
});
}
};
3 changes: 2 additions & 1 deletion server/db/models/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.TEXT
},
web_view: {
type: DataTypes.TEXT
type: DataTypes.JSONB,
defaultValue: []
}
}, {
timestamps: true,
Expand Down
72 changes: 29 additions & 43 deletions server/mail/templates/helpers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const {
BITHOLLA_DOMAIN,
BITHOLLA_LOGO_BLACK,
EMAIL_ICONS
} = require('../../constants');
const { DOMAIN, GET_KIT_CONFIG } = require('../../../constants');
const LOGO_IMAGE = () => GET_KIT_CONFIG().logo_image;
Expand All @@ -25,27 +24,27 @@ const footerTemplate = (language = DEFAULT_LANGUAGE(), domain = DOMAIN) => {
return `
<div style="${styles.footer}">
<div style="float: left">
${(LINKS().terms) ? `<a style="${styles.link}" href="${domain}">${FOOTER.PRIVACY_POLICY}</a>
|
<a style="${styles.link}" href="${domain}">${FOOTER.TERMS}</a>` : ''}
<p>${FOOTER.INVITE_YOUR_FRIENDS} <a style="${styles.link_blue}" href="${domain}">${domain}</a><p>
<p><a style="${styles.link_blue}" href="${domain}">${domain}</a><p>
</div>
<div style="float: right; font-size: 8px; text-align: right;">
<div>
<a href="${LINKS().twitter}">
<img style="padding-right: 5px" src="${EMAIL_ICONS.TWITTER}" height="20"/>
</a>
<a href="${LINKS().facebook}">
<img src="${EMAIL_ICONS.FACEBOOK}" height="20"/>
</a>
</div>
${!LINKS().hide_referral_badge
? `<div style="${styles.poweredby}">
<a href="${LINKS().referral_link && LINKS().referral_label ? LINKS().referral_link : BITHOLLA_DOMAIN}">
${LINKS().referral_label ? LINKS().referral_label : `${FOOTER.POWERED_BY} <img src="${BITHOLLA_LOGO_BLACK}" height="10"/>`}
${
!LINKS().hide_referral_badge
? `<div style="${styles.poweredby}">
<a href="${
LINKS().referral_link && LINKS().referral_label
? LINKS().referral_link
: BITHOLLA_DOMAIN
}">
${
LINKS().referral_label
? LINKS().referral_label
: `${
FOOTER.POWERED_BY
} <img src="${BITHOLLA_LOGO_BLACK}" height="10"/>`
}
</a>
</div>`
: ''
: ''
}
</div>
</div>
Expand All @@ -60,19 +59,7 @@ const LOGO_TEMPLATE = ({ domain = DOMAIN, logoPath = LOGO_IMAGE() }) => `
</div>
`;

const HEADER_TEMPLATE = ({ title, imagePath = '' }) => `
<div style="${styles.header}">
${imagePath &&
`
<div style="${styles.header_icon_wrapper}">
<img style="${styles.header_icon}" src="${imagePath}"/>
</div>
`}
<div style="${styles.header_icon_title}">${title}</div>
</div>
`;

const rtlLanguage = (lang) => (lang === 'fa' || lang === 'ar') ? RTL : '';
const rtlLanguage = (lang) => (lang === 'fa' || lang === 'ar' ? RTL : '');

exports.TemplateEmail = (
headerProps = {},
Expand All @@ -83,17 +70,16 @@ exports.TemplateEmail = (
const bodyStyle = styles.body.concat('');

return `
<div style="${bodyStyle}">
<div style="${styles.wrapper}">
${LOGO_TEMPLATE(domain)}
<div style="${styles.box_shadow}">
${HEADER_TEMPLATE(headerProps)}
<div style="${styles.container}${rtlLanguage(language)}">
${content}
</div>
${footerTemplate(language, domain)}
<div style="${bodyStyle}">
<div style="${styles.wrapper}">
<div style="${styles.box_shadow}">
${LOGO_TEMPLATE(domain)}
<div style="${styles.container}${rtlLanguage(language)}">
${content}
</div>
</div>
</div>
${footerTemplate(language, domain)}
</div>
</div>
</div>
`;
};
};
4 changes: 2 additions & 2 deletions server/mail/templates/helpers/styles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
body:
'background-color: #f3f3f3; padding: 1rem 0; font-family: arial; color: #000 !important',
'background-color: #ffffff; padding: 1rem 0; font-family: arial; color: #000 !important',
logo: 'text-align: center; margin-bottom: 1.5rem;',
wrapper: 'align-items:center; max-width: 45rem; margin: 0 auto;',
header:
'padding-top: 3rem; padding-bottom: 1rem; background-color: #333333; text-align: center',
'padding-top: 3rem; padding-bottom: 1rem; background-color: #ffffff; text-align: center',
header_icon: 'width: 60px',
header_icon_wrapper: 'text-align: center; margin-bottom:0.5rem;',
header_icon_title: 'color: #FFF; text-align: center; font-size: 1.3rem',
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.12",
"version": "2.0.13",
"private": false,
"description": "HollaEx Kit",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions server/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ checkStatus()
},
web_view: {
in: ['body'],
errorMessage: 'must be a string or null',
isString: true,
errorMessage: 'must be an array or null',
isArray: true,
optional: { options: { nullable: true } }
},
prescript: {
Expand Down Expand Up @@ -577,8 +577,8 @@ checkStatus()
},
web_view: {
in: ['body'],
errorMessage: 'must be a string or null',
isString: true,
errorMessage: 'must be an array or null',
isArray: true,
optional: { options: { nullable: true } }
},
prescript: {
Expand Down
13 changes: 8 additions & 5 deletions server/ws/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { isUserBanned } = require('./ban');
const moment = require('moment');
const { subscriber, publisher } = require('../../db/pubsub');
const { getChannels } = require('../channel');
const WebSocket = require('ws');

const MESSAGES_KEY = 'WS:MESSAGES';
let MESSAGES = [];
Expand Down Expand Up @@ -68,11 +69,13 @@ const deleteMessage = (idToDelete) => {

const publishChatMessage = (event, data) => {
each(getChannels()[WEBSOCKET_CHANNEL('chat')], (ws) => {
ws.send(JSON.stringify({
topic: 'chat',
action: event,
data
}));
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
topic: 'chat',
action: event,
data
}));
}
});
};

Expand Down
19 changes: 14 additions & 5 deletions server/ws/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { WS_HUB_CHANNEL, WEBSOCKET_CHANNEL } = require('../constants');
const { each } = require('lodash');
const { getChannels, resetChannels } = require('./channel');
const { updateOrderbookData, updateTradeData, resetPublicData } = require('./publicData');
const WebSocket = require('ws');

let networkNodeLib = null;
let wsConnected = false;
Expand Down Expand Up @@ -63,10 +64,10 @@ const connect = () => {
if (data !== 'pong') {
try {
data = JSON.parse(data);
handleHubData(data);
} catch (err) {
loggerWebsocket.error('ws/hub message err', err.message);
}
handleHubData(data);
}
});
}
Expand All @@ -84,19 +85,25 @@ const handleHubData = (data) => {
case 'orderbook':
updateOrderbookData(data);
each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.symbol)], (ws) => {
ws.send(JSON.stringify(data));
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
break;
case 'trade':
updateTradeData(data);
each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.symbol)], (ws) => {
ws.send(JSON.stringify(data));
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
break;
case 'order':
case 'wallet':
each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.user_id)], (ws) => {
ws.send(JSON.stringify(data));
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
break;
default:
Expand All @@ -107,7 +114,9 @@ const handleHubData = (data) => {
const closeAllClients = () => {
each(getChannels(), (channel) => {
each(channel, (ws) => {
ws.close();
if (ws.readyState !== WebSocket.CONNECTING) {
ws.close();
}
});
});
resetChannels();
Expand Down
13 changes: 8 additions & 5 deletions server/ws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ const {
const { initializeTopic, terminateTopic, authorizeUser, terminateClosedChannels, handleChatData } = require('./sub');
const { connect, hubConnected } = require('./hub');
const { setWsHeartbeat } = require('ws-heartbeat/server');
const WebSocket = require('ws');

wss.on('connection', (ws, req) => {
// attaching unique id and authorization to the socket
ws.id = uuid();
ws.auth = req.auth;

// send welcome message
ws.send(JSON.stringify({ message: WS_WELCOME }));
if (ws.readyState === WebSocket.OPEN) {
// send welcome message
ws.send(JSON.stringify({ message: WS_WELCOME }));

// send authenticated message if authenticated
if (ws.auth.sub) {
ws.send(JSON.stringify({ message: WS_USER_AUTHENTICATED(ws.auth.sub.email) }));
// send authenticated message if authenticated
if (ws.auth.sub) {
ws.send(JSON.stringify({ message: WS_USER_AUTHENTICATED(ws.auth.sub.email) }));
}
}

ws.on('message', (message) => {
Expand Down
13 changes: 10 additions & 3 deletions server/ws/sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ const { sendInitialMessages, addMessage, deleteMessage } = require('./chat');
const { getUsername, changeUsername } = require('./chat/username');
const { sendBannedUsers, banUser, unbanUser } = require('./chat/ban');
const { sendNetworkWsMessage } = require('./hub');
const WebSocket = require('ws');

subscriber.subscribe(WS_PUBSUB_DEPOSIT_CHANNEL);
subscriber.on('message', (channel, data) => {
if (channel === WS_PUBSUB_DEPOSIT_CHANNEL) {
data = JSON.parse(data);
handleDepositData(data);
try {
data = JSON.parse(data);
handleDepositData(data);
} catch (err) {
loggerWebsocket.error('ws/sub/subscriber deposit message', err.message);
}
}
});

Expand Down Expand Up @@ -264,7 +269,9 @@ const handleDepositData = (data) => {
switch (data.topic) {
case 'deposit':
each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.user_id)], (ws) => {
ws.send(JSON.stringify(data));
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.12
2.0.13
Loading

0 comments on commit 22c5f1c

Please sign in to comment.