From ff58a8382230b1899d12e49b1bb32ebd604e362a Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 30 Jun 2022 14:59:10 +0800 Subject: [PATCH] fix: check bonded android device & android search device failed OK-10405 OK-10408 (#1008) * fix: check bonded android device * fix: android search device interval Co-authored-by: ll__ --- .../kit/src/utils/hardware/deviceUtils.ts | 3 +- .../HardwareWallet/ConnectHardware.tsx | 62 +++++++++---------- 2 files changed, 31 insertions(+), 34 deletions(-) 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', + }), + }); } }); },