Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/appkit/src/views/w3m-connecting-view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSnapshot } from 'valtio';
import { useEffect, useLayoutEffect, useState } from 'react';
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { ErrorUtil, type Platform } from '@reown/appkit-common-react-native';
import {
WcController,
Expand All @@ -22,16 +22,16 @@ export function ConnectingView() {
const { connect } = useInternalAppKit();
const { installed } = useSnapshot(ApiController.state);
const { data } = RouterController.state;
const [lastRetry, setLastRetry] = useState(Date.now());
const lastRetryRef = useRef<number>(Date.now());
const isQr = !data?.wallet;
const isInstalled = !!installed?.find(wallet => wallet.id === data?.wallet?.id);

const [platform, setPlatform] = useState<Platform>();
const [platforms, setPlatforms] = useState<Platform[]>([]);

const onRetry = () => {
if (CoreHelperUtil.isAllowedRetry(lastRetry)) {
setLastRetry(Date.now());
if (CoreHelperUtil.isAllowedRetry(lastRetryRef.current)) {
lastRetryRef.current = Date.now();
initializeConnection(true);
} else {
SnackController.showError('Please wait a second before retrying');
Expand Down Expand Up @@ -73,10 +73,10 @@ export function ConnectingView() {
}
});

const currentRetryTime = retryTimestamp ?? lastRetry;
const currentRetryTime = retryTimestamp ?? lastRetryRef.current;
if (isQr && CoreHelperUtil.isAllowedRetry(currentRetryTime)) {
const newRetryTime = Date.now();
setLastRetry(newRetryTime);
lastRetryRef.current = newRetryTime;
initializeConnection(true, newRetryTime);
}
}
Expand Down Expand Up @@ -107,6 +107,9 @@ export function ConnectingView() {
}, [data, isInstalled]);

useEffect(() => {
// Clear any stale URI from previous connection attempts
WcController.clearUri();

initializeConnection();
let _interval: NodeJS.Timeout;

Expand Down
Loading