diff --git a/packages/kit/src/utils/hardware/deviceUtils.ts b/packages/kit/src/utils/hardware/deviceUtils.ts index 69a467df8a8..f913da2b071 100644 --- a/packages/kit/src/utils/hardware/deviceUtils.ts +++ b/packages/kit/src/utils/hardware/deviceUtils.ts @@ -98,7 +98,8 @@ class DeviceUtils { }; this.scanning = true; - poll(); + const time = platformEnv.isNativeAndroid ? 2000 : POLL_INTERVAL; + poll(time); } stopScan() { diff --git a/packages/kit/src/views/CreateWallet/HardwareWallet/ConnectHardware.tsx b/packages/kit/src/views/CreateWallet/HardwareWallet/ConnectHardware.tsx index 4cd4c0a2c89..20aa83c25ab 100644 --- a/packages/kit/src/views/CreateWallet/HardwareWallet/ConnectHardware.tsx +++ b/packages/kit/src/views/CreateWallet/HardwareWallet/ConnectHardware.tsx @@ -134,18 +134,20 @@ const ConnectHardwareModal: FC = () => { deviceUtils.startDeviceScan((response) => { if (!response.success) { - ToastManager.show({ - title: intl.formatMessage({ - id: 'msg__hardware_failed_to_search_devices', - }), - }); + if (platformEnv.isNative) { + ToastManager.show({ + title: intl.formatMessage({ + id: 'msg__hardware_failed_to_search_devices', + }), + }); + } setIsSearching(false); return; } setSearchedDevices(response.payload); }); - }, []); + }, [intl]); useEffect(() => { if (platformEnv.isRuntimeBrowser) handleScanDevice(); @@ -190,35 +192,29 @@ const ConnectHardwareModal: FC = () => { finishConnected(result); }) .catch(async (err) => { - switch (err) { - case DeviceNotBonded: { - if (!checkBonded && platformEnv.isNativeAndroid) { - setCheckBonded(true); - const bonded = await deviceUtils.checkDeviceBonded( - device.connectId ?? '', - ); - if (bonded) { - setCheckBonded(false); - deviceUtils.connect(device.connectId ?? '').then((r) => { - setTimeout(() => finishConnected(r), 1000); - }); - } - } - break; - } - default: - if (err instanceof OneKeyHardwareError) { - ToastManager.show({ - title: intl.formatMessage({ id: err.key }), - }); - } else { - ToastManager.show({ - title: intl.formatMessage({ - id: 'action__connection_timeout', - }), + if (err instanceof DeviceNotBonded) { + if (!checkBonded && platformEnv.isNativeAndroid) { + setCheckBonded(true); + const bonded = await deviceUtils.checkDeviceBonded( + device.connectId ?? '', + ); + if (bonded) { + setCheckBonded(false); + deviceUtils.connect(device.connectId ?? '').then((r) => { + setTimeout(() => finishConnected(r), 1000); }); } - break; + } + } else if (err instanceof OneKeyHardwareError) { + ToastManager.show({ + title: intl.formatMessage({ id: err.key }), + }); + } else { + ToastManager.show({ + title: intl.formatMessage({ + id: 'action__connection_timeout', + }), + }); } }); },