Skip to content

Commit ac7caa0

Browse files
committed
chore: fixed nested onMount conflict.
1 parent 37af899 commit ac7caa0

File tree

1 file changed

+50
-69
lines changed

1 file changed

+50
-69
lines changed

infrastructure/eid-wallet/src/routes/(app)/main/+page.svelte

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,41 @@
11
<script lang="ts">
2-
import { goto } from "$app/navigation";
3-
import { Hero, IdentityCard } from "$lib/fragments";
4-
import type { GlobalState } from "$lib/global";
5-
import { Drawer } from "$lib/ui";
6-
import * as Button from "$lib/ui/Button";
7-
import { QrCodeIcon, Settings02Icon } from "@hugeicons/core-free-icons";
8-
import { HugeiconsIcon } from "@hugeicons/svelte";
9-
import { getCurrent } from "@tauri-apps/plugin-deep-link";
10-
import { type Snippet, getContext, onMount } from "svelte";
11-
import { onDestroy } from "svelte";
12-
import { Shadow } from "svelte-loading-spinners";
13-
import QrCode from "svelte-qrcode";
14-
15-
let userData: Record<string, unknown> | undefined = $state(undefined);
16-
let greeting: string | undefined = $state(undefined);
17-
let ename: string | undefined = $state(undefined);
18-
let profileCreationStatus: "idle" | "loading" | "success" | "failed" =
19-
$state("idle");
20-
21-
let shareQRdrawerOpen = $state(false);
22-
let statusInterval: ReturnType<typeof setInterval> | undefined =
23-
$state(undefined);
24-
25-
function shareQR() {
26-
alert("QR Code shared!");
27-
shareQRdrawerOpen = false;
28-
}
29-
30-
async function retryProfileCreation() {
31-
try {
32-
await globalState.vaultController.retryProfileCreation();
33-
} catch (error) {
34-
console.error("Retry failed:", error);
2+
import { goto } from "$app/navigation";
3+
import { Hero, IdentityCard } from "$lib/fragments";
4+
import type { GlobalState } from "$lib/global";
5+
import { Drawer } from "$lib/ui";
6+
import * as Button from "$lib/ui/Button";
7+
import { QrCodeIcon, Settings02Icon } from "@hugeicons/core-free-icons";
8+
import { HugeiconsIcon } from "@hugeicons/svelte";
9+
import { getCurrent } from "@tauri-apps/plugin-deep-link";
10+
import { type Snippet, getContext, onMount } from "svelte";
11+
import { onDestroy } from "svelte";
12+
import { Shadow } from "svelte-loading-spinners";
13+
import QrCode from "svelte-qrcode";
14+
15+
let userData: Record<string, unknown> | undefined = $state(undefined);
16+
let greeting: string | undefined = $state(undefined);
17+
let ename: string | undefined = $state(undefined);
18+
let profileCreationStatus: "idle" | "loading" | "success" | "failed" =
19+
$state("idle");
20+
21+
let shareQRdrawerOpen = $state(false);
22+
let statusInterval: ReturnType<typeof setInterval> | undefined =
23+
$state(undefined);
24+
25+
function shareQR() {
26+
alert("QR Code shared!");
27+
shareQRdrawerOpen = false;
3528
}
36-
}
3729
38-
const globalState = getContext<() => GlobalState>("globalState")();
30+
async function retryProfileCreation() {
31+
try {
32+
await globalState.vaultController.retryProfileCreation();
33+
} catch (error) {
34+
console.error("Retry failed:", error);
35+
}
36+
}
3937
40-
onMount(async () => {
41-
// Load initial data
42-
(async () => {
43-
const userInfo = await globalState.userController.user;
44-
const isFake = await globalState.userController.isFake;
45-
userData = { ...userInfo, isFake };
46-
const vaultData = await globalState.vaultController.vault;
47-
ename = vaultData?.ename;
48-
})();
38+
const globalState = getContext<() => GlobalState>("globalState")();
4939
5040
onMount(async () => {
5141
// Load initial data
@@ -66,6 +56,18 @@ onMount(async () => {
6656
// Check status periodically
6757
statusInterval = setInterval(checkStatus, 1000);
6858
59+
const urls = await getCurrent();
60+
if (urls && urls.length > 0) {
61+
const url = urls[0];
62+
const [scheme, ...rest] = url.split("://");
63+
const deeplink = rest.join("://");
64+
console.log("URL", scheme, deeplink);
65+
if (scheme !== "w3ds") {
66+
console.error("unsupported url scheme");
67+
}
68+
goto(`/scan-qr?${deeplink}`);
69+
}
70+
6971
const currentHour = new Date().getHours();
7072
greeting =
7173
currentHour > 17
@@ -75,32 +77,11 @@ onMount(async () => {
7577
: "Good Morning";
7678
});
7779
78-
const urls = await getCurrent();
79-
if (urls && urls.length > 0) {
80-
const url = urls[0];
81-
const [scheme, ...rest] = url.split("://");
82-
const deeplink = rest.join("://");
83-
console.log("URL", scheme, deeplink);
84-
if (scheme !== "w3ds") {
85-
console.error("unsupported url scheme");
80+
onDestroy(() => {
81+
if (statusInterval) {
82+
clearInterval(statusInterval);
8683
}
87-
goto(`/scan-qr?${deeplink}`);
88-
}
89-
90-
const currentHour = new Date().getHours();
91-
greeting =
92-
currentHour > 17
93-
? "Good Evening"
94-
: currentHour > 12
95-
? "Good Afternoon"
96-
: "Good Morning";
97-
});
98-
99-
onDestroy(() => {
100-
if (statusInterval) {
101-
clearInterval(statusInterval);
102-
}
103-
});
84+
});
10485
</script>
10586

10687
{#if profileCreationStatus === "loading"}

0 commit comments

Comments
 (0)