@fileverse-dev/fortune-react 1.0.88-patch-5 → 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 -81
- 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 -80
- 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,46 +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
|
-
localStorage.removeItem("GNOSIS_PAY_ACCESS");
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
setHasGnosisPayToken(!!access.token);
|
|
59
|
-
setAccessTokenCreatedAt(access.createdAt);
|
|
60
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
61
|
-
} else {
|
|
62
|
-
var urlParams = new URLSearchParams(window.location.search);
|
|
63
|
-
var isRejected = urlParams.has("reject");
|
|
64
|
-
if (isRejected) {
|
|
65
|
-
var url = new URL(window.location.href);
|
|
66
|
-
url.searchParams.delete("reject");
|
|
67
|
-
window.history.replaceState({}, "", url.toString());
|
|
68
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
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;
|
|
72
44
|
useEffect(function () {
|
|
73
45
|
if (fn) {
|
|
74
46
|
setApiKeyAdded(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY));
|
|
@@ -81,9 +53,9 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
81
53
|
ETHERSCAN_API_KEY: "Etherscan API key"
|
|
82
54
|
};
|
|
83
55
|
var hintRef = useRef(null);
|
|
84
|
-
var
|
|
85
|
-
top =
|
|
86
|
-
setTop =
|
|
56
|
+
var _g = useState(0),
|
|
57
|
+
top = _g[0],
|
|
58
|
+
setTop = _g[1];
|
|
87
59
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
88
60
|
var _a, _b, _c;
|
|
89
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;
|
|
@@ -132,43 +104,6 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
132
104
|
if (el && handleWheel) el.removeEventListener("wheel", handleWheel);
|
|
133
105
|
};
|
|
134
106
|
}, []);
|
|
135
|
-
var gnosisTokenTokenIntervalRef = useRef(null);
|
|
136
|
-
var _k = useState(false),
|
|
137
|
-
isLoading = _k[0],
|
|
138
|
-
setIsLoading = _k[1];
|
|
139
|
-
useEffect(function () {
|
|
140
|
-
return function () {
|
|
141
|
-
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
142
|
-
};
|
|
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
|
-
};
|
|
172
107
|
if (!fn) return null;
|
|
173
108
|
return /*#__PURE__*/React.createElement("div", __assign({}, props, {
|
|
174
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,46 +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
|
-
localStorage.removeItem("GNOSIS_PAY_ACCESS");
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
setHasGnosisPayToken(!!access.token);
|
|
68
|
-
setAccessTokenCreatedAt(access.createdAt);
|
|
69
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
70
|
-
} else {
|
|
71
|
-
var urlParams = new URLSearchParams(window.location.search);
|
|
72
|
-
var isRejected = urlParams.has("reject");
|
|
73
|
-
if (isRejected) {
|
|
74
|
-
var url = new URL(window.location.href);
|
|
75
|
-
url.searchParams.delete("reject");
|
|
76
|
-
window.history.replaceState({}, "", url.toString());
|
|
77
|
-
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
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;
|
|
81
53
|
(0, _react.useEffect)(function () {
|
|
82
54
|
if (fn) {
|
|
83
55
|
setApiKeyAdded(!!localStorage.getItem(fn === null || fn === void 0 ? void 0 : fn.API_KEY));
|
|
@@ -90,9 +62,9 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
90
62
|
ETHERSCAN_API_KEY: "Etherscan API key"
|
|
91
63
|
};
|
|
92
64
|
var hintRef = (0, _react.useRef)(null);
|
|
93
|
-
var
|
|
94
|
-
top =
|
|
95
|
-
setTop =
|
|
65
|
+
var _g = (0, _react.useState)(0),
|
|
66
|
+
top = _g[0],
|
|
67
|
+
setTop = _g[1];
|
|
96
68
|
var calcuatePopUpPlacement = function calcuatePopUpPlacement() {
|
|
97
69
|
var _a, _b, _c;
|
|
98
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;
|
|
@@ -141,43 +113,6 @@ var FormulaHint = function FormulaHint(props) {
|
|
|
141
113
|
if (el && handleWheel) el.removeEventListener("wheel", handleWheel);
|
|
142
114
|
};
|
|
143
115
|
}, []);
|
|
144
|
-
var gnosisTokenTokenIntervalRef = (0, _react.useRef)(null);
|
|
145
|
-
var _k = (0, _react.useState)(false),
|
|
146
|
-
isLoading = _k[0],
|
|
147
|
-
setIsLoading = _k[1];
|
|
148
|
-
(0, _react.useEffect)(function () {
|
|
149
|
-
return function () {
|
|
150
|
-
if (gnosisTokenTokenIntervalRef.current) clearInterval(gnosisTokenTokenIntervalRef.current);
|
|
151
|
-
};
|
|
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
|
-
};
|
|
181
116
|
if (!fn) return null;
|
|
182
117
|
return /*#__PURE__*/_react.default.createElement("div", __assign({}, props, {
|
|
183
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",
|