Skip to content

Commit

Permalink
Merge pull request #2904 from hollaex/testnet
Browse files Browse the repository at this point in the history
Testnet
  • Loading branch information
abeikverdi authored Jul 3, 2024
2 parents 7bb0db3 + 98aad77 commit 2a23bde
Show file tree
Hide file tree
Showing 45 changed files with 3,472 additions and 1,150 deletions.
38 changes: 38 additions & 0 deletions server/api/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,43 @@ const getUserBalanceHistoryByAdmin = (req, res) => {
});
};

const disableUserWithdrawal = (req, res) => {
loggerAdmin.verbose(
req.uuid,
'controllers/admin/disableUserWithdrawal auth',
req.auth
);

const {
user_id,
expiry_date
} = req.swagger.params.data.value;

loggerAdmin.info(
req.uuid,
'controllers/admin/disableUserWithdrawal',
user_id,
expiry_date
);

toolsLib.user.disableUserWithdrawal(user_id, { expiry_date })
.then((data) => {
toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], req?.swagger?.params?.data?.value);
loggerAdmin.info(
req.uuid,
'controllers/admin/disableUserWithdrawal successful'
);
return res.status(200).json({ message: 'Success' });
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/admin/disableUserWithdrawal err',
err
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const createTradeByAdmin = (req, res) => {
loggerAdmin.verbose(
Expand Down Expand Up @@ -3034,6 +3071,7 @@ module.exports = {
deleteTransactionLimit,
getUserBalanceHistoryByAdmin,
createTradeByAdmin,
disableUserWithdrawal,
performDirectWithdrawalByAdmin,
getUserReferralCodesByAdmin,
createUserReferralCodeByAdmin
Expand Down
42 changes: 42 additions & 0 deletions server/api/swagger/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,48 @@ paths:
- admin
x-token-permissions:
- can_withdraw
/admin/user/disable-withdrawal:
x-swagger-router-controller: admin
post:
description: Block user withdrawal ability by admin
operationId: disableUserWithdrawal
tags:
- Admin
parameters:
- name: data
in: body
required: true
schema:
type: object
required:
- user_id
properties:
user_id:
type: number
format: int32
expiry_date:
type: ['string', 'null']
format: date-time
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
202:
description: CSV
schema:
type: string
default:
description: Error
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
- hmac
x-security-scopes:
- admin
/admin/user/sessions:
x-swagger-router-controller: admin
get:
Expand Down
2 changes: 1 addition & 1 deletion server/api/swagger/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const definition = {
swagger: '2.0',
info: {
title: 'HollaEx Kit',
version: '2.11.2'
version: '2.11.3'
},
host: 'api.hollaex.com',
basePath: '/v2',
Expand Down
14 changes: 14 additions & 0 deletions server/db/migrations/20240624132614-add-withdrawal-blocked-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const TABLE = 'Users';
const COLUMN = 'withdrawal_blocked';

module.exports = {
up: (queryInterface, Sequelize) =>
queryInterface.addColumn(TABLE, COLUMN, {
type: Sequelize.DATE,
allowNull: true
}),
down: (queryInterface, Sequelize) =>
queryInterface.removeColumn(TABLE, COLUMN)
};
4 changes: 4 additions & 0 deletions server/db/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.BOOLEAN,
defaultValue: true
},
withdrawal_blocked: {
type: DataTypes.DATE,
allowNull: true
},
note: {
type: DataTypes.STRING,
defaultValue: ''
Expand Down
6 changes: 3 additions & 3 deletions server/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ const checkStatus = () => {
return networkNodeLib;
})
.catch((err) => {
loggerInit.info('init/checkStatus/catch error', err.message);
loggerInit.error('init/checkStatus/catch error', err.message);
setTimeout(() => {
process.exit(0);
}, 5000);
process.exit(1);
}, 60000);
});
};

Expand Down
3 changes: 2 additions & 1 deletion server/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ exports.EMAIL_IS_SAME = 'New email cannot be same as the existing one';
exports.EMAIL_EXISTS = 'This email already exists';
exports.CANNOT_CHANGE_DELETED_EMAIL = 'Cannot change deleted email';
exports.FAILED_GET_QUOTE = 'Failed to get the quote';
exports.BALANCE_HISTORY_NOT_ACTIVE = 'This feature is not active on the exchange';
exports.BALANCE_HISTORY_NOT_ACTIVE = 'This feature is not active on the exchange';
exports.WITHDRAWAL_DISABLED = 'Withdrawal disabled for this user';
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.11.2",
"version": "2.11.3",
"private": false,
"description": "HollaEx Kit",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ checkStatus()
message
);

setTimeout(() => { process.exit(1); }, 5000);
setTimeout(() => { process.exit(1); }, 60000);
});
4 changes: 2 additions & 2 deletions server/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const startPluginProcess = async () => {

pluginWorkerThread = childProcess;

pluginWorkerThread.on("exit", (code) => {
pluginWorkerThread.on('exit', (code) => {
if (code === 0) {
startPluginProcess();
}
Expand Down Expand Up @@ -217,7 +217,7 @@ checkStatus()
message
);

setTimeout(() => { process.exit(1); }, 5000);
setTimeout(() => { process.exit(1); }, 60000);
});

module.exports = {
Expand Down
9 changes: 9 additions & 0 deletions server/utils/hollaex-tools-lib/tools/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ const joinKitConfig = (existingKitConfig = {}, newKitConfig = {}) => {
if (newKitConfig.p2p_config.user_fee == null) {
throw new Error('buyer_fee cannot be null');
}

const percentagePattern = /^(100(\.00?)?|(\d{1,2})(\.\d{1,2})?)$/;

if (!percentagePattern.test(newKitConfig.p2p_config.merchant_fee)) {
throw new Error('merchant_fee must be in percentage format');
}
if (!percentagePattern.test(newKitConfig.p2p_config.user_fee)) {
throw new Error('buyer_fee must be in percentage format');
}
}

if (newKitConfig.referral_history_config) {
Expand Down
85 changes: 48 additions & 37 deletions server/utils/hollaex-tools-lib/tools/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ const createP2PDeal = async (data) => {
side,
buying_asset,
spending_asset,
margin,
spread,
exchange_rate,
total_order_amount,
min_order_value,
max_order_value,
Expand All @@ -221,40 +222,45 @@ const createP2PDeal = async (data) => {
//Check Merhcant Tier
if (p2pConfig.starting_merchant_tier > merchant.verification_level) {
throw new Error('Your tier does not support creating P2P deals');
}
};

if (!subscribedToCoin(spending_asset)) {
throw new Error('Invalid coin ' + spending_asset);
}
};

if (!subscribedToCoin(buying_asset)) {
throw new Error('Invalid coin ' + buying_asset);
}
};

const balance = await getP2PAccountBalance(merchant_id, buying_asset);

if(new BigNumber(balance).comparedTo(new BigNumber(total_order_amount)) !== 1) {
if (new BigNumber(balance).comparedTo(new BigNumber(total_order_amount)) !== 1) {
throw new Error(FUNDING_ACCOUNT_INSUFFICIENT_BALANCE);
}
if(min_order_value < 0) {
throw new Error('cannot be less than 0');
}
};

if (min_order_value < 0) {
throw new Error('min order alue cannot be less than 0');
};

if(max_order_value < 0) {
if (max_order_value < 0) {
throw new Error('max order value cannot be less than 0');
}
};

if(min_order_value > max_order_value) {
throw new Error('min order value cannot be bigger than max');
}
if (min_order_value > max_order_value) {
throw new Error('min order value cannot be bigger than max order value');
};

if (margin < 0) {
throw new Error('Margin cannot be less than 0');
}
if (spread < 0) {
throw new Error('spread cannot be less than 0');
};

if (exchange_rate < 0) {
throw new Error('exchange rate cannot be less than 0');
};

if (side !== 'sell') {
throw new Error('side can only be sell');
}
};

data.status = true;

Expand Down Expand Up @@ -287,7 +293,8 @@ const updateP2PDeal = async (data) => {
side,
buying_asset,
spending_asset,
margin,
spread,
exchange_rate,
total_order_amount,
min_order_value,
max_order_value,
Expand Down Expand Up @@ -330,40 +337,44 @@ const updateP2PDeal = async (data) => {

if (!subscribedToCoin(spending_asset)) {
throw new Error('Invalid coin ' + spending_asset);
}
};

if (!subscribedToCoin(buying_asset)) {
throw new Error('Invalid coin ' + buying_asset);
}
};

const balance = await getP2PAccountBalance(merchant_id, buying_asset);

if(new BigNumber(balance).comparedTo(new BigNumber(total_order_amount)) !== 1) {
if (new BigNumber(balance).comparedTo(new BigNumber(total_order_amount)) !== 1) {
throw new Error(FUNDING_ACCOUNT_INSUFFICIENT_BALANCE);
}
if(min_order_value < 0) {
throw new Error('cannot be less than 0');
}
};
if (min_order_value < 0) {
throw new Error('min order alue cannot be less than 0');
};

if(max_order_value < 0) {
throw new Error('cannot be less than 0');
}
if (max_order_value < 0) {
throw new Error('max order value cannot be less than 0');
};

if(min_order_value > max_order_value) {
throw new Error('cannot be bigger');
}
if (min_order_value > max_order_value) {
throw new Error('min order value cannot be bigger than max order value');
};

if (margin < 0) {
throw new Error('Margin cannot be less than 0');
}
if (spread < 0) {
throw new Error('spread cannot be less than 0');
};

if (exchange_rate < 0) {
throw new Error('exchange rate cannot be less than 0');
};

if (side !== 'sell') {
throw new Error('side can only be sell');
}
};

if (data.status == null) {
data.status = true;
}
};

return p2pDeal.update(data, {
fields: [
Expand Down
22 changes: 22 additions & 0 deletions server/utils/hollaex-tools-lib/tools/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,27 @@ const setUsernameById = (userId, username) => {
});
};

const disableUserWithdrawal = async (user_id, opts = { expiry_date : null }) => {
const user = await getUserByKitId(user_id, false);
let { expiry_date } = opts;

if (!user) {
throw new Error(USER_NOT_FOUND);
};

let withdrawal_blocked = null;

if (expiry_date) {
withdrawal_blocked = moment(expiry_date).toISOString();
};

return user.update(
{ withdrawal_blocked },
{ fields: ['withdrawal_blocked'], returning: true }
);
};


const createUserCryptoAddressByNetworkId = (networkId, crypto, opts = {
network: null,
additionalHeaders: null
Expand Down Expand Up @@ -3278,6 +3299,7 @@ module.exports = {
createAudit,
createAuditLog,
getUserStatsByKitId,
disableUserWithdrawal,
getExchangeOperators,
inviteExchangeOperator,
createUserOnNetwork,
Expand Down
Loading

0 comments on commit 2a23bde

Please sign in to comment.