1
- import { useMemo } from 'react' ;
1
+ import { useMemo , useState } from 'react' ;
2
2
3
3
import { motion } from 'framer-motion' ;
4
4
import styled from 'styled-components' ;
5
5
6
6
import { deviceNeedsAttention , getStatus } from '@suite-common/suite-utils' ;
7
7
import { selectDevices , selectSelectedDevice } from '@suite-common/wallet-core' ;
8
- import { Button , motionEasing } from '@trezor/components' ;
8
+ import { Button , ElevationContext , ElevationDown , Flex , motionEasing } from '@trezor/components' ;
9
9
10
10
import { goto } from 'src/actions/suite/routerActions' ;
11
11
import { ConnectDevicePrompt , Translation } from 'src/components/suite' ;
12
12
import { useDispatch , useSelector } from 'src/hooks/suite' ;
13
- import { selectHasTransportOfType , selectPrerequisite } from 'src/reducers/suite/suiteReducer' ;
13
+ import { selectPrerequisite } from 'src/reducers/suite/suiteReducer' ;
14
14
15
15
import { DeviceAcquire } from './DeviceAcquire' ;
16
16
import { DeviceBootloader } from './DeviceBootloader' ;
@@ -43,16 +43,25 @@ const ButtonWrapper = styled.div`
43
43
margin-top: 30px;
44
44
` ;
45
45
46
- interface PrerequisitesGuideProps {
46
+ const Bluetooth = ( ) => (
47
+ < ElevationContext baseElevation = { - 1 } >
48
+ { /* Here we need to draw the inner card with elevation -1 (custom design) */ }
49
+ < ElevationDown >
50
+ < Flex width = { 470 } > Here will be the Bluetooth connection dialog</ Flex >
51
+ </ ElevationDown >
52
+ </ ElevationContext >
53
+ ) ;
54
+
55
+ type NonBluetoothProps = {
47
56
allowSwitchDevice ?: boolean ;
48
- }
57
+ setIsBluetoothConnectOpen : ( isOpen : boolean ) => void ;
58
+ } ;
49
59
50
- export const PrerequisitesGuide = ( { allowSwitchDevice } : PrerequisitesGuideProps ) => {
60
+ const NonBluetooth = ( { allowSwitchDevice, setIsBluetoothConnectOpen } : NonBluetoothProps ) => {
51
61
const dispatch = useDispatch ( ) ;
52
62
const device = useSelector ( selectSelectedDevice ) ;
53
63
const devices = useSelector ( selectDevices ) ;
54
64
const connectedDevicesCount = devices . filter ( d => d . connected === true ) . length ;
55
- const isWebUsbTransport = useSelector ( selectHasTransportOfType ( 'WebUsbTransport' ) ) ;
56
65
const prerequisite = useSelector ( selectPrerequisite ) ;
57
66
58
67
const TipComponent = useMemo (
@@ -63,7 +72,9 @@ export const PrerequisitesGuide = ({ allowSwitchDevice }: PrerequisitesGuideProp
63
72
case 'device-disconnect-required' :
64
73
return < DeviceDisconnectRequired /> ;
65
74
case 'device-disconnected' :
66
- return < DeviceConnect isWebUsbTransport = { isWebUsbTransport } /> ;
75
+ return (
76
+ < DeviceConnect onBluetoothClick = { ( ) => setIsBluetoothConnectOpen ( true ) } />
77
+ ) ;
67
78
case 'device-unacquired' :
68
79
return < DeviceAcquire /> ;
69
80
case 'device-used-elsewhere' :
@@ -91,14 +102,14 @@ export const PrerequisitesGuide = ({ allowSwitchDevice }: PrerequisitesGuideProp
91
102
return < > </ > ;
92
103
}
93
104
} ,
94
- [ prerequisite , isWebUsbTransport , device ] ,
105
+ [ prerequisite , device , setIsBluetoothConnectOpen ] ,
95
106
) ;
96
107
97
108
const handleSwitchDeviceClick = ( ) =>
98
109
dispatch ( goto ( 'suite-switch-device' , { params : { cancelable : true } } ) ) ;
99
110
100
111
return (
101
- < Wrapper >
112
+ < >
102
113
< ConnectDevicePrompt
103
114
connected = { ! ! device }
104
115
showWarning = {
@@ -123,6 +134,27 @@ export const PrerequisitesGuide = ({ allowSwitchDevice }: PrerequisitesGuideProp
123
134
>
124
135
< TipComponent />
125
136
</ TipsContainer >
137
+ </ >
138
+ ) ;
139
+ } ;
140
+
141
+ interface PrerequisitesGuideProps {
142
+ allowSwitchDevice ?: boolean ;
143
+ }
144
+
145
+ export const PrerequisitesGuide = ( { allowSwitchDevice } : PrerequisitesGuideProps ) => {
146
+ const [ isBluetoothConnectOpen , setIsBluetoothConnectOpen ] = useState ( false ) ;
147
+
148
+ return (
149
+ < Wrapper >
150
+ { isBluetoothConnectOpen ? (
151
+ < Bluetooth />
152
+ ) : (
153
+ < NonBluetooth
154
+ allowSwitchDevice = { allowSwitchDevice }
155
+ setIsBluetoothConnectOpen = { setIsBluetoothConnectOpen }
156
+ />
157
+ ) }
126
158
</ Wrapper >
127
159
) ;
128
160
} ;
0 commit comments