-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4b52d7
commit bdb4180
Showing
7 changed files
with
192 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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 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
92 changes: 92 additions & 0 deletions
92
frontend/src/features/MarketDetail/components/MarketDetails/index.tsx
This file contains 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,92 @@ | ||
import { Box, Stack, Typography } from '@mui/joy' | ||
|
||
import { Market } from '@api/queries/Market' | ||
import { StyleProps } from '@utils/styles' | ||
import { LoadableWidget } from '@lib/Loadable/Widget' | ||
import { useSuspenseCurrentMarket } from '@features/MarketDetail/utils' | ||
import { getPercentage } from '@utils/number' | ||
import BigNumber from 'bignumber.js' | ||
|
||
const MarketDetails = (props: StyleProps) => { | ||
return ( | ||
<LoadableWidget | ||
useDeps={useSuspenseCurrentMarket} | ||
renderContent={(market) => <MarketDetailsContent market={market} />} | ||
placeholderContent={<MarketDetailsPlaceholder />} | ||
sx={props.sx} | ||
/> | ||
) | ||
} | ||
|
||
const MarketDetailsContent = (props: { market: Market }) => { | ||
const { market } = props | ||
const marketSum = market.possibleOutcomes.reduce((sum, outcome) => sum.plus(outcome.totalTokens), BigNumber(0)) | ||
|
||
return ( | ||
<> | ||
<Typography level="h3"> | ||
{market.title} | ||
</Typography> | ||
<Typography level="body-lg"> | ||
{market.description} | ||
</Typography> | ||
|
||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
gap={4} | ||
sx={{ mt: 2 }} | ||
> | ||
{market.possibleOutcomes.map(outcome => | ||
<Box key={outcome.id}> | ||
<Typography | ||
level="title-lg" | ||
fontWeight={600} | ||
color={outcome.label === "Yes" ? "success" : outcome.label === "No" ? "danger" : "neutral"} | ||
> | ||
{getPercentage(outcome.totalTokens, marketSum)}% {outcome.label} | ||
</Typography> | ||
<Typography level="title-md" textColor="text.secondary" fontWeight={500}> | ||
{outcome.totalTokens.toFixed(3)} Tokens | ||
</Typography> | ||
</Box> | ||
)} | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
const MarketDetailsPlaceholder = () => { | ||
return ( | ||
<> | ||
<Typography level="h3"> | ||
Loading this market's title... | ||
</Typography> | ||
<Typography level="body-lg"> | ||
Loading this market's description... | ||
</Typography> | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
gap={4} | ||
sx={{ mt: 2 }} | ||
> | ||
{["Yes", "No"].map(outcome => | ||
<Box key={outcome}> | ||
<Typography | ||
level="title-lg" | ||
fontWeight={600} | ||
> | ||
0.00% {outcome} | ||
</Typography> | ||
<Typography level="title-md" textColor="text.secondary" fontWeight={500}> | ||
0.000000 Tokens | ||
</Typography> | ||
</Box> | ||
)} | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
export { MarketDetails } |
68 changes: 0 additions & 68 deletions
68
frontend/src/features/MarketDetail/components/MarketOutcomes/index.tsx
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
frontend/src/features/MarketDetail/components/MarketTitle/index.tsx
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
frontend/src/features/MarketDetail/components/MyPositions/index.tsx
This file contains 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,87 @@ | ||
import { Box, Stack, Typography } from '@mui/joy' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
|
||
import { useCurrentAccount } from '@config/chain' | ||
import { Market } from '@api/queries/Market' | ||
import { Positions, positionsQuery } from '@api/queries/Positions' | ||
import { StyleProps } from '@utils/styles' | ||
import { LoadableWidget } from '@lib/Loadable/Widget' | ||
import { useSuspenseCurrentMarket } from '@features/MarketDetail/utils' | ||
|
||
const MyPositions = (props: StyleProps) => { | ||
return ( | ||
<LoadableWidget | ||
useDeps={useDeps} | ||
renderContent={({ market, positions }) => <MyPositionsContent market={market} positions={positions} />} | ||
placeholderContent={<MyPositionsPlaceholder />} | ||
sx={props.sx} | ||
/> | ||
) | ||
} | ||
|
||
const useDeps = () => { | ||
const account = useCurrentAccount() | ||
const market = useSuspenseCurrentMarket() | ||
const positions = useSuspenseQuery(positionsQuery(account.bech32Address, market.id)).data | ||
|
||
return { market, positions } | ||
} | ||
|
||
const MyPositionsContent = (props: { market: Market, positions: Positions }) => { | ||
const { market, positions } = props | ||
|
||
return ( | ||
<> | ||
<Typography level="title-md" fontWeight={600} sx={{ mb: 2 }}>My positions</Typography> | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
gap={4} | ||
> | ||
{market.possibleOutcomes | ||
.filter(outcome => positions.get(outcome.id)?.gt(0)) | ||
.map(outcome => | ||
<Box key={outcome.id}> | ||
<Typography | ||
level="title-lg" | ||
fontWeight={600} | ||
color={outcome.label === "Yes" ? "success" : outcome.label === "No" ? "danger" : "neutral"} | ||
> | ||
{outcome.label} | ||
</Typography> | ||
<Typography level="title-md" textColor="text.secondary" fontWeight={500}> | ||
{positions.get(outcome.id)?.toFixed(3)} Tokens | ||
</Typography> | ||
</Box> | ||
) | ||
} | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
const MyPositionsPlaceholder = () => { | ||
return ( | ||
<> | ||
<Typography level="title-md" fontWeight={600} sx={{ mb: 2 }}>My positions</Typography> | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
gap={4} | ||
> | ||
{[0, 1, 2].map(index => | ||
<Box key={index}> | ||
<Typography level="body-md" fontWeight={600}> | ||
0.00% Yes | ||
</Typography> | ||
<Typography level="body-sm" fontWeight={500}> | ||
10000 TOKENS | ||
</Typography> | ||
</Box> | ||
)} | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
export { MyPositions } |
This file contains 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