diff --git a/packages/atlas/src/joystream-lib/extrinsics.ts b/packages/atlas/src/joystream-lib/extrinsics.ts index 7991dd46fd..3f773c863c 100644 --- a/packages/atlas/src/joystream-lib/extrinsics.ts +++ b/packages/atlas/src/joystream-lib/extrinsics.ts @@ -1076,15 +1076,15 @@ export class JoystreamLibExtrinsics { return this.api.tx.content.finalizeRevenueSplit(member, parseInt(channelId)) } - finalizeRevenueSplit: PublicExtrinsic = async ( + finalizeRevenueSplit: PublicExtrinsic = async ( memberId, channelId, cb ) => { const tx = await this.finalizeRevenueSplitTx(memberId, channelId) - const { block } = await this.sendExtrinsic(tx, cb) - - return { block } + const { block, getEventData } = await this.sendExtrinsic(tx, cb) + const amount = getEventData('projectToken', 'RevenueSplitFinalized')[2] + return { block, amount: amount.toString() } } deissueCreatorTokenTx = async (memberId: MemberId, channelId: ChannelId) => { diff --git a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx index fdacb90930..07c321cbda 100644 --- a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx +++ b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx @@ -6,6 +6,11 @@ import { Tabs } from '@/components/Tabs' import { Text } from '@/components/Text' import { Button } from '@/components/_buttons/Button' import { StartRevenueShare } from '@/components/_crt/StartRevenueShareModal/StartRevenueShareModal' +import { atlasConfig } from '@/config' +import { useJoystream } from '@/providers/joystream' +import { useSnackbar } from '@/providers/snackbars' +import { useTransaction } from '@/providers/transactions/transactions.hooks' +import { useUser } from '@/providers/user/user.hooks' import { HeaderContainer, MainContainer, TabsContainer } from '@/views/studio/CrtDashboard/CrtDashboard.styles' import { CrtDashboardMainTab } from '@/views/studio/CrtDashboard/tabs/CrtDashboardMainTab' import { CrtHoldersTab } from '@/views/studio/CrtDashboard/tabs/CrtHoldersTab' @@ -16,12 +21,33 @@ const TABS = ['Dashboard', 'Holders', 'Revenue share', 'Settings'] as const export const CrtDashboard = () => { const [currentTab, setCurrentTab] = useState(0) const [openRevenueShareModal, setOpenRevenueShareModal] = useState(false) + const { joystream, proxyCallback } = useJoystream() + const { channelId, memberId } = useUser() + const { displaySnackbar } = useSnackbar() + const handleTransaction = useTransaction() const handleChangeTab = useCallback((idx: number) => { setCurrentTab(idx) }, []) const mappedTabs = TABS.map((tab) => ({ name: tab })) + 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]) + return ( setOpenRevenueShareModal(false)} /> @@ -46,9 +72,12 @@ export const CrtDashboard = () => { )} {currentTab === 2 && ( - + <> + + + )} {currentTab === 0 && }