From 95579864570216eb69bd8c0dd3b033d3980a4a35 Mon Sep 17 00:00:00 2001 From: MiZiet <55240109+MiZiet@users.noreply.github.com> Date: Fri, 18 Dec 2020 18:32:29 +0100 Subject: [PATCH] Add create bounty modal (#4231) * Add new bounty modal with inputs * WIP - add bounty bond to modal * Add bounty bond * Remove "Add Bounty" from locales * useCallback for input change handler Co-authored-by: Ewa Kowalska Co-authored-by: Krzysztof Jelski --- .../apps/public/locales/en/app-bounties.json | 10 ++ packages/page-bounties/src/Bounties.tsx | 36 +++++--- packages/page-bounties/src/BountyCreate.tsx | 91 +++++++++++++++++++ .../src/helpers/calculateBountyBond.spec.ts | 25 +++++ .../src/helpers/calculateBountyBond.ts | 14 +++ 5 files changed, 161 insertions(+), 15 deletions(-) create mode 100644 packages/page-bounties/src/BountyCreate.tsx create mode 100644 packages/page-bounties/src/helpers/calculateBountyBond.spec.ts create mode 100644 packages/page-bounties/src/helpers/calculateBountyBond.ts diff --git a/packages/apps/public/locales/en/app-bounties.json b/packages/apps/public/locales/en/app-bounties.json index 6c0797dfa1..1cdfba76ff 100644 --- a/packages/apps/public/locales/en/app-bounties.json +++ b/packages/apps/public/locales/en/app-bounties.json @@ -1,11 +1,21 @@ { + "Add Bounty": "Add Bounty", "Bounties": "Bounties", + "Calculated bond for bounty": "Calculated bond for bounty", "Claimable": "Claimable", "No open bounties": "No open bounties", + "Select the account you wish to propose the bounty from.": "Select the account you wish to propose the bounty from.", + "The description of this bounty": "The description of this bounty", + "The total payment amount of this bounty, curators fee included.": "The total payment amount of this bounty, curators fee included.", + "This amount will be reserved from origin account and returned on approval or slashed upon rejection.": "This amount will be reserved from origin account and returned on approval or slashed upon rejection.", "beneficiary": "beneficiary", "bounties": "bounties", + "bounty bond": "bounty bond", + "bounty requested allocation": "bounty requested allocation", + "bounty title": "bounty title", "curator": "curator", "payout due": "payout due", + "submit with account": "submit with account", "title": "title", "update due": "update due", "value": "value", diff --git a/packages/page-bounties/src/Bounties.tsx b/packages/page-bounties/src/Bounties.tsx index 7d4d61b026..7cd4b4753a 100644 --- a/packages/page-bounties/src/Bounties.tsx +++ b/packages/page-bounties/src/Bounties.tsx @@ -6,7 +6,8 @@ import type { BlockNumber } from '@polkadot/types/interfaces'; import React, { useRef } from 'react'; -import { Table } from '@polkadot/react-components'; +import BountyCreate from '@polkadot/app-bounties/BountyCreate'; +import { Button, Table } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; import Bounty from './Bounty'; @@ -33,20 +34,25 @@ function Bounties (): React.ReactElement { ]); return ( - ('No open bounties')} - header={headerRef.current} - > - {deriveBounties && bestNumber && deriveBounties.map(({ bounty, description }, index) => ( - - ))} -
+ <> + + + + ('No open bounties')} + header={headerRef.current} + > + {deriveBounties && bestNumber && deriveBounties.map(({ bounty, description }, index) => ( + + ))} +
+ ); } diff --git a/packages/page-bounties/src/BountyCreate.tsx b/packages/page-bounties/src/BountyCreate.tsx new file mode 100644 index 0000000000..f30a389c95 --- /dev/null +++ b/packages/page-bounties/src/BountyCreate.tsx @@ -0,0 +1,91 @@ +// Copyright 2017-2020 @polkadot/app-bounties authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import BN from 'bn.js'; +import React, { useCallback, useState } from 'react'; + +import { useTranslation } from '@polkadot/app-accounts/translate'; +import { calculateBountyBond } from '@polkadot/app-bounties/helpers/calculateBountyBond'; +import { Button, Input, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; +import { useApi, useToggle } from '@polkadot/react-hooks'; +import { BN_ZERO } from '@polkadot/util'; + +function BountyCreate () { + const { t } = useTranslation(); + const { api } = useApi(); + + const [accountId, setAccountId] = useState(null); + const [title, setTitle] = useState(''); + const [bond, setBond] = useState(api.consts.treasury.bountyDepositBase.toBn()); + const [amount, setAmount] = useState(BN_ZERO); + const [isValid] = useState(true); + const [isOpen, toggleIsOpen] = useToggle(); + + const onTitleChange = useCallback((value: string) => { + const bountyDepositBase = api.consts.treasury.bountyDepositBase; + const bountyDepositPerByte = api.consts.treasury.dataDepositPerByte; + + setTitle(value); + setBond(calculateBountyBond(value, bountyDepositBase, bountyDepositPerByte)); + }, [api]); + + return ( + <> +