@fileverse-dev/fortune-react 1.0.88-patch-4 → 1.0.88-patch-6
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/SheetOverlay/FormulaHint/constants.d.ts +1 -0
- package/es/components/SheetOverlay/FormulaHint/constants.js +1 -0
- package/es/components/SheetOverlay/FormulaHint/index.js +16 -80
- package/es/components/SheetOverlay/FormulaHint/use-gnosis-pay.d.ts +10 -0
- package/es/components/SheetOverlay/FormulaHint/use-gnosis-pay.js +89 -0
- package/lib/components/SheetOverlay/FormulaHint/constants.d.ts +1 -0
- package/lib/components/SheetOverlay/FormulaHint/constants.js +7 -0
- package/lib/components/SheetOverlay/FormulaHint/index.js +15 -79
- package/lib/components/SheetOverlay/FormulaHint/use-gnosis-pay.d.ts +10 -0
- package/lib/components/SheetOverlay/FormulaHint/use-gnosis-pay.js +95 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GNOSIS_PAY_ACCESS = "GNOSIS_PAY_ACCESS";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var GNOSIS_PAY_ACCESS = "GNOSIS_PAY_ACCESS";
|
|
@@ -13,7 +13,8 @@ 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
|
-
import {
|
|
16
|
+
import { timeFromNowMessage } from "./utils/utils";
|
|
17
|
+
import useGnosisPay from "./use-gnosis-pay";
|
|
17
18
|
var FormulaHint = function FormulaHint(props) {
|
|
18
19
|
var _a;
|
|
19
20
|
var context = useContext(WorkbookContext).context;
|
|
@@ -29,45 +30,17 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
29
30
|
var _d = useState(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY)),
|
|
30
31
|
isKeyAdded = _d[0],
|
|
31
32
|
setApiKeyAdded = _d[1];
|
|
32
|
-
var _e = useState(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var _f =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
setAccessTokenCreatedAt = _h[1];
|
|
44
|
-
var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
|
|
45
|
-
var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
|
|
46
|
-
if (localStorage.getItem("GNOSIS_PAY_ACCESS")) {
|
|
47
|
-
var access = JSON.parse(localStorage.getItem("GNOSIS_PAY_ACCESS") || "");
|
|
48
|
-
if (!(access === null || access === void 0 ? void 0 : access.token) || isExpired(access === null || access === void 0 ? void 0 : access.createdAt)) {
|
|
49
|
-
if (hasGnosisPayToken) {
|
|
50
|
-
setHasGnosisPayToken(false);
|
|
51
|
-
}
|
|
52
|
-
if (accessTokenCreatedAt) {
|
|
53
|
-
setAccessTokenCreatedAt(0);
|
|
54
|
-
}
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
setHasGnosisPayToken(!!access.token);
|
|
58
|
-
setAccessTokenCreatedAt(access.createdAt);
|
|
59
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
60
|
-
} else {
|
|
61
|
-
var urlParams = new URLSearchParams(window.location.search);
|
|
62
|
-
var isRejected = urlParams.has("reject");
|
|
63
|
-
if (isRejected) {
|
|
64
|
-
var url = new URL(window.location.href);
|
|
65
|
-
url.searchParams.delete("reject");
|
|
66
|
-
window.history.replaceState({}, "", url.toString());
|
|
67
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
33
|
+
var _e = useState(true),
|
|
34
|
+
showFunctionBody = _e[0],
|
|
35
|
+
setShouldShowFunctionBody = _e[1];
|
|
36
|
+
var _f = useGnosisPay(fn),
|
|
37
|
+
grantAccess = _f.grantAccess,
|
|
38
|
+
handleGnosisPayToken = _f.handleGnosisPayToken,
|
|
39
|
+
hasGnosisPayToken = _f.hasGnosisPayToken,
|
|
40
|
+
isWrongGnosisPayConnector = _f.isWrongGnosisPayConnector,
|
|
41
|
+
isLoading = _f.isLoading,
|
|
42
|
+
accessTokenCreatedAt = _f.accessTokenCreatedAt,
|
|
43
|
+
timeLeft = _f.timeLeft;
|
|
71
44
|
useEffect(function () {
|
|
72
45
|
if (fn) {
|
|
73
46
|
setApiKeyAdded(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY));
|
|
@@ -80,9 +53,9 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
80
53
|
ETHERSCAN_API_KEY: "Etherscan API key"
|
|
81
54
|
};
|
|
82
55
|
var hintRef = useRef(null);
|
|
83
|
-
var
|
|
84
|
-
top =
|
|
85
|
-
setTop =
|
|
56
|
+
var _g = useState(0),
|
|
57
|
+
top = _g[0],
|
|
58
|
+
setTop = _g[1];
|
|
86
59
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
87
60
|
var _a, _b, _c;
|
|
88
61
|
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;
|
|
@@ -131,43 +104,6 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
131
104
|
if (el && handleWheel) el.removeEventListener("wheel", handleWheel);
|
|
132
105
|
};
|
|
133
106
|
}, []);
|
|
134
|
-
var gnosisTokenTokenIntervalRef = useRef(null);
|
|
135
|
-
var _k = useState(false),
|
|
136
|
-
isLoading = _k[0],
|
|
137
|
-
setIsLoading = _k[1];
|
|
138
|
-
useEffect(function () {
|
|
139
|
-
return function () {
|
|
140
|
-
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
141
|
-
};
|
|
142
|
-
}, [gnosisTokenTokenIntervalRef]);
|
|
143
|
-
useEffect(function () {
|
|
144
|
-
if (accessTokenCreatedAt <= 0) return function () {};
|
|
145
|
-
var interval = setInterval(function () {
|
|
146
|
-
var EXPIRY_DURATION_MS = 60 * 60 * 1000;
|
|
147
|
-
var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
|
|
148
|
-
var newTimeLeft = expiryTimestamp - Date.now();
|
|
149
|
-
setTimeLeft(formatTimeLeft(newTimeLeft));
|
|
150
|
-
if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
|
|
151
|
-
clearInterval(interval);
|
|
152
|
-
}
|
|
153
|
-
}, 1000);
|
|
154
|
-
return function () {
|
|
155
|
-
clearInterval(interval);
|
|
156
|
-
};
|
|
157
|
-
}, [accessTokenCreatedAt, fn]);
|
|
158
|
-
var grantAccess = function grantAccess() {
|
|
159
|
-
var button = document.getElementById("grant-gnosispay-access");
|
|
160
|
-
if (!button) return;
|
|
161
|
-
button.click();
|
|
162
|
-
setIsLoading(true);
|
|
163
|
-
var interval = setInterval(function () {
|
|
164
|
-
handleGnosisPayToken(function () {
|
|
165
|
-
clearInterval(interval);
|
|
166
|
-
setIsLoading(false);
|
|
167
|
-
});
|
|
168
|
-
}, 5000);
|
|
169
|
-
gnosisTokenTokenIntervalRef.current = interval;
|
|
170
|
-
};
|
|
171
107
|
if (!fn) return null;
|
|
172
108
|
return /*#__PURE__*/React.createElement("div", __assign({}, props, {
|
|
173
109
|
ref: hintRef,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const useGnosisPay: (fn: any) => {
|
|
2
|
+
grantAccess: () => void;
|
|
3
|
+
handleGnosisPayToken: (onDone?: () => void) => void;
|
|
4
|
+
hasGnosisPayToken: boolean;
|
|
5
|
+
isWrongGnosisPayConnector: boolean;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
accessTokenCreatedAt: number;
|
|
8
|
+
timeLeft: string;
|
|
9
|
+
};
|
|
10
|
+
export default useGnosisPay;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { GNOSIS_PAY_ACCESS } from "./constants";
|
|
3
|
+
import { formatTimeLeft, isExpired } from "./utils/utils";
|
|
4
|
+
var useGnosisPay = function useGnosisPay(fn) {
|
|
5
|
+
var gnosisTokenTokenIntervalRef = useRef(null);
|
|
6
|
+
var _a = useState(false),
|
|
7
|
+
isLoading = _a[0],
|
|
8
|
+
setIsLoading = _a[1];
|
|
9
|
+
var _b = useState(false),
|
|
10
|
+
hasGnosisPayToken = _b[0],
|
|
11
|
+
setHasGnosisPayToken = _b[1];
|
|
12
|
+
var _c = useState("00:00"),
|
|
13
|
+
timeLeft = _c[0],
|
|
14
|
+
setTimeLeft = _c[1];
|
|
15
|
+
var _d = useState(0),
|
|
16
|
+
accessTokenCreatedAt = _d[0],
|
|
17
|
+
setAccessTokenCreatedAt = _d[1];
|
|
18
|
+
var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
|
|
19
|
+
var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
|
|
20
|
+
if (localStorage.getItem(GNOSIS_PAY_ACCESS)) {
|
|
21
|
+
var access = JSON.parse(localStorage.getItem(GNOSIS_PAY_ACCESS) || "");
|
|
22
|
+
if (!(access === null || access === void 0 ? void 0 : access.token) || isExpired(access === null || access === void 0 ? void 0 : access.createdAt)) {
|
|
23
|
+
if (hasGnosisPayToken) {
|
|
24
|
+
setHasGnosisPayToken(false);
|
|
25
|
+
}
|
|
26
|
+
if (accessTokenCreatedAt) {
|
|
27
|
+
setAccessTokenCreatedAt(0);
|
|
28
|
+
}
|
|
29
|
+
localStorage.removeItem(GNOSIS_PAY_ACCESS);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
setHasGnosisPayToken(!!access.token);
|
|
33
|
+
setAccessTokenCreatedAt(access.createdAt);
|
|
34
|
+
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
35
|
+
} else {
|
|
36
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
37
|
+
var isRejected = urlParams.has("reject");
|
|
38
|
+
if (isRejected) {
|
|
39
|
+
var url = new URL(window.location.href);
|
|
40
|
+
url.searchParams.delete("reject");
|
|
41
|
+
window.history.replaceState({}, "", url.toString());
|
|
42
|
+
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
return function () {
|
|
48
|
+
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
49
|
+
};
|
|
50
|
+
}, [gnosisTokenTokenIntervalRef]);
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (accessTokenCreatedAt <= 0) return function () {};
|
|
53
|
+
var interval = setInterval(function () {
|
|
54
|
+
var EXPIRY_DURATION_MS = 60 * 60 * 1000;
|
|
55
|
+
var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
|
|
56
|
+
var newTimeLeft = expiryTimestamp - Date.now();
|
|
57
|
+
setTimeLeft(formatTimeLeft(newTimeLeft));
|
|
58
|
+
if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
|
|
59
|
+
clearInterval(interval);
|
|
60
|
+
}
|
|
61
|
+
}, 1000);
|
|
62
|
+
return function () {
|
|
63
|
+
clearInterval(interval);
|
|
64
|
+
};
|
|
65
|
+
}, [accessTokenCreatedAt, fn]);
|
|
66
|
+
var grantAccess = function grantAccess() {
|
|
67
|
+
var button = document.getElementById("grant-gnosispay-access");
|
|
68
|
+
if (!button) return;
|
|
69
|
+
button.click();
|
|
70
|
+
setIsLoading(true);
|
|
71
|
+
var interval = setInterval(function () {
|
|
72
|
+
handleGnosisPayToken(function () {
|
|
73
|
+
clearInterval(interval);
|
|
74
|
+
setIsLoading(false);
|
|
75
|
+
});
|
|
76
|
+
}, 5000);
|
|
77
|
+
gnosisTokenTokenIntervalRef.current = interval;
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
grantAccess: grantAccess,
|
|
81
|
+
handleGnosisPayToken: handleGnosisPayToken,
|
|
82
|
+
hasGnosisPayToken: hasGnosisPayToken,
|
|
83
|
+
isWrongGnosisPayConnector: isWrongGnosisPayConnector,
|
|
84
|
+
isLoading: isLoading,
|
|
85
|
+
accessTokenCreatedAt: accessTokenCreatedAt,
|
|
86
|
+
timeLeft: timeLeft
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export default useGnosisPay;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GNOSIS_PAY_ACCESS = "GNOSIS_PAY_ACCESS";
|
|
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _context = _interopRequireDefault(require("../../../context"));
|
|
12
12
|
require("./index.css");
|
|
13
13
|
var _utils = require("./utils/utils");
|
|
14
|
+
var _useGnosisPay = _interopRequireDefault(require("./use-gnosis-pay"));
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
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); }
|
|
16
17
|
var __assign = void 0 && (void 0).__assign || function () {
|
|
@@ -38,45 +39,17 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
38
39
|
var _d = (0, _react.useState)(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY)),
|
|
39
40
|
isKeyAdded = _d[0],
|
|
40
41
|
setApiKeyAdded = _d[1];
|
|
41
|
-
var _e = (0, _react.useState)(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _f = (0,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
setAccessTokenCreatedAt = _h[1];
|
|
53
|
-
var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
|
|
54
|
-
var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
|
|
55
|
-
if (localStorage.getItem("GNOSIS_PAY_ACCESS")) {
|
|
56
|
-
var access = JSON.parse(localStorage.getItem("GNOSIS_PAY_ACCESS") || "");
|
|
57
|
-
if (!(access === null || access === void 0 ? void 0 : access.token) || (0, _utils.isExpired)(access === null || access === void 0 ? void 0 : access.createdAt)) {
|
|
58
|
-
if (hasGnosisPayToken) {
|
|
59
|
-
setHasGnosisPayToken(false);
|
|
60
|
-
}
|
|
61
|
-
if (accessTokenCreatedAt) {
|
|
62
|
-
setAccessTokenCreatedAt(0);
|
|
63
|
-
}
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
setHasGnosisPayToken(!!access.token);
|
|
67
|
-
setAccessTokenCreatedAt(access.createdAt);
|
|
68
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
69
|
-
} else {
|
|
70
|
-
var urlParams = new URLSearchParams(window.location.search);
|
|
71
|
-
var isRejected = urlParams.has("reject");
|
|
72
|
-
if (isRejected) {
|
|
73
|
-
var url = new URL(window.location.href);
|
|
74
|
-
url.searchParams.delete("reject");
|
|
75
|
-
window.history.replaceState({}, "", url.toString());
|
|
76
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
42
|
+
var _e = (0, _react.useState)(true),
|
|
43
|
+
showFunctionBody = _e[0],
|
|
44
|
+
setShouldShowFunctionBody = _e[1];
|
|
45
|
+
var _f = (0, _useGnosisPay.default)(fn),
|
|
46
|
+
grantAccess = _f.grantAccess,
|
|
47
|
+
handleGnosisPayToken = _f.handleGnosisPayToken,
|
|
48
|
+
hasGnosisPayToken = _f.hasGnosisPayToken,
|
|
49
|
+
isWrongGnosisPayConnector = _f.isWrongGnosisPayConnector,
|
|
50
|
+
isLoading = _f.isLoading,
|
|
51
|
+
accessTokenCreatedAt = _f.accessTokenCreatedAt,
|
|
52
|
+
timeLeft = _f.timeLeft;
|
|
80
53
|
(0, _react.useEffect)(function () {
|
|
81
54
|
if (fn) {
|
|
82
55
|
setApiKeyAdded(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY));
|
|
@@ -89,9 +62,9 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
89
62
|
ETHERSCAN_API_KEY: "Etherscan API key"
|
|
90
63
|
};
|
|
91
64
|
var hintRef = (0, _react.useRef)(null);
|
|
92
|
-
var
|
|
93
|
-
top =
|
|
94
|
-
setTop =
|
|
65
|
+
var _g = (0, _react.useState)(0),
|
|
66
|
+
top = _g[0],
|
|
67
|
+
setTop = _g[1];
|
|
95
68
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
96
69
|
var _a, _b, _c;
|
|
97
70
|
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;
|
|
@@ -140,43 +113,6 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
140
113
|
if (el && handleWheel) el.removeEventListener("wheel", handleWheel);
|
|
141
114
|
};
|
|
142
115
|
}, []);
|
|
143
|
-
var gnosisTokenTokenIntervalRef = (0, _react.useRef)(null);
|
|
144
|
-
var _k = (0, _react.useState)(false),
|
|
145
|
-
isLoading = _k[0],
|
|
146
|
-
setIsLoading = _k[1];
|
|
147
|
-
(0, _react.useEffect)(function () {
|
|
148
|
-
return function () {
|
|
149
|
-
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
150
|
-
};
|
|
151
|
-
}, [gnosisTokenTokenIntervalRef]);
|
|
152
|
-
(0, _react.useEffect)(function () {
|
|
153
|
-
if (accessTokenCreatedAt <= 0) return function () {};
|
|
154
|
-
var interval = setInterval(function () {
|
|
155
|
-
var EXPIRY_DURATION_MS = 60 * 60 * 1000;
|
|
156
|
-
var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
|
|
157
|
-
var newTimeLeft = expiryTimestamp - Date.now();
|
|
158
|
-
setTimeLeft((0, _utils.formatTimeLeft)(newTimeLeft));
|
|
159
|
-
if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
|
|
160
|
-
clearInterval(interval);
|
|
161
|
-
}
|
|
162
|
-
}, 1000);
|
|
163
|
-
return function () {
|
|
164
|
-
clearInterval(interval);
|
|
165
|
-
};
|
|
166
|
-
}, [accessTokenCreatedAt, fn]);
|
|
167
|
-
var grantAccess = function grantAccess() {
|
|
168
|
-
var button = document.getElementById("grant-gnosispay-access");
|
|
169
|
-
if (!button) return;
|
|
170
|
-
button.click();
|
|
171
|
-
setIsLoading(true);
|
|
172
|
-
var interval = setInterval(function () {
|
|
173
|
-
handleGnosisPayToken(function () {
|
|
174
|
-
clearInterval(interval);
|
|
175
|
-
setIsLoading(false);
|
|
176
|
-
});
|
|
177
|
-
}, 5000);
|
|
178
|
-
gnosisTokenTokenIntervalRef.current = interval;
|
|
179
|
-
};
|
|
180
116
|
if (!fn) return null;
|
|
181
117
|
return /*#__PURE__*/_react.default.createElement("div", __assign({}, props, {
|
|
182
118
|
ref: hintRef,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const useGnosisPay: (fn: any) => {
|
|
2
|
+
grantAccess: () => void;
|
|
3
|
+
handleGnosisPayToken: (onDone?: () => void) => void;
|
|
4
|
+
hasGnosisPayToken: boolean;
|
|
5
|
+
isWrongGnosisPayConnector: boolean;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
accessTokenCreatedAt: number;
|
|
8
|
+
timeLeft: string;
|
|
9
|
+
};
|
|
10
|
+
export default useGnosisPay;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
var _utils = require("./utils/utils");
|
|
10
|
+
var useGnosisPay = function useGnosisPay(fn) {
|
|
11
|
+
var gnosisTokenTokenIntervalRef = (0, _react.useRef)(null);
|
|
12
|
+
var _a = (0, _react.useState)(false),
|
|
13
|
+
isLoading = _a[0],
|
|
14
|
+
setIsLoading = _a[1];
|
|
15
|
+
var _b = (0, _react.useState)(false),
|
|
16
|
+
hasGnosisPayToken = _b[0],
|
|
17
|
+
setHasGnosisPayToken = _b[1];
|
|
18
|
+
var _c = (0, _react.useState)("00:00"),
|
|
19
|
+
timeLeft = _c[0],
|
|
20
|
+
setTimeLeft = _c[1];
|
|
21
|
+
var _d = (0, _react.useState)(0),
|
|
22
|
+
accessTokenCreatedAt = _d[0],
|
|
23
|
+
setAccessTokenCreatedAt = _d[1];
|
|
24
|
+
var isWrongGnosisPayConnector = localStorage.getItem("LOGIN_METHOD") !== "walletAddress";
|
|
25
|
+
var handleGnosisPayToken = function handleGnosisPayToken(onDone) {
|
|
26
|
+
if (localStorage.getItem(_constants.GNOSIS_PAY_ACCESS)) {
|
|
27
|
+
var access = JSON.parse(localStorage.getItem(_constants.GNOSIS_PAY_ACCESS) || "");
|
|
28
|
+
if (!(access === null || access === void 0 ? void 0 : access.token) || (0, _utils.isExpired)(access === null || access === void 0 ? void 0 : access.createdAt)) {
|
|
29
|
+
if (hasGnosisPayToken) {
|
|
30
|
+
setHasGnosisPayToken(false);
|
|
31
|
+
}
|
|
32
|
+
if (accessTokenCreatedAt) {
|
|
33
|
+
setAccessTokenCreatedAt(0);
|
|
34
|
+
}
|
|
35
|
+
localStorage.removeItem(_constants.GNOSIS_PAY_ACCESS);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setHasGnosisPayToken(!!access.token);
|
|
39
|
+
setAccessTokenCreatedAt(access.createdAt);
|
|
40
|
+
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
41
|
+
} else {
|
|
42
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
43
|
+
var isRejected = urlParams.has("reject");
|
|
44
|
+
if (isRejected) {
|
|
45
|
+
var url = new URL(window.location.href);
|
|
46
|
+
url.searchParams.delete("reject");
|
|
47
|
+
window.history.replaceState({}, "", url.toString());
|
|
48
|
+
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
(0, _react.useEffect)(function () {
|
|
53
|
+
return function () {
|
|
54
|
+
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
55
|
+
};
|
|
56
|
+
}, [gnosisTokenTokenIntervalRef]);
|
|
57
|
+
(0, _react.useEffect)(function () {
|
|
58
|
+
if (accessTokenCreatedAt <= 0) return function () {};
|
|
59
|
+
var interval = setInterval(function () {
|
|
60
|
+
var EXPIRY_DURATION_MS = 60 * 60 * 1000;
|
|
61
|
+
var expiryTimestamp = accessTokenCreatedAt + EXPIRY_DURATION_MS;
|
|
62
|
+
var newTimeLeft = expiryTimestamp - Date.now();
|
|
63
|
+
setTimeLeft((0, _utils.formatTimeLeft)(newTimeLeft));
|
|
64
|
+
if (newTimeLeft <= 0 || !document.getElementById("gnosis-pay-area")) {
|
|
65
|
+
clearInterval(interval);
|
|
66
|
+
}
|
|
67
|
+
}, 1000);
|
|
68
|
+
return function () {
|
|
69
|
+
clearInterval(interval);
|
|
70
|
+
};
|
|
71
|
+
}, [accessTokenCreatedAt, fn]);
|
|
72
|
+
var grantAccess = function grantAccess() {
|
|
73
|
+
var button = document.getElementById("grant-gnosispay-access");
|
|
74
|
+
if (!button) return;
|
|
75
|
+
button.click();
|
|
76
|
+
setIsLoading(true);
|
|
77
|
+
var interval = setInterval(function () {
|
|
78
|
+
handleGnosisPayToken(function () {
|
|
79
|
+
clearInterval(interval);
|
|
80
|
+
setIsLoading(false);
|
|
81
|
+
});
|
|
82
|
+
}, 5000);
|
|
83
|
+
gnosisTokenTokenIntervalRef.current = interval;
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
grantAccess: grantAccess,
|
|
87
|
+
handleGnosisPayToken: handleGnosisPayToken,
|
|
88
|
+
hasGnosisPayToken: hasGnosisPayToken,
|
|
89
|
+
isWrongGnosisPayConnector: isWrongGnosisPayConnector,
|
|
90
|
+
isLoading: isLoading,
|
|
91
|
+
accessTokenCreatedAt: accessTokenCreatedAt,
|
|
92
|
+
timeLeft: timeLeft
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var _default = exports.default = useGnosisPay;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.0.88-patch-
|
|
3
|
+
"version": "1.0.88-patch-6",
|
|
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-
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.0.88-patch-6",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-21",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|