-
Notifications
You must be signed in to change notification settings - Fork 0
Add Shopping tab, fiat rate fallback, and performance optimizations #391
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
Open
nghiacc
wants to merge
13
commits into
master
Choose a base branch
from
feature/shopping-fiat-fallback-optimization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
61c541e
feat: Shopping tab, fiat rate fallback, and performance optimization
nghiacc 968793a
fix: Code formatting and additional refinements
nghiacc bd02191
fix: Reorder imports in useOfferPrice hook
nghiacc 989474e
refactor: Extract rate transformation logic into reusable utility fun…
nghiacc ae060b2
docs: Add comprehensive documentation for rate transformation refacto…
nghiacc 1757960
chore: Apply Prettier formatting and finalize documentation
nghiacc b959b17
fix: Address AI review comments
nghiacc c289abc
fix: Handle legacy Goods & Services offers without price
nghiacc 7d884ec
fix: Address three new AI review comments
nghiacc 37b902e
refactor: Remove client-side Telegram alert code
nghiacc 21da5d2
fix: Add null check for coinPayment in getCoinRate
nghiacc 3b1a112
feat: Add unified fiat rate error banner across all pages
nghiacc 0011299
refactor: Clean up PlaceAnOrderModal component styling
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
Some comments aren't visible on the classic Files Changed page.
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
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,230 @@ | ||
| 'use client'; | ||
|
|
||
| import FiatRateErrorBanner from '@/src/components/Common/FiatRateErrorBanner'; | ||
| import ShoppingFilterComponent from '@/src/components/FilterOffer/ShoppingFilterComponent'; | ||
| import Header from '@/src/components/Header/Header'; | ||
| import OfferItem from '@/src/components/OfferItem/OfferItem'; | ||
| import { PAYMENT_METHOD } from '@bcpros/lixi-models'; | ||
| import { | ||
| OfferOrderField, | ||
| OrderDirection, | ||
| TimelineQueryItem, | ||
| fiatCurrencyApi, | ||
| getNewPostAvailable, | ||
| offerApi, | ||
| openModal, | ||
| setNewPostAvailable, | ||
| useInfiniteOfferFilterDatabaseQuery, | ||
| useSliceDispatch as useLixiSliceDispatch, | ||
| useSliceSelector as useLixiSliceSelector | ||
| } from '@bcpros/redux-store'; | ||
| import styled from '@emotion/styled'; | ||
| import CachedRoundedIcon from '@mui/icons-material/CachedRounded'; | ||
| import SortIcon from '@mui/icons-material/Sort'; | ||
| import { Badge, Box, CircularProgress, Skeleton, Slide, Typography } from '@mui/material'; | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
| import InfiniteScroll from 'react-infinite-scroll-component'; | ||
| import MobileLayout from '../../components/layout/MobileLayout'; | ||
| import { isShowAmountOrSortFilter } from '../../store/util'; | ||
|
|
||
| const { useGetAllFiatRateQuery } = fiatCurrencyApi; | ||
|
|
||
| const WrapShopping = styled.div``; | ||
|
|
||
| const ShoppingPage = styled.div` | ||
| position: relative; | ||
| padding: 1rem; | ||
| padding-bottom: 85px; | ||
| min-height: 100svh; | ||
|
|
||
| .MuiButton-root { | ||
| text-transform: none; | ||
| } | ||
|
|
||
| .MuiIconButton-root { | ||
| padding: 0 !important; | ||
|
|
||
| &:hover { | ||
| background: none; | ||
| opacity: 0.8; | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const Section = styled.div` | ||
| .title-offer { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| font-weight: 600; | ||
| } | ||
| `; | ||
|
|
||
| const StyledBadge = styled(Badge)` | ||
| background: #0f98f2; | ||
| position: absolute; | ||
| z-index: 1; | ||
| left: 40%; | ||
| top: 1rem; | ||
| cursor: pointer; | ||
| padding: 8px 13px; | ||
| border-radius: 50px; | ||
| display: flex; | ||
| align-items: center; | ||
| color: white; | ||
| gap: 3px; | ||
|
|
||
| .refresh-text { | ||
| font-size: 14px; | ||
| font-weight: bold; | ||
| } | ||
| `; | ||
|
|
||
| export default function Shopping() { | ||
| const newPostAvailable = useLixiSliceSelector(getNewPostAvailable); | ||
| const [visible, setVisible] = useState(true); | ||
| const dispatch = useLixiSliceDispatch(); | ||
|
|
||
| // Prefetch fiat rates in the background for better modal performance | ||
| // This will cache the data so PlaceAnOrderModal can use it immediately | ||
| const { | ||
| data: fiatData, | ||
| isError: fiatRateError, | ||
| isLoading: isFiatRateLoading | ||
| } = useGetAllFiatRateQuery(undefined, { | ||
| // Polling disabled for performance - only fetch once on mount | ||
| pollingInterval: 0, | ||
| // Refetch on mount to ensure fresh data | ||
| refetchOnMountOrArgChange: true | ||
| }); | ||
|
|
||
| // Fixed filter config for shopping: only Goods & Services sell offers | ||
| const [shoppingFilterConfig, setShoppingFilterConfig] = useState({ | ||
| isBuyOffer: true, // Buy offers (users wanting to buy XEC by selling goods/services - so shoppers can buy the goods) | ||
| paymentMethodIds: [PAYMENT_METHOD.GOODS_SERVICES], | ||
| tickerPriceGoodsServices: null, // NEW: Backend filter for G&S currency | ||
| fiatCurrency: null, | ||
| coin: null, | ||
| amount: null, | ||
| countryName: null, | ||
| countryCode: null, | ||
| stateName: null, | ||
| adminCode: null, | ||
| cityName: null, | ||
| paymentApp: null, | ||
| coinOthers: null, | ||
| offerOrder: { | ||
| field: OfferOrderField.Relevance, | ||
| direction: OrderDirection.Desc | ||
| } | ||
| }); | ||
|
|
||
| const isShowSortIcon = isShowAmountOrSortFilter(shoppingFilterConfig); | ||
|
|
||
| const { | ||
| data: dataFilter, | ||
| hasNext: hasNextFilter, | ||
| isFetching: isFetchingFilter, | ||
| fetchNext: fetchNextFilter, | ||
| isLoading: isLoadingFilter, | ||
| refetch | ||
| } = useInfiniteOfferFilterDatabaseQuery({ first: 20, offerFilterInput: shoppingFilterConfig }, false); | ||
|
|
||
| const loadMoreItemsFilter = () => { | ||
| if (hasNextFilter && !isFetchingFilter) { | ||
| fetchNextFilter(); | ||
| } | ||
| }; | ||
|
|
||
| const handleRefresh = () => { | ||
| dispatch(offerApi.api.util.resetApiState()); | ||
| refetch(); | ||
| dispatch(setNewPostAvailable(false)); | ||
| window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }); | ||
| }; | ||
|
|
||
| //reset flag for new-post when reload | ||
| useEffect(() => { | ||
| dispatch(setNewPostAvailable(false)); | ||
| }, []); | ||
|
|
||
| const openSortDialog = () => { | ||
| dispatch(openModal('SortOfferModal', {})); | ||
| }; | ||
|
|
||
| const isSorted = useMemo( | ||
| () => | ||
| shoppingFilterConfig?.offerOrder?.direction !== OrderDirection.Desc || | ||
| shoppingFilterConfig?.offerOrder?.field !== OfferOrderField.Relevance, | ||
| [shoppingFilterConfig?.offerOrder] | ||
| ); | ||
|
|
||
| return ( | ||
| <MobileLayout> | ||
| <WrapShopping> | ||
| <Slide direction="down" in={newPostAvailable && visible}> | ||
| <StyledBadge className="badge-new-offer" color="info" onClick={handleRefresh}> | ||
| <CachedRoundedIcon color="action" /> <span className="refresh-text">Refresh</span> | ||
| </StyledBadge> | ||
| </Slide> | ||
| <ShoppingPage> | ||
| <Header /> | ||
|
|
||
| <ShoppingFilterComponent filterConfig={shoppingFilterConfig} setFilterConfig={setShoppingFilterConfig} /> | ||
|
|
||
| {/* Show fiat rate error banner if service is down */} | ||
| <FiatRateErrorBanner fiatData={fiatData} fiatRateError={fiatRateError} isLoading={isFiatRateLoading} /> | ||
|
|
||
| <Section> | ||
| <Typography className="title-offer" variant="body1" component="div"> | ||
| <span>Goods & Services</span> | ||
| {isShowSortIcon && ( | ||
| <SortIcon | ||
| style={{ cursor: 'pointer', color: `${isSorted ? '#0076C4' : ''}` }} | ||
| onClick={openSortDialog} | ||
| /> | ||
| )} | ||
| {(shoppingFilterConfig.stateName || | ||
| shoppingFilterConfig.countryName || | ||
| shoppingFilterConfig.cityName) && ( | ||
| <span> | ||
| {[shoppingFilterConfig.cityName, shoppingFilterConfig.stateName, shoppingFilterConfig.countryName] | ||
| .filter(Boolean) | ||
| .join(', ')} | ||
| </span> | ||
| )} | ||
| </Typography> | ||
| <div | ||
| id="scrollableDiv" | ||
| className="offer-list" | ||
| style={{ overflow: 'auto', maxHeight: 'calc(100vh - 250px)' }} | ||
| > | ||
| {!isLoadingFilter ? ( | ||
| <InfiniteScroll | ||
| dataLength={dataFilter.length} | ||
| next={loadMoreItemsFilter} | ||
| hasMore={hasNextFilter} | ||
| loader={ | ||
| <> | ||
| <Skeleton variant="text" /> | ||
| <Skeleton variant="text" /> | ||
| </> | ||
| } | ||
| scrollableTarget="scrollableDiv" | ||
| scrollThreshold={'100px'} | ||
| > | ||
| {dataFilter.map(item => { | ||
| return <OfferItem key={item.id} timelineItem={item as TimelineQueryItem} />; | ||
| })} | ||
| </InfiniteScroll> | ||
| ) : ( | ||
| <Box sx={{ height: '50vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}> | ||
| <CircularProgress color="primary" /> | ||
| </Box> | ||
| )} | ||
| </div> | ||
| </Section> | ||
| </ShoppingPage> | ||
| </WrapShopping> | ||
| </MobileLayout> | ||
| ); | ||
| } | ||
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.