From 6edd7a1170cfb1caf666ea7d9bc31dfca5b40165 Mon Sep 17 00:00:00 2001 From: NPC Date: Thu, 16 Jul 2026 19:58:37 +0700 Subject: [PATCH 01/12] Remove deprecated retry from useWalletOrchestrator --- src/hooks/internal/useWalletOrchestrator.ts | 19 +----------- src/hooks/useWdkApp.ts | 4 +-- src/provider/WdkAppProvider.tsx | 6 ++-- tests/hooks/useWalletManager.test.tsx | 2 -- tests/hooks/useWalletOrchestrator.test.tsx | 29 ------------------- tests/hooks/useWdkApp.test.tsx | 3 -- tests/hooks/useWorkletInitializer.test.tsx | 29 ------------------- tests/provider/WdkAppProvider.test.tsx | 32 ++++----------------- 8 files changed, 10 insertions(+), 114 deletions(-) diff --git a/src/hooks/internal/useWalletOrchestrator.ts b/src/hooks/internal/useWalletOrchestrator.ts index 0c1008c..d341262 100644 --- a/src/hooks/internal/useWalletOrchestrator.ts +++ b/src/hooks/internal/useWalletOrchestrator.ts @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useEffect, useMemo, useRef, useState } from 'react' import { getWalletIdFromLoadingState, getWalletStore, - isWalletErrorState, isWalletLoadingState, updateWalletLoadingState, WalletLoadingState, @@ -333,21 +332,6 @@ export function useWalletOrchestrator({ walletStore ]) - const retry = useCallback(() => { - log('[useWalletOrchestrator] Retrying initialization...') - if (authErrorRef.current) { - log( - '[useWalletOrchestrator] Clearing authentication error flag for retry', - ) - authErrorRef.current = null - } - if (isWalletErrorState(walletLoadingState)) { - walletStore.setState((prev) => - updateWalletLoadingState(prev, { type: 'not_loaded' }), - ) - } - }, [walletLoadingState, walletStore]) - const state = useMemo((): WdkAppState => { const walletError = walletLoadingState.type === 'error' ? walletLoadingState.error : null @@ -385,6 +369,5 @@ export function useWalletOrchestrator({ return { state, - retry, } } diff --git a/src/hooks/useWdkApp.ts b/src/hooks/useWdkApp.ts index f9c9b1d..80319ab 100644 --- a/src/hooks/useWdkApp.ts +++ b/src/hooks/useWdkApp.ts @@ -24,7 +24,7 @@ * import { useWdkApp } from '@tetherto/wdk-react-native-core' * * function App() { - * const { state, retry } = useWdkApp() + * const { state } = useWdkApp() * * switch (state.status) { * case 'INITIALIZING': @@ -40,7 +40,7 @@ * return * * case 'ERROR': - * return + * return * * default: * return diff --git a/src/provider/WdkAppProvider.tsx b/src/provider/WdkAppProvider.tsx index 6a26ecf..9a83045 100644 --- a/src/provider/WdkAppProvider.tsx +++ b/src/provider/WdkAppProvider.tsx @@ -40,7 +40,6 @@ export type WdkAppState = export interface WdkAppContextValue { state: WdkAppState; - retry: () => void; } const WdkAppContext = createContext(null) @@ -112,7 +111,7 @@ export function WdkAppProvider< useAppLifecycle({ clearSensitiveDataOnBackground }) - const { state, retry } = useWalletOrchestrator({ + const { state } = useWalletOrchestrator({ enableAutoInitialization, currentUserId, isWorkletStarted, @@ -124,9 +123,8 @@ export function WdkAppProvider< const contextValue: WdkAppContextValue = useMemo( () => ({ state, - retry, }), - [state, retry], + [state], ) return ( diff --git a/tests/hooks/useWalletManager.test.tsx b/tests/hooks/useWalletManager.test.tsx index edd631a..104d65f 100644 --- a/tests/hooks/useWalletManager.test.tsx +++ b/tests/hooks/useWalletManager.test.tsx @@ -114,7 +114,6 @@ beforeEach(() => { mockUseWdkApp.mockReturnValue({ state: { status: 'READY', walletId: 'mock-wdk-ready' }, - retry: jest.fn(), reinitializeWdk: jest.fn(), resetWallets: jest.fn(), }); @@ -131,7 +130,6 @@ beforeEach(() => { const ContextWrapper = ({ children }: PropsWithChildren) => { const mockWdkAppValue: WdkAppContextValue = { state: { status: 'READY', walletId: 'mock-wdk-ready' }, - retry: jest.fn(), }; mockUseWdkApp.mockReturnValue(mockWdkAppValue); diff --git a/tests/hooks/useWalletOrchestrator.test.tsx b/tests/hooks/useWalletOrchestrator.test.tsx index abeca65..26313b5 100644 --- a/tests/hooks/useWalletOrchestrator.test.tsx +++ b/tests/hooks/useWalletOrchestrator.test.tsx @@ -160,35 +160,6 @@ describe('useWalletOrchestrator', () => { expect(mockUnlock).toHaveBeenCalledTimes(1); }); - it('should retry initialization when retry() is called', async () => { - const error = new Error('some error'); - mockWalletStore.setState({ - activeWalletId: 'user1', - walletLoadingState: { type: 'error', error } as WalletLoadingState - }); - (WalletSetupService.hasWallet as jest.Mock).mockResolvedValue(true); - - const { result, rerender } = renderHook((props) => useWalletOrchestrator(props), { initialProps }); - - expect(mockUnlock).not.toHaveBeenCalled(); - - rerender(initialProps); - - expect(mockUnlock).not.toHaveBeenCalled(); - - act(() => { - result.current.retry(); - }); - - expect(mockWalletStore.getState().walletLoadingState.type).toBe('not_loaded'); - - rerender(initialProps); - - await waitFor(() => { - expect(mockUnlock).toHaveBeenCalledWith('user1'); - }); - }); - it('should return correct WdkAppState', async () => { const { result, rerender } = renderHook((props) => useWalletOrchestrator(props), { initialProps: { ...initialProps, isWorkletStarted: false } diff --git a/tests/hooks/useWdkApp.test.tsx b/tests/hooks/useWdkApp.test.tsx index 095858e..88b25bc 100644 --- a/tests/hooks/useWdkApp.test.tsx +++ b/tests/hooks/useWdkApp.test.tsx @@ -32,10 +32,8 @@ jest.spyOn(operationMutex, 'withOperationMutex').mockImplementation((_, fn) => f describe('useWdkApp', () => { let mockStore: StoreApi; - const mockRetry = jest.fn(); const mockContextValue: WdkAppContextValue = { state: { status: 'INITIALIZING' }, - retry: mockRetry, }; // Create a wrapper component that provides the mock context @@ -64,7 +62,6 @@ describe('useWdkApp', () => { const { result } = renderHook(() => useWdkApp(), { wrapper }); expect(result.current.state.status).toBe('INITIALIZING'); - expect(result.current.retry).toBe(mockRetry); }); describe('reinitializeWdk', () => { diff --git a/tests/hooks/useWorkletInitializer.test.tsx b/tests/hooks/useWorkletInitializer.test.tsx index ea6099a..a588a3b 100644 --- a/tests/hooks/useWorkletInitializer.test.tsx +++ b/tests/hooks/useWorkletInitializer.test.tsx @@ -171,35 +171,6 @@ describe('useWalletOrchestrator', () => { expect(mockUnlock).toHaveBeenCalledTimes(1); }); - it('should retry initialization when retry() is called', async () => { - const error = new Error('some error'); - mockWalletStore.setState({ - activeWalletId: 'user1', - walletLoadingState: { type: 'error', error } as WalletLoadingState - }); - (WalletSetupService.hasWallet as jest.Mock).mockResolvedValue(true); - - const { result, rerender } = renderHook((props) => useWalletOrchestrator(props), { initialProps }); - - expect(mockUnlock).not.toHaveBeenCalled(); - - rerender(initialProps); - - expect(mockUnlock).not.toHaveBeenCalled(); - - act(() => { - result.current.retry(); - }); - - expect(mockWalletStore.getState().walletLoadingState.type).toBe('not_loaded'); - - rerender(initialProps); - - await waitFor(() => { - expect(mockUnlock).toHaveBeenCalledWith('user1'); - }); - }); - it('should return correct WdkAppState', async () => { const { result, rerender } = renderHook((props) => useWalletOrchestrator(props), { initialProps: { ...initialProps, isWorkletStarted: false } diff --git a/tests/provider/WdkAppProvider.test.tsx b/tests/provider/WdkAppProvider.test.tsx index 935c31d..9b79e1b 100644 --- a/tests/provider/WdkAppProvider.test.tsx +++ b/tests/provider/WdkAppProvider.test.tsx @@ -13,8 +13,8 @@ // limitations under the License. import React from 'react'; -import { View, Text, Button } from 'react-native'; -import { render, screen, fireEvent } from '@testing-library/react-native'; +import { View, Text } from 'react-native'; +import { render, screen } from '@testing-library/react-native'; import { WdkAppProvider } from '../../src/provider/WdkAppProvider'; import { useWdkApp } from '../../src/hooks/useWdkApp'; import { useWalletOrchestrator } from '../../src/hooks/internal/useWalletOrchestrator'; @@ -40,7 +40,7 @@ jest.mock('../../src/hooks/internal/useAppLifecycle', () => ({ const mockUseWalletOrchestrator = useWalletOrchestrator as jest.Mock; const DummyConsumer = () => { - const { state, retry } = useWdkApp(); + const { state } = useWdkApp(); return ( @@ -48,7 +48,6 @@ const DummyConsumer = () => { {state.status === 'ERROR' && ( {state.error.message} )} -