Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask credential #123

Merged
merged 8 commits into from
Feb 6, 2024
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"devDependencies": {
"@capacitor/assets": "^3.0.4",
"@faker-js/faker": "^8.4.0",
"@lottiefiles/svelte-lottie-player": "^0.3.1",
"@playwright/test": "^1.28.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.1.0",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/lib/slangroom/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Then print data
}
};

export const getService = async (id: string): Promise<Response> => {
export const getService = async (id: string): Promise<Response<Service>> => {
try {
const res = await slangroom.execute(
`Rule unknown ignore
Expand All @@ -59,7 +59,9 @@ Given I connect to 'path' and do get and output into 'http_result'
Given I have a 'string dictionary' named 'http_result'
Then print data`,
{
data: { path: `${PUBLIC_BACKEND_URL}/api/collections/services/records/${id}?expand=templates` }
data: {
path: `${PUBLIC_BACKEND_URL}/api/collections/services/records/${id}?expand=templates`
}
}
);
return res.result.http_result.result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getService } from '$lib/slangroom/services.js';

export const load = async ({ params }) => {
const credential = getService(params.id)
return {credential};
};
const credential = await getService(params.id);
return { credential };
};
93 changes: 93 additions & 0 deletions src/routes/(protected)/[id]/credential-offer/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<script lang="ts">
import Logo from '$lib/components/atoms/Logo.svelte';
import JSONSchemaForm from '$lib/JSONSchemaForms/JSONSchemaForm.svelte';
import JSONSchemaParser from '$lib/JSONSchemaForms/JSONSchemaParser.svelte';
import ErrorDisplay from '$lib/components/errorDisplay.svelte';
import { fly } from 'svelte/transition';
import { thumbsUpOutline } from 'ionicons/icons';
import { goto } from '$app/navigation';
import { LottiePlayer } from '@lottiefiles/svelte-lottie-player';
export let data: any;
const { credential } = data;
let isModalOpen: boolean = false;
let isCredentialVerified: boolean = false;

const getCredential = () => {
isModalOpen = true;
setTimeout(() => {
isCredentialVerified = true;
setTimeout(() => {
isModalOpen = false;
goto('/home');
}, 3000);
}, 5000);
};
</script>

<ion-header>
<ion-toolbar>
<ion-title>
<div class="flex items-center gap-2">
<Logo />
<h1 class="text-2xl">Credential offer</h1>
</div>
</ion-title>
</ion-toolbar>
</ion-header>

<ion-content fullscreen class="ion-padding">
<div class="flex h-full flex-col justify-between pb-16">
<div>
<div class="text-on flex items-center gap-2 text-xl font-semibold not-italic">
<d-avatar name={credential.name}></d-avatar>
<d-heading size="s">{credential.name}</d-heading>
</div>
<div class="mt-2 flex flex-col gap-2">
<d-text size="l">{credential.expand.templates[0].name}</d-text>
<div class="flex flex-col gap-4">
<d-text size="s"
>Lorem ipsum dolor sit amet consectetur. Leo ultricies pellentesque morbi in eu metus commodo felis.
Pellentesque facilisis a auctor enim lectus. Nulla dolor cras viverra massa.</d-text
>
</div>
</div>
</div>

<JSONSchemaParser schema={credential.expand.templates[0].schema} let:schema>
<JSONSchemaForm {schema} onSubmit={() => {}} />
<svelte:fragment slot="error" let:error>
<ErrorDisplay name={error.name} message={error.message} />
</svelte:fragment>
</JSONSchemaParser>
<pre>{credential.expand.templates[0].schema}</pre>
<div class="w-full">
<ion-button expand="block" on:click={getCredential} on:keydown={getCredential} aria-hidden
>Get this credential</ion-button
>
<ion-button expand="block" href="/home">decline</ion-button>
</div>
</div>
<ion-modal is-open={isModalOpen} backdrop-dismiss={false} transition:fly class="visible">
<ion-content class="ion-padding">
<div class="flex h-full flex-col justify-around">
<div>
{#if !isCredentialVerified}
We are generating this credential
<d-credential-card name={credential.name} issuer={credential.issuer} description={credential.description} />
<LottiePlayer
src="https://assets2.lottiefiles.com/packages/lf20_wxUJzo.json"
autoplay={true}
loop={true}
renderer="svg"
background="transparent"
/>
{:else}
<div class="flex w-full justify-around">
<ion-icon icon={thumbsUpOutline} class="mx-auto my-6 text-9xl text-green-400"></ion-icon>
</div>
{/if}
</div>
</div>
</ion-content>
</ion-modal>
</ion-content>
2 changes: 1 addition & 1 deletion src/routes/(protected)/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="flex flex-col gap-2">
{#each services as service}
<d-credential-service name={service.name} issuer={service.issuer} href={`/request/${service.id}`} />
<d-credential-service name={service.name} issuer={service.issuer} href={`/${service.id}/credential-offer`} />
{/each}
</div>
{/await}
Expand Down
19 changes: 0 additions & 19 deletions src/routes/(protected)/request/[id]/+page.svelte

This file was deleted.

4 changes: 0 additions & 4 deletions src/routes/(protected)/scan/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { goto } from '$app/navigation';
import Modal from '$lib/components/molecules/Modal.svelte';
import Scanner from '$lib/components/organisms/scanner/Scanner.svelte';
import { parseQr, verifyCredential, type Credential } from '$lib/components/organisms/scanner/tools';
Expand All @@ -9,7 +8,6 @@
let res: any;

const request = async (credential: Credential) => {
// isModalOpen = false;
res = await verifyCredential(credential);
};
</script>
Expand All @@ -21,12 +19,10 @@
isModalOpen = true;
}}
>
<!-- {JSON.stringify(res)} -->
<Modal {isModalOpen} closeCb={scan}>
{@const parsedQr = parseQr(barcode)}
{#if !(parsedQr?.result === 'ok')}
<ion-title>{parsedQr?.message || 'error'}</ion-title>
<!-- {barcode} -->
{:else}
{@const { name, issuedBy, url } = parsedQr.credential}
<ion-title>{name}</ion-title>
Expand Down
Loading