From 3eda5f6b5d5686d1c908e065d9545aa1ffa105e8 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Mon, 19 Feb 2024 19:43:55 -0700 Subject: [PATCH] show more succinct info in feed, targeted toward user's visibility --- src/libs/endorserServer.ts | 63 ++++++++++--- src/router/index.ts | 12 +-- src/views/AccountViewView.vue | 2 +- src/views/ContactsView.vue | 4 +- src/views/HomeView.vue | 171 ++++++++++++++++++++++------------ src/views/SeedBackupView.vue | 2 +- 6 files changed, 168 insertions(+), 86 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 45ad00ac9..55756e6c8 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -352,32 +352,65 @@ export function removeVisibleToDids(input: any): any { } } -/** - always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY - - Similar logic is found in endorser-mobile. - **/ -export function didInfo( +export function contactForDid( did: string | undefined, - activeDid: string | undefined, - allMyDids: string[], contacts: Contact[], -): string { - if (!did) return "Someone Anonymous"; +): Contact | undefined { + return isEmptyOrHiddenDid(did) + ? undefined + : R.find((c) => c.did === did, contacts); +} - const contact = R.find((c) => c.did === did, contacts); +/** + * + * Similar logic is found in endorser-mobile. + * + * @param did + * @param activeDid + * @param contact + * @param allMyDids + * @return { known: boolean, displayName: string } where known is true if the display name is some easily-recogizable name, false if it's a generic name like "Someone Anonymous" + */ +export function didInfoForContact( + did: string | undefined, + activeDid: string | undefined, + contact?: Contact, + allMyDids: string[] = [], + // eslint-disable-next-line @typescript-eslint/no-explicit-any +): { known: boolean; displayName: string } { + if (!did) return { displayName: "Someone Anonymous", known: false }; if (contact) { - return contact.name || "Contact With No Name"; + return { + displayName: contact.name || "Contact With No Name", + known: !!contact.name, + }; + } else if (did === activeDid) { + return { displayName: "You", known: true }; } else { const myId = R.find(R.equals(did), allMyDids); return myId - ? `You${myId !== activeDid ? " (Alt ID)" : ""}` + ? { displayName: "You (Alt ID)", known: true } : isHiddenDid(did) - ? "Someone Outside Your Network" - : "Someone Outside Contacts"; + ? { displayName: "Someone Outside Your Network", known: false } + : { displayName: "Someone Outside Contacts", known: false }; } } +/** + always returns text, maybe something like "unnamed" or "unknown" + + Now that we're using more informational didInfoForContact under the covers, we might want to consolidate. + **/ +export function didInfo( + did: string | undefined, + activeDid: string | undefined, + allMyDids: string[], + contacts: Contact[], +): string { + const contact = contactForDid(did, contacts); + return didInfoForContact(did, activeDid, contact, allMyDids).displayName; +} + /** * For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim * diff --git a/src/router/index.ts b/src/router/index.ts index 0e653ad4c..68da028fc 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -28,12 +28,6 @@ const enterOrStart = async ( }; const routes: Array = [ - { - path: "/", - name: "home", - component: () => - import(/* webpackChunkName: "home" */ "../views/HomeView.vue"), - }, { path: "/account", name: "account", @@ -96,6 +90,12 @@ const routes: Array = [ component: () => import(/* webpackChunkName: "help" */ "../views/HelpView.vue"), }, + { + path: "/", + name: "home", + component: () => + import(/* webpackChunkName: "home" */ "../views/HomeView.vue"), + }, { path: "/help-notifications", name: "help-notifications", diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 47633a55a..864db7c0a 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -1,5 +1,5 @@