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

WIP: Payouts page - Clain #167

Open
wants to merge 5 commits into
base: feature/payouts
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion config/kusama.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import-storage:
- Bids
- Candidates
- Members
- Payouts
Bids:
- who: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
kind:
Expand Down Expand Up @@ -102,6 +103,15 @@ import-storage:
ChallengeRoundCount: 6
RoundCount: 6
MemberCount: 2
Head: 5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw
Head: 5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw # Eve
Payouts:
-
-
- 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL # Ferdie
- paid: 0
payouts:
-
- 20000000
- 15000000000000
ParasDisputes:
$removePrefix: ['disputes'] # those can makes block building super slow
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useAccount } from '../../../../account/AccountContext'
import { AccountIdentity } from '../../../../components/AccountIdentity'
import { DataHeaderRow, DataRow } from '../../../../components/base'
import { FormatBalance } from '../../../../components/FormatBalance'
// import { truncate } from '../../../../helpers/truncate'
import { Identicon } from '../../components/Identicon'
import { toastByStatus } from '../../helpers'

Expand Down
55 changes: 46 additions & 9 deletions src/pages/explore/PayoutsPage/components/PayoutsList.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import type { ApiPromise } from '@polkadot/api'
import { WalletAccount } from '@talismn/connect-wallets'
import { useState, useEffect } from 'react'
import { Badge, Col } from 'react-bootstrap'
import { Badge, Button, Col } from 'react-bootstrap'
import styled from 'styled-components'
import { DataHeaderRow, DataRow } from '../../../../components/base'
import { FormatBalance } from '../../../../components/FormatBalance'
import { useBlockTime } from '../../../../hooks/useBlockTime'
import { Identicon } from '../../components/Identicon'
import { payout } from '../helper'

const StyledDataRow = styled(DataRow)`
background-color: ${(props) => (props.$isDefender ? props.theme.colors.black : '')};
border: ${(props) => (props.$isDefender ? `2px solid ${props.theme.colors.secondary}` : '')};

&:hover {
cursor: pointer;
}

@media (max-width: 992px) {
padding-block: 12px;
margin-inline: 2px;
Expand All @@ -27,7 +30,14 @@ type PayoutsListProps = {
handleUpdate: () => void
}

const TimeRemaining = ({ block, latestBlock, api }: { block: number; latestBlock: number | null; api: ApiPromise }) => {
type TimeRemainingProps = {
api: ApiPromise
block: number
latestBlock: number | null
onClainPayout: () => void
}

const TimeRemaining = ({ block, latestBlock, api, onClainPayout }: TimeRemainingProps) => {
if (!latestBlock)
return (
<Badge pill bg="black" className="me-2 p-2">
Expand All @@ -47,9 +57,15 @@ const TimeRemaining = ({ block, latestBlock, api }: { block: number; latestBlock

if (blocksLeft <= 0)
return (
<Badge pill bg="primary" className="me-2 p-2">
Matured
</Badge>
<>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does not look really beautiful for now, I just added the button to test

A can make it look better as soon as the behavior is done 🙏

Screenshot 2024-12-05 at 13 03 29

<Badge pill bg="primary" className="me-2 p-2">
Matured
</Badge>
{/* @TODO: Only show claim button if it's the current address */}
<Button variant="primary" onClick={onClainPayout}>
Claim Payout
</Button>
</>
)

return (
Expand All @@ -59,9 +75,11 @@ const TimeRemaining = ({ block, latestBlock, api }: { block: number; latestBlock
)
}

const PayoutsList = ({ api, members }: PayoutsListProps): JSX.Element => {
const PayoutsList = ({ api, members, activeAccount }: PayoutsListProps): JSX.Element => {
const [latestBlock, setLatestBlock] = useState<number | null>(null)

const isMember = (member: ExtendedSocietyMember) => activeAccount?.address === member.accountId.toHuman()

useEffect(() => {
const fetchLatestBlock = async () => {
const header = await api.rpc.chain.getHeader()
Expand All @@ -80,6 +98,16 @@ const PayoutsList = ({ api, members }: PayoutsListProps): JSX.Element => {

if (members.length === 0) return <>No members</>

const onClainPayout = () => {
const tx = api.tx.society.payout()

const notReallySure = () => {
console.log('oiii ??????')
}
Comment on lines +104 to +106
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really sure what we need to do on onStatusChange


payout(tx, api, activeAccount, notReallySure)
}

return (
<>
<DataHeaderRow className="d-none d-lg-flex text-center">
Expand Down Expand Up @@ -122,9 +150,12 @@ const PayoutsList = ({ api, members }: PayoutsListProps): JSX.Element => {
</Badge>
)}
{member.hasPayouts && (
<>
<TimeRemaining block={member.extendedPayouts.block} latestBlock={latestBlock} api={api} />
</>
<TimeRemaining
block={member.extendedPayouts.block}
latestBlock={latestBlock}
api={api}
onClainPayout={onClainPayout}
/>
)}
{member.extendedPayouts.pending == 0 && member.extendedPayouts.paid > 0 && (
<Badge pill bg="black" className="me-2 p-2">
Expand All @@ -136,6 +167,12 @@ const PayoutsList = ({ api, members }: PayoutsListProps): JSX.Element => {
Paid before V2
</Badge>
)}

{isMember(member) && (
<Badge bg="primary" className="me-2 p-2">
You
</Badge>
)}
</Col>
</StyledDataRow>
))}
Expand Down
17 changes: 17 additions & 0 deletions src/pages/explore/PayoutsPage/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiPromise } from '@polkadot/api'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { WalletAccount } from '@talismn/connect-wallets'
import { doTx } from '../../../helpers/extrinsics'

const waitingText = 'Request sent. Waiting for response...'

export const payout = async (
tx: SubmittableExtrinsic<'promise', any>,
api: ApiPromise,
activeAccount: WalletAccount | undefined,
onStatusChange: any
) => {
const finalizedText = 'Payout submitted successfully.'

await doTx(api, tx, finalizedText, waitingText, activeAccount, onStatusChange)
}
8 changes: 4 additions & 4 deletions src/pages/explore/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ const NavigationBar = ({ totals }: { totals: Totals }) => {
</Nav.Link>
</StyledNavItem>
<StyledNavItem>
<Nav.Link as={LinkWithQuery} to="/journey">
Journey
<Nav.Link as={LinkWithQuery} to="/explore/payouts">
Payouts
</Nav.Link>
</StyledNavItem>
<StyledNavItem>
<Nav.Link as={LinkWithQuery} to="/explore/payouts">
Payouts
<Nav.Link as={LinkWithQuery} to="/journey">
Journey
</Nav.Link>
</StyledNavItem>
</StyledNav>
Expand Down