@ -514,50 +514,86 @@ export default class HomeView extends Vue {
* @ throws Logs error if DID retrieval fails
* @ throws Logs error if DID retrieval fails
* /
* /
private async initializeIdentity ( ) {
private async initializeIdentity ( ) {
try {
/ / R e t r i e v e D I D s w i t h b e t t e r e r r o r h a n d l i n g
try {
try {
this . allMyDids = await retrieveAccountDids ( ) ;
this . allMyDids = await retrieveAccountDids ( ) ;
logConsoleAndDb ( ` [HomeView] Retrieved ${ this . allMyDids . length } DIDs ` ) ;
} catch ( error ) {
logConsoleAndDb ( ` [HomeView] Failed to retrieve DIDs: ${ error } ` , true ) ;
throw new Error ( "Failed to load existing identities. Please try restarting the app." ) ;
}
/ / C r e a t e n e w D I D i f n e e d e d
if ( this . allMyDids . length === 0 ) {
if ( this . allMyDids . length === 0 ) {
try {
this . isCreatingIdentifier = true ;
this . isCreatingIdentifier = true ;
const newDid = await generateSaveAndActivateIdentity ( ) ;
const newDid = await generateSaveAndActivateIdentity ( ) ;
this . isCreatingIdentifier = false ;
this . isCreatingIdentifier = false ;
this . allMyDids = [ newDid ] ;
this . allMyDids = [ newDid ] ;
logConsoleAndDb ( ` [HomeView] Created new identity: ${ newDid } ` ) ;
} catch ( error ) {
this . isCreatingIdentifier = false ;
logConsoleAndDb ( ` [HomeView] Failed to create new identity: ${ error } ` , true ) ;
throw new Error ( "Failed to create new identity. Please try again." ) ;
}
}
}
let settings = await databaseUtil . retrieveSettingsForActiveAccount ( ) ;
/ / L o a d s e t t i n g s w i t h b e t t e r e r r o r c o n t e x t
let settings ;
try {
settings = await databaseUtil . retrieveSettingsForActiveAccount ( ) ;
if ( USE_DEXIE_DB ) {
if ( USE_DEXIE_DB ) {
settings = await retrieveSettingsForActiveAccount ( ) ;
settings = await retrieveSettingsForActiveAccount ( ) ;
}
}
logConsoleAndDb ( ` [HomeView] Retrieved settings for ${ settings . activeDid || 'no active DID' } ` ) ;
} catch ( error ) {
logConsoleAndDb ( ` [HomeView] Failed to retrieve settings: ${ error } ` , true ) ;
throw new Error ( "Failed to load user settings. Some features may be limited." ) ;
}
/ / U p d a t e c o m p o n e n t s t a t e
this . apiServer = settings . apiServer || "" ;
this . apiServer = settings . apiServer || "" ;
this . activeDid = settings . activeDid || "" ;
this . activeDid = settings . activeDid || "" ;
/ / L o a d c o n t a c t s w i t h g r a c e f u l f a l l b a c k
try {
const platformService = PlatformServiceFactory . getInstance ( ) ;
const platformService = PlatformServiceFactory . getInstance ( ) ;
const dbContacts = await platformService . dbQuery (
const dbContacts = await platformService . dbQuery ( "SELECT * FROM contacts" ) ;
"SELECT * FROM contacts" ,
this . allContacts = databaseUtil . mapQueryResultToValues ( dbContacts ) as Contact [ ] ;
) ;
this . allContacts = databaseUtil . mapQueryResultToValues (
dbContacts ,
) as unknown as Contact [ ] ;
if ( USE_DEXIE_DB ) {
if ( USE_DEXIE_DB ) {
this . allContacts = await db . contacts . toArray ( ) ;
this . allContacts = await db . contacts . toArray ( ) ;
}
}
logConsoleAndDb ( ` [HomeView] Retrieved ${ this . allContacts . length } contacts ` ) ;
} catch ( error ) {
logConsoleAndDb ( ` [HomeView] Failed to retrieve contacts: ${ error } ` , true ) ;
this . allContacts = [ ] ; / / E n s u r e w e h a v e a v a l i d e m p t y a r r a y
this . $notify ( {
group : "alert" ,
type : "warning" ,
title : "Contact Loading Issue" ,
text : "Some contact information may be unavailable." ,
} , 5000 ) ;
}
/ / U p d a t e r e m a i n i n g s e t t i n g s
this . feedLastViewedClaimId = settings . lastViewedClaimId ;
this . feedLastViewedClaimId = settings . lastViewedClaimId ;
this . givenName = settings . firstName || "" ;
this . givenName = settings . firstName || "" ;
this . isFeedFilteredByVisible = ! ! settings . filterFeedByVisible ;
this . isFeedFilteredByVisible = ! ! settings . filterFeedByVisible ;
this . isFeedFilteredByNearby = ! ! settings . filterFeedByNearby ;
this . isFeedFilteredByNearby = ! ! settings . filterFeedByNearby ;
this . isRegistered = ! ! settings . isRegistered ;
this . isRegistered = ! ! settings . isRegistered ;
this . lastAckedOfferToUserJwtId = settings . lastAckedOfferToUserJwtId ;
this . lastAckedOfferToUserJwtId = settings . lastAckedOfferToUserJwtId ;
this . lastAckedOfferToUserProjectsJwtId =
this . lastAckedOfferToUserProjectsJwtId = settings . lastAckedOfferToUserProjectsJwtId ;
settings . lastAckedOfferToUserProjectsJwtId ;
this . searchBoxes = settings . searchBoxes || [ ] ;
this . searchBoxes = settings . searchBoxes || [ ] ;
this . showShortcutBvc = ! ! settings . showShortcutBvc ;
this . showShortcutBvc = ! ! settings . showShortcutBvc ;
this . isAnyFeedFilterOn = checkIsAnyFeedFilterOn ( settings ) ;
this . isAnyFeedFilterOn = checkIsAnyFeedFilterOn ( settings ) ;
/ / C h e c k o n b o a r d i n g s t a t u s
if ( ! settings . finishedOnboarding ) {
if ( ! settings . finishedOnboarding ) {
( this . $refs . onboardingDialog as OnboardingDialog ) . open (
( this . $refs . onboardingDialog as OnboardingDialog ) . open ( OnboardPage . Home ) ;
OnboardPage . Home ,
) ;
}
}
/ / s o m e o n e m a y h a v e h a v e r e g i s t e r e d a f t e r s h a r i n g c o n t a c t i n f o , s o r e c h e c k
/ / C h e c k r e g i s t r a t i o n s t a t u s i f n e e d e d
if ( ! this . isRegistered && this . activeDid ) {
if ( ! this . isRegistered && this . activeDid ) {
try {
try {
const resp = await fetchEndorserRateLimits (
const resp = await fetchEndorserRateLimits (
@ -577,51 +613,62 @@ export default class HomeView extends Vue {
} ) ;
} ) ;
}
}
this . isRegistered = true ;
this . isRegistered = true ;
logConsoleAndDb ( ` [HomeView] User ${ this . activeDid } is now registered ` ) ;
}
}
} catch ( e ) {
} catch ( error ) {
/ / i g n o r e t h e e r r o r . . . j u s t k e e p u s u n r e g i s t e r e d
logConsoleAndDb ( ` [HomeView] Registration check failed: ${ error } ` , true ) ;
/ / C o n t i n u e a s u n r e g i s t e r e d - t h i s i s e x p e c t e d f o r n e w u s e r s
}
}
}
}
/ / t h i s r e t u r n s a P r o m i s e b u t w e d o n ' t n e e d t o w a i t f o r i t
/ / I n i t i a l i z e f e e d a n d o f f e r s
this . updateAllFeed ( ) ;
try {
/ / S t a r t f e e d u p d a t e i n b a c k g r o u n d
this . updateAllFeed ( ) . catch ( error => {
logConsoleAndDb ( ` [HomeView] Background feed update failed: ${ error } ` , true ) ;
} ) ;
/ / L o a d n e w o f f e r s i f w e h a v e a n a c t i v e D I D
if ( this . activeDid ) {
if ( this . activeDid ) {
const offersToUserData = await getNewOffersToUser (
const [ offersToUser , offersToProjects ] = await Promise . all ( [
getNewOffersToUser (
this . axios ,
this . axios ,
this . apiServer ,
this . apiServer ,
this . activeDid ,
this . activeDid ,
this . lastAckedOfferToUserJwtId ,
this . lastAckedOfferToUserJwtId ,
) ;
) ,
this . numNewOffersToUser = offersToUserData . data . length ;
getNewOffersToUserProjects (
this . newOffersToUserHitLimit = offersToUserData . hitLimit ;
}
if ( this . activeDid ) {
const offersToUserProjects = await getNewOffersToUserProjects (
this . axios ,
this . axios ,
this . apiServer ,
this . apiServer ,
this . activeDid ,
this . activeDid ,
this . lastAckedOfferToUserProjectsJwtId ,
this . lastAckedOfferToUserProjectsJwtId ,
) ,
] ) ;
this . numNewOffersToUser = offersToUser . data . length ;
this . newOffersToUserHitLimit = offersToUser . hitLimit ;
this . numNewOffersToUserProjects = offersToProjects . data . length ;
this . newOffersToUserProjectsHitLimit = offersToProjects . hitLimit ;
logConsoleAndDb (
` [HomeView] Retrieved ${ this . numNewOffersToUser } user offers and ` +
` ${ this . numNewOffersToUserProjects } project offers `
) ;
) ;
this . numNewOffersToUserProjects = offersToUserProjects . data . length ;
this . newOffersToUserProjectsHitLimit = offersToUserProjects . hitLimit ;
}
}
} catch ( error ) {
/ / e s l i n t - d i s a b l e - n e x t - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
logConsoleAndDb ( ` [HomeView] Failed to initialize feed/offers: ${ error } ` , true ) ;
} catch ( err : any ) {
/ / D o n ' t t h r o w - w e c a n c o n t i n u e w i t h e m p t y f e e d
logConsoleAndDb ( "Error retrieving settings or feed: " + err , true ) ;
this . $notify ( {
this . $notify (
{
group : "alert" ,
group : "alert" ,
type : "danger" ,
type : "warning" ,
title : "Error" ,
title : "Feed Loading Issue" ,
text :
text : "Some feed data may be unavailable. Pull to refresh." ,
( err as { userMessage ? : string } ) ? . userMessage ||
} , 5000 ) ;
"There was an error retrieving your settings or the latest activity." ,
}
} ,
5000 ,
} catch ( error ) {
) ;
this . handleError ( error ) ;
throw error ; / / R e - t h r o w t o b e c a u g h t b y m o u n t e d ( )
}
}
}
}
@ -784,19 +831,24 @@ export default class HomeView extends Vue {
* - Displays user notification
* - Displays user notification
*
*
* @ internal
* @ internal
* Called by mounted ( )
* Called by mounted ( ) and initializeIdentity ( )
* @ param err Error object with optional userMessage
* @ param err Error object with optional userMessage
* /
* /
private handleError ( err : unknown ) {
private handleError ( err : unknown ) {
logConsoleAndDb ( "Error retrieving settings or feed: " + err , true ) ;
const errorMessage = err instanceof Error ? err . message : String ( err ) ;
const userMessage = ( err as { userMessage ? : string } ) ? . userMessage ;
logConsoleAndDb (
` [HomeView] Initialization error: ${ errorMessage } ${ userMessage ? ` ( ${ userMessage } ) ` : '' } ` ,
true
) ;
this . $notify (
this . $notify (
{
{
group : "alert" ,
group : "alert" ,
type : "danger" ,
type : "danger" ,
title : "Error" ,
title : "Error" ,
text :
text : userMessage || "There was an error loading your data. Please try refreshing the page." ,
( err as { userMessage ? : string } ) ? . userMessage ||
"There was an error retrieving your settings or the latest activity." ,
} ,
} ,
5000 ,
5000 ,
) ;
) ;