@@ -88,4 +88,85 @@ describe('NestedTransactionTag', () => {
8888 } ) ;
8989 expect ( container ) . toBeEmptyDOMElement ( ) ;
9090 } ) ;
91+
92+ it ( 'handles transition from batch to non-batch transactions without error' , ( ) => {
93+ useNestedTransactionLabelsMock . mockReturnValue ( [
94+ FUNCTION_NAME_MOCK ,
95+ FUNCTION_NAME_MOCK ,
96+ ] ) ;
97+
98+ // First render with batch transactions
99+ const { getByText, rerender, container } = render ( {
100+ nestedTransactions : [
101+ BATCH_TRANSACTION_PARAMS_MOCK ,
102+ BATCH_TRANSACTION_PARAMS_MOCK ,
103+ ] ,
104+ } ) ;
105+ expect ( getByText ( 'Includes 2 transactions' ) ) . toBeInTheDocument ( ) ;
106+
107+ // Re-render with no nested transactions (simulating switching to different confirmation)
108+ // This should not throw React hooks error
109+ const storeWithNoNested = configureStore (
110+ getMockConfirmStateForTransaction (
111+ genUnapprovedContractInteractionConfirmation ( {
112+ address : ADDRESS_MOCK ,
113+ nestedTransactions : undefined ,
114+ } ) ,
115+ ) ,
116+ ) ;
117+
118+ expect ( ( ) => {
119+ rerender (
120+ renderWithConfirmContextProvider (
121+ < NestedTransactionTag /> ,
122+ storeWithNoNested ,
123+ ) . container . firstChild as React . ReactElement ,
124+ ) ;
125+ } ) . not . toThrow ( ) ;
126+ } ) ;
127+
128+ it ( 'handles transition between confirmations with different nested transaction counts without error' , ( ) => {
129+ // Start with 2 nested transactions
130+ useNestedTransactionLabelsMock . mockReturnValue ( [
131+ FUNCTION_NAME_MOCK ,
132+ FUNCTION_NAME_MOCK ,
133+ ] ) ;
134+
135+ const { getByText, container } = render ( {
136+ nestedTransactions : [
137+ BATCH_TRANSACTION_PARAMS_MOCK ,
138+ BATCH_TRANSACTION_PARAMS_MOCK ,
139+ ] ,
140+ } ) ;
141+ expect ( getByText ( 'Includes 2 transactions' ) ) . toBeInTheDocument ( ) ;
142+
143+ // Update mock to return 3 labels for next render
144+ useNestedTransactionLabelsMock . mockReturnValue ( [
145+ FUNCTION_NAME_MOCK ,
146+ FUNCTION_NAME_MOCK ,
147+ FUNCTION_NAME_MOCK ,
148+ ] ) ;
149+
150+ // Render with 3 nested transactions - should not throw due to different hook call count
151+ const storeWith3Nested = configureStore (
152+ getMockConfirmStateForTransaction (
153+ genUnapprovedContractInteractionConfirmation ( {
154+ address : ADDRESS_MOCK ,
155+ nestedTransactions : [
156+ BATCH_TRANSACTION_PARAMS_MOCK ,
157+ BATCH_TRANSACTION_PARAMS_MOCK ,
158+ BATCH_TRANSACTION_PARAMS_MOCK ,
159+ ] ,
160+ } ) ,
161+ ) ,
162+ ) ;
163+
164+ // This should not throw - the wrapper/inner pattern ensures clean remount
165+ expect ( ( ) => {
166+ renderWithConfirmContextProvider (
167+ < NestedTransactionTag /> ,
168+ storeWith3Nested ,
169+ ) ;
170+ } ) . not . toThrow ( ) ;
171+ } ) ;
91172} ) ;
0 commit comments