-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.tsx
More file actions
77 lines (71 loc) · 2.46 KB
/
index.tsx
File metadata and controls
77 lines (71 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { useEffect, useReducer } from 'react'
import { useDialogWrapper } from 'utils'
import Confirming from './confirming'
import ImportError from './import-error'
import SelectModel from './select-model'
import DetectDevice from './detect-device'
import ImportSuccess from './import-success'
import NameWallet from './name-wallet'
import { ImportStep, ImportHardwareState, ActionType } from './common'
import styles from './findDevice.module.scss'
const reducer: React.Reducer<ImportHardwareState, ActionType> = (state, action) => {
return { ...state, ...action }
}
const Content = () => {
const [importHardwareStates, dispatch] = useReducer(reducer, { step: ImportStep.ImportHardware })
const { dialogRef, openDialog, closeDialog } = useDialogWrapper()
useEffect(() => {
if (!dialogRef) {
return
}
if (
importHardwareStates.step === ImportStep.ImportHardware ||
importHardwareStates.step === ImportStep.NameWallet
) {
closeDialog()
} else {
openDialog()
}
}, [importHardwareStates.step, dialogRef, closeDialog, openDialog])
switch (importHardwareStates.step) {
case ImportStep.ImportHardware:
case ImportStep.DetectDevice:
case ImportStep.Confirming:
case ImportStep.Error:
case ImportStep.Success:
return (
<>
<SelectModel dispatch={dispatch} />
<dialog ref={dialogRef} className={styles.dialog}>
{ImportStep.DetectDevice === importHardwareStates.step && (
<DetectDevice dispatch={dispatch} model={importHardwareStates.model!} />
)}
{ImportStep.Confirming === importHardwareStates.step && <Confirming dispatch={dispatch} />}
{ImportStep.Error === importHardwareStates.step && (
<ImportError dispatch={dispatch} error={importHardwareStates.error} />
)}
{ImportStep.Success === importHardwareStates.step && <ImportSuccess dispatch={dispatch} />}
</dialog>
</>
)
case ImportStep.NameWallet:
return (
<NameWallet
dispatch={dispatch}
model={importHardwareStates.model}
extendedPublicKey={importHardwareStates.extendedPublicKey}
/>
)
default:
return <SelectModel dispatch={dispatch} />
}
}
const ImportHardware = () => {
return (
<div className={styles.importHardwareRoot}>
<Content />
</div>
)
}
ImportHardware.displayName = 'ImportHardware'
export default ImportHardware