@riocrypto/common-server 1.0.1311 → 1.0.1313
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Fiat } from "@riocrypto/common";
|
|
2
|
-
export declare const getExchangeRates: (
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const getExchangeRates: (fiat: Fiat) => Promise<{
|
|
3
|
+
conversionRateToUSD: number;
|
|
4
|
+
conversionRateToUSDWithMarkups?: number | undefined;
|
|
5
|
+
conversionRateFromUSD: number;
|
|
6
|
+
conversionRateFromUSDWithMarkups?: number | undefined;
|
|
5
7
|
}>;
|
|
@@ -13,26 +13,28 @@ exports.getExchangeRates = void 0;
|
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
14
|
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
15
15
|
const kapstar_client_1 = require("../clients/kapstar-client");
|
|
16
|
-
const getExchangeRates = (
|
|
16
|
+
const getExchangeRates = (fiat) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
18
18
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
19
|
-
const
|
|
19
|
+
const conversionRateToUSD = fiat === common_1.Fiat.BRL
|
|
20
20
|
? yield kapstarClient.getBRLExchangeRateUSD()
|
|
21
|
-
: yield currencyAPIClient.convert(
|
|
22
|
-
let
|
|
21
|
+
: yield currencyAPIClient.convert(fiat, common_1.Fiat.USD);
|
|
22
|
+
let conversionRateFromUSD = 1 / conversionRateToUSD;
|
|
23
|
+
let conversionRateToUSDWithMarkups = conversionRateToUSD;
|
|
24
|
+
let conversionRateFromUSDWithMarkups = conversionRateFromUSD;
|
|
23
25
|
// Time based markups
|
|
24
|
-
if (
|
|
26
|
+
if (fiat === common_1.Fiat.PEN) {
|
|
25
27
|
const now = new Date();
|
|
26
28
|
const peruTime = new Date(now.toLocaleString("en-US", { timeZone: "America/Lima" }));
|
|
27
29
|
const hours = peruTime.getHours();
|
|
28
30
|
const minutes = peruTime.getMinutes();
|
|
29
31
|
// Check if it's between 2:10 PM and 12:00 AM
|
|
30
32
|
if ((hours === 14 && minutes >= 10) || hours > 14 || hours === 0) {
|
|
31
|
-
|
|
33
|
+
conversionRateToUSDWithMarkups = conversionRateToUSD * 0.997;
|
|
34
|
+
conversionRateFromUSDWithMarkups = conversionRateFromUSD * 0.997;
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
if (
|
|
35
|
-
(from === common_1.Fiat.USD && to === common_1.Fiat.MXN)) {
|
|
37
|
+
if (fiat === common_1.Fiat.MXN) {
|
|
36
38
|
const now = new Date();
|
|
37
39
|
const mexicoCityTime = new Date(now.toLocaleString("en-US", { timeZone: "America/Mexico_City" }));
|
|
38
40
|
const hours = mexicoCityTime.getHours();
|
|
@@ -40,15 +42,19 @@ const getExchangeRates = (from, to) => __awaiter(void 0, void 0, void 0, functio
|
|
|
40
42
|
if ((hours === 15 && minutes >= 45) ||
|
|
41
43
|
(hours > 15 && hours < 24) ||
|
|
42
44
|
(hours === 0 && minutes === 0)) {
|
|
43
|
-
|
|
45
|
+
conversionRateToUSDWithMarkups = conversionRateToUSD * 0.997;
|
|
46
|
+
conversionRateFromUSDWithMarkups = conversionRateFromUSD * 0.997;
|
|
44
47
|
}
|
|
45
48
|
else if (hours >= 0 && hours < 7) {
|
|
46
|
-
|
|
49
|
+
conversionRateToUSDWithMarkups = conversionRateToUSD * 0.996;
|
|
50
|
+
conversionRateFromUSDWithMarkups = conversionRateFromUSD * 0.996;
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
conversionRateToUSD,
|
|
55
|
+
conversionRateToUSDWithMarkups,
|
|
56
|
+
conversionRateFromUSD,
|
|
57
|
+
conversionRateFromUSDWithMarkups,
|
|
52
58
|
};
|
|
53
59
|
});
|
|
54
60
|
exports.getExchangeRates = getExchangeRates;
|
|
@@ -8,22 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.getUserTransactionLimits = void 0;
|
|
16
|
-
const mongoose_1 = __importDefault(require("mongoose"));
|
|
17
13
|
const user_1 = require("../models/user");
|
|
18
14
|
const common_1 = require("@riocrypto/common");
|
|
19
15
|
const calculate_aggregate_volume_and_revenue_1 = require("./calculate-aggregate-volume-and-revenue");
|
|
20
|
-
const getUserTransactionLimits = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
const User = (0, user_1.buildUser)(
|
|
16
|
+
const getUserTransactionLimits = (mongoose, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const User = (0, user_1.buildUser)(mongoose);
|
|
22
18
|
const user = yield User.findById(id);
|
|
23
19
|
if (!user) {
|
|
24
20
|
throw new common_1.NotFoundError("User");
|
|
25
21
|
}
|
|
26
|
-
const { volume } = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(
|
|
22
|
+
const { volume } = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose, 30, user, true);
|
|
27
23
|
const { riskTier } = user;
|
|
28
24
|
let limit = 0;
|
|
29
25
|
if (riskTier === common_1.RiskTier.High) {
|