Browse Source

adjust to change of confirmed -> amountConfirmed

pull/15/head
Trent Larson 2 years ago
parent
commit
00182443fd
  1. 7
      src/libs/endorserServer.ts
  2. 14
      src/views/ContactAmountsView.vue
  3. 4
      src/views/ContactsView.vue

7
src/libs/endorserServer.ts

@ -4,13 +4,15 @@ export const SERVICE_ID = "endorser.ch";
export interface AgreeVerifiableCredential {
"@context": string;
"@type": string;
// "any" because arbitrary objects can be subject of agreement
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: Record<any, any>;
}
export interface GiveServerRecord {
agentDid: string;
amount: number;
confirmed: number;
amountConfirmed: number;
description: string;
fullClaim: GiveVerifiableCredential;
handleId: string;
@ -20,10 +22,11 @@ export interface GiveServerRecord {
}
export interface GiveVerifiableCredential {
"@context": string;
"@context"?: string; // optional when embedded, eg. in an Agree
"@type": string;
agent: { identifier: string };
description?: string;
identifier?: string;
object: { amountOfThisGood: number; unitCode: string };
recipient: { identifier: string };
}

14
src/views/ContactAmountsView.vue

@ -68,7 +68,7 @@
<span v-if="record.agentDid == contact.did">
<div class="font-bold">
{{ record.amount }} {{ record.unit }}
<span v-if="record.confirmed" class="tooltip">
<span v-if="record.amountConfirmed" class="tooltip">
<fa icon="circle-check" class="text-green-600 fa-fw ml-1" />
<span class="tooltiptext">Confirmed</span>
</span>
@ -94,7 +94,7 @@
<span v-if="record.agentDid != contact.did">
<div class="font-bold">
{{ record.amount }} {{ record.unit }}
<span v-if="record.confirmed" class="tooltip">
<span v-if="record.amountConfirmed" class="tooltip">
<fa icon="circle-check" class="text-green-600 fa-fw ml-1" />
<span class="tooltiptext">Confirmed</span>
</span>
@ -134,10 +134,8 @@ import { AppString } from "@/constants/app";
import { accessToken, SimpleSigner } from "@/libs/crypto";
import {
AgreeVerifiableCredential,
GiveServerRecord,
RegisterVerifiableCredential,
GiveServerRecord, GiveVerifiableCredential,
SCHEMA_ORG_CONTEXT,
SERVICE_ID,
} from "@/libs/endorserServer";
import * as didJwt from "did-jwt";
import { AxiosError } from "axios";
@ -243,7 +241,9 @@ export default class ContactsView extends Vue {
async confirm(record: GiveServerRecord) {
// Make claim
// I use clone here because otherwise it gets a Proxy object.
const origClaim: Record<any, any> = R.clone(record.fullClaim);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const origClaim: GiveVerifiableCredential =
R.clone(record.fullClaim);
if (record.fullClaim["@context"] == SCHEMA_ORG_CONTEXT) {
delete origClaim["@context"];
}
@ -294,7 +294,7 @@ export default class ContactsView extends Vue {
const resp = await this.axios.post(url, payload, { headers });
//console.log("Got resp data:", resp.data);
if (resp.data?.success) {
record.confirmed = 1;
record.amountConfirmed = origClaim.object?.amountOfThisGood || 1;
}
} catch (error) {
let userMessage = "There was an error. See logs for more info.";

4
src/views/ContactsView.vue

@ -326,7 +326,7 @@ export default class ContactsView extends Vue {
for (const give of allData) {
if (give.unit == "HUR") {
const recipDid: string = give.recipientDid;
if (give.confirmed) {
if (give.amountConfirmed) {
const prevAmount = contactConfirmed[recipDid] || 0;
contactConfirmed[recipDid] = prevAmount + give.amount;
} else {
@ -380,7 +380,7 @@ export default class ContactsView extends Vue {
const allData: Array<GiveServerRecord> = resp.data.data;
for (const give of allData) {
if (give.unit == "HUR") {
if (give.confirmed) {
if (give.amountConfirmed) {
const prevAmount = contactConfirmed[give.agentDid] || 0;
contactConfirmed[give.agentDid] = prevAmount + give.amount;
} else {

Loading…
Cancel
Save