Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/app-society/src/Overview/Bid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017-2020 @polkadot/app-society authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { Bid } from '@polkadot/types/interfaces';

import React from 'react';
import { AddressSmall } from '@polkadot/react-components';
import { FormatBalance } from '@polkadot/react-query';

import { useTranslation } from '../translate';

interface Props {
value: Bid;
}

export default function BidRow ({ value: { who, kind, value } }: Props): React.ReactElement<Props> {
const { t } = useTranslation();

return (
<tr>
<td className='top'>
<AddressSmall value={who} />
</td>
<td className='number top'>
<label>{t('kind')}</label>
{kind.type}
</td>
<td className='number top'>
<FormatBalance
label={<label>{t('value')}</label>}
value={value}
/>
</td>
</tr>
);
}
43 changes: 43 additions & 0 deletions packages/app-society/src/Overview/Bids.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2017-2020 @polkadot/app-society authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { Bid } from '@polkadot/types/interfaces';

import React from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';

import { useTranslation } from '../translate';
import BidRow from './Bid';

interface Props {
className?: string;
}

export default function Bids ({ className }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const bids = useCall<Bid[]>(api.query.society.bids, []);

return (
<div className={`overviewSection ${className}`}>
<h1>{t('bids')}</h1>
{bids?.length
? (
<Table>
<Table.Body>
{bids.map((bid): React.ReactNode => (
<BidRow
key={bid.who.toString()}
value={bid}
/>
))}
</Table.Body>
</Table>
)
: t('No bids')
}
</div>
);
}
4 changes: 2 additions & 2 deletions packages/app-society/src/Overview/Candidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export default function Candidate ({ value: { accountId, kind, value } }: Props)
</td>
<td className='number top'>
<label>{t('kind')}</label>
{kind.toString()}
{kind.type}
</td>
<td className='number top'>
<FormatBalance
label={t('value')}
label={<label>{t('value')}</label>}
value={value}
/>
</td>
Expand Down
44 changes: 34 additions & 10 deletions packages/app-society/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { DeriveSociety } from '@polkadot/api-derive/types';
import { AccountId } from '@polkadot/types/interfaces';
import { AccountId, BlockNumber } from '@polkadot/types/interfaces';

import React from 'react';
import styled from 'styled-components';
import { AccountName, IdentityIcon, SummaryBox, CardSummary } from '@polkadot/react-components';
import { AccountIndex, IdentityIcon, SummaryBox, CardSummary } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { formatBalance } from '@polkadot/util';

Expand All @@ -34,7 +34,7 @@ function Name ({ label, value }: NameProps): React.ReactElement<NameProps> | nul
size={24}
value={value}
/>
<AccountName value={value} />
<AccountIndex value={value} />
</div>
</CardSummary>
);
Expand All @@ -45,6 +45,7 @@ function Summary ({ className }: Props): React.ReactElement<Props> {
const { api } = useApi();
const info = useCall<DeriveSociety>(api.derive.society.info, []);
const members = useCall<any[]>(api.derive.society.members, []);
const bestNumber = useCall<BlockNumber>(api.derive.chain.bestNumber, []);

const pot = info?.pot.gtn(0)
? info.pot.toString()
Expand All @@ -58,19 +59,42 @@ function Summary ({ className }: Props): React.ReactElement<Props> {
value={info?.head}
/>
</section>
<section>
<section className='ui--media-medium'>
{info && members && (
<CardSummary label={t('members')}>
{members.length}/{info.maxMembers.toString()}
</CardSummary>
)}
</section>
{bestNumber && (
<>
<section>
<CardSummary
label={t('rotation')}
progress={{
total: api.consts.society.rotationPeriod as BlockNumber,
value: bestNumber.mod(api.consts.society.rotationPeriod as BlockNumber)
}}
/>
</section>
<section className='ui--media-large'>
<CardSummary
label={t('challenge')}
progress={{
total: api.consts.society.challengePeriod as BlockNumber,
value: bestNumber.mod(api.consts.society.challengePeriod as BlockNumber)
}}
/>
</section>
</>
)}
<section>
{pot && (
<CardSummary label={t('available')}>
{formatBalance(pot, false)}{formatBalance.calcSi(pot).value}
</CardSummary>
)}
<CardSummary label={t('pot')}>
{pot
? <>{formatBalance(pot, false)}{formatBalance.calcSi(pot).value}</>
: '-'
}
</CardSummary>
</section>
</SummaryBox>
);
Expand All @@ -80,7 +104,7 @@ export default styled(Summary)`
.society--header--account {
white-space: nowrap;

.ui--AccountName,
.ui--AccountIndex,
.ui--IdentityIcon {
display: inline-block;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/app-society/src/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import React from 'react';
import styled from 'styled-components';

import Bids from './Bids';
import Candidates from './Candidates';
import Members from './Members';
import Summary from './Summary';
Expand All @@ -19,6 +20,7 @@ function Overview ({ className }: Props): React.ReactElement<Props> {
<Summary />
<Members />
<Candidates />
<Bids />
</div>
);
}
Expand Down