Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
fix: redirect on policy verification failed
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkar-jain committed Oct 31, 2023
1 parent 7cbac6f commit 52d52c8
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions web/src/pages/exchange/presentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
</template>

<template v-if="!immediateAccept" v-slot:menu>
<ActionButton icon="heroicons:x-mark" class="inline-flex focus:outline focus:outline-red-700 focus:outline-offset-2 items-center rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700 hover:scale-105 hover:animate-pulse focus:animate-none"
display-text="Reject"
type="button" @click="navigateTo('/')"/>

<ActionButton icon="heroicons:check" :failed="failed" class="inline-flex focus:outline focus:outline-offset-2 items-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm"
:class="[failed ? 'bg-red-600 animate-pulse focus:outline focus:outline-red-700 focus:outline-offset-2 hover:bg-red-700 hover:scale-105' : 'bg-green-600 focus:outline-green-700 hover:bg-green-700 hover:scale-105 hover:animate-pulse focus:animate-none']"
display-text="Accept"
type="button" @click="acceptPresentation"/>
<ActionButton icon="heroicons:x-mark"
class="inline-flex focus:outline focus:outline-red-700 focus:outline-offset-2 items-center rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700 hover:scale-105 hover:animate-pulse focus:animate-none"
display-text="Reject" type="button" @click="navigateTo('/')" />

<ActionButton icon="heroicons:check" :failed="failed"
class="inline-flex focus:outline focus:outline-offset-2 items-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm"
:class="[failed ? 'bg-red-600 animate-pulse focus:outline focus:outline-red-700 focus:outline-offset-2 hover:bg-red-700 hover:scale-105' : 'bg-green-600 focus:outline-green-700 hover:bg-green-700 hover:scale-105 hover:animate-pulse focus:animate-none']"
display-text="Accept" type="button" @click="acceptPresentation" />
</template>
</PageHeader>
<CenterMain>
Expand All @@ -31,17 +31,20 @@

<div aria-label="Credential list" class="h-full overflow-y-auto shadow-xl">
<div v-for="group in groupedCredentialTypes.keys()" :key="group.id" class="relative">
<div class="sticky top-0 z-10 border-y border-b-gray-200 border-t-gray-100 bg-gray-50 px-3 py-1.5 text-sm font-semibold leading-6 text-gray-900">
<div
class="sticky top-0 z-10 border-y border-b-gray-200 border-t-gray-100 bg-gray-50 px-3 py-1.5 text-sm font-semibold leading-6 text-gray-900">
<h3>{{ group }}s:</h3>
</div>
<ul class="divide-y divide-gray-100" role="list">
<li v-for="credential in groupedCredentialTypes.get(group)" :key="credential" class="flex gap-x-4 px-3 py-5">
<li v-for="credential in groupedCredentialTypes.get(group)" :key="credential"
class="flex gap-x-4 px-3 py-5">

<CredentialIcon :credentialType="credential.name" class="h-6 w-6 flex-none rounded-full bg-gray-50"></CredentialIcon>
<CredentialIcon :credentialType="credential.name"
class="h-6 w-6 flex-none rounded-full bg-gray-50"></CredentialIcon>

<div class="min-w-0 flex flex-row items-center">
<span class="text-lg font-semibold leading-6 text-gray-900">{{ credential.id }}.</span> <span
class="ml-1 truncate text-sm leading-5 text-gray-800">{{ credential.name }}</span>
<span class="text-lg font-semibold leading-6 text-gray-900">{{ credential.id }}.</span>
<span class="ml-1 truncate text-sm leading-5 text-gray-800">{{ credential.name }}</span>
</div>
</li>
</ul>
Expand All @@ -53,17 +56,17 @@

<script lang="ts" setup>
import CenterMain from "~/components/CenterMain.vue";
import {CheckIcon, XMarkIcon} from '@heroicons/vue/24/outline'
import { CheckIcon, XMarkIcon } from '@heroicons/vue/24/outline'
import PageHeader from "~/components/PageHeader.vue";
import CredentialIcon from "~/components/CredentialIcon.vue";
import ActionButton from "~/components/buttons/ActionButton.vue";
import LoadingIndicator from "~/components/loading/LoadingIndicator.vue";
import {groupBy} from "~/composables/groupings";
import {useTitle} from "@vueuse/core";
import { groupBy } from "~/composables/groupings";
import { useTitle } from "@vueuse/core";
async function resolvePresentationRequest(request) {
try {
console.log("RESOLVING request", request)
console.log("RESOLVING request", request)
const response = await $fetch("/r/wallet/exchange/resolvePresentationRequest", { method: 'POST', body: request })
console.log(response)
return response
Expand Down Expand Up @@ -92,7 +95,7 @@ console.log("inputDescriptors: ", inputDescriptors)
let i = 0
let groupedCredentialTypes = groupBy(inputDescriptors.map(item => {
return {id: ++i, name: item.id}
return { id: ++i, name: item.id }
}), c => c.name)
console.log("groupedCredentialTypes: ", groupedCredentialTypes)
Expand All @@ -112,19 +115,19 @@ async function acceptPresentation() {
if (response.redirectUri) {
window.location.href = response.redirectUri
}
/*setInterval(async () => {
let sessionId = presentationUrl.searchParams.get('state');
let response = await fetch(`https://verifier.portal.walt.id/vp/session/${sessionId}`);
response = await response.json();
if (response.verificationResult) {
window.location.href = `https://portal.walt.id/success/${sessionId}`;
}
}, 1000);*/
} catch (e) {
failed.value = true
window.alert(e)
throw e
console.log("Policy verification failed: ", e)
let sessionId = presentationUrl.searchParams.get('state');
let response = await fetch(`https://verifier.portal.walt.id/vp/session/${sessionId}`);
response = await response.json();
if (response.verificationResult) {
window.location.href = `https://portal.walt.id/success/${sessionId}`;
}
// failed.value = true
// window.alert(e)
// throw e
}
}
Expand All @@ -137,6 +140,4 @@ if (query.accept) { // TODO make accept a JWT or something wallet-backend secure
useTitle(`Present credentials - walt.id`)
</script>

<style scoped>
</style>
<style scoped></style>

0 comments on commit 52d52c8

Please sign in to comment.