From e1d1060f6503e31fe49bc07dc2e6e0f3d1c4a7a8 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 14 Dec 2023 13:29:08 +0200 Subject: [PATCH 1/8] Resolve creator spaceId - add about modal is spaceId exist in url --- src/api/domains.ts | 8 +++ .../creatorsStaking/Creators/CreatorCard.tsx | 12 ++--- .../creatorsStaking/Creators/index.tsx | 43 +++++++++++---- .../Creators/modals/AboutModal.tsx | 2 +- .../Creators/modals/AmountInput.tsx | 2 +- .../Creators/modals/DefaultAboutModal.tsx | 45 ++++++++++++++++ .../Creators/modals/StakeModal.tsx | 2 +- .../Creators/modals/TxButtons.tsx | 2 +- src/components/creatorsStaking/index.tsx | 6 ++- src/components/main/CreatorStakingPage.tsx | 12 ++++- src/pages/creators/[creator].tsx | 54 +++++++++++++++++++ src/pages/creators/index.tsx | 3 ++ src/rtk/app/util.ts | 1 + 13 files changed, 169 insertions(+), 23 deletions(-) create mode 100644 src/components/creatorsStaking/Creators/modals/DefaultAboutModal.tsx create mode 100644 src/pages/creators/[creator].tsx 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..eefb715c 100644 --- a/src/components/creatorsStaking/Creators/CreatorCard.tsx +++ b/src/components/creatorsStaking/Creators/CreatorCard.tsx @@ -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 { useRef, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import StakingModal, { StakingModalVariant } from './modals/StakeModal' import ValueOrSkeleton from '../utils/ValueOrSkeleton' import { ContactInfo } from '../utils/socialLinks' @@ -39,7 +39,7 @@ const CreatorName = ({ name, loading, cardRef }: CreatorNameProps) => { return ( (
@@ -108,10 +108,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('stake') + const [openAboutModal, setOpenAboutModal] = useState(false) + const [openStakeModal, setOpenStakeModal] = useState(false) + const [openMoveStakeModal, setOpenMoveStakeModal] = useState(false) + const [modalVariant, setModalVariant] = useState('stake') const { setOpen, setSpaceId, setMetadata } = useChatContext() const cardRef = useRef(null) diff --git a/src/components/creatorsStaking/Creators/index.tsx b/src/components/creatorsStaking/Creators/index.tsx index f47fa81c..64188ed7 100644 --- a/src/components/creatorsStaking/Creators/index.tsx +++ b/src/components/creatorsStaking/Creators/index.tsx @@ -22,6 +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'; // const DEFAULT_PAGE_SIZE = 9 @@ -51,7 +52,12 @@ const CreatorsCards = ({ ) const creatorsCards = ids.map((spaceId, i) => ( - + )) // const start = (page - 1) * DEFAULT_PAGE_SIZE @@ -75,15 +81,19 @@ const CreatorsCards = ({ ) } -type CreatorsSectionInnerProps = { +type CreatorsSectionInnerProps = CreatorsSectionProps & { spaceIds?: string[] era?: string } -const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { - const [ tab, setTab ] = useState(0) +const CreatorsSectionInner = ({ + spaceIds, + era, + defaultSpaceId, +}: CreatorsSectionInnerProps) => { + 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() @@ -94,7 +104,7 @@ const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { !!creatorsList?.find( (item) => toGenericAccountId(item.creator.stakeholder) === myAddress ), - [ creatorsList?.length ] + [creatorsList?.length] ) const myCreatorsIds = useGetMyCreatorsIds(spaceIds) @@ -105,14 +115,18 @@ const CreatorsSectionInner = ({ spaceIds, era }: CreatorsSectionInnerProps) => { } else { store.set(betaVersionAgreementStorageName, false) } - }, [ myCreatorsIds.length, myAddress ]) + }, [myCreatorsIds.length, myAddress]) const tabs: TabsProps['tabs'] = [ { 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..3ed636e9 100644 --- a/src/components/creatorsStaking/Creators/modals/AboutModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/AboutModal.tsx @@ -11,7 +11,7 @@ type AboutModalProps = { closeModal: () => void spaceId: string isStake: boolean - amount: string + amount?: string setAmount: (amount: string) => void } 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..71ff0b5e --- /dev/null +++ b/src/components/creatorsStaking/Creators/modals/DefaultAboutModal.tsx @@ -0,0 +1,45 @@ +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' + +type DefaultAboutModalProps = { + defaultSpaceId?: string +} + +const DefaultAboutModal = ({ defaultSpaceId }: DefaultAboutModalProps) => { + const myAddress = useMyAddress() + const { amount, setAmount } = useModalContext() + const [ openDefaultAboutModal, setOpenDefaultAboutModal ] = useState(false) + + const backerInfo = useBackerInfo(defaultSpaceId, myAddress) + + const { info } = backerInfo || {} + + // const { backersCount, totalStaked: total } = eraStakeInfo || {} + const { totalStaked } = info || {} + + const isStake = totalStaked === '0' + + useEffect(() => { + if (defaultSpaceId) { + setOpenDefaultAboutModal(true) + } + }, [defaultSpaceId]) + + if(!defaultSpaceId) return null + + return ( + setOpenDefaultAboutModal(false)} + spaceId={defaultSpaceId} + isStake={isStake} + amount={amount} + setAmount={setAmount} + /> + ) +} + +export default DefaultAboutModal diff --git a/src/components/creatorsStaking/Creators/modals/StakeModal.tsx b/src/components/creatorsStaking/Creators/modals/StakeModal.tsx index f6a49f5c..3793b6c1 100644 --- a/src/components/creatorsStaking/Creators/modals/StakeModal.tsx +++ b/src/components/creatorsStaking/Creators/modals/StakeModal.tsx @@ -144,7 +144,7 @@ type StakeModalProps = { open: boolean spaceId: string modalVariant: StakingModalVariant - amount: string + amount?: string setAmount: (amount: string) => void } diff --git a/src/components/creatorsStaking/Creators/modals/TxButtons.tsx b/src/components/creatorsStaking/Creators/modals/TxButtons.tsx index 67e6713b..9d97e428 100644 --- a/src/components/creatorsStaking/Creators/modals/TxButtons.tsx +++ b/src/components/creatorsStaking/Creators/modals/TxButtons.tsx @@ -29,7 +29,7 @@ import { useModalContext } from '../../contexts/ModalContext' import store from 'store' export type CommonTxButtonProps = { - amount: string + amount?: string spaceId: string decimal: number label: string diff --git a/src/components/creatorsStaking/index.tsx b/src/components/creatorsStaking/index.tsx index 037c7ab3..575343ca 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 ( diff --git a/src/components/main/CreatorStakingPage.tsx b/src/components/main/CreatorStakingPage.tsx index 49596fca..c38f8342 100644 --- a/src/components/main/CreatorStakingPage.tsx +++ b/src/components/main/CreatorStakingPage.tsx @@ -5,8 +5,16 @@ import Footer from '../footer/Footer' import styles from './Main.module.sass' import CreatorsStaking from '../creatorsStaking' import clsx from 'clsx' +import { NextPage } from 'next' + +type CreatorStakingPageProp = { + spaceId?: string + domain?: string +} + +const CreatorStakingPage: NextPage = (props) => { + console.log(props) -const CreatorStakingPage = () => { return ( <> @@ -21,7 +29,7 @@ const CreatorStakingPage = () => {
- +