From a8d90ae0fd74ef9af6b2ed428ab21931a425b748 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Wed, 1 Jan 2025 12:51:58 -0700 Subject: [PATCH] add ability to edit & resubmit any raw claim --- src/views/ClaimAddRawView.vue | 60 +++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/views/ClaimAddRawView.vue b/src/views/ClaimAddRawView.vue index 20ac3f0..586bd82 100644 --- a/src/views/ClaimAddRawView.vue +++ b/src/views/ClaimAddRawView.vue @@ -32,10 +32,12 @@ import { Component, Vue } from "vue-facing-decorator"; import { Router } from "vue-router"; +import QuickNav from "@/components/QuickNav.vue"; import { NotificationIface } from "@/constants/app"; -import { retrieveSettingsForActiveAccount } from "@/db/index"; +import { logConsoleAndDb, retrieveSettingsForActiveAccount } from "@/db/index"; import * as serverUtil from "@/libs/endorserServer"; -import QuickNav from "@/components/QuickNav.vue"; +import * as libsUtil from "@/libs/util"; +import { errorStringForLog } from "@/libs/endorserServer"; @Component({ components: { QuickNav }, @@ -54,11 +56,55 @@ export default class ClaimAddRawView extends Vue { this.apiServer = settings.apiServer || ""; this.claimStr = (this.$route as Router).query["claim"]; - try { - this.veriClaim = JSON.parse(this.claimStr); - this.claimStr = JSON.stringify(this.veriClaim, null, 2); - } catch (e) { - // ignore a parse + if (this.claimStr) { + try { + const veriClaim = JSON.parse(this.claimStr); + this.claimStr = JSON.stringify(veriClaim, null, 2); + } catch (e) { + // ignore a parse error + } + } else { + // there may be no link that uses this, meaning you'd have to enter it in a browser + const claimJwtId = (this.$route as Router).query["claimJwtId"]; + if (claimJwtId) { + const urlPath = libsUtil.isGlobalUri(claimJwtId) + ? "/api/claim/byHandle/" + : "/api/claim/"; + const url = this.apiServer + urlPath + encodeURIComponent(claimJwtId); + const headers = await serverUtil.getHeaders(this.activeDid); + + try { + const response = await this.axios.get(url, { headers }); + if (response.status === 200) { + const claim = response.data?.claim; + claim.lastClaimId = serverUtil.stripEndorserPrefix(claimJwtId); + this.claimStr = JSON.stringify(claim, null, 2); + } else { + throw { + message: "Got an error loading that claim.", + response: { + status: response.status, + statusText: response.statusText, + // url is in "fetch" response but not in AxiosResponse + }, + }; + } + } catch (error: unknown) { + logConsoleAndDb( + "Error retrieving claim: " + errorStringForLog(error), + true, + ); + this.$notify( + { + group: "alert", + type: "danger", + title: "Error", + text: "Got an error retrieving claim data.", + }, + 3000, + ); + } + } } }