From aefaeee33dbf21aedff6be48253405d35e635555 Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Tue, 12 Jul 2022 00:40:40 -0700 Subject: [PATCH] Fix: ble upgrade OK-10716 OK-10723 (#1078) * 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 --- packages/kit/package.json | 6 +- .../kit/src/components/Protected/index.tsx | 10 ++- packages/kit/src/hooks/useEnsureConnected.ts | 7 +- packages/kit/src/utils/hardware/errors.ts | 2 + .../Account/AddNewAccount/RecoverAccounts.tsx | 34 ++++++-- .../Hardware/Onekey/OnekeyHardwareDetails.tsx | 12 ++- .../src/views/Hardware/PopupHandle/index.tsx | 2 + .../UpdateFirmware/Updating/StateView.tsx | 12 ++- .../UpdateFirmware/Updating/index.tsx | 30 +++++-- packages/kit/src/views/ReceiveToken/index.tsx | 27 +++++-- yarn.lock | 80 +++++++++---------- 11 files changed, 146 insertions(+), 76 deletions(-) diff --git a/packages/kit/package.json b/packages/kit/package.json index 3382c2d81d4..eba4c55b082 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -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", diff --git a/packages/kit/src/components/Protected/index.tsx b/packages/kit/src/components/Protected/index.tsx index 21a4845444d..2346001801d 100644 --- a/packages/kit/src/components/Protected/index.tsx +++ b/packages/kit/src/components/Protected/index.tsx @@ -27,6 +27,7 @@ import Validation from './Validation'; type ProtectedOptions = { isLocalAuthentication?: boolean; withEnableAuthentication?: boolean; + deviceFeatures?: IOneKeyDeviceFeatures; }; type ProtectedProps = { @@ -47,7 +48,7 @@ const Protected: FC = ({ const walletDetail = useGetWalletDetail(walletId); const intl = useIntl(); const { engine, serviceHardware } = backgroundApiProxy; - const [deviceCheckSuccess, setDeviceCheckSuccess] = useState(false); + const [deviceFeatures, setDeviceFeatures] = useState(); const [password, setPassword] = useState(''); const [withEnableAuthentication, setWithEnableAuthentication] = useState(); @@ -167,7 +168,9 @@ const Protected: FC = ({ safeGoBack(); return; } - setDeviceCheckSuccess(true); + + // device connect success + setDeviceFeatures(features); } loadDevices(); }, [isHardware, engine, walletDetail?.id, intl, safeGoBack, serviceHardware]); @@ -198,12 +201,13 @@ const Protected: FC = ({ } if (isHardware) { - if (deviceCheckSuccess) { + if (deviceFeatures) { return ( {children(password, { withEnableAuthentication, isLocalAuthentication, + deviceFeatures, })} ); diff --git a/packages/kit/src/hooks/useEnsureConnected.ts b/packages/kit/src/hooks/useEnsureConnected.ts index 361b0458b40..ad2e2c4691e 100644 --- a/packages/kit/src/hooks/useEnsureConnected.ts +++ b/packages/kit/src/hooks/useEnsureConnected.ts @@ -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'; @@ -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); diff --git a/packages/kit/src/utils/hardware/errors.ts b/packages/kit/src/utils/hardware/errors.ts index e06119addea..c99d76c2383 100644 --- a/packages/kit/src/utils/hardware/errors.ts +++ b/packages/kit/src/utils/hardware/errors.ts @@ -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 { diff --git a/packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx b/packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx index 81d6969246d..cc2c082fdaa 100644 --- a/packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx +++ b/packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx @@ -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'; @@ -23,6 +24,7 @@ import { Typography, useToast, } from '@onekeyhq/components'; +import { OneKeyErrorClassNames } from '@onekeyhq/engine/src/errors'; import type { Account, ImportableHDAccount, @@ -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; @@ -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?.(); }); diff --git a/packages/kit/src/views/Hardware/Onekey/OnekeyHardwareDetails.tsx b/packages/kit/src/views/Hardware/Onekey/OnekeyHardwareDetails.tsx index 350deba10a0..1bef7f70893 100644 --- a/packages/kit/src/views/Hardware/Onekey/OnekeyHardwareDetails.tsx +++ b/packages/kit/src/views/Hardware/Onekey/OnekeyHardwareDetails.tsx @@ -31,17 +31,18 @@ type RouteProps = RouteProp< type OnekeyHardwareDetailsModalProps = { walletId: string; + deviceFeatures?: IOneKeyDeviceFeatures; }; const OnekeyHardwareDetails: FC = ({ walletId, + deviceFeatures, }) => { const intl = useIntl(); const navigation = useNavigation(); const { engine, serviceHardware } = backgroundApiProxy; const { deviceUpdates } = useSettings() || {}; - const [deviceFeatures, setDeviceFeatures] = useState(); const [deviceConnectId, setDeviceConnectId] = useState(); const updates = useMemo( @@ -53,9 +54,7 @@ const OnekeyHardwareDetails: FC = ({ (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(); @@ -174,7 +173,12 @@ const OnekeyHardwareDetailsModal: FC = () => { scrollViewProps={{ children: ( - {() => } + {(_, { deviceFeatures }) => ( + + )} ), }} diff --git a/packages/kit/src/views/Hardware/PopupHandle/index.tsx b/packages/kit/src/views/Hardware/PopupHandle/index.tsx index 8f96a7c8e34..11435d0ebeb 100644 --- a/packages/kit/src/views/Hardware/PopupHandle/index.tsx +++ b/packages/kit/src/views/Hardware/PopupHandle/index.tsx @@ -122,6 +122,8 @@ const HardwarePopup: FC = () => { uiRequestMemo, ]); + if (!popupView) return null; + return ( = ({ stateInfo }) => { } break; + case 'common_error': + stateContent = { + emoji: '😞', + title: intl.formatMessage({ + id: 'msg__unknown_error', + }), + }; + break; + default: stateContent = { emoji: '💀', diff --git a/packages/kit/src/views/Hardware/UpdateFirmware/Updating/index.tsx b/packages/kit/src/views/Hardware/UpdateFirmware/Updating/index.tsx index 5f7a3a61169..6f5f7980746 100644 --- a/packages/kit/src/views/Hardware/UpdateFirmware/Updating/index.tsx +++ b/packages/kit/src/views/Hardware/UpdateFirmware/Updating/index.tsx @@ -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'); }; diff --git a/packages/kit/src/views/ReceiveToken/index.tsx b/packages/kit/src/views/ReceiveToken/index.tsx index 8793ac20a34..fd80d0fe09e 100644 --- a/packages/kit/src/views/ReceiveToken/index.tsx +++ b/packages/kit/src/views/ReceiveToken/index.tsx @@ -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'; @@ -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]); diff --git a/yarn.lock b/yarn.lock index 638ca9dcdea..cd9280dd1f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3484,69 +3484,69 @@ "@onekeyfe/cross-inpage-provider-core" "^0.0.10" "@onekeyfe/cross-inpage-provider-types" "^0.0.10" -"@onekeyfe/hd-ble-sdk@0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-ble-sdk/-/hd-ble-sdk-0.1.9.tgz#ff253fb97d4b585dd3d1e22014a81d6febffe7b2" - integrity sha512-EZpl4Cd/0KxTUagL3x8Q3WSZcBvBM1DHdgJ8PjVjRRLGXCPtjwrmHil2S0XK1EcqrfoYWMuUSjuWmSE7BGJP1Q== +"@onekeyfe/hd-ble-sdk@0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-ble-sdk/-/hd-ble-sdk-0.1.10.tgz#25e4bcc455b31547c352ebe7df353564599ed52b" + integrity sha512-5Xrx5B8QSMUkI1Z2rODBjhwf9L0nS+lQ86fFmbYMwDjTrjzmxqJVxK6/dA5lDqatFnQe8LKRE2FPuM6C8kMP0g== dependencies: - "@onekeyfe/hd-core" "^0.1.9" - "@onekeyfe/hd-shared" "^0.1.9" - "@onekeyfe/hd-transport-react-native" "^0.1.9" + "@onekeyfe/hd-core" "^0.1.10" + "@onekeyfe/hd-shared" "^0.1.10" + "@onekeyfe/hd-transport-react-native" "^0.1.10" -"@onekeyfe/hd-core@0.1.9", "@onekeyfe/hd-core@^0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-core/-/hd-core-0.1.9.tgz#d074f15fc267b043186263a14b2774900a7ddea2" - integrity sha512-uSjaXgvCdXYKskm/lXMBQZR65zIQhCrJP18S5NPJwZg8pwj2rYf+qF27r9zaeDLuQp/hHa61opwjDHKeeNfcdQ== +"@onekeyfe/hd-core@0.1.10", "@onekeyfe/hd-core@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-core/-/hd-core-0.1.10.tgz#8d4d66e78b6a392d3bd72829b8bca440e3cdcbad" + integrity sha512-dnxV1ydK+RcR1Hd+KEOP71TJcjlpr3MER89VdA3aRSxFDpw7bbEcfLPtAOQnw2ufcn0GuWe3OZrLlseKdWX2BA== dependencies: - "@onekeyfe/hd-shared" "^0.1.9" - "@onekeyfe/hd-transport" "^0.1.9" + "@onekeyfe/hd-shared" "^0.1.10" + "@onekeyfe/hd-transport" "^0.1.10" axios "^0.27.2" bignumber.js "^9.0.2" parse-uri "^1.0.7" semver "^7.3.7" -"@onekeyfe/hd-shared@^0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-shared/-/hd-shared-0.1.9.tgz#dc9e3522c16e7b7fdc6ead438347d99c4d60b434" - integrity sha512-+s1eSLHmez4Ue2exclzAIiY1epuJr4p4l6TSF2AI2SOfzqcwfZ/TfDmgN/CA/3R4NE2sSMT6EelQcHthdfmoaA== +"@onekeyfe/hd-shared@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-shared/-/hd-shared-0.1.10.tgz#d90b1c88273a7f9b57a577a5eb26faff64c67ca6" + integrity sha512-ilxj0oMo5oWgB4HCXT31EzELXpl6SKHDQaeTCXo0u0rMzokDAa84oVjSbWFup9YGUQVNgQiuVn7y2Pn0KbhU0g== -"@onekeyfe/hd-transport-http@^0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport-http/-/hd-transport-http-0.1.9.tgz#5b8b81b981a976d0b4a9a395bc16a0b5de249d4f" - integrity sha512-ao9mvGWtFCL0WzbO1FlzrtzUPvPylXkbdOYkI8SpZglGWFM8H20VVtFs2Voj1ebccC2edHZLmOGusAv1N6FifA== +"@onekeyfe/hd-transport-http@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport-http/-/hd-transport-http-0.1.10.tgz#fe57a69054c1b2b5eb9a2a6ada5cd0163ba001df" + integrity sha512-Sz6MBuTt8xaxD9S9t7QzbVOsAKE8zfSj+ItIg0yaOwNTAcWG/fn3+kTo7Y8h8R7WXlXRkO5oH4E6ts1vAetSXQ== dependencies: - "@onekeyfe/hd-shared" "^0.1.9" - "@onekeyfe/hd-transport" "^0.1.9" + "@onekeyfe/hd-shared" "^0.1.10" + "@onekeyfe/hd-transport" "^0.1.10" axios "^0.27.2" -"@onekeyfe/hd-transport-react-native@^0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport-react-native/-/hd-transport-react-native-0.1.9.tgz#73fa4870094727daf3fd71b05ec0ce0eca8dfb03" - integrity sha512-7KfTIxQidY/qCBcGT6T0/72Oezm4iYdm2OX7HVKV4UaAaq8PQqCwk6C3A9CkXGLs8xguiNQ1JcZB2O9Pg55dXQ== +"@onekeyfe/hd-transport-react-native@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport-react-native/-/hd-transport-react-native-0.1.10.tgz#a71efd6dd4505a6d5c7d8b6c0270b8b54b96bce5" + integrity sha512-u78qWeTZVefv8MkDcxK+rblkRA2KoQ6lIMrwo88+jnyiR88adgsXlJabuHSVdMiBvHpI8RhTkUA85+u6MyADTA== dependencies: - "@onekeyfe/hd-shared" "^0.1.9" - "@onekeyfe/hd-transport" "^0.1.9" + "@onekeyfe/hd-shared" "^0.1.10" + "@onekeyfe/hd-transport" "^0.1.10" react-native-ble-manager "^8.1.0" react-native-ble-plx "^2.0.3" -"@onekeyfe/hd-transport@^0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport/-/hd-transport-0.1.9.tgz#e8c352e97f79b1912d3bb068fb955a6369fce4cf" - integrity sha512-3+Cwd1p6kBfdeDSjdoi0uFPu/xMwC2+rFC8LW9+c0E8CdAeep5LRI/g7663/OOqzd7b/QT4Q8UlJLQ5xv1sq3w== +"@onekeyfe/hd-transport@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-transport/-/hd-transport-0.1.10.tgz#51302415ed589b8a57f984934b06136fcb5b2c08" + integrity sha512-EsGx9glSDH4fBsg+Op1zGzEoHKRWOLgX4LgVQR9JuspfHJQBO5SVV9pCspgfjrsffdUE8PAU1c4drkhqZuauPg== dependencies: bytebuffer "^5.0.1" long "^4.0.0" protobufjs "^6.11.2" -"@onekeyfe/hd-web-sdk@0.1.9": - version "0.1.9" - resolved "https://registry.yarnpkg.com/@onekeyfe/hd-web-sdk/-/hd-web-sdk-0.1.9.tgz#39d1b8c9a6bd77685c286cd074391951bf2b02b9" - integrity sha512-w4mZX7P6pXs5uqnOWC9TtZLC64784a6X/TZTBbEkiu7dljMCKdQgQxu2uR/7ExPUAFO1ljl5sqNQOzgQ+nOvsA== +"@onekeyfe/hd-web-sdk@0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@onekeyfe/hd-web-sdk/-/hd-web-sdk-0.1.10.tgz#9dfbd2dbc33563fba62a31eead9ddd38923f9c18" + integrity sha512-e1ZwyHalOyYVVYJT9NM1cynLHY+whKQUa5Oh7rlKeEji8H1kQ7V3zijEOIJmJTGrjrU+8IFZhTvchjL3eMZUNQ== dependencies: "@onekeyfe/cross-inpage-provider-core" "^0.0.14" - "@onekeyfe/hd-core" "^0.1.9" - "@onekeyfe/hd-shared" "^0.1.9" - "@onekeyfe/hd-transport-http" "^0.1.9" + "@onekeyfe/hd-core" "^0.1.10" + "@onekeyfe/hd-shared" "^0.1.10" + "@onekeyfe/hd-transport-http" "^0.1.10" "@onekeyfe/inpage-providers-hub@^0.0.10": version "0.0.10"