tiwiflix-wallet-connector 1.5.6 → 1.5.7
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/dist/index.esm.js +31 -0
- package/dist/index.js +31 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7835,6 +7835,18 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7835
7835
|
});
|
|
7836
7836
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7837
7837
|
}, [account?.address, fetchTransactions, cacheTimeout]);
|
|
7838
|
+
// Fallback guard to avoid getting stuck in a loading state (e.g., after page refresh)
|
|
7839
|
+
useEffect(() => {
|
|
7840
|
+
// Only run when we are actually in a loading state
|
|
7841
|
+
if (!isInitializing && !balanceLoading && !isConnecting)
|
|
7842
|
+
return;
|
|
7843
|
+
const timeout = setTimeout(() => {
|
|
7844
|
+
setIsInitializing(false);
|
|
7845
|
+
setBalanceLoading(false);
|
|
7846
|
+
setIsConnecting(false);
|
|
7847
|
+
}, 4000); // force-resolve after 4s
|
|
7848
|
+
return () => clearTimeout(timeout);
|
|
7849
|
+
}, [isInitializing, balanceLoading, isConnecting]);
|
|
7838
7850
|
// Check chain ID and validate network
|
|
7839
7851
|
useEffect(() => {
|
|
7840
7852
|
const checkChain = async () => {
|
|
@@ -7888,6 +7900,25 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7888
7900
|
// Get initial state
|
|
7889
7901
|
const initialState = connector.getState();
|
|
7890
7902
|
setStatus(initialState.status);
|
|
7903
|
+
// Immediate hydration from cached state/localStorage to avoid loading flashes on page changes
|
|
7904
|
+
if (initialState.account) {
|
|
7905
|
+
setAccount(initialState.account);
|
|
7906
|
+
// Prefer fresh TWC state, otherwise restore from localStorage cache
|
|
7907
|
+
if (initialState.twcBalance && initialState.twcBalance !== '0' && initialState.twcBalance !== '0.00') {
|
|
7908
|
+
setTwcBalance(initialState.twcBalance);
|
|
7909
|
+
setUsdValueStable(initialState.usdValue ?? null);
|
|
7910
|
+
}
|
|
7911
|
+
else {
|
|
7912
|
+
const cached = loadTWCBalanceFromCache(initialState.account.address);
|
|
7913
|
+
if (cached?.balance) {
|
|
7914
|
+
setTwcBalance(cached.balance);
|
|
7915
|
+
setUsdValueStable(cached.usdValue);
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
// Since we have hydrated from cache, avoid showing the loading state
|
|
7919
|
+
setIsInitializing(false);
|
|
7920
|
+
setBalanceLoading(false);
|
|
7921
|
+
}
|
|
7891
7922
|
// Safety: Clear isConnecting on mount (in case it was stuck from previous session)
|
|
7892
7923
|
setIsConnecting(false);
|
|
7893
7924
|
// Only set wallets once to prevent re-renders
|
package/dist/index.js
CHANGED
|
@@ -7837,6 +7837,18 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7837
7837
|
});
|
|
7838
7838
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7839
7839
|
}, [account?.address, fetchTransactions, cacheTimeout]);
|
|
7840
|
+
// Fallback guard to avoid getting stuck in a loading state (e.g., after page refresh)
|
|
7841
|
+
React.useEffect(() => {
|
|
7842
|
+
// Only run when we are actually in a loading state
|
|
7843
|
+
if (!isInitializing && !balanceLoading && !isConnecting)
|
|
7844
|
+
return;
|
|
7845
|
+
const timeout = setTimeout(() => {
|
|
7846
|
+
setIsInitializing(false);
|
|
7847
|
+
setBalanceLoading(false);
|
|
7848
|
+
setIsConnecting(false);
|
|
7849
|
+
}, 4000); // force-resolve after 4s
|
|
7850
|
+
return () => clearTimeout(timeout);
|
|
7851
|
+
}, [isInitializing, balanceLoading, isConnecting]);
|
|
7840
7852
|
// Check chain ID and validate network
|
|
7841
7853
|
React.useEffect(() => {
|
|
7842
7854
|
const checkChain = async () => {
|
|
@@ -7890,6 +7902,25 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7890
7902
|
// Get initial state
|
|
7891
7903
|
const initialState = connector.getState();
|
|
7892
7904
|
setStatus(initialState.status);
|
|
7905
|
+
// Immediate hydration from cached state/localStorage to avoid loading flashes on page changes
|
|
7906
|
+
if (initialState.account) {
|
|
7907
|
+
setAccount(initialState.account);
|
|
7908
|
+
// Prefer fresh TWC state, otherwise restore from localStorage cache
|
|
7909
|
+
if (initialState.twcBalance && initialState.twcBalance !== '0' && initialState.twcBalance !== '0.00') {
|
|
7910
|
+
setTwcBalance(initialState.twcBalance);
|
|
7911
|
+
setUsdValueStable(initialState.usdValue ?? null);
|
|
7912
|
+
}
|
|
7913
|
+
else {
|
|
7914
|
+
const cached = loadTWCBalanceFromCache(initialState.account.address);
|
|
7915
|
+
if (cached?.balance) {
|
|
7916
|
+
setTwcBalance(cached.balance);
|
|
7917
|
+
setUsdValueStable(cached.usdValue);
|
|
7918
|
+
}
|
|
7919
|
+
}
|
|
7920
|
+
// Since we have hydrated from cache, avoid showing the loading state
|
|
7921
|
+
setIsInitializing(false);
|
|
7922
|
+
setBalanceLoading(false);
|
|
7923
|
+
}
|
|
7893
7924
|
// Safety: Clear isConnecting on mount (in case it was stuck from previous session)
|
|
7894
7925
|
setIsConnecting(false);
|
|
7895
7926
|
// Only set wallets once to prevent re-renders
|
package/package.json
CHANGED