@getpara/react-core 3.12.0-dev.0 → 3.12.0-dev.1
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.
|
@@ -41,6 +41,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
41
41
|
import { useEffect, useMemo, useRef } from "react";
|
|
42
42
|
import { useClient } from "../utils/useClient.js";
|
|
43
43
|
import { useIsFullyLoggedIn } from "./useIsFullyLoggedIn.js";
|
|
44
|
+
import { useCoreStore } from "../../stores/CoreStoreContext.js";
|
|
44
45
|
import { getEmbeddedAccount } from "../../actions/getEmbeddedAccount.js";
|
|
45
46
|
const ACCOUNT_BASE_KEY = "PARA_ACCOUNT";
|
|
46
47
|
function useInvalidation(connections, queryKey) {
|
|
@@ -73,12 +74,18 @@ function createAccountHook(useExternalWallets) {
|
|
|
73
74
|
var _a, _b;
|
|
74
75
|
const client = useClient();
|
|
75
76
|
const { data: isFullyLoggedIn, isSuccess, isLoading: isFullyLoggedInLoading } = useIsFullyLoggedIn();
|
|
77
|
+
const corePhase = useCoreStore((state) => {
|
|
78
|
+
var _a2;
|
|
79
|
+
return (_a2 = state.paraState) == null ? void 0 : _a2.corePhase;
|
|
80
|
+
});
|
|
81
|
+
const isSettled = corePhase === "authenticated" || corePhase === "guest_mode";
|
|
82
|
+
const isEmbeddedReady = isFullyLoggedIn && isSettled;
|
|
76
83
|
const external = (_a = useExternalWallets == null ? void 0 : useExternalWallets()) != null ? _a : {
|
|
77
84
|
queryKeys: [],
|
|
78
85
|
connections: {},
|
|
79
86
|
data: {}
|
|
80
87
|
};
|
|
81
|
-
const queryKey = [ACCOUNT_BASE_KEY,
|
|
88
|
+
const queryKey = [ACCOUNT_BASE_KEY, isEmbeddedReady != null ? isEmbeddedReady : null, (_b = client == null ? void 0 : client.userId) != null ? _b : null, ...external.queryKeys];
|
|
82
89
|
const connectionsKey = JSON.stringify(external.connections);
|
|
83
90
|
const connections = useMemo(() => external.connections, [connectionsKey]);
|
|
84
91
|
useInvalidation(connections, queryKey);
|
|
@@ -86,7 +93,7 @@ function createAccountHook(useExternalWallets) {
|
|
|
86
93
|
enabled: isSuccess && !!client && !isFullyLoggedInLoading,
|
|
87
94
|
queryKey,
|
|
88
95
|
queryFn: () => __async(null, null, function* () {
|
|
89
|
-
const paraAccount = yield getEmbeddedAccount(client,
|
|
96
|
+
const paraAccount = yield getEmbeddedAccount(client, isEmbeddedReady);
|
|
90
97
|
let connectionType = "none";
|
|
91
98
|
const hasExternalConnection = Object.values(external.connections).some(Boolean);
|
|
92
99
|
if (paraAccount.isConnected) {
|
|
@@ -22,7 +22,21 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
22
22
|
import { useClient } from "../utils/useClient.js";
|
|
23
23
|
import { useCoreStore } from "../../stores/CoreStoreContext.js";
|
|
24
24
|
const IS_FULLY_LOGGED_IN_BASE_KEY = "PARA_FULLY_LOGGED_IN";
|
|
25
|
-
const
|
|
25
|
+
const FULL_LOGIN_RETRY_DELAYS_MS = [1100, 2e3, 4e3, 8e3];
|
|
26
|
+
const waitForRetry = (delayMs, signal) => new Promise((resolve) => {
|
|
27
|
+
const timeoutId = setTimeout(onComplete, delayMs);
|
|
28
|
+
function onComplete() {
|
|
29
|
+
signal.removeEventListener("abort", onAbort);
|
|
30
|
+
resolve(true);
|
|
31
|
+
}
|
|
32
|
+
function onAbort() {
|
|
33
|
+
clearTimeout(timeoutId);
|
|
34
|
+
signal.removeEventListener("abort", onAbort);
|
|
35
|
+
resolve(false);
|
|
36
|
+
}
|
|
37
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
38
|
+
if (signal.aborted) onAbort();
|
|
39
|
+
});
|
|
26
40
|
const useIsFullyLoggedIn = () => {
|
|
27
41
|
var _a;
|
|
28
42
|
const client = useClient();
|
|
@@ -38,12 +52,16 @@ const useIsFullyLoggedIn = () => {
|
|
|
38
52
|
return useQuery({
|
|
39
53
|
enabled: isReady && !!client,
|
|
40
54
|
queryKey: [IS_FULLY_LOGGED_IN_BASE_KEY, phaseKey, (_a = client == null ? void 0 : client.userId) != null ? _a : null],
|
|
41
|
-
queryFn: () => __async(null,
|
|
55
|
+
queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
|
|
42
56
|
var _a2, _b;
|
|
43
|
-
|
|
57
|
+
let isFullyLoggedIn = (_a2 = yield client == null ? void 0 : client.isFullyLoggedIn()) != null ? _a2 : false;
|
|
44
58
|
if (isFullyLoggedIn || phaseKey !== "authenticated") return isFullyLoggedIn;
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
for (const delayMs of FULL_LOGIN_RETRY_DELAYS_MS) {
|
|
60
|
+
if (!(yield waitForRetry(delayMs, signal))) return false;
|
|
61
|
+
isFullyLoggedIn = (_b = yield client == null ? void 0 : client.isFullyLoggedIn()) != null ? _b : false;
|
|
62
|
+
if (isFullyLoggedIn) return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
47
65
|
})
|
|
48
66
|
});
|
|
49
67
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/react-core",
|
|
3
|
-
"version": "3.12.0-dev.
|
|
3
|
+
"version": "3.12.0-dev.1",
|
|
4
4
|
"description": "Platform-agnostic ParaProvider, hooks, and store for Para SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -89,18 +89,18 @@
|
|
|
89
89
|
"test": "vitest run"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@getpara/core-sdk": "3.
|
|
92
|
+
"@getpara/core-sdk": "3.12.0-dev.1",
|
|
93
93
|
"zustand": "^5.0.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@cosmjs/amino": "^0.32.0",
|
|
97
97
|
"@cosmjs/proto-signing": "^0.32.0",
|
|
98
|
-
"@getpara/cosmjs-v0-integration": "3.
|
|
99
|
-
"@getpara/ethers-v6-integration": "3.
|
|
100
|
-
"@getpara/solana-signers-v2-integration": "3.
|
|
101
|
-
"@getpara/stellar-sdk-v14-integration": "3.
|
|
102
|
-
"@getpara/sui-sdk-integration": "3.
|
|
103
|
-
"@getpara/viem-v2-integration": "3.
|
|
98
|
+
"@getpara/cosmjs-v0-integration": "3.11.0",
|
|
99
|
+
"@getpara/ethers-v6-integration": "3.11.0",
|
|
100
|
+
"@getpara/solana-signers-v2-integration": "3.11.0",
|
|
101
|
+
"@getpara/stellar-sdk-v14-integration": "3.11.0",
|
|
102
|
+
"@getpara/sui-sdk-integration": "3.11.0",
|
|
103
|
+
"@getpara/viem-v2-integration": "3.11.0",
|
|
104
104
|
"@solana/signers": "^2.0.0",
|
|
105
105
|
"@tanstack/react-query": "^5.74.0",
|
|
106
106
|
"@testing-library/dom": "^10.4.0",
|