Skip to content

Commit

Permalink
Add timeout for mobile WalletConnect URI pre-loader (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Oct 2, 2024
1 parent 6b9bad1 commit 3cf1570
Showing 1 changed file with 20 additions and 1 deletion.
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

0 comments on commit 3cf1570

Please sign in to comment.