Skip to content

Commit 2149ab2

Browse files
committed
fix: coderabbit suggestions
1 parent 14e726b commit 2149ab2

File tree

11 files changed

+115
-23
lines changed

11 files changed

+115
-23
lines changed

.vscode/settings.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77
"editor.defaultFormatter": "rust-lang.rust-analyzer",
88
"editor.formatOnSave": true
99
},
10-
"[js,ts,svelte]": {
10+
"[javascript]": {
11+
"editor.defaultFormatter": "biomejs.biome",
12+
"editor.codeActionsOnSave": {
13+
"source.organizeImports.biome": "explicit",
14+
"source.fixAll.biome": "explicit"
15+
}
16+
},
17+
"[typescript]": {
18+
"editor.defaultFormatter": "biomejs.biome",
19+
"editor.codeActionsOnSave": {
20+
"source.organizeImports.biome": "explicit",
21+
"source.fixAll.biome": "explicit"
22+
}
23+
},
24+
"[svelte]": {
1125
"editor.defaultFormatter": "biomejs.biome",
1226
"editor.codeActionsOnSave": {
1327
"source.organizeImports.biome": "explicit",

infrastructure/eid-wallet/src-tauri/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,41 @@ mod funcs;
77
// format!("Hello, {}! You've been greeted from Rust!", name)
88
// }
99

10+
/// Hashes a PIN using Argon2 with a random salt
11+
///
12+
/// # Arguments
13+
/// * `pin` - A string containing the user's PIN
14+
///
15+
/// # Returns
16+
/// * `Result<String, String>` - The hashed PIN string or an error message
1017
#[tauri::command]
1118
async fn hash(pin: String) -> Result<String, String> {
12-
Ok(funcs::hash(pin).map_err(|err| err.to_string())?)
19+
funcs::hash(pin).map_err(|err| format!("Failed to hash PIN: {}", err))
1320
}
1421

22+
/// Verifies a PIN against a stored hash using Argon2
23+
///
24+
/// # Arguments
25+
/// * `pin` - A string containing the user's PIN to verify
26+
/// * `hash` - The stored hash to compare against
27+
///
28+
/// # Returns
29+
/// * `Result<bool, String>` - Whether the PIN matches the hash, or an error message
1530
#[tauri::command]
1631
async fn verify(pin: String, hash: String) -> Result<bool, String> {
17-
Ok(funcs::verify(pin, hash).map_err(|err| err.to_string())?)
32+
funcs::verify(pin, hash).map_err(|err| format!("Failed to verify PIN: {}", err))
1833
}
1934

2035
#[cfg_attr(mobile, tauri::mobile_entry_point)]
2136
pub fn run() {
2237
tauri::Builder::default()
23-
.plugin(tauri_plugin_barcode_scanner::init())
2438
.plugin(tauri_plugin_opener::init())
2539
.plugin(tauri_plugin_store::Builder::new().build())
2640
.setup(move |_app| {
2741
#[cfg(mobile)]
2842
{
2943
_app.handle().plugin(tauri_plugin_biometric::init())?;
44+
_app.handle().plugin(tauri_plugin_barcode_scanner::init())?;
3045
}
3146
Ok(())
3247
})

infrastructure/eid-wallet/src/lib/global/controllers/security.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class SecurityController {
130130
throw new Error("Invalid pin");
131131
}
132132
await this.#setPin(newPin);
133+
return;
133134
}
134135
throw new Error("Old pin not provided!");
135136
}
@@ -189,7 +190,10 @@ export class SecurityController {
189190
* ```
190191
*/
191192
set biometricSupport(value: boolean | Promise<boolean>) {
192-
this.#setBiometric(value);
193+
this.#setBiometric(value).catch((error) => {
194+
console.error("Failed to set biometric support:", error);
195+
// Consider how to handle errors in a setter - possibly notify via an event
196+
});
193197
}
194198

195199
/**

infrastructure/eid-wallet/src/lib/global/controllers/user.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,35 @@ export class UserController {
5454
* ```
5555
* @throws {Error} If the user state cannot be set in the store
5656
*/
57-
set user(user:
58-
| Promise<Record<string, string> | undefined>
59-
| Record<string, string>
60-
| undefined) {
61-
this.#store.set("user", user);
57+
set user(
58+
user:
59+
| Promise<Record<string, string> | undefined>
60+
| Record<string, string>
61+
| undefined
62+
) {
63+
if (user instanceof Promise) {
64+
user.then((resolvedUser) => {
65+
this.#store.set("user", resolvedUser);
66+
}).catch((error) => {
67+
console.error("Failed to set user:", error);
68+
});
69+
} else {
70+
this.#store.set("user", user);
71+
}
6272
}
6373

6474
get user() {
65-
return this.#store.get<Record<string, string>>("user").then((user) => {
66-
if (!user) {
75+
return this.#store
76+
.get<Record<string, string>>("user")
77+
.then((user) => {
78+
if (!user) {
79+
return undefined;
80+
}
81+
return user;
82+
})
83+
.catch((error) => {
84+
console.error("Failed to get user:", error);
6785
return undefined;
68-
}
69-
return user;
70-
});
86+
});
7187
}
7288
}

infrastructure/eid-wallet/src/lib/ui/InputPin/InputPin.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const changeHandler = (e: KeyboardEvent, i: number) => {
6464
const regx = /^\d+$/;
6565
6666
if (isKeyDelete(e.key)) {
67+
e.preventDefault()
6768
if (pins[i] !== "") {
6869
pins[i] = "";
6970
return;
@@ -75,12 +76,24 @@ const changeHandler = (e: KeyboardEvent, i: number) => {
7576
}
7677
7778
if (regx.test(e.key)) {
79+
e.preventDefault()
7880
pins[i] = e.key;
7981
if (currentIndex < items.length - 1) {
8082
newIndex = currentIndex + 1;
8183
(items[newIndex] as HTMLInputElement)?.focus();
8284
}
8385
}
86+
87+
// Allow arrow keys for navigation
88+
if (e.key === 'ArrowLeft' && currentIndex > 0) {
89+
newIndex = currentIndex - 1;
90+
(items[newIndex] as HTMLInputElement)?.focus();
91+
}
92+
93+
if (e.key === 'ArrowRight' && currentIndex < items.length - 1) {
94+
newIndex = currentIndex + 1;
95+
(items[newIndex] as HTMLInputElement)?.focus();
96+
}
8497
};
8598
8699
const createArray = (size: number) => {
@@ -125,7 +138,6 @@ const cBase =
125138
}}
126139
maxlength="1"
127140
onkeydown={(event) => {
128-
event.preventDefault()
129141
changeHandler(event, i)
130142
}}
131143
placeholder=""

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function startScan() {
5959
const formats = [Format.QRCode];
6060
const windowed = true;
6161
62+
if (scanning) return;
6263
scanning = true;
6364
scan({ formats, windowed })
6465
.then((res) => {
@@ -74,6 +75,9 @@ async function startScan() {
7475
scanning = false;
7576
});
7677
}
78+
79+
console.error("Permission denied or not granted");
80+
// TODO: consider handling GUI for permission denied
7781
}
7882
7983
async function cancelScan() {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ const authOpts: AuthOptions = {
3333
3434
onMount(async () => {
3535
globalState = getContext<() => GlobalState>("globalState")();
36-
if (!globalState) throw new Error("Global state is not defined");
36+
if (!globalState) {
37+
console.error("Global state is not defined");
38+
await goto("/"); // Redirect to home or error page
39+
return;
40+
}
3741
3842
clearPin = async () => {
3943
await globalState?.securityController.clearPin();
@@ -43,7 +47,7 @@ onMount(async () => {
4347
handlePinInput = async (pin: string) => {
4448
if (pin.length === 4) {
4549
isError = false;
46-
const check = await globalState?.securityController.verifyPin(pin);
50+
const check = globalState ? await globalState.securityController.verifyPin(pin) : false;
4751
if (!check) {
4852
isError = true;
4953
return;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ onMount(async () => {
7272
"Cannot set biometric support, Global state is not defined",
7373
);
7474
if (isBiometricsAvailable) {
75-
globalState.securityController.biometricSupport = true;
75+
try {
76+
globalState.securityController.biometricSupport = true;
77+
} catch (error) {
78+
console.error("Failed to enable biometric support:", error);
79+
// Consider showing an error message to the user
80+
return;
81+
}
7682
}
7783
isBiometricsAdded = true;
7884
};

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,12 @@ onMount(() => {
3333
/>
3434
<img class="mx-auto mt-20" src="images/Passport.svg" alt="passport">
3535
</section>
36-
<ButtonAction class="w-full" callback={async() => handleVerification()}>I'm ready</ButtonAction>
36+
<ButtonAction class="w-full" callback={async() => {
37+
try {
38+
await handleVerification();
39+
} catch (error) {
40+
console.error("Verification failed:", error);
41+
// Consider adding user-facing error handling here
42+
}
43+
}}>I'm ready</ButtonAction>
3744
</main>

infrastructure/eid-wallet/src/routes/+layout.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ onMount(async () => {
3838
};
3939
}
4040
runtime.biometry = status.biometryType;
41-
globalState = await GlobalState.create();
41+
try {
42+
globalState = await GlobalState.create();
43+
} catch (error) {
44+
console.error("Failed to initialize global state:", error);
45+
// Consider adding fallback behavior or user notification
46+
}
4247
4348
showSplashScreen = true; // Can't set up the original state to true or animation won't start
4449
navigationStack.push(window.location.pathname);

0 commit comments

Comments
 (0)