Skip to content

Commit 366fc48

Browse files
committed
chore: fixed duplicate handleFinalSubmit function definitions.
1 parent ac7caa0 commit 366fc48

File tree

1 file changed

+113
-136
lines changed
  • infrastructure/eid-wallet/src/routes/(auth)/onboarding

1 file changed

+113
-136
lines changed

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

Lines changed: 113 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,132 @@
11
<script lang="ts">
2-
import { goto } from "$app/navigation";
3-
import {
4-
PUBLIC_PROVISIONER_URL,
5-
PUBLIC_REGISTRY_URL,
6-
} from "$env/static/public";
7-
import { Hero } from "$lib/fragments";
8-
import { GlobalState } from "$lib/global";
9-
import { ButtonAction, Drawer } from "$lib/ui";
10-
import { capitalize } from "$lib/utils";
11-
import {
12-
generate,
13-
getPublicKey,
14-
// signPayload, verifySignature
15-
} from "@auvo/tauri-plugin-crypto-hw-api";
16-
import * as falso from "@ngneat/falso";
17-
import axios from "axios";
18-
import { getContext, onMount } from "svelte";
19-
import { Shadow } from "svelte-loading-spinners";
20-
import { v4 as uuidv4 } from "uuid";
2+
import { goto } from "$app/navigation";
3+
import {
4+
PUBLIC_PROVISIONER_URL,
5+
PUBLIC_REGISTRY_URL,
6+
} from "$env/static/public";
7+
import { Hero } from "$lib/fragments";
8+
import { GlobalState } from "$lib/global";
9+
import { ButtonAction, Drawer } from "$lib/ui";
10+
import { capitalize } from "$lib/utils";
11+
import {
12+
generate,
13+
getPublicKey,
14+
// signPayload, verifySignature
15+
} from "@auvo/tauri-plugin-crypto-hw-api";
16+
import * as falso from "@ngneat/falso";
17+
import axios from "axios";
18+
import { getContext, onMount } from "svelte";
19+
import { Shadow } from "svelte-loading-spinners";
20+
import { v4 as uuidv4 } from "uuid";
2121
22-
let isPaneOpen = $state(false);
23-
let preVerified = $state(false);
24-
let loading = $state(false);
25-
let verificationId = $state("");
26-
let demoName = $state("");
27-
let verificationSuccess = $state(false);
22+
let isPaneOpen = $state(false);
23+
let preVerified = $state(false);
24+
let loading = $state(false);
25+
let verificationId = $state("");
26+
let demoName = $state("");
27+
let verificationSuccess = $state(false);
2828
29-
const handleGetStarted = async () => {
30-
//get started functionality
31-
isPaneOpen = true;
32-
preVerified = false;
33-
};
34-
35-
const handlePreVerified = () => {
36-
isPaneOpen = true;
37-
preVerified = true;
38-
};
29+
const handleGetStarted = async () => {
30+
//get started functionality
31+
isPaneOpen = true;
32+
preVerified = false;
33+
};
3934
40-
function generatePassportNumber() {
41-
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
42-
const randomLetters = () =>
43-
letters.charAt(Math.floor(Math.random() * letters.length)) +
44-
letters.charAt(Math.floor(Math.random() * letters.length));
45-
const randomDigits = () =>
46-
String(Math.floor(1000000 + Math.random() * 9000000)); // 7 digits
35+
const handlePreVerified = () => {
36+
isPaneOpen = true;
37+
preVerified = true;
38+
};
4739
48-
return randomLetters() + randomDigits();
49-
}
40+
function generatePassportNumber() {
41+
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
42+
const randomLetters = () =>
43+
letters.charAt(Math.floor(Math.random() * letters.length)) +
44+
letters.charAt(Math.floor(Math.random() * letters.length));
45+
const randomDigits = () =>
46+
String(Math.floor(1000000 + Math.random() * 9000000)); // 7 digits
5047
51-
// IMO, call this function early, check if hardware even supports the app
52-
// docs: https://github.com/auvoid/tauri-plugin-crypto-hw/blob/48d0b9db7083f9819766e7b3bfd19e39de9a77f3/examples/tauri-app/src/App.svelte#L13
53-
async function generateApplicationKeyPair() {
54-
let res: string | undefined;
55-
try {
56-
res = await generate("default");
57-
console.log(res);
58-
} catch (e) {
59-
// Put hardware crypto missing error here
60-
console.log(e);
48+
return randomLetters() + randomDigits();
6149
}
62-
return res;
63-
}
6450
65-
async function getApplicationPublicKey() {
66-
let res: string | undefined;
67-
try {
68-
res = await getPublicKey("default");
69-
console.log(res);
70-
} catch (e) {
71-
console.log(e);
51+
// IMO, call this function early, check if hardware even supports the app
52+
// docs: https://github.com/auvoid/tauri-plugin-crypto-hw/blob/48d0b9db7083f9819766e7b3bfd19e39de9a77f3/examples/tauri-app/src/App.svelte#L13
53+
async function generateApplicationKeyPair() {
54+
let res: string | undefined;
55+
try {
56+
res = await generate("default");
57+
console.log(res);
58+
} catch (e) {
59+
// Put hardware crypto missing error here
60+
console.log(e);
61+
}
62+
return res;
7263
}
73-
return res; // check getPublicKey doc comments (multibase hex format)
74-
}
7564
76-
const handleNext = async () => {
77-
//handle next functionlity
78-
goto("/verify");
79-
};
80-
81-
let globalState: GlobalState;
82-
let handleContinue: () => Promise<void> | void;
83-
let handleFinalSubmit: () => Promise<void> | void;
84-
let ename: string;
85-
let uri: string;
65+
async function getApplicationPublicKey() {
66+
let res: string | undefined;
67+
try {
68+
res = await getPublicKey("default");
69+
console.log(res);
70+
} catch (e) {
71+
console.log(e);
72+
}
73+
return res; // check getPublicKey doc comments (multibase hex format)
74+
}
8675
87-
let error: string | null = $state(null);
76+
const handleNext = async () => {
77+
//handle next functionlity
78+
goto("/verify");
79+
};
8880
89-
onMount(() => {
90-
globalState = getContext<() => GlobalState>("globalState")();
91-
// handle verification logic + sec user data in the store
81+
let globalState: GlobalState;
82+
let handleContinue: () => Promise<void> | void;
83+
let handleFinalSubmit: () => Promise<void> | void;
84+
let ename: string;
85+
let uri: string;
9286
93-
handleContinue = async () => {
94-
loading = true;
95-
const {
96-
data: { token: registryEntropy },
97-
} = await axios.get(
98-
new URL("/entropy", PUBLIC_REGISTRY_URL).toString(),
99-
);
87+
let error: string | null = $state(null);
10088
101-
const { data } = await axios
102-
.post(new URL("/provision", PUBLIC_PROVISIONER_URL).toString(), {
103-
registryEntropy,
104-
namespace: uuidv4(),
105-
verificationId,
106-
})
107-
.catch(() => {
108-
loading = false;
109-
console.log("caught");
110-
preVerified = false;
111-
verificationId = "";
112-
error = "Wrong pre-verificaiton code";
113-
setTimeout(() => {
114-
error = null;
115-
}, 6_000);
116-
return { data: null };
117-
});
118-
if (!data) return;
89+
onMount(() => {
90+
globalState = getContext<() => GlobalState>("globalState")();
91+
// handle verification logic + sec user data in the store
11992
120-
// If verification is successful, show demo name input
121-
if (data.success === true) {
122-
loading = false;
123-
verificationSuccess = true;
124-
uri = data.uri;
125-
ename = data.w3id;
126-
}
127-
};
93+
handleContinue = async () => {
94+
loading = true;
95+
const {
96+
data: { token: registryEntropy },
97+
} = await axios.get(
98+
new URL("/entropy", PUBLIC_REGISTRY_URL).toString(),
99+
);
128100
129-
// New function to handle final submission with demo name
130-
handleFinalSubmit = async () => {
131-
loading = true;
101+
const { data } = await axios
102+
.post(
103+
new URL("/provision", PUBLIC_PROVISIONER_URL).toString(),
104+
{
105+
registryEntropy,
106+
namespace: uuidv4(),
107+
verificationId,
108+
},
109+
)
110+
.catch(() => {
111+
loading = false;
112+
console.log("caught");
113+
preVerified = false;
114+
verificationId = "";
115+
error = "Wrong pre-verificaiton code";
116+
setTimeout(() => {
117+
error = null;
118+
}, 6_000);
119+
return { data: null };
120+
});
121+
if (!data) return;
132122
133-
const tenYearsLater = new Date();
134-
tenYearsLater.setFullYear(tenYearsLater.getFullYear() + 10);
135-
globalState.userController.user = {
136-
name:
137-
demoName ||
138-
capitalize(`${falso.randFirstName()} ${falso.randLastName()}`),
139-
"Date of Birth": new Date().toDateString(),
140-
"ID submitted": `Passport - ${falso.randCountryCode()}`,
141-
"Passport Number": generatePassportNumber(),
142-
};
143-
globalState.userController.isFake = true;
144-
globalState.userController.document = {
145-
"Valid From": new Date(Date.now()).toDateString(),
146-
"Valid Until": tenYearsLater.toDateString(),
147-
"Verified On": new Date().toDateString(),
148-
};
149-
globalState.vaultController.vault = {
150-
uri,
151-
ename,
123+
// If verification is successful, show demo name input
124+
if (data.success === true) {
125+
loading = false;
126+
verificationSuccess = true;
127+
uri = data.uri;
128+
ename = data.w3id;
129+
}
152130
};
153131
154132
// New function to handle final submission with demo name
@@ -182,8 +160,7 @@ onMount(() => {
182160
goto("/register");
183161
}, 10_000);
184162
};
185-
};
186-
});
163+
});
187164
</script>
188165

189166
<main

0 commit comments

Comments
 (0)