|
@ -70,8 +70,7 @@ |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script lang="ts"> |
|
|
<script lang="ts"> |
|
|
import * as R from "ramda"; |
|
|
import { Component, Vue } from "vue-facing-decorator"; |
|
|
import { Options, Vue } from "vue-class-component"; |
|
|
|
|
|
|
|
|
|
|
|
import GiftedDialog from "@/components/GiftedDialog.vue"; |
|
|
import GiftedDialog from "@/components/GiftedDialog.vue"; |
|
|
import { db, accountsDB } from "@/db"; |
|
|
import { db, accountsDB } from "@/db"; |
|
@ -83,7 +82,7 @@ import { Contact } from "@/db/tables/contacts"; |
|
|
import AlertMessage from "@/components/AlertMessage"; |
|
|
import AlertMessage from "@/components/AlertMessage"; |
|
|
import QuickNav from "@/components/QuickNav"; |
|
|
import QuickNav from "@/components/QuickNav"; |
|
|
|
|
|
|
|
|
@Options({ |
|
|
@Component({ |
|
|
components: { GiftedDialog, AlertMessage, QuickNav }, |
|
|
components: { GiftedDialog, AlertMessage, QuickNav }, |
|
|
}) |
|
|
}) |
|
|
export default class HomeView extends Vue { |
|
|
export default class HomeView extends Vue { |
|
@ -99,7 +98,6 @@ export default class HomeView extends Vue { |
|
|
alertTitle = ""; |
|
|
alertTitle = ""; |
|
|
alertMessage = ""; |
|
|
alertMessage = ""; |
|
|
|
|
|
|
|
|
// 'created' hook runs when the Vue instance is first created |
|
|
|
|
|
async created() { |
|
|
async created() { |
|
|
try { |
|
|
try { |
|
|
await accountsDB.open(); |
|
|
await accountsDB.open(); |
|
@ -119,6 +117,28 @@ export default class HomeView extends Vue { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async buildHeaders() { |
|
|
|
|
|
const headers = { "Content-Type": "application/json" }; |
|
|
|
|
|
|
|
|
|
|
|
if (this.activeDid) { |
|
|
|
|
|
await accountsDB.open(); |
|
|
|
|
|
const allAccounts = await accountsDB.accounts.toArray(); |
|
|
|
|
|
const account = allAccounts.find((acc) => acc.did === this.activeDid); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
|
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error( |
|
|
|
|
|
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service." |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
headers["Authorization"] = "Bearer " + (await accessToken(identity)); |
|
|
|
|
|
} else { |
|
|
|
|
|
// it's OK without auth... we just won't get any identifiers |
|
|
|
|
|
} |
|
|
|
|
|
return headers; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
updateAllFeed = async () => { |
|
|
updateAllFeed = async () => { |
|
|
this.isHiddenSpinner = false; |
|
|
this.isHiddenSpinner = false; |
|
|
|
|
|
|
|
@ -126,7 +146,6 @@ export default class HomeView extends Vue { |
|
|
.then(async (results) => { |
|
|
.then(async (results) => { |
|
|
if (results.data.length > 0) { |
|
|
if (results.data.length > 0) { |
|
|
this.feedData = this.feedData.concat(results.data); |
|
|
this.feedData = this.feedData.concat(results.data); |
|
|
//console.log("Feed data:", this.feedData); |
|
|
|
|
|
this.feedAllLoaded = results.hitLimit; |
|
|
this.feedAllLoaded = results.hitLimit; |
|
|
this.feedPreviousOldestId = |
|
|
this.feedPreviousOldestId = |
|
|
results.data[results.data.length - 1].jwtId; |
|
|
results.data[results.data.length - 1].jwtId; |
|
@ -134,7 +153,6 @@ export default class HomeView extends Vue { |
|
|
this.feedLastViewedId == null || |
|
|
this.feedLastViewedId == null || |
|
|
this.feedLastViewedId < results.data[0].jwtId |
|
|
this.feedLastViewedId < results.data[0].jwtId |
|
|
) { |
|
|
) { |
|
|
// save it to storage |
|
|
|
|
|
await db.open(); |
|
|
await db.open(); |
|
|
db.settings.update(MASTER_SETTINGS_KEY, { |
|
|
db.settings.update(MASTER_SETTINGS_KEY, { |
|
|
lastViewedClaimId: results.data[0].jwtId, |
|
|
lastViewedClaimId: results.data[0].jwtId, |
|
@ -154,41 +172,26 @@ export default class HomeView extends Vue { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
retrieveClaims = async (endorserApiServer, identifier, beforeId) => { |
|
|
retrieveClaims = async (endorserApiServer, identifier, beforeId) => { |
|
|
//const afterQuery = afterId == null ? "" : "&afterId=" + afterId; |
|
|
|
|
|
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId; |
|
|
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId; |
|
|
const headers = { "Content-Type": "application/json" }; |
|
|
const response = await fetch( |
|
|
if (this.activeDid) { |
|
|
this.apiServer + "/api/v2/report/gives?" + beforeQuery, |
|
|
const account = R.find( |
|
|
{ |
|
|
(acc) => acc.did === this.activeDid, |
|
|
|
|
|
this.allAccounts |
|
|
|
|
|
); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error("No identity found."); |
|
|
|
|
|
} |
|
|
|
|
|
const token = await accessToken(identity); |
|
|
|
|
|
headers["Authorization"] = "Bearer " + token; |
|
|
|
|
|
} else { |
|
|
|
|
|
// it's OK without auth... we just won't get any identifiers |
|
|
|
|
|
} |
|
|
|
|
|
return fetch(this.apiServer + "/api/v2/report/gives?" + beforeQuery, { |
|
|
|
|
|
method: "GET", |
|
|
method: "GET", |
|
|
headers: headers, |
|
|
headers: await buildHeaders(), |
|
|
}) |
|
|
} |
|
|
.then(async (response) => { |
|
|
); |
|
|
|
|
|
|
|
|
if (response.status !== 200) { |
|
|
if (response.status !== 200) { |
|
|
const details = await response.text(); |
|
|
throw await response.text(); |
|
|
throw details; |
|
|
|
|
|
} |
|
|
} |
|
|
return response.json(); |
|
|
|
|
|
}) |
|
|
const results = await response.json(); |
|
|
.then((results) => { |
|
|
|
|
|
if (results.data) { |
|
|
if (results.data) { |
|
|
return results; |
|
|
return results; |
|
|
} else { |
|
|
} else { |
|
|
throw JSON.stringify(results); |
|
|
throw JSON.stringify(results); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
giveDescription(giveRecord) { |
|
|
giveDescription(giveRecord) { |
|
@ -235,6 +238,7 @@ export default class HomeView extends Vue { |
|
|
openDialog(giver) { |
|
|
openDialog(giver) { |
|
|
this.$refs.customDialog.open(giver); |
|
|
this.$refs.customDialog.open(giver); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleDialogResult(result) { |
|
|
handleDialogResult(result) { |
|
|
if (result.action === "confirm") { |
|
|
if (result.action === "confirm") { |
|
|
return new Promise((resolve) => { |
|
|
return new Promise((resolve) => { |
|
@ -259,21 +263,23 @@ export default class HomeView extends Vue { |
|
|
"You must select an identity before you can record a give."; |
|
|
"You must select an identity before you can record a give."; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!description && !hours) { |
|
|
if (!description && !hours) { |
|
|
this.alertTitle = "Error"; |
|
|
this.alertTitle = "Error"; |
|
|
this.alertMessage = |
|
|
this.alertMessage = |
|
|
"You must enter a description or some number of hours."; |
|
|
"You must enter a description or some number of hours."; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const account = R.find( |
|
|
|
|
|
(acc) => acc.did === this.activeDid, |
|
|
const account = this.allAccounts.find((acc) => acc.did === this.activeDid); |
|
|
this.allAccounts |
|
|
|
|
|
); |
|
|
|
|
|
//console.log("about to parse from", this.activeDid, account?.identity); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
|
|
|
if (!identity) { |
|
|
if (!identity) { |
|
|
throw new Error("No identity found."); |
|
|
throw new Error( |
|
|
|
|
|
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service." |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createAndSubmitGive( |
|
|
createAndSubmitGive( |
|
|
this.axios, |
|
|
this.axios, |
|
|
this.apiServer, |
|
|
this.apiServer, |
|
@ -284,20 +290,18 @@ export default class HomeView extends Vue { |
|
|
hours |
|
|
hours |
|
|
) |
|
|
) |
|
|
.then((result) => { |
|
|
.then((result) => { |
|
|
if (result.status != 201 || result.data?.error) { |
|
|
const error = result.data?.error; |
|
|
|
|
|
if (result.status !== 201 || error) { |
|
|
console.log("Error with give result:", result); |
|
|
console.log("Error with give result:", result); |
|
|
this.alertTitle = "Error"; |
|
|
this.alertTitle = "Error"; |
|
|
this.alertMessage = |
|
|
this.alertMessage = |
|
|
result.data?.error?.message || |
|
|
error?.message || "There was an error recording the give."; |
|
|
"There was an error recording the give."; |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.alertTitle = "Success"; |
|
|
this.alertTitle = "Success"; |
|
|
this.alertMessage = "That gift was recorded."; |
|
|
this.alertMessage = "That gift was recorded."; |
|
|
//this.updateAllFeed(); // full update is overkill but we should show something |
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
// axios throws errors on 400 responses |
|
|
|
|
|
console.log("Error with give caught:", e); |
|
|
console.log("Error with give caught:", e); |
|
|
this.alertTitle = "Error"; |
|
|
this.alertTitle = "Error"; |
|
|
this.alertMessage = |
|
|
this.alertMessage = |
|
|