diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue
index ea487de..759ea39 100644
--- a/src/views/NewEditProjectView.vue
+++ b/src/views/NewEditProjectView.vue
@@ -145,14 +145,25 @@
-
-
-
+
@@ -237,6 +248,7 @@ export default class NewEditProjectView extends Vue {
projectId = "";
projectIssuerDid = "";
sendToTrustroots = false;
+ sendToTripHopping = false;
showGeneralAdvanced = false;
startDateInput?: string;
startTimeInput?: string;
@@ -371,7 +383,7 @@ export default class NewEditProjectView extends Vue {
}
}
- private async saveProject(issuerDid: string) {
+ private async saveProject() {
// Make a claim
const vcClaim: PlanVerifiableCredential = this.fullClaim;
if (this.projectId) {
@@ -422,13 +434,13 @@ export default class NewEditProjectView extends Vue {
} else {
delete vcClaim.startTime;
}
- const vcJwt = await createEndorserJwtVcFromClaim(issuerDid, vcClaim);
+ const vcJwt = await createEndorserJwtVcFromClaim(this.activeDid, vcClaim);
// Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt });
const url = this.apiServer + "/api/v2/claim";
- const headers = await getHeaders(issuerDid);
+ const headers = await getHeaders(this.activeDid);
try {
const resp = await this.axios.post(url, payload, { headers });
@@ -438,67 +450,14 @@ export default class NewEditProjectView extends Vue {
const projectPath = encodeURIComponent(resp.data.success.handleId);
if (this.sendToTrustroots) {
- // first, get the public key for nostr
- const account = await getAccount(this.activeDid);
- // get the last number of the derivationPath
- const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
- // remove any trailing '
- const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
- const accountNum = Number(finalDerNumNoApostrophe || 0);
- const pubPri = accountFromSeedWords(account?.mnemonic as string, "", accountNum);
- const nostrPubKey = pubPri?.publicKey;
-
- const trustrootsUrl = DEFAULT_PARTNER_API_SERVER + "/api/partner/link";
- const timeSafariUrl = window.location.origin + "/claim/" + resp.data.success.claimId;
- const content = this.fullClaim.name + " - see " + timeSafariUrl;
- const trustrootsParams = new URLSearchParams({
- jwtId: resp.data.success.claimId,
- linkCode: "NOSTR-EVENT-TRUSTROOTS",
- inputJson: JSON.stringify(content),
- nostrPubKeyHex: nostrPubKey,
- });
- const fullTrustrootsUrl = trustrootsUrl + "?" + trustrootsParams.toString();
- const headers = await getHeaders(issuerDid);
- try {
- const linkResp = await this.axios.post(fullTrustrootsUrl, {}, { headers });
- if (linkResp.status === 201) {
- this.$notify(
- {
- group: "alert",
- type: "success",
- title: "Sent to Trustroots",
- text: "The project info was sent to Trustroots.",
- },
- 5000,
- );
- } else {
- // axios never gets here because it throws an error, but just in case
- this.$notify(
- {
- group: "alert",
- type: "danger",
- title: "Failed Sending to Trustroots",
- text: JSON.stringify(linkResp.data),
- },
- 5000,
- );
- }
- } catch (error) {
- console.error("Error sending to Trustroots", error);
- let errorMessage = "There was an error sending to Trustroots.";
- if (error.response?.data?.error?.message) {
- errorMessage = error.response.data.error.message;
- }
- this.$notify(
- {
- group: "alert",
- type: "danger",
- title: "Error Sending to Trustroots",
- text: errorMessage,
- },
- 5000,
- );
- }
+ this.sendToNostrPartner(
+ "NOSTR-EVENT-TRUSTROOTS", "Trustroots", resp.data.success.claimId
+ );
+ }
+ if (this.sendToTripHopping) {
+ this.sendToNostrPartner(
+ "NOSTR-EVENT-TRIPHOPPING", "TripHopping", resp.data.success.claimId
+ );
}
(this.$router as Router).push({ path: "/project/" + projectPath });
@@ -565,6 +524,71 @@ export default class NewEditProjectView extends Vue {
}
}
+ private async sendToNostrPartner(linkCode: string, serviceName: string, jwtId: string) {
+ // first, get the public key for nostr
+ const account = await getAccount(this.activeDid);
+ // get the last number of the derivationPath
+ const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
+ // remove any trailing '
+ const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
+ const accountNum = Number(finalDerNumNoApostrophe || 0);
+ const pubPri = accountFromSeedWords(account?.mnemonic as string, "", accountNum);
+ const nostrPubKey = pubPri?.publicKey;
+
+ const trustrootsUrl = DEFAULT_PARTNER_API_SERVER + "/api/partner/link";
+ const timeSafariUrl = window.location.origin + "/claim/" + jwtId;
+ const content = this.fullClaim.name + " - see " + timeSafariUrl;
+ const trustrootsParams = {
+ jwtId: jwtId,
+ linkCode: linkCode,
+ inputJson: JSON.stringify(content),
+ nostrPubKeyHex: nostrPubKey,
+ };
+ const fullTrustrootsUrl = trustrootsUrl;
+ const headers = await getHeaders(this.activeDid);
+ try {
+ const linkResp = await this.axios.post(fullTrustrootsUrl, trustrootsParams, { headers });
+ if (linkResp.status === 201) {
+ this.$notify(
+ {
+ group: "alert",
+ type: "success",
+ title: `Sent to ${serviceName}`,
+ text: `The project info was sent to ${serviceName}.`,
+ },
+ 5000,
+ );
+ } else {
+ // axios never gets here because it throws an error, but just in case
+ this.$notify(
+ {
+ group: "alert",
+ type: "danger",
+ title: `Failed Sending to ${serviceName}`,
+ text: JSON.stringify(linkResp.data),
+ },
+ 5000,
+ );
+ }
+ } catch (error) {
+ console.error(`Error sending to ${serviceName}`, error);
+ let errorMessage = `There was an error sending to ${serviceName}.`;
+ if (error.response?.data?.error?.message) {
+ errorMessage = error.response.data.error.message;
+ }
+ this.$notify(
+ {
+ group: "alert",
+ type: "danger",
+ title: `Error Sending to ${serviceName}`,
+ text: errorMessage,
+ },
+ 5000,
+ );
+ }
+
+ }
+
public async onSaveProjectClick() {
this.isHiddenSave = true;
this.isHiddenSpinner = false;
@@ -572,7 +596,7 @@ export default class NewEditProjectView extends Vue {
if (this.numAccounts === 0) {
console.error("Error: there is no account.");
} else {
- this.saveProject(this.activeDid);
+ this.saveProject();
}
}