@@ -83,75 +83,6 @@ jest.mock('../../../app/util/haptics', () => {
8383 } ) ,
8484 } ;
8585} ) ;
86- jest . mock (
87- '../../../app/components/Views/confirmations/hooks/pay/useTransactionPayData' ,
88- ( ) => ( {
89- useTransactionPayTotals : ( ) => null ,
90- useIsTransactionPayQuoteLoading : ( ) => false ,
91- } ) ,
92- ) ;
93- jest . mock (
94- '../../../app/components/Views/confirmations/hooks/pay/useTransactionPayMetrics' ,
95- ( ) => ( {
96- useTransactionPayMetrics : jest . fn ( ) ,
97- } ) ,
98- ) ;
99- jest . mock (
100- '../../../app/components/Views/confirmations/hooks/pay/useTransactionPayToken' ,
101- ( ) => ( {
102- useTransactionPayToken : ( ) => ( { payToken : null } ) ,
103- } ) ,
104- ) ;
105- jest . mock (
106- '../../../app/components/Views/confirmations/hooks/tokens/useAddToken' ,
107- ( ) => ( {
108- useAddToken : jest . fn ( ) ,
109- } ) ,
110- ) ;
111- jest . mock (
112- '../../../app/components/Views/confirmations/hooks/transactions/useTransactionConfirm' ,
113- ( ) => ( {
114- useTransactionConfirm : ( ) => ( {
115- onConfirm : jest . fn ( ) . mockResolvedValue ( undefined ) ,
116- } ) ,
117- } ) ,
118- ) ;
119- jest . mock (
120- '../../../app/components/Views/confirmations/hooks/transactions/useTransactionCustomAmount' ,
121- ( ) => ( {
122- useTransactionCustomAmount : ( ) => ( { setCustomAmount : jest . fn ( ) } ) ,
123- } ) ,
124- ) ;
125- jest . mock (
126- '../../../app/components/Views/confirmations/hooks/transactions/useTransactionMetadataRequest' ,
127- ( ) => ( {
128- useTransactionMetadataRequest : ( ) => undefined ,
129- } ) ,
130- ) ;
131- jest . mock (
132- '../../../app/components/Views/confirmations/hooks/transactions/useUpdateTokenAmount' ,
133- ( ) => ( {
134- useUpdateTokenAmount : ( ) => jest . fn ( ) ,
135- } ) ,
136- ) ;
137- jest . mock (
138- '../../../app/components/Views/confirmations/hooks/useConfirmActions' ,
139- ( ) => ( {
140- useConfirmActions : ( ) => ( { onReject : jest . fn ( ) } ) ,
141- } ) ,
142- ) ;
143- jest . mock (
144- '../../../app/components/Views/confirmations/hooks/alerts/useInsufficientPayTokenBalanceAlert' ,
145- ( ) => ( {
146- useInsufficientPayTokenBalanceAlert : ( ) => [ ] ,
147- } ) ,
148- ) ;
149- jest . mock (
150- '../../../app/components/Views/confirmations/hooks/alerts/useNoPayTokenQuotesAlert' ,
151- ( ) => ( {
152- useNoPayTokenQuotesAlert : ( ) => [ ] ,
153- } ) ,
154- ) ;
15586jest . mock ( '../../../app/util/trace' , ( ) => ( {
15687 TraceName : {
15788 PerpsOrderView : 'PerpsOrderView' ,
@@ -170,6 +101,8 @@ import React from 'react';
170101import { View } from 'react-native' ;
171102import { SafeAreaProvider } from 'react-native-safe-area-context' ;
172103import { createStackNavigator } from '@react-navigation/stack' ;
104+ import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
105+ import { ConnectionStatus } from '@metamask/hw-wallet-sdk' ;
173106
174107import { buildPerpsFlowHarness , type PerpsFlowHarness } from './perps-flow' ;
175108import type { PerpsHarnessOptions } from './perps' ;
@@ -193,6 +126,9 @@ import type {
193126import { AccessRestrictedProvider } from '../../../app/components/UI/Compliance' ;
194127import Routes from '../../../app/constants/navigation/Routes' ;
195128import { initialStatePerps } from '../../component-view/presets/perpsStatePreset' ;
129+ import HardwareWalletContext , {
130+ type HardwareWalletContextValue ,
131+ } from '../../../app/core/HardwareWallet/contexts/HardwareWalletContext' ;
196132
197133type ToastOptionsForHarness = ToastOptions ;
198134
@@ -230,6 +166,30 @@ export interface PerpsComponentHarness extends PerpsFlowHarness {
230166
231167const noopUnsubscribe = ( ) : void => undefined ;
232168
169+ function createTestQueryClient ( ) {
170+ return new QueryClient ( {
171+ defaultOptions : {
172+ queries : { retry : false } ,
173+ mutations : { retry : false } ,
174+ } ,
175+ } ) ;
176+ }
177+
178+ function QueryClientBoundary ( { children } : { children : React . ReactNode } ) {
179+ const [ queryClient ] = React . useState ( createTestQueryClient ) ;
180+
181+ React . useEffect (
182+ ( ) => ( ) => {
183+ queryClient . clear ( ) ;
184+ } ,
185+ [ queryClient ] ,
186+ ) ;
187+
188+ return (
189+ < QueryClientProvider client = { queryClient } > { children } </ QueryClientProvider >
190+ ) ;
191+ }
192+
233193const testConnectionValue : PerpsConnectionContextValue = {
234194 isConnected : true ,
235195 isConnecting : false ,
@@ -241,6 +201,31 @@ const testConnectionValue: PerpsConnectionContextValue = {
241201 reconnectWithNewContext : async ( ) : Promise < void > => undefined ,
242202} ;
243203
204+ const testHardwareWalletValue : HardwareWalletContextValue = {
205+ walletType : null ,
206+ deviceId : null ,
207+ connectionState : { status : ConnectionStatus . Disconnected } ,
208+ deviceSelection : {
209+ devices : [ ] ,
210+ selectedDevice : null ,
211+ isScanning : false ,
212+ scanError : null ,
213+ } ,
214+ ensureDeviceReady : async ( ) : Promise < boolean > => true ,
215+ setTargetWalletType : ( ) : void => undefined ,
216+ setPendingOperationAddress : ( ) : void => undefined ,
217+ showHardwareWalletError : ( ) : void => undefined ,
218+ showAwaitingConfirmation : ( ) : void => undefined ,
219+ hideAwaitingConfirmation : ( ) : void => undefined ,
220+ qr : {
221+ pendingScanRequest : undefined ,
222+ isSigningQRObject : false ,
223+ setRequestCompleted : ( ) : void => undefined ,
224+ isRequestCompleted : false ,
225+ cancelQRScanRequestIfPresent : async ( ) : Promise < void > => undefined ,
226+ } ,
227+ } ;
228+
244229function channelWithInitialValue < T > ( initialValue : T ) {
245230 return {
246231 subscribe : ( params : { callback : ( data : T ) => void } ) : ( ( ) => void ) => {
@@ -349,15 +334,19 @@ export function buildPerpsComponentHarness(
349334 insets : { top : 0 , left : 0 , right : 0 , bottom : 0 } ,
350335 } }
351336 >
352- < ToastContext . Provider value = { { toastRef } } >
353- < AccessRestrictedProvider >
354- < PerpsConnectionContext . Provider value = { testConnectionValue } >
355- < PerpsStreamProvider testStreamManager = { streamManager } >
356- { component }
357- </ PerpsStreamProvider >
358- </ PerpsConnectionContext . Provider >
359- </ AccessRestrictedProvider >
360- </ ToastContext . Provider >
337+ < QueryClientBoundary >
338+ < HardwareWalletContext . Provider value = { testHardwareWalletValue } >
339+ < ToastContext . Provider value = { { toastRef } } >
340+ < AccessRestrictedProvider >
341+ < PerpsConnectionContext . Provider value = { testConnectionValue } >
342+ < PerpsStreamProvider testStreamManager = { streamManager } >
343+ { component }
344+ </ PerpsStreamProvider >
345+ </ PerpsConnectionContext . Provider >
346+ </ AccessRestrictedProvider >
347+ </ ToastContext . Provider >
348+ </ HardwareWalletContext . Provider >
349+ </ QueryClientBoundary >
361350 </ SafeAreaProvider >
362351 ) ;
363352
0 commit comments