From 5af251bb8dab54393b77593bcab0fdadae379640 Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Wed, 20 Sep 2023 13:06:55 +0200 Subject: [PATCH 1/5] Bump types package --- packages/atlas/package.json | 2 +- yarn.lock | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/atlas/package.json b/packages/atlas/package.json index 86f9483d9a..5f039fbaea 100644 --- a/packages/atlas/package.json +++ b/packages/atlas/package.json @@ -39,7 +39,7 @@ "@hookform/resolvers": "^2.9.10", "@joystream/js": "^1.4.0", "@joystream/metadata-protobuf": "2.8.1", - "@joystream/types": "2.1.0", + "@joystream/types": "4.0.0", "@livesession/sdk": "^1.1.4", "@loadable/component": "^5.15.2", "@lottiefiles/react-lottie-player": "^3.5.0", diff --git a/yarn.lock b/yarn.lock index 5096598dcc..4ae4179154 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4217,7 +4217,7 @@ __metadata: "@joystream/js": ^1.4.0 "@joystream/metadata-protobuf": 2.8.1 "@joystream/prettier-config": ^1.0.0 - "@joystream/types": 2.1.0 + "@joystream/types": 4.0.0 "@livesession/sdk": ^1.1.4 "@loadable/component": ^5.15.2 "@lottiefiles/react-lottie-player": ^3.5.0 @@ -4367,7 +4367,22 @@ __metadata: languageName: node linkType: hard -"@joystream/types@npm:2.1.0, @joystream/types@npm:^2.0.0": +"@joystream/types@npm:4.0.0": + version: 4.0.0 + resolution: "@joystream/types@npm:4.0.0" + dependencies: + "@polkadot/api": 8.9.1 + "@polkadot/keyring": 9.5.1 + "@polkadot/types": 8.9.1 + "@types/lodash": ^4.14.157 + "@types/vfile": ^4.0.0 + lodash: ^4.17.15 + moment: ^2.24.0 + checksum: 8af69c43fe9c54a0dc3327c9006bd21cb130c6aceb41410e674db79821dcdf68440634ac28c3d3eb678b679830d8929ad36ea9340ce0d0e5f914668db4ce853c + languageName: node + linkType: hard + +"@joystream/types@npm:^2.0.0": version: 2.1.0 resolution: "@joystream/types@npm:2.1.0" dependencies: From 0d0457d42e1bd9347d08318e3264c3b9da676b9d Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Wed, 20 Sep 2023 13:25:41 +0200 Subject: [PATCH 2/5] Return extra info from transaction --- packages/atlas/src/joystream-lib/extrinsics.ts | 9 +++++---- packages/atlas/src/joystream-lib/types.ts | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/atlas/src/joystream-lib/extrinsics.ts b/packages/atlas/src/joystream-lib/extrinsics.ts index ecb6c0da32..199056ee27 100644 --- a/packages/atlas/src/joystream-lib/extrinsics.ts +++ b/packages/atlas/src/joystream-lib/extrinsics.ts @@ -42,6 +42,7 @@ import { ExtrinsicResult, ExtrinsicStatus, ExtrinsicStatusCallbackFn, + FinalizeRevenueSplitResult, GetEventDataFn, MemberExtrinsicResult, MemberId, @@ -1073,15 +1074,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/joystream-lib/types.ts b/packages/atlas/src/joystream-lib/types.ts index 95be3b2513..18ec258dd0 100644 --- a/packages/atlas/src/joystream-lib/types.ts +++ b/packages/atlas/src/joystream-lib/types.ts @@ -153,7 +153,9 @@ export type VideoExtrinsicResult = ExtrinsicResult<{ export type MemberExtrinsicResult = ExtrinsicResult<{ memberId: MemberId }> export type NftExtrinsicResult = ExtrinsicResult export type MetaprotcolExtrinsicResult = ExtrinsicResult<{ metaprotocol: true; transactionHash: string }> - +export type FinalizeRevenueSplitResult = { + amount: string +} & ExtrinsicResult type TxMethodsFromClass = T extends `${infer _}Tx` ? T : never export type TxMethodName = TxMethodsFromClass From 32efcc926cea9a7637417131fcde991e366c36a5 Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Wed, 20 Sep 2023 13:30:00 +0200 Subject: [PATCH 3/5] Add transaction to finalize revenue split --- .../studio/CrtDashboard/CrtDashboard.tsx | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx index f900f62ae8..7cd5f99493 100644 --- a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx +++ b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx @@ -5,6 +5,11 @@ import { LimitedWidthContainer } from '@/components/LimitedWidthContainer' import { Tabs } from '@/components/Tabs' import { Text } from '@/components/Text' import { Button } from '@/components/_buttons/Button' +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' @@ -14,12 +19,33 @@ const TABS = ['Dashboard', 'Holders', 'Revenue share', 'Settings'] as const export const CrtDashboard = () => { const [currentTab, setCurrentTab] = useState(0) + 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]) + return ( @@ -34,9 +60,12 @@ export const CrtDashboard = () => { - + {currentTab === 0 && ( + + )} + {currentTab === 2 && } {currentTab === 0 && } From d8e02a35354fe5a42a2a7822c6e081844afc6cb0 Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Wed, 20 Sep 2023 13:33:17 +0200 Subject: [PATCH 4/5] Fix deps array --- packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx index 7cd5f99493..1b227d25a4 100644 --- a/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx +++ b/packages/atlas/src/views/studio/CrtDashboard/CrtDashboard.tsx @@ -44,7 +44,7 @@ export const CrtDashboard = () => { }) }, }) - }, [channelId, displaySnackbar, handleTransaction, joystream, memberId]) + }, [channelId, displaySnackbar, handleTransaction, joystream, memberId, proxyCallback]) return ( From 54c228996342b38d104bf0f40cc04eecea04088c Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Fri, 6 Oct 2023 12:26:23 +0200 Subject: [PATCH 5/5] Fix build --- packages/atlas/src/joystream-lib/extrinsics.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/atlas/src/joystream-lib/extrinsics.ts b/packages/atlas/src/joystream-lib/extrinsics.ts index 233977bf5f..3f773c863c 100644 --- a/packages/atlas/src/joystream-lib/extrinsics.ts +++ b/packages/atlas/src/joystream-lib/extrinsics.ts @@ -44,7 +44,6 @@ import { ExtrinsicResult, ExtrinsicStatus, ExtrinsicStatusCallbackFn, - FinalizeRevenueSplitResult, GetEventDataFn, MemberExtrinsicResult, MemberId, @@ -1077,7 +1076,7 @@ export class JoystreamLibExtrinsics { return this.api.tx.content.finalizeRevenueSplit(member, parseInt(channelId)) } - finalizeRevenueSplit: PublicExtrinsic = async ( + finalizeRevenueSplit: PublicExtrinsic = async ( memberId, channelId, cb