1
0
Kaynağa Gözat

Merge branch 'dev' into 'master'

Artem 1 yıl önce
ebeveyn
işleme
15275d7167

+ 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 || [],