diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index f8c62060..0ecb8d27 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -67,22 +67,8 @@ - -
- -
- -
-
+
+
Hours to Add: import { AxiosError } from "axios"; import * as didJwt from "did-jwt"; +import * as R from "ramda"; import { Options, Vue } from "vue-class-component"; import { AppString } from "@/constants/app"; @@ -153,7 +140,7 @@ export interface GiveVerifiableCredential { components: {}, }) export default class ContactsView extends Vue { - contacts: Contact[] = []; + contacts: Array = []; contactInput = ""; // { "did:...": amount } entry for each contact givenByMeTotals = {}; @@ -167,13 +154,15 @@ export default class ContactsView extends Vue { // 'created' hook runs when the Vue instance is first created async created() { await db.open(); + const accounts = await db.accounts.toArray(); + this.identity = JSON.parse(accounts[0].identity); this.contacts = await db.contacts.toArray(); const params = new URLSearchParams(window.location.search); this.showGiveTotals = params.get("showGiveTotals") == "true"; - - const accounts = await db.accounts.toArray(); - this.identity = JSON.parse(accounts[0].identity); + if (this.showGiveTotals) { + this.loadGives(); + } } async onClickNewContact(): void { @@ -259,6 +248,10 @@ export default class ContactsView extends Vue { return !isNaN(str) && !isNaN(parseFloat(str)); } + private contactForDid(contacts: Array, did: string): Contact { + return R.find((con) => con.did == did, contacts); + } + async onClickAddGive(fromDid: string, toDid: string): void { if (!this.hourInput) { this.errorMessage = "Giving 0 hours does nothing."; @@ -267,7 +260,23 @@ export default class ContactsView extends Vue { "This is not a valid number of hours: " + this.hourInput; } else { this.errorMessage = ""; - this.createAndSubmitGive(fromDid, toDid, parseFloat(this.hourInput)); + let toFrom; + if (fromDid == this.identity.did) { + toFrom = "to " + this.contactForDid(this.contacts, toDid).name; + } else { + toFrom = "from " + this.contactForDid(this.contacts, fromDid).name; + } + if ( + confirm( + "Are you sure you want to record " + + this.hourInput + + " hours " + + toFrom + + "?" + ) + ) { + this.createAndSubmitGive(fromDid, toDid, parseFloat(this.hourInput)); + } } }