Skip to content

Commit a4b8cd1

Browse files
authored
Use a Slide action for Asset picker in mobile (#3353)
* Use a Slide action for Asset picker in mobile Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> * Swipe edge and full height Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> * Add Swiper Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> * Expand swiper area Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> * Use SwipableDrawer instead of Popover Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> --------- Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent f4adde2 commit a4b8cd1

File tree

3 files changed

+158
-77
lines changed

3 files changed

+158
-77
lines changed

wormhole-connect/src/views/v2/Bridge/AssetPicker/ChainList.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@ import type { WalletData } from 'store/wallet';
1717
import SearchableList from 'views/v2/Bridge/AssetPicker/SearchableList';
1818

1919
import { Chain } from '@wormhole-foundation/sdk';
20-
import { useMediaQuery, useTheme } from '@mui/material';
2120

2221
const useStyles = makeStyles()((theme: any) => ({
2322
card: {
2423
background: theme.palette.input.background,
2524
width: '420px',
2625
[theme.breakpoints.down('sm')]: {
27-
maxWidth: '420px',
28-
width: '360px',
29-
},
30-
'@media (max-width: 366px)': {
31-
width: '330px',
26+
width: '100vw',
3227
},
3328
},
3429
cardContent: {
@@ -46,6 +41,9 @@ const useStyles = makeStyles()((theme: any) => ({
4641
},
4742
chainSearch: {
4843
maxHeight: '400px',
44+
[theme.breakpoints.down('sm')]: {
45+
maxHeight: '600px',
46+
},
4947
},
5048
chainButton: {
5149
display: 'flex',
@@ -76,12 +74,9 @@ type Props = {
7674
};
7775

7876
const SHORT_LIST_SIZE = 5;
79-
const SHORT_LIST_SIZE_MOBILE = 4;
8077

8178
const ChainList = (props: Props) => {
8279
const { classes } = useStyles();
83-
const theme = useTheme();
84-
const mobile = useMediaQuery(theme.breakpoints.down('sm'));
8580
const {
8681
chainList,
8782
selectedChainConfig,
@@ -98,25 +93,24 @@ const ChainList = (props: Props) => {
9893
const selectedChainIndex = allChains.findIndex((chain) => {
9994
return chain.key === selectedChain?.key;
10095
});
101-
const shortListSize = mobile ? SHORT_LIST_SIZE_MOBILE : SHORT_LIST_SIZE;
10296
// If the selected chain is outside the top list, we add it to the top;
10397
// otherwise we do not change its index in the top list
10498
if (
10599
selectedChain &&
106100
selectedChainIndex &&
107-
selectedChainIndex >= shortListSize
101+
selectedChainIndex >= SHORT_LIST_SIZE
108102
) {
109103
return [
110-
[selectedChain, ...allChains.slice(0, shortListSize - 1)],
111-
allChains.length > shortListSize,
104+
[selectedChain, ...allChains.slice(0, SHORT_LIST_SIZE - 1)],
105+
allChains.length > SHORT_LIST_SIZE,
112106
];
113107
}
114108

115109
return [
116-
allChains.slice(0, shortListSize),
117-
allChains.length > shortListSize,
110+
allChains.slice(0, SHORT_LIST_SIZE),
111+
allChains.length > SHORT_LIST_SIZE,
118112
];
119-
}, [mobile, chainList, selectedChainConfig]);
113+
}, [chainList, selectedChainConfig]);
120114

121115
const shortList = useMemo(() => {
122116
return (
@@ -166,6 +160,7 @@ const ChainList = (props: Props) => {
166160
onChainSelect,
167161
selectedChainConfig?.key,
168162
setShowSearch,
163+
showMoreButton,
169164
topChains,
170165
]);
171166

wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import TokenItem from 'views/v2/Bridge/AssetPicker/TokenItem';
1515
import { calculateUSDPrice, isFrankensteinToken } from 'utils';
1616
import config from 'config';
1717
import { useTokens } from 'contexts/TokensContext';
18+
1819
const useStyles = makeStyles()((theme: any) => ({
1920
card: {
2021
background: theme.palette.input.background,
@@ -32,7 +33,10 @@ const useStyles = makeStyles()((theme: any) => ({
3233
justifyContent: 'space-between',
3334
},
3435
tokenList: {
35-
maxHeight: 340,
36+
maxHeight: '360px',
37+
[theme.breakpoints.down('sm')]: {
38+
maxHeight: '480px',
39+
},
3640
},
3741
}));
3842

@@ -83,7 +87,9 @@ const TokenList = (props: Props) => {
8387
// Failed to parse the search query as an address... this is expected to happen a lot
8488
}
8589
}
86-
}, [searchQuery, props.selectedChainConfig.sdkName, getOrFetchToken]);
90+
// Run the side-effect only when search query or chain changes
91+
// eslint-disable-next-line react-hooks/exhaustive-deps
92+
}, [searchQuery, props.selectedChainConfig.sdkName]);
8793

8894
const sortedTokens = useMemo(() => {
8995
const nativeToken = config.tokens.getGasToken(
@@ -252,13 +258,14 @@ const TokenList = (props: Props) => {
252258

253259
return tokens;
254260
}, [
255-
balances,
256-
props.tokenList,
261+
props.selectedChainConfig.sdkName,
257262
props.selectedChainConfig.key,
263+
props.selectedToken,
264+
props.tokenList,
258265
props.sourceToken,
259266
props.isSource,
260267
props.wallet?.address,
261-
props.selectedToken,
268+
balances,
262269
searchQuery,
263270
]);
264271

0 commit comments

Comments
 (0)