@@ -12,7 +12,7 @@ import {
1212 getPlatform ,
1313} from 'services/remote'
1414import { ErrorCode , clsx , errorFormatter , isSuccessResponse , addressToAddress , useDidMount } from 'utils'
15- import { CkbAppNotFoundException , DeviceNotFoundException } from 'exceptions'
15+ import { CkbAppNotFoundException , DeviceNotFoundException , DeviceNotMatchWalletException } from 'exceptions'
1616import Alert from 'widgets/Alert'
1717import styles from './receive.module.scss'
1818
@@ -42,9 +42,14 @@ const VerifyHardwareAddress = ({ address, wallet, onClose = () => {} }: VerifyHa
4242 const userInputStatus = t ( 'hardware-verify-address.status.user-input' )
4343 const disconnectStatus = t ( 'hardware-verify-address.status.disconnect' )
4444 const ckbAppNotFoundStatus = t ( CkbAppNotFoundException . message )
45+ const deviceNotMatchWalletStatus = t ( DeviceNotMatchWalletException . message )
4546 const isNotAvailableToVerify = useMemo ( ( ) => {
46- return status ?. message === disconnectStatus || status ?. message === ckbAppNotFoundStatus
47- } , [ status , disconnectStatus , ckbAppNotFoundStatus ] )
47+ return (
48+ status ?. message === disconnectStatus ||
49+ status ?. message === ckbAppNotFoundStatus ||
50+ status ?. message === deviceNotMatchWalletStatus
51+ )
52+ } , [ status , disconnectStatus , ckbAppNotFoundStatus , deviceNotMatchWalletStatus ] )
4853
4954 const [ deviceInfo , setDeviceInfo ] = useState ( wallet . device ! )
5055 const [ isReconnecting , setIsReconnecting ] = useState ( false )
@@ -55,14 +60,16 @@ const VerifyHardwareAddress = ({ address, wallet, onClose = () => {} }: VerifyHa
5560 const ensureDeviceAvailable = useCallback (
5661 async ( device : DeviceInfo ) => {
5762 try {
58- const connectionRes = await connectDevice ( device )
63+ const connectionRes = await connectDevice ( { ... device , walletID : wallet . id } )
5964 let { descriptor } = device
6065 if ( ! isSuccessResponse ( connectionRes ) ) {
6166 // for win32, opening or closing the ckb app changes the HID descriptor(deviceInfo),
6267 // so if we can't connect to the device, we need to re-search device automatically.
6368 // for unix, the descriptor never changes unless user plugs the device into another USB port,
6469 // in that case, mannauly re-search device one time will do.
65- if ( isWin32 ) {
70+ if ( connectionRes . status === ErrorCode . DeviceNotMatchWallet ) {
71+ throw new DeviceNotMatchWalletException ( )
72+ } else if ( isWin32 ) {
6673 setIsReconnecting ( true )
6774 const devicesRes = await getDevices ( device )
6875 setIsReconnecting ( false )
@@ -99,12 +106,14 @@ const VerifyHardwareAddress = ({ address, wallet, onClose = () => {} }: VerifyHa
99106 } catch ( err ) {
100107 if ( err instanceof CkbAppNotFoundException ) {
101108 setStatus ( { type : 'error' , message : ckbAppNotFoundStatus } )
109+ } else if ( err instanceof DeviceNotMatchWalletException ) {
110+ setStatus ( { type : 'error' , message : deviceNotMatchWalletStatus } )
102111 } else {
103112 setStatus ( { type : 'error' , message : disconnectStatus } )
104113 }
105114 }
106115 } ,
107- [ disconnectStatus , ckbAppNotFoundStatus , isWin32 ]
116+ [ disconnectStatus , ckbAppNotFoundStatus , isWin32 , wallet ]
108117 )
109118
110119 const reconnect = useCallback ( async ( ) => {
0 commit comments