From 94e57f6dcf2e6157be8075109b7b99319e81ec24 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 2 Dec 2020 19:23:30 +0100 Subject: [PATCH] hasIndentities extract base (#2900) --- packages/api-derive/src/accounts/identity.ts | 18 +++++++++++++----- packages/api-derive/src/accounts/types.ts | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/api-derive/src/accounts/identity.ts b/packages/api-derive/src/accounts/identity.ts index 815261440a..7fc432e543 100644 --- a/packages/api-derive/src/accounts/identity.ts +++ b/packages/api-derive/src/accounts/identity.ts @@ -10,7 +10,7 @@ import type { DeriveAccountRegistration, DeriveHasIdentity } from '../types'; import { combineLatest, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { u8aToString } from '@polkadot/util'; +import { isHex, u8aToString } from '@polkadot/util'; import { memo } from '../util'; @@ -121,13 +121,21 @@ export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (acc const superOfOpt = supers[index]; const parentId = superOfOpt && superOfOpt.isSome ? superOfOpt.unwrap()[0].toString() - : null; - const hasIdentity = !!parentId || !!(identityOfOpt && identityOfOpt.isSome); + : undefined; + let display: string | undefined; - return { hasIdentity, parentId }; + if (identityOfOpt && identityOfOpt.isSome) { + const value = dataAsString(identityOfOpt.unwrap().info.display); + + if (value && !isHex(value)) { + display = value; + } + } + + return { display, hasIdentity: !!(display || parentId), parentId }; }) ) ) - : of(accountIds.map(() => ({ hasIdentity: false, parentId: null }))) + : of(accountIds.map(() => ({ hasIdentity: false }))) ); } diff --git a/packages/api-derive/src/accounts/types.ts b/packages/api-derive/src/accounts/types.ts index d0d0124413..392a2c7079 100644 --- a/packages/api-derive/src/accounts/types.ts +++ b/packages/api-derive/src/accounts/types.ts @@ -37,6 +37,7 @@ export interface DeriveAccountInfo { } export interface DeriveHasIdentity { + display?: string; hasIdentity: boolean; - parentId: string | null; + parentId?: string; }