* 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>
65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
// Copyright 2017-2021 @polkadot/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { DeriveAccountRegistration } from '@polkadot/api-derive/types';
|
|
import type { DisplayedJudgement } from '@polkadot/react-components/types';
|
|
import type { SortedJudgements } from '@polkadot/react-components/util/types';
|
|
import type { RegistrationJudgement } from '@polkadot/types/interfaces';
|
|
|
|
function extractIndexes (registrars: RegistrationJudgement[]) {
|
|
return registrars.map((judgement) => judgement[0]);
|
|
}
|
|
|
|
export function getJudgements (identity: DeriveAccountRegistration | undefined): SortedJudgements {
|
|
if (!identity) return [];
|
|
|
|
const judgements = groupJudgements(identity.judgements);
|
|
|
|
const result = [];
|
|
|
|
for (const name in judgements) {
|
|
const judgementName = name as DisplayedJudgement;
|
|
|
|
if (judgements[judgementName].length !== 0) {
|
|
result.push({ judgementName, registrarsIndexes: extractIndexes(judgements[judgementName]) });
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export function groupJudgements (judgements: RegistrationJudgement[]): Record<DisplayedJudgement, RegistrationJudgement[]> {
|
|
const consideredJudgements = filterConsideredJudgements(judgements);
|
|
const knownGoodJudgements = filterKnownGood(consideredJudgements);
|
|
const reasonableJudgements = filterReasonable(consideredJudgements);
|
|
const erroneousJudgements = filterErroneous(consideredJudgements);
|
|
const lowQualityJudgements = filterLowQuality(consideredJudgements);
|
|
|
|
return {
|
|
Erroneous: erroneousJudgements,
|
|
'Known good': knownGoodJudgements,
|
|
'Low quality': lowQualityJudgements,
|
|
Reasonable: reasonableJudgements
|
|
};
|
|
}
|
|
|
|
const filterConsideredJudgements = (judgements: RegistrationJudgement[]): RegistrationJudgement[] => {
|
|
return judgements.filter(([, judgement]) => !judgement.isFeePaid);
|
|
};
|
|
|
|
const filterKnownGood = (judgements: RegistrationJudgement[]): RegistrationJudgement[] => {
|
|
return judgements.filter(([, judgement]) => judgement.isKnownGood);
|
|
};
|
|
|
|
const filterReasonable = (judgements: RegistrationJudgement[]): RegistrationJudgement[] => {
|
|
return judgements.filter(([, judgement]) => judgement.isReasonable);
|
|
};
|
|
|
|
const filterErroneous = (judgements: RegistrationJudgement[]): RegistrationJudgement[] => {
|
|
return judgements.filter(([, judgement]) => judgement.isErroneous);
|
|
};
|
|
|
|
const filterLowQuality = (judgements: RegistrationJudgement[]): RegistrationJudgement[] => {
|
|
return judgements.filter(([, judgement]) => judgement.isLowQuality);
|
|
};
|