@@ -5,26 +5,24 @@ import { setTransactionActive } from '../../../store/actions';
5
5
import { useWindowFocus } from '../../../hooks/useWindowFocus' ;
6
6
import { useConfirmContext } from '../context/confirm' ;
7
7
8
- const shouldSetFocusedForType = ( type : TransactionType ) => {
9
- return (
10
- type === TransactionType . contractInteraction ||
11
- type === TransactionType . deployContract ||
12
- type === TransactionType . simpleSend ||
13
- type === TransactionType . smart ||
14
- type === TransactionType . tokenMethodTransfer ||
15
- type === TransactionType . tokenMethodTransferFrom ||
16
- type === TransactionType . tokenMethodSafeTransferFrom
17
- ) ;
18
- } ;
8
+ const FOCUSABLE_TYPES : Set < TransactionType > = new Set ( [
9
+ TransactionType . contractInteraction ,
10
+ TransactionType . deployContract ,
11
+ TransactionType . simpleSend ,
12
+ TransactionType . smart ,
13
+ TransactionType . tokenMethodTransfer ,
14
+ TransactionType . tokenMethodTransferFrom ,
15
+ TransactionType . tokenMethodSafeTransferFrom ,
16
+ ] ) ;
19
17
20
18
export const useTransactionFocusEffect = ( ) => {
21
19
const { currentConfirmation } = useConfirmContext ( ) ;
22
20
const { id, type } = currentConfirmation ?? { } ;
23
21
const isWindowFocused = useWindowFocus ( ) ;
24
22
const dispatch = useDispatch ( ) ;
25
- const [ focusedConfirmation , setFocusedConfirmation ] = useState < string | null > (
26
- null ,
27
- ) ;
23
+ const [ focusedConfirmationId , setFocusedConfirmationId ] = useState <
24
+ string | null
25
+ > ( null ) ;
28
26
29
27
const setTransactionFocus = useCallback (
30
28
async ( transactionId : string , isFocused : boolean ) => {
@@ -34,32 +32,32 @@ export const useTransactionFocusEffect = () => {
34
32
) ;
35
33
36
34
useEffect ( ( ) => {
37
- const shouldBeMarked = shouldSetFocusedForType ( type as TransactionType ) ;
35
+ const isFocusable = FOCUSABLE_TYPES . has ( type as TransactionType ) ;
38
36
39
- if ( ! shouldBeMarked ) {
37
+ if ( ! isFocusable ) {
40
38
// If the transaction type is not one of the types that should be focused,
41
39
// we need to unfocus the previous focused confirmation and reset the focused confirmation
42
- if ( focusedConfirmation ) {
43
- setTransactionFocus ( focusedConfirmation , false ) ;
44
- setFocusedConfirmation ( null ) ;
40
+ if ( focusedConfirmationId ) {
41
+ setTransactionFocus ( focusedConfirmationId , false ) ;
42
+ setFocusedConfirmationId ( null ) ;
45
43
}
46
44
return ;
47
45
}
48
46
49
- if ( isWindowFocused && focusedConfirmation !== id ) {
47
+ if ( isWindowFocused && focusedConfirmationId !== id ) {
50
48
// If the window is focused and the focused confirmation is not the current one,
51
49
// we need to unfocus the previous focused confirmation and focus the current one
52
- if ( focusedConfirmation ) {
53
- setTransactionFocus ( focusedConfirmation , false ) ;
50
+ if ( focusedConfirmationId ) {
51
+ setTransactionFocus ( focusedConfirmationId , false ) ;
54
52
}
55
53
// Set the focused confirmation to the current one
56
- setFocusedConfirmation ( id ) ;
54
+ setFocusedConfirmationId ( id ) ;
57
55
setTransactionFocus ( id , true ) ;
58
- } else if ( ! isWindowFocused && focusedConfirmation ) {
56
+ } else if ( ! isWindowFocused && focusedConfirmationId ) {
59
57
// If the window is not focused and there is a focused confirmation,
60
58
// we need to unfocus the focused confirmation
61
- setTransactionFocus ( focusedConfirmation , false ) ;
62
- setFocusedConfirmation ( null ) ;
59
+ setTransactionFocus ( focusedConfirmationId , false ) ;
60
+ setFocusedConfirmationId ( null ) ;
63
61
}
64
- } , [ focusedConfirmation , id , isWindowFocused , setTransactionFocus , type ] ) ;
62
+ } , [ focusedConfirmationId , id , isWindowFocused , setTransactionFocus , type ] ) ;
65
63
} ;
0 commit comments