@ -70,7 +70,7 @@
< / div >
<!-- Results List -- >
< ul class = "" >
< ul v-if ="contacts.length > 0" >
< li
class = "border-b border-slate-300"
v - for = "contact in contacts"
@ -187,6 +187,7 @@
< / div >
< / li >
< / ul >
< p v-else > This identity has no contacts. < / p >
< AlertMessage
: alertTitle = "alertTitle"
: alertMessage = "alertMessage"
@ -204,7 +205,6 @@ import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings" ;
import { accessToken , SimpleSigner } from "@/libs/crypto" ;
import {
GiveServerRecord ,
GiveVerifiableCredential ,
RegisterVerifiableCredential ,
SERVICE_ID ,
@ -261,10 +261,10 @@ export default class ContactsView extends Vue {
) ;
}
async loadGives ( ) {
public async getIdentity ( activeDid ) {
await accountsDB . open ( ) ;
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" ) ;
if ( ! identity ) {
@ -272,45 +272,43 @@ export default class ContactsView extends Vue {
"Attempted to load Give records with no identity available." ,
) ;
}
return identity ;
}
/ / l o a d a l l t h e t i m e I h a v e g i v e n
try {
const url =
this . apiServer +
"/api/v2/report/gives?agentDid=" +
encodeURIComponent ( identity . did ) ;
const token = await accessToken ( identity ) ;
const headers = {
"Content-Type" : "application/json" ,
Authorization : "Bearer " + token ,
} ;
const resp = await this . axios . get ( url , { headers } ) ;
/ / c o n s o l e . l o g ( " A l l g i f t s y o u ' v e g i v e n : " , r e s p . d a t a ) ;
public async getHeaders ( identity ) {
const token = await accessToken ( identity ) ;
const headers = {
"Content-Type" : "application/json" ,
Authorization : "Bearer " + token ,
} ;
return headers ;
}
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 ) {
const contactDescriptions : Record < string , string > = { } ;
const contactConfirmed : Record < string , number > = { } ;
const contactUnconfirmed : Record < string , number > = { } ;
const allData : Array < GiveServerRecord > = resp . data . data ;
const allData = resp . data . data ;
for ( const give of allData ) {
if ( give . unit == "HUR" ) {
const recipDid : string = give . recipientDid ;
if ( give . unit === "HUR" ) {
if ( give . amountConfirmed ) {
const prevAmount = contactCon firmed [ recip Did] || 0 ;
contactCon firmed [ recip Did] = prevAmount + give . amount ;
const prevAmount = confirmed [ give . agent Did] || 0 ;
confirmed [ give . agent Did] = prevAmount + give . amount ;
} else {
const prevAmount = contactUnconfirmed [ recip Did] || 0 ;
contactUnconfirmed [ recip Did] = prevAmount + give . amount ;
const prevAmount = unconfirmed [ give . agent Did] || 0 ;
unconfirmed [ give . agent Did] = prevAmount + give . amount ;
}
if ( ! contactDescriptions [ recipDid ] && give . description ) {
/ / S i n c e m a n y m a k e t h e t o o l t i p t o o b i g , w e ' l l j u s t u s e t h e l a t e s t .
contactDescriptions [ recipDid ] = give . description ;
if ( ! descriptions [ give . agentDid ] && give . description ) {
descriptions [ give . agentDid ] = give . description ;
}
}
}
/ / c o n s o l e . l o g ( " D o n e r e t r i e v i n g g i v e s " , c o n t a c t C o n f i r m e d ) ;
this . givenByMeDescriptions = contactDescriptions ;
this . givenByMeConfirmed = contactConfirmed ;
this . givenByMeUnconfirmed = contactUnconfirmed ;
} else {
console . error (
"Got bad response status & data of" ,
@ -319,60 +317,56 @@ export default class ContactsView extends Vue {
) ;
this . alertTitle = "Error With Server" ;
this . alertMessage =
"Got an error retrieving your given time from the server." ;
"Got an error retrieving your " +
resp . config . url . includes ( "recipientDid" )
? "received"
: "given" + " time from the server." ;
}
} catch ( error ) {
this . alertTitle = "Error With Server" ;
this . alertMessage = error as string ;
}
} ;
/ / l o a d a l l t h e t i m e I h a v e r e c e i v e d
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 +
"/api/v2/report/gives?recipientDid=" +
encodeURIComponent ( identity . did ) ;
const token = await accessToken ( identity ) ;
const headers = {
"Content-Type" : "application/json" ,
Authorization : "Bearer " + token ,
} ;
const resp = await this . axios . get ( url , { headers } ) ;
/ / c o n s o l e . l o g ( " A l l g i f t s y o u ' v e r e c i e v e d : " , r e s p . d a t a ) ;
if ( resp . status === 200 ) {
const contactDescriptions : Record < string , string > = { } ;
const contactConfirmed : Record < string , number > = { } ;
const contactUnconfirmed : Record < string , number > = { } ;
const allData : Array < GiveServerRecord > = resp . data . data ;
for ( const give of allData ) {
if ( give . unit == "HUR" ) {
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 ) {
/ / S i n c e m a n y m a k e t h e t o o l t i p t o o b i g , w e ' l l j u s t u s e t h e l a t e s t .
contactDescriptions [ give . agentDid ] = give . description ;
}
}
}
/ / c o n s o l e . l o g ( " D o n e r e t r i e v i n g r e c e i p t s " , c o n t a c t C o n f i r m e d ) ;
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 . alertMessage =
"Got an error retrieving your received time from the server." ;
}
const [ givenByMeResp , givenToMeResp ] = await Promise . all ( [
this . axios . get ( givenByUrl , { headers } ) ,
this . axios . get ( givenToUrl , { headers } ) ,
] ) ;
const givenByMeDescriptions = { } ;
const givenByMeConfirmed = { } ;
const givenByMeUnconfirmed = { } ;
handleResponse (
givenByMeResp ,
givenByMeDescriptions ,
givenByMeConfirmed ,
givenByMeUnconfirmed ,
) ;
this . givenByMeDescriptions = givenByMeDescriptions ;
this . givenByMeConfirmed = givenByMeConfirmed ;
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 ) {
this . alertTitle = "Error With Server" ;
this . alertMessage = error as string ;
@ -430,15 +424,8 @@ export default class ContactsView extends Vue {
"?" ,
)
) {
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 identity = await this . getIdentity ( this . activeDid ) ;
/ / M a k e a c l a i m
const vcClaim : RegisterVerifiableCredential = {
"@context" : "https://schema.org" ,
"@type" : "RegisterAction" ,
@ -518,19 +505,8 @@ export default class ContactsView extends Vue {
this . apiServer +
"/api/report/" +
( visibility ? "canSeeMe" : "cannotSeeMe" ) ;
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 ,
} ;
const identity = await this . getIdentity ( this . activeDid ) ;
const headers = await this . getHeaders ( identity ) ;
const payload = JSON . stringify ( { did : contact . did } ) ;
try {
@ -558,19 +534,6 @@ export default class ContactsView extends Vue {
this . apiServer +
"/api/report/canDidExplicitlySeeMe?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 {
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 > {
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 identity = await this . getIdentity ( this . activeDid ) ;
/ / i f t h e y h a v e u n c o n f i r m e d a m o u n t s , a s k t o c o n f i r m t h o s e f i r s t
if ( toDid == identity ? . did && this . givenToMeUnconfirmed [ fromDid ] > 0 ) {
Note that this message doesn't really apply on this page. The original has the more generic: "An ID is chosen but there are no keys for it so it cannot be used to talk with the service." Recommend making some more generic message for all these cases if you want to keep the same error message for them all.