@riocrypto/common-server 1.0.1593 → 1.0.1595
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.
- package/build/clients/currency-api-client.js +0 -1
- package/build/helpers/get-currency-api-exchange-rates.d.ts +8 -0
- package/build/helpers/get-currency-api-exchange-rates.js +30 -0
- package/build/helpers/get-tax-rate.d.ts +2 -0
- package/build/helpers/get-tax-rate.js +23 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/package.json +2 -2
|
@@ -39,7 +39,6 @@ class CurrencyAPIClient {
|
|
|
39
39
|
catch (e) {
|
|
40
40
|
const cachedResponse = cache.get(`v3/latest?apikey=${this.apiKey}&base_currency=${from}¤cies=${to}`);
|
|
41
41
|
if (!cachedResponse) {
|
|
42
|
-
console.log(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
|
|
43
42
|
throw new common_1.GenericInternalError(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
|
|
44
43
|
}
|
|
45
44
|
const exchangeRate = cachedResponse.data[to].value;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fiat } from "@riocrypto/common";
|
|
2
|
+
import { Mongoose } from "mongoose";
|
|
3
|
+
export declare const getCurrencyAPIExchangeRates: (mongoose: Mongoose, fiat: Fiat) => Promise<{
|
|
4
|
+
conversionRateToUSD: number;
|
|
5
|
+
conversionRateToUSDWithMarkups?: number | undefined;
|
|
6
|
+
conversionRateFromUSD: number;
|
|
7
|
+
conversionRateFromUSDWithMarkups?: number | undefined;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getCurrencyAPIExchangeRates = void 0;
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
14
|
+
const rio_settings_1 = require("../models/rio-settings");
|
|
15
|
+
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
16
|
+
const getCurrencyAPIExchangeRates = (mongoose, fiat) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const RioSettings = (0, rio_settings_1.buildRioSettings)(mongoose);
|
|
18
|
+
const rioSettings = yield RioSettings.findOne();
|
|
19
|
+
if (!rioSettings) {
|
|
20
|
+
throw new Error("Rio settings not found");
|
|
21
|
+
}
|
|
22
|
+
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
23
|
+
const conversionRateToUSD = yield currencyAPIClient.convert(fiat, common_1.Fiat.USD);
|
|
24
|
+
let conversionRateFromUSD = yield currencyAPIClient.convert(common_1.Fiat.USD, fiat);
|
|
25
|
+
return {
|
|
26
|
+
conversionRateToUSD,
|
|
27
|
+
conversionRateFromUSD,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
exports.getCurrencyAPIExchangeRates = getCurrencyAPIExchangeRates;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTaxRate = void 0;
|
|
4
|
+
const common_1 = require("@riocrypto/common");
|
|
5
|
+
const getTaxRate = (user, country, fiat, processor) => {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
let taxRate = 0;
|
|
8
|
+
if ((fiat === common_1.Fiat.MXN && processor === common_1.Processor.SPEI) ||
|
|
9
|
+
(fiat === common_1.Fiat.MXN && processor === common_1.Processor.Bitso) ||
|
|
10
|
+
(fiat === common_1.Fiat.USD && processor === common_1.Processor.SPID)) {
|
|
11
|
+
if (country === common_1.Country.Mexico &&
|
|
12
|
+
((_b = (_a = user === null || user === void 0 ? void 0 : user.onboarding[country]) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.country) === common_1.CountryOfOrigin.Mexico) {
|
|
13
|
+
taxRate = 0.16;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (fiat === common_1.Fiat.PEN && processor === common_1.Processor.Interbank) {
|
|
17
|
+
if (((_d = (_c = user === null || user === void 0 ? void 0 : user.onboarding[country]) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.country) === common_1.CountryOfOrigin.Peru) {
|
|
18
|
+
taxRate = 0.18;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return taxRate;
|
|
22
|
+
};
|
|
23
|
+
exports.getTaxRate = getTaxRate;
|
package/build/index.d.ts
CHANGED
|
@@ -88,3 +88,5 @@ export * from "./helpers/sanitize-quote-doc";
|
|
|
88
88
|
export * from "./helpers/sanitize-order-doc";
|
|
89
89
|
export * from "./helpers/sanitize-chained-order-doc";
|
|
90
90
|
export * from "./helpers/get-polygon-exchange-rates";
|
|
91
|
+
export * from "./helpers/get-currency-api-exchange-rates";
|
|
92
|
+
export * from "./helpers/get-tax-rate";
|
package/build/index.js
CHANGED
|
@@ -104,3 +104,5 @@ __exportStar(require("./helpers/sanitize-quote-doc"), exports);
|
|
|
104
104
|
__exportStar(require("./helpers/sanitize-order-doc"), exports);
|
|
105
105
|
__exportStar(require("./helpers/sanitize-chained-order-doc"), exports);
|
|
106
106
|
__exportStar(require("./helpers/get-polygon-exchange-rates"), exports);
|
|
107
|
+
__exportStar(require("./helpers/get-currency-api-exchange-rates"), exports);
|
|
108
|
+
__exportStar(require("./helpers/get-tax-rate"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1595",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
29
|
"@google-cloud/vision": "^4.0.2",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.4.2",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.1433",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^1.6.0",
|
|
34
34
|
"ccxt": "^3.0.30",
|