-
Notifications
You must be signed in to change notification settings - Fork 2
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
kammradt
wants to merge
5
commits into
feature/payouts
Choose a base branch
from
feature/payouts-kamm
base: feature/payouts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; | ||
|
@@ -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"> | ||
|
@@ -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> | ||
<> | ||
<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 ( | ||
|
@@ -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() | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure what we need to do on |
||
|
||
payout(tx, api, activeAccount, notReallySure) | ||
} | ||
|
||
return ( | ||
<> | ||
<DataHeaderRow className="d-none d-lg-flex text-center"> | ||
|
@@ -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"> | ||
|
@@ -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> | ||
))} | ||
|
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,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) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 🙏