Skip to content

Commit

Permalink
fixed results on market details for esports
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikic committed Mar 24, 2023
1 parent 9cf7015 commit afe3804
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
39 changes: 21 additions & 18 deletions src/pages/Markets/Market/MarketDetailsV2/MarketDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,27 @@ const MarketDetails: React.FC<MarketDetailsPropType> = ({ market }) => {
</InfoLabel>
)}
</ResultLabel>
{!SPORTS_TAGS_MAP['Soccer'].includes(Number(liveResultInfo?.sportId)) && (
<PeriodsContainer directionRow={true}>
{liveResultInfo?.scoreHomeByPeriod.map((homePeriodResult, index) => {
return (
<PeriodContainer key={index}>
<InfoLabel className="gray">{index + 1}</InfoLabel>
<InfoLabel>{homePeriodResult}</InfoLabel>
<InfoLabel>{liveResultInfo.scoreAwayByPeriod[index]}</InfoLabel>
</PeriodContainer>
);
})}
<PeriodContainer>
<InfoLabel className="gray">T</InfoLabel>
<InfoLabel>{liveResultInfo?.homeScore}</InfoLabel>
<InfoLabel>{liveResultInfo?.awayScore}</InfoLabel>
</PeriodContainer>
</PeriodsContainer>
)}
{console.log(!SPORTS_TAGS_MAP['eSports'].includes(Number(liveResultInfo?.sportId)))}
{console.log(Number(liveResultInfo?.sportId))}
{!SPORTS_TAGS_MAP['Soccer'].includes(Number(liveResultInfo?.sportId)) &&
!SPORTS_TAGS_MAP['eSports'].includes(Number(liveResultInfo?.sportId)) && (
<PeriodsContainer directionRow={true}>
{liveResultInfo?.scoreHomeByPeriod.map((homePeriodResult, index) => {
return (
<PeriodContainer key={index}>
<InfoLabel className="gray">{index + 1}</InfoLabel>
<InfoLabel>{homePeriodResult}</InfoLabel>
<InfoLabel>{liveResultInfo.scoreAwayByPeriod[index]}</InfoLabel>
</PeriodContainer>
);
})}
<PeriodContainer>
<InfoLabel className="gray">T</InfoLabel>
<InfoLabel>{liveResultInfo?.homeScore}</InfoLabel>
<InfoLabel>{liveResultInfo?.awayScore}</InfoLabel>
</PeriodContainer>
</PeriodsContainer>
)}
</ResultContainer>
)}
</Status>
Expand Down
43 changes: 33 additions & 10 deletions src/queries/markets/useEnetpulseAdditionalDataQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SportMarketLiveResult } from 'types/markets';
import networkConnector from 'utils/networkConnector';
import Web3 from 'web3';
import marketContract from 'utils/contracts/sportsMarketContract';
import { SPORTS_TAGS_MAP } from 'constants/tags';

const useEnetpulseAdditionalDataQuery = (
marketId: string,
Expand All @@ -24,8 +25,6 @@ const useEnetpulseAdditionalDataQuery = (
);
const events = Object.values(JSON.parse(await response.text()).events);

console.log(events);

let gameIdString = '';
if (marketId.length == 42) {
// marketId represents market address in types ParlayMarket and AccountPositionProfile
Expand All @@ -50,27 +49,51 @@ const useEnetpulseAdditionalDataQuery = (
}
}

console.log(trimmedMarketId);
const event = events.find((sportEvent: any) => sportEvent.id == trimmedMarketId) as any;

console.log(event.tournament_stage_name);

if (event) {
const tournamentName = event.tournament_stage_name;
const tournamentRound = ENETPULSE_ROUNDS[Number(event.round_typeFK)];
const eventParticipants: any[] = Object.values(event.event_participants);
const homeResults: any[] = Object.values(eventParticipants[0].result);
const awayResults: any[] = Object.values(eventParticipants[1].result);
let homeScore = 0;
let awayScore = 0;
if (SPORTS_TAGS_MAP['Tennis'].includes(sportTag)) {
homeScore = homeResults.find((result) => result.result_code.toLowerCase() == 'setswon').value;
awayScore = awayResults.find((result) => result.result_code.toLowerCase() == 'setswon').value;
}

const scoreHomeByPeriod = [];
const scoreAwayByPeriod = [];

for (let i = 1; i <= 5; i++) {
const homeSetResult = homeResults.find(
(result) => result.result_code.toLowerCase() == 'set' + i
);
if (homeSetResult) {
scoreHomeByPeriod.push(homeSetResult.value);
}

const awaySetResult = awayResults.find(
(result) => result.result_code.toLowerCase() == 'set' + i
);
if (awaySetResult) {
scoreAwayByPeriod.push(awaySetResult.value);
}
}
const period = 0;
const status = 'finished';
const displayClock = '0';
const sportId = sportParameter;
const sportId = sportTag;

const finalResult: SportMarketLiveResult = {
homeScore: 0,
awayScore: 0,
homeScore,
awayScore,
period,
status,
scoreHomeByPeriod: [],
scoreAwayByPeriod: [],
scoreHomeByPeriod,
scoreAwayByPeriod,
displayClock,
sportId,
tournamentName,
Expand Down

0 comments on commit afe3804

Please sign in to comment.