1
1
import { invityAPI } from '@suite-common/trading' ;
2
- import { UI } from '@trezor/connect' ;
3
2
4
3
import { MODAL , ROUTER } from 'src/actions/suite/constants' ;
5
4
import { TRADING_COMMON } from 'src/actions/wallet/constants' ;
@@ -42,6 +41,18 @@ const TRADING_EXCHANGE_ROUTE = {
42
41
url : '/accounts/coinmarket/exchange#/btc/0/normal' ,
43
42
} ;
44
43
44
+ const DEFAULT_ROUTE = {
45
+ loaded : false ,
46
+ url : '/' ,
47
+ pathname : '/' ,
48
+ app : 'unknown' ,
49
+ route : undefined ,
50
+ params : undefined ,
51
+ settingsBackRoute : {
52
+ name : 'suite-index' ,
53
+ } ,
54
+ } as RouterState ;
55
+
45
56
type TradingState = ReturnType < typeof tradingReducer > ;
46
57
type SelectedAccountState = ReturnType < typeof selectedAccountReducer > ;
47
58
type SuiteState = ReturnType < typeof suiteReducer > ;
@@ -54,7 +65,7 @@ interface Args {
54
65
modal ?: ModalState ;
55
66
}
56
67
57
- const getInitialState = ( { trading, selectedAccount } : Args = { } ) => ( {
68
+ const getInitialState = ( { trading, selectedAccount, router } : Args = { } ) => ( {
58
69
wallet : {
59
70
trading :
60
71
trading ||
@@ -85,20 +96,7 @@ const getInitialState = ({ trading, selectedAccount }: Args = {}) => ({
85
96
} as any ,
86
97
{ type : 'foo' } as any ,
87
98
) ,
88
- router : routerReducer (
89
- {
90
- loaded : false ,
91
- url : '/' ,
92
- pathname : '/' ,
93
- app : 'unknown' ,
94
- route : undefined ,
95
- params : undefined ,
96
- settingsBackRoute : {
97
- name : 'suite-index' ,
98
- } ,
99
- } as RouterState ,
100
- { } as Action ,
101
- ) ,
99
+ router : router ?? routerReducer ( DEFAULT_ROUTE , { } as Action ) ,
102
100
modal : modalReducer ( { context : MODAL . CONTEXT_NONE } , { } as Action ) ,
103
101
} ) ;
104
102
@@ -229,71 +227,30 @@ describe('tradingMiddleware', () => {
229
227
expect ( setInvityServersEnvironmentMock ) . toHaveBeenCalledTimes ( 0 ) ;
230
228
} ) ;
231
229
232
- it ( 'Test of cleaning modalAccountKey property after receive modal is closed ' , ( ) => {
230
+ it ( 'should clean modalAccountKey after leaving trading ' , ( ) => {
233
231
const store = initStore (
234
232
getInitialState ( {
235
233
trading : {
236
234
...initialState ,
237
235
modalAccountKey : accounts [ 0 ] . key ,
238
236
lastLoadedTimestamp : Date . now ( ) ,
239
237
} ,
238
+ router : routerReducer ( TRADING_EXCHANGE_ROUTE as RouterState , { } as Action ) ,
240
239
} ) ,
241
240
) ;
242
241
243
- // go to trading
242
+ // go away from trading
244
243
store . dispatch ( {
245
244
type : ROUTER . LOCATION_CHANGE ,
246
- payload : TRADING_EXCHANGE_ROUTE ,
247
- } ) ;
248
-
249
- // open modal
250
- store . dispatch ( {
251
- type : UI . REQUEST_BUTTON ,
252
245
payload : {
253
- context : MODAL . CONTEXT_DEVICE ,
254
- code : 'ButtonRequest_Address' ,
255
- } ,
256
- } ) ;
257
-
258
- // close modal
259
- store . dispatch ( {
260
- type : UI . CLOSE_UI_WINDOW ,
261
- } ) ;
262
-
263
- expect ( store . getState ( ) . wallet . trading . modalAccountKey ) . toEqual ( undefined ) ;
264
- } ) ;
265
-
266
- it ( 'Test of cleaning modalAccountKey property after send modal is closed' , ( ) => {
267
- const store = initStore (
268
- getInitialState ( {
269
- trading : {
270
- ...initialState ,
271
- modalAccountKey : accounts [ 0 ] . key ,
272
- lastLoadedTimestamp : Date . now ( ) ,
246
+ ...DEFAULT_ROUTE ,
247
+ route : {
248
+ ...DEFAULT_ROUTE . route ,
249
+ name : 'suite-start' ,
273
250
} ,
274
- } ) ,
275
- ) ;
276
-
277
- // go to trading
278
- store . dispatch ( {
279
- type : ROUTER . LOCATION_CHANGE ,
280
- payload : TRADING_EXCHANGE_ROUTE ,
281
- } ) ;
282
-
283
- // open modal
284
- store . dispatch ( {
285
- type : UI . REQUEST_BUTTON ,
286
- payload : {
287
- context : MODAL . CONTEXT_DEVICE ,
288
- code : 'ButtonRequest_SignTx' ,
289
251
} ,
290
252
} ) ;
291
253
292
- // close modal
293
- store . dispatch ( {
294
- type : MODAL . CLOSE ,
295
- } ) ;
296
-
297
254
expect ( store . getState ( ) . wallet . trading . modalAccountKey ) . toEqual ( undefined ) ;
298
255
} ) ;
299
256
@@ -303,6 +260,9 @@ describe('tradingMiddleware', () => {
303
260
trading : {
304
261
...initialState ,
305
262
} ,
263
+ router : {
264
+ ...getInitialState ( ) . router ,
265
+ } ,
306
266
} ) ,
307
267
) ;
308
268
0 commit comments