diff --git a/src/api/domains.ts b/src/api/domains.ts index 04ee90ef..fa09b551 100644 --- a/src/api/domains.ts +++ b/src/api/domains.ts @@ -6,4 +6,12 @@ export const getOwnerByDomain = async (domain: string) => ( onFailReturnedValue: undefined, onFailedText: 'Failed to get address by domain' }) +) + +export const getDomainBySpaceId = async (spaceId: string) => ( + sendGetRequest({ + params: { url: `domain/${spaceId}` }, + onFailReturnedValue: undefined, + onFailedText: 'Failed to get domain by space id' + }) ) \ No newline at end of file diff --git a/src/components/creatorsStaking/Creators/CreatorCard.tsx b/src/components/creatorsStaking/Creators/CreatorCard.tsx index 83e81303..3b38aebe 100644 --- a/src/components/creatorsStaking/Creators/CreatorCard.tsx +++ b/src/components/creatorsStaking/Creators/CreatorCard.tsx @@ -21,6 +21,7 @@ import { pluralize } from '@subsocial/utils' import { MdArrowOutward } from 'react-icons/md' // import { useEraStakesById } from '@/rtk/features/creatorStaking/eraStake/eraStakeHooks' import MoveStakeModal from './modals/MoveStakeModal' +import { useRouter } from 'next/router' type CreatorNameProps = { name?: string @@ -96,6 +97,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 @@ -114,6 +121,7 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => { const [ modalVariant, setModalVariant ] = useState('stake') const { setOpen, setSpaceId, setMetadata } = useChatContext() const cardRef = useRef(null) + const router = useRouter() const { space, loading: spaceLoading } = creatorSpaceEntity || {} // const { info: eraStakeInfo, loading: eraStakeLoading } = eraStake || {} @@ -124,8 +132,16 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => { const isStake = totalStaked === '0' - const { name, about, postsCount, ownedByAccount, image, links, email } = - space || {} + const { + name, + about, + postsCount, + ownedByAccount, + image, + links, + email, + domain, + } = space || {} const owner = ownedByAccount?.id @@ -226,7 +242,17 @@ const CreatorCard = ({ spaceId }: CreatorCardProps) => {
setOpenAboutModal(true)} + onClick={() => { + router.replace( + '/creators/[creator]', + buildCreatorLinks(spaceId, domain), + { + scroll: false, + } + ) + + setOpenAboutModal(true) + }} >
( - + )) // const start = (page - 1) * DEFAULT_PAGE_SIZE @@ -75,12 +81,16 @@ const CreatorsCards = ({ ) } -type CreatorsSectionInnerProps = { +type CreatorsSectionInnerProps = CreatorsSectionProps & { spaceIds?: string[] era?: string } -const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { +const CreatorsSectionInner = ({ + spaceIds, + era, + defaultSpaceId, +}: CreatorsSectionInnerProps) => { const [ tab, setTab ] = useState(0) const myAddress = useMyAddress() const [ sortBy, changeSortBy ] = useState('default') @@ -112,7 +122,11 @@ const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { id: 'all-creators', text: 'All Creators', content: () => ( - + ), }, { @@ -173,11 +187,16 @@ const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { tokenSymbol={'SUB'} amount={amount} /> +
) } -const CreatorsSection = () => { +type CreatorsSectionProps = { + defaultSpaceId?: string +} + +const CreatorsSection = ({ defaultSpaceId }: CreatorsSectionProps) => { const myAddress = useMyAddress() const creatorsList = useCreatorsList() const eraInfo = useGeneralEraInfo() @@ -192,7 +211,11 @@ const CreatorsSection = () => { return ( - + ) } diff --git a/src/components/creatorsStaking/Creators/modals/AboutModal.tsx b/src/components/creatorsStaking/Creators/modals/AboutModal.tsx index 9884d773..e46ec4e3 100644 --- a/src/components/creatorsStaking/Creators/modals/AboutModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/AboutModal.tsx @@ -5,13 +5,14 @@ import StakingModal, { StakingModalVariant } from './StakeModal' import { useState } from 'react' import AccountPreview from '../AccountPreview' import MoveStakeModal from './MoveStakeModal' +import { useRouter } from 'next/router' type AboutModalProps = { open: boolean closeModal: () => void spaceId: string isStake: boolean - amount: string + amount?: string setAmount: (amount: string) => void } @@ -28,6 +29,7 @@ const AboutModal = ({ const [ openStakeModal, setOpenStakeModal ] = useState(false) const [ modalVariant, setModalVariant ] = useState('stake') const [ openMoveStakeModal, setOpenMoveStakeModal ] = useState(false) + const router = useRouter() const { space } = creatorSpaceEntity || {} @@ -42,6 +44,21 @@ const AboutModal = ({ title={'ℹī¸ About'} withCloseButton closeModal={() => { + const query = router.query + + if (query.creator) { + delete query.creator + } + + router.replace( + { + pathname: '/creators', + query, + }, + undefined, + { scroll: false } + ) + closeModal() }} > diff --git a/src/components/creatorsStaking/Creators/modals/AmountInput.tsx b/src/components/creatorsStaking/Creators/modals/AmountInput.tsx index 9e532731..880ba362 100644 --- a/src/components/creatorsStaking/Creators/modals/AmountInput.tsx +++ b/src/components/creatorsStaking/Creators/modals/AmountInput.tsx @@ -22,7 +22,7 @@ type CommonAmountInputProps = { setAmount: (amount: string) => void inputError?: string setInputError: (error?: string) => void - amount: string + amount?: string tokenSymbol?: string decimals?: number label: string diff --git a/src/components/creatorsStaking/Creators/modals/DefaultAboutModal.tsx b/src/components/creatorsStaking/Creators/modals/DefaultAboutModal.tsx new file mode 100644 index 00000000..f4983c89 --- /dev/null +++ b/src/components/creatorsStaking/Creators/modals/DefaultAboutModal.tsx @@ -0,0 +1,57 @@ +import { useEffect, useState } from 'react' +import AboutModal from './AboutModal' +import { useBackerInfo } from '@/rtk/features/creatorStaking/backerInfo/backerInfoHooks' +import { useMyAddress } from '@/components/providers/MyExtensionAccountsContext' +import { useModalContext } from '../../contexts/ModalContext' +import { useCreatorsList } from '@/rtk/features/creatorStaking/creatorsList/creatorsListHooks' +import useRedirectToCreatorsPage from '../../hooks/useRedirectToCreatorsPage' + +type DefaultAboutModalProps = { + defaultSpaceId?: string +} + +const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => { + const myAddress = useMyAddress() + const { amount, setAmount } = useModalContext() + const [ openDefaultAboutModal, setOpenDefaultAboutModal ] = useState(false) + const creatorsList = useCreatorsList() + const redirectToCreatorsPage = useRedirectToCreatorsPage() + + const creatorsSpaceIds = creatorsList?.map(({ id }) => id) + + const isCreator = + defaultSpaceId && creatorsSpaceIds?.includes(defaultSpaceId?.toString()) + + const backerInfo = useBackerInfo(defaultSpaceId, myAddress) + + const { info } = backerInfo || {} + + const { totalStaked } = info || {} + + const isStake = totalStaked === '0' + + useEffect(() => { + if (defaultSpaceId && isCreator) { + setOpenDefaultAboutModal(true) + } + + if (defaultSpaceId && !isCreator) { + redirectToCreatorsPage() + } + }, [ creatorsSpaceIds?.join(',') ]) + + if (!defaultSpaceId || !isCreator) return null + + return ( + setOpenDefaultAboutModal(false)} + spaceId={defaultSpaceId} + isStake={isStake} + amount={amount} + setAmount={setAmount} + /> + ) +} + +export default DefaultAboutModal diff --git a/src/components/creatorsStaking/Creators/modals/MoveStakeModal.tsx b/src/components/creatorsStaking/Creators/modals/MoveStakeModal.tsx index 5a37d44c..9b6153a9 100644 --- a/src/components/creatorsStaking/Creators/modals/MoveStakeModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/MoveStakeModal.tsx @@ -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 @@ -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) @@ -130,6 +132,7 @@ const MoveStakeModal = ({ title={'🌟 Move Stake'} withCloseButton closeModal={() => { + redirectToCreatorsPage() closeModal() }} > diff --git a/src/components/creatorsStaking/Creators/modals/StakeModal.tsx b/src/components/creatorsStaking/Creators/modals/StakeModal.tsx index f6a49f5c..951bda0f 100644 --- a/src/components/creatorsStaking/Creators/modals/StakeModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/StakeModal.tsx @@ -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' @@ -136,7 +137,7 @@ const modalData = { modalButton: 'Increase', amountInput: StakeOrIncreaseStakeAmountInput, actionButton: StakeOrIncreaseTxButton, - } + }, } type StakeModalProps = { @@ -144,7 +145,7 @@ type StakeModalProps = { open: boolean spaceId: string modalVariant: StakingModalVariant - amount: string + amount?: string setAmount: (amount: string) => void } @@ -162,6 +163,7 @@ const StakingModal = ({ const betaversionAgreement = store.get( betaVersionAgreementStorageName ) as boolean + const redirectToCreatorsPage = useRedirectToCreatorsPage() useEffect(() => { if (open) { @@ -196,6 +198,8 @@ const StakingModal = ({ title={title} withCloseButton closeModal={() => { + redirectToCreatorsPage() + closeModal() }} > diff --git a/src/components/creatorsStaking/Creators/modals/SuccessModal.tsx b/src/components/creatorsStaking/Creators/modals/SuccessModal.tsx index 7aeb5399..51df48fe 100644 --- a/src/components/creatorsStaking/Creators/modals/SuccessModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/SuccessModal.tsx @@ -38,8 +38,6 @@ const SuccessModal = ({ const { name, ownedByAccount, image, links } = space || {} const owner = ownedByAccount?.id - - return ( { - const amountWithDecimals = getBalanceWithDecimal(amount, decimal) + const amountWithDecimals = getBalanceWithDecimal(amount || '0', decimal) return [ spaceId, amountWithDecimals.toString() ] } diff --git a/src/components/creatorsStaking/hooks/useRedirectToCreatorsPage.tsx b/src/components/creatorsStaking/hooks/useRedirectToCreatorsPage.tsx new file mode 100644 index 00000000..f5890256 --- /dev/null +++ b/src/components/creatorsStaking/hooks/useRedirectToCreatorsPage.tsx @@ -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 diff --git a/src/components/creatorsStaking/index.tsx b/src/components/creatorsStaking/index.tsx index 037c7ab3..e5c5597a 100644 --- a/src/components/creatorsStaking/index.tsx +++ b/src/components/creatorsStaking/index.tsx @@ -58,7 +58,11 @@ const MultiAccountWarning = () => { ) } -const CreatorsStaking = () => { +type CreatorsStakingProps = { + defaultSpaceId?: string +} + +const CreatorsStaking = ({ defaultSpaceId }: CreatorsStakingProps) => { const isMulti = useIsMulti() return ( @@ -78,7 +82,7 @@ const CreatorsStaking = () => { )} - +
diff --git a/src/components/main/CreatorStakingPage.tsx b/src/components/main/CreatorStakingPage.tsx index 49596fca..afb31d6b 100644 --- a/src/components/main/CreatorStakingPage.tsx +++ b/src/components/main/CreatorStakingPage.tsx @@ -5,8 +5,13 @@ import Footer from '../footer/Footer' import styles from './Main.module.sass' import CreatorsStaking from '../creatorsStaking' import clsx from 'clsx' +import { NextPage } from 'next' -const CreatorStakingPage = () => { +type CreatorStakingPageProp = { + spaceId?: string +} + +const CreatorStakingPage: NextPage = (props) => { return ( <> @@ -21,7 +26,7 @@ const CreatorStakingPage = () => {
- +