@fileverse-dev/fortune-react 1.0.50 → 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.d.ts +2 -1
- package/es/components/Workbook/index.js +4 -0
- package/es/components/index.d.ts +2 -1
- package/es/components/index.js +2 -2
- package/es/utils/cryptoApi.js +42 -14
- package/lib/components/Workbook/index.d.ts +2 -1
- package/lib/components/Workbook/index.js +4 -0
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +12 -14
- package/lib/utils/cryptoApi.js +42 -14
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Settings, Context, CellWithRowAndCol, Sheet as SheetType, Op, CellMatrix, api } from "@fileverse-dev/fortune-core";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import "./index.css";
|
|
4
|
+
import { getCryptoPrice } from "../../utils/cryptoApi";
|
|
4
5
|
import { generateAPIs } from "./api";
|
|
5
6
|
export type WorkbookInstance = ReturnType<typeof generateAPIs>;
|
|
6
7
|
type AdditionalProps = {
|
|
@@ -9,7 +10,7 @@ type AdditionalProps = {
|
|
|
9
10
|
};
|
|
10
11
|
declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalProps & React.RefAttributes<{
|
|
11
12
|
applyOp: (ops: Op[]) => void;
|
|
12
|
-
getCryptoPrice: typeof
|
|
13
|
+
getCryptoPrice: typeof getCryptoPrice;
|
|
13
14
|
getCellValue: (row: number, column: number, options?: api.CommonOptions & {
|
|
14
15
|
type?: "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
|
|
15
16
|
}) => any;
|
|
@@ -20,6 +20,7 @@ import React, { useMemo, useState, useCallback, useEffect, useRef, useImperative
|
|
|
20
20
|
import "./index.css";
|
|
21
21
|
import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
|
|
22
22
|
import _ from "lodash";
|
|
23
|
+
import { getCryptoPrice } from "../../utils/cryptoApi";
|
|
23
24
|
import Sheet from "../Sheet";
|
|
24
25
|
import WorkbookContext from "../../context";
|
|
25
26
|
import Toolbar from "../Toolbar";
|
|
@@ -322,6 +323,9 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
322
323
|
var _a, _b;
|
|
323
324
|
(_b = (_a = mergedSettings.hooks) === null || _a === void 0 ? void 0 : _a.afterActivateSheet) === null || _b === void 0 ? void 0 : _b.call(_a, context.currentSheetId);
|
|
324
325
|
}, [context.currentSheetId]);
|
|
326
|
+
useEffect(function () {
|
|
327
|
+
getCryptoPrice("bitcoin", "usd");
|
|
328
|
+
}, []);
|
|
325
329
|
useEffect(function () {
|
|
326
330
|
var _a, _b;
|
|
327
331
|
setContext(function (ctx) {
|
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
|
@@ -113,37 +113,65 @@ var __generator = this && this.__generator || function (thisArg, body) {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
|
|
116
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,eur,gbp,jpy,cny,inr,cad,aud,nzd,sek,pln";
|
|
117
117
|
var CACHE_DURATION = 60 * 1000;
|
|
118
|
+
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
119
|
+
var FIAT_LIST = ["usd", "eur", "gbp", "jpy", "cny", "inr", "cad", "aud", "nzd", "sek", "pln"];
|
|
118
120
|
var priceCache = {};
|
|
121
|
+
function updatePriceCache(data, timestamp) {
|
|
122
|
+
CRYPTO_LIST.forEach(function (crypto) {
|
|
123
|
+
FIAT_LIST.forEach(function (fiat) {
|
|
124
|
+
var _a;
|
|
125
|
+
var price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
126
|
+
if (typeof price === "number") {
|
|
127
|
+
var key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
128
|
+
priceCache[key] = {
|
|
129
|
+
price: price,
|
|
130
|
+
timestamp: timestamp
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
var fetchCall = function fetchCall(url) {
|
|
137
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
return [2, new Promise(function (resolve, reject) {
|
|
140
|
+
fetch(url).then(function (response) {
|
|
141
|
+
return response.json();
|
|
142
|
+
}).then(function (data) {
|
|
143
|
+
return resolve(data);
|
|
144
|
+
}).catch(function (error) {
|
|
145
|
+
return reject(error);
|
|
146
|
+
});
|
|
147
|
+
})];
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
119
151
|
export function getCryptoPrice(crypto, fiat) {
|
|
120
152
|
var _a;
|
|
121
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
-
var key, now,
|
|
154
|
+
var key, now, data, price;
|
|
123
155
|
return __generator(this, function (_b) {
|
|
124
156
|
switch (_b.label) {
|
|
125
157
|
case 0:
|
|
126
158
|
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
127
159
|
now = Date.now();
|
|
128
|
-
console.log("Fetching crypto price for ".concat(key), priceCache);
|
|
129
160
|
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
130
|
-
console.log("Using cached price for ".concat(key));
|
|
131
161
|
return [2, priceCache[key].price];
|
|
132
162
|
}
|
|
133
|
-
|
|
134
|
-
|
|
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)];
|
|
135
170
|
case 1:
|
|
136
|
-
resp = _b.sent();
|
|
137
|
-
if (!resp.ok) throw new Error("Failed to fetch crypto price");
|
|
138
|
-
return [4, resp.json()];
|
|
139
|
-
case 2:
|
|
140
171
|
data = _b.sent();
|
|
141
172
|
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
142
173
|
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
143
|
-
|
|
144
|
-
price: price,
|
|
145
|
-
timestamp: now
|
|
146
|
-
};
|
|
174
|
+
updatePriceCache(data, now);
|
|
147
175
|
return [2, price];
|
|
148
176
|
}
|
|
149
177
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Settings, Context, CellWithRowAndCol, Sheet as SheetType, Op, CellMatrix, api } from "@fileverse-dev/fortune-core";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import "./index.css";
|
|
4
|
+
import { getCryptoPrice } from "../../utils/cryptoApi";
|
|
4
5
|
import { generateAPIs } from "./api";
|
|
5
6
|
export type WorkbookInstance = ReturnType<typeof generateAPIs>;
|
|
6
7
|
type AdditionalProps = {
|
|
@@ -9,7 +10,7 @@ type AdditionalProps = {
|
|
|
9
10
|
};
|
|
10
11
|
declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalProps & React.RefAttributes<{
|
|
11
12
|
applyOp: (ops: Op[]) => void;
|
|
12
|
-
getCryptoPrice: typeof
|
|
13
|
+
getCryptoPrice: typeof getCryptoPrice;
|
|
13
14
|
getCellValue: (row: number, column: number, options?: api.CommonOptions & {
|
|
14
15
|
type?: "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
|
|
15
16
|
}) => any;
|
|
@@ -10,6 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
require("./index.css");
|
|
11
11
|
var _immer = _interopRequireWildcard(require("immer"));
|
|
12
12
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
13
|
+
var _cryptoApi = require("../../utils/cryptoApi");
|
|
13
14
|
var _Sheet = _interopRequireDefault(require("../Sheet"));
|
|
14
15
|
var _context = _interopRequireDefault(require("../../context"));
|
|
15
16
|
var _Toolbar = _interopRequireDefault(require("../Toolbar"));
|
|
@@ -331,6 +332,9 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
331
332
|
var _a, _b;
|
|
332
333
|
(_b = (_a = mergedSettings.hooks) === null || _a === void 0 ? void 0 : _a.afterActivateSheet) === null || _b === void 0 ? void 0 : _b.call(_a, context.currentSheetId);
|
|
333
334
|
}, [context.currentSheetId]);
|
|
335
|
+
(0, _react.useEffect)(function () {
|
|
336
|
+
(0, _cryptoApi.getCryptoPrice)("bitcoin", "usd");
|
|
337
|
+
}, []);
|
|
334
338
|
(0, _react.useEffect)(function () {
|
|
335
339
|
var _a, _b;
|
|
336
340
|
setContext(function (ctx) {
|
|
@@ -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
|
@@ -120,37 +120,65 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
|
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
-
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
|
|
123
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,eur,gbp,jpy,cny,inr,cad,aud,nzd,sek,pln";
|
|
124
124
|
var CACHE_DURATION = 60 * 1000;
|
|
125
|
+
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
126
|
+
var FIAT_LIST = ["usd", "eur", "gbp", "jpy", "cny", "inr", "cad", "aud", "nzd", "sek", "pln"];
|
|
125
127
|
var priceCache = {};
|
|
128
|
+
function updatePriceCache(data, timestamp) {
|
|
129
|
+
CRYPTO_LIST.forEach(function (crypto) {
|
|
130
|
+
FIAT_LIST.forEach(function (fiat) {
|
|
131
|
+
var _a;
|
|
132
|
+
var price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
133
|
+
if (typeof price === "number") {
|
|
134
|
+
var key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
135
|
+
priceCache[key] = {
|
|
136
|
+
price: price,
|
|
137
|
+
timestamp: timestamp
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
var fetchCall = function fetchCall(url) {
|
|
144
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
return [2, new Promise(function (resolve, reject) {
|
|
147
|
+
fetch(url).then(function (response) {
|
|
148
|
+
return response.json();
|
|
149
|
+
}).then(function (data) {
|
|
150
|
+
return resolve(data);
|
|
151
|
+
}).catch(function (error) {
|
|
152
|
+
return reject(error);
|
|
153
|
+
});
|
|
154
|
+
})];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
126
158
|
function getCryptoPrice(crypto, fiat) {
|
|
127
159
|
var _a;
|
|
128
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var key, now,
|
|
161
|
+
var key, now, data, price;
|
|
130
162
|
return __generator(this, function (_b) {
|
|
131
163
|
switch (_b.label) {
|
|
132
164
|
case 0:
|
|
133
165
|
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
134
166
|
now = Date.now();
|
|
135
|
-
console.log("Fetching crypto price for ".concat(key), priceCache);
|
|
136
167
|
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
137
|
-
console.log("Using cached price for ".concat(key));
|
|
138
168
|
return [2, priceCache[key].price];
|
|
139
169
|
}
|
|
140
|
-
|
|
141
|
-
|
|
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)];
|
|
142
177
|
case 1:
|
|
143
|
-
resp = _b.sent();
|
|
144
|
-
if (!resp.ok) throw new Error("Failed to fetch crypto price");
|
|
145
|
-
return [4, resp.json()];
|
|
146
|
-
case 2:
|
|
147
178
|
data = _b.sent();
|
|
148
179
|
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
149
180
|
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
150
|
-
|
|
151
|
-
price: price,
|
|
152
|
-
timestamp: now
|
|
153
|
-
};
|
|
181
|
+
updatePriceCache(data, now);
|
|
154
182
|
return [2, price];
|
|
155
183
|
}
|
|
156
184
|
});
|
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",
|