1
- import { useDispatch } from 'react-redux' ;
1
+ import { useDispatch , useSelector } from 'react-redux' ;
2
2
3
- import { Button , HStack , Text } from '@suite-native/atoms' ;
3
+ import { Button , HStack , Loader , Text } from '@suite-native/atoms' ;
4
4
import { Translation } from '@suite-native/intl' ;
5
- import { deviceActions , toggleRememberDevice } from '@suite-common/wallet-core' ;
5
+ import {
6
+ DeviceRootState ,
7
+ DiscoveryRootState ,
8
+ deviceActions ,
9
+ selectIsDiscoveryActiveByDeviceState ,
10
+ toggleRememberDevice ,
11
+ } from '@suite-common/wallet-core' ;
6
12
import { analytics , EventType } from '@suite-native/analytics' ;
7
13
import { useAlert } from '@suite-native/alerts' ;
8
14
import { useToast } from '@suite-native/toasts' ;
@@ -11,18 +17,25 @@ import { TrezorDevice } from '@suite-common/suite-types';
11
17
import { prepareNativeStyle , useNativeStyles } from '@trezor/styles' ;
12
18
import { setViewOnlyCancelationTimestamp } from '@suite-native/settings' ;
13
19
20
+ type WalletRowProps = {
21
+ device : TrezorDevice ;
22
+ } ;
23
+
14
24
const walletRowStyle = prepareNativeStyle ( utils => ( {
15
25
paddingHorizontal : utils . spacings . medium ,
16
26
justifyContent : 'space-between' ,
17
27
alignItems : 'center' ,
18
28
height : 60 ,
19
29
} ) ) ;
20
30
21
- export const WalletRow = ( { device } : { device : TrezorDevice } ) => {
31
+ export const WalletRow = ( { device } : WalletRowProps ) => {
22
32
const dispatch = useDispatch ( ) ;
23
33
const { showAlert, hideAlert } = useAlert ( ) ;
24
34
const { showToast } = useToast ( ) ;
25
35
const { applyStyle } = useNativeStyles ( ) ;
36
+ const isDeviceDiscoveryActive = useSelector ( ( state : DiscoveryRootState & DeviceRootState ) =>
37
+ selectIsDiscoveryActiveByDeviceState ( state , device . state ) ,
38
+ ) ;
26
39
27
40
const walletNameLabel = device . useEmptyPassphrase ? (
28
41
< Translation id = "moduleSettings.viewOnly.wallet.standard" />
@@ -90,6 +103,8 @@ export const WalletRow = ({ device }: { device: TrezorDevice }) => {
90
103
} ) ;
91
104
} ;
92
105
106
+ const showToggleButton = device . remember || ! isDeviceDiscoveryActive ;
107
+
93
108
return (
94
109
< HStack key = { device . instance } style = { applyStyle ( walletRowStyle ) } >
95
110
< HStack spacing = { 12 } alignItems = "center" >
@@ -99,19 +114,23 @@ export const WalletRow = ({ device }: { device: TrezorDevice }) => {
99
114
/>
100
115
< Text variant = "callout" > { walletNameLabel } </ Text >
101
116
</ HStack >
102
- < Button
103
- size = "extraSmall"
104
- colorScheme = { device . remember ? 'redElevation0' : 'primary' }
105
- onPress = { ( ) => ( device . remember ? handleDisableViewOnly ( ) : toggleViewOnly ( ) ) }
106
- >
107
- < Translation
108
- id = {
109
- device . remember
110
- ? 'moduleSettings.viewOnly.button.disable'
111
- : 'moduleSettings.viewOnly.button.enable'
112
- }
113
- />
114
- </ Button >
117
+ { showToggleButton ? (
118
+ < Button
119
+ size = "extraSmall"
120
+ colorScheme = { device . remember ? 'redElevation0' : 'primary' }
121
+ onPress = { ( ) => ( device . remember ? handleDisableViewOnly ( ) : toggleViewOnly ( ) ) }
122
+ >
123
+ < Translation
124
+ id = {
125
+ device . remember
126
+ ? 'moduleSettings.viewOnly.button.disable'
127
+ : 'moduleSettings.viewOnly.button.enable'
128
+ }
129
+ />
130
+ </ Button >
131
+ ) : (
132
+ < Loader size = "small" />
133
+ ) }
115
134
</ HStack >
116
135
) ;
117
136
} ;
0 commit comments