@fileverse-dev/fortune-react 1.0.88-patch-3 → 1.0.88-patch-5

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.
@@ -1,7 +1,4 @@
1
1
  import React from "react";
2
2
  import "./index.css";
3
- export declare function formatExpiryTime(createdAt: number): string;
4
- export declare function isExpired(createdAt: number): boolean;
5
- export declare function timeFromNowMessage(expiryStr: string): string;
6
3
  declare const FormulaHint: React.FC<React.HTMLAttributes<HTMLDivElement>>;
7
4
  export default FormulaHint;
@@ -13,23 +13,7 @@ import { Button, TextField, LucideIcon } from "@fileverse/ui";
13
13
  import React, { useContext, useEffect, useRef, useState } from "react";
14
14
  import WorkbookContext from "../../../context";
15
15
  import "./index.css";
16
- export function formatExpiryTime(createdAt) {
17
- var expiry = new Date(createdAt + 60 * 60 * 1000);
18
- var mm = String(expiry.getMinutes()).padStart(2, "0");
19
- var ss = String(expiry.getSeconds()).padStart(2, "0");
20
- return "".concat(mm, ":").concat(ss);
21
- }
22
- export function isExpired(createdAt) {
23
- var expiryTs = createdAt + 60 * 60 * 1000;
24
- return Date.now() > expiryTs;
25
- }
26
- export function timeFromNowMessage(expiryStr) {
27
- if (!expiryStr) {
28
- return "0 minute";
29
- }
30
- var mm = expiryStr.split(":").map(Number)[0];
31
- return "".concat(mm, " minute").concat(mm !== 1 ? "s" : "");
32
- }
16
+ import { formatTimeLeft, isExpired, timeFromNowMessage } from "./utils/utils";
33
17
  var FormulaHint = function FormulaHint(props) {
34
18
  var _a;
35
19
  var context = useContext(WorkbookContext).context;
@@ -51,9 +35,12 @@ var FormulaHint = function FormulaHint(props) {
51
35
  var _f = useState(true),
52
36
  showFunctionBody = _f[0],
53
37
  setShouldShowFunctionBody = _f[1];
54
- var _g = useState(""),
55
- expiryTime = _g[0],
56
- setExpiryTime = _g[1];
38
+ var _g = useState("0 minute"),
39
+ timeLeft = _g[0],
40
+ setTimeLeft = _g[1];
41
+ var _h = useState(0),
42
+ accessTokenCreatedAt = _h[0],
43
+ setAccessTokenCreatedAt = _h[1];
57
44
  var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
58
45
  var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
59
46
  if (localStorage.getItem("GNOSIS_PAY_ACCESS")) {
@@ -62,13 +49,14 @@ var FormulaHint = function FormulaHint(props) {
62
49
  if (hasGnosisPayToken) {
63
50
  setHasGnosisPayToken(false);
64
51
  }
65
- if (expiryTime) {
66
- setExpiryTime("");
52
+ if (accessTokenCreatedAt) {
53
+ setAccessTokenCreatedAt(0);
67
54
  }
55
+ localStorage.removeItem("GNOSIS_PAY_ACCESS");
68
56
  return;
69
57
  }
70
58
  setHasGnosisPayToken(!!access.token);
71
- setExpiryTime(formatExpiryTime(access.createdAt));
59
+ setAccessTokenCreatedAt(access.createdAt);
72
60
  onDone === null || onDone === void 0 ? void 0 : onDone();
73
61
  } else {
74
62
  var urlParams = new URLSearchParams(window.location.search);
@@ -93,9 +81,9 @@ var FormulaHint = function FormulaHint(props) {
93
81
  ETHERSCAN_API_KEY: "Etherscan API key"
94
82
  };
95
83
  var hintRef = useRef(null);
96
- var _h = useState(0),
97
- top = _h[0],
98
- setTop = _h[1];
84
+ var _j = useState(0),
85
+ top = _j[0],
86
+ setTop = _j[1];
99
87
  var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
100
88
  var _a, _b, _c;
101
89
  if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
@@ -145,14 +133,42 @@ var FormulaHint = function FormulaHint(props) {
145
133
  };
146
134
  }, []);
147
135
  var gnosisTokenTokenIntervalRef = useRef(null);
148
- var _j = useState(false),
149
- isLoading = _j[0],
150
- setIsLoading = _j[1];
136
+ var _k = useState(false),
137
+ isLoading = _k[0],
138
+ setIsLoading = _k[1];
151
139
  useEffect(function () {
152
140
  return function () {
153
141
  if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
154
142
  };
155
143
  }, [gnosisTokenTokenIntervalRef]);
144
+ useEffect(function () {
145
+ if (accessTokenCreatedAt <= 0) return function () {};
146
+ var interval = setInterval(function () {
147
+ var EXPIRY_DURATION_MS = 60 * 60 * 1000;
148
+ var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
149
+ var newTimeLeft = expiryTimestamp - Date.now();
150
+ setTimeLeft(formatTimeLeft(newTimeLeft));
151
+ if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
152
+ clearInterval(interval);
153
+ }
154
+ }, 1000);
155
+ return function () {
156
+ clearInterval(interval);
157
+ };
158
+ }, [accessTokenCreatedAt, fn]);
159
+ var grantAccess = function grantAccess() {
160
+ var button = document.getElementById("grant-gnosispay-access");
161
+ if (!button) return;
162
+ button.click();
163
+ setIsLoading(true);
164
+ var interval = setInterval(function () {
165
+ handleGnosisPayToken(function () {
166
+ clearInterval(interval);
167
+ setIsLoading(false);
168
+ });
169
+ }, 5000);
170
+ gnosisTokenTokenIntervalRef.current = interval;
171
+ };
156
172
  if (!fn) return null;
157
173
  return /*#__PURE__*/React.createElement("div", __assign({}, props, {
158
174
  ref: hintRef,
@@ -315,6 +331,7 @@ var FormulaHint = function FormulaHint(props) {
315
331
  disabled: !API_KEY,
316
332
  className: "min-w-[80px]"
317
333
  }, "Ok"))))))), fn.n === "GNOSISPAY" && (/*#__PURE__*/React.createElement("div", {
334
+ id: "gnosis-pay-area",
318
335
  style: {
319
336
  borderLeft: "4px solid ".concat(hasGnosisPayToken ? "#177E23" : "#fb923c"),
320
337
  backgroundColor: "white",
@@ -339,27 +356,15 @@ var FormulaHint = function FormulaHint(props) {
339
356
  margin: "0 0 16px 0"
340
357
  },
341
358
  className: "text-body-sm color-text-default"
342
- }, !hasGnosisPayToken ? "To access your Gnosis Pay account, please grant permission. Your dSheet account should be created via the same wallet ss your Gnosis Pay. " : " You have ".concat(timeFromNowMessage(expiryTime), " to use your Gnosis Pay account. Then you need to grand access again.")), /*#__PURE__*/React.createElement(Button, {
343
- onClick: function onClick() {
344
- var button = document.getElementById("grant-gnosispay-access");
345
- if (!button) return;
346
- button.click();
347
- setIsLoading(true);
348
- var interval = setInterval(function () {
349
- handleGnosisPayToken(function () {
350
- clearInterval(interval);
351
- setIsLoading(false);
352
- });
353
- }, 5000);
354
- gnosisTokenTokenIntervalRef.current = interval;
355
- },
359
+ }, !hasGnosisPayToken ? "To access your Gnosis Pay account, please grant permission. Your dSheet account should be created via the same wallet ss your Gnosis Pay. " : " You have ".concat(timeFromNowMessage(timeLeft), " to use your Gnosis Pay account. Then you need to grant access again.")), /*#__PURE__*/React.createElement(Button, {
360
+ onClick: grantAccess,
356
361
  disabled: hasGnosisPayToken || isWrongGnosisPayConnector || isLoading,
357
362
  className: "w-full items-center flex gap-1"
358
363
  }, isLoading && (/*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(LucideIcon, {
359
364
  name: "LoaderCircle",
360
365
  className: "animate-spin",
361
366
  size: "sm"
362
- }))), /*#__PURE__*/React.createElement("p", null, "Grant access "), " ", expiryTime && /*#__PURE__*/React.createElement("div", null, expiryTime))))), /*#__PURE__*/React.createElement("div", {
367
+ }))), /*#__PURE__*/React.createElement("p", null, "Grant access "), " ", accessTokenCreatedAt > 0 && /*#__PURE__*/React.createElement("div", null, timeLeft))))), /*#__PURE__*/React.createElement("div", {
363
368
  style: {
364
369
  backgroundColor: "white",
365
370
  padding: "6px",
@@ -0,0 +1,3 @@
1
+ export declare function formatTimeLeft(msLeft: number): string;
2
+ export declare function isExpired(createdAt: number): boolean;
3
+ export declare function timeFromNowMessage(expiryStr: string): string;
@@ -0,0 +1,17 @@
1
+ export function formatTimeLeft(msLeft) {
2
+ var totalSeconds = Math.max(0, Math.floor(msLeft / 1000));
3
+ var minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
4
+ var seconds = String(totalSeconds % 60).padStart(2, "0");
5
+ return "".concat(minutes, ":").concat(seconds);
6
+ }
7
+ export function isExpired(createdAt) {
8
+ var expiryTs = createdAt + 60 * 60 * 1000;
9
+ return Date.now() > expiryTs;
10
+ }
11
+ export function timeFromNowMessage(expiryStr) {
12
+ if (!expiryStr) {
13
+ return "0 minute";
14
+ }
15
+ var mm = expiryStr.split(":").map(Number)[0];
16
+ return "".concat(mm, " minute").concat(mm !== 1 ? "s" : "");
17
+ }
@@ -1,7 +1,4 @@
1
1
  import React from "react";
2
2
  import "./index.css";
3
- export declare function formatExpiryTime(createdAt: number): string;
4
- export declare function isExpired(createdAt: number): boolean;
5
- export declare function timeFromNowMessage(expiryStr: string): string;
6
3
  declare const FormulaHint: React.FC<React.HTMLAttributes<HTMLDivElement>>;
7
4
  export default FormulaHint;
@@ -5,14 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- exports.formatExpiryTime = formatExpiryTime;
9
- exports.isExpired = isExpired;
10
- exports.timeFromNowMessage = timeFromNowMessage;
11
8
  var _fortuneCore = require("@fileverse-dev/fortune-core");
12
9
  var _ui = require("@fileverse/ui");
13
10
  var _react = _interopRequireWildcard(require("react"));
14
11
  var _context = _interopRequireDefault(require("../../../context"));
15
12
  require("./index.css");
13
+ var _utils = require("./utils/utils");
16
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
18
16
  var __assign = void 0 && (void 0).__assign || function () {
@@ -25,23 +23,6 @@ var __assign = void 0 && (void 0).__assign || function () {
25
23
  };
26
24
  return __assign.apply(this, arguments);
27
25
  };
28
- function formatExpiryTime(createdAt) {
29
- var expiry = new Date(createdAt + 60 * 60 * 1000);
30
- var mm = String(expiry.getMinutes()).padStart(2, "0");
31
- var ss = String(expiry.getSeconds()).padStart(2, "0");
32
- return "".concat(mm, ":").concat(ss);
33
- }
34
- function isExpired(createdAt) {
35
- var expiryTs = createdAt + 60 * 60 * 1000;
36
- return Date.now() > expiryTs;
37
- }
38
- function timeFromNowMessage(expiryStr) {
39
- if (!expiryStr) {
40
- return "0 minute";
41
- }
42
- var mm = expiryStr.split(":").map(Number)[0];
43
- return "".concat(mm, " minute").concat(mm !== 1 ? "s" : "");
44
- }
45
26
  var FormulaHint = function FormulaHint(props) {
46
27
  var _a;
47
28
  var context = (0, _react.useContext)(_context.default).context;
@@ -63,24 +44,28 @@ var FormulaHint = function FormulaHint(props) {
63
44
  var _f = (0, _react.useState)(true),
64
45
  showFunctionBody = _f[0],
65
46
  setShouldShowFunctionBody = _f[1];
66
- var _g = (0, _react.useState)(""),
67
- expiryTime = _g[0],
68
- setExpiryTime = _g[1];
47
+ var _g = (0, _react.useState)("0 minute"),
48
+ timeLeft = _g[0],
49
+ setTimeLeft = _g[1];
50
+ var _h = (0, _react.useState)(0),
51
+ accessTokenCreatedAt = _h[0],
52
+ setAccessTokenCreatedAt = _h[1];
69
53
  var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
70
54
  var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
71
55
  if (localStorage.getItem("GNOSIS_PAY_ACCESS")) {
72
56
  var access = JSON.parse(localStorage.getItem("GNOSIS_PAY_ACCESS") || "");
73
- if (!(access === null || access === void 0 ? void 0 : access.token) || isExpired(access === null || access === void 0 ? void 0 : access.createdAt)) {
57
+ if (!(access === null || access === void 0 ? void 0 : access.token) || (0, _utils.isExpired)(access === null || access === void 0 ? void 0 : access.createdAt)) {
74
58
  if (hasGnosisPayToken) {
75
59
  setHasGnosisPayToken(false);
76
60
  }
77
- if (expiryTime) {
78
- setExpiryTime("");
61
+ if (accessTokenCreatedAt) {
62
+ setAccessTokenCreatedAt(0);
79
63
  }
64
+ localStorage.removeItem("GNOSIS_PAY_ACCESS");
80
65
  return;
81
66
  }
82
67
  setHasGnosisPayToken(!!access.token);
83
- setExpiryTime(formatExpiryTime(access.createdAt));
68
+ setAccessTokenCreatedAt(access.createdAt);
84
69
  onDone === null || onDone === void 0 ? void 0 : onDone();
85
70
  } else {
86
71
  var urlParams = new URLSearchParams(window.location.search);
@@ -105,9 +90,9 @@ var FormulaHint = function FormulaHint(props) {
105
90
  ETHERSCAN_API_KEY: "Etherscan API key"
106
91
  };
107
92
  var hintRef = (0, _react.useRef)(null);
108
- var _h = (0, _react.useState)(0),
109
- top = _h[0],
110
- setTop = _h[1];
93
+ var _j = (0, _react.useState)(0),
94
+ top = _j[0],
95
+ setTop = _j[1];
111
96
  var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
112
97
  var _a, _b, _c;
113
98
  if (!((_a = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.top) === null || _a === void 0 ? void 0 : _a.toString()) || !((_b = firstSelection.height_move) === null || _b === void 0 ? void 0 : _b.toString()) || !hintRef.current) return;
@@ -157,14 +142,42 @@ var FormulaHint = function FormulaHint(props) {
157
142
  };
158
143
  }, []);
159
144
  var gnosisTokenTokenIntervalRef = (0, _react.useRef)(null);
160
- var _j = (0, _react.useState)(false),
161
- isLoading = _j[0],
162
- setIsLoading = _j[1];
145
+ var _k = (0, _react.useState)(false),
146
+ isLoading = _k[0],
147
+ setIsLoading = _k[1];
163
148
  (0, _react.useEffect)(function () {
164
149
  return function () {
165
150
  if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
166
151
  };
167
152
  }, [gnosisTokenTokenIntervalRef]);
153
+ (0, _react.useEffect)(function () {
154
+ if (accessTokenCreatedAt <= 0) return function () {};
155
+ var interval = setInterval(function () {
156
+ var EXPIRY_DURATION_MS = 60 * 60 * 1000;
157
+ var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
158
+ var newTimeLeft = expiryTimestamp - Date.now();
159
+ setTimeLeft((0, _utils.formatTimeLeft)(newTimeLeft));
160
+ if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
161
+ clearInterval(interval);
162
+ }
163
+ }, 1000);
164
+ return function () {
165
+ clearInterval(interval);
166
+ };
167
+ }, [accessTokenCreatedAt, fn]);
168
+ var grantAccess = function grantAccess() {
169
+ var button = document.getElementById("grant-gnosispay-access");
170
+ if (!button) return;
171
+ button.click();
172
+ setIsLoading(true);
173
+ var interval = setInterval(function () {
174
+ handleGnosisPayToken(function () {
175
+ clearInterval(interval);
176
+ setIsLoading(false);
177
+ });
178
+ }, 5000);
179
+ gnosisTokenTokenIntervalRef.current = interval;
180
+ };
168
181
  if (!fn) return null;
169
182
  return /*#__PURE__*/_react.default.createElement("div", __assign({}, props, {
170
183
  ref: hintRef,
@@ -327,6 +340,7 @@ var FormulaHint = function FormulaHint(props) {
327
340
  disabled: !API_KEY,
328
341
  className: "min-w-[80px]"
329
342
  }, "Ok"))))))), fn.n === "GNOSISPAY" && (/*#__PURE__*/_react.default.createElement("div", {
343
+ id: "gnosis-pay-area",
330
344
  style: {
331
345
  borderLeft: "4px solid ".concat(hasGnosisPayToken ? "#177E23" : "#fb923c"),
332
346
  backgroundColor: "white",
@@ -351,27 +365,15 @@ var FormulaHint = function FormulaHint(props) {
351
365
  margin: "0 0 16px 0"
352
366
  },
353
367
  className: "text-body-sm color-text-default"
354
- }, !hasGnosisPayToken ? "To access your Gnosis Pay account, please grant permission. Your dSheet account should be created via the same wallet ss your Gnosis Pay. " : " You have ".concat(timeFromNowMessage(expiryTime), " to use your Gnosis Pay account. Then you need to grand access again.")), /*#__PURE__*/_react.default.createElement(_ui.Button, {
355
- onClick: function onClick() {
356
- var button = document.getElementById("grant-gnosispay-access");
357
- if (!button) return;
358
- button.click();
359
- setIsLoading(true);
360
- var interval = setInterval(function () {
361
- handleGnosisPayToken(function () {
362
- clearInterval(interval);
363
- setIsLoading(false);
364
- });
365
- }, 5000);
366
- gnosisTokenTokenIntervalRef.current = interval;
367
- },
368
+ }, !hasGnosisPayToken ? "To access your Gnosis Pay account, please grant permission. Your dSheet account should be created via the same wallet ss your Gnosis Pay. " : " You have ".concat((0, _utils.timeFromNowMessage)(timeLeft), " to use your Gnosis Pay account. Then you need to grant access again.")), /*#__PURE__*/_react.default.createElement(_ui.Button, {
369
+ onClick: grantAccess,
368
370
  disabled: hasGnosisPayToken || isWrongGnosisPayConnector || isLoading,
369
371
  className: "w-full items-center flex gap-1"
370
372
  }, isLoading && (/*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
371
373
  name: "LoaderCircle",
372
374
  className: "animate-spin",
373
375
  size: "sm"
374
- }))), /*#__PURE__*/_react.default.createElement("p", null, "Grant access "), " ", expiryTime && /*#__PURE__*/_react.default.createElement("div", null, expiryTime))))), /*#__PURE__*/_react.default.createElement("div", {
376
+ }))), /*#__PURE__*/_react.default.createElement("p", null, "Grant access "), " ", accessTokenCreatedAt > 0 && /*#__PURE__*/_react.default.createElement("div", null, timeLeft))))), /*#__PURE__*/_react.default.createElement("div", {
375
377
  style: {
376
378
  backgroundColor: "white",
377
379
  padding: "6px",
@@ -0,0 +1,3 @@
1
+ export declare function formatTimeLeft(msLeft: number): string;
2
+ export declare function isExpired(createdAt: number): boolean;
3
+ export declare function timeFromNowMessage(expiryStr: string): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatTimeLeft = formatTimeLeft;
7
+ exports.isExpired = isExpired;
8
+ exports.timeFromNowMessage = timeFromNowMessage;
9
+ function formatTimeLeft(msLeft) {
10
+ var totalSeconds = Math.max(0, Math.floor(msLeft / 1000));
11
+ var minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
12
+ var seconds = String(totalSeconds % 60).padStart(2, "0");
13
+ return "".concat(minutes, ":").concat(seconds);
14
+ }
15
+ function isExpired(createdAt) {
16
+ var expiryTs = createdAt + 60 * 60 * 1000;
17
+ return Date.now() > expiryTs;
18
+ }
19
+ function timeFromNowMessage(expiryStr) {
20
+ if (!expiryStr) {
21
+ return "0 minute";
22
+ }
23
+ var mm = expiryStr.split(":").map(Number)[0];
24
+ return "".concat(mm, " minute").concat(mm !== 1 ? "s" : "");
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.0.88-patch-3",
3
+ "version": "1.0.88-patch-5",
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.88-patch-3",
19
+ "@fileverse-dev/fortune-core": "1.0.88-patch-5",
20
20
  "@fileverse/ui": "^4.1.7-patch-21",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",