Skip to content

Commit

Permalink
fix: twitter screen name too long (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask authored May 17, 2024
1 parent 3134c0a commit a100fc2
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/components/StakeMaskStatusCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const StakeMaskStatusCard: FC<StakeMaskStatusCardProps> = ({ ...props })
spacing={6}
>
{pool?.apr ? (
<Tooltip label={formatNumber(+pool.apr * 100, 18)}>
<Tooltip label={`${formatNumber(+pool.apr * 100, 18)}%`}>
<Box
h="56px"
fontSize="32px"
Expand Down
19 changes: 19 additions & 0 deletions src/components/TextOverflowTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { cloneElement, memo, type ReactElement } from 'react'
import { Tooltip, TooltipProps } from '@chakra-ui/react'
import { useDetectOverflow } from '../hooks/useDetectOverflow'

interface TextOverflowTooltipProps extends TooltipProps {
children: ReactElement
}

export const TextOverflowTooltip = memo(({ children, ...rest }: TextOverflowTooltipProps) => {
const [overflow, ref] = useDetectOverflow()

return (
<Tooltip {...rest} label={overflow ? rest.label : ''}>
{cloneElement(children, { ...children.props, ref })}
</Tooltip>
)
})

TextOverflowTooltip.displayName = 'TextOverflowTooltip'
29 changes: 22 additions & 7 deletions src/components/UserStatus/UserTotalPoint.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import { Image, VStack, Text, Box, StackProps } from '@chakra-ui/react'
import { t } from '@lingui/macro'
import { UserInfo } from '../../types/api'
import { TextOverflowTooltip } from '../TextOverflowTooltip'

interface Props extends StackProps {
user: UserInfo
}

export function UserTotalPoints({ user, ...props }: Props) {
return (
<VStack {...props}>
<Box flexDir="row" w="100%">
<VStack overflow="hidden" {...props}>
<Box flexDir="row" w="100%" pl="100px" pos="relative">
<Image
position="absolute"
left={0}
width={100}
height={100}
border="2px solid"
borderColor="gradient.purple"
borderRadius="50%"
objectFit="cover"
draggable={false}
userSelect="none"
src={user.twitter_image || new URL('../../assets/default-avatar.svg', import.meta.url).href}
src={user.twitter_image}
fallbackSrc={new URL('../../assets/default-avatar.svg', import.meta.url).href}
alt="user name"
/>
<Text fontSize="xx-large" textAlign="right" fontWeight="bold">
{user.twitter_display_name || 'N/A'}
</Text>
<TextOverflowTooltip label={user.twitter_display_name} hasArrow placement="top">
<Text
fontSize="xx-large"
textAlign="right"
fontWeight="bold"
textOverflow="ellipsis"
whiteSpace="nowrap"
overflow="hidden"
>
{user.twitter_display_name || 'N/A'}
</Text>
</TextOverflowTooltip>
</Box>
<Box
w="100%"
h="120px"
h="132px"
mt="14px"
boxSizing="border-box"
flexDir="column"
rounded={16}
Expand Down
12 changes: 6 additions & 6 deletions src/components/UserStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface UserStatusProps extends GridProps {}
export function UserStatus(props: UserStatusProps) {
const { address } = useAccount()
const store = usePoolStore()
const { data } = useUserInfo(address, store.poolId)
const { data: userInfo } = useUserInfo(address, store.poolId)

if (!data)
if (!userInfo)
return (
<Grid
gap={6}
Expand Down Expand Up @@ -46,10 +46,10 @@ export function UserStatus(props: UserStatusProps) {
maxW="maxW"
{...props}
>
<UserTotalPoints flexGrow={1} flexBasis={0} user={data.data} />
<StakedMask alignSelf="stretch" flexGrow={1} flexBasis={0} />
<RewardCard alignSelf="stretch" title={t`Estimated Rewards`} flexGrow={1} flexBasis={0} />
<RewardCard alignSelf="stretch" title={t`Estimated Rewards`} flexGrow={1} flexBasis={0} />
<UserTotalPoints user={userInfo} />
<StakedMask alignSelf="stretch" />
<RewardCard alignSelf="stretch" title={t`Estimated Rewards`} />
<RewardCard alignSelf="stretch" title={t`Estimated Rewards`} />
</Grid>
)
}
10 changes: 10 additions & 0 deletions src/hooks/useDetectOverflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useState, useCallback } from 'react'

export function useDetectOverflow<T extends HTMLDivElement>(): [overflow: boolean, ref: (node: T | null) => void] {
const [overflow, setOverflow] = useState(false)
const ref = useCallback((node: T | null) => {
if (node) setOverflow(node.offsetWidth !== node.scrollWidth)
}, [])

return [overflow, ref]
}
9 changes: 8 additions & 1 deletion src/hooks/useUserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import { fetchJSON } from '../helpers/fetchJSON'
import { FIREFLY_API_ROOT } from '../constants/api'
import { UserInfoResponse } from '../types/api'
import { UserInfo, UserInfoResponse } from '../types/api'
import urlcat from 'urlcat'

export function useUserInfo(address: string | undefined, pool_id: number | null) {
Expand All @@ -15,5 +15,12 @@ export function useUserInfo(address: string | undefined, pool_id: number | null)
})
return fetchJSON<UserInfoResponse>(url)
},
select(res) {
if (!res.data) return res.data
return {
...res.data,
twitter_image: res.data.twitter_image.replace(/_normal.(jpe?g|png|gif|bmp)/, '_400x400.$1'),
} as UserInfo
},
})
}
1 change: 0 additions & 1 deletion src/modals/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface Props extends ModalProps {
}
export function BaseModal({ title, width, height, ...rest }: Props) {
const isMobile = useBreakpointValue({ base: true, md: false })
console.log({ isMobile })
const header = (
<>
<Text fontSize="32px">{title}</Text>
Expand Down
4 changes: 2 additions & 2 deletions src/modals/CookiePolicyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const CookiePolicyContent = () => (
<br />
{t`Cookies are small text files that are stored on your computer or mobile device when you visit a website. They are used to store information about you and your internet usage habits to improve your online experience. Cookies enable websites to recognize your device and remember some information about your preferences.`}
</p>
<p>
<div>
{t`Types of Cookies We Use`}
<ul>
<li>{t`Session Cookies: These cookies exist only during your visit to the website and are automatically deleted when you close your browser. They are used to maintain session state, such as storing the contents of your shopping cart.`}</li>
<li>{t`Persistent Cookies: These cookies are stored on your device until they reach their expiration date or are manually deleted. They are used to remember your preferences and provide a personalized experience when you revisit the website.`}</li>
<li>{t`Third-Party Cookies: The Site may use cookies from third-party service providers for traffic analysis and user behavior tracking, as well as to display ads relevant to your interests.`}</li>
</ul>
</p>
</div>
<p>
{t`How to Control Cookies`}
<br />
Expand Down
7 changes: 6 additions & 1 deletion src/modals/StakeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import {
VStack,
} from '@chakra-ui/react'
import { Trans, t } from '@lingui/macro'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import dayjs from 'dayjs'
import { useState } from 'react'
import { useAccount, useBalance } from 'wagmi'
import { StepIcon } from '../components/StepIcon'
import { TokenIcon } from '../components/TokenIcon'
import { Tooltip } from '../components/Tooltip.tsx'
import { formatNumber } from '../helpers/formatNumber'
import { useLinkTwitter } from '../hooks/useLinkTwitter'
import { usePoolInfo } from '../hooks/usePoolInfo'
import { usePoolStore } from '../store/poolStore'
import { Tooltip } from '../components/Tooltip.tsx'
import { BaseModal } from './BaseModal'

interface Props extends ModalProps {}

export function StakeModal(props: Props) {
const account = useAccount()
const { openConnectModal } = useConnectModal()
const { data: pool } = usePoolInfo()
const { maskTokenAddress } = usePoolStore()
const [amount, setAmount] = useState('')
Expand All @@ -55,6 +57,9 @@ export function StakeModal(props: Props) {
ml="auto"
fontSize={14}
rounded={24}
onClick={() => {
openConnectModal?.()
}}
>{t`Connect Wallet`}</Button>
)}
</ListItem>
Expand Down

0 comments on commit a100fc2

Please sign in to comment.