Extract sub identities (via accounts derive) (#1713)

* Extract sub identities

* Cleanups
This commit is contained in:
Jaco Greeff
2020-01-12 14:42:42 +01:00
committed by GitHub
parent 44b56fb0cb
commit 7ac3043f83
2 changed files with 58 additions and 21 deletions
+55 -21
View File
@@ -36,32 +36,66 @@ function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<s
);
}
function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
if (!identityOfOpt?.isSome) {
return { judgements: [] };
}
const { info, judgements } = identityOfOpt.unwrap();
const topDisplay = dataAsString(info.display);
return {
display: superOf
? dataAsString(superOf[1]) || topDisplay
: topDisplay,
displayParent: superOf
? topDisplay
: undefined,
email: dataAsString(info.email),
image: dataAsString(info.image),
legal: dataAsString(info.legal),
parent: superOf
? superOf[0]
: undefined,
pgp: info.pgpFingerprint.isSome
? info.pgpFingerprint.unwrap().toHex()
: undefined,
riot: dataAsString(info.riot),
twitter: dataAsString(info.twitter),
web: dataAsString(info.web),
judgements
};
}
function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observable<DeriveAccountRegistration> {
return ((
accountId && api.query.identity?.identityOf
? api.query.identity.identityOf<Option<Registration>>(accountId)
: of(undefined)
) as Observable<Option<Registration> | undefined>).pipe(
map((identityOfOpt): DeriveAccountRegistration => {
if (!identityOfOpt?.isSome) {
return { judgements: [] };
? api.queryMulti([
[api.query.identity.identityOf, accountId],
[api.query.identity.superOf, accountId]
])
: of([undefined, undefined])
) as Observable<[Option<Registration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]>).pipe(
switchMap(([identityOfOpt, superOfOpt]): Observable<[Option<Registration> | undefined, [AccountId, Data] | undefined]> => {
if (identityOfOpt?.isSome) {
// this identity has something set
return of([identityOfOpt, undefined]);
} else if (superOfOpt?.isSome) {
const superOf = superOfOpt.unwrap();
// we have a super
return combineLatest([
api.query.identity.identityOf<Option<Registration>>(superOf[0]),
of(superOf)
]);
}
const { info, judgements } = identityOfOpt.unwrap();
return {
display: dataAsString(info.display),
email: dataAsString(info.email),
image: dataAsString(info.image),
legal: dataAsString(info.legal),
pgp: info.pgpFingerprint.isSome
? info.pgpFingerprint.unwrap().toHex()
: undefined,
riot: dataAsString(info.riot),
web: dataAsString(info.web),
judgements
};
})
// nothing of value returned
return of([undefined, undefined]);
}),
map(([identityOfOpt, superOf]): DeriveAccountRegistration =>
extractIdentity(identityOfOpt, superOf)
)
);
}
+3
View File
@@ -11,11 +11,14 @@ export type AccountIndexes = Record<string, AccountIndex>;
export interface DeriveAccountRegistration {
display?: string;
displayParent?: string;
email?: string;
image?: string;
legal?: string;
parent?: AccountId;
pgp?: string;
riot?: string;
twitter?: string;
web?: string;
judgements: RegistrationJudgement[];
}