Skip to content

Commit f016b45

Browse files
committed
feat: wallet deep link logic
1 parent 6f2e842 commit f016b45

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href="w3ds://auth">CLICK ME</a>
1+
<a href="w3ds://auth?redirect=https://blabsy.w3ds.metastate.foundation/api/auth&session=8854f847-6b80-4df0-bb94-68fb9a756aa4&platform=blabsy">CLICK ME</a>

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import * as Button from "$lib/ui/Button";
77
import { QrCodeIcon, Settings02Icon } from "@hugeicons/core-free-icons";
88
import { HugeiconsIcon } from "@hugeicons/svelte";
9-
import { getContext, onMount, type Snippet } from "svelte";
10-
import { Shadow } from "svelte-loading-spinners";
9+
import {
10+
getCurrent
11+
} from '@tauri-apps/plugin-deep-link'
12+
import { type Snippet, getContext, onMount } from "svelte";
1113
import { onDestroy } from "svelte";
14+
import { Shadow } from "svelte-loading-spinners";
1215
import QrCode from "svelte-qrcode";
1316
1417
let userData: Record<string, unknown> | undefined = $state(undefined);
@@ -35,7 +38,7 @@
3538
3639
const globalState = getContext<() => GlobalState>("globalState")();
3740
38-
onMount(() => {
41+
onMount(async () => {
3942
// Load initial data
4043
(async () => {
4144
const userInfo = await globalState.userController.user;
@@ -58,6 +61,21 @@
5861
// Check status periodically
5962
statusInterval = setInterval(checkStatus, 1000);
6063
64+
const urls = await getCurrent()
65+
if (urls && urls.length > 0) {
66+
const url = urls[0]
67+
const [scheme, ...rest] = url.split("://")
68+
const deeplink = rest.join("://")
69+
console.log("URL", scheme, deeplink)
70+
if (scheme !== "w3ds") {
71+
console.error("unsupported url scheme")
72+
}
73+
// const url = new URL(urls[0])
74+
// console.log(url)
75+
// if (url.protocol)
76+
goto(`/scan-qr?${deeplink}`)
77+
}
78+
6179
const currentHour = new Date().getHours();
6280
greeting =
6381
currentHour > 17

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
2+
import { page } from "$app/state";
23
import { PUBLIC_PROVISIONER_URL } from "$env/static/public";
34
import AppNav from "$lib/fragments/AppNav/AppNav.svelte";
5+
import type { GlobalState } from "$lib/global";
46
import { Drawer } from "$lib/ui";
57
import * as Button from "$lib/ui/Button";
68
import { QrCodeIcon } from "@hugeicons/core-free-icons";
@@ -14,10 +16,9 @@
1416
requestPermissions,
1517
scan,
1618
} from "@tauri-apps/plugin-barcode-scanner";
19+
import axios from "axios";
1720
import { getContext, onDestroy, onMount } from "svelte";
1821
import type { SVGAttributes } from "svelte/elements";
19-
import type { GlobalState } from "$lib/global";
20-
import axios from "axios";
2122
2223
const globalState = getContext<() => GlobalState>("globalState")();
2324
const pathProps: SVGAttributes<SVGPathElement> = {
@@ -96,6 +97,31 @@
9697
}
9798
9899
onMount(async () => {
100+
// const params = page.url.searchParams
101+
const [_empty, ...rest] = page.url.search.split("?")
102+
const methodAndParam = rest.join("?")
103+
const [method, ...param] = methodAndParam.split("?")
104+
const data = param.join("?")
105+
const deeplinkMethodSpecifiers = ["auth"]
106+
if (method && !deeplinkMethodSpecifiers.includes(method)) {
107+
console.error("Unknown method specifier")
108+
}
109+
switch (method) {
110+
case "auth": {
111+
const params = new URLSearchParams(data)
112+
platform = params.get("platform")
113+
session = params.get("session")
114+
redirect = params.get("redirect")
115+
if (!redirect || !platform || !session) {
116+
console.error("Bad deeplink!")
117+
break
118+
}
119+
hostname = (new URL(redirect as string)).hostname
120+
codeScannedDrawerOpen = true
121+
scanning = false
122+
break
123+
}
124+
}
99125
startScan();
100126
});
101127

infrastructure/eid-wallet/src/routes/(auth)/onboarding/+page.svelte

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
// signPayload, verifySignature
1414
} from "@auvo/tauri-plugin-crypto-hw-api"
1515
import * as falso from "@ngneat/falso";
16-
import {
17-
getCurrent,
18-
onOpenUrl
19-
} from '@tauri-apps/plugin-deep-link'
2016
import axios from "axios";
2117
import { getContext, onMount } from "svelte";
2218
import { Shadow } from "svelte-loading-spinners";
@@ -90,7 +86,6 @@
9086
let error: string | null = $state(null);
9187
9288
onMount(async () => {
93-
console.log("YOOOOOO", await getCurrent())
9489
globalState = getContext<() => GlobalState>("globalState")();
9590
// handle verification logic + sec user data in the store
9691
@@ -146,7 +141,7 @@
146141
`${falso.randFirstName()} ${falso.randLastName()}`,
147142
),
148143
"Date of Birth": new Date().toDateString(),
149-
"ID submitted": "Passport - " + falso.randCountryCode(),
144+
"ID submitted": `Passport - ${falso.randCountryCode()}`,
150145
"Passport Number": generatePassportNumber(),
151146
};
152147
globalState.userController.isFake = true;

0 commit comments

Comments
 (0)