Remove unnecessary code

This commit is contained in:
AdityaSalunkhe21 2025-04-11 19:17:49 +05:30
parent feb86bd5f8
commit 1aabebf2c0
5 changed files with 10 additions and 42 deletions

View File

@ -40,7 +40,7 @@ import { WalletEmbed } from "./screens/WalletEmbed";
import { AutoSignIn } from "./screens/AutoSignIn"; import { AutoSignIn } from "./screens/AutoSignIn";
import { checkSufficientFunds, getPathKey, sendMessage } from "./utils/misc"; import { checkSufficientFunds, getPathKey, sendMessage } from "./utils/misc";
import useAccountsData from "./hooks/useAccountsData"; import useAccountsData from "./hooks/useAccountsData";
import { useSignRequestHandler } from "./hooks/useSignRequestHandler"; import { useWebViewHandler } from "./hooks/useWebViewHandler";
const Stack = createStackNavigator<StackParamsList>(); const Stack = createStackNavigator<StackParamsList>();
@ -280,7 +280,7 @@ const App = (): React.JSX.Element => {
const showWalletConnect = useMemo(() => accounts.length > 0, [accounts]); const showWalletConnect = useMemo(() => accounts.length > 0, [accounts]);
useSignRequestHandler(); useWebViewHandler();
return ( return (
<Surface style={styles.appSurface}> <Surface style={styles.appSurface}>

5
src/global.d.ts vendored
View File

@ -1,7 +1,7 @@
// Extends the Window interface for Android WebView communication // Extends the Window interface for Android WebView communication
declare global { declare global {
interface Window { interface Window {
// Android bridge callbacks for signature-related events // Android bridge callbacks for signature and accounts related events
Android?: { Android?: {
// Called when signature is successfully generated // Called when signature is successfully generated
onSignatureComplete?: (signature: string) => void; onSignatureComplete?: (signature: string) => void;
@ -12,9 +12,6 @@ declare global {
// Called when signature process is cancelled // Called when signature process is cancelled
onSignatureCancelled?: () => void; onSignatureCancelled?: () => void;
// Called when JS bridge is initialized
onJsBridgeReady?: () => void;
// Called when accounts are ready for use // Called when accounts are ready for use
onAccountsReady?: () => void; onAccountsReady?: () => void;
}; };

View File

@ -57,6 +57,7 @@ const useGetOrCreateAccounts = () => {
const isAndroidWebView = !!(window.Android); const isAndroidWebView = !!(window.Android);
// TODO: Call method to auto create accounts from android app
if (isAndroidWebView) { if (isAndroidWebView) {
autoCreateAccounts(); autoCreateAccounts();
} }

View File

@ -1,4 +1,4 @@
import { useEffect, useRef, useCallback } from 'react'; import { useEffect, useCallback } 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';
@ -7,7 +7,7 @@ import { useNetworks } from '../context/NetworksContext';
import { StackParamsList } from '../types'; import { StackParamsList } from '../types';
import useGetOrCreateAccounts from './useGetOrCreateAccounts'; import useGetOrCreateAccounts from './useGetOrCreateAccounts';
export const useSignRequestHandler = () => { export const useWebViewHandler = () => {
// Navigation and context hooks // Navigation and context hooks
const navigation = useNavigation<NativeStackNavigationProp<StackParamsList>>(); const navigation = useNavigation<NativeStackNavigationProp<StackParamsList>>();
const { selectedNetwork } = useNetworks(); const { selectedNetwork } = useNetworks();
@ -16,19 +16,8 @@ export const useSignRequestHandler = () => {
// Initialize accounts // Initialize accounts
useGetOrCreateAccounts(); useGetOrCreateAccounts();
// Use a ref for pending messages instead of state to avoid re-renders
const pendingMessageRef = useRef<string | null>(null);
// Core navigation handler // Core navigation handler
const navigateToSignRequest = useCallback((message: string) => { const navigateToSignRequest = useCallback((message: string) => {
// Data readiness check
const isDataReady = !!(selectedNetwork && accounts && accounts.length > 0);
if (!isDataReady) {
pendingMessageRef.current = message;
return;
}
try { try {
// Validation checks // Validation checks
if (!selectedNetwork?.namespace || !selectedNetwork?.chainId) { if (!selectedNetwork?.namespace || !selectedNetwork?.chainId) {
@ -81,29 +70,12 @@ export const useSignRequestHandler = () => {
} }
}, [selectedNetwork, accounts, currentIndex, navigation]); }, [selectedNetwork, accounts, currentIndex, navigation]);
// Setup Android bridge and handle pending messages
useEffect(() => { useEffect(() => {
// Setup global function to receive sign requests from Android // Assign the function to the window object
window.receiveSignRequestFromAndroid = navigateToSignRequest; window.receiveSignRequestFromAndroid = navigateToSignRequest;
// Process any pending messages whenever dependencies change
if (pendingMessageRef.current && selectedNetwork && accounts?.length > 0) {
const message = pendingMessageRef.current;
pendingMessageRef.current = null;
navigateToSignRequest(message);
}
// Notify Android that JS bridge is ready
if (window.Android) {
const timeoutId = setTimeout(() => window.Android?.onJsBridgeReady?.(), 100);
return () => {
clearTimeout(timeoutId);
window.receiveSignRequestFromAndroid = undefined;
};
}
return () => { return () => {
window.receiveSignRequestFromAndroid = undefined; window.receiveSignRequestFromAndroid = undefined;
}; };
}, [navigateToSignRequest, selectedNetwork, accounts]); }, [navigateToSignRequest]); // Only the function reference as dependency
}; };

View File

@ -10,10 +10,8 @@ export type StackParamsList = {
selectedNamespace: string; selectedNamespace: string;
selectedChainId: string; selectedChainId: string;
accountInfo: Account; accountInfo: Account;
prefillMessage?: string;
}; };
SignRequest: { SignRequest: {
path?: string;
namespace: string; namespace: string;
chainId?: string; chainId?: string;
address: string; address: string;