Skip to content

Commit

Permalink
fix: mf-5340 optimize swap (#11295)
Browse files Browse the repository at this point in the history
  • Loading branch information
beyond009 committed Jan 17, 2024
1 parent f1f94ca commit 23303a4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
Expand Up @@ -45,9 +45,9 @@ const useStyles = makeStyles()((theme) => ({
}))

enum OptionName {
ONE_QUARTE = '15',
TWO_QUARTE = '30',
ONE_HOUR = '60',
ONE_QUARTE = '15 Min',
TWO_QUARTE = '30 Min',
ONE_HOUR = '60 Min',
ONE_DAY = '1 Day',
NEVER = 'Never',
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/Trader/src/SiteAdaptor/trader/TradeForm.tsx
Expand Up @@ -52,7 +52,7 @@ const useStyles = makeStyles()((theme) => {
},
reverse: {
backgroundColor:
Sniffings.is_dashboard_page ? MaskColorVar.lightBackground : theme.palette.background.default,
Sniffings.is_dashboard_page ? MaskColorVar.lightBackground : theme.palette.maskColor.bottom,
width: 32,
height: 32,
borderRadius: 99,
Expand All @@ -61,7 +61,7 @@ const useStyles = makeStyles()((theme) => {
alignItems: 'center',
},
reverseWrapper: {
backgroundColor: theme.palette.background.paper,
backgroundColor: theme.palette.maskColor.line,
padding: 2,
borderRadius: 99,
marginTop: -16,
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/UI/components/FungibleTokenList/index.tsx
Expand Up @@ -62,9 +62,9 @@ export interface FungibleTokenListProps<T extends NetworkPluginID>
mode?: TokenListMode
}

const useStyles = makeStyles<{ enableMange: boolean }>()((theme, { enableMange }) => ({
const useStyles = makeStyles<{}>()(() => ({
channel: {
position: enableMange ? 'relative' : 'unset',
width: '100%',
},
bar: {
position: 'absolute',
Expand All @@ -90,7 +90,7 @@ export function FungibleTokenList<T extends NetworkPluginID>(props: FungibleToke
} = props

const t = useSharedTrans()
const { classes } = useStyles({ enableMange: mode === TokenListMode.List && enableManage }, { props })
const { classes } = useStyles({}, { props })

const { pluginID } = useNetworkContext<T>(props.pluginID)
const account = useAccount(pluginID)
Expand Down
@@ -1,21 +1,33 @@
import { useState, useMemo } from 'react'
import { DialogContent, type Theme, useMediaQuery, inputClasses } from '@mui/material'
import { useNetworkContext, useNativeTokenAddress } from '@masknet/web3-hooks-base'
import { useNetworkContext, useNativeTokenAddress, useNetworks } from '@masknet/web3-hooks-base'
import type { Web3Helper } from '@masknet/web3-helpers'
import { EMPTY_LIST, EnhanceableSite, type NetworkPluginID, Sniffings } from '@masknet/shared-base'
import { EMPTY_LIST, EnhanceableSite, NetworkPluginID, Sniffings } from '@masknet/shared-base'
import { useRowSize } from '@masknet/shared-base-ui'
import { makeStyles, MaskColorVar } from '@masknet/theme'
import type { FungibleToken } from '@masknet/web3-shared-base'
import { TokenListMode } from '../../components/FungibleTokenList/type.js'
import { useSharedTrans } from '../../../locales/index.js'
import { InjectedDialog, useBaseUIRuntime } from '../../contexts/index.js'
import { FungibleTokenList } from '../../components/index.js'
import { FungibleTokenList, SelectNetworkSidebar } from '../../components/index.js'
import { ChainId } from '@masknet/web3-shared-evm'

interface StyleProps {
compact: boolean
}

const useStyles = makeStyles<StyleProps>()((theme, { compact }) => ({
container: {
display: 'flex',
flex: 1,
width: '100%',
gap: '16px',
position: 'relative',
},
sidebarContainer: {
width: '27px',
height: '432px',
},
content: {
...(compact ? { minWidth: 552 } : {}),
padding: theme.spacing(2),
Expand All @@ -36,7 +48,6 @@ const useStyles = makeStyles<StyleProps>()((theme, { compact }) => ({
},
},
wrapper: {
paddingTop: theme.spacing(2),
paddingBottom: theme.spacing(6),
},
}))
Expand All @@ -55,6 +66,7 @@ interface SelectFungibleTokenDialogProps<T extends NetworkPluginID = NetworkPlug
disableNativeToken?: boolean
selectedTokens?: string[]
onClose(token: Web3Helper.FungibleTokenAll | null): void
setChainId(chainId: Web3Helper.Definition[T]['ChainId']): void
}

export function SelectFungibleTokenDialog({
Expand All @@ -70,13 +82,15 @@ export function SelectFungibleTokenDialog({
title,
enableManage = true,
onClose,
setChainId,
}: SelectFungibleTokenDialogProps) {
const t = useSharedTrans()
const { networkIdentifier } = useBaseUIRuntime()
const compact = networkIdentifier === EnhanceableSite.Minds
const { pluginID: currentPluginID } = useNetworkContext(pluginID)
const { classes } = useStyles({ compact })
const isMdScreen = useMediaQuery<Theme>((theme) => theme.breakpoints.down('md'))
const allNetworks = useNetworks(NetworkPluginID.PLUGIN_EVM, true)

const rowSize = useRowSize()
const [mode, setMode] = useState(TokenListMode.List)
Expand All @@ -101,26 +115,37 @@ export function SelectFungibleTokenDialog({
: t.select_token()
}>
<DialogContent classes={{ root: classes.content }}>
<FungibleTokenList
mode={mode}
setMode={setMode}
pluginID={currentPluginID}
chainId={chainId}
tokens={tokens ?? EMPTY_LIST}
whitelist={whitelist}
enableManage={enableManage}
blacklist={
disableNativeToken && nativeTokenAddress ? [nativeTokenAddress, ...blacklist] : blacklist
}
disableSearch={disableSearchBar}
selectedTokens={selectedTokens}
onSelect={onClose}
FixedSizeListProps={FixedSizeListProps}
SearchTextFieldProps={{
InputProps: { classes: { root: classes.search } },
}}
isHiddenChainIcon={false}
/>
<div className={classes.container}>
<div className={classes.sidebarContainer}>
<SelectNetworkSidebar
hideAllButton
chainId={chainId}
onChainChange={(chainId) => setChainId(chainId ?? ChainId.Mainnet)}
networks={allNetworks}
pluginID={NetworkPluginID.PLUGIN_EVM}
/>
</div>
<FungibleTokenList
mode={mode}
setMode={setMode}
pluginID={currentPluginID}
chainId={chainId}
tokens={tokens ?? EMPTY_LIST}
whitelist={whitelist}
enableManage={enableManage}
blacklist={
disableNativeToken && nativeTokenAddress ? [nativeTokenAddress, ...blacklist] : blacklist
}
disableSearch={disableSearchBar}
selectedTokens={selectedTokens}
onSelect={onClose}
FixedSizeListProps={FixedSizeListProps}
SearchTextFieldProps={{
InputProps: { classes: { root: classes.search } },
}}
isHiddenChainIcon={false}
/>
</div>
</DialogContent>
</InjectedDialog>
)
Expand Down
Expand Up @@ -65,6 +65,7 @@ export const SelectFungibleTokenModal = forwardRef<
disableSearchBar={disableSearchBar}
selectedTokens={selectedTokens}
onClose={(token) => dispatch?.close(token)}
setChainId={setChainId}
/>
)
})
Expand Up @@ -60,7 +60,7 @@ export function SearchableList<T extends {}>({
}: MaskSearchableListProps<T>) {
const [keyword, setKeyword] = useState('')
const theme = useTheme()
const { classes } = useStyles(undefined, { props })
const { classes, cx } = useStyles(undefined, { props })
const { height = 300, itemSize, ...rest } = FixedSizeListProps
const { InputProps, ...textFieldPropsRest } = SearchFieldProps ?? {}

Expand Down Expand Up @@ -110,7 +110,7 @@ export function SearchableList<T extends {}>({
return (
<div className={classes.container}>
{!disableSearch && (
<Box className={classes.searchInput}>
<Box className={cx(classes.searchInput, classes.input)}>
<MaskTextField
value={keyword}
placeholder="Search"
Expand Down Expand Up @@ -194,6 +194,9 @@ const useStyles = makeStyles()((theme) => ({
margin: 'auto',
},
},
input: {
paddingBottom: '16px',
},
list: {
scrollbarWidth: 'thin',
},
Expand Down

0 comments on commit 23303a4

Please sign in to comment.