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 | 65 +++++++++---- 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, 169 insertions(+), 87 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 45ad00ac..55756e6c 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -352,10 +352,54 @@ export function removeVisibleToDids(input: any): any { } } -/** - always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY +export function contactForDid( + did: string | undefined, + contacts: Contact[], +): Contact | undefined { + return isEmptyOrHiddenDid(did) + ? undefined + : R.find((c) => c.did === did, contacts); +} - Similar logic is found in endorser-mobile. +/** + * + * 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 { + 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 + ? { displayName: "You (Alt ID)", known: true } + : isHiddenDid(did) + ? { 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, @@ -363,19 +407,8 @@ export function didInfo( allMyDids: string[], contacts: Contact[], ): string { - if (!did) return "Someone Anonymous"; - - const contact = R.find((c) => c.did === did, contacts); - if (contact) { - return contact.name || "Contact With No Name"; - } else { - const myId = R.find(R.equals(did), allMyDids); - return myId - ? `You${myId !== activeDid ? " (Alt ID)" : ""}` - : isHiddenDid(did) - ? "Someone Outside Your Network" - : "Someone Outside Contacts"; - } + const contact = contactForDid(did, contacts); + return didInfoForContact(did, activeDid, contact, allMyDids).displayName; } /** diff --git a/src/router/index.ts b/src/router/index.ts index 0e653ad4..68da028f 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 47633a55..864db7c0 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -1,5 +1,5 @@