forked from jsnbuchanan/crowd-funder-for-time-pwa
Considerable cleanup. I think I also found the issue from the other day with values not loading from settings.
This commit is contained in:
@@ -104,6 +104,7 @@ export default class HomeView extends Vue {
|
||||
this.allAccounts = await accountsDB.accounts.toArray();
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
console.log(settings);
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
this.allContacts = await db.contacts.toArray();
|
||||
@@ -128,7 +129,7 @@ export default class HomeView extends Vue {
|
||||
|
||||
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."
|
||||
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,9 +140,8 @@ export default class HomeView extends Vue {
|
||||
return headers;
|
||||
}
|
||||
|
||||
updateAllFeed = async () => {
|
||||
public async updateAllFeed() {
|
||||
this.isHiddenSpinner = false;
|
||||
|
||||
await this.retrieveClaims(this.apiServer, null, this.feedPreviousOldestId)
|
||||
.then(async (results) => {
|
||||
if (results.data.length > 0) {
|
||||
@@ -169,16 +169,16 @@ export default class HomeView extends Vue {
|
||||
});
|
||||
|
||||
this.isHiddenSpinner = true;
|
||||
};
|
||||
}
|
||||
|
||||
retrieveClaims = async (endorserApiServer, identifier, beforeId) => {
|
||||
public async retrieveClaims(endorserApiServer, identifier, beforeId) {
|
||||
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId;
|
||||
const response = await fetch(
|
||||
this.apiServer + "/api/v2/report/gives?" + beforeQuery,
|
||||
endorserApiServer + "/api/v2/report/gives?" + beforeQuery,
|
||||
{
|
||||
method: "GET",
|
||||
headers: await buildHeaders(),
|
||||
}
|
||||
headers: await this.buildHeaders(),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
@@ -192,12 +192,11 @@ export default class HomeView extends Vue {
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
giveDescription(giveRecord) {
|
||||
let claim = giveRecord.fullClaim;
|
||||
if (claim.claim) {
|
||||
// it's probably a Verified Credential
|
||||
claim = claim.claim;
|
||||
}
|
||||
|
||||
@@ -208,7 +207,7 @@ export default class HomeView extends Vue {
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
this.allAccounts,
|
||||
this.allContacts
|
||||
this.allContacts,
|
||||
);
|
||||
const gaveAmount = claim.object?.amountOfThisGood
|
||||
? this.displayAmount(claim.object.unitCode, claim.object.amountOfThisGood)
|
||||
@@ -221,7 +220,7 @@ export default class HomeView extends Vue {
|
||||
gaveRecipientId,
|
||||
this.activeDid,
|
||||
this.allAccounts,
|
||||
this.allContacts
|
||||
this.allContacts,
|
||||
)
|
||||
: "";
|
||||
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
|
||||
@@ -276,7 +275,7 @@ export default class HomeView extends Vue {
|
||||
|
||||
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."
|
||||
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -287,28 +286,41 @@ export default class HomeView extends Vue {
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
description,
|
||||
hours
|
||||
hours,
|
||||
)
|
||||
.then((result) => {
|
||||
const error = result.data?.error;
|
||||
if (result.status !== 201 || error) {
|
||||
if (isGiveCreationError(result)) {
|
||||
const errorMessage = getGiveCreationErrorMessage(result);
|
||||
console.log("Error with give result:", result);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
error?.message || "There was an error recording the give.";
|
||||
errorMessage || "There was an error recording the give.";
|
||||
} else {
|
||||
this.alertTitle = "Success";
|
||||
this.alertMessage = "That gift was recorded.";
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("Error with give caught:", e);
|
||||
.catch((error) => {
|
||||
console.log("Error with give caught:", error);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
e.userMessage ||
|
||||
e.response?.data?.error?.message ||
|
||||
getGiveErrorMessage(error) ||
|
||||
"There was an error recording the give.";
|
||||
});
|
||||
}
|
||||
|
||||
// Helper functions for readability
|
||||
|
||||
isGiveCreationError(result) {
|
||||
return result.status !== 201 || result.data?.error;
|
||||
}
|
||||
|
||||
getGiveCreationErrorMessage(result) {
|
||||
return result.data?.error?.message;
|
||||
}
|
||||
|
||||
getGiveErrorMessage(error) {
|
||||
return error.userMessage || error.response?.data?.error?.message;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user