@riocrypto/common-server 1.0.693 → 1.0.696
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,7 +16,9 @@ const kapstar_client_1 = require("../clients/kapstar-client");
|
|
|
16
16
|
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
17
17
|
const partner_1 = require("../models/partner");
|
|
18
18
|
const user_1 = require("../models/user");
|
|
19
|
+
const order_1 = require("../models/order");
|
|
19
20
|
const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, country, partnerId, brokerCustomerId, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
20
22
|
let platformFeeFiat;
|
|
21
23
|
let platformFeeFiatTax = 0;
|
|
22
24
|
let partnerFeeFiat = 0;
|
|
@@ -56,8 +58,40 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
56
58
|
partnerFeeFiat = amountFiat * partner.partnerFee;
|
|
57
59
|
}
|
|
58
60
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
61
|
+
let volume;
|
|
62
|
+
if ((_a = user === null || user === void 0 ? void 0 : user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
63
|
+
const startDate = new Date();
|
|
64
|
+
startDate.setDate(startDate.getDate() - 14); // Subtract 14 days from current date
|
|
65
|
+
const Order = (0, order_1.buildOrder)(mongoose);
|
|
66
|
+
const buyOrders = yield Order.find({
|
|
67
|
+
userId: user.id,
|
|
68
|
+
type: common_1.Side.Buy,
|
|
69
|
+
status: common_1.OrderStatus.Complete,
|
|
70
|
+
createdAt: { $gte: startDate },
|
|
71
|
+
});
|
|
72
|
+
const sellOrders = yield Order.find({
|
|
73
|
+
userId: user.id,
|
|
74
|
+
type: common_1.Side.Buy,
|
|
75
|
+
status: common_1.OrderStatus.Complete,
|
|
76
|
+
createdAt: { $gte: startDate },
|
|
77
|
+
});
|
|
78
|
+
volume =
|
|
79
|
+
buyOrders.reduce((sum, order) => {
|
|
80
|
+
var _a, _b, _c, _d, _e;
|
|
81
|
+
return sum +
|
|
82
|
+
(order.amountFiat -
|
|
83
|
+
((((_a = order.fees) === null || _a === void 0 ? void 0 : _a.partnerFeeFiat) || 0) +
|
|
84
|
+
(((_b = order.fees) === null || _b === void 0 ? void 0 : _b.platformFeeFiat) || 0) +
|
|
85
|
+
(((_c = order.fees) === null || _c === void 0 ? void 0 : _c.platformFeeFiatTax) || 0) +
|
|
86
|
+
(((_d = order.fees) === null || _d === void 0 ? void 0 : _d.processingFeeFiat) || 0) +
|
|
87
|
+
(((_e = order.fees) === null || _e === void 0 ? void 0 : _e.transferFeeFiat) || 0)) || 0);
|
|
88
|
+
}, 0) + sellOrders.reduce((sum, order) => sum + order.amountFiat, 0);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
volume = Number(amountUSD);
|
|
92
|
+
}
|
|
59
93
|
for (const range of user.platformFeeRanges) {
|
|
60
|
-
if (range.min <= Number(
|
|
94
|
+
if (range.min <= Number(volume) && range.max >= Number(volume)) {
|
|
61
95
|
platformFeeFiat = amountFiat * range.fee;
|
|
62
96
|
break;
|
|
63
97
|
}
|
|
@@ -40,16 +40,13 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
40
40
|
authorizationTypes.includes(common_1.AuthorizationType.UserOptional) ||
|
|
41
41
|
authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
|
|
42
42
|
const apiKey = req.header("x-api-key");
|
|
43
|
-
console.log("x-api-key is ", apiKey);
|
|
44
43
|
if (apiKey) {
|
|
45
44
|
try {
|
|
46
|
-
console.log("x-api-key is ", apiKey);
|
|
47
45
|
const hashedApiKey = yield apiKey_1.ApiKey.toHash(apiKey);
|
|
48
46
|
const Auth = yield (0, auth_1.buildAuth)(mongoose);
|
|
49
47
|
const auth = yield Auth.findOne({
|
|
50
48
|
"apiKeys.value": hashedApiKey,
|
|
51
49
|
});
|
|
52
|
-
console.log(auth);
|
|
53
50
|
if (auth) {
|
|
54
51
|
const missing = [];
|
|
55
52
|
if (!auth.password) {
|
|
@@ -63,7 +60,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
63
60
|
phoneNumber: auth.phoneNumber,
|
|
64
61
|
missing,
|
|
65
62
|
};
|
|
66
|
-
console.log(payload);
|
|
67
63
|
req.currentAuth = payload;
|
|
68
64
|
}
|
|
69
65
|
}
|
|
@@ -99,7 +95,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
99
95
|
throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
|
|
100
96
|
}
|
|
101
97
|
const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
|
|
102
|
-
console.log(payload);
|
|
103
98
|
req.currentAdminAuth = payload;
|
|
104
99
|
}
|
|
105
100
|
catch (err) {
|
|
@@ -213,9 +208,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
213
208
|
!req.validAdminApiKey &&
|
|
214
209
|
!req.currentPartnerAuth &&
|
|
215
210
|
!authorizationTypes.includes(common_1.AuthorizationType.Public))) {
|
|
216
|
-
console.log("missing auth");
|
|
217
|
-
console.log("currentAdminAuth, ", req.currentAdminAuth);
|
|
218
|
-
console.log(authorizationTypes);
|
|
219
211
|
if (!req.user &&
|
|
220
212
|
authorizationTypes.includes(common_1.AuthorizationType.UserOptional)) {
|
|
221
213
|
next();
|
|
@@ -223,14 +215,12 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
223
215
|
}
|
|
224
216
|
if (req.currentAdminAuth &&
|
|
225
217
|
authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
|
|
226
|
-
console.log("safe");
|
|
227
218
|
next();
|
|
228
219
|
return;
|
|
229
220
|
}
|
|
230
221
|
if (missingKYC) {
|
|
231
222
|
throw new common_1.MissingKYCApprovalError();
|
|
232
223
|
}
|
|
233
|
-
console.log("not safe");
|
|
234
224
|
if ((authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
235
225
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
|
|
236
226
|
((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.accessToken)) {
|