Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout for mobile WalletConnect URI pre-loader #268

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all 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
21 changes: 20 additions & 1 deletion components/views/WalletSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useWallets } from '../../hooks/useWallets'
import { DeviceType } from '../../helpers/device'
import { ViewContainer } from '../layout/ViewContainer'
import { useRpc } from '../../contexts/FclContext'
import { useEffect, useState } from 'react'

type Props = {
onSelectWallet: (wallet: Wallet) => void
Expand Down Expand Up @@ -68,8 +69,26 @@ const MobileWrapper = ({
const { rpcEnabled } = useRpc()
const shouldShowLoading = (wcUriLoading && rpcEnabled) || isLoading

// If the WC URI is still loading after 5 seconds, there is likely an issue
// with WalletConnect. The loading spinner will be disabled in order to prevent
// blocking the entire page. If the user proceeds to a mobile wallet and the WC URI
// happens to load, deep linking may not work as expected, but the user can still
// manually retry the connection.
const [isTimedOut, setIsTimedOut] = useState(false)
useEffect(() => {
if (!wcUriLoading) {
return
}
const timeout = setTimeout(() => {
setIsTimedOut(true)
}, 5000)
return () => clearTimeout(timeout)
}, [wcUriLoading])

return (
<LoadingWrapper isLoading={shouldShowLoading}>{children}</LoadingWrapper>
<LoadingWrapper isLoading={shouldShowLoading && !isTimedOut}>
{children}
</LoadingWrapper>
)
}

Expand Down
Loading