-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Society vouching * Bump API, decode votes * Inline count * Remove unused style
- Loading branch information
Showing
11 changed files
with
256 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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 React, { useMemo, useState } from 'react'; | ||
import { useToggle } from '@polkadot/react-hooks'; | ||
|
||
import { useTranslation } from '../translate'; | ||
import { Button, Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; | ||
|
||
interface Props { | ||
candidateId: string; | ||
isMember: boolean; | ||
ownMembers: string[]; | ||
} | ||
|
||
export default function CandidateVoting ({ candidateId, isMember, ownMembers }: Props): React.ReactElement<Props> { | ||
const { t } = useTranslation(); | ||
const [isVisible, toggleVisible] = useToggle(); | ||
const [vote, setVote] = useState(true); | ||
const [accountId, setAccountId] = useState<string | null>(null); | ||
const voteOpts = useMemo(() => [ | ||
{ text: t('Aye, I approve'), value: true }, | ||
{ text: t('Nay, I do not approve'), value: false } | ||
], [t]); | ||
|
||
return ( | ||
<> | ||
{isVisible && ( | ||
<Modal header={t('Vote for candidate')}> | ||
<Modal.Content> | ||
<InputAddress | ||
filter={ownMembers} | ||
help={t('The address to vote from (must be a member)')} | ||
label={t('vote from account')} | ||
onChange={setAccountId} | ||
/> | ||
<Dropdown | ||
help={t('Approve this candidacy.')} | ||
label={t('vote for andidate')} | ||
onChange={setVote} | ||
options={voteOpts} | ||
value={vote} | ||
/> | ||
</Modal.Content> | ||
<Modal.Actions onCancel={toggleVisible}> | ||
<TxButton | ||
accountId={accountId} | ||
icon='check' | ||
label={t('Vote')} | ||
onStart={toggleVisible} | ||
params={[candidateId, vote]} | ||
tx='society.vote' | ||
/> | ||
</Modal.Actions> | ||
</Modal> | ||
)} | ||
<Button | ||
icon='check' | ||
isDisabled={!isMember} | ||
isPrimary | ||
label={t('Vote')} | ||
onClick={toggleVisible} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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 { DeriveSocietyMember } from '@polkadot/api-derive/types'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { useAccounts, useApi, useCall } from '@polkadot/react-hooks'; | ||
|
||
interface OwnMembers { | ||
allMembers: string[]; | ||
isMember: boolean; | ||
ownMembers: string[]; | ||
} | ||
|
||
export default function useMembers (): OwnMembers { | ||
const { api } = useApi(); | ||
const { allAccounts } = useAccounts(); | ||
const members = useCall<DeriveSocietyMember[]>(api.derive.society.members, []); | ||
const [ownState, setOwnState] = useState<OwnMembers>({ allMembers: [], isMember: false, ownMembers: [] }); | ||
|
||
useEffect((): void => { | ||
if (allAccounts && members) { | ||
const allMembers = members | ||
.filter((member): boolean => !member.isSuspended) | ||
.map((member): string => member.accountId.toString()); | ||
const ownMembers = allMembers | ||
.filter((address): boolean => allAccounts.includes(address)); | ||
|
||
setOwnState({ allMembers, isMember: ownMembers.length !== 0, ownMembers }); | ||
} | ||
}, [allAccounts, members]); | ||
|
||
return ownState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.