Skip to content

Commit

Permalink
chore: fix update error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Mar 19, 2024
1 parent 58db0db commit 37cfabc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,14 @@ function FirmwareUpdate({ selectDevice, onDisconnectDevice }: FirmwareUpdateProp

if (type === 'ble' || type === 'firmware' || type === 'bootloader') {
setShowUpdateDialog(true);
// @ts-expect-error
const res = await sdk.firmwareUpdate(
Platform.OS === 'web' ? undefined : selectDevice.connectId,
{
updateType: type === 'bootloader' ? 'firmware' : type,
binary: fileData,
platform: Platform.OS === 'web' ? 'web' : 'native',
}
);

// const res = await sdk.firmwareUpdateV2(
// Platform.OS === 'web' ? undefined : selectDevice.connectId,
// {
// updateType: type === 'bootloader' ? 'firmware' : type,
// binary: fileData,
// platform: Platform.OS === 'web' ? 'web' : 'native',
// }
// );

setShowUpdateDialog(false);
if (!res.success) {
return {
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/api/FirmwareUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
validateParams(payload, [
{ name: 'version', type: 'array' },
{ name: 'binary', type: 'buffer' },
{ name: 'updateType', type: 'string', required: true },
]);

if (!payload.updateType) {
throw ERRORS.TypedError(
HardwareErrorCode.CallMethodInvalidParameter,
'updateType is required'
);
}

this.params = { updateType: payload.updateType };

if ('version' in payload) {
Expand Down Expand Up @@ -201,6 +195,8 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
}

await this.device.acquire();

return uploadFirmware(
params.updateType,
this.device.getCommands().typedCall.bind(this.device.getCommands()),
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/types/api/firmwareUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { PROTO } from '../../constants';
import type { Params, Response } from '../params';

type IUpdateType = 'firmware' | 'ble';

export interface FirmwareUpdateBinaryParams {
binary: ArrayBuffer;
updateType: IUpdateType;
}

export interface FirmwareUpdateParams {
version?: number[];
btcOnly?: boolean;
updateType: 'firmware' | 'ble';
updateType: IUpdateType;
forcedUpdateRes?: boolean;
isUpdateBootloader?: boolean;
}
Expand Down

0 comments on commit 37cfabc

Please sign in to comment.