ghost-portal/packages/react-hooks/src/useRegistrars.ts
MiZiet 053e0efca2
Split registrars display (#6157)
* Add subs modal

* Add tests

* Add Translations

* Improve closing modal

* Improve tests

* Improve styles

* Style balances & identity

* Optimize imports

* Improve styles

* Set greater width to balance section

* Rename subs modal toggle

* Change 'amount' to 'count' in test name

* Set make modal header fixed while content is scrollable

* Style multisig

* Update multisig styles

* Capitalize headers

* Move sidebar tests to Sidebar.spec.tsx

* Remove duplications in tests

* Add UserIcon component

* Revert subs modal changes and add scrollable section in Sidebar

* Remove unused styles

* Use accountsPage clearAccount method

* Wrap subs into Expander

* Add useSubidentities hook

* Adjust api mock in tests

* WIP - split judgements

* Display judgements

* Handle no judgements case

* [WIP] Add popup test

* Extract JudgmentTag component

* Add popup test

* Refactor tests and remove pointer from no judgements tag

* Extract JudgementTag test class

* Close popup on scroll

* Remove old section

* Clean registration

* Clean up identity in useAccountInfo and mock in Page

* Remove fragment tag

* Fix imports

* Move SortedJudgements to /types

* Move Registrar interface to types

* Refactor clickRegistrar fcn

* Move hasAccount check to isRegistrar

* Add useJudgements hook

* Rename and move getJudgementColor to utils

* Fix import and casting in tests

* Sort imports

* Add review fixes

* Fix tests

Co-authored-by: Krzysztof Jelski <krzysztof@ethworks.io>
Co-authored-by: Ewa Kowalska <ewcia.kowalska@gmail.com>
Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2021-09-29 10:45:34 +02:00

50 lines
1.4 KiB
TypeScript

// Copyright 2017-2021 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@polkadot/types';
import type { RegistrarInfo } from '@polkadot/types/interfaces';
import type { Registrar } from './types';
import { useMemo } from 'react';
import { useAccounts } from './useAccounts';
import { useApi } from './useApi';
import { useCall } from './useCall';
interface RegistrarNull {
address: string | null;
index: number;
}
interface State {
isRegistrar: boolean;
registrars: Registrar[];
skipQuery?: boolean;
}
export function useRegistrars (skipQuery?: boolean): State {
const { api } = useApi();
const { allAccounts, hasAccounts } = useAccounts();
const query = useCall<Option<RegistrarInfo>[]>(!skipQuery && api.query.identity?.registrars);
// determine if we have a registrar or not - registrars are allowed to approve
return useMemo(
(): State => {
const registrars = (query || [])
.map((registrar, index): RegistrarNull => ({
address: registrar.isSome
? registrar.unwrap().account.toString()
: null,
index
}))
.filter((registrar): registrar is Registrar => !!registrar.address);
return {
isRegistrar: hasAccounts && registrars.some(({ address }) => allAccounts.includes(address)),
registrars
};
},
[allAccounts, hasAccounts, query]
);
}