Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion infrastructure/control-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
"lucide-svelte": "^0.539.0",
"tailwind-merge": "^3.0.2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ $effect(() => {
pin = calcPin(pins);
});

$effect(() => {
if (pin === "") {
for (const key of Object.keys(pins)) {
pins[+key] = "";
}
}
});

const calcPin = (pins: { [key: number]: string }) => {
return Object.values(pins).join("") || "";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { goto } from "$app/navigation";
import type { GlobalState } from "$lib/global";
import { runtime } from "$lib/global/runtime.svelte";
import { ButtonAction, Drawer, InputPin } from "$lib/ui";
Expand All @@ -16,6 +17,7 @@ let showDrawer = $state(false);
const handleClose = async () => {
// close functionality goes here.
showDrawer = false;
goto("/settings");
};

const handleChangePIN = async () => {
Expand All @@ -30,7 +32,11 @@ const handleChangePIN = async () => {
}

try {
await globalState?.securityController.updatePin(currentPin, newPin);
await globalState?.securityController.updatePin(
newPin,
repeatPin,
currentPin,
);
isError = false;
showDrawer = true;
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ onMount(async () => {
}

clearPin = async () => {
await globalState?.securityController.clearPin();
goto("/");
pin = "";
isError = false;
};

handlePinInput = async (pin: string) => {
Expand Down
57 changes: 46 additions & 11 deletions infrastructure/eid-wallet/src/routes/(auth)/register/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ let isBiometricsAvailable = $state(false);
let isBiometricScreen = $state(false);
let isBiometricsAdded = $state(false);
let isError = $state(false);
let btnVariant = $state<"soft" | "solid">("soft");

let globalState: GlobalState | undefined = $state(undefined);

const handleFirstStep = async () => {
if (pin.length === 4) firstStep = false;
if (pin.length === 4) {
firstStep = false;
btnVariant = "solid";
}
};

let handleConfirm: () => Promise<void> = $state(async () => {});
Expand All @@ -47,6 +51,21 @@ $effect(() => {
isError = false;
});

$effect(() => {
// First step button
if (firstStep) {
btnVariant = pin.length === 4 ? "solid" : "soft";
} else {
// Second step button
if (repeatPin.length === 4 && pin === repeatPin) {
btnVariant = "solid";
isError = false;
} else {
btnVariant = "soft";
}
}
});

onMount(async () => {
globalState = getContext<() => GlobalState>("globalState")();
if (!globalState) throw new Error("Global state is not defined");
Expand All @@ -55,17 +74,27 @@ onMount(async () => {
console.log("isBiometricsAvailable", isBiometricsAvailable);

handleConfirm = async () => {
//confirm pin logic goes here
if (repeatPin && repeatPin.length === 4 && pin !== repeatPin) {
firstStep = true;
if (repeatPin.length < 4) {
isError = true;
} else {
isError = false;
showDrawer = true;
await globalState?.securityController.updatePin(pin, repeatPin);
return;
}

if (pin !== repeatPin) {
isError = true;
firstStep = true;
return;
}

isError = false;
try {
await globalState?.securityController.updatePin(pin, repeatPin);
showDrawer = true;
} catch (error) {
console.error("Failed to update PIN:", error);
isError = true;
}
};

handleSetupBiometrics = async () => {
if (!globalState)
throw new Error(
Expand Down Expand Up @@ -103,7 +132,11 @@ onMount(async () => {
Your PIN does not match, try again.
</p>
</section>
<ButtonAction class="w-full" variant="soft" callback={handleFirstStep}>
<ButtonAction
class="w-full"
variant={btnVariant}
callback={handleFirstStep}
>
Confirm
</ButtonAction>
</main>
Expand All @@ -119,8 +152,10 @@ onMount(async () => {
</Hero>
<InputPin bind:pin={repeatPin} />
</section>
<ButtonAction class="w-full" callback={handleConfirm}
>Confirm</ButtonAction
<ButtonAction
variant={btnVariant}
class="w-full"
callback={handleConfirm}>Confirm</ButtonAction
>
</main>
{/if}
Expand Down