Skip to content

Commit

Permalink
chore: remove all banners and buttons related to lazy staking
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Feb 1, 2024
1 parent ea401a7 commit 8b54fcc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 99 deletions.
29 changes: 5 additions & 24 deletions src/components/creators/CreatorDashboardSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { SpaceData } from '@subsocial/api/types'
import clsx from 'clsx'
import { ComponentProps } from 'react'
import { useIsCreatorSpace } from 'src/rtk/features/creators/creatorsListHooks'
import { useFetchStakeData } from 'src/rtk/features/creators/stakesHooks'
import { useFetchTotalStake } from 'src/rtk/features/creators/totalStakeHooks'
import { useMyAddress } from '../auth/MyAccountsContext'
import CreatePostCard from './cards/CreatePostCard'
import CreatorInfoCard from './cards/CreatorInfoCard'
import MyStakeCard from './cards/MyStakeCard'
import StakeSubCard from './cards/StakeSubCard'
import SupportCreatorsCard from './cards/SupportCreatorsCard'
import RewardInfoCard from './rewards/RewardInfoCard'

export type CreatorDashboardHomeVariant = 'posts' | 'spaces'
export type CreatorDashboardSidebarType =
| { name: 'home-page'; variant: CreatorDashboardHomeVariant }
| { name: 'space-page'; space: SpaceData }
| { name: 'space-page' }
| { name: 'post-page'; space: SpaceData }

export type CreatorDashboardSidebarProps = ComponentProps<'div'> & {
Expand Down Expand Up @@ -64,24 +61,13 @@ function HomePageSidebar({ variant }: Extract<CreatorDashboardSidebarType, { nam
)
}

function SpacePageSidebar({ space }: Extract<CreatorDashboardSidebarType, { name: 'space-page' }>) {
function SpacePageSidebar({}: Extract<CreatorDashboardSidebarType, { name: 'space-page' }>) {
const myAddress = useMyAddress() ?? ''
const { data: stakeData, loading: loadingStakeData } = useFetchStakeData(myAddress, space.id)
const { isCreatorSpace, loading: loadingIsCreator } = useIsCreatorSpace(space.id)
const { data: totalStake, loading: loadingTotalStake } = useFetchTotalStake(myAddress)

if (loadingIsCreator || loadingStakeData) {
return null
}

const renderTopCard = () => {
if (!isCreatorSpace) {
if (!totalStake?.hasStaked) return <SupportCreatorsCard />
return null
}

if (stakeData?.hasStaked) return <MyStakeCard space={space} />
else return <StakeSubCard space={space} />
if (!totalStake?.hasStaked) return <SupportCreatorsCard />
return null
}

return (
Expand All @@ -95,15 +81,10 @@ function SpacePageSidebar({ space }: Extract<CreatorDashboardSidebarType, { name
function PostPageSidebar({ space }: Extract<CreatorDashboardSidebarType, { name: 'post-page' }>) {
const myAddress = useMyAddress() ?? ''
const { data, loading: loadingTotalStake } = useFetchTotalStake(myAddress)
const { loading: loadingCreator } = useIsCreatorSpace(space.id)

if (loadingCreator) {
return null
}

return (
<>
<CreatorInfoCard showStakeButton={data?.hasStaked} space={space} />
<CreatorInfoCard space={space} />
{!loadingTotalStake &&
(data?.hasStaked ? <RewardInfoCard /> : <StakeSubCard space={space} />)}
</>
Expand Down
81 changes: 9 additions & 72 deletions src/components/creators/cards/CreatorInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { SpaceData } from '@subsocial/api/types'
import { Button } from 'antd'
import clsx from 'clsx'
import { BsBoxArrowUpRight } from 'react-icons/bs'
import { useMyAddress } from 'src/components/auth/MyAccountsContext'
import { FormatBalance } from 'src/components/common/balances'
import { SpaceFollowersModal } from 'src/components/profiles/AccountsListModal'
import { OfficialSpaceStatus, SpaceAvatar, useIsMySpace } from 'src/components/spaces/helpers'
import ViewSpaceLink from 'src/components/spaces/ViewSpaceLink'
Expand All @@ -12,29 +9,20 @@ import FollowSpaceButton from 'src/components/utils/FollowSpaceButton'
import { Pluralize } from 'src/components/utils/Plularize'
import Segment from 'src/components/utils/Segment'
import { useSendEvent } from 'src/providers/AnalyticContext'
import { useIsCreatorSpace } from 'src/rtk/features/creators/creatorsListHooks'
import { useFetchStakeData } from 'src/rtk/features/creators/stakesHooks'
import { useFetchTotalStake } from 'src/rtk/features/creators/totalStakeHooks'
import { getAmountRange } from 'src/utils/analytics'
import { getSubIdCreatorsLink } from 'src/utils/links'
import styles from './CreatorInfoCard.module.sass'

export type CreatorInfoCardProps = {
space: SpaceData
showStakeButton?: boolean
}

export default function CreatorInfoCard({ space, showStakeButton = true }: CreatorInfoCardProps) {
export default function CreatorInfoCard({ space }: CreatorInfoCardProps) {
const myAddress = useMyAddress() ?? ''
const { isCreatorSpace } = useIsCreatorSpace(space.id)
const { data: stakeData } = useFetchStakeData(myAddress, space.id)
const { data: totalStake } = useFetchTotalStake(myAddress)
const sendEvent = useSendEvent()
const isMySpace = useIsMySpace(space.struct)

const shouldShowStakeButton = isCreatorSpace && showStakeButton
const shouldShowFollowButton = !isMySpace

return (
<Segment className={clsx(styles.CreatorInfoCard)}>
<div className={styles.TitleContainer}>
Expand Down Expand Up @@ -67,71 +55,20 @@ export default function CreatorInfoCard({ space, showStakeButton = true }: Creat
text={space.content?.about ?? ''}
limit={120}
/>
{!stakeData?.hasStaked ? (
(shouldShowFollowButton || shouldShowStakeButton) && (
<div className={clsx('GapSmall d-flex flex-column mt-2')}>
{shouldShowStakeButton && (
<Button
target='_blank'
type='primary'
href={getSubIdCreatorsLink(space)}
onClick={() =>
sendEvent('astake_banner_add_stake', {
eventSource: 'creator-info-banner',
spaceId: space.id,
})
}
>
Stake
</Button>
)}
{shouldShowFollowButton && (
<div
className='w-100'
onClick={() =>
sendEvent('follow', {
spaceId: space.id,
eventSource: 'post',
amountRange: getAmountRange(totalStake?.amount),
})
}
>
<FollowSpaceButton className='w-100' space={space.struct} />
</div>
)}
</div>
)
) : (
<div className={clsx('d-flex flex-column GapNormal', styles.MyStake)}>
<div className='GapSmall d-flex align-items-center justify-content-between FontSmall'>
<span className='ColorMuted'>My Stake</span>
<span className='FontWeightMedium'>
<FormatBalance
value={stakeData?.stakeAmount}
decimals={10}
currency='SUB'
precision={2}
/>
</span>
</div>
<Button
className={clsx('d-flex align-items-center GapTiny justify-content-center pt-1')}
type='primary'
ghost
href={getSubIdCreatorsLink(space)}
target='_blank'
{!isMySpace && (
<div className={clsx('GapSmall d-flex flex-column mt-2')}>
<div
className='w-100'
onClick={() =>
sendEvent('astake_dashboard_manage_stake', {
eventSource: 'creator-info-banner',
sendEvent('follow', {
spaceId: space.id,
eventSource: 'post',
amountRange: getAmountRange(totalStake?.amount),
spaceStakeAmountRange: getAmountRange(stakeData?.stakeAmount),
})
}
>
Manage my stake
<BsBoxArrowUpRight />
</Button>
<FollowSpaceButton className='w-100' space={space.struct} />
</div>
</div>
)}
</Segment>
Expand Down
3 changes: 1 addition & 2 deletions src/components/spaces/SpaceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DfMd } from '../utils/DfMd'
import FollowSpaceButton from '../utils/FollowSpaceButton'
import MyEntityLabel from '../utils/MyEntityLabel'
import { OfficialSpaceStatus, SpaceAvatar, useIsMySpace } from './helpers'
import { StakeButton } from './ViewSpace'
import ViewSpaceLink from './ViewSpaceLink'

export interface SpaceCardProps
Expand Down Expand Up @@ -63,7 +62,7 @@ export default function SpaceCard({ spaceId, ...props }: SpaceCardProps) {
subtitle={<DfMd className='ColorCurrentColor FontSmall' source={spaceData?.content?.about} />}
buttons={
spaceData && [
<StakeButton key={'stake'} spaceStruct={spaceData.struct} />,
// <StakeButton key={'stake'} spaceStruct={spaceData.struct} />,
isMySpace ? (
<ButtonLink
href={'/[spaceId]/edit'}
Expand Down
2 changes: 1 addition & 1 deletion src/components/spaces/ViewSpacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const InnerViewSpacePage: FC<Props> = props => {
}}
withSidebar
withVoteBanner
creatorDashboardSidebarType={{ name: 'space-page', space: spaceData }}
creatorDashboardSidebarType={{ name: 'space-page' }}
>
{showBanner && (
<ClaimSpaceBanner
Expand Down

0 comments on commit 8b54fcc

Please sign in to comment.