Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pick commits #11138

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FollowModuleType, type LensBaseAPI } from '@masknet/web3-providers/type
import { formatBalance, isLessThan, isSameAddress, ZERO } from '@masknet/web3-shared-base'
import { ChainId, createERC20Token, formatAmount, ProviderType } from '@masknet/web3-shared-evm'
import { Avatar, Box, Button, buttonClasses, CircularProgress, DialogContent, Typography } from '@mui/material'
import { Web3ProfileTrans, useWeb3ProfileTrans } from '../../locales/i18n_generated.js'
import { useWeb3ProfileTrans, Web3ProfileTrans } from '../../locales/i18n_generated.js'
import { getLensterLink } from '../../utils.js'
import { useFollow } from '../hooks/Lens/useFollow.js'
import { useUnfollow } from '../hooks/Lens/useUnfollow.js'
Expand Down Expand Up @@ -199,6 +199,7 @@ export function FollowLensDialog({ handle, onClose }: Props) {
profile?.id,
currentProfile?.id,
followModule,
currentProfile?.signless,
(event: MouseEvent<HTMLElement>) => {
showConfettiExplosion(event.currentTarget.offsetWidth, event.currentTarget.offsetHeight)
setIsFollowing(true)
Expand All @@ -208,6 +209,7 @@ export function FollowLensDialog({ handle, onClose }: Props) {
const { loading: unfollowLoading, handleUnfollow } = useUnfollow(
profile?.id,
currentProfile?.id,
currentProfile?.signless,
(event: MouseEvent<HTMLElement>) => {
setIsFollowing(false)
},
Expand Down Expand Up @@ -238,6 +240,7 @@ export function FollowLensDialog({ handle, onClose }: Props) {
const disabled = useMemo(() => {
if (
!account ||
!currentProfile ||
!!wallet?.owner ||
pluginID !== NetworkPluginID.PLUGIN_EVM ||
providerType === ProviderType.Fortmatic ||
Expand All @@ -258,6 +261,7 @@ export function FollowLensDialog({ handle, onClose }: Props) {

return false
}, [
currentProfile,
account,
wallet?.owner,
chainId,
Expand Down Expand Up @@ -300,11 +304,11 @@ export function FollowLensDialog({ handle, onClose }: Props) {
)
return t.follow_with_charge_tips()
else if (profile?.followModule?.type === FollowModuleType.RevertFollowModule) return t.follow_with_revert_tips()
else if (!defaultProfile) {
return t.follow_gas_tips()
else if (!currentProfile) {
return t.follow_with_out_handle_tips()
}
return
}, [wallet?.owner, chainId, profile, feeTokenBalance, pluginID, providerType, isSelf])
}, [wallet?.owner, chainId, profile, feeTokenBalance, pluginID, providerType, isSelf, currentProfile])

const avatar = useMemo(() => {
if (!profile?.metadata?.picture?.optimized.uri) return
Expand All @@ -327,7 +331,9 @@ export function FollowLensDialog({ handle, onClose }: Props) {
src={avatar ?? new URL('../assets/Lens.png', import.meta.url).toString()}
sx={{ width: 64, height: 64 }}
/>
<Typography className={classes.name}>{profile?.metadata?.displayName}</Typography>
<Typography className={classes.name}>
{profile?.metadata?.displayName ?? profile?.handle.localName}
</Typography>
<Typography className={classes.handle}>@{profile?.handle.localName}</Typography>
<Typography className={classes.followers}>
<Web3ProfileTrans.followers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
useWallet,
useWeb3Utils,
} from '@masknet/web3-hooks-base'
import { ProviderType } from '@masknet/web3-shared-evm'
import { useWeb3ProfileTrans } from '../../locales/i18n_generated.js'
import { ChainId, ProviderType } from '@masknet/web3-shared-evm'
import type { LensBaseAPI } from '@masknet/web3-providers/types'
import { Icons } from '@masknet/icons'
import { ProfilePopup } from './ProfilePopup.js'
import { useWeb3ProfileTrans } from '../../locales/i18n_generated.js'
import { NetworkPluginID } from '@masknet/shared-base'

const useStyles = makeStyles()((theme) => ({
container: {
Expand Down Expand Up @@ -82,7 +83,14 @@ export const HandlerDescription = memo<HandlerDescriptionProps>(({ profiles, cur
<Typography className={classes.address}>{Utils.formatAddress(account, 4)}</Typography>
</Box>
</Box>
<Button variant="text" onClick={() => SelectProviderModal.open()}>
<Button
variant="text"
onClick={() =>
SelectProviderModal.open({
requiredSupportPluginID: NetworkPluginID.PLUGIN_EVM,
requiredSupportChainIds: [ChainId.Matic],
})
}>
{t.wallet_status_button_change()}
</Button>
</Box>
Expand All @@ -101,12 +109,15 @@ export const HandlerDescription = memo<HandlerDescriptionProps>(({ profiles, cur
}
/>
<Box>
<Typography className={classes.name}>{currentProfile.metadata?.displayName}</Typography>
<Typography className={classes.name}>
{currentProfile.metadata?.displayName ?? currentProfile.handle.localName}
</Typography>
<Typography className={classes.address}>{Utils.formatAddress(account, 4)}</Typography>
</Box>
</Box>
<Icons.ArrowDrop size={18} onClick={(e) => setAnchorEl(e.currentTarget)} />
<ProfilePopup
walletName={walletName}
profiles={profiles}
anchorEl={anchorEl}
open={!!anchorEl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Icons } from '@masknet/icons'
import { Image } from '@masknet/shared'
import { CrossIsolationMessages } from '@masknet/shared-base'
import { CrossIsolationMessages, EMPTY_LIST } from '@masknet/shared-base'
import { ActionButton, makeStyles } from '@masknet/theme'
import type { FireflyBaseAPI } from '@masknet/web3-providers/types'
import { List, ListItem, Typography, type ListProps } from '@mui/material'
import { memo } from 'react'
import { useWeb3ProfileTrans } from '../../locales/i18n_generated.js'
import { useChainContext } from '@masknet/web3-hooks-base'
import { Lens } from '@masknet/web3-providers'
import { isSameAddress } from '@masknet/web3-shared-base'
import { useQuery } from '@tanstack/react-query'
import { compact, first } from 'lodash-es'
import { useWeb3ProfileTrans } from '../../locales/i18n_generated.js'

const useStyles = makeStyles()((theme) => {
const isDark = theme.palette.mode === 'dark'
Expand Down Expand Up @@ -82,9 +82,9 @@ export const LensList = memo(({ className, accounts, ...rest }: Props) => {
const { account: wallet } = useChainContext()

const { data = accounts, isLoading } = useQuery({
queryKey: ['Lens', 'Popup-List', accounts.map((x) => x.handle).join('')],
queryKey: ['Lens', 'Popup-List', accounts.map((x) => x.handle).join(''), wallet],
queryFn: async () => {
if (!accounts.length) return
if (!accounts.length) return EMPTY_LIST
let currentProfile = await Lens.queryDefaultProfileByAddress(wallet)
if (!currentProfile?.id) {
const profiles = await Lens.queryProfilesByAddress(wallet)
Expand Down Expand Up @@ -120,6 +120,7 @@ export const LensList = memo(({ className, accounts, ...rest }: Props) => {
}),
)
},

refetchOnWindowFocus: false,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { Icons } from '@masknet/icons'
import { makeStyles, usePortalShadowRoot } from '@masknet/theme'
import type { LensBaseAPI } from '@masknet/web3-providers/types'
import {
Box,
Button,
List,
ListItemButton,
ListItemIcon,
ListItemSecondaryAction,
ListItemText,
Popover,
Radio,
Typography,
} from '@mui/material'
import { memo } from 'react'
import { Image } from '@masknet/shared'
import { formatEthereumAddress } from '@masknet/web3-shared-evm'
import { Image, SelectProviderModal, WalletIcon } from '@masknet/shared'
import { ChainId, formatEthereumAddress } from '@masknet/web3-shared-evm'
import { NetworkPluginID } from '@masknet/shared-base'
import { useChainContext, useProviderDescriptor, useWeb3Utils } from '@masknet/web3-hooks-base'
import { useWeb3ProfileTrans } from '../../locales/i18n_generated.js'

const useStyles = makeStyles()((theme) => ({
paper: {
Expand All @@ -39,6 +45,45 @@ const useStyles = makeStyles()((theme) => ({
color: theme.palette.maskColor.second,
fontWeight: 700,
},
container: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
background: theme.palette.maskColor.bg,
borderRadius: 8,
padding: theme.spacing(1.5),
},
description: {
display: 'flex',
columnGap: 4,
},
name: {
fontWeight: 700,
fontSize: 14,
lineHeight: '18px',
color: theme.palette.maskColor.main,
},
address: {
fontWeight: 700,
fontSize: 14,
lineHeight: '18px',
color: theme.palette.maskColor.second,
},
list: {
maxHeight: 200,
overflow: 'auto',
'::-webkit-scrollbar': {
backgroundColor: 'transparent',
width: 18,
},
'::-webkit-scrollbar-thumb': {
borderRadius: '20px',
width: 5,
border: '7px solid rgba(0, 0, 0, 0)',
backgroundColor: theme.palette.maskColor.secondaryLine,
backgroundClip: 'padding-box',
},
},
}))

interface ProfilePopupProps {
Expand All @@ -48,6 +93,7 @@ interface ProfilePopupProps {
onClose: () => void
onChange: (profile: LensBaseAPI.Profile) => void
currentProfile: LensBaseAPI.Profile
walletName?: string
}

export const ProfilePopup = memo<ProfilePopupProps>(function ProfilePopup({
Expand All @@ -57,9 +103,18 @@ export const ProfilePopup = memo<ProfilePopupProps>(function ProfilePopup({
onClose,
currentProfile,
onChange,
walletName,
}) {
const t = useWeb3ProfileTrans()

const Utils = useWeb3Utils()

const { classes } = useStyles()

const { account } = useChainContext()

const providerDescriptor = useProviderDescriptor()

return usePortalShadowRoot((container) => (
<Popover
disableScrollLock
Expand All @@ -77,7 +132,7 @@ export const ProfilePopup = memo<ProfilePopupProps>(function ProfilePopup({
vertical: 'top',
horizontal: 'right',
}}>
<List disablePadding>
<List disablePadding className={classes.list}>
{profiles?.map((profile) => {
return (
<ListItemButton
Expand Down Expand Up @@ -108,6 +163,25 @@ export const ProfilePopup = memo<ProfilePopupProps>(function ProfilePopup({
)
})}
</List>
<Box className={classes.container}>
<Box className={classes.description}>
<WalletIcon size={36} mainIcon={providerDescriptor?.icon} />
<Box>
<Typography className={classes.name}>{walletName}</Typography>
<Typography className={classes.address}>{Utils.formatAddress(account, 4)}</Typography>
</Box>
</Box>
<Button
variant="text"
onClick={() =>
SelectProviderModal.open({
requiredSupportPluginID: NetworkPluginID.PLUGIN_EVM,
requiredSupportChainIds: [ChainId.Matic],
})
}>
{t.wallet_status_button_change()}
</Button>
</Box>
</Popover>
))
})
Loading
Loading