Skip to content

Commit

Permalink
Remove space id if space is not a creator
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Dec 18, 2023
1 parent 9a0cbfd commit 84678a4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
13 changes: 6 additions & 7 deletions src/components/creatorsStaking/Creators/CreatorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormatBalance } from 'src/components/common/balances'
import { useBackerInfo } from 'src/rtk/features/creatorStaking/backerInfo/backerInfoHooks'
import { useMyAddress } from 'src/components/providers/MyExtensionAccountsContext'
import AboutModal from './modals/AboutModal'
import { useEffect, useRef, useState } from 'react'
import { useRef, useState } from 'react'
import StakingModal, { StakingModalVariant } from './modals/StakeModal'
import ValueOrSkeleton from '../utils/ValueOrSkeleton'
import { ContactInfo } from '../utils/socialLinks'
Expand Down Expand Up @@ -40,7 +40,7 @@ const CreatorName = ({ name, loading, cardRef }: CreatorNameProps) => {

return (
<FloatingWrapper
allowedPlacements={['top']}
allowedPlacements={[ 'top' ]}
mainAxisOffset={4}
panel={() => (
<div className='rounded-md border border-background-lighter bg-white px-1.5 text-sm py-1'>
Expand Down Expand Up @@ -109,10 +109,10 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => {
// const eraStake = useEraStakesById(spaceId, era)
const { decimal, tokenSymbol } = useGetDecimalsAndSymbolByNetwork('subsocial')
const backerInfo = useBackerInfo(spaceId, myAddress)
const [openAboutModal, setOpenAboutModal] = useState(false)
const [openStakeModal, setOpenStakeModal] = useState(false)
const [openMoveStakeModal, setOpenMoveStakeModal] = useState(false)
const [modalVariant, setModalVariant] = useState<StakingModalVariant>('stake')
const [ openAboutModal, setOpenAboutModal ] = useState(false)
const [ openStakeModal, setOpenStakeModal ] = useState(false)
const [ openMoveStakeModal, setOpenMoveStakeModal ] = useState(false)
const [ modalVariant, setModalVariant ] = useState<StakingModalVariant>('stake')
const { setOpen, setSpaceId, setMetadata } = useChatContext()
const cardRef = useRef<HTMLDivElement>(null)
const router = useRouter()
Expand Down Expand Up @@ -244,7 +244,6 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => {
`/creators/${domainName ? '@' + domainName : spaceId}`,
{
scroll: false,
shallow: true,
}
)

Expand Down
10 changes: 5 additions & 5 deletions src/components/creatorsStaking/Creators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SuccessModal from './modals/SuccessModal'
import { toGenericAccountId } from 'src/rtk/app/util'
import { betaVersionAgreementStorageName } from './modals/StakeModal'
import store from 'store'
import DefaultAboutModal from './modals/DefaultAboutModal';
import DefaultAboutModal from './modals/DefaultAboutModal'

// const DEFAULT_PAGE_SIZE = 9

Expand Down Expand Up @@ -91,9 +91,9 @@ const CreatorsSectionInner = ({
era,
defaultSpaceId,
}: CreatorsSectionInnerProps) => {
const [tab, setTab] = useState(0)
const [ tab, setTab ] = useState(0)
const myAddress = useMyAddress()
const [sortBy, changeSortBy] = useState('default')
const [ sortBy, changeSortBy ] = useState('default')
const { showSuccessModal, setShowSuccessModal, amount, stakedSpaceId } =
useModalContext()
const creatorsList = useCreatorsList()
Expand All @@ -104,7 +104,7 @@ const CreatorsSectionInner = ({
!!creatorsList?.find(
(item) => toGenericAccountId(item.creator.stakeholder) === myAddress
),
[creatorsList?.length]
[ creatorsList?.length ]
)

const myCreatorsIds = useGetMyCreatorsIds(spaceIds)
Expand All @@ -115,7 +115,7 @@ const CreatorsSectionInner = ({
} else {
store.set(betaVersionAgreementStorageName, false)
}
}, [myCreatorsIds.length, myAddress])
}, [ myCreatorsIds.length, myAddress ])

const tabs: TabsProps['tabs'] = [
{
Expand Down
6 changes: 3 additions & 3 deletions src/components/creatorsStaking/Creators/modals/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const AboutModal = ({
}: AboutModalProps) => {
const creatorSpaceEntity = useCreatorSpaceById(spaceId)

const [openStakeModal, setOpenStakeModal] = useState(false)
const [modalVariant, setModalVariant] = useState<StakingModalVariant>('stake')
const [openMoveStakeModal, setOpenMoveStakeModal] = useState(false)
const [ openStakeModal, setOpenStakeModal ] = useState(false)
const [ modalVariant, setModalVariant ] = useState<StakingModalVariant>('stake')
const [ openMoveStakeModal, setOpenMoveStakeModal ] = useState(false)
const router = useRouter()

const { space } = creatorSpaceEntity || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useBackerInfo } from '@/rtk/features/creatorStaking/backerInfo/backerIn
import { useMyAddress } from '@/components/providers/MyExtensionAccountsContext'
import { useModalContext } from '../../contexts/ModalContext'
import { useCreatorsList } from '@/rtk/features/creatorStaking/creatorsList/creatorsListHooks'
import { useRouter } from 'next/router'

type DefaultAboutModalProps = {
defaultSpaceId?: string
Expand All @@ -12,8 +13,9 @@ type DefaultAboutModalProps = {
const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => {
const myAddress = useMyAddress()
const { amount, setAmount } = useModalContext()
const [openDefaultAboutModal, setOpenDefaultAboutModal] = useState(false)
const [ openDefaultAboutModal, setOpenDefaultAboutModal ] = useState(false)
const creatorsList = useCreatorsList()
const router = useRouter()

const creatorsSpaceIds = creatorsList?.map(({ id }) => id)

Expand All @@ -32,7 +34,15 @@ const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => {
if (defaultSpaceId && isCreator) {
setOpenDefaultAboutModal(true)
}
}, [creatorsSpaceIds?.join(',')])

if (defaultSpaceId && !isCreator) {
const query = router.query

if(query.creator) {
router.replace('/creators')
}
}
}, [ creatorsSpaceIds?.join(',') ])

if (!defaultSpaceId || !isCreator) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function StakingTxButton ({
}

const buildParams = () => {
const amountWithDecimals = getBalanceWithDecimal(amount, decimal)
const amountWithDecimals = getBalanceWithDecimal(amount || '0', decimal)

return [ spaceId, amountWithDecimals.toString() ]
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/creatorsStaking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const CreatorsStaking = ({ defaultSpaceId }: CreatorsStakingProps) => {
)}

<StakingInfoBanner />
<CreatorsSection />
<CreatorsSection defaultSpaceId={defaultSpaceId} />
</div>
</StakingContextWrapper>
</div>
Expand Down

0 comments on commit 84678a4

Please sign in to comment.