forked from w3f-webops/polkadot-staking-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNominate.tsx
73 lines (66 loc) · 2.3 KB
/
Nominate.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only
import { useTranslation } from 'react-i18next';
import { useApi } from 'contexts/Api';
import { useSetup } from 'contexts/Setup';
import { Footer } from 'library/SetupSteps/Footer';
import { Header } from 'library/SetupSteps/Header';
import { MotionContainer } from 'library/SetupSteps/MotionContainer';
import { useActiveAccounts } from 'contexts/ActiveAccounts';
import { Subheading } from 'pages/Nominate/Wrappers';
import { GenerateNominations } from '../GenerateNominations';
import type { NominationsProps } from './types';
import type { AnyJson } from 'types';
export const Nominate = ({ bondFor, section }: NominationsProps) => {
const { t } = useTranslation('library');
const { consts } = useApi();
const { activeAccount } = useActiveAccounts();
const { getNominatorSetup, getPoolSetup, setActiveAccountSetup } = useSetup();
const setup =
bondFor === 'nominator'
? getNominatorSetup(activeAccount)
: getPoolSetup(activeAccount);
const { progress } = setup;
const { maxNominations } = consts;
// Handler for updating setup.
const handleSetupUpdate = (value: AnyJson) => {
setActiveAccountSetup(bondFor, value);
};
return (
<>
<Header
thisSection={section}
complete={progress.nominations.length > 0}
title={t('nominate')}
helpKey="Nominating"
bondFor={bondFor}
/>
<MotionContainer thisSection={section} activeSection={setup.section}>
<Subheading>
<h4>
{t('chooseValidators', {
maxNominations: maxNominations.toString(),
})}
</h4>
</Subheading>
<GenerateNominations
setters={[
{
current: {
callable: true,
fn: () =>
(bondFor === 'nominator'
? getNominatorSetup(activeAccount)
: getPoolSetup(activeAccount)
).progress,
},
set: handleSetupUpdate,
},
]}
nominations={{ nominations: progress.nominations }}
/>
<Footer complete={progress.nominations.length > 0} bondFor={bondFor} />
</MotionContainer>
</>
);
};