-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/shopping tab improvements #404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
08847e3
fix: Shopping tab improvements
nghiacc 6c88ff1
feat: Add VND currency support for Goods & Services
nghiacc f8cf61f
fix: Format XEC and fiat prices with proper decimals
nghiacc 836ceeb
fix: Address PR review comments
nghiacc fb4ec6f
fix: Add aria-labelledby to ShoppingCurrencyModal for accessibility
nghiacc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
apps/telegram-ecash-escrow/src/components/FilterList/ShoppingCurrencyModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| 'use client'; | ||
|
|
||
| import { LIST_CURRENCIES_USED } from '@bcpros/lixi-models'; | ||
| import { ChevronLeft } from '@mui/icons-material'; | ||
| import { | ||
| Box, | ||
| Button, | ||
| Dialog, | ||
| DialogContent, | ||
| DialogTitle, | ||
| IconButton, | ||
| Slide, | ||
| TextField, | ||
| Typography, | ||
| useMediaQuery, | ||
| useTheme | ||
| } from '@mui/material'; | ||
| import { styled } from '@mui/material/styles'; | ||
| import { TransitionProps } from '@mui/material/transitions'; | ||
| import React, { useId, useMemo, useState } from 'react'; | ||
| import { FilterCurrencyType } from '../../store/type/types'; | ||
|
|
||
| interface ShoppingCurrencyModalProps { | ||
| isOpen: boolean; | ||
| onDismissModal?: (value: boolean) => void; | ||
| setSelectedItem?: (value: FilterCurrencyType) => void; | ||
| } | ||
|
|
||
| const StyledDialog = styled(Dialog)(({ theme }) => ({ | ||
| '.MuiPaper-root': { | ||
| background: theme.palette.background.default, | ||
| backgroundRepeat: 'no-repeat', | ||
| backgroundSize: 'cover', | ||
| width: '500px', | ||
| height: '100vh', | ||
| maxHeight: '100%', | ||
| margin: 0, | ||
| [theme.breakpoints.down('sm')]: { | ||
| width: '100%' | ||
| } | ||
| }, | ||
|
|
||
| '.MuiIconButton-root': { | ||
| width: 'fit-content', | ||
| svg: { | ||
| fontSize: '32px' | ||
| } | ||
| }, | ||
|
|
||
| '.MuiDialogTitle-root': { | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
|
|
||
| '.back-btn': { | ||
| position: 'absolute', | ||
| left: '10px' | ||
| }, | ||
|
|
||
| '.btn-clear': { | ||
| color: '#FFF', | ||
| position: 'absolute', | ||
| right: '10px', | ||
| fontSize: '12px', | ||
| padding: '1px 5px' | ||
| } | ||
| }, | ||
|
|
||
| '.MuiDialogContent-root': { | ||
| padding: '16px' | ||
| }, | ||
|
|
||
| button: { | ||
| color: theme.palette.text.secondary | ||
| } | ||
| })); | ||
|
|
||
| const Transition = React.forwardRef(function Transition( | ||
| props: TransitionProps & { | ||
| children: React.ReactElement; | ||
| }, | ||
| ref: React.Ref<unknown> | ||
| ) { | ||
| return <Slide direction="up" ref={ref} {...props} />; | ||
| }); | ||
|
|
||
| /** | ||
| * Simplified currency modal for Shopping tab | ||
| * Shows fiat currencies + XEC in a single list, sorted alphabetically | ||
| */ | ||
| const ShoppingCurrencyModal: React.FC<ShoppingCurrencyModalProps> = props => { | ||
| const { isOpen, onDismissModal, setSelectedItem } = props; | ||
| const theme = useTheme(); | ||
| const fullScreen = useMediaQuery(theme.breakpoints.down('md')); | ||
|
|
||
| const [searchTerm, setSearchTerm] = useState(''); | ||
| const titleId = useId(); | ||
|
|
||
| // Build combined list of fiat currencies + XEC, sorted alphabetically by code | ||
| const currencyList = useMemo(() => { | ||
| // Add XEC as a currency option | ||
| const xecOption = { code: 'XEC', name: 'eCash' }; | ||
|
|
||
| // Combine fiat currencies with XEC | ||
| const allCurrencies = [...LIST_CURRENCIES_USED, xecOption]; | ||
|
|
||
| // Sort alphabetically by code | ||
| return allCurrencies.sort((a, b) => a.code.localeCompare(b.code)); | ||
| }, []); | ||
|
|
||
| // Filter currencies based on search term | ||
| const filteredCurrencies = useMemo(() => { | ||
| if (!searchTerm) return currencyList; | ||
|
|
||
| const lowerSearch = searchTerm.toLowerCase(); | ||
| return currencyList.filter( | ||
| option => option.code.toLowerCase().includes(lowerSearch) || option.name.toLowerCase().includes(lowerSearch) | ||
| ); | ||
| }, [currencyList, searchTerm]); | ||
|
|
||
| const handleSelect = (currency: { code: string; name: string }) => { | ||
| const filterCurrency: FilterCurrencyType = { | ||
| paymentMethod: 5, // PAYMENT_METHOD.GOODS_SERVICES | ||
| value: currency.code | ||
| }; | ||
| setSelectedItem?.(filterCurrency); | ||
| onDismissModal?.(false); | ||
| setSearchTerm(''); | ||
| }; | ||
|
|
||
| const handleClear = () => { | ||
| setSelectedItem?.({ paymentMethod: 5, value: '' }); | ||
| onDismissModal?.(false); | ||
| setSearchTerm(''); | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| onDismissModal?.(false); | ||
| setSearchTerm(''); | ||
| }; | ||
|
|
||
| return ( | ||
| <StyledDialog | ||
| fullScreen={fullScreen} | ||
| open={isOpen} | ||
| onClose={handleClose} | ||
| TransitionComponent={Transition} | ||
| aria-labelledby={titleId} | ||
| > | ||
| <DialogTitle id={titleId}> | ||
| <IconButton className="back-btn" onClick={handleClose} aria-label="Close"> | ||
| <ChevronLeft /> | ||
| </IconButton> | ||
| <Typography style={{ fontSize: '20px', fontWeight: 'bold' }}>Select currency</Typography> | ||
| <Button variant="contained" className="btn-clear" onClick={handleClear}> | ||
| Clear | ||
| </Button> | ||
| </DialogTitle> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <DialogContent> | ||
| <TextField | ||
| label="Search" | ||
| variant="filled" | ||
| fullWidth | ||
| onChange={e => setSearchTerm(e.target.value)} | ||
| value={searchTerm} | ||
| autoFocus | ||
| /> | ||
| <Box sx={{ mt: 1, maxHeight: 'calc(100vh - 200px)', overflow: 'auto' }}> | ||
| {filteredCurrencies.map(option => ( | ||
| <Button | ||
| key={option.code} | ||
| onClick={() => handleSelect(option)} | ||
| fullWidth | ||
| variant="text" | ||
| style={{ textTransform: 'none', fontSize: '1.1rem' }} | ||
| sx={{ justifyContent: 'flex-start', textAlign: 'left' }} | ||
| > | ||
| {option.code} - {option.name} | ||
| </Button> | ||
| ))} | ||
| {filteredCurrencies.length === 0 && ( | ||
| <Typography sx={{ p: 2, textAlign: 'center', color: 'text.secondary' }}>No currencies found</Typography> | ||
| )} | ||
| </Box> | ||
| </DialogContent> | ||
| </StyledDialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default ShoppingCurrencyModal; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.