Skip to content

Commit

Permalink
Fix: ble upgrade OK-10716 OK-10723 (#1078)
Browse files Browse the repository at this point in the history
* chore: Optimize the display of device details

* chore: Optimized error messages for confirm address

* feat: Display upgrade more error messages

* feat: update hardware sdk to v0.1.10

* chore: Optimize HardwarePopup

* fix: merge error
  • Loading branch information
ByteZhang1024 authored Jul 12, 2022
1 parent 4bf98a1 commit aefaeee
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 76 deletions.
6 changes: 3 additions & 3 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"dependencies": {
"@cloudinary/url-gen": "^1.8.0",
"@gorhom/bottom-sheet": "^4",
"@onekeyfe/hd-ble-sdk": "0.1.9",
"@onekeyfe/hd-core": "0.1.9",
"@onekeyfe/hd-web-sdk": "0.1.9",
"@onekeyfe/hd-ble-sdk": "0.1.10",
"@onekeyfe/hd-core": "0.1.10",
"@onekeyfe/hd-web-sdk": "0.1.10",
"@onekeyhq/components": "*",
"@reduxjs/toolkit": "^1.6.2",
"@types/redux-logger": "^3.0.9",
Expand Down
10 changes: 7 additions & 3 deletions packages/kit/src/components/Protected/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Validation from './Validation';
type ProtectedOptions = {
isLocalAuthentication?: boolean;
withEnableAuthentication?: boolean;
deviceFeatures?: IOneKeyDeviceFeatures;
};

type ProtectedProps = {
Expand All @@ -47,7 +48,7 @@ const Protected: FC<ProtectedProps> = ({
const walletDetail = useGetWalletDetail(walletId);
const intl = useIntl();
const { engine, serviceHardware } = backgroundApiProxy;
const [deviceCheckSuccess, setDeviceCheckSuccess] = useState(false);
const [deviceFeatures, setDeviceFeatures] = useState<IOneKeyDeviceFeatures>();
const [password, setPassword] = useState('');
const [withEnableAuthentication, setWithEnableAuthentication] =
useState<boolean>();
Expand Down Expand Up @@ -167,7 +168,9 @@ const Protected: FC<ProtectedProps> = ({
safeGoBack();
return;
}
setDeviceCheckSuccess(true);

// device connect success
setDeviceFeatures(features);
}
loadDevices();
}, [isHardware, engine, walletDetail?.id, intl, safeGoBack, serviceHardware]);
Expand Down Expand Up @@ -198,12 +201,13 @@ const Protected: FC<ProtectedProps> = ({
}

if (isHardware) {
if (deviceCheckSuccess) {
if (deviceFeatures) {
return (
<Box w="full" h="full">
{children(password, {
withEnableAuthentication,
isLocalAuthentication,
deviceFeatures,
})}
</Box>
);
Expand Down
7 changes: 4 additions & 3 deletions packages/kit/src/hooks/useEnsureConnected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCallback, useState } from 'react';
import { useIntl } from 'react-intl';

import { ToastManager } from '@onekeyhq/components';
import { OneKeyHardwareAbortError } from '@onekeyhq/engine/src/errors';
import { OneKeyErrorClassNames } from '@onekeyhq/engine/src/errors';
import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy';
import { getDeviceUUID } from '@onekeyhq/kit/src/utils/hardware';
import { IOneKeyDeviceFeatures } from '@onekeyhq/shared/types';
Expand Down Expand Up @@ -47,8 +47,9 @@ export function useEnsureConnected(params?: IUseEnsureConnected) {
let features: IOneKeyDeviceFeatures | null = null;
try {
features = await serviceHardware.ensureConnected(device.mac);
} catch (e) {
if (!(e instanceof OneKeyHardwareAbortError)) {
} catch (e: any) {
const { className } = e || {};
if (!(className === OneKeyErrorClassNames.OneKeyAbortError)) {
showMessage();
}
setLoading(false);
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/utils/hardware/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class UserCancel extends OneKeyHardwareError {

export class UserCancelFromOutside extends OneKeyHardwareError {
override code = HardwareErrorCode.DeviceInterruptedFromOutside;

override key: LocaleIds = 'msg__hardware_user_cancel_error';
}

export class UnknownMethod extends OneKeyHardwareError {
Expand Down
34 changes: 27 additions & 7 deletions packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
useState,
} from 'react';

import { HardwareErrorCode } from '@onekeyfe/hd-shared';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { useIntl } from 'react-intl';
import { ListRenderItem } from 'react-native';
Expand All @@ -23,6 +24,7 @@ import {
Typography,
useToast,
} from '@onekeyhq/components';
import { OneKeyErrorClassNames } from '@onekeyhq/engine/src/errors';
import type {
Account,
ImportableHDAccount,
Expand All @@ -35,7 +37,6 @@ import {
CreateAccountRoutesParams,
} from '@onekeyhq/kit/src/routes';
import { ModalScreenProps } from '@onekeyhq/kit/src/routes/types';
import { UserCancelFromOutside } from '@onekeyhq/kit/src/utils/hardware/errors';

type NavigationProps = ModalScreenProps<CreateAccountRoutesParams>;

Expand Down Expand Up @@ -151,15 +152,34 @@ const RecoverAccounts: FC = () => {
}),
]);
})
.catch((e) => {
if (e instanceof UserCancelFromOutside) {
.catch((e: any) => {
const { className, key, code, message } = e || {};
if (code === HardwareErrorCode.DeviceInterruptedFromOutside) {
return;
}

isFetchingData.current = false;
ToastManager.show({
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
title: intl.formatMessage({ id: e?.message ?? '' }),
});

if (className === OneKeyErrorClassNames.OneKeyHardwareError) {
ToastManager.show(
{
title: intl.formatMessage({ id: key }),
},
{
type: 'error',
},
);
} else {
ToastManager.show(
{
title: message,
},
{
type: 'default',
},
);
}

navigation?.goBack?.();
navigation?.goBack?.();
});
Expand Down
12 changes: 8 additions & 4 deletions packages/kit/src/views/Hardware/Onekey/OnekeyHardwareDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ type RouteProps = RouteProp<

type OnekeyHardwareDetailsModalProps = {
walletId: string;
deviceFeatures?: IOneKeyDeviceFeatures;
};

const OnekeyHardwareDetails: FC<OnekeyHardwareDetailsModalProps> = ({
walletId,
deviceFeatures,
}) => {
const intl = useIntl();
const navigation = useNavigation();
const { engine, serviceHardware } = backgroundApiProxy;
const { deviceUpdates } = useSettings() || {};

const [deviceFeatures, setDeviceFeatures] = useState<IOneKeyDeviceFeatures>();
const [deviceConnectId, setDeviceConnectId] = useState<string>();

const updates = useMemo(
Expand All @@ -53,9 +54,7 @@ const OnekeyHardwareDetails: FC<OnekeyHardwareDetailsModalProps> = ({
(async () => {
try {
const device = await engine.getHWDeviceByWalletId(walletId);
const features = await serviceHardware.getFeatures(device?.mac ?? '');
setDeviceConnectId(device?.mac);
setDeviceFeatures(features ?? undefined);
} catch (err: any) {
if (navigation.canGoBack()) {
navigation.goBack();
Expand Down Expand Up @@ -174,7 +173,12 @@ const OnekeyHardwareDetailsModal: FC = () => {
scrollViewProps={{
children: (
<Protected walletId={walletId}>
{() => <OnekeyHardwareDetails walletId={walletId} />}
{(_, { deviceFeatures }) => (
<OnekeyHardwareDetails
walletId={walletId}
deviceFeatures={deviceFeatures}
/>
)}
</Protected>
),
}}
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/views/Hardware/PopupHandle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const HardwarePopup: FC<HardwarePopupProps> = () => {
uiRequestMemo,
]);

if (!popupView) return null;

return (
<Modal
backdropColor="overlay"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export type StateViewType =
| 'success'
| 'bluetooth-turned-off'
| 'manually-enter-bootloader-one'
| 'manually-enter-bootloader-two';
| 'manually-enter-bootloader-two'
| 'common_error';

type StateContent = {
emoji?: string;
Expand Down Expand Up @@ -198,6 +199,15 @@ const StateView: FC<StateViewProps> = ({ stateInfo }) => {
}
break;

case 'common_error':
stateContent = {
emoji: '😞',
title: intl.formatMessage({
id: 'msg__unknown_error',
}),
};
break;

default:
stateContent = {
emoji: '💀',
Expand Down
30 changes: 23 additions & 7 deletions packages/kit/src/views/Hardware/UpdateFirmware/Updating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,37 @@ const UpdatingModal: FC = () => {
setStateViewInfo({ type: 'install-failure' });
} else if (currentStep === 'reboot-bootloader') {
setStateViewInfo({ type: 'reboot-bootloader-failure' });
}

if (className === 'OneKeyHardwareError') {
ToastManager.show(
{
} else if (className === 'OneKeyHardwareError') {
setStateViewInfo({
type: 'common_error',
content: {
title: intl.formatMessage({
// @ts-expect-error
id: key,
defaultMessage: error.message,
}),
},
{ type: 'error' },
);
});
} else {
// other error
setStateViewInfo({
type: 'common_error',
content: {
title: `「${code}${error.message}`,
},
});
}

ToastManager.show(
{
title: intl.formatMessage({
// @ts-expect-error
id: key,
}),
},
{ type: 'error' },
);

setProgressState('failure');
};

Expand Down
27 changes: 19 additions & 8 deletions packages/kit/src/views/ReceiveToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@onekeyhq/components';
import { shortenAddress } from '@onekeyhq/components/src/utils';
import { copyToClipboard } from '@onekeyhq/components/src/utils/ClipboardUtils';
import { OneKeyErrorClassNames } from '@onekeyhq/engine/src/errors';
import IconAccount from '@onekeyhq/kit/assets/3d_account.png';
import BlurQRCode from '@onekeyhq/kit/assets/blur-qrcode.png';
import qrcodeLogo from '@onekeyhq/kit/assets/qrcode_logo.png';
Expand Down Expand Up @@ -74,17 +75,27 @@ const ReceiveToken = () => {
setIsLoadingForHardware(true);
getAddress()
.then((res) => setOnHardwareConfirmed(res === shownAddress))
.catch((e: Error) => {
ToastManager.show(
{
title: e.message,
},
{ type: 'default' },
);
.catch((e: any) => {
const { className, key, message } = e;
if (className === OneKeyErrorClassNames.OneKeyHardwareError) {
ToastManager.show(
{
title: intl.formatMessage({ id: key }),
},
{ type: 'error' },
);
} else {
ToastManager.show(
{
title: message,
},
{ type: 'default' },
);
}
})
.finally(() => setIsLoadingForHardware(false));
}
}, [confirmConnected, getAddress, shownAddress]);
}, [confirmConnected, getAddress, intl, shownAddress]);

useEffect(() => () => abortConnect(), [abortConnect]);

Expand Down
Loading

0 comments on commit aefaeee

Please sign in to comment.