@fileverse-dev/fortune-react 1.0.51 → 1.0.52
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/es/components/Workbook/index.js +1 -1
- package/es/components/index.d.ts +2 -1
- package/es/components/index.js +2 -2
- package/es/utils/cryptoApi.js +29 -28
- package/lib/components/Workbook/index.js +1 -1
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +12 -14
- package/lib/utils/cryptoApi.js +29 -28
- package/package.json +2 -2
|
@@ -19,8 +19,8 @@ import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, g
|
|
|
19
19
|
import React, { useMemo, useState, useCallback, useEffect, useRef, useImperativeHandle } from "react";
|
|
20
20
|
import "./index.css";
|
|
21
21
|
import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
|
|
22
|
-
import { getCryptoPrice } from "../../utils/cryptoApi";
|
|
23
22
|
import _ from "lodash";
|
|
23
|
+
import { getCryptoPrice } from "../../utils/cryptoApi";
|
|
24
24
|
import Sheet from "../Sheet";
|
|
25
25
|
import WorkbookContext from "../../context";
|
|
26
26
|
import Toolbar from "../Toolbar";
|
package/es/components/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Workbook from "./Workbook";
|
|
2
|
+
export { ERROR_MESSAGES_FLAG, SERVICES_API_KEY, } from "@fileverse-dev/formulajs/crypto-constants";
|
|
2
3
|
export { Workbook };
|
|
3
4
|
export type { WorkbookInstance } from "./Workbook";
|
|
4
|
-
export
|
|
5
|
+
export type { Cell, Sheet } from "@fileverse-dev/fortune-core";
|
package/es/components/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import Workbook from "./Workbook";
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
2
|
+
export { ERROR_MESSAGES_FLAG, SERVICES_API_KEY } from "@fileverse-dev/formulajs/crypto-constants";
|
|
3
|
+
export { Workbook };
|
package/es/utils/cryptoApi.js
CHANGED
|
@@ -118,34 +118,6 @@ var CACHE_DURATION = 60 * 1000;
|
|
|
118
118
|
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
119
119
|
var FIAT_LIST = ["usd", "eur", "gbp", "jpy", "cny", "inr", "cad", "aud", "nzd", "sek", "pln"];
|
|
120
120
|
var priceCache = {};
|
|
121
|
-
export function getCryptoPrice(crypto, fiat) {
|
|
122
|
-
var _a;
|
|
123
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
var key, now, data, price;
|
|
125
|
-
return __generator(this, function (_b) {
|
|
126
|
-
switch (_b.label) {
|
|
127
|
-
case 0:
|
|
128
|
-
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
129
|
-
now = Date.now();
|
|
130
|
-
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
131
|
-
return [2, priceCache[key].price];
|
|
132
|
-
} else if (priceCache[key]) {
|
|
133
|
-
fetchCall(COINGECKO_API).then(function (data) {
|
|
134
|
-
updatePriceCache(data, now);
|
|
135
|
-
});
|
|
136
|
-
return [2, priceCache[key].price];
|
|
137
|
-
}
|
|
138
|
-
return [4, fetchCall(COINGECKO_API)];
|
|
139
|
-
case 1:
|
|
140
|
-
data = _b.sent();
|
|
141
|
-
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
142
|
-
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
143
|
-
updatePriceCache(data, now);
|
|
144
|
-
return [2, price];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
121
|
function updatePriceCache(data, timestamp) {
|
|
150
122
|
CRYPTO_LIST.forEach(function (crypto) {
|
|
151
123
|
FIAT_LIST.forEach(function (fiat) {
|
|
@@ -176,6 +148,35 @@ var fetchCall = function fetchCall(url) {
|
|
|
176
148
|
});
|
|
177
149
|
});
|
|
178
150
|
};
|
|
151
|
+
export function getCryptoPrice(crypto, fiat) {
|
|
152
|
+
var _a;
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
var key, now, data, price;
|
|
155
|
+
return __generator(this, function (_b) {
|
|
156
|
+
switch (_b.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
159
|
+
now = Date.now();
|
|
160
|
+
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
161
|
+
return [2, priceCache[key].price];
|
|
162
|
+
}
|
|
163
|
+
if (priceCache[key]) {
|
|
164
|
+
fetchCall(COINGECKO_API).then(function (data) {
|
|
165
|
+
updatePriceCache(data, now);
|
|
166
|
+
});
|
|
167
|
+
return [2, priceCache[key].price];
|
|
168
|
+
}
|
|
169
|
+
return [4, fetchCall(COINGECKO_API)];
|
|
170
|
+
case 1:
|
|
171
|
+
data = _b.sent();
|
|
172
|
+
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
173
|
+
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
174
|
+
updatePriceCache(data, now);
|
|
175
|
+
return [2, price];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
179
180
|
export function clearCryptoPriceCache() {
|
|
180
181
|
Object.keys(priceCache).forEach(function (key) {
|
|
181
182
|
return delete priceCache[key];
|
|
@@ -9,8 +9,8 @@ var _fortuneCore = require("@fileverse-dev/fortune-core");
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
require("./index.css");
|
|
11
11
|
var _immer = _interopRequireWildcard(require("immer"));
|
|
12
|
-
var _cryptoApi = require("../../utils/cryptoApi");
|
|
13
12
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
13
|
+
var _cryptoApi = require("../../utils/cryptoApi");
|
|
14
14
|
var _Sheet = _interopRequireDefault(require("../Sheet"));
|
|
15
15
|
var _context = _interopRequireDefault(require("../../context"));
|
|
16
16
|
var _Toolbar = _interopRequireDefault(require("../Toolbar"));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Workbook from "./Workbook";
|
|
2
|
+
export { ERROR_MESSAGES_FLAG, SERVICES_API_KEY, } from "@fileverse-dev/formulajs/crypto-constants";
|
|
2
3
|
export { Workbook };
|
|
3
4
|
export type { WorkbookInstance } from "./Workbook";
|
|
4
|
-
export
|
|
5
|
+
export type { Cell, Sheet } from "@fileverse-dev/fortune-core";
|
package/lib/components/index.js
CHANGED
|
@@ -3,9 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Object.defineProperty(exports, "ERROR_MESSAGES_FLAG", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _cryptoConstants.ERROR_MESSAGES_FLAG;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "SERVICES_API_KEY", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _cryptoConstants.SERVICES_API_KEY;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
9
18
|
Object.defineProperty(exports, "Workbook", {
|
|
10
19
|
enumerable: true,
|
|
11
20
|
get: function get() {
|
|
@@ -14,15 +23,4 @@ Object.defineProperty(exports, "Workbook", {
|
|
|
14
23
|
});
|
|
15
24
|
var _Workbook = _interopRequireDefault(require("./Workbook"));
|
|
16
25
|
var _cryptoConstants = require("@fileverse-dev/formulajs/crypto-constants");
|
|
17
|
-
Object.keys(_cryptoConstants).forEach(function (key) {
|
|
18
|
-
if (key === "default" || key === "__esModule") return;
|
|
19
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
|
-
if (key in exports && exports[key] === _cryptoConstants[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _cryptoConstants[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
26
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/lib/utils/cryptoApi.js
CHANGED
|
@@ -125,34 +125,6 @@ var CACHE_DURATION = 60 * 1000;
|
|
|
125
125
|
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
126
126
|
var FIAT_LIST = ["usd", "eur", "gbp", "jpy", "cny", "inr", "cad", "aud", "nzd", "sek", "pln"];
|
|
127
127
|
var priceCache = {};
|
|
128
|
-
function getCryptoPrice(crypto, fiat) {
|
|
129
|
-
var _a;
|
|
130
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
var key, now, data, price;
|
|
132
|
-
return __generator(this, function (_b) {
|
|
133
|
-
switch (_b.label) {
|
|
134
|
-
case 0:
|
|
135
|
-
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
136
|
-
now = Date.now();
|
|
137
|
-
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
138
|
-
return [2, priceCache[key].price];
|
|
139
|
-
} else if (priceCache[key]) {
|
|
140
|
-
fetchCall(COINGECKO_API).then(function (data) {
|
|
141
|
-
updatePriceCache(data, now);
|
|
142
|
-
});
|
|
143
|
-
return [2, priceCache[key].price];
|
|
144
|
-
}
|
|
145
|
-
return [4, fetchCall(COINGECKO_API)];
|
|
146
|
-
case 1:
|
|
147
|
-
data = _b.sent();
|
|
148
|
-
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
149
|
-
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
150
|
-
updatePriceCache(data, now);
|
|
151
|
-
return [2, price];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
128
|
function updatePriceCache(data, timestamp) {
|
|
157
129
|
CRYPTO_LIST.forEach(function (crypto) {
|
|
158
130
|
FIAT_LIST.forEach(function (fiat) {
|
|
@@ -183,6 +155,35 @@ var fetchCall = function fetchCall(url) {
|
|
|
183
155
|
});
|
|
184
156
|
});
|
|
185
157
|
};
|
|
158
|
+
function getCryptoPrice(crypto, fiat) {
|
|
159
|
+
var _a;
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
var key, now, data, price;
|
|
162
|
+
return __generator(this, function (_b) {
|
|
163
|
+
switch (_b.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
166
|
+
now = Date.now();
|
|
167
|
+
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
168
|
+
return [2, priceCache[key].price];
|
|
169
|
+
}
|
|
170
|
+
if (priceCache[key]) {
|
|
171
|
+
fetchCall(COINGECKO_API).then(function (data) {
|
|
172
|
+
updatePriceCache(data, now);
|
|
173
|
+
});
|
|
174
|
+
return [2, priceCache[key].price];
|
|
175
|
+
}
|
|
176
|
+
return [4, fetchCall(COINGECKO_API)];
|
|
177
|
+
case 1:
|
|
178
|
+
data = _b.sent();
|
|
179
|
+
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
180
|
+
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
181
|
+
updatePriceCache(data, now);
|
|
182
|
+
return [2, price];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
186
187
|
function clearCryptoPriceCache() {
|
|
187
188
|
Object.keys(priceCache).forEach(function (key) {
|
|
188
189
|
return delete priceCache[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"tsc": "tsc"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@fileverse-dev/fortune-core": "1.0.
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.0.52",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-16",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|