Skip to content

Commit

Permalink
OK-19750, OK-19769: add params for scan qrcode validate & add connect…
Browse files Browse the repository at this point in the history
…Id for Bluetooth connect (#2943)

* fix: enable imported account for Cardano

* feat: add usedfor params for scan qrcode

* fix: add connectId for bluetooth connect

* feat: skipHeavyChains
  • Loading branch information
originalix authored May 6, 2023
1 parent e8f9d9e commit 71073f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
9 changes: 6 additions & 3 deletions packages/engine/src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isString } from 'lodash';
import type { Network } from '@onekeyhq/kit/src/store/typings';
import { backgroundMethod } from '@onekeyhq/shared/src/background/backgroundDecorators';
import {
IMPL_ADA,
IMPL_COSMOS,
IMPL_DOT,
IMPL_XMR,
Expand All @@ -28,7 +27,7 @@ const FEE_LIMIT_HIGH_VALUE_TIMES = 20;
const FEE_PRICE_HIGH_VALUE_TIMES = 4;

const FORK_CHAIN_ADDRESS_NOT_DIFFERENT = [IMPL_COSMOS, IMPL_DOT];
const WEBVIEW_BACKED_CHAIN = platformEnv.isNative ? [IMPL_ADA, IMPL_XMR] : [];
const WEBVIEW_BACKED_CHAIN = platformEnv.isNative ? [IMPL_XMR] : [];

class Validators {
private _dbApi: DBAPI;
Expand Down Expand Up @@ -106,6 +105,7 @@ class Validators {
input: string,
forCategories: Array<UserInputCategory> = [],
returnEarly = false,
skipHeavyChains = false,
): Promise<Array<UserInputCheckResult>> {
const ret = [];
const filterCategories =
Expand Down Expand Up @@ -139,7 +139,7 @@ class Validators {
for (const [impl, networks] of Object.entries(
await this.engine.listEnabledNetworksGroupedByVault(),
)) {
if (WEBVIEW_BACKED_CHAIN.includes(impl)) {
if (skipHeavyChains && WEBVIEW_BACKED_CHAIN.includes(impl)) {
// skip webview backed chain
// eslint-disable-next-line no-continue
continue;
Expand Down Expand Up @@ -181,15 +181,18 @@ class Validators {
input,
onlyFor,
returnEarly,
skipHeavyChains,
}: {
input: string;
onlyFor?: UserInputCategory;
returnEarly?: boolean;
skipHeavyChains?: boolean;
}) {
return this.validateUserInput(
input,
onlyFor !== undefined ? [onlyFor] : [],
returnEarly,
skipHeavyChains,
);
}

Expand Down
34 changes: 21 additions & 13 deletions packages/kit-bg/src/services/ServiceHardware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,15 @@ class ServiceHardware extends ServiceBase {
const version = settings.deviceUpdates?.[connectId][firmwareType]?.version;

try {
const response = await hardwareSDK.firmwareUpdateV2(undefined, {
updateType: firmwareType,
forcedUpdateRes,
version,
platform: platformEnv.symbol ?? 'web',
});
const response = await hardwareSDK.firmwareUpdateV2(
platformEnv.isNative ? connectId : undefined,
{
updateType: firmwareType,
forcedUpdateRes,
version,
platform: platformEnv.symbol ?? 'web',
},
);

// update bootloader
if (
Expand Down Expand Up @@ -850,7 +853,9 @@ class ServiceHardware extends ServiceBase {
) {
const hardwareSDK = await this.getSDKInstance();
return hardwareSDK
?.checkBootloaderRelease(undefined, { willUpdateFirmwareVersion })
?.checkBootloaderRelease(platformEnv.isNative ? connectId : undefined, {
willUpdateFirmwareVersion,
})
.then((response) => {
if (!response.success) {
return Promise.reject(
Expand All @@ -862,7 +867,7 @@ class ServiceHardware extends ServiceBase {
}

@backgroundMethod()
async updateBootloaderForClassicAndMini() {
async updateBootloaderForClassicAndMini(connectId: string) {
const { dispatch } = this.backgroundApi;
dispatch(setUpdateFirmwareStep(''));
const hardwareSDK = await this.getSDKInstance();
Expand All @@ -871,11 +876,14 @@ class ServiceHardware extends ServiceBase {
};
hardwareSDK.on('ui-firmware-tip', listener);
try {
const response = await hardwareSDK.firmwareUpdateV2(undefined, {
updateType: 'firmware',
platform: platformEnv.symbol ?? 'web',
isUpdateBootloader: true,
});
const response = await hardwareSDK.firmwareUpdateV2(
platformEnv.isNative ? connectId : undefined,
{
updateType: 'firmware',
platform: platformEnv.symbol ?? 'web',
isUpdateBootloader: true,
},
);
return response;
} finally {
hardwareSDK.off('ui-firmware-tip', listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const UpdatingBootloader: FC = () => {
return;
}
serviceHardware
.updateBootloaderForClassicAndMini()
.updateBootloaderForClassicAndMini(connectId)
.then(async (res) => {
if (res.success) {
engine.getWalletByDeviceId(device?.id ?? '').then((wallet) => {
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/views/ScanQrcode/ScanQrcodeResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const ScanQrcodeResult: FC = () => {
.validateCreateInput({
input: data,
returnEarly: true,
skipHeavyChains: true,
})
.then(([result]) => {
if (result) {
Expand Down

0 comments on commit 71073f7

Please sign in to comment.