From f2446b0b838f9bc1206c433adec80747b25c562d Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 22 Sep 2024 08:40:24 -0600 Subject: [PATCH 1/4] add nostr Trustroots partner as an option when submitting a project --- src/views/NewEditProjectView.vue | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index c9f199d64..cdffe6925 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -145,6 +145,16 @@ +
+ + +
+
-
- - +
+
+ + +
+
+ + +
@@ -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(); } } From cf797c7702a9f92784263e5b1498467df924938f Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Thu, 26 Sep 2024 09:13:22 -0600 Subject: [PATCH 4/4] disable checkboxes for nostr partner messages; adjust linting warnings --- .eslintrc.js | 9 +++++--- src/components/PhotoDialog.vue | 3 ++- src/views/AccountViewView.vue | 10 ++++++--- src/views/HelpOnboardingView.vue | 3 ++- src/views/HelpView.vue | 2 +- src/views/NewEditProjectView.vue | 38 +++++++++++++++++++++++++------- src/views/ProjectViewView.vue | 5 ++++- src/views/ProjectsView.vue | 5 ++++- src/views/StatisticsView.vue | 15 ++++++++----- 9 files changed, 65 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 58c9c9849..553ac75d8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,15 +17,18 @@ module.exports = { "max-len": [ "warn", { - code: 100, - ignoreComments: true, + code: 120, + ignoreComments: true, // why does this not make it allow comment of any length? + ignorePattern: '^\\s*class="[^"]*"$', + ignoreStrings: true, ignoreTemplateLiterals: true, + ignoreTrailingComments: true, ignoreUrls: true, }, ], "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", - "prettier/prettier": ["warn", { printWidth: 100 }], + // "prettier/prettier": ["warn", { printWidth: 120 }], // removes errors but adds thousands of warnings "@typescript-eslint/no-unnecessary-type-constraint": "off", }, }; diff --git a/src/components/PhotoDialog.vue b/src/components/PhotoDialog.vue index ddf07ad8b..a83890b15 100644 --- a/src/components/PhotoDialog.vue +++ b/src/components/PhotoDialog.vue @@ -76,7 +76,8 @@
- +
- Image Server URL  + Image Server URL +   {{ DEFAULT_IMAGE_API_SERVER }}
- Partner Server URL  + Partner Server URL {{ DEFAULT_PARTNER_API_SERVER }}
diff --git a/src/views/HelpOnboardingView.vue b/src/views/HelpOnboardingView.vue index e6c6b116d..9685dfa99 100644 --- a/src/views/HelpOnboardingView.vue +++ b/src/views/HelpOnboardingView.vue @@ -50,7 +50,8 @@

Discuss Backups

- 8) Exporting backups are important if they lose their phone --- especially for the Identifier Seed! + 8) Exporting backups are important if they lose their phone + --- especially for the Identifier Seed!

diff --git a/src/views/HelpView.vue b/src/views/HelpView.vue index cf3c9a1ca..89f4f8db8 100644 --- a/src/views/HelpView.vue +++ b/src/views/HelpView.vue @@ -21,7 +21,7 @@
- +

This app focuses on gifts & gratitude, using them to build cool things together with your network. diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 759ea39e8..c91138d4a 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -145,7 +145,10 @@

- - +