Allow api.derive.accounts.identity() to obtain SubIdentities (#6066)
* Allow api.derive.accounts.identity to obtain subidentities * Fix subs type
This commit is contained in:
@@ -135,11 +135,36 @@ export function identity (instanceId: string, api: DeriveApi): (accountId?: Acco
|
||||
),
|
||||
map(([identityOfOpt, superOf]) =>
|
||||
extractIdentity(identityOfOpt, superOf)
|
||||
),
|
||||
switchMap((identity) =>
|
||||
getSubIdentities(identity, api, accountId)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// if an account has no parents it will extract its subidentities
|
||||
// otherwise if the account is a subidentity, obtain all subidentities of its parent.
|
||||
function getSubIdentities (identity: DeriveAccountRegistration, api: DeriveApi, accountId?: AccountId | Uint8Array | string): Observable<DeriveAccountRegistration> {
|
||||
const targetAccount = identity.parent || accountId;
|
||||
|
||||
if (!targetAccount) {
|
||||
// No valid accountId return the identity as-is
|
||||
return of(identity);
|
||||
}
|
||||
|
||||
return api.query.identity.subsOf(targetAccount).pipe(
|
||||
map((subsResponse) => {
|
||||
const subs = subsResponse[1];
|
||||
|
||||
return {
|
||||
...identity,
|
||||
subs
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const hasIdentity = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: AccountId | Uint8Array | string) =>
|
||||
api.derive.accounts.hasIdentityMulti([accountId])
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId, AccountIndex, RegistrationJudgement } from '@polkadot/types/interfaces';
|
||||
import type { Vec } from '@polkadot/types-codec';
|
||||
|
||||
export type AccountIdAndIndex = [AccountId | undefined, AccountIndex | undefined];
|
||||
|
||||
@@ -20,6 +21,7 @@ export interface DeriveAccountRegistration {
|
||||
parent?: AccountId | undefined;
|
||||
pgp?: string | undefined;
|
||||
riot?: string | undefined;
|
||||
subs?: Vec<AccountId> | undefined;
|
||||
twitter?: string | undefined;
|
||||
web?: string | undefined;
|
||||
judgements: RegistrationJudgement[];
|
||||
|
||||
Reference in New Issue
Block a user