Skip to content

Commit

Permalink
Explorer recent plays
Browse files Browse the repository at this point in the history
  • Loading branch information
bone-house committed Oct 2, 2023
1 parent a89c716 commit cac9af6
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 75 deletions.
126 changes: 126 additions & 0 deletions apps/explorer/src/AllPlatforms.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Box, Card, Container, Flex, Grid, Table, Text } from '@radix-ui/themes'
import React from 'react'
import { Graph } from './Graph'
import { Money } from './Money'
import { getCreators, getDailyVolume } from './api'
import { Loader } from './components/Loader'
import { PlatformAccountItem } from './components/AccountItem'
import { TableRowNavLink } from './components/TableRowLink'
import { DailyVolume } from './data'

export function VolumeGraph({ creator }: {creator?: string}) {
const [dailyVolume, setDailyVolume] = React.useState<DailyVolume[]>([])
const [hovered, setHovered] = React.useState<DailyVolume | null>(null)

React.useEffect(() => {
getDailyVolume(creator).then(setDailyVolume).catch(console.error)
}, [])

const totalVolume = React.useMemo(() => {
return dailyVolume.reduce((prev, creator) => prev + creator.total_volume, 0)
}, [dailyVolume])

return (
<Card size="2">
<Grid gap="2">
<Text color="gray">
{hovered?.date ? new Date(hovered.date).toLocaleString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) : '30d Volume'}
</Text>
<Text size="7" weight="bold">
<Money lamports={hovered?.total_volume ?? totalVolume} />
</Text>
<Box style={{height: '200px'}}>
<Graph onHover={setHovered} dailyVolume={dailyVolume} />
</Box>
</Grid>
</Card>
)
}

function useDashboard() {
const [loading, setLoading] = React.useState(true)
const [creators, setCreators] = React.useState<{creator: string, volume: number}[]>([])

React.useEffect(() => {
const fetch = async () => {
try {
setLoading(true)
setCreators(await getCreators())
} finally {
setLoading(false)
}
}
fetch()
}, [])

return {loading, creators}
}

function CreatorList({creators}: {creators: {creator: string, volume: number}[]}) {
return (
<Table.Root className="CreatorsTable" variant="surface">
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>
#
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>
Platform
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell align="right">
Volume
</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
{creators.map((creator, i) => {
const { creator: address, volume } = creator
const index = creators.indexOf(creator)
return (
<TableRowNavLink key={i} to={'/platform/' + address}>
<Table.Cell>
<Text>
{index + 1}
</Text>
</Table.Cell>
<Table.Cell>
<PlatformAccountItem address={address} />
</Table.Cell>
<Table.Cell align="right">
<Text>
<Money lamports={volume} />
</Text>
</Table.Cell>
</TableRowNavLink>
)
})}
</Table.Body>
</Table.Root>
)
}

export function AllPlatforms() {
const {loading, creators} = useDashboard()

if (loading) {
return (
<Container>
<Flex align="center" justify="center" p="4">
<Loader />
</Flex>
</Container>
)
}

return (
<Container>
<Grid gap="4">
<Box>
<Text color="gray">All Platforms</Text>
</Box>
<CreatorList creators={creators} />
</Grid>
</Container>
)
}
9 changes: 7 additions & 2 deletions apps/explorer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PlatformView } from './Platform'
import { PlayView } from './PlayView'
import { PlayerView } from './Player'
import { Search } from './Search'
import { AllPlatforms } from './AllPlatforms'

export function App() {
const [search, setSearch] = React.useState('')
Expand Down Expand Up @@ -47,10 +48,10 @@ export function App() {
</Box>
<Box>
<Flex gap="4">
<Link href="https://github.com/gamba-labs/gamba" target="_blank" rel="noreferrer">
<Link size="1" href="https://github.com/gamba-labs/gamba" target="_blank" rel="noreferrer">
Github <ExternalLinkIcon />
</Link>
<Link href="https://gamba.so" target="_blank" rel="noreferrer">
<Link size="1" href="https://gamba.so" target="_blank" rel="noreferrer">
About <ExternalLinkIcon />
</Link>
</Flex>
Expand Down Expand Up @@ -78,6 +79,10 @@ export function App() {
path="/search/:signatureOrAddress"
element={<Search />}
/>
<Route
path="/platforms"
element={<AllPlatforms />}
/>
<Route
path="/tx/:txid"
element={<PlayView />}
Expand Down
64 changes: 50 additions & 14 deletions apps/explorer/src/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningBoltIcon, StarFilledIcon } from '@radix-ui/react-icons'
import { Badge, Box, Card, Container, Flex, Grid, Table, Text } from '@radix-ui/themes'
import { ArrowRightIcon, LightningBoltIcon, StarFilledIcon } from '@radix-ui/react-icons'
import { Avatar, Badge, Box, Button, Card, Container, Flex, Grid, Link, ScrollArea, Table, Text } from '@radix-ui/themes'
import React from 'react'
import Marquee from 'react-fast-marquee'
import { NavLink } from 'react-router-dom'
Expand All @@ -8,13 +8,15 @@ import { Graph } from './Graph'
import { Money } from './Money'
import { END_TIME, TopBetResult, getCreators, getDailyVolume, getPlayers, getTopBets } from './api'
import { Loader } from './components/Loader'
import { PlatformText } from './components/PlatformText'
import { PlatformAccountItem } from './components/AccountItem'
import { TableRowNavLink } from './components/TableRowLink'
import { DailyVolume, getCreatorMeta } from './data'
import { RecentPlays } from './RecentPlays'

const TopPlayLink = styled(NavLink)`
text-decoration: none;
cursor: pointer;
color: unset;
`

export function VolumeGraph({ creator }: {creator?: string}) {
Expand Down Expand Up @@ -100,7 +102,7 @@ function CreatorList({creators}: {creators: {creator: string, volume: number}[]}
</Text>
</Table.Cell>
<Table.Cell>
<PlatformText address={address} />
<PlatformAccountItem address={address} />
</Table.Cell>
<Table.Cell align="right">
<Text>
Expand Down Expand Up @@ -135,13 +137,14 @@ export function Dashboard() {
return (
<Container>
<Grid gap="4">

<Box>
<Card size="1">
<Grid columns="2" style={{ gridTemplateColumns: 'auto 1fr' }}>
<Flex gap="2" p="2" align="center" pr="4">
<StarFilledIcon />
<Text color="gray">
Weekly best
Top plays
</Text>
</Flex>
<Marquee delay={2} speed={33} pauseOnHover>
Expand Down Expand Up @@ -201,18 +204,51 @@ export function Dashboard() {
</Grid>
</Card>
</Box>
<Box>
<Flex gap="2" align="center">
<LightningBoltIcon />
<Text color="gray">Top Platforms this week</Text>
</Flex>
</Box>
<CreatorList creators={trendingCreators.slice(0, 5)} />


<Flex gap="2" align="center" justify="between">
<Text color="gray">
Top Platforms this week
</Text>
<Link asChild>
<NavLink to="/platforms">
View all <ArrowRightIcon />
</NavLink>
</Link>
</Flex>

<ScrollArea>

<Flex gap="2" pb="1">
{trendingCreators.slice(0, 8).map((platform, i) => (
<TopPlayLink key={platform.creator} to={`/platform/${platform.creator}`}>
<Card size="2">
<Grid gap="2">
<Flex justify="center">
<Avatar
size="2"
src={getCreatorMeta(platform.creator).image}
fallback={platform.creator.substr(0,3)}
/>
</Flex>
<Text size="1" style={{width: '100px', overflow: 'hidden', textOverflow: 'ellipsis', textAlign: 'center', whiteSpace: 'nowrap'}}>
{getCreatorMeta(platform.creator).name}
</Text>
</Grid>
<Badge style={{position: 'absolute', right: 0, top: 0}}>
#{1 + i}
</Badge>
</Card>
</TopPlayLink>
))}
</Flex>
</ScrollArea>


<Box>
<Text color="gray">All Platforms</Text>
<Text color="gray">Recent Plays</Text>
</Box>
<CreatorList creators={creators} />
<RecentPlays />
</Grid>
</Container>
)
Expand Down
12 changes: 4 additions & 8 deletions apps/explorer/src/Platform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Money } from './Money'
import { RecentPlays } from './RecentPlays'
import { TopBetResult, TopPlayer, TopPlayerWager, getDailyVolume, getPlayers, getTopBets, getTopPlayers, getTopPlayersByWager } from './api'
import { Loader } from './components/Loader'
import { PlatformText } from './components/PlatformText'
import { PlatformAccountItem, PlayerAccountItem } from './components/AccountItem'
import { TableRowNavLink } from './components/TableRowLink'
import { DailyVolume, getCreatorMeta } from './data'
import { truncateString } from './utils'
Expand Down Expand Up @@ -88,7 +88,7 @@ export function PlatformView() {
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>
<PlatformText address={address!} />
<PlatformAccountItem address={address!} />
</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>
Expand Down Expand Up @@ -183,9 +183,7 @@ export function PlatformView() {
<TableRowNavLink key={i} to={`/player/${player.player}`} style={{flexGrow: '1'}}>
<Table.Cell>
<Flex gap="2" justify="between">
<Text>
{truncateString(player.player)}
</Text>
<PlayerAccountItem address={player.player} />
<Text color="green">
<Money lamports={player.total_wager} />
</Text>
Expand All @@ -210,9 +208,7 @@ export function PlatformView() {
<TableRowNavLink key={i} to={`/player/${player.player}`} style={{flexGrow: '1'}}>
<Table.Cell>
<Flex justify="between" gap="2">
<Text>
{truncateString(player.player)}
</Text>
<PlayerAccountItem address={player.player} />
<Text color="green">
+<Money lamports={player.net_wins} />
</Text>
Expand Down
6 changes: 3 additions & 3 deletions apps/explorer/src/PlayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GameResult, ParsedGambaTransaction, parseGambaTransaction } from 'gamba
import React from 'react'
import { NavLink, useParams } from 'react-router-dom'
import { Money } from './Money'
import { PlatformText } from './components/PlatformText'
import { PlatformAccountItem, PlayerAccountItem } from './components/AccountItem'
import styles from './test.module.css'
import { isSignature } from './utils'
import { Loader } from './components/Loader'
Expand Down Expand Up @@ -218,7 +218,7 @@ function TransactionDetails({parsed}: {parsed: ParsedGambaTransaction}) {
</Text>
<Link asChild>
<NavLink to={'/platform/' + gameResult.creator.toBase58()}>
<PlatformText address={gameResult.creator} />
<PlatformAccountItem address={gameResult.creator} />
</NavLink>
</Link>
</Grid>
Expand All @@ -233,7 +233,7 @@ function TransactionDetails({parsed}: {parsed: ParsedGambaTransaction}) {
</Text>
<Link asChild>
<NavLink to={'/player/' + gameResult.player.toBase58()}>
{gameResult.player.toBase58()}
<PlayerAccountItem address={gameResult.player} />
</NavLink>
</Link>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Container, Grid, Link, Table, Text } from '@radix-ui/themes'
import React from 'react'
import { useParams } from 'react-router-dom'
import { RecentPlays } from './RecentPlays'
import { PlatformText } from './components/PlatformText'
import { PlatformAccountItem, PlayerAccountItem } from './components/AccountItem'

export function PlayerView() {
const { address } = useParams<{address: string}>()
Expand All @@ -15,7 +15,7 @@ export function PlayerView() {
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>
<PlatformText address={address!} />
<PlayerAccountItem address={address!} />
</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>
Expand Down
17 changes: 6 additions & 11 deletions apps/explorer/src/RecentPlays.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { PlusCircledIcon } from '@radix-ui/react-icons'
import { Badge, Box, Button, Flex, Link, Table, Text } from '@radix-ui/themes'
import { Avatar, Badge, Box, Button, Flex, Table, Text } from '@radix-ui/themes'
import React from 'react'
import { NavLink } from 'react-router-dom'
import styled from 'styled-components'
import { Money } from './Money'
import { RecentBet, getBets } from './api'
import { PlatformIcon, PlatformText } from './components/PlatformText'
import { getCreatorMeta } from './data'
import styled from 'styled-components'
import { truncateString } from './utils'
import { PlatformAccountItem, PlayerAccountItem } from './components/AccountItem'
import { TableRowNavLink } from './components/TableRowLink'
import { truncateString } from './utils'

const timeAgo = (time: number) => {
const diff = Date.now() - time
Expand Down Expand Up @@ -98,15 +96,12 @@ export function RecentPlays({creator, player}: {creator?: string, player?: strin
<TableRowNavLink to={'/play/' + transaction.signature} key={transaction.signature}>
{!creator && (
<Table.Cell>
<PlatformText address={transaction.creator} />
<PlatformAccountItem address={transaction.creator} />
</Table.Cell>
)}
{!player && (
<Table.Cell>
<Flex gap="2">
<PlatformIcon />
{truncateString(transaction.player)}
</Flex>
<PlayerAccountItem address={transaction.player} />
</Table.Cell>
)}
<Table.Cell>
Expand Down
Loading

0 comments on commit cac9af6

Please sign in to comment.