Skip to content

Commit

Permalink
Merge branch 'main' into creator-staking-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Dec 19, 2023
2 parents 2ca1c97 + f5fac56 commit 3968a1c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
10 changes: 7 additions & 3 deletions src/components/creatorsStaking/Creators/CreatorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ const CreatorCardValue = ({
)
}

const buildCreatorLinks = (spaceId: string, domain?: string) => {
const domainName = domain?.replace('.sub', '')

return `/creators/${domainName ? '@' + domainName : spaceId}`
}

type CreatorCardProps = {
spaceId: string
era?: string
Expand Down Expand Up @@ -244,11 +250,9 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => {
<div
className='cursor-pointer flex flex-col gap-3'
onClick={() => {
const domainName = domain?.replace('.sub', '')

router.replace(
'/creators/[creator]',
`/creators/${domainName ? '@' + domainName : spaceId}`,
buildCreatorLinks(spaceId, domain),
{
scroll: false,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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'
import { useSendEvent } from '@/components/providers/AnalyticContext'
import useRedirectToCreatorsPage from '../../hooks/useRedirectToCreatorsPage'

type DefaultAboutModalProps = {
defaultSpaceId?: string
Expand All @@ -16,8 +16,8 @@ const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => {
const { amount, setAmount } = useModalContext()
const [ openDefaultAboutModal, setOpenDefaultAboutModal ] = useState(false)
const creatorsList = useCreatorsList()
const router = useRouter()
const sendEvent = useSendEvent()
const redirectToCreatorsPage = useRedirectToCreatorsPage()

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

Expand All @@ -39,11 +39,7 @@ const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => {
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { BIGNUMBER_ZERO } from '@/config/app/consts'
import BN from 'bignumber.js'
import UserIcon from '@/assets/icons/user-icon.svg'
import useRedirectToCreatorsPage from '../../hooks/useRedirectToCreatorsPage'

type MoveStakeModalProps = {
open: boolean
Expand All @@ -35,6 +36,7 @@ const MoveStakeModal = ({
const myAddress = useMyAddress()
const creatorsList = useCreatorsList()
const { decimal, tokenSymbol } = useGetDecimalsAndSymbolByNetwork('subsocial')
const redirectToCreatorsPage = useRedirectToCreatorsPage()

const spaceIds = creatorsList?.map((item) => item.creator.spaceId)
const myCreatorsIds = useGetMyCreatorsIds(spaceIds)
Expand Down Expand Up @@ -130,6 +132,7 @@ const MoveStakeModal = ({
title={'🌟 Move Stake'}
withCloseButton
closeModal={() => {
redirectToCreatorsPage()
closeModal()
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import clsx from 'clsx'
import { DaysToWithdrawWarning } from '../../utils/DaysToWithdraw'
import { useStakingConsts } from '../../../../rtk/features/creatorStaking/stakingConsts/stakingConstsHooks'
import AccountPreview from '../AccountPreview'
import useRedirectToCreatorsPage from '../../hooks/useRedirectToCreatorsPage'

export const betaVersionAgreementStorageName = 'BetaVersionAgreement'

Expand Down Expand Up @@ -136,7 +137,7 @@ const modalData = {
modalButton: 'Increase',
amountInput: StakeOrIncreaseStakeAmountInput,
actionButton: StakeOrIncreaseTxButton,
}
},
}

type StakeModalProps = {
Expand Down Expand Up @@ -164,6 +165,7 @@ const StakingModal = ({
const betaversionAgreement = store.get(
betaVersionAgreementStorageName
) as boolean
const redirectToCreatorsPage = useRedirectToCreatorsPage()

useEffect(() => {
if (open) {
Expand Down Expand Up @@ -198,6 +200,8 @@ const StakingModal = ({
title={title}
withCloseButton
closeModal={() => {
redirectToCreatorsPage()

closeModal()
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const SuccessModal = ({
const { name, ownedByAccount, image, links } = space || {}
const owner = ownedByAccount?.id



return (
<Modal
isOpen={open}
Expand Down
15 changes: 15 additions & 0 deletions src/components/creatorsStaking/hooks/useRedirectToCreatorsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useRouter } from 'next/router'

const useRedirectToCreatorsPage = () => {
const router = useRouter()

return () => {
const creator = router.query.creator

if (creator) {
router.replace('/creators', '/creators', { scroll: false })
}
}
}

export default useRedirectToCreatorsPage
2 changes: 1 addition & 1 deletion src/components/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const isHomePage = (): boolean =>
isClientSide() && window.location.pathname === '/'

export const isCreatorStakingPage = (): boolean =>
isClientSide() && window.location.pathname === '/creators'
isClientSide() && window.location.pathname.includes('/creators')

export const isAccountsPage = (): boolean =>
isClientSide() &&
Expand Down
5 changes: 4 additions & 1 deletion src/pages/creators/[creator].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ getInitialPropsWithRedux(CreatorsStakingPage, async ({ dispatch, context }) => {
? domainOrSpaceIdFromUrl
: domainOrSpaceIdFromUrl + '.sub'

const domainStructByDomainName = await getOwnerByDomain(domain.replace('@', ''))
const domainStructByDomainName = await getOwnerByDomain(
domain.replace('@', '')
)

const { innerValue } = domainStructByDomainName || {}

Expand All @@ -37,6 +39,7 @@ getInitialPropsWithRedux(CreatorsStakingPage, async ({ dispatch, context }) => {
head: {
title: 'Support Favorite Creators And Receive Tokens!',
desc: 'Stake SUB towards the best creators of content, applications, and communities. Both you and the creator will receive more tokens, and help grow the network.',
// TODO: create auto-generated image for particular creator, we can use this one: https://nextjs.org/docs/app/api-reference/functions/image-response
image: '/images/creator-staking/meta-bg.jpg',
forceTitle: true,
},
Expand Down
4 changes: 1 addition & 3 deletions src/pages/creators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { FETCH_CHIAN_INFO_WITH_PRICES } from 'src/rtk/app/actions'
import { fetchStakingConsts } from '../../rtk/features/creatorStaking/stakingConsts/stakingConstsHooks'

getInitialPropsWithRedux(CreatorsStakingPage, async ({ dispatch }) => {

dispatch({ type: FETCH_CHIAN_INFO_WITH_PRICES })
fetchCreatorsList(dispatch)
fetchStakingConsts(dispatch)
Expand All @@ -17,8 +16,7 @@ getInitialPropsWithRedux(CreatorsStakingPage, async ({ dispatch }) => {
image: '/images/creator-staking/meta-bg.jpg',
forceTitle: true,
},
spaceId: '',
domain: '',
spaceId: undefined,
}
})

Expand Down

0 comments on commit 3968a1c

Please sign in to comment.