Fix error when using build files

This commit is contained in:
AdityaSalunkhe21 2025-04-14 13:18:23 +05:30 committed by pranavjadhav007
parent d0623be1c3
commit b1cc35d4e0

View File

@ -1,4 +1,4 @@
import { useEffect, useCallback } from 'react'; import { useEffect, useCallback, useState } from 'react';
import { useNavigation } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { NativeStackNavigationProp } from '@react-navigation/native-stack';
@ -8,6 +8,9 @@ import { StackParamsList } from '../types';
import useGetOrCreateAccounts from './useGetOrCreateAccounts'; import useGetOrCreateAccounts from './useGetOrCreateAccounts';
export const useWebViewHandler = () => { export const useWebViewHandler = () => {
const [isReady, setIsReady] = useState(false);
useGetOrCreateAccounts();
// Navigation and context hooks // Navigation and context hooks
const navigation = useNavigation<NativeStackNavigationProp<StackParamsList>>(); const navigation = useNavigation<NativeStackNavigationProp<StackParamsList>>();
const { selectedNetwork } = useNetworks(); const { selectedNetwork } = useNetworks();
@ -19,6 +22,13 @@ export const useWebViewHandler = () => {
// Core navigation handler // Core navigation handler
const navigateToSignRequest = useCallback((message: string) => { const navigateToSignRequest = useCallback((message: string) => {
try { 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 // Validation checks
if (!selectedNetwork?.namespace || !selectedNetwork?.chainId) { if (!selectedNetwork?.namespace || !selectedNetwork?.chainId) {
window.Android?.onSignatureError?.('Invalid network configuration'); window.Android?.onSignatureError?.('Invalid network configuration');
@ -68,7 +78,7 @@ export const useWebViewHandler = () => {
} catch (error) { } catch (error) {
window.Android?.onSignatureError?.(`Navigation error: ${error}`); window.Android?.onSignatureError?.(`Navigation error: ${error}`);
} }
}, [selectedNetwork, accounts, currentIndex, navigation]); }, [selectedNetwork, accounts, currentIndex, navigation, isReady]);
useEffect(() => { useEffect(() => {
// Assign the function to the window object // Assign the function to the window object