forked from trent_larson/crowd-funder-for-time-pwa
fix 'give' query and restore confirmClaim method
This commit is contained in:
@@ -99,6 +99,11 @@ export function numberOrZero(str: string): number {
|
||||
return isNumeric(str) ? +str : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* from https://tools.ietf.org/html/rfc3986#section-3
|
||||
* also useful is https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Definition
|
||||
**/
|
||||
export const isGlobalUri = (uri: string) => {
|
||||
return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/));
|
||||
};
|
||||
|
||||
@@ -442,7 +442,7 @@ import { NotificationIface } from "../constants/app";
|
||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as serverUtil from "../libs/endorserServer";
|
||||
import { GiveSummaryRecord } from "../interfaces";
|
||||
import { GenericVerifiableCredential, GiveSummaryRecord } from "../interfaces";
|
||||
import { displayAmount } from "../libs/endorserServer";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import { retrieveAccountDids } from "../libs/util";
|
||||
@@ -621,7 +621,8 @@ export default class ConfirmGiftView extends Vue {
|
||||
* Fetches detailed give information
|
||||
*/
|
||||
private async fetchGiveDetails(claimId: string, userDid: string) {
|
||||
const giveUrl = `${this.apiServer}/api/v2/report/gives?handleId=${encodeURIComponent(claimId)}`;
|
||||
const param = libsUtil.isGlobalUri(claimId) ? "handleId" : "jwtId";
|
||||
const giveUrl = `${this.apiServer}/api/v2/report/gives?${param}=${encodeURIComponent(claimId)}`;
|
||||
|
||||
try {
|
||||
const headers = await serverUtil.getHeaders(userDid);
|
||||
@@ -645,15 +646,10 @@ export default class ConfirmGiftView extends Vue {
|
||||
if (!this.giveDetails) return;
|
||||
|
||||
this.urlForNewGive = "/gifted-details?";
|
||||
this.addGiveDetailsToUrl();
|
||||
this.processParticipantInfo();
|
||||
this.processAdditionalDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds basic give details to URL
|
||||
*/
|
||||
private addGiveDetailsToUrl() {
|
||||
/**
|
||||
* Add basic give details to URL
|
||||
*/
|
||||
if (this.giveDetails?.amount) {
|
||||
this.urlForNewGive += `&amountInput=${encodeURIComponent(String(this.giveDetails.amount))}`;
|
||||
}
|
||||
@@ -663,12 +659,10 @@ export default class ConfirmGiftView extends Vue {
|
||||
if (this.giveDetails?.description) {
|
||||
this.urlForNewGive += `&description=${encodeURIComponent(this.giveDetails.description)}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes participant (giver/recipient) information
|
||||
*/
|
||||
private processParticipantInfo() {
|
||||
/**
|
||||
* Add participant (giver/recipient) name & URL info
|
||||
*/
|
||||
if (this.giveDetails?.agentDid) {
|
||||
this.giverName = this.didInfo(this.giveDetails.agentDid);
|
||||
this.urlForNewGive += `&giverDid=${encodeURIComponent(this.giveDetails.agentDid)}&giverName=${encodeURIComponent(this.giverName)}`;
|
||||
@@ -677,12 +671,10 @@ export default class ConfirmGiftView extends Vue {
|
||||
this.recipientName = this.didInfo(this.giveDetails.recipientDid);
|
||||
this.urlForNewGive += `&recipientDid=${encodeURIComponent(this.giveDetails.recipientDid)}&recipientName=${encodeURIComponent(this.recipientName)}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes additional give details (image, offer, plan)
|
||||
*/
|
||||
private processAdditionalDetails() {
|
||||
/**
|
||||
* Add additional give details to URL (image, offer, plan)
|
||||
*/
|
||||
if (this.giveDetails?.fullClaim.image) {
|
||||
this.urlForNewGive += `&image=${encodeURIComponent(this.giveDetails.fullClaim.image)}`;
|
||||
}
|
||||
@@ -803,6 +795,53 @@ export default class ConfirmGiftView extends Vue {
|
||||
);
|
||||
}
|
||||
|
||||
// similar code is found in ProjectViewView
|
||||
async confirmClaim() {
|
||||
// similar logic is found in endorser-mobile
|
||||
const goodClaim = serverUtil.removeSchemaContext(
|
||||
serverUtil.removeVisibleToDids(
|
||||
serverUtil.addLastClaimOrHandleAsIdIfMissing(
|
||||
this.veriClaim.claim,
|
||||
this.veriClaim.id,
|
||||
this.veriClaim.handleId,
|
||||
),
|
||||
),
|
||||
);
|
||||
const confirmationClaim: GenericVerifiableCredential = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "AgreeAction",
|
||||
object: goodClaim,
|
||||
};
|
||||
const result = await serverUtil.createAndSubmitClaim(
|
||||
confirmationClaim,
|
||||
this.activeDid,
|
||||
this.apiServer,
|
||||
this.axios,
|
||||
);
|
||||
if (result.type === "success") {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Success",
|
||||
text: "Confirmation submitted.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
} else {
|
||||
console.error("Got error submitting the confirmation:", result);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "There was a problem submitting the confirmation.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies user why they cannot confirm the gift
|
||||
* Explains requirements or restrictions preventing confirmation
|
||||
|
||||
Reference in New Issue
Block a user