Skip to content

Commit

Permalink
Meenu market section subtask (#678)
Browse files Browse the repository at this point in the history
* fix: updated dropdown size and added default value

* empty: empty commit

* fix: fixed sorting issue
  • Loading branch information
meenakshi-deriv authored Jul 17, 2024
1 parent afb2a98 commit e850770
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/javascript/app/pages/trade/markets/markets-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import contractManager from '../../../common/contract_manager';

export const getMarketName = () => {
const obj = ActiveSymbols.getMarkets();
const symbolKey = Defaults.get(PARAM_NAMES.UNDERLYING);
const symbolKey = Defaults.get(PARAM_NAMES.UNDERLYING) || 'frxAUDJPY';

// Find the market and submarket where the symbolKey exists
const marketKey = Object.keys(obj).find(market =>
Expand Down Expand Up @@ -138,12 +138,12 @@ export const MarketsDropdown = () => {
// Handle selecting of tabs on scroll
useEffect(() => {
const container = itemsContainer.current;

const checkActiveMarket = () => {
const marketDivs = container.querySelectorAll('div');
let closestMarket = '';
let closestOffset = Infinity;

marketDivs.forEach((div) => {
const paddingOffset = 120;
const offsetTop = div.offsetTop - container.scrollTop - paddingOffset;
Expand All @@ -153,25 +153,25 @@ export const MarketsDropdown = () => {
closestMarket = div.getAttribute('data-id');
}
});

if (closestMarket) {
setActiveMarket(closestMarket);
}
};

const handleScroll = () => {
if (!isScrolling.current) {
checkActiveMarket();
}
};

container.addEventListener('scroll', handleScroll);

return () => {
container.removeEventListener('scroll', handleScroll);
};
}, [isMounted]);

const getactiveMarketIndex = () => Object.keys(markets).indexOf(activeMarket);

const scrollToMarketByIndex = (index) => {
Expand Down Expand Up @@ -244,10 +244,18 @@ export const MarketsDropdown = () => {
{Object.keys(markets).map((ik) => {
const market = markets[ik];
const { submarkets } = market;

const sortedSubmarketKeys = Object.keys(submarkets).sort((a, b) => {
if (a === 'major_pairs') return -1;
if (b === 'major_pairs') return 1;
if (a === 'minor_pairs') return -1;
if (b === 'minor_pairs') return 1;
return 0;
});

return (
<div id={`${ik}-dropdown-list`} key={ik} data-id={ik}>
{Object.keys(submarkets).map((sk) => {
{sortedSubmarketKeys.map((sk) => {
const submarket = submarkets[sk];
const { symbols, name } = submarket;

Expand All @@ -258,14 +266,14 @@ export const MarketsDropdown = () => {
const symbol = symbols[yk];
const { display } = symbol;
const isSelected = yk === selectedMarket;

return (
<DropdownItem
key={yk}
onClick={() => handleUnderlyingClick(yk)}
label={display}
selected={isSelected}
size='sm'
size='md'
/>
);
})}
Expand All @@ -276,6 +284,7 @@ export const MarketsDropdown = () => {
</div>
);
})}

</div>
</div>
</div>
Expand Down

0 comments on commit e850770

Please sign in to comment.