|
@ -70,7 +70,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<!-- Results List --> |
|
|
<!-- Results List --> |
|
|
<ul class=""> |
|
|
<ul v-if="contacts.length > 0"> |
|
|
<li |
|
|
<li |
|
|
class="border-b border-slate-300" |
|
|
class="border-b border-slate-300" |
|
|
v-for="contact in contacts" |
|
|
v-for="contact in contacts" |
|
@ -187,6 +187,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
</li> |
|
|
</li> |
|
|
</ul> |
|
|
</ul> |
|
|
|
|
|
<p v-else>This identity has no contacts.</p> |
|
|
<AlertMessage |
|
|
<AlertMessage |
|
|
:alertTitle="alertTitle" |
|
|
:alertTitle="alertTitle" |
|
|
:alertMessage="alertMessage" |
|
|
:alertMessage="alertMessage" |
|
@ -204,7 +205,6 @@ import { Contact } from "@/db/tables/contacts"; |
|
|
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; |
|
|
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; |
|
|
import { accessToken, SimpleSigner } from "@/libs/crypto"; |
|
|
import { accessToken, SimpleSigner } from "@/libs/crypto"; |
|
|
import { |
|
|
import { |
|
|
GiveServerRecord, |
|
|
|
|
|
GiveVerifiableCredential, |
|
|
GiveVerifiableCredential, |
|
|
RegisterVerifiableCredential, |
|
|
RegisterVerifiableCredential, |
|
|
SERVICE_ID, |
|
|
SERVICE_ID, |
|
@ -261,10 +261,10 @@ export default class ContactsView extends Vue { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async loadGives() { |
|
|
public async getIdentity(activeDid) { |
|
|
await accountsDB.open(); |
|
|
await accountsDB.open(); |
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
const account = R.find((acc) => acc.did === this.activeDid, accounts); |
|
|
const account = R.find((acc) => acc.did === activeDid, accounts); |
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
|
|
|
if (!identity) { |
|
|
if (!identity) { |
|
@ -272,45 +272,43 @@ export default class ContactsView extends Vue { |
|
|
"Attempted to load Give records with no identity available.", |
|
|
"Attempted to load Give records with no identity available.", |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
return identity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// load all the time I have given |
|
|
public async getHeaders(identity) { |
|
|
try { |
|
|
|
|
|
const url = |
|
|
|
|
|
this.apiServer + |
|
|
|
|
|
"/api/v2/report/gives?agentDid=" + |
|
|
|
|
|
encodeURIComponent(identity.did); |
|
|
|
|
|
const token = await accessToken(identity); |
|
|
const token = await accessToken(identity); |
|
|
const headers = { |
|
|
const headers = { |
|
|
"Content-Type": "application/json", |
|
|
"Content-Type": "application/json", |
|
|
Authorization: "Bearer " + token, |
|
|
Authorization: "Bearer " + token, |
|
|
}; |
|
|
}; |
|
|
const resp = await this.axios.get(url, { headers }); |
|
|
return headers; |
|
|
//console.log("All gifts you've given:", resp.data); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async getHeadersAndIdentity(activeDid) { |
|
|
|
|
|
const identity = await this.getIdentity(activeDid); |
|
|
|
|
|
const headers = await this.getHeaders(identity); |
|
|
|
|
|
|
|
|
|
|
|
return { headers, identity }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async loadGives() { |
|
|
|
|
|
const handleResponse = (resp, descriptions, confirmed, unconfirmed) => { |
|
|
if (resp.status === 200) { |
|
|
if (resp.status === 200) { |
|
|
const contactDescriptions: Record<string, string> = {}; |
|
|
const allData = resp.data.data; |
|
|
const contactConfirmed: Record<string, number> = {}; |
|
|
|
|
|
const contactUnconfirmed: Record<string, number> = {}; |
|
|
|
|
|
const allData: Array<GiveServerRecord> = resp.data.data; |
|
|
|
|
|
for (const give of allData) { |
|
|
for (const give of allData) { |
|
|
if (give.unit == "HUR") { |
|
|
if (give.unit === "HUR") { |
|
|
const recipDid: string = give.recipientDid; |
|
|
|
|
|
if (give.amountConfirmed) { |
|
|
if (give.amountConfirmed) { |
|
|
const prevAmount = contactConfirmed[recipDid] || 0; |
|
|
const prevAmount = confirmed[give.agentDid] || 0; |
|
|
contactConfirmed[recipDid] = prevAmount + give.amount; |
|
|
confirmed[give.agentDid] = prevAmount + give.amount; |
|
|
} else { |
|
|
} else { |
|
|
const prevAmount = contactUnconfirmed[recipDid] || 0; |
|
|
const prevAmount = unconfirmed[give.agentDid] || 0; |
|
|
contactUnconfirmed[recipDid] = prevAmount + give.amount; |
|
|
unconfirmed[give.agentDid] = prevAmount + give.amount; |
|
|
} |
|
|
} |
|
|
if (!contactDescriptions[recipDid] && give.description) { |
|
|
if (!descriptions[give.agentDid] && give.description) { |
|
|
// Since many make the tooltip too big, we'll just use the latest. |
|
|
descriptions[give.agentDid] = give.description; |
|
|
contactDescriptions[recipDid] = give.description; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//console.log("Done retrieving gives", contactConfirmed); |
|
|
|
|
|
this.givenByMeDescriptions = contactDescriptions; |
|
|
|
|
|
this.givenByMeConfirmed = contactConfirmed; |
|
|
|
|
|
this.givenByMeUnconfirmed = contactUnconfirmed; |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
console.error( |
|
|
console.error( |
|
|
"Got bad response status & data of", |
|
|
"Got bad response status & data of", |
|
@ -319,60 +317,56 @@ export default class ContactsView extends Vue { |
|
|
); |
|
|
); |
|
|
this.alertTitle = "Error With Server"; |
|
|
this.alertTitle = "Error With Server"; |
|
|
this.alertMessage = |
|
|
this.alertMessage = |
|
|
"Got an error retrieving your given time from the server."; |
|
|
"Got an error retrieving your " + |
|
|
} |
|
|
resp.config.url.includes("recipientDid") |
|
|
} catch (error) { |
|
|
? "received" |
|
|
this.alertTitle = "Error With Server"; |
|
|
: "given" + " time from the server."; |
|
|
this.alertMessage = error as string; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// load all the time I have received |
|
|
|
|
|
try { |
|
|
try { |
|
|
const url = |
|
|
const { headers, identity } = await this.getHeadersAndIdentity( |
|
|
|
|
|
this.activeDid, |
|
|
|
|
|
); |
|
|
|
|
|
const givenByUrl = |
|
|
|
|
|
this.apiServer + |
|
|
|
|
|
"/api/v2/report/gives?agentDid=" + |
|
|
|
|
|
encodeURIComponent(identity.did); |
|
|
|
|
|
const givenToUrl = |
|
|
this.apiServer + |
|
|
this.apiServer + |
|
|
"/api/v2/report/gives?recipientDid=" + |
|
|
"/api/v2/report/gives?recipientDid=" + |
|
|
encodeURIComponent(identity.did); |
|
|
encodeURIComponent(identity.did); |
|
|
const token = await accessToken(identity); |
|
|
|
|
|
const headers = { |
|
|
const [givenByMeResp, givenToMeResp] = await Promise.all([ |
|
|
"Content-Type": "application/json", |
|
|
this.axios.get(givenByUrl, { headers }), |
|
|
Authorization: "Bearer " + token, |
|
|
this.axios.get(givenToUrl, { headers }), |
|
|
}; |
|
|
]); |
|
|
const resp = await this.axios.get(url, { headers }); |
|
|
|
|
|
//console.log("All gifts you've recieved:", resp.data); |
|
|
const givenByMeDescriptions = {}; |
|
|
if (resp.status === 200) { |
|
|
const givenByMeConfirmed = {}; |
|
|
const contactDescriptions: Record<string, string> = {}; |
|
|
const givenByMeUnconfirmed = {}; |
|
|
const contactConfirmed: Record<string, number> = {}; |
|
|
handleResponse( |
|
|
const contactUnconfirmed: Record<string, number> = {}; |
|
|
givenByMeResp, |
|
|
const allData: Array<GiveServerRecord> = resp.data.data; |
|
|
givenByMeDescriptions, |
|
|
for (const give of allData) { |
|
|
givenByMeConfirmed, |
|
|
if (give.unit == "HUR") { |
|
|
givenByMeUnconfirmed, |
|
|
if (give.amountConfirmed) { |
|
|
|
|
|
const prevAmount = contactConfirmed[give.agentDid] || 0; |
|
|
|
|
|
contactConfirmed[give.agentDid] = prevAmount + give.amount; |
|
|
|
|
|
} else { |
|
|
|
|
|
const prevAmount = contactUnconfirmed[give.agentDid] || 0; |
|
|
|
|
|
contactUnconfirmed[give.agentDid] = prevAmount + give.amount; |
|
|
|
|
|
} |
|
|
|
|
|
if (!contactDescriptions[give.agentDid] && give.description) { |
|
|
|
|
|
// Since many make the tooltip too big, we'll just use the latest. |
|
|
|
|
|
contactDescriptions[give.agentDid] = give.description; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//console.log("Done retrieving receipts", contactConfirmed); |
|
|
|
|
|
this.givenToMeDescriptions = contactDescriptions; |
|
|
|
|
|
this.givenToMeConfirmed = contactConfirmed; |
|
|
|
|
|
this.givenToMeUnconfirmed = contactUnconfirmed; |
|
|
|
|
|
} else { |
|
|
|
|
|
console.error( |
|
|
|
|
|
"Got bad response status & data of", |
|
|
|
|
|
resp.status, |
|
|
|
|
|
resp.data, |
|
|
|
|
|
); |
|
|
); |
|
|
this.alertTitle = "Error With Server"; |
|
|
this.givenByMeDescriptions = givenByMeDescriptions; |
|
|
this.alertMessage = |
|
|
this.givenByMeConfirmed = givenByMeConfirmed; |
|
|
"Got an error retrieving your received time from the server."; |
|
|
this.givenByMeUnconfirmed = givenByMeUnconfirmed; |
|
|
} |
|
|
|
|
|
|
|
|
const givenToMeDescriptions = {}; |
|
|
|
|
|
const givenToMeConfirmed = {}; |
|
|
|
|
|
const givenToMeUnconfirmed = {}; |
|
|
|
|
|
handleResponse( |
|
|
|
|
|
givenToMeResp, |
|
|
|
|
|
givenToMeDescriptions, |
|
|
|
|
|
givenToMeConfirmed, |
|
|
|
|
|
givenToMeUnconfirmed, |
|
|
|
|
|
); |
|
|
|
|
|
this.givenToMeDescriptions = givenToMeDescriptions; |
|
|
|
|
|
this.givenToMeConfirmed = givenToMeConfirmed; |
|
|
|
|
|
this.givenToMeUnconfirmed = givenToMeUnconfirmed; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
this.alertTitle = "Error With Server"; |
|
|
this.alertTitle = "Error With Server"; |
|
|
this.alertMessage = error as string; |
|
|
this.alertMessage = error as string; |
|
@ -430,15 +424,8 @@ export default class ContactsView extends Vue { |
|
|
"?", |
|
|
"?", |
|
|
) |
|
|
) |
|
|
) { |
|
|
) { |
|
|
await accountsDB.open(); |
|
|
const identity = await this.getIdentity(this.activeDid); |
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
|
|
|
const account = R.find((acc) => acc.did === this.activeDid, accounts); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error("No identity found."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make a claim |
|
|
|
|
|
const vcClaim: RegisterVerifiableCredential = { |
|
|
const vcClaim: RegisterVerifiableCredential = { |
|
|
"@context": "https://schema.org", |
|
|
"@context": "https://schema.org", |
|
|
"@type": "RegisterAction", |
|
|
"@type": "RegisterAction", |
|
@ -518,19 +505,8 @@ export default class ContactsView extends Vue { |
|
|
this.apiServer + |
|
|
this.apiServer + |
|
|
"/api/report/" + |
|
|
"/api/report/" + |
|
|
(visibility ? "canSeeMe" : "cannotSeeMe"); |
|
|
(visibility ? "canSeeMe" : "cannotSeeMe"); |
|
|
await accountsDB.open(); |
|
|
const identity = await this.getIdentity(this.activeDid); |
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
const headers = await this.getHeaders(identity); |
|
|
const account = R.find((acc) => acc.did === this.activeDid, accounts); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error("No identity found."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const token = await accessToken(identity); |
|
|
|
|
|
const headers = { |
|
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
|
Authorization: "Bearer " + token, |
|
|
|
|
|
}; |
|
|
|
|
|
const payload = JSON.stringify({ did: contact.did }); |
|
|
const payload = JSON.stringify({ did: contact.did }); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
@ -558,19 +534,6 @@ export default class ContactsView extends Vue { |
|
|
this.apiServer + |
|
|
this.apiServer + |
|
|
"/api/report/canDidExplicitlySeeMe?did=" + |
|
|
"/api/report/canDidExplicitlySeeMe?did=" + |
|
|
encodeURIComponent(contact.did); |
|
|
encodeURIComponent(contact.did); |
|
|
await accountsDB.open(); |
|
|
|
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
|
|
|
const account = R.find((acc) => acc.did === this.activeDid, accounts); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error("No identity found."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const token = await accessToken(identity); |
|
|
|
|
|
const headers = { |
|
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
|
Authorization: "Bearer " + token, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const resp = await this.axios.get(url, { headers }); |
|
|
const resp = await this.axios.get(url, { headers }); |
|
@ -615,13 +578,7 @@ export default class ContactsView extends Vue { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async onClickAddGive(fromDid: string, toDid: string): Promise<void> { |
|
|
async onClickAddGive(fromDid: string, toDid: string): Promise<void> { |
|
|
await accountsDB.open(); |
|
|
const identity = await this.getIdentity(this.activeDid); |
|
|
const accounts = await accountsDB.accounts.toArray(); |
|
|
|
|
|
const account = R.find((acc) => acc.did === this.activeDid, accounts); |
|
|
|
|
|
const identity = JSON.parse(account?.identity || "null"); |
|
|
|
|
|
if (!identity) { |
|
|
|
|
|
throw new Error("No identity found."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if they have unconfirmed amounts, ask to confirm those first |
|
|
// if they have unconfirmed amounts, ask to confirm those first |
|
|
if (toDid == identity?.did && this.givenToMeUnconfirmed[fromDid] > 0) { |
|
|
if (toDid == identity?.did && this.givenToMeUnconfirmed[fromDid] > 0) { |
|
|