@fileverse-dev/fortune-react 1.0.35 → 1.0.36

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.
Files changed (45) hide show
  1. package/es/components/CryptoDenominationSelector/index.css +67 -0
  2. package/es/components/CryptoDenominationSelector/index.d.ts +8 -0
  3. package/es/components/CryptoDenominationSelector/index.js +272 -0
  4. package/es/components/FormatSearch/index.js +9 -5
  5. package/es/components/SVGDefines.js +60 -1
  6. package/es/components/SheetTab/index.js +22 -2
  7. package/es/components/Toolbar/Combo.js +18 -4
  8. package/es/components/Toolbar/index.css +6 -0
  9. package/es/components/Toolbar/index.d.ts +1 -1
  10. package/es/components/Toolbar/index.js +334 -3
  11. package/es/components/Workbook/index.d.ts +23 -23
  12. package/es/components/Workbook/index.js +25 -1
  13. package/es/constants.d.ts +26 -0
  14. package/es/constants.js +42 -1
  15. package/es/hooks/useCryptoCells.d.ts +11 -0
  16. package/es/hooks/useCryptoCells.js +210 -0
  17. package/es/utils/convertCellsToCrypto.d.ts +8 -0
  18. package/es/utils/convertCellsToCrypto.js +215 -0
  19. package/es/utils/cryptoApi.d.ts +2 -0
  20. package/es/utils/cryptoApi.js +154 -0
  21. package/es/utils/updateCellsDecimalFormat.d.ts +6 -0
  22. package/es/utils/updateCellsDecimalFormat.js +80 -0
  23. package/lib/components/CryptoDenominationSelector/index.css +67 -0
  24. package/lib/components/CryptoDenominationSelector/index.d.ts +8 -0
  25. package/lib/components/CryptoDenominationSelector/index.js +281 -0
  26. package/lib/components/FormatSearch/index.js +9 -5
  27. package/lib/components/SVGDefines.js +60 -1
  28. package/lib/components/SheetTab/index.js +22 -2
  29. package/lib/components/Toolbar/Combo.js +18 -4
  30. package/lib/components/Toolbar/index.css +6 -0
  31. package/lib/components/Toolbar/index.d.ts +1 -1
  32. package/lib/components/Toolbar/index.js +333 -2
  33. package/lib/components/Workbook/index.d.ts +23 -23
  34. package/lib/components/Workbook/index.js +24 -0
  35. package/lib/constants.d.ts +26 -0
  36. package/lib/constants.js +44 -2
  37. package/lib/hooks/useCryptoCells.d.ts +11 -0
  38. package/lib/hooks/useCryptoCells.js +216 -0
  39. package/lib/utils/convertCellsToCrypto.d.ts +8 -0
  40. package/lib/utils/convertCellsToCrypto.js +222 -0
  41. package/lib/utils/cryptoApi.d.ts +2 -0
  42. package/lib/utils/cryptoApi.js +161 -0
  43. package/lib/utils/updateCellsDecimalFormat.d.ts +6 -0
  44. package/lib/utils/updateCellsDecimalFormat.js +86 -0
  45. package/package.json +2 -2
@@ -0,0 +1,210 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) {
13
+ return value instanceof P ? value : new P(function (resolve) {
14
+ resolve(value);
15
+ });
16
+ }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) {
19
+ try {
20
+ step(generator.next(value));
21
+ } catch (e) {
22
+ reject(e);
23
+ }
24
+ }
25
+ function rejected(value) {
26
+ try {
27
+ step(generator["throw"](value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ }
32
+ function step(result) {
33
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
34
+ }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ var __generator = this && this.__generator || function (thisArg, body) {
39
+ var _ = {
40
+ label: 0,
41
+ sent: function sent() {
42
+ if (t[0] & 1) throw t[1];
43
+ return t[1];
44
+ },
45
+ trys: [],
46
+ ops: []
47
+ },
48
+ f,
49
+ y,
50
+ t,
51
+ g;
52
+ return g = {
53
+ next: verb(0),
54
+ "throw": verb(1),
55
+ "return": verb(2)
56
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
57
+ return this;
58
+ }), g;
59
+ function verb(n) {
60
+ return function (v) {
61
+ return step([n, v]);
62
+ };
63
+ }
64
+ function step(op) {
65
+ if (f) throw new TypeError("Generator is already executing.");
66
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
+ if (y = 0, t) op = [op[0] & 2, t.value];
69
+ switch (op[0]) {
70
+ case 0:
71
+ case 1:
72
+ t = op;
73
+ break;
74
+ case 4:
75
+ _.label++;
76
+ return {
77
+ value: op[1],
78
+ done: false
79
+ };
80
+ case 5:
81
+ _.label++;
82
+ y = op[1];
83
+ op = [0];
84
+ continue;
85
+ case 7:
86
+ op = _.ops.pop();
87
+ _.trys.pop();
88
+ continue;
89
+ default:
90
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
91
+ _ = 0;
92
+ continue;
93
+ }
94
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
95
+ _.label = op[1];
96
+ break;
97
+ }
98
+ if (op[0] === 6 && _.label < t[1]) {
99
+ _.label = t[1];
100
+ t = op;
101
+ break;
102
+ }
103
+ if (t && _.label < t[2]) {
104
+ _.label = t[2];
105
+ _.ops.push(op);
106
+ break;
107
+ }
108
+ if (t[2]) _.ops.pop();
109
+ _.trys.pop();
110
+ continue;
111
+ }
112
+ op = body.call(thisArg, _);
113
+ } catch (e) {
114
+ op = [6, e];
115
+ y = 0;
116
+ } finally {
117
+ f = t = 0;
118
+ }
119
+ if (op[0] & 5) throw op[1];
120
+ return {
121
+ value: op[0] ? op[1] : void 0,
122
+ done: true
123
+ };
124
+ }
125
+ };
126
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
127
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
128
+ if (ar || !(i in from)) {
129
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
130
+ ar[i] = from[i];
131
+ }
132
+ }
133
+ return to.concat(ar || Array.prototype.slice.call(from));
134
+ };
135
+ import { useEffect, useRef, useState } from "react";
136
+ import { getCryptoPrice } from "../utils/cryptoApi";
137
+ export function useCryptoCells() {
138
+ var _this = this;
139
+ var _a = useState([]),
140
+ cryptoCells = _a[0],
141
+ setCryptoCells = _a[1];
142
+ var timerRef = useRef(null);
143
+ var upsertCryptoCell = function upsertCryptoCell(cellId, baseValue, cryptoType, fiat) {
144
+ return __awaiter(_this, void 0, void 0, function () {
145
+ var price;
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ return [4, getCryptoPrice(cryptoType, fiat)];
150
+ case 1:
151
+ price = _a.sent();
152
+ setCryptoCells(function (prev) {
153
+ var idx = prev.findIndex(function (c) {
154
+ return c.cellId === cellId;
155
+ });
156
+ var newCell = {
157
+ cellId: cellId,
158
+ baseValue: baseValue,
159
+ cryptoType: cryptoType,
160
+ fiat: fiat,
161
+ value: baseValue / price
162
+ };
163
+ if (idx === -1) return __spreadArray(__spreadArray([], prev, true), [newCell], false);
164
+ var updated = __spreadArray([], prev, true);
165
+ updated[idx] = newCell;
166
+ return updated;
167
+ });
168
+ return [2];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ useEffect(function () {
174
+ function refreshAll() {
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ var _this = this;
177
+ return __generator(this, function (_a) {
178
+ setCryptoCells(function (prev) {
179
+ var updatePromises = prev.map(function (cell) {
180
+ return __awaiter(_this, void 0, void 0, function () {
181
+ var price;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0:
185
+ return [4, getCryptoPrice(cell.cryptoType, cell.fiat)];
186
+ case 1:
187
+ price = _a.sent();
188
+ return [2, __assign(__assign({}, cell), {
189
+ value: cell.baseValue / price
190
+ })];
191
+ }
192
+ });
193
+ });
194
+ });
195
+ return Promise.all(updatePromises);
196
+ });
197
+ return [2];
198
+ });
199
+ });
200
+ }
201
+ timerRef.current = setInterval(refreshAll, 20 * 60 * 1000);
202
+ return function () {
203
+ if (timerRef.current) clearInterval(timerRef.current);
204
+ };
205
+ }, []);
206
+ return {
207
+ cryptoCells: cryptoCells,
208
+ upsertCryptoCell: upsertCryptoCell
209
+ };
210
+ }
@@ -0,0 +1,8 @@
1
+ export declare const getFiatSymbol: (code: string) => string;
2
+ export declare function convertCellsToCrypto({ context, setContext, denomination, decimals, baseCurrency, }: {
3
+ context: any;
4
+ setContext: (fn: (ctx: any) => void) => void;
5
+ denomination: string;
6
+ decimals: number;
7
+ baseCurrency: string;
8
+ }): Promise<void>;
@@ -0,0 +1,215 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) {
9
+ try {
10
+ step(generator.next(value));
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ }
15
+ function rejected(value) {
16
+ try {
17
+ step(generator["throw"](value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ }
22
+ function step(result) {
23
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
24
+ }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ };
28
+ var __generator = this && this.__generator || function (thisArg, body) {
29
+ var _ = {
30
+ label: 0,
31
+ sent: function sent() {
32
+ if (t[0] & 1) throw t[1];
33
+ return t[1];
34
+ },
35
+ trys: [],
36
+ ops: []
37
+ },
38
+ f,
39
+ y,
40
+ t,
41
+ g;
42
+ return g = {
43
+ next: verb(0),
44
+ "throw": verb(1),
45
+ "return": verb(2)
46
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
47
+ return this;
48
+ }), g;
49
+ function verb(n) {
50
+ return function (v) {
51
+ return step([n, v]);
52
+ };
53
+ }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [0];
74
+ continue;
75
+ case 7:
76
+ op = _.ops.pop();
77
+ _.trys.pop();
78
+ continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
+ _ = 0;
82
+ continue;
83
+ }
84
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
+ _.label = op[1];
86
+ break;
87
+ }
88
+ if (op[0] === 6 && _.label < t[1]) {
89
+ _.label = t[1];
90
+ t = op;
91
+ break;
92
+ }
93
+ if (t && _.label < t[2]) {
94
+ _.label = t[2];
95
+ _.ops.push(op);
96
+ break;
97
+ }
98
+ if (t[2]) _.ops.pop();
99
+ _.trys.pop();
100
+ continue;
101
+ }
102
+ op = body.call(thisArg, _);
103
+ } catch (e) {
104
+ op = [6, e];
105
+ y = 0;
106
+ } finally {
107
+ f = t = 0;
108
+ }
109
+ if (op[0] & 5) throw op[1];
110
+ return {
111
+ value: op[0] ? op[1] : void 0,
112
+ done: true
113
+ };
114
+ }
115
+ };
116
+ import { getFlowdata } from "@fileverse-dev/fortune-core";
117
+ import { getCryptoPrice } from "./cryptoApi";
118
+ export var getFiatSymbol = function getFiatSymbol(code) {
119
+ switch (code) {
120
+ case "USD":
121
+ return "$";
122
+ case "EUR":
123
+ return "€";
124
+ case "GBP":
125
+ return "£";
126
+ case "JPY":
127
+ return "¥";
128
+ case "CNY":
129
+ return "¥";
130
+ case "INR":
131
+ return "₹";
132
+ default:
133
+ return code;
134
+ }
135
+ };
136
+ var COINGECKO_IDS = {
137
+ BTC: "bitcoin",
138
+ ETH: "ethereum",
139
+ SOL: "solana"
140
+ };
141
+ export function convertCellsToCrypto(_a) {
142
+ var context = _a.context,
143
+ setContext = _a.setContext,
144
+ denomination = _a.denomination,
145
+ decimals = _a.decimals,
146
+ baseCurrency = _a.baseCurrency;
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var selections, flowdata, selectedCells, denomStr, coingeckoId, price;
149
+ return __generator(this, function (_b) {
150
+ switch (_b.label) {
151
+ case 0:
152
+ selections = context.luckysheet_select_save;
153
+ flowdata = getFlowdata(context);
154
+ if (!selections || !flowdata) return [2];
155
+ selectedCells = [];
156
+ selections.forEach(function (selection) {
157
+ for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
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
+ selectedCells.forEach(function (_a) {
173
+ var _b, _c, _d;
174
+ var row = _a.row,
175
+ col = _a.col;
176
+ var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
177
+ var baseValue = 0;
178
+ if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
179
+ baseValue = cell.baseValue;
180
+ } else {
181
+ if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
182
+ baseValue = cell.v;
183
+ } else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
184
+ baseValue = parseFloat(cell.v);
185
+ }
186
+ if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
187
+ var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
188
+ if (!Number.isNaN(numericValue)) {
189
+ baseValue = numericValue;
190
+ }
191
+ }
192
+ }
193
+ if (!baseValue || Number.isNaN(baseValue)) return;
194
+ var cryptoValue = baseValue / price;
195
+ setContext(function (ctx) {
196
+ var d = getFlowdata(ctx);
197
+ if (!d || !Array.isArray(d) || !d[row] || !d[row][col] || cryptoValue === null) return;
198
+ if (!d[row]) d[row] = [];
199
+ if (!d[row][col]) d[row][col] = {};
200
+ var cellCp = d[row][col];
201
+ cellCp.v = baseValue.toString();
202
+ cellCp.m = "".concat(cryptoValue.toFixed(decimals), " ").concat(denomStr);
203
+ cellCp.ct = {
204
+ fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
205
+ t: "n"
206
+ };
207
+ cellCp.baseValue = baseValue;
208
+ d[row][col] = cellCp;
209
+ });
210
+ });
211
+ return [2];
212
+ }
213
+ });
214
+ });
215
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getCryptoPrice(crypto: string, fiat: string): Promise<number>;
2
+ export declare function clearCryptoPriceCache(): void;
@@ -0,0 +1,154 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) {
9
+ try {
10
+ step(generator.next(value));
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ }
15
+ function rejected(value) {
16
+ try {
17
+ step(generator["throw"](value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ }
22
+ function step(result) {
23
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
24
+ }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ };
28
+ var __generator = this && this.__generator || function (thisArg, body) {
29
+ var _ = {
30
+ label: 0,
31
+ sent: function sent() {
32
+ if (t[0] & 1) throw t[1];
33
+ return t[1];
34
+ },
35
+ trys: [],
36
+ ops: []
37
+ },
38
+ f,
39
+ y,
40
+ t,
41
+ g;
42
+ return g = {
43
+ next: verb(0),
44
+ "throw": verb(1),
45
+ "return": verb(2)
46
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
47
+ return this;
48
+ }), g;
49
+ function verb(n) {
50
+ return function (v) {
51
+ return step([n, v]);
52
+ };
53
+ }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [0];
74
+ continue;
75
+ case 7:
76
+ op = _.ops.pop();
77
+ _.trys.pop();
78
+ continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
+ _ = 0;
82
+ continue;
83
+ }
84
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
+ _.label = op[1];
86
+ break;
87
+ }
88
+ if (op[0] === 6 && _.label < t[1]) {
89
+ _.label = t[1];
90
+ t = op;
91
+ break;
92
+ }
93
+ if (t && _.label < t[2]) {
94
+ _.label = t[2];
95
+ _.ops.push(op);
96
+ break;
97
+ }
98
+ if (t[2]) _.ops.pop();
99
+ _.trys.pop();
100
+ continue;
101
+ }
102
+ op = body.call(thisArg, _);
103
+ } catch (e) {
104
+ op = [6, e];
105
+ y = 0;
106
+ } finally {
107
+ f = t = 0;
108
+ }
109
+ if (op[0] & 5) throw op[1];
110
+ return {
111
+ value: op[0] ? op[1] : void 0,
112
+ done: true
113
+ };
114
+ }
115
+ };
116
+ var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
117
+ var CACHE_DURATION = 60 * 1000;
118
+ var priceCache = {};
119
+ export function getCryptoPrice(crypto, fiat) {
120
+ var _a;
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var key, now, url, resp, data, price;
123
+ return __generator(this, function (_b) {
124
+ switch (_b.label) {
125
+ case 0:
126
+ key = "".concat(crypto, "-").concat(fiat).toLowerCase();
127
+ now = Date.now();
128
+ if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
129
+ return [2, priceCache[key].price];
130
+ }
131
+ url = "".concat(COINGECKO_API, "?ids=").concat(crypto, "&vs_currencies=").concat(fiat);
132
+ return [4, fetch(url)];
133
+ case 1:
134
+ resp = _b.sent();
135
+ if (!resp.ok) throw new Error("Failed to fetch crypto price");
136
+ return [4, resp.json()];
137
+ case 2:
138
+ data = _b.sent();
139
+ price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
140
+ if (typeof price !== "number") throw new Error("Invalid price data");
141
+ priceCache[key] = {
142
+ price: price,
143
+ timestamp: now
144
+ };
145
+ return [2, price];
146
+ }
147
+ });
148
+ });
149
+ }
150
+ export function clearCryptoPriceCache() {
151
+ Object.keys(priceCache).forEach(function (key) {
152
+ return delete priceCache[key];
153
+ });
154
+ }
@@ -0,0 +1,6 @@
1
+ export declare function updateCellsDecimalFormat({ context, setContext, decimals, denomination, }: {
2
+ context: any;
3
+ setContext: (fn: (ctx: any) => void) => void;
4
+ decimals: number;
5
+ denomination?: string;
6
+ }): void;
@@ -0,0 +1,80 @@
1
+ import { getFlowdata } from "@fileverse-dev/fortune-core";
2
+ import { FIAT_ICON_MAP } from "../constants";
3
+ function getFiatSymbol(code) {
4
+ switch (code) {
5
+ case "USD":
6
+ return "$";
7
+ case "EUR":
8
+ return "€";
9
+ case "GBP":
10
+ return "£";
11
+ case "JPY":
12
+ return "¥";
13
+ case "CNY":
14
+ return "¥";
15
+ case "INR":
16
+ return "₹";
17
+ default:
18
+ return code;
19
+ }
20
+ }
21
+ export function updateCellsDecimalFormat(_a) {
22
+ var context = _a.context,
23
+ setContext = _a.setContext,
24
+ decimals = _a.decimals,
25
+ denomination = _a.denomination;
26
+ var selections = context.luckysheet_select_save;
27
+ var flowdata = getFlowdata(context);
28
+ if (!selections || !flowdata) return;
29
+ var selectedCells = [];
30
+ selections.forEach(function (selection) {
31
+ for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
32
+ for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
33
+ selectedCells.push({
34
+ row: row,
35
+ col: col
36
+ });
37
+ }
38
+ }
39
+ });
40
+ setContext(function (ctx) {
41
+ var d = getFlowdata(ctx);
42
+ if (!d) return;
43
+ selectedCells.forEach(function (_a) {
44
+ var _b;
45
+ var row = _a.row,
46
+ col = _a.col;
47
+ var cell = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col];
48
+ if (!cell) return;
49
+ var denomStr = "ETH";
50
+ var isCrypto = false;
51
+ if (cell.ct && typeof cell.ct.fa === "string") {
52
+ var _c = cell.ct.fa.match(/"([A-Z]+)"/) || [],
53
+ matchedDenom = _c[1];
54
+ if (matchedDenom) {
55
+ denomStr = matchedDenom;
56
+ isCrypto = true;
57
+ }
58
+ }
59
+ if (isCrypto) {
60
+ cell.ct = {
61
+ fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
62
+ t: "n"
63
+ };
64
+ if (typeof cell.v === "number") {
65
+ cell.m = "".concat(cell.v.toFixed(decimals), " ").concat(denomStr);
66
+ }
67
+ } else {
68
+ var fiat = denomination || "USD";
69
+ var symbol = fiat in FIAT_ICON_MAP ? getFiatSymbol(fiat) : fiat;
70
+ cell.ct = {
71
+ fa: "".concat(symbol, " #,##0.").concat("0".repeat(decimals)),
72
+ t: "n"
73
+ };
74
+ if (typeof cell.v === "number") {
75
+ cell.m = "".concat(symbol, " ").concat(cell.v.toFixed(decimals));
76
+ }
77
+ }
78
+ });
79
+ });
80
+ }