From b1cc35d4e07717c173faedac7443403c27105daf Mon Sep 17 00:00:00 2001 From: AdityaSalunkhe21 Date: Mon, 14 Apr 2025 13:18:23 +0530 Subject: [PATCH] Fix error when using build files --- src/hooks/useWebViewHandler.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hooks/useWebViewHandler.ts b/src/hooks/useWebViewHandler.ts index 7a0c99c..cca1a20 100644 --- a/src/hooks/useWebViewHandler.ts +++ b/src/hooks/useWebViewHandler.ts @@ -1,4 +1,4 @@ -import { useEffect, useCallback } from 'react'; +import { useEffect, useCallback, useState } from 'react'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; @@ -8,6 +8,9 @@ import { StackParamsList } from '../types'; import useGetOrCreateAccounts from './useGetOrCreateAccounts'; export const useWebViewHandler = () => { + const [isReady, setIsReady] = useState(false); + useGetOrCreateAccounts(); + // Navigation and context hooks const navigation = useNavigation>(); const { selectedNetwork } = useNetworks(); @@ -19,6 +22,13 @@ export const useWebViewHandler = () => { // Core navigation handler const navigateToSignRequest = useCallback((message: string) => { try { + // Wait for accounts to be ready + if (!isReady) { + console.log('Accounts not yet ready'); + window.Android?.onSignatureError?.('Accounts not yet ready'); + return; + } + // Validation checks if (!selectedNetwork?.namespace || !selectedNetwork?.chainId) { window.Android?.onSignatureError?.('Invalid network configuration'); @@ -68,7 +78,7 @@ export const useWebViewHandler = () => { } catch (error) { window.Android?.onSignatureError?.(`Navigation error: ${error}`); } - }, [selectedNetwork, accounts, currentIndex, navigation]); + }, [selectedNetwork, accounts, currentIndex, navigation, isReady]); useEffect(() => { // Assign the function to the window object