Skip to content

Commit

Permalink
Merge pull request #2887 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi authored Jun 25, 2024
2 parents ccc0c41 + 5bf1453 commit 9a835e3
Show file tree
Hide file tree
Showing 192 changed files with 28,951 additions and 1,989 deletions.
202 changes: 101 additions & 101 deletions plugins/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,151 +4,151 @@ import numbro from 'numbro';
import validator from 'validator';
import isEmail from 'validator/lib/isEmail';

export const required = value => (!value ? "Required" : undefined);
export const required = value => (!value ? 'Required' : undefined);

export const editableRequired = (string) => (value) => (!value ? (string || "Required") : undefined);
export const editableRequired = (string) => (value) => (!value ? (string || 'Required') : undefined);

export const validateOtp = (message) => (
value = ''
value = ''
) => {
let error = undefined;
if (value.length !== 6 || !validator.isNumeric(value)) {
error = message;
}
return error;
let error = undefined;
if (value.length !== 6 || !validator.isNumeric(value)) {
error = message;
}
return error;
};

export const DEFAULT_COIN_DATA = {
fullname: '',
symbol: '',
min: 0.001,
fullname: '',
symbol: '',
min: 0.001,
};

const local_base_currnecy = localStorage.getItem('base_currnecy');

export const BASE_CURRENCY = local_base_currnecy
? local_base_currnecy.toLowerCase()
: 'usdt';
? local_base_currnecy.toLowerCase()
: 'usdt';

export const CURRENCY_PRICE_FORMAT = '{0} {1}';

export const formatToCurrency = (amount = 0, min = 0, fullFormat = false) => {
let formatObj = getFormat(min, fullFormat);
return numbro(roundNumber(amount, formatObj.digit)).format(formatObj.format);
let formatObj = getFormat(min, fullFormat);
return numbro(roundNumber(amount, formatObj.digit)).format(formatObj.format);
};

export const roundNumber = (number = 0, decimals = 4) => {
if (number === 0) {
return 0;
} else if (decimals > 0) {
const multipliedNumber = math.multiply(
math.fraction(number),
math.pow(10, decimals)
);
const dividedNumber = math.divide(
math.floor(multipliedNumber),
math.pow(10, decimals)
);
return math.number(dividedNumber);
} else {
return math.floor(number);
}
if (number === 0 || number === Infinity || isNaN(number)) {
return 0;
} else if (decimals > 0) {
const multipliedNumber = math.multiply(
math.fraction(number),
math.pow(10, decimals)
);
const dividedNumber = math.divide(
math.floor(multipliedNumber),
math.pow(10, decimals)
);
return math.number(dividedNumber);
} else {
return math.floor(number);
}
};

export const getFormat = (min = 0, fullFormat) => {
let value = math.format(min, { notation: 'fixed' });
if (fullFormat) {
return { digit: 8, format: '0,0.[00000000]' };
} else if (min % 1) {
let point = value.toString().split('.')[1]
? value.toString().split('.')[1]
: '';
let res = point
.split('')
.map((val) => 0)
.join('');
return { digit: point.length, format: `0,0.[${res}]` };
} else {
return { digit: 4, format: `0,0.[0000]` };
}
let value = math.format(min, { notation: 'fixed' });
if (fullFormat) {
return { digit: 8, format: '0,0.[00000000]' };
} else if (min % 1) {
let point = value.toString().split('.')[1]
? value.toString().split('.')[1]
: '';
let res = point
.split('')
.map((val) => 0)
.join('');
return { digit: point.length, format: `0,0.[${res}]` };
} else {
return { digit: 4, format: '0,0.[0000]' };
}
};

export const getDecimals = (value = 0) => {
let result = math.format(math.number(value), { notation: 'fixed' });
return value % 1
? result.toString().split('.')[1]
? result.toString().split('.')[1].length
: 0
: 0;
let result = math.format(math.number(value), { notation: 'fixed' });
return value % 1
? result.toString().split('.')[1]
? result.toString().split('.')[1].length
: 0
: 0;
};

export const normalizeBTC = (value = 0) => (value ? roundNumber(value, 8) : '');

export const maxValue = (maxValue, message) => (value = 0) =>
value > maxValue
? message
: undefined;
value > maxValue
? message
: undefined;

export const minValue = (minValue, message) => (value = 0) =>
value < minValue
? message
: undefined;
value < minValue
? message
: undefined;

export const checkBalance = (available, message, fee = 0) => (value = 0) => {
const operation =
const operation =
fee > 0
? math.number(
math.add(
math.fraction(value),
math.multiply(math.fraction(value), math.fraction(fee))
)
)
: value;

if (operation > available) {
return message;
}
return undefined;
? math.number(
math.add(
math.fraction(value),
math.multiply(math.fraction(value), math.fraction(fee))
)
)
: value;

if (operation > available) {
return message;
}
return undefined;
};

export const checkBalance_new = (available, message, fee = 0) => (value = 0) => {
const operation =
const operation =
fee > 0
? math.number(
math.add(
math.fraction(value),
math.fraction(fee)
)
)
: value;

if (operation > available) {
return message;
}
return undefined;
? math.number(
math.add(
math.fraction(value),
math.fraction(fee)
)
)
: value;

if (operation > available) {
return message;
}
return undefined;
};

export const toFixed = (exponential) => {
if (Math.abs(exponential) < 1.0) {
let e = parseInt(exponential.toString().split('e-')[1], 10);
if (e) {
exponential *= Math.pow(10, e - 1);
exponential =
if (Math.abs(exponential) < 1.0) {
let e = parseInt(exponential.toString().split('e-')[1], 10);
if (e) {
exponential *= Math.pow(10, e - 1);
exponential =
'0.' + new Array(e).join('0') + exponential.toString().substring(2);
}
} else {
let e = parseInt(exponential.toString().split('+')[1], 10);
if (e > 20) {
e -= 20;
exponential /= Math.pow(10, e);
exponential += new Array(e + 1).join('0');
}
}
return exponential;
}
} else {
let e = parseInt(exponential.toString().split('+')[1], 10);
if (e > 20) {
e -= 20;
exponential /= Math.pow(10, e);
exponential += new Array(e + 1).join('0');
}
}
return exponential;
};

export const email = (value = '') =>
value && !isEmail(value) ? 'Invalid email address' : undefined;
value && !isEmail(value) ? 'Invalid email address' : undefined;

export const maxLength = (length, message) => (value = "") =>
value.length > length ? message : undefined;
export const maxLength = (length, message) => (value = '') =>
value.length > length ? message : undefined;
77 changes: 75 additions & 2 deletions server/api/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const toolsLib = require('hollaex-tools-lib');
const { cloneDeep, pick } = require('lodash');
const { all } = require('bluebird');
const { INIT_CHANNEL, ROLES } = require('../../constants');
const { USER_NOT_FOUND, API_KEY_NOT_PERMITTED, PROVIDE_VALID_EMAIL, INVALID_PASSWORD, USER_EXISTS, NO_DATA_FOR_CSV, INVALID_VERIFICATION_CODE, INVALID_OTP_CODE } = require('../../messages');
const { USER_NOT_FOUND, API_KEY_NOT_PERMITTED, PROVIDE_VALID_EMAIL, INVALID_PASSWORD, USER_EXISTS, NO_DATA_FOR_CSV, INVALID_VERIFICATION_CODE, INVALID_OTP_CODE, REFERRAL_HISTORY_NOT_ACTIVE } = require('../../messages');
const { sendEmail, testSendSMTPEmail, sendRawEmail } = require('../../mail');
const { MAILTYPE } = require('../../mail/strings');
const { errorMessageConverter } = require('../../utils/conversion');
Expand Down Expand Up @@ -2892,6 +2892,77 @@ const createTradeByAdmin = (req, res) => {
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};
const getUserReferralCodesByAdmin = (req, res) => {
loggerAdmin.info(
req.uuid,
'controllers/user/getUserReferralCodesByAdmin',
);

const { limit, page, order_by, order, start_date, end_date } = req.swagger.params;

if (
!toolsLib.getKitConfig().referral_history_config ||
!toolsLib.getKitConfig().referral_history_config.active
) {
throw new Error(REFERRAL_HISTORY_NOT_ACTIVE);
}

const user_id = req.swagger.params.user_id.value;

toolsLib.user.getUserReferralCodes({
user_id,
limit: limit.value,
page: page.value,
order_by: order_by.value,
order: order.value,
start_date: start_date.value,
end_date: end_date.value
})
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/user/getUserReferralCodesByAdmin err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};
const createUserReferralCodeByAdmin = (req, res) => {
loggerAdmin.info(
req.uuid,
'controllers/user/createUserReferralCodeByAdmin',
);
const { user_id, discount, earning_rate, code } = req.swagger.params.data.value;

if (
!toolsLib.getKitConfig().referral_history_config ||
!toolsLib.getKitConfig().referral_history_config.active
) {
throw new Error(REFERRAL_HISTORY_NOT_ACTIVE);
}

toolsLib.user.createUserReferralCode({
user_id,
discount,
earning_rate,
code,
is_admin: true
})
.then(() => {
return res.json({ message: 'success' });
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/user/createUserReferralCodeByAdmin err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

module.exports = {
createInitialAdmin,
Expand Down Expand Up @@ -2963,5 +3034,7 @@ module.exports = {
deleteTransactionLimit,
getUserBalanceHistoryByAdmin,
createTradeByAdmin,
performDirectWithdrawalByAdmin
performDirectWithdrawalByAdmin,
getUserReferralCodesByAdmin,
createUserReferralCodeByAdmin
};
Loading

0 comments on commit 9a835e3

Please sign in to comment.