Skip to content

Commit

Permalink
fix: touch hardware upgrade (#274)
Browse files Browse the repository at this point in the history
* fix: hardware upgrade

* chore: update hardware version
  • Loading branch information
ByteZhang1024 authored Aug 14, 2023
1 parent 65bc552 commit cf0501a
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 58 deletions.
10 changes: 5 additions & 5 deletions packages/connect-examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "0.3.23",
"version": "0.3.24",
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
Expand All @@ -10,10 +10,10 @@
},
"dependencies": {
"@noble/hashes": "^1.1.3",
"@onekeyfe/hd-ble-sdk": "^0.3.23",
"@onekeyfe/hd-common-connect-sdk": "^0.3.23",
"@onekeyfe/hd-core": "^0.3.23",
"@onekeyfe/hd-web-sdk": "^0.3.23",
"@onekeyfe/hd-ble-sdk": "^0.3.24",
"@onekeyfe/hd-common-connect-sdk": "^0.3.24",
"@onekeyfe/hd-core": "^0.3.24",
"@onekeyfe/hd-web-sdk": "^0.3.24",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"@react-native-async-storage/async-storage": "^1.17.6",
"@react-native-picker/picker": "2.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getHardwareSDKInstance = memoizee(
console.log(HardwareSDK);

if (Platform.OS === 'web') {
settings.connectSrc = 'https://jssdk.onekey.so/0.3.22/';
settings.connectSrc = 'https://jssdk.onekey.so/0.3.24/';
// settings.connectSrc = 'https://localhost:8087/';
settings.env = 'web';
settings.preRelease = false;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-core",
"version": "0.3.23",
"version": "0.3.24",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -25,8 +25,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport": "^0.3.24",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
15 changes: 6 additions & 9 deletions packages/core/src/api/firmware/getBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDeviceType, httpRequest } from '../../utils';
import { DataManager } from '../../data-manager';
import { findLatestRelease } from '../../utils/release';
import { getFirmwareUpdateField } from '../../utils/deviceFeaturesUtils';
import { FirmwareField } from '../../data-manager/DataManager';

export interface GetInfoProps {
features: Features;
Expand Down Expand Up @@ -74,15 +75,11 @@ export const getInfo = ({ features, updateType, targetVersion }: GetInfoProps) =
const deviceType = getDeviceType(features);
const { deviceMap } = DataManager;

let firmwareUpdateField: 'firmware' | 'ble' | 'firmware-v2' | 'firmware-v3' =
getFirmwareUpdateField(features, updateType);
if (deviceType === 'touch' && targetVersion) {
if (semver.eq(targetVersion, '4.0.0')) {
firmwareUpdateField = 'firmware-v2';
} else if (semver.gt(targetVersion, '4.0.0')) {
firmwareUpdateField = 'firmware-v3';
}
}
const firmwareUpdateField: 'ble' | FirmwareField = getFirmwareUpdateField({
features,
updateType,
targetVersion,
});

const releaseInfo = deviceMap?.[deviceType]?.[firmwareUpdateField] ?? [];
return findLatestRelease(releaseInfo);
Expand Down
39 changes: 30 additions & 9 deletions packages/core/src/data-manager/DataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
} from '../types';
import { findLatestRelease, getReleaseChangelog, getReleaseStatus } from '../utils/release';

type FirmwareField = 'firmware' | 'firmware-v2' | 'firmware-v3' | 'firmware-v4';
export type FirmwareField = 'firmware' | 'firmware-v2' | 'firmware-v4';

export type MessageVersion = 'latest' | 'v1';

Expand Down Expand Up @@ -69,7 +69,7 @@ export default class DataManager {
return 'unknown';
}

const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware');
const firmwareUpdateField = getFirmwareUpdateField({ features, updateType: 'firmware' });
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const currentVersion = deviceFirmwareVersion.join('.');
return getReleaseStatus(targetDeviceConfigList, currentVersion);
Expand All @@ -85,7 +85,10 @@ export default class DataManager {

if (deviceType !== 'pro' && deviceType !== 'touch') return undefined;

const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const currentVersion = deviceFirmwareVersion.join('.');
const targetDeviceConfig = targetDeviceConfigList.filter(item =>
Expand All @@ -106,7 +109,10 @@ export default class DataManager {

if (deviceType !== 'pro' && deviceType !== 'touch') return undefined;

const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.fullResource);

Expand All @@ -117,7 +123,10 @@ export default class DataManager {
const deviceType = getDeviceType(features);

if (deviceType !== 'pro' && deviceType !== 'touch') return undefined;
const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.bootloaderResource);

Expand All @@ -127,7 +136,10 @@ export default class DataManager {
static getBootloaderTargetVersion = (features: Features): IVersionArray | undefined => {
const deviceType = getDeviceType(features);

const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.bootloaderResource);

Expand All @@ -138,7 +150,10 @@ export default class DataManager {
const deviceType = getDeviceType(features);

if (!(deviceType === 'classic' || deviceType === 'mini')) return undefined;
const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const targetDeviceConfig = targetDeviceConfigList.filter(
item => !!item.bootloaderRelatedFirmwareVersion
Expand All @@ -158,15 +173,21 @@ export default class DataManager {
return [];
}

const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
const currentVersion = deviceFirmwareVersion.join('.');
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
};

static getFirmwareLatestRelease = (features: Features) => {
const deviceType = getDeviceType(features);
const firmwareUpdateField = getFirmwareUpdateField(features, 'firmware') as FirmwareField;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
}) as FirmwareField;
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];

const target = findLatestRelease(targetDeviceConfigList);
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export type DeviceTypeMap = {
[k in IDeviceType]: {
firmware: IFirmwareReleaseInfo[];
'firmware-v2'?: IFirmwareReleaseInfo[];
'firmware-v3'?: IFirmwareReleaseInfo[];
'firmware-v4'?: IFirmwareReleaseInfo[];
ble: IBLEFirmwareReleaseInfo[];
};
Expand Down
21 changes: 16 additions & 5 deletions packages/core/src/utils/deviceFeaturesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
SupportFeatureType,
} from '../types';
import { DeviceTypeToModels } from '../types';
import DataManager, { MessageVersion } from '../data-manager/DataManager';
import DataManager, { FirmwareField, MessageVersion } from '../data-manager/DataManager';
import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
import { Device } from '../device/Device';

Expand Down Expand Up @@ -240,10 +240,15 @@ export const supportModifyHomescreen = (features?: Features): SupportFeatureType
/**
* Since 3.5.0, Touch uses the firmware-v3 field to get firmware release info
*/
export const getFirmwareUpdateField = (
features: Features,
updateType: 'firmware' | 'ble'
): 'firmware' | 'ble' | 'firmware-v4' => {
export const getFirmwareUpdateField = ({
features,
updateType,
targetVersion,
}: {
features: Features;
updateType: 'firmware' | 'ble';
targetVersion?: string;
}): 'ble' | FirmwareField => {
const deviceType = getDeviceType(features);
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
if (updateType === 'ble') {
Expand All @@ -255,7 +260,13 @@ export const getFirmwareUpdateField = (
}

if (deviceType === 'touch') {
if (targetVersion) {
if (semver.eq(targetVersion, '4.0.0')) return 'firmware-v2';
if (semver.gt(targetVersion, '4.0.0')) return 'firmware-v4';
}

if (semver.lt(deviceFirmwareVersion.join('.'), '3.4.0')) return 'firmware';

return 'firmware-v4';
}
return 'firmware';
Expand Down
8 changes: 4 additions & 4 deletions packages/hd-ble-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-ble-sdk",
"version": "0.3.23",
"version": "0.3.24",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport-react-native": "^0.3.23"
"@onekeyfe/hd-core": "^0.3.24",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport-react-native": "^0.3.24"
}
}
10 changes: 5 additions & 5 deletions packages/hd-common-connect-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-common-connect-sdk",
"version": "0.3.23",
"version": "0.3.24",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,9 +20,9 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport-http": "^0.3.23",
"@onekeyfe/hd-transport-webusb": "^0.3.23"
"@onekeyfe/hd-core": "^0.3.24",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport-http": "^0.3.24",
"@onekeyfe/hd-transport-webusb": "^0.3.24"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-http",
"version": "0.3.23",
"version": "0.3.24",
"description": "hardware http transport",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport": "^0.3.24",
"axios": "^0.27.2"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-react-native",
"version": "0.3.23",
"version": "0.3.24",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -19,8 +19,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport": "^0.3.24",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"react-native-ble-manager": "^8.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-webusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-webusb",
"version": "0.3.23",
"version": "0.3.24",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport": "^0.3.23"
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport": "^0.3.24"
},
"devDependencies": {
"@types/w3c-web-usb": "^1.0.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/hd-transport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport",
"version": "0.3.23",
"version": "0.3.24",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand Down
10 changes: 5 additions & 5 deletions packages/hd-web-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-web-sdk",
"version": "0.3.23",
"version": "0.3.24",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -21,10 +21,10 @@
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "^0.0.17",
"@onekeyfe/hd-core": "^0.3.23",
"@onekeyfe/hd-shared": "^0.3.23",
"@onekeyfe/hd-transport-http": "^0.3.23",
"@onekeyfe/hd-transport-webusb": "^0.3.23"
"@onekeyfe/hd-core": "^0.3.24",
"@onekeyfe/hd-shared": "^0.3.24",
"@onekeyfe/hd-transport-http": "^0.3.24",
"@onekeyfe/hd-transport-webusb": "^0.3.24"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.17.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-shared",
"version": "0.3.23",
"version": "0.3.24",
"description": "Hardware SDK's shared tool library",
"keywords": [
"Hardware-SDK",
Expand Down

0 comments on commit cf0501a

Please sign in to comment.