mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
- ui/chart.tsx: recharts 3 stopped exposing tooltip/legend content props on its public types; declare the ChartPayloadItem shape we consume - base-ui Select onValueChange passes string|null: guard null in BillingCycleSelector, PasteImportModal, TransactionModal - type the untyped api.get calls (cycles, categories) - push-notifications: back the VAPID key with an explicit ArrayBuffer so it satisfies BufferSource under TS 5.9 Unblocks gating CI on pnpm typecheck. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import api from './api';
|
|
|
|
function urlBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer> {
|
|
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
|
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
|
const rawData = window.atob(base64);
|
|
// Explicit ArrayBuffer backing so the result satisfies BufferSource.
|
|
const outputArray = new Uint8Array(new ArrayBuffer(rawData.length));
|
|
for (let i = 0; i < rawData.length; ++i) {
|
|
outputArray[i] = rawData.charCodeAt(i);
|
|
}
|
|
return outputArray;
|
|
}
|
|
|
|
export async function subscribeToPush(): Promise<void> {
|
|
if (!('serviceWorker' in navigator) || !('PushManager' in window)) {
|
|
return;
|
|
}
|
|
|
|
const permission = await Notification.requestPermission();
|
|
if (permission !== 'granted') {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const { data } = await api.get<{ publicKey: string }>('/notifications/vapid-public-key');
|
|
const registration = await navigator.serviceWorker.ready;
|
|
|
|
const existing = await registration.pushManager.getSubscription();
|
|
if (existing) {
|
|
await sendSubscriptionToServer(existing);
|
|
return;
|
|
}
|
|
|
|
const subscription = await registration.pushManager.subscribe({
|
|
userVisibleOnly: true,
|
|
applicationServerKey: urlBase64ToUint8Array(data.publicKey),
|
|
});
|
|
|
|
await sendSubscriptionToServer(subscription);
|
|
} catch (err) {
|
|
console.warn('Push subscription failed:', err);
|
|
}
|
|
}
|
|
|
|
async function sendSubscriptionToServer(subscription: PushSubscription): Promise<void> {
|
|
const json = subscription.toJSON();
|
|
await api.post('/notifications/subscribe', {
|
|
endpoint: json.endpoint,
|
|
keys: json.keys,
|
|
});
|
|
}
|