Skip to content

Commit

Permalink
🎬 Close revenue share (Joystream#4909)
Browse files Browse the repository at this point in the history
* Bump types package

* Return extra info from transaction

* Add transaction to finalize revenue split

* Fix deps array

* Fix build
  • Loading branch information
WRadoslaw committed Apr 22, 2024
1 parent e462249 commit fbf4b98
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/atlas/src/joystream-lib/extrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,15 +1082,15 @@ export class JoystreamLibExtrinsics {
return this.api.tx.content.finalizeRevenueSplit(member, parseInt(channelId))
}

finalizeRevenueSplit: PublicExtrinsic<typeof this.finalizeRevenueSplitTx, ExtrinsicResult> = async (
finalizeRevenueSplit: PublicExtrinsic<typeof this.finalizeRevenueSplitTx, ExitRevenueSplitResult> = 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) => {
Expand Down
35 changes: 32 additions & 3 deletions packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -16,12 +21,33 @@ const TABS = ['Dashboard', 'Holders', 'Revenue share', 'Settings'] as const
export const CrtDashboard = () => {
const [currentTab, setCurrentTab] = useState<number>(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 (
<LimitedWidthContainer>
<StartRevenueShare show={openRevenueShareModal} tokenId="1" onClose={() => setOpenRevenueShareModal(false)} />
Expand All @@ -46,9 +72,12 @@ export const CrtDashboard = () => {
</>
)}
{currentTab === 2 && (
<Button onClick={() => setOpenRevenueShareModal(true)} icon={<SvgActionRevenueShare />}>
Start revenue share
</Button>
<>
<Button onClick={() => setOpenRevenueShareModal(true)} icon={<SvgActionRevenueShare />}>
Start revenue share
</Button>
<Button onClick={finalizeRevenueShare}>Close revenue share</Button>
</>
)}
</TabsContainer>
{currentTab === 0 && <CrtDashboardMainTab />}
Expand Down

0 comments on commit fbf4b98

Please sign in to comment.