Skip to content

Commit

Permalink
Fix api.derive.accounts.{info && identity} (#5885)
Browse files Browse the repository at this point in the history
* Fix api.derive.accounts.identity and all residual derives

* reorder types
  • Loading branch information
TarikGul authored May 17, 2024
1 parent baaa27b commit f9c5820
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/api-derive/src/accounts/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import type { Observable } from 'rxjs';
import type { Bytes, Data } from '@polkadot/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Bytes, Data, Struct } from '@polkadot/types';
import type { AccountId, H160 } from '@polkadot/types/interfaces';
import type { PalletIdentityLegacyIdentityInfo, PalletIdentityRegistration } from '@polkadot/types/lookup';
import type { Option } from '@polkadot/types-codec';
import type { ITuple } from '@polkadot/types-codec/types';
Expand All @@ -17,9 +17,26 @@ import { firstMemo, memo } from '../util/index.js';

type IdentityInfoAdditional = PalletIdentityLegacyIdentityInfo['additional'][0];

interface PeopleIdentityInfo extends Struct {
display: Data;
legal: Data;
web: Data;
matrix: Data;
email: Data;
pgpFingerprint: Option<H160>;
image: Data;
twitter: Data;
github: Data;
discord: Data;
}

const UNDEF_HEX = { toHex: () => undefined };

function dataAsString (data: Data): string | undefined {
if (!data) {
return data;
}

return data.isRaw
? u8aToString(data.asRaw.toU8a(true))
: data.isNone
Expand Down Expand Up @@ -58,13 +75,16 @@ function extractIdentity (identityOfOpt?: Option<ITuple<[PalletIdentityRegistrat
const topDisplay = dataAsString(info.display);

return {
discord: dataAsString((info as unknown as PeopleIdentityInfo).discord),
display: (superOf && dataAsString(superOf[1])) || topDisplay,
displayParent: superOf && topDisplay,
email: dataAsString(info.email),
github: dataAsString((info as unknown as PeopleIdentityInfo).github),
image: dataAsString(info.image),
judgements,
legal: dataAsString(info.legal),
other: extractOther(info.additional),
matrix: dataAsString((info as unknown as PeopleIdentityInfo).matrix),
other: info.additional ? extractOther(info.additional) : {},
parent: superOf?.[0],
pgp: info.pgpFingerprint.unwrapOr(UNDEF_HEX).toHex(),
riot: dataAsString(info.riot),
Expand Down
3 changes: 3 additions & 0 deletions packages/api-derive/src/accounts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export type AccountIdAndIndex = [AccountId | undefined, AccountIndex | undefined
export type AccountIndexes = Record<string, AccountIndex>;

export interface DeriveAccountRegistration {
discord?: string | undefined;
display?: string | undefined;
displayParent?: string | undefined;
email?: string | undefined;
github?: string | undefined;
image?: string | undefined;
legal?: string | undefined;
matrix?: string | undefined;
other?: Record<string, string> | undefined;
parent?: AccountId | undefined;
pgp?: string | undefined;
Expand Down

0 comments on commit f9c5820

Please sign in to comment.