forked from Joystream/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show action button for revenue share correctly
- Loading branch information
Showing
5 changed files
with
61 additions
and
31 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/atlas/src/components/_crt/CloseRevenueShareButton/CloseRevenueShareButton.tsx
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,45 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { FullCreatorTokenFragment } from '@/api/queries/__generated__/fragments.generated' | ||
import { Button } from '@/components/_buttons/Button' | ||
import { atlasConfig } from '@/config' | ||
import { useJoystream } from '@/providers/joystream' | ||
import { useJoystreamStore } from '@/providers/joystream/joystream.store' | ||
import { useSnackbar } from '@/providers/snackbars' | ||
import { useTransaction } from '@/providers/transactions/transactions.hooks' | ||
import { useUser } from '@/providers/user/user.hooks' | ||
|
||
type CloseRevenueShareButtonProps = { | ||
revenueShare: FullCreatorTokenFragment['revenueShares'][number] | ||
} | ||
|
||
export const CloseRevenueShareButton = ({ revenueShare }: CloseRevenueShareButtonProps) => { | ||
const { joystream, proxyCallback } = useJoystream() | ||
const { channelId, memberId } = useUser() | ||
const handleTransaction = useTransaction() | ||
const { displaySnackbar } = useSnackbar() | ||
const { currentBlock } = useJoystreamStore() | ||
|
||
const finalizeRevenueShare = useCallback(() => { | ||
if (!joystream || !memberId || !channelId) { | ||
return | ||
} | ||
handleTransaction({ | ||
txFactory: async (updateStatus) => | ||
(await joystream.extrinsics).finalizeRevenueSplit(memberId, channelId, proxyCallback(updateStatus)), | ||
onTxSync: async (data) => { | ||
displaySnackbar({ | ||
title: 'Revenue share is closed', | ||
description: `Remaining unclaimed ${data.amount} ${atlasConfig.joystream.tokenTicker} was transfered back to your channel balance`, | ||
iconType: 'info', | ||
}) | ||
}, | ||
}) | ||
}, [channelId, displaySnackbar, handleTransaction, joystream, memberId, proxyCallback]) | ||
|
||
if (currentBlock < revenueShare.endsAt) { | ||
return null | ||
} | ||
|
||
return <Button onClick={finalizeRevenueShare}>Close revenue share</Button> | ||
} |
1 change: 1 addition & 0 deletions
1
packages/atlas/src/components/_crt/CloseRevenueShareButton/index.ts
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 @@ | ||
export * from './CloseRevenueShareButton' |
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