浏览代码

Merge pull request #4043 from attemka/master

* Throw error if user is trying to use excluded channel (#4041)

* Throw error if user is trying to use excluded channel

* Release v2.0.4

---------

Co-authored-by: Artem <Artem Slugin>
Co-authored-by: WRadoslaw <92513933+WRadoslaw@users.noreply.github.com>
Co-authored-by: Bartosz Dryl <drylbartosz@gmail.com>
attemka 1 年之前
父节点
当前提交
6524b52197

+ 6 - 0
CHANGELOG.md

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.0.4] - 2023-04-06
+
+### Fixed
+- Fixed video upload extrinsic bug
+- Fixed channel creation bug
+
 ## [2.0.3] - 2023-04-05
 
 ### Fixed

+ 1 - 1
packages/atlas/package.json

@@ -1,7 +1,7 @@
 {
   "name": "@joystream/atlas",
   "description": "UI for consuming Joystream - a user governed video platform",
-  "version": "2.0.3",
+  "version": "2.0.4",
   "license": "GPL-3.0",
   "scripts": {
     "start": "vite",

+ 7 - 0
packages/atlas/src/api/hooks/apps.ts

@@ -5,6 +5,7 @@ import { useCallback } from 'react'
 import { useGetAppActionSignatureMutation } from '@/api/queries/__generated__/admin.generated'
 import { AppActionActionType } from '@/api/queries/__generated__/baseTypes.generated'
 import { atlasConfig } from '@/config'
+import { JoystreamLibError } from '@/joystream-lib/errors'
 import { RawMetadataProcessorFn } from '@/joystream-lib/types'
 import { useUser } from '@/providers/user/user.hooks'
 
@@ -30,6 +31,12 @@ export const useAppActionMetadataProcessor = (
         },
         fetchPolicy: 'network-only',
       })
+
+      // If channels length is 0 it probably means that during the video creation channel was excluded by operator
+      if (actionType === AppActionActionType.CreateVideo && !data?.membershipById?.channels.length) {
+        throw new JoystreamLibError({ name: 'ChannelExcludedError' })
+      }
+
       const nonce =
         (actionType === AppActionActionType.CreateVideo
           ? data?.membershipById?.channels[0]?.totalVideosCreated

+ 1 - 1
packages/atlas/src/components/StudioEntrypoint/StudioEntrypoint.tsx

@@ -14,7 +14,7 @@ type StudioEntrypointProps = {
 export const StudioEntrypoint: FC<StudioEntrypointProps> = ({ enterLocation }) => {
   const { channelId, isLoggedIn, activeMembership } = useUser()
 
-  const channelSet = !!channelId
+  const channelSet = !!(channelId && activeMembership?.channels.find((channel) => channel.id === channelId))
 
   // not signed user with not account set and/or no extension
   if (!isLoggedIn) {

+ 1 - 0
packages/atlas/src/joystream-lib/errors.ts

@@ -7,6 +7,7 @@ export type JoystreamLibErrorType =
   | 'MissingRequiredEventError'
   | 'MetaprotocolTransactionError'
   | 'AccountBalanceTooLow'
+  | 'ChannelExcludedError'
 
 // ExtrinsicStatus:: 1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low,
 type JoystreamLibErrorArgs = {

+ 18 - 0
packages/atlas/src/providers/transactions/transactions.hooks.ts

@@ -1,6 +1,7 @@
 import { useApolloClient } from '@apollo/client'
 import BN from 'bn.js'
 import { useCallback } from 'react'
+import { useNavigate } from 'react-router'
 
 import { MetaprotocolTransactionResultFieldsFragment } from '@/api/queries/__generated__/fragments.generated'
 import {
@@ -8,6 +9,7 @@ import {
   GetMetaprotocolTransactionStatusEventsQuery,
   GetMetaprotocolTransactionStatusEventsQueryVariables,
 } from '@/api/queries/__generated__/transactionEvents.generated'
+import { absoluteRoutes } from '@/config/routes'
 import { ErrorCode, JoystreamLibError, JoystreamLibErrorType } from '@/joystream-lib/errors'
 import { ExtrinsicResult, ExtrinsicStatus, ExtrinsicStatusCallbackFn } from '@/joystream-lib/types'
 import { useSubscribeAccountBalance } from '@/providers/joystream/joystream.hooks'
@@ -53,6 +55,7 @@ export const useTransaction = (): HandleTransactionFn => {
     (state) => state.actions
   )
   const userWalletName = useUserStore((state) => state.wallet?.title)
+  const navigate = useNavigate()
 
   const [openOngoingTransactionModal, closeOngoingTransactionModal] = useConfirmationModal()
   const nodeConnectionStatus = useConnectionStatusStore((state) => state.nodeConnectionStatus)
@@ -233,6 +236,20 @@ export const useTransaction = (): HandleTransactionFn => {
           return false
         }
 
+        if (errorName === 'ChannelExcludedError') {
+          removeTransaction(transactionId)
+          displaySnackbar({
+            title: 'Something went wrong',
+            description:
+              "The channel you're using either doesn't exist, was deleted by creator, has been moderated by the DAO content curation team, or not included to be viewed by the application operators. Choose different channel. If you need support, reach out to our community on Discord.",
+            iconType: 'error',
+            timeout: MINIMIZED_SIGN_CANCELLED_SNACKBAR_TIMEOUT,
+          })
+
+          navigate(absoluteRoutes.viewer.index())
+          return false
+        }
+
         if (errorName === 'SignCancelledError') {
           ConsoleLogger.warn('Sign cancelled')
           removeTransaction(transactionId)
@@ -289,6 +306,7 @@ export const useTransaction = (): HandleTransactionFn => {
       closeOngoingTransactionModal,
       displaySnackbar,
       getMetaprotocolTxStatus,
+      navigate,
       nodeConnectionStatus,
       openOngoingTransactionModal,
       removeTransaction,

+ 10 - 0
packages/atlas/src/providers/user/user.provider.tsx

@@ -151,6 +151,16 @@ export const UserProvider: FC<PropsWithChildren> = ({ children }) => {
 
   const activeMembership = (memberId && memberships?.find((membership) => membership.id === memberId)) || null
 
+  const isChannelBelongsToTheUserOrExists = activeMembership?.channels.length
+    ? activeMembership.channels.some((channel) => channel.id === channelId)
+    : true
+
+  useEffect(() => {
+    if (!isChannelBelongsToTheUserOrExists) {
+      setActiveUser({ channelId: activeMembership?.channels.length ? activeMembership.channels[0].id : null })
+    }
+  }, [activeMembership?.channels, isChannelBelongsToTheUserOrExists, setActiveUser])
+
   const contextValue: UserContextValue = useMemo(
     () => ({
       memberships: memberships || [],