fix(native): read a notice button's href without a weak type

An action button carries no href, so a parameter typed as only an optional href refused the notice DTO; the button type now names its kind as well.
This commit is contained in:
Maurice
2026-10-25 18:58:27 +01:00
parent 8963180006
commit cb6149f8ba
2 changed files with 8 additions and 7 deletions
+4 -3
View File
@@ -42,9 +42,10 @@ describe('in the native app', () => {
describe('noticeAsksForDonation', () => {
it('looks at both buttons', () => {
expect(noticeAsksForDonation({ cta: { href: 'https://ko-fi.com/x' } })).toBe(true);
expect(noticeAsksForDonation({ secondaryCta: { href: 'https://buymeacoffee.com/x' } })).toBe(true);
expect(noticeAsksForDonation({ cta: { href: '/settings' }, secondaryCta: null })).toBe(false);
expect(noticeAsksForDonation({ cta: { kind: 'link', href: 'https://ko-fi.com/x' } })).toBe(true);
expect(noticeAsksForDonation({ secondaryCta: { kind: 'link', href: 'https://buymeacoffee.com/x' } })).toBe(true);
expect(noticeAsksForDonation({ cta: { kind: 'nav', href: '/settings' }, secondaryCta: null })).toBe(false);
expect(noticeAsksForDonation({ cta: { kind: 'action' } })).toBe(false);
expect(noticeAsksForDonation({})).toBe(false);
});
});
+4 -4
View File
@@ -29,10 +29,10 @@ export function withoutDonationsInApp<T extends { href: string }>(links: T[]): T
return donationsShown() ? links : links.filter((link) => !isDonationLink(link.href));
}
/** A notice button: a link or a navigation carries an href, an action does not. */
type NoticeButton = { kind: string; href?: string } | null | undefined;
/** Whether a system notice asks for a donation through one of its buttons. */
export function noticeAsksForDonation(notice: {
cta?: { href?: string } | null;
secondaryCta?: { href?: string } | null;
}): boolean {
export function noticeAsksForDonation(notice: { cta?: NoticeButton; secondaryCta?: NoticeButton }): boolean {
return isDonationLink(notice.cta?.href) || isDonationLink(notice.secondaryCta?.href);
}