Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ export const GET: RequestHandler = async () => {
const timeout = setTimeout(() => controller.abort(), 5000);
const response = await fetch(`${baseUrl}/api/references/all`, {
headers: env.VISUALIZER_API_KEY ? { 'x-visualizer-key': env.VISUALIZER_API_KEY } : {},
signal: controller.signal,
signal: controller.signal
});
clearTimeout(timeout);


if (!response.ok) {
console.error('eReputation API error:', response.status, response.statusText);
Expand All @@ -24,6 +23,9 @@ export const GET: RequestHandler = async () => {
return json(data);
} catch (error) {
console.error('Error fetching references from eReputation:', error);
return json({ error: 'Failed to connect to eReputation API', references: [] }, { status: 500 });
return json(
{ error: 'Failed to connect to eReputation API', references: [] },
{ status: 500 }
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface ReferenceEdge {
createdAt: string;
}


export const load: PageServerLoad = async ({ fetch }) => {
try {
const response = await fetch('/api/references');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { PUBLIC_PROVISIONER_URL } from "$env/static/public";
import { addNotification } from "$lib/stores/notifications";
import {
isPermissionGranted,
onNotificationReceived,
registerForPushNotifications,
requestPermission,
sendNotification,
} from "@choochmeque/tauri-plugin-notifications-api";
import type { PluginListener } from "@tauri-apps/api/core";
import { invoke } from "@tauri-apps/api/core";

export interface DeviceRegistration {
Expand Down Expand Up @@ -401,6 +403,33 @@ class NotificationService {
if (platform !== "android" && platform !== "ios") return undefined;
return this.getPushNotificationToken();
}
/**
* Listen for push notifications arriving while the app is in the foreground.
* Stores them in the notification panel so they appear in the notifications tab.
* Returns a cleanup function to remove the listener.
*/
async listenForForegroundNotifications(): Promise<PluginListener> {
return onNotificationReceived((notification) => {
if (notification.source !== "push") return;
const title = notification.title ?? "";
if (!title) return;

const raw = (notification.extra ?? {}) as Record<string, unknown>;
const data = Object.fromEntries(
Object.entries(raw).filter(
(entry): entry is [string, string] =>
typeof entry[1] === "string",
),
);

addNotification({
title,
body: notification.body ?? "",
data: Object.keys(data).length > 0 ? data : undefined,
});
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/**
* Get eName from vault (helper method)
*/
Expand Down
16 changes: 15 additions & 1 deletion infrastructure/eid-wallet/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import { goto } from "$app/navigation";
import { page } from "$app/state";
import type { GlobalState } from "$lib/global";
import type { PluginListener } from "@tauri-apps/api/core";
import type { Snippet } from "svelte";
import { getContext, onMount } from "svelte";
import { getContext, onDestroy, onMount } from "svelte";
import type { LayoutData } from "./$types";

let { data, children }: { data: LayoutData; children: Snippet } = $props();

let currentRoute = $derived(page.url.pathname.split("/").pop() || "home");
let globalState: GlobalState | undefined = $state(undefined);
let notificationListener: PluginListener | undefined;

onMount(async () => {
// Get global state
Expand Down Expand Up @@ -47,6 +49,14 @@ onMount(async () => {
);
}

// Listen for push notifications while app is in the foreground
try {
notificationListener =
await globalState.notificationService.listenForForegroundNotifications();
} catch (error) {
console.error("Failed to set up notification listener:", error);
}

// Check for pending notifications and navigate to the message's open page
try {
const notificationService = globalState.notificationService;
Expand All @@ -72,6 +82,10 @@ onMount(async () => {
}
});

onDestroy(() => {
notificationListener?.unregister();
});

$effect(() => {
const isScanPage = currentRoute === "scan-qr";
if (isScanPage) return document.body.classList.add("custom-global-style");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { onDestroy, onMount } from "svelte";

let notifications: StoredNotification[] = $state([]);
let loaded = $state(false);
let unsubscribe: (() => void) | undefined;

function refresh() {
Expand All @@ -19,6 +20,7 @@ function refresh() {

onMount(() => {
refresh();
loaded = true;
unsubscribe = subscribe(refresh);
});

Expand Down Expand Up @@ -80,7 +82,11 @@ function handleClearAll() {
</div>
{/if}

{#if notifications.length === 0}
{#if !loaded}
<div class="flex flex-col items-center justify-center mt-20">
<p class="text-sm text-black-500">Loading...</p>
</div>
{:else if notifications.length === 0}
<div class="flex flex-col items-center justify-center mt-20">
<p class="text-lg text-black-700">No notifications</p>
<p class="text-sm text-black-500 mt-1">You're all caught up</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ export function createScanLogic({
// Ensure auth drawer is closed before opening logged in drawer
codeScannedDrawerOpen.set(false);
loggedInDrawerOpen.set(true);
startScan();
} catch (error) {
console.error("Error completing authentication:", error);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,10 +1438,25 @@ onMount(async () => {
{diditRejectionReason ??
"Your verification could not be completed."}
</p>
<p class="text-black-500 text-xs">
If you believe this was a mistake, please contact us at
<a href="mailto:info@metastate.foundation" class="text-primary underline">info@metastate.foundation</a>.
</p>
<div class="flex flex-col gap-3 pt-2">
<ButtonAction class="w-full" callback={handleKycNext}>
Try Again
</ButtonAction>
{#if !upgradeMode}
<ButtonAction
variant="soft"
class="w-full"
callback={() => {
step = "anonymous-form";
}}
>
Self-declare instead
</ButtonAction>
{/if}
<ButtonAction
variant="soft"
class="w-full"
Expand Down
Loading