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
35 changes: 26 additions & 9 deletions infrastructure/eid-wallet/src/routes/(app)/scan-qr/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const {
isRevealingVote,
revealSuccess,
revealedVoteData,
authError,
signingError,
authLoading,
} = stores;

const {
Expand Down Expand Up @@ -95,16 +98,20 @@ $effect(() => {
);
});

function handleAuthDrawerDecline() {
setCodeScannedDrawerOpen(false);
startScan();
async function handleAuthDrawerDecline() {
// If there's an error, "Okay" button closes modal and navigates to main
if ($authError) {
setCodeScannedDrawerOpen(false);
await goto("/main");
} else {
// Otherwise, "Decline" closes modal and restarts scanning
setCodeScannedDrawerOpen(false);
startScan();
}
}

function handleAuthDrawerOpenChange(value: boolean) {
setCodeScannedDrawerOpen(value);
if (!value) {
startScan();
}
}

function handleLoggedInDrawerConfirm() {
Expand All @@ -118,9 +125,16 @@ function handleLoggedInDrawerOpenChange(value: boolean) {
setLoggedInDrawerOpen(value);
}

function handleSigningDrawerDecline() {
setSigningDrawerOpen(false);
startScan();
async function handleSigningDrawerDecline() {
// If there's an error, "Okay" button closes modal and navigates to main
if ($signingError) {
setSigningDrawerOpen(false);
await goto("/main");
} else {
// Otherwise, "Decline" closes modal and restarts scanning
setSigningDrawerOpen(false);
startScan();
}
}

function handleSigningDrawerOpenChange(value: boolean) {
Expand Down Expand Up @@ -177,6 +191,8 @@ function handleRevealDrawerOpenChange(value: boolean) {
hostname={$hostname}
scannedContent={$scannedData?.content}
isSigningRequest={$isSigningRequest}
authError={$authError}
authLoading={$authLoading}
onConfirm={handleAuth}
onDecline={handleAuthDrawerDecline}
onOpenChange={handleAuthDrawerOpenChange}
Expand All @@ -199,6 +215,7 @@ function handleRevealDrawerOpenChange(value: boolean) {
selectedBlindVoteOption={$selectedBlindVoteOption}
isSubmittingBlindVote={$isSubmittingBlindVote}
loading={$loading}
signingError={$signingError}
onDecline={handleSigningDrawerDecline}
onSign={handleSignVote}
onBlindVoteOptionChange={handleBlindVoteOptionChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export let platform: string | null | undefined;
export let hostname: string | null | undefined;
export let scannedContent: string | undefined;
export let isSigningRequest: boolean;
export let authError: string | null | undefined;
export let authLoading: boolean | undefined;
export let onConfirm: () => void;
export let onDecline: () => void;
export let onOpenChange: (value: boolean) => void;
Expand Down Expand Up @@ -63,17 +65,64 @@ $: if (internalOpen !== lastReportedOpen) {
{hostname ?? scannedContent}
</p>
</div>

{#if authError}
<div class="bg-red-50 border border-red-200 rounded-lg p-4 mt-4">
<div class="flex items-center">
<div class="flex-shrink-0">
<svg
class="h-5 w-5 text-red-400"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
clip-rule="evenodd"
/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">Error</h3>
<div class="mt-2 text-sm text-red-700">
{authError}
</div>
</div>
</div>
</div>
{/if}

<div class="flex justify-center gap-3 items-center mt-4">
<Button.Action
variant="danger-soft"
class="w-full"
callback={onDecline}
>
Decline
</Button.Action>
<Button.Action variant="solid" class="w-full" callback={onConfirm}>
Confirm
</Button.Action>
{#if authError}
<Button.Action
variant="solid"
class="w-full"
callback={onDecline}
>
Okay
</Button.Action>
{:else}
<Button.Action
variant="danger-soft"
class="w-full"
callback={onDecline}
disabled={authLoading}
>
Decline
</Button.Action>
<Button.Action
variant="solid"
class="w-full"
callback={onConfirm}
disabled={authLoading}
>
{#if authLoading}
Authenticating...
{:else}
Confirm
{/if}
</Button.Action>
{/if}
</div>

{#if isSigningRequest === false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export let blindVoteError: string | null;
export let selectedBlindVoteOption: number | null;
export let isSubmittingBlindVote: boolean;
export let loading: boolean;
export let signingError: string | null | undefined;
export let onDecline: () => void;
export let onSign: () => void;
export let onBlindVoteOptionChange: (value: number) => void;
Expand Down Expand Up @@ -250,30 +251,66 @@ $: hasPollDetails =
{signingData?.sessionId?.slice(0, 8) ?? "Unknown"}...
</p>
</div>

{#if signingError}
<div class="bg-red-50 border border-red-200 rounded-lg p-4 mt-4">
<div class="flex items-center">
<div class="flex-shrink-0">
<svg
class="h-5 w-5 text-red-400"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
clip-rule="evenodd"
/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">Error</h3>
<div class="mt-2 text-sm text-red-700">
{signingError}
</div>
</div>
</div>
</div>
{/if}
{/if}

<div class="flex justify-center gap-3 items-center mt-4">
{#if !isBlindVotingRequest}
<Button.Action
variant="danger-soft"
class="w-full"
callback={onDecline}
>
Decline
</Button.Action>
<Button.Action
variant="solid"
class="w-full"
callback={onSign}
>
{#if loading}
Signing...
{:else if signingData?.pollId}
Sign Vote
{:else}
Sign Message
{/if}
</Button.Action>
{#if signingError}
<Button.Action
variant="solid"
class="w-full"
callback={onDecline}
>
Okay
</Button.Action>
{:else}
<Button.Action
variant="danger-soft"
class="w-full"
callback={onDecline}
>
Decline
</Button.Action>
<Button.Action
variant="solid"
class="w-full"
callback={onSign}
>
{#if loading}
Signing...
{:else if signingData?.pollId}
Sign Vote
{:else}
Sign Message
{/if}
</Button.Action>
{/if}
{/if}
</div>
{/if}
Expand Down
Loading