Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Funding request multiple recipient preview #4509

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
254936f
preview multiple receipients modal
vrrayz Jun 20, 2023
dead262
multiple funding request validation
vrrayz Jun 20, 2023
4d0bfa0
csv reg exp pattern
vrrayz Jun 20, 2023
30651dc
Preview And Validate Modal validation
vrrayz Jun 21, 2023
e7517cc
lint fix
vrrayz Jun 21, 2023
e7d4b82
Tx fail fix
vrrayz Jun 21, 2023
51ddf50
suggestions
vrrayz Jul 24, 2023
dc0fb3d
Merge branch 'dev' of https://github.com/vrrayz/pioneer into issue-2365
vrrayz Jul 24, 2023
383089d
lint fix
vrrayz Jul 24, 2023
d06d0ca
side drawer
vrrayz Jul 25, 2023
1abf1d0
csv pattern change and cleanup
vrrayz Jul 25, 2023
283dd51
Multiple funding request test
vrrayz Jul 28, 2023
91cb882
lint
vrrayz Jul 28, 2023
f4477df
Merge branch 'Joystream:dev' into issue-2365
vrrayz Jul 28, 2023
e018470
Merge branch 'issue-2365' of https://github.com/vrrayz/pioneer into i…
vrrayz Jul 28, 2023
855aa76
Update packages/ui/src/app/pages/Proposals/CurrentProposals.stories.tsx
vrrayz Aug 6, 2023
44dcd9a
requested changes
vrrayz Aug 7, 2023
8fdbc0b
Merge branch 'Joystream:dev' into issue-2365
vrrayz Aug 7, 2023
172518f
lint
vrrayz Aug 7, 2023
617ab12
disable preview button
vrrayz Aug 11, 2023
18b3cf5
Merge branch 'dev' of https://github.com/vrrayz/pioneer into issue-2365
vrrayz Aug 11, 2023
904d370
Merge branch 'Joystream:dev' into issue-2365
vrrayz Aug 11, 2023
59f10f2
updated storybook test for multiple funding request
vrrayz Aug 11, 2023
9a3d8bb
Merge branch 'issue-2365' of https://github.com/vrrayz/pioneer into i…
vrrayz Aug 11, 2023
313eb98
requested changes
vrrayz Aug 11, 2023
f58a6fb
requested changes
vrrayz Aug 11, 2023
548fc6d
Preview multi recipients proposal in storybook
thesan Aug 9, 2023
48e898d
Fix the story
thesan Aug 18, 2023
81d9d19
Merge branch 'feature/multi-recipient-story' of https://github.com/th…
vrrayz Aug 30, 2023
397bc2c
Preview fix
vrrayz Aug 30, 2023
733d99b
build fix
vrrayz Aug 31, 2023
2da82e8
requested changes
vrrayz Sep 1, 2023
ba0c7ab
requested changes
vrrayz Sep 1, 2023
6b04de3
council budget added to funding proposal
vrrayz Sep 1, 2023
9c64ed7
council budget added to funding proposal
vrrayz Sep 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ export const FillWorkingGroupLeadOpening: Story = {
export const FundingRequest: Story = {
args: { type: 'FundingRequestProposalDetails' },
}
export const FundingRequestMultipleRecipients: Story = {
args: { type: 'FundingRequestMultipleRecipientsProposalDetails' },
}
export const RuntimeUpgrade: Story = {
args: { type: 'RuntimeUpgradeProposalDetails', constitutionality: 2 },
parameters: {
Expand Down
19 changes: 15 additions & 4 deletions packages/ui/src/mocks/data/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ const proposalDetails = {
destinations: [{ __typename: 'FundingRequestDestination', amount: joy(200), account: membership.rootAccount }],
},
},
FundingRequestMultipleRecipientsProposalDetails: {
destinationsList: {
__typename: 'FundingRequestDestinationsList',
destinations: [
{ __typename: 'FundingRequestDestination', amount: joy(200), account: membership.rootAccount },
{ __typename: 'FundingRequestDestination', amount: joy(20), account: member('alice').rootAccount },
{ __typename: 'FundingRequestDestination', amount: joy(1), account: member('bob').rootAccount },
{ __typename: 'FundingRequestDestination', amount: joy(500), account: member('charlie').rootAccount },
],
},
},
RuntimeUpgradeProposalDetails: { newRuntimeBytecode: { __typename: 'RuntimeWasmBytecode', id: '0' } },
SetCouncilBudgetIncrementProposalDetails: { newAmount: joy(200) },
SetCouncilorRewardProposalDetails: { newRewardPerBlock: joy(200) },
Expand All @@ -79,10 +90,10 @@ const proposalDetails = {
VetoProposalDetails: { proposal: { __typename: 'Proposal', id: '0', title: random.words(4) } },
} as Record<string, RecursivePartial<ProposalWithDetailsFieldsFragment['details']>>

export const proposalDetailsMap = mapValues(
proposalDetails,
(value, __typename) => Object.assign(value, { __typename }) as Partial<ProposalWithDetailsFieldsFragment['details']>
)
export const proposalDetailsMap = mapValues(proposalDetails, (value, key) => {
const __typename = key === 'FundingRequestMultipleRecipientsProposalDetails' ? 'FundingRequestProposalDetails' : key
return Object.assign(value, { __typename }) as Partial<ProposalWithDetailsFieldsFragment['details']>
})

export const proposalTypes = Object.keys(proposalDetailsMap) as ProposalDetailsType[]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Api } from '@/api'
import { ProposalFieldsFragment } from '@/proposals/queries'

export type ProposalDetailsType = ProposalFieldsFragment['details']['__typename']
export type ProposalDetailsType =
| ProposalFieldsFragment['details']['__typename']
| 'FundingRequestMultipleRecipientsProposalDetails'

export const proposalDetailsToConstantKey = (details: ProposalDetailsType) =>
proposalDetailsToConstantKeyMap.get(details) as string
Expand All @@ -13,6 +15,7 @@ const proposalDetailsToConstantKeyMap = new Map<ProposalDetailsType, keyof Api['
['DecreaseWorkingGroupLeadStakeProposalDetails', 'decreaseWorkingGroupLeadStakeProposalParameters'],
['FillWorkingGroupLeadOpeningProposalDetails', 'fillWorkingGroupOpeningProposalParameters'],
['FundingRequestProposalDetails', 'fundingRequestProposalParameters'],
['FundingRequestMultipleRecipientsProposalDetails', 'fundingRequestProposalParameters'],
['RuntimeUpgradeProposalDetails', 'runtimeUpgradeProposalParameters'],
['SetCouncilBudgetIncrementProposalDetails', 'setCouncilBudgetIncrementProposalParameters'],
['SetCouncilorRewardProposalDetails', 'setCouncilorRewardProposalParameters'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useWorkingGroup } from '@/working-groups/hooks/useWorkingGroup'
import {
Address,
Amount,
DestinationsPreview,
Divider,
Hash,
Markdown,
Expand Down Expand Up @@ -49,6 +50,7 @@ const renderTypeMapper: Partial<Record<RenderType, ProposalDetailContent>> = {
OpeningLink: OpeningLink,
Percentage: Percentage,
Hash: Hash,
DestinationsPreview: DestinationsPreview,
}

export const ProposalDetails = ({ proposalDetails }: Props) => {
Expand Down Expand Up @@ -78,6 +80,16 @@ export const ProposalDetails = ({ proposalDetails }: Props) => {
] as RenderNode[]
}

if (proposalDetails?.type === 'fundingRequest') {
return [
{
renderType: 'Amount',
label: 'Current WG Budget',
value: group?.budget,
},
] as RenderNode[]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works. I'm not sure why but the WG budget that this proposal should show is the content WG.

Here proposalDetails?.group?.id doesn't exist so the budget remain at 0.
Check https://dao-git-fork-vrrayz-funding-request-multiple-r-8b2aed-joystream.vercel.app/#/proposals/preview/374 (if the QN let you)
Screen Shot 2023-08-31 at 11 26 12

if (proposalDetails?.type === 'updateWorkingGroupBudget') {
return [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import BN from 'bn.js'
import React, { useEffect, useState } from 'react'

import { AccountInfo } from '@/accounts/components/AccountInfo'
import { useMyAccounts } from '@/accounts/hooks/useMyAccounts'
import { accountOrNamed } from '@/accounts/model/accountOrNamed'
import { AccountOption } from '@/accounts/types'
import { CloseButton } from '@/common/components/buttons'
import { ArrowRightIcon } from '@/common/components/icons'
import {
BalanceInfoInRow,
InfoTitle,
InfoValue,
ModalFooter,
Row,
TransactionInfoContainer,
} from '@/common/components/Modal'
import { RowGapBlock } from '@/common/components/page/PageContent'
import { SidePaneGlass, SidePaneTitle, SidePanelTop } from '@/common/components/SidePane'
import { StatisticButton } from '@/common/components/statistics/StatisticButton'
import { TransactionFee } from '@/common/components/TransactionFee'
import { TextInlineBig, TokenValue } from '@/common/components/typography'
import {
CustomAccountRow,
PreviewPanel,
PreviewPanelBody,
PreviewPanelHeader,
} from '@/proposals/modals/AddNewProposal/components/SpecificParameters/modals/PreviewAndValidate'

interface Props {
label: string
value: { account: string; amount: BN }[]
}
export const DestinationsPreview = ({ label, value }: Props) => {
const [isDescriptionVisible, setDescriptionVisible] = useState(false)
const [totalAmount, setTotalAmount] = useState<BN>(new BN(0))
const { allAccounts } = useMyAccounts()
const accounts = allAccounts as AccountOption[]

const onBackgroundClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (e.target === e.currentTarget) {
setDescriptionVisible(false)
}
}

useEffect(() => {
let total = new BN(0)
value?.map((item) => {
total = total.add(item.amount)
})
setTotalAmount(total)
}, [])
return (
<>
<StatisticButton
title="Payment Details"
onClick={() => {
setDescriptionVisible(true)
}}
icon={<ArrowRightIcon />}
>
<TextInlineBig bold value>
{label}
</TextInlineBig>
</StatisticButton>
{isDescriptionVisible && (
<SidePaneGlass onClick={onBackgroundClick}>
<PreviewPanel>
<PreviewPanelHeader>
<SidePanelTop>
<SidePaneTitle>{label}</SidePaneTitle>
<CloseButton onClick={() => setDescriptionVisible(false)} />
</SidePanelTop>
</PreviewPanelHeader>
<PreviewPanelBody>
<RowGapBlock gap={8}>
<Row>
{value?.map((previewAccount, i) => (
<CustomAccountRow key={i}>
<AccountInfo account={accountOrNamed(accounts, previewAccount.account, 'Unknown Member')} />
<BalanceInfoInRow>
<InfoTitle>Amount</InfoTitle>
<InfoValue>
<TokenValue value={previewAccount.amount} />
</InfoValue>
</BalanceInfoInRow>
</CustomAccountRow>
))}
</Row>
</RowGapBlock>
</PreviewPanelBody>
<ModalFooter>
<TransactionInfoContainer>
<TransactionFee title={'Total amount'} value={totalAmount} />
</TransactionInfoContainer>
</ModalFooter>
</PreviewPanel>
</SidePaneGlass>
)}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './Numeric'
export * from './ProposalLink'
export * from './OpeningLink'
export * from './Hash'
export * from './DestinationsPreview'
44 changes: 32 additions & 12 deletions packages/ui/src/proposals/helpers/getDetailsRenderStructure.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BN from 'bn.js'
import { omit } from 'lodash'

import { TooltipContentProp } from '@/common/components/Tooltip'
Expand Down Expand Up @@ -39,6 +40,7 @@ export type RenderType =
| 'OpeningLink'
| 'Percentage'
| 'Hash'
| 'DestinationsPreview'

export interface RenderNode {
label: string
Expand All @@ -55,23 +57,41 @@ type Mapper<Detail, Key extends keyof Detail> = (
const destinationsMapper: Mapper<DestinationsDetail, 'destinations'> = (value): RenderNode[] => {
const result: RenderNode[] = []

value.forEach((destination) => {
result.push({
label: 'amount',
value: destination.amount,
renderType: 'Amount',
if (value.length === 1) {
value.forEach((destination) => {
result.push({
label: 'amount',
value: destination.amount,
renderType: 'Amount',
})
result.push({
label: 'destination',
value: destination.account,
renderType: 'Address',
})
result.push({
label: '',
value: undefined,
renderType: 'Divider',
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if the page shows one more "statistic" I think this should be removed

Suggested change
result.push({
label: '',
value: undefined,
renderType: 'Divider',
})

})
}
if (value.length > 1) {
let total = new BN(0)
value.forEach((destination) => {
total = total.add(destination.amount)
})
result.push({
label: 'destination',
value: destination.account,
renderType: 'Address',
label: 'Total Payment',
value: total,
renderType: 'Amount',
})
result.push({
label: '',
value: undefined,
renderType: 'Divider',
label: 'Payment Details',
value: value,
renderType: 'DestinationsPreview',
})
})
}

return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const PreviewAndValidateModal = ({ onClose }: PreviewAndValidateModalProp
</SidePaneGlass>
)
}
const CustomAccountRow = styled(AccountRow)`
export const CustomAccountRow = styled(AccountRow)`
margin-bottom: 4px;
padding-right: 16px;
&.error {
Expand All @@ -187,12 +187,12 @@ const CustomBalanceInfoInRow = styled(BalanceInfoInRow)`
margin-left: auto;
}
`
const PreviewPanel = styled(SidePane)`
export const PreviewPanel = styled(SidePane)`
grid-template-rows: auto 1fr auto;
`
const PreviewPanelHeader = styled(SidePaneHeader)`
export const PreviewPanelHeader = styled(SidePaneHeader)`
padding: 12px 24px;
`
const PreviewPanelBody = styled(SidePaneBody)`
export const PreviewPanelBody = styled(SidePaneBody)`
padding: 12px 24px;
`
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,27 @@ describe('getDetailsRenderStructure()', () => {
expect(structure).toEqual({
structure: [
{
label: 'amount',
value: new BN(20),
renderType: 'Amount',
},
{
label: 'destination',
value: alice.address,
renderType: 'Address',
},
{
label: '',
value: undefined,
renderType: 'Divider',
},
{
label: 'amount',
value: new BN(30),
renderType: 'Amount',
},
{
label: 'destination',
value: bob.address,
renderType: 'Address',
},
{
label: '',
value: undefined,
renderType: 'Divider',
},
{
label: 'amount',
value: new BN(10),
label: 'Total Payment',
value: new BN(60),
renderType: 'Amount',
},
{
label: 'destination',
value: aliceStash.address,
renderType: 'Address',
},
{
label: '',
value: undefined,
renderType: 'Divider',
label: 'Payment Details',
value: [
{
account: alice.address,
amount: new BN(20),
},
{
account: bob.address,
amount: new BN(30),
},
{
account: aliceStash.address,
amount: new BN(10),
},
],
renderType: 'DestinationsPreview',
},
],
})
Expand Down