Skip to content

Commit c0af43e

Browse files
committed
fix: test/api use onekey branch api
1 parent 68ae7cf commit c0af43e

27 files changed

+216
-46028
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"dev:common": "cd ./packages/hd-common-connect-sdk && yarn dev",
4141
"dev:core": "cd ./packages/core && yarn dev",
4242
"dev:transport": "cd ./packages/hd-transport && yarn dev",
43-
"dev:transport-http": "cd ./packages/hd-transport-web && yarn dev",
43+
"dev:transport-http": "cd ./packages/hd-transport-http && yarn dev",
4444
"dev:transport-rn": "cd ./packages/hd-transport-react-native && yarn dev",
4545
"dev:transport-lowlevel": "cd ./packages/hd-transport-lowlevel && yarn dev",
4646
"dev:transport-webusb": "cd ./packages/hd-transport-webusb && yarn dev",

packages/connect-examples/expo-example/src/components/DeviceList.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ function DeviceListFC(
123123
selectDevice(undefined);
124124
if (!sdk) return alert(intl.formatMessage({ id: 'tip__sdk_not_ready' }));
125125

126-
let response;
127-
const env = 'webusb';
128-
if (env === 'webusb') {
129-
const promptResponse = await sdk.promptWebDeviceAccess();
130-
console.log('promptResponse:====>>>::: ', promptResponse);
131-
response = promptResponse.success
132-
? { payload: [promptResponse.payload.device] }
133-
: { payload: [] };
134-
} else {
135-
response = await sdk.searchDevices();
136-
}
126+
// let response;
127+
// const env = 'webusb';
128+
// if (env === 'webusb') {
129+
// const promptResponse = await sdk.promptWebDeviceAccess();
130+
// console.log('promptResponse:====>>>::: ', promptResponse);
131+
// response = promptResponse.success
132+
// ? { payload: [promptResponse.payload.device] }
133+
// : { payload: [] };
134+
// } else {
135+
const response = await sdk.searchDevices();
136+
// }
137137
const foundDevices = (response.payload as unknown as Device[]) ?? [];
138138
setDevices(foundDevices);
139139
if (Platform.OS === 'web' && foundDevices?.length) {

packages/connect-examples/expo-example/src/utils/hardwareInstance.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import memoizee from 'memoizee';
22
import { Platform } from 'react-native';
33
import { ConnectSettings, CoreApi, LowLevelCoreApi } from '@onekeyfe/hd-core';
4-
import { importSdk } from './importSdk';
4+
import { importSdk, importLowLevelSDK } from './importSdk';
55
import { CONNECT_SRC } from '../constants/connect';
66

77
// eslint-disable-next-line import/no-mutable-exports
@@ -32,17 +32,20 @@ export const getHardwareSDKInstance = memoizee(
3232
fetchConfig: true,
3333
};
3434

35-
HardwareSDK = await importSdk({
36-
useCommonSdk: true,
37-
});
35+
// HardwareSDK = await importSdk({
36+
// useCommonSdk: true,
37+
// });
38+
HardwareSDK = await importSdk();
39+
3840
// HardwareSDK = await importTopLevelSdk();
3941
console.log(HardwareSDK);
4042

4143
if (Platform.OS === 'web') {
4244
settings.connectSrc = CONNECT_SRC;
43-
settings.env = 'webusb';
45+
// settings.env = 'webusb';
46+
settings.env = 'web';
4447
settings.preRelease = true;
45-
// HardwareLowLevelSDK = await importLowLevelSDK();
48+
HardwareLowLevelSDK = await importLowLevelSDK();
4649

4750
// Override Connect src
4851
// @ts-expect-error
@@ -58,7 +61,6 @@ export const getHardwareSDKInstance = memoizee(
5861
console.log('HardwareSDK initialized success');
5962
initialized = true;
6063

61-
// @ts-expect-error
6264
resolve({ HardwareSDK, HardwareLowLevelSDK, useLowLevelApi });
6365
} catch (e) {
6466
reject(e);

packages/connect-examples/expo-example/src/utils/importSdk/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ interface ISdkImportOptions {
44
useCommonSdk?: boolean;
55
}
66

7-
export const importSdk = async (options: ISdkImportOptions) => {
8-
if (options.useCommonSdk) {
7+
export const importSdk = async (options?: ISdkImportOptions) => {
8+
if (options?.useCommonSdk) {
99
return (await import('@onekeyfe/hd-common-connect-sdk')).default as unknown as CoreApi;
1010
}
1111
return (await import('@onekeyfe/hd-web-sdk')).default.HardwareWebSdk as unknown as CoreApi;
1212
};
1313

14-
export const importTopLevelSdk = async (options: ISdkImportOptions) => {
15-
if (options.useCommonSdk) {
14+
export const importTopLevelSdk = async (options?: ISdkImportOptions) => {
15+
if (options?.useCommonSdk) {
1616
return (await import('@onekeyfe/hd-common-connect-sdk')).default as unknown as CoreApi;
1717
}
1818
return (await import('@onekeyfe/hd-web-sdk')).default.HardwareSDKTopLevel as unknown as CoreApi;

packages/core/src/api/FirmwareUpdate.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,7 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
142142
// auto go to bootloader mode
143143
try {
144144
this.postTipMessage('AutoRebootToBootloader');
145-
let bootRes;
146-
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
147-
// @ts-expect-error
148-
bootRes = await commands.typedCall('BixinReboot', 'Success');
149-
} else {
150-
bootRes = await commands.typedCall('DeviceBackToBoot', 'Success');
151-
}
145+
const bootRes = await commands.typedCall('DeviceBackToBoot', 'Success');
152146
// @ts-expect-error
153147
if (bootRes.type === 'CallMethodError') {
154148
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);

packages/core/src/api/FirmwareUpdateV2.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
245245
// auto go to bootloader mode
246246
try {
247247
this.postTipMessage('AutoRebootToBootloader');
248-
let bootRes;
249-
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
250-
// @ts-expect-error
251-
bootRes = await commands.typedCall('BixinReboot', 'Success');
252-
} else {
253-
bootRes = await commands.typedCall('DeviceBackToBoot', 'Success');
254-
}
255-
248+
const bootRes = await commands.typedCall('DeviceBackToBoot', 'Success');
256249
// @ts-expect-error
257250
if (bootRes.type === 'CallMethodError') {
258251
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);

packages/core/src/api/device/DeviceRebootToBoardloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
2222
async run() {
2323
// On Touch devices, messsage code 904 is RebootToBoardloader
2424
// so BininOutMessageSE message code 904 is used here
25-
const res = await this.device.commands.typedCall('RebootToBoardloader', 'Success');
25+
const res = await this.device.commands.typedCall('BixinOutMessageSE', 'Success');
2626

2727
return Promise.resolve(res.message);
2828
}

packages/core/src/api/device/DeviceRebootToBootloader.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
88
this.skipForceUpdateCheck = true;
99
}
1010

11+
getVersionRange() {
12+
return {
13+
classic: {
14+
min: '2.1.11',
15+
},
16+
mini: {
17+
min: '2.1.11',
18+
},
19+
};
20+
}
21+
1122
async run() {
1223
const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
1324

packages/core/src/api/device/DeviceUpdateReboot.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { DeviceBackToBoot } from '@onekeyfe/hd-transport';
22
import { BaseMethod } from '../BaseMethod';
3-
import { DeviceModelToTypes } from '../../types';
4-
import { getDeviceType } from '../../utils';
53

64
// Upload hint Reboot BootLoader
75
export default class DeviceUpdateReboot extends BaseMethod<DeviceBackToBoot> {
@@ -11,14 +9,7 @@ export default class DeviceUpdateReboot extends BaseMethod<DeviceBackToBoot> {
119
}
1210

1311
async run() {
14-
const deviceType = getDeviceType(this.device.features);
15-
let res;
16-
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
17-
// @ts-expect-error
18-
res = await this.device.commands.typedCall('BixinReboot', 'Success');
19-
} else {
20-
res = await this.device.commands.typedCall('DeviceBackToBoot', 'Success');
21-
}
12+
const res = await this.device.commands.typedCall('DeviceBackToBoot', 'Success');
2213

2314
return Promise.resolve(res.message);
2415
}

packages/core/src/api/device/DeviceVerify.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import { validateParams, validateResult } from '../helpers/paramsValidator';
88
import { getDeviceType } from '../../utils';
99
import { DeviceModelToTypes } from '../../types';
1010
import type { DeviceVerifySignature } from '../../types';
11-
import { UI_REQUEST } from '../../constants/ui-request';
1211

1312
export default class DeviceVerify extends BaseMethod<BixinVerifyDeviceRequest> {
1413
init() {
1514
this.useDevicePassphraseState = false;
16-
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.BOOTLOADER];
17-
this.skipForceUpdateCheck = true;
15+
1816
// check payload
1917
validateParams(this.payload, [{ name: 'dataHex', type: 'hexString' }]);
2018

0 commit comments

Comments
 (0)