From a032da57b9b70c1efa4a68239c9821d6fe44d1b4 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 27 Nov 2024 18:39:30 +0100 Subject: [PATCH] Wallet filters (#1627) * Add wallet filters * Fix grid layout shift * Store filter state in query params * Use auto-fill instead of auto-fit This doesn't seem to change anything but this is closer to our intention how the grid should work with fixed column width. * Use same order for filters as icons in card * Use state update function * Use user-select: none for wallet filters * Remove unnecessary '|| false' * Add media query to keep centered grid layout on small screens * Decrease wallet filter margin-top to 1rem * fix wallet support usage * improve grid --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b --- pages/settings/wallets/index.js | 81 ++++++++++++++++++++++++--------- styles/wallet.module.css | 35 ++++++++++++-- 2 files changed, 89 insertions(+), 27 deletions(-) diff --git a/pages/settings/wallets/index.js b/pages/settings/wallets/index.js index a8330c83..95e9a6eb 100644 --- a/pages/settings/wallets/index.js +++ b/pages/settings/wallets/index.js @@ -7,6 +7,11 @@ import { useCallback, useState } from 'react' import { useIsClient } from '@/components/use-client' import WalletCard from '@/components/wallet-card' import { useToast } from '@/components/toast' +import BootstrapForm from 'react-bootstrap/Form' +import RecvIcon from '@/svgs/arrow-left-down-line.svg' +import SendIcon from '@/svgs/arrow-right-up-line.svg' +import { useRouter } from 'next/router' +import { supportsReceive, supportsSend } from '@/wallets/common' export const getServerSideProps = getGetServerSideProps({ authRequired: true }) @@ -17,6 +22,12 @@ export default function Wallet ({ ssrData }) { const [sourceIndex, setSourceIndex] = useState(null) const [targetIndex, setTargetIndex] = useState(null) + const router = useRouter() + const [filter, setFilter] = useState({ + send: router.query.send === 'true', + receive: router.query.receive === 'true' + }) + const reorder = useCallback(async (sourceIndex, targetIndex) => { const newOrder = [...wallets.filter(w => w.config?.enabled)] const [source] = newOrder.splice(sourceIndex, 1) @@ -65,6 +76,13 @@ export default function Wallet ({ ssrData }) { } }, [sourceIndex, reorder, onReorderError]) + const onFilterChange = useCallback((key) => { + return e => { + setFilter(old => ({ ...old, [key]: e.target.checked })) + router.replace({ query: { ...router.query, [key]: e.target.checked } }, undefined, { shallow: true }) + } + }, [router]) + return (
@@ -76,33 +94,52 @@ export default function Wallet ({ ssrData }) {
- {wallets.map((w, i) => { - const draggable = isClient && w.config?.enabled +
+ receive} + onChange={onFilterChange('receive')} + checked={filter.receive} + /> + send} + onChange={onFilterChange('send')} + checked={filter.send} + /> +
+ {wallets + .filter(w => { + return (!filter.send || (filter.send && supportsSend(w))) && + (!filter.receive || (filter.receive && supportsReceive(w))) + }) + .map((w, i) => { + const draggable = isClient && w.config?.enabled - return ( -
- -
- ) - } - )} + suppressHydrationWarning + > + +
+ ) + } + )} diff --git a/styles/wallet.module.css b/styles/wallet.module.css index f968297f..a4c28752 100644 --- a/styles/wallet.module.css +++ b/styles/wallet.module.css @@ -1,10 +1,34 @@ .walletGrid { display: grid; - grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); + grid-template-columns: repeat(auto-fill, 160px); grid-gap: 20px; - justify-items: center; - align-items: center; - margin-top: 3rem; + padding: 20px 0; + justify-content: center; +} + +@media (max-width: 440px) { + .walletGrid { + grid-template-columns: repeat(auto-fill, 140px); + grid-gap: 15px; + } + .card { + width: 140px; + } +} + +@media (max-width: 330px) { + .walletGrid { + grid-template-columns: 100%; + } + .walletGrid > * { + justify-self: center; + } +} + +.walletFilters { + grid-column: 1 / -1; + margin-left: 0.2rem; + user-select: none; } .drag { @@ -17,7 +41,8 @@ .card { width: 160px; - height: 180px; + max-width: 100%; + aspect-ratio: 160 / 180; } .indicators {