@fileverse-dev/fortune-react 1.0.51 → 1.0.53
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/CryptoDenominationSelector/index.js +1 -2
- package/es/components/Toolbar/Combo.js +5 -1
- package/es/components/Toolbar/index.js +1 -2
- 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/convertCellsToCrypto.d.ts +2 -2
- package/es/utils/convertCellsToCrypto.js +151 -78
- package/es/utils/cryptoApi.d.ts +1 -0
- package/es/utils/cryptoApi.js +38 -30
- package/lib/components/CryptoDenominationSelector/index.js +1 -2
- package/lib/components/Toolbar/Combo.js +5 -1
- package/lib/components/Toolbar/index.js +1 -2
- 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/convertCellsToCrypto.d.ts +2 -2
- package/lib/utils/convertCellsToCrypto.js +151 -78
- package/lib/utils/cryptoApi.d.ts +1 -0
- package/lib/utils/cryptoApi.js +39 -30
- package/package.json +2 -2
|
@@ -173,8 +173,7 @@ var CryptoDenominationSelector = function CryptoDenominationSelector(_a) {
|
|
|
173
173
|
context: context,
|
|
174
174
|
setContext: setContext,
|
|
175
175
|
denomination: newDenomination,
|
|
176
|
-
decimals: decimals
|
|
177
|
-
baseCurrency: "USD"
|
|
176
|
+
decimals: decimals
|
|
178
177
|
})];
|
|
179
178
|
case 1:
|
|
180
179
|
_a.sent();
|
|
@@ -87,7 +87,11 @@ var Combo = function Combo(_a) {
|
|
|
87
87
|
})))));
|
|
88
88
|
return /*#__PURE__*/React.createElement("div", {
|
|
89
89
|
ref: buttonRef,
|
|
90
|
-
className: "fortune-toolbar-item"
|
|
90
|
+
className: "fortune-toolbar-item",
|
|
91
|
+
onKeyDown: function onKeyDown(e) {
|
|
92
|
+
e.stopPropagation();
|
|
93
|
+
console.log("clicked");
|
|
94
|
+
}
|
|
91
95
|
}, /*#__PURE__*/React.createElement(Popover, {
|
|
92
96
|
open: open,
|
|
93
97
|
onOpenChange: handleOpenChange,
|
|
@@ -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 };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const getFiatSymbol: (code: string) => string;
|
|
2
|
-
export declare
|
|
2
|
+
export declare const getFiatGeckoId: (symbol: string, baseCurrency: string) => string;
|
|
3
|
+
export declare function convertCellsToCrypto({ context, setContext, denomination, decimals, }: {
|
|
3
4
|
context: any;
|
|
4
5
|
setContext: (fn: (ctx: any) => void) => void;
|
|
5
6
|
denomination: string;
|
|
6
7
|
decimals: number;
|
|
7
|
-
baseCurrency: string;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -114,7 +114,7 @@ var __generator = this && this.__generator || function (thisArg, body) {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
import { getFlowdata } from "@fileverse-dev/fortune-core";
|
|
117
|
-
import {
|
|
117
|
+
import { getCachedPrice } from "./cryptoApi";
|
|
118
118
|
export var getFiatSymbol = function getFiatSymbol(code) {
|
|
119
119
|
switch (code) {
|
|
120
120
|
case "USD":
|
|
@@ -133,6 +133,80 @@ export var getFiatSymbol = function getFiatSymbol(code) {
|
|
|
133
133
|
return code;
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
|
+
export var getFiatGeckoId = function getFiatGeckoId(symbol, baseCurrency) {
|
|
137
|
+
switch (symbol) {
|
|
138
|
+
case "$":
|
|
139
|
+
return "usd";
|
|
140
|
+
case "€":
|
|
141
|
+
return "eur";
|
|
142
|
+
case "£":
|
|
143
|
+
return "gbp";
|
|
144
|
+
case "CN¥":
|
|
145
|
+
return "cny";
|
|
146
|
+
case "HK$":
|
|
147
|
+
return "hkd";
|
|
148
|
+
case "JP¥":
|
|
149
|
+
return "jpy";
|
|
150
|
+
case "AU$":
|
|
151
|
+
return "aud";
|
|
152
|
+
case "৳":
|
|
153
|
+
return "bdt";
|
|
154
|
+
case "BHD":
|
|
155
|
+
return "bhd";
|
|
156
|
+
case "R$":
|
|
157
|
+
return "brl";
|
|
158
|
+
case "CA$":
|
|
159
|
+
return "cad";
|
|
160
|
+
case "CHF":
|
|
161
|
+
return "chf";
|
|
162
|
+
case "CLP$":
|
|
163
|
+
return "clp";
|
|
164
|
+
case "kr.":
|
|
165
|
+
return "dkk";
|
|
166
|
+
case "GEL":
|
|
167
|
+
return "gel";
|
|
168
|
+
case "HUF":
|
|
169
|
+
return "huf";
|
|
170
|
+
case "Rp.":
|
|
171
|
+
return "idr";
|
|
172
|
+
case "Rs.":
|
|
173
|
+
return "inr";
|
|
174
|
+
case "₩":
|
|
175
|
+
return "krw";
|
|
176
|
+
case "KWD":
|
|
177
|
+
return "kwd";
|
|
178
|
+
case "K":
|
|
179
|
+
return "mmk";
|
|
180
|
+
case "Mex$":
|
|
181
|
+
return "mxn";
|
|
182
|
+
case "RM":
|
|
183
|
+
return "myr";
|
|
184
|
+
case "₦":
|
|
185
|
+
return "ngn";
|
|
186
|
+
case "kr":
|
|
187
|
+
return "nok";
|
|
188
|
+
case "₱":
|
|
189
|
+
return "php";
|
|
190
|
+
case "zł":
|
|
191
|
+
return "pln";
|
|
192
|
+
case "₽":
|
|
193
|
+
return "rub";
|
|
194
|
+
case "Rial":
|
|
195
|
+
return "sar";
|
|
196
|
+
case "S$":
|
|
197
|
+
return "sgd";
|
|
198
|
+
case "฿":
|
|
199
|
+
return "thb";
|
|
200
|
+
case "₺":
|
|
201
|
+
return "try";
|
|
202
|
+
case "грн.":
|
|
203
|
+
return "uah";
|
|
204
|
+
case "ZAR":
|
|
205
|
+
return "zar";
|
|
206
|
+
default:
|
|
207
|
+
return baseCurrency || "usd";
|
|
208
|
+
}
|
|
209
|
+
};
|
|
136
210
|
var COINGECKO_IDS = {
|
|
137
211
|
BTC: "bitcoin",
|
|
138
212
|
ETH: "ethereum",
|
|
@@ -142,87 +216,86 @@ export function convertCellsToCrypto(_a) {
|
|
|
142
216
|
var context = _a.context,
|
|
143
217
|
setContext = _a.setContext,
|
|
144
218
|
denomination = _a.denomination,
|
|
145
|
-
decimals = _a.decimals
|
|
146
|
-
baseCurrency = _a.baseCurrency;
|
|
219
|
+
decimals = _a.decimals;
|
|
147
220
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
var selections, flowdata, selectedCells, denomStr, coingeckoId,
|
|
221
|
+
var selections, flowdata, selectedCells, denomStr, coingeckoId, cellUpdates;
|
|
149
222
|
return __generator(this, function (_b) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
|
|
159
|
-
selectedCells.push({
|
|
160
|
-
row: row,
|
|
161
|
-
col: col
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
denomStr = typeof denomination === "string" && denomination.trim() !== "" ? denomination : "ETH";
|
|
167
|
-
denomStr = denomStr.toUpperCase();
|
|
168
|
-
coingeckoId = typeof COINGECKO_IDS[denomStr] === "string" ? COINGECKO_IDS[denomStr] : "ethereum";
|
|
169
|
-
return [4, getCryptoPrice(String(coingeckoId), baseCurrency.toLowerCase())];
|
|
170
|
-
case 1:
|
|
171
|
-
price = _b.sent();
|
|
172
|
-
cellUpdates = [];
|
|
173
|
-
selectedCells.forEach(function (_a) {
|
|
174
|
-
var _b, _c, _d;
|
|
175
|
-
var row = _a.row,
|
|
176
|
-
col = _a.col;
|
|
177
|
-
var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
178
|
-
var baseValue = 0;
|
|
179
|
-
if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
|
|
180
|
-
baseValue = cell.baseValue;
|
|
181
|
-
} else {
|
|
182
|
-
if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
|
|
183
|
-
baseValue = cell.v;
|
|
184
|
-
} else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
|
|
185
|
-
baseValue = parseFloat(cell.v);
|
|
186
|
-
}
|
|
187
|
-
if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
|
|
188
|
-
var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
|
|
189
|
-
if (!Number.isNaN(numericValue)) {
|
|
190
|
-
baseValue = numericValue;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (!baseValue || Number.isNaN(baseValue)) return;
|
|
195
|
-
var cryptoValue = baseValue / price;
|
|
196
|
-
cellUpdates.push({
|
|
223
|
+
selections = context.luckysheet_select_save;
|
|
224
|
+
flowdata = getFlowdata(context);
|
|
225
|
+
if (!selections || !flowdata) return [2];
|
|
226
|
+
selectedCells = [];
|
|
227
|
+
selections.forEach(function (selection) {
|
|
228
|
+
for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
|
|
229
|
+
for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
|
|
230
|
+
selectedCells.push({
|
|
197
231
|
row: row,
|
|
198
|
-
col: col
|
|
199
|
-
baseValue: baseValue,
|
|
200
|
-
cryptoValue: cryptoValue
|
|
232
|
+
col: col
|
|
201
233
|
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
denomStr = typeof denomination === "string" && denomination.trim() !== "" ? denomination : "ETH";
|
|
238
|
+
denomStr = denomStr.toUpperCase();
|
|
239
|
+
coingeckoId = typeof COINGECKO_IDS[denomStr] === "string" ? COINGECKO_IDS[denomStr] : "ethereum";
|
|
240
|
+
cellUpdates = [];
|
|
241
|
+
selectedCells.forEach(function (_a) {
|
|
242
|
+
var _b, _c, _d, _e;
|
|
243
|
+
var row = _a.row,
|
|
244
|
+
col = _a.col;
|
|
245
|
+
var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
246
|
+
var baseValue = 0;
|
|
247
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
|
|
248
|
+
baseValue = cell.baseValue;
|
|
249
|
+
} else {
|
|
250
|
+
if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
|
|
251
|
+
baseValue = cell.v;
|
|
252
|
+
} else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
|
|
253
|
+
baseValue = parseFloat(cell.v);
|
|
254
|
+
}
|
|
255
|
+
if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
|
|
256
|
+
var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
|
|
257
|
+
if (!Number.isNaN(numericValue)) {
|
|
258
|
+
baseValue = numericValue;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (!baseValue || Number.isNaN(baseValue)) return;
|
|
263
|
+
var fiatSymbol = (_e = cell === null || cell === void 0 ? void 0 : cell.m) === null || _e === void 0 ? void 0 : _e.split(" ")[0];
|
|
264
|
+
var fiatVsCryptoPrice = getCachedPrice(coingeckoId, getFiatGeckoId(fiatSymbol, cell === null || cell === void 0 ? void 0 : cell.baseCurrency));
|
|
265
|
+
var cryptoValue = baseValue / fiatVsCryptoPrice;
|
|
266
|
+
console.log(getFiatGeckoId(fiatSymbol, cell === null || cell === void 0 ? void 0 : cell.baseCurrency));
|
|
267
|
+
cellUpdates.push({
|
|
268
|
+
row: row,
|
|
269
|
+
col: col,
|
|
270
|
+
baseValue: baseValue,
|
|
271
|
+
cryptoValue: cryptoValue,
|
|
272
|
+
baseCurrency: getFiatGeckoId(fiatSymbol) || "usd"
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
setContext(function (ctx) {
|
|
276
|
+
var d = getFlowdata(ctx);
|
|
277
|
+
if (!d || !Array.isArray(d)) return;
|
|
278
|
+
cellUpdates.forEach(function (_a) {
|
|
279
|
+
var row = _a.row,
|
|
280
|
+
col = _a.col,
|
|
281
|
+
baseValue = _a.baseValue,
|
|
282
|
+
cryptoValue = _a.cryptoValue,
|
|
283
|
+
baseCurrency = _a.baseCurrency;
|
|
284
|
+
if (!d[row]) d[row] = [];
|
|
285
|
+
if (!d[row][col]) d[row][col] = {};
|
|
286
|
+
var cellCp = d[row][col];
|
|
287
|
+
cellCp.v = baseValue.toString();
|
|
288
|
+
cellCp.m = "".concat(cryptoValue.toFixed(decimals), " ").concat(denomStr);
|
|
289
|
+
cellCp.ct = {
|
|
290
|
+
fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
|
|
291
|
+
t: "n"
|
|
292
|
+
};
|
|
293
|
+
cellCp.baseValue = baseValue;
|
|
294
|
+
cellCp.baseCurrency = baseCurrency.toLowerCase();
|
|
295
|
+
d[row][col] = cellCp;
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
return [2];
|
|
226
299
|
});
|
|
227
300
|
});
|
|
228
301
|
}
|
package/es/utils/cryptoApi.d.ts
CHANGED
package/es/utils/cryptoApi.js
CHANGED
|
@@ -113,39 +113,11 @@ 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?ids=bitcoin,ethereum,solana&vs_currencies=usd,eur,gbp,
|
|
116
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,aed,ars,aud,bdt,bhd,bmd,brl,cad,chf,clp,cny,czk,dkk,eur,gbp,gel,hkd,huf,idr,ils,inr,jpy,krw,kwd,lkr,mmk,mxn,myr,ngn,nok,nzd,php,pkr,pln,rub,sar,sek,sgd,thb,try,twd,uah,vef,vnd,zar";
|
|
117
117
|
var CACHE_DURATION = 60 * 1000;
|
|
118
118
|
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
119
|
-
var FIAT_LIST = ["usd", "eur", "gbp", "
|
|
119
|
+
var FIAT_LIST = ["usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "gel", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar"];
|
|
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,42 @@ 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
|
+
console.log("Fetching price for", crypto, fiat);
|
|
159
|
+
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
160
|
+
now = Date.now();
|
|
161
|
+
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
162
|
+
return [2, priceCache[key].price];
|
|
163
|
+
}
|
|
164
|
+
if (priceCache[key]) {
|
|
165
|
+
fetchCall(COINGECKO_API).then(function (data) {
|
|
166
|
+
updatePriceCache(data, now);
|
|
167
|
+
});
|
|
168
|
+
return [2, priceCache[key].price];
|
|
169
|
+
}
|
|
170
|
+
return [4, fetchCall(COINGECKO_API)];
|
|
171
|
+
case 1:
|
|
172
|
+
data = _b.sent();
|
|
173
|
+
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
174
|
+
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
175
|
+
updatePriceCache(data, now);
|
|
176
|
+
return [2, price];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
export var getCachedPrice = function getCachedPrice(crypto, fiat) {
|
|
182
|
+
var _a;
|
|
183
|
+
var key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
184
|
+
getCryptoPrice(crypto, fiat);
|
|
185
|
+
return (_a = priceCache[key]) === null || _a === void 0 ? void 0 : _a.price;
|
|
186
|
+
};
|
|
179
187
|
export function clearCryptoPriceCache() {
|
|
180
188
|
Object.keys(priceCache).forEach(function (key) {
|
|
181
189
|
return delete priceCache[key];
|
|
@@ -182,8 +182,7 @@ var CryptoDenominationSelector = function CryptoDenominationSelector(_a) {
|
|
|
182
182
|
context: context,
|
|
183
183
|
setContext: setContext,
|
|
184
184
|
denomination: newDenomination,
|
|
185
|
-
decimals: decimals
|
|
186
|
-
baseCurrency: "USD"
|
|
185
|
+
decimals: decimals
|
|
187
186
|
})];
|
|
188
187
|
case 1:
|
|
189
188
|
_a.sent();
|
|
@@ -96,7 +96,11 @@ var Combo = function Combo(_a) {
|
|
|
96
96
|
})))));
|
|
97
97
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
98
98
|
ref: buttonRef,
|
|
99
|
-
className: "fortune-toolbar-item"
|
|
99
|
+
className: "fortune-toolbar-item",
|
|
100
|
+
onKeyDown: function onKeyDown(e) {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
console.log("clicked");
|
|
103
|
+
}
|
|
100
104
|
}, /*#__PURE__*/_react.default.createElement(_ui.Popover, {
|
|
101
105
|
open: open,
|
|
102
106
|
onOpenChange: handleOpenChange,
|
|
@@ -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 }; }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const getFiatSymbol: (code: string) => string;
|
|
2
|
-
export declare
|
|
2
|
+
export declare const getFiatGeckoId: (symbol: string, baseCurrency: string) => string;
|
|
3
|
+
export declare function convertCellsToCrypto({ context, setContext, denomination, decimals, }: {
|
|
3
4
|
context: any;
|
|
4
5
|
setContext: (fn: (ctx: any) => void) => void;
|
|
5
6
|
denomination: string;
|
|
6
7
|
decimals: number;
|
|
7
|
-
baseCurrency: string;
|
|
8
8
|
}): Promise<void>;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.convertCellsToCrypto = convertCellsToCrypto;
|
|
7
|
-
exports.getFiatSymbol = void 0;
|
|
7
|
+
exports.getFiatSymbol = exports.getFiatGeckoId = void 0;
|
|
8
8
|
var _fortuneCore = require("@fileverse-dev/fortune-core");
|
|
9
9
|
var _cryptoApi = require("./cryptoApi");
|
|
10
10
|
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
@@ -140,6 +140,80 @@ var getFiatSymbol = exports.getFiatSymbol = function getFiatSymbol(code) {
|
|
|
140
140
|
return code;
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
var getFiatGeckoId = exports.getFiatGeckoId = function getFiatGeckoId(symbol, baseCurrency) {
|
|
144
|
+
switch (symbol) {
|
|
145
|
+
case "$":
|
|
146
|
+
return "usd";
|
|
147
|
+
case "€":
|
|
148
|
+
return "eur";
|
|
149
|
+
case "£":
|
|
150
|
+
return "gbp";
|
|
151
|
+
case "CN¥":
|
|
152
|
+
return "cny";
|
|
153
|
+
case "HK$":
|
|
154
|
+
return "hkd";
|
|
155
|
+
case "JP¥":
|
|
156
|
+
return "jpy";
|
|
157
|
+
case "AU$":
|
|
158
|
+
return "aud";
|
|
159
|
+
case "৳":
|
|
160
|
+
return "bdt";
|
|
161
|
+
case "BHD":
|
|
162
|
+
return "bhd";
|
|
163
|
+
case "R$":
|
|
164
|
+
return "brl";
|
|
165
|
+
case "CA$":
|
|
166
|
+
return "cad";
|
|
167
|
+
case "CHF":
|
|
168
|
+
return "chf";
|
|
169
|
+
case "CLP$":
|
|
170
|
+
return "clp";
|
|
171
|
+
case "kr.":
|
|
172
|
+
return "dkk";
|
|
173
|
+
case "GEL":
|
|
174
|
+
return "gel";
|
|
175
|
+
case "HUF":
|
|
176
|
+
return "huf";
|
|
177
|
+
case "Rp.":
|
|
178
|
+
return "idr";
|
|
179
|
+
case "Rs.":
|
|
180
|
+
return "inr";
|
|
181
|
+
case "₩":
|
|
182
|
+
return "krw";
|
|
183
|
+
case "KWD":
|
|
184
|
+
return "kwd";
|
|
185
|
+
case "K":
|
|
186
|
+
return "mmk";
|
|
187
|
+
case "Mex$":
|
|
188
|
+
return "mxn";
|
|
189
|
+
case "RM":
|
|
190
|
+
return "myr";
|
|
191
|
+
case "₦":
|
|
192
|
+
return "ngn";
|
|
193
|
+
case "kr":
|
|
194
|
+
return "nok";
|
|
195
|
+
case "₱":
|
|
196
|
+
return "php";
|
|
197
|
+
case "zł":
|
|
198
|
+
return "pln";
|
|
199
|
+
case "₽":
|
|
200
|
+
return "rub";
|
|
201
|
+
case "Rial":
|
|
202
|
+
return "sar";
|
|
203
|
+
case "S$":
|
|
204
|
+
return "sgd";
|
|
205
|
+
case "฿":
|
|
206
|
+
return "thb";
|
|
207
|
+
case "₺":
|
|
208
|
+
return "try";
|
|
209
|
+
case "грн.":
|
|
210
|
+
return "uah";
|
|
211
|
+
case "ZAR":
|
|
212
|
+
return "zar";
|
|
213
|
+
default:
|
|
214
|
+
return baseCurrency || "usd";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
143
217
|
var COINGECKO_IDS = {
|
|
144
218
|
BTC: "bitcoin",
|
|
145
219
|
ETH: "ethereum",
|
|
@@ -149,87 +223,86 @@ function convertCellsToCrypto(_a) {
|
|
|
149
223
|
var context = _a.context,
|
|
150
224
|
setContext = _a.setContext,
|
|
151
225
|
denomination = _a.denomination,
|
|
152
|
-
decimals = _a.decimals
|
|
153
|
-
baseCurrency = _a.baseCurrency;
|
|
226
|
+
decimals = _a.decimals;
|
|
154
227
|
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
-
var selections, flowdata, selectedCells, denomStr, coingeckoId,
|
|
228
|
+
var selections, flowdata, selectedCells, denomStr, coingeckoId, cellUpdates;
|
|
156
229
|
return __generator(this, function (_b) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
|
|
166
|
-
selectedCells.push({
|
|
167
|
-
row: row,
|
|
168
|
-
col: col
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
denomStr = typeof denomination === "string" && denomination.trim() !== "" ? denomination : "ETH";
|
|
174
|
-
denomStr = denomStr.toUpperCase();
|
|
175
|
-
coingeckoId = typeof COINGECKO_IDS[denomStr] === "string" ? COINGECKO_IDS[denomStr] : "ethereum";
|
|
176
|
-
return [4, (0, _cryptoApi.getCryptoPrice)(String(coingeckoId), baseCurrency.toLowerCase())];
|
|
177
|
-
case 1:
|
|
178
|
-
price = _b.sent();
|
|
179
|
-
cellUpdates = [];
|
|
180
|
-
selectedCells.forEach(function (_a) {
|
|
181
|
-
var _b, _c, _d;
|
|
182
|
-
var row = _a.row,
|
|
183
|
-
col = _a.col;
|
|
184
|
-
var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
185
|
-
var baseValue = 0;
|
|
186
|
-
if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
|
|
187
|
-
baseValue = cell.baseValue;
|
|
188
|
-
} else {
|
|
189
|
-
if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
|
|
190
|
-
baseValue = cell.v;
|
|
191
|
-
} else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
|
|
192
|
-
baseValue = parseFloat(cell.v);
|
|
193
|
-
}
|
|
194
|
-
if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
|
|
195
|
-
var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
|
|
196
|
-
if (!Number.isNaN(numericValue)) {
|
|
197
|
-
baseValue = numericValue;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (!baseValue || Number.isNaN(baseValue)) return;
|
|
202
|
-
var cryptoValue = baseValue / price;
|
|
203
|
-
cellUpdates.push({
|
|
230
|
+
selections = context.luckysheet_select_save;
|
|
231
|
+
flowdata = (0, _fortuneCore.getFlowdata)(context);
|
|
232
|
+
if (!selections || !flowdata) return [2];
|
|
233
|
+
selectedCells = [];
|
|
234
|
+
selections.forEach(function (selection) {
|
|
235
|
+
for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
|
|
236
|
+
for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
|
|
237
|
+
selectedCells.push({
|
|
204
238
|
row: row,
|
|
205
|
-
col: col
|
|
206
|
-
baseValue: baseValue,
|
|
207
|
-
cryptoValue: cryptoValue
|
|
239
|
+
col: col
|
|
208
240
|
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
denomStr = typeof denomination === "string" && denomination.trim() !== "" ? denomination : "ETH";
|
|
245
|
+
denomStr = denomStr.toUpperCase();
|
|
246
|
+
coingeckoId = typeof COINGECKO_IDS[denomStr] === "string" ? COINGECKO_IDS[denomStr] : "ethereum";
|
|
247
|
+
cellUpdates = [];
|
|
248
|
+
selectedCells.forEach(function (_a) {
|
|
249
|
+
var _b, _c, _d, _e;
|
|
250
|
+
var row = _a.row,
|
|
251
|
+
col = _a.col;
|
|
252
|
+
var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
253
|
+
var baseValue = 0;
|
|
254
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
|
|
255
|
+
baseValue = cell.baseValue;
|
|
256
|
+
} else {
|
|
257
|
+
if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
|
|
258
|
+
baseValue = cell.v;
|
|
259
|
+
} else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
|
|
260
|
+
baseValue = parseFloat(cell.v);
|
|
261
|
+
}
|
|
262
|
+
if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
|
|
263
|
+
var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
|
|
264
|
+
if (!Number.isNaN(numericValue)) {
|
|
265
|
+
baseValue = numericValue;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!baseValue || Number.isNaN(baseValue)) return;
|
|
270
|
+
var fiatSymbol = (_e = cell === null || cell === void 0 ? void 0 : cell.m) === null || _e === void 0 ? void 0 : _e.split(" ")[0];
|
|
271
|
+
var fiatVsCryptoPrice = (0, _cryptoApi.getCachedPrice)(coingeckoId, getFiatGeckoId(fiatSymbol, cell === null || cell === void 0 ? void 0 : cell.baseCurrency));
|
|
272
|
+
var cryptoValue = baseValue / fiatVsCryptoPrice;
|
|
273
|
+
console.log(getFiatGeckoId(fiatSymbol, cell === null || cell === void 0 ? void 0 : cell.baseCurrency));
|
|
274
|
+
cellUpdates.push({
|
|
275
|
+
row: row,
|
|
276
|
+
col: col,
|
|
277
|
+
baseValue: baseValue,
|
|
278
|
+
cryptoValue: cryptoValue,
|
|
279
|
+
baseCurrency: getFiatGeckoId(fiatSymbol) || "usd"
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
setContext(function (ctx) {
|
|
283
|
+
var d = (0, _fortuneCore.getFlowdata)(ctx);
|
|
284
|
+
if (!d || !Array.isArray(d)) return;
|
|
285
|
+
cellUpdates.forEach(function (_a) {
|
|
286
|
+
var row = _a.row,
|
|
287
|
+
col = _a.col,
|
|
288
|
+
baseValue = _a.baseValue,
|
|
289
|
+
cryptoValue = _a.cryptoValue,
|
|
290
|
+
baseCurrency = _a.baseCurrency;
|
|
291
|
+
if (!d[row]) d[row] = [];
|
|
292
|
+
if (!d[row][col]) d[row][col] = {};
|
|
293
|
+
var cellCp = d[row][col];
|
|
294
|
+
cellCp.v = baseValue.toString();
|
|
295
|
+
cellCp.m = "".concat(cryptoValue.toFixed(decimals), " ").concat(denomStr);
|
|
296
|
+
cellCp.ct = {
|
|
297
|
+
fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
|
|
298
|
+
t: "n"
|
|
299
|
+
};
|
|
300
|
+
cellCp.baseValue = baseValue;
|
|
301
|
+
cellCp.baseCurrency = baseCurrency.toLowerCase();
|
|
302
|
+
d[row][col] = cellCp;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
return [2];
|
|
233
306
|
});
|
|
234
307
|
});
|
|
235
308
|
}
|
package/lib/utils/cryptoApi.d.ts
CHANGED
package/lib/utils/cryptoApi.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.clearCryptoPriceCache = clearCryptoPriceCache;
|
|
7
|
+
exports.getCachedPrice = void 0;
|
|
7
8
|
exports.getCryptoPrice = getCryptoPrice;
|
|
8
9
|
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
9
10
|
function adopt(value) {
|
|
@@ -120,39 +121,11 @@ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
|
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
};
|
|
123
|
-
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,eur,gbp,
|
|
124
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,aed,ars,aud,bdt,bhd,bmd,brl,cad,chf,clp,cny,czk,dkk,eur,gbp,gel,hkd,huf,idr,ils,inr,jpy,krw,kwd,lkr,mmk,mxn,myr,ngn,nok,nzd,php,pkr,pln,rub,sar,sek,sgd,thb,try,twd,uah,vef,vnd,zar";
|
|
124
125
|
var CACHE_DURATION = 60 * 1000;
|
|
125
126
|
var CRYPTO_LIST = ["bitcoin", "ethereum", "solana"];
|
|
126
|
-
var FIAT_LIST = ["usd", "eur", "gbp", "
|
|
127
|
+
var FIAT_LIST = ["usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "gel", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar"];
|
|
127
128
|
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
129
|
function updatePriceCache(data, timestamp) {
|
|
157
130
|
CRYPTO_LIST.forEach(function (crypto) {
|
|
158
131
|
FIAT_LIST.forEach(function (fiat) {
|
|
@@ -183,6 +156,42 @@ var fetchCall = function fetchCall(url) {
|
|
|
183
156
|
});
|
|
184
157
|
});
|
|
185
158
|
};
|
|
159
|
+
function getCryptoPrice(crypto, fiat) {
|
|
160
|
+
var _a;
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var key, now, data, price;
|
|
163
|
+
return __generator(this, function (_b) {
|
|
164
|
+
switch (_b.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
console.log("Fetching price for", crypto, fiat);
|
|
167
|
+
key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
168
|
+
now = Date.now();
|
|
169
|
+
if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
|
|
170
|
+
return [2, priceCache[key].price];
|
|
171
|
+
}
|
|
172
|
+
if (priceCache[key]) {
|
|
173
|
+
fetchCall(COINGECKO_API).then(function (data) {
|
|
174
|
+
updatePriceCache(data, now);
|
|
175
|
+
});
|
|
176
|
+
return [2, priceCache[key].price];
|
|
177
|
+
}
|
|
178
|
+
return [4, fetchCall(COINGECKO_API)];
|
|
179
|
+
case 1:
|
|
180
|
+
data = _b.sent();
|
|
181
|
+
price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
|
|
182
|
+
if (typeof price !== "number") throw new Error("Invalid price data");
|
|
183
|
+
updatePriceCache(data, now);
|
|
184
|
+
return [2, price];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
var getCachedPrice = exports.getCachedPrice = function getCachedPrice(crypto, fiat) {
|
|
190
|
+
var _a;
|
|
191
|
+
var key = "".concat(crypto, "-").concat(fiat).toLowerCase();
|
|
192
|
+
getCryptoPrice(crypto, fiat);
|
|
193
|
+
return (_a = priceCache[key]) === null || _a === void 0 ? void 0 : _a.price;
|
|
194
|
+
};
|
|
186
195
|
function clearCryptoPriceCache() {
|
|
187
196
|
Object.keys(priceCache).forEach(function (key) {
|
|
188
197
|
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.53",
|
|
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.53",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-16",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|