-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(suite): cleanup code around parseFirmwareChangelog + add suppor…
…t for BTC only changelog
- Loading branch information
1 parent
5afc0ab
commit 3018dce
Showing
8 changed files
with
113 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
suite-common/suite-utils/src/__tests__/parseFirmwareChangelog.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { FirmwareRelease } from '@trezor/connect'; | ||
|
||
import { | ||
parseFirmwareChangelog, | ||
ParseFirmwareChangelogParams, | ||
ParseFirmwareChangelogResult, | ||
} from '../parseFirmwareChangelog'; | ||
|
||
const releaseData: Omit<FirmwareRelease, 'changelog' | 'changelogBtcOnly'> = { | ||
required: false, | ||
version: [1, 9, 4], | ||
bootloader_version: [1, 8, 0], | ||
min_firmware_version: [1, 6, 2], | ||
min_bootloader_version: [1, 5, 0], | ||
url: 'firmware/1/trezor-1.9.4.bin', | ||
url_bitcoinonly: 'firmware/1/trezor-1.9.4-bitcoinonly.bin', | ||
fingerprint: '867017bd784cc4e9ce6f0875c61ea86f89b19380d54045c34608b85472998000', | ||
fingerprint_bitcoinonly: '3f73dfbcfc48f66c8814f6562524d81888230e0acd1c19b52b6e8772c6c67e7f', | ||
notes: 'https://blog.trezor.io/trezor-suite-and-firmware-updates-rbf-and-spending-now-live-c2f69c42d7f7', | ||
}; | ||
|
||
const parseFirmwareChangelogFixture: Array<{ | ||
description: string; | ||
input: ParseFirmwareChangelogParams; | ||
result: ParseFirmwareChangelogResult | null; | ||
}> = [ | ||
{ | ||
description: 'Parse release changelog', | ||
input: { | ||
release: { | ||
...releaseData, | ||
changelog: | ||
'* Replacement transaction signing for replace-by-fee.\n* Support for Output Descriptors export.\n* Show Ypub/Zpub correctly for multisig GetAddress.\n* Show amounts in mBTC, uBTC and sat denominations.', | ||
}, | ||
isBtcOnly: false, | ||
}, | ||
|
||
result: { | ||
changelog: [ | ||
'Replacement transaction signing for replace-by-fee.', | ||
'Support for Output Descriptors export.', | ||
'Show Ypub/Zpub correctly for multisig GetAddress.', | ||
'Show amounts in mBTC, uBTC and sat denominations.', | ||
], | ||
notes: 'https://blog.trezor.io/trezor-suite-and-firmware-updates-rbf-and-spending-now-live-c2f69c42d7f7', | ||
url: 'firmware/1/trezor-1.9.4.bin', | ||
versionString: '1.9.4', | ||
}, | ||
}, | ||
{ | ||
description: 'No firmware release', | ||
input: { | ||
release: undefined, | ||
isBtcOnly: false, | ||
}, | ||
result: null, | ||
}, | ||
]; | ||
|
||
describe(parseFirmwareChangelog.name, () => { | ||
parseFirmwareChangelogFixture.forEach(row => { | ||
it(row.description, () => { | ||
expect(parseFirmwareChangelog(row.input)).toEqual(row.result); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { FirmwareRelease } from '@trezor/connect'; | ||
|
||
export type ParseFirmwareChangelogParams = { | ||
release?: FirmwareRelease; | ||
isBtcOnly: boolean; | ||
}; | ||
|
||
export type ParseFirmwareChangelogResult = { | ||
url: string; | ||
notes: string | undefined; | ||
changelog: string[]; | ||
versionString: string; | ||
}; | ||
|
||
export const parseFirmwareChangelog = ({ | ||
release, | ||
isBtcOnly, | ||
}: ParseFirmwareChangelogParams): ParseFirmwareChangelogResult | null => { | ||
const changeLogField: keyof FirmwareRelease = isBtcOnly ? 'changelogBtcOnly' : 'changelog'; | ||
|
||
if ( | ||
release === undefined || | ||
release[changeLogField] === undefined || | ||
release[changeLogField]?.length === 0 | ||
) { | ||
return null; | ||
} | ||
|
||
// Default changelog format is a long string where individual changes are separated by "*" symbol. | ||
const changelog = (release[changeLogField] ?? '') | ||
.trim() | ||
.split('*') | ||
.map(l => l.trim()) | ||
.filter(l => l.length); | ||
|
||
return { | ||
url: release.url, | ||
notes: release.notes, | ||
changelog, | ||
versionString: release.version.join('.'), | ||
}; | ||
}; |