Skip to content

Commit

Permalink
fix: check bonded android device & android search device failed OK-10…
Browse files Browse the repository at this point in the history
…405 OK-10408 (#1008)

* fix: check bonded android device

* fix: android search device interval

Co-authored-by: ll__ <[email protected]>
  • Loading branch information
originalix and loatheb authored Jun 30, 2022
1 parent 8849588 commit ff58a83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
3 changes: 2 additions & 1 deletion packages/kit/src/utils/hardware/deviceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class DeviceUtils {
};

this.scanning = true;
poll();
const time = platformEnv.isNativeAndroid ? 2000 : POLL_INTERVAL;
poll(time);
}

stopScan() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
}),
});
}
});
},
Expand Down

0 comments on commit ff58a83

Please sign in to comment.