2024-01-31 14:21:29 +00:00
import { useT } from '../../lib/use-t' ;
import { ErrorBoundary } from '@sentry/react' ;
import { CompetitionsHeader } from '../../components/competitions/competitions-header' ;
2024-02-20 14:39:41 +00:00
import {
ExternalLink ,
Intent ,
Loader ,
TradingButton ,
} from '@vegaprotocol/ui-toolkit' ;
2024-02-15 20:14:04 +00:00
import { useEpochInfoQuery } from '../../lib/hooks/__generated__/Epoch' ;
2024-01-31 14:21:29 +00:00
import { Link , useNavigate } from 'react-router-dom' ;
import { Links } from '../../lib/links' ;
import {
CompetitionsAction ,
CompetitionsActionsContainer ,
} from '../../components/competitions/competitions-cta' ;
import { GamesContainer } from '../../components/competitions/games-container' ;
import { CompetitionsLeaderboard } from '../../components/competitions/competitions-leaderboard' ;
import { useTeams } from '../../lib/hooks/use-teams' ;
import take from 'lodash/take' ;
import { usePageTitle } from '../../lib/hooks/use-page-title' ;
2024-02-02 18:07:06 +00:00
import { TeamCard } from '../../components/competitions/team-card' ;
import { useMyTeam } from '../../lib/hooks/use-my-team' ;
2024-02-20 12:20:35 +00:00
import { useRewards } from '../../lib/hooks/use-rewards' ;
2024-02-20 14:39:41 +00:00
import { Trans } from 'react-i18next' ;
import { DocsLinks } from '@vegaprotocol/environment' ;
2024-01-31 14:21:29 +00:00
export const CompetitionsHome = ( ) = > {
const t = useT ( ) ;
const navigate = useNavigate ( ) ;
usePageTitle ( t ( 'Competitions' ) ) ;
2024-02-15 20:14:04 +00:00
const { data : epochData } = useEpochInfoQuery ( ) ;
2024-01-31 14:21:29 +00:00
const currentEpoch = Number ( epochData ? . epoch . id ) ;
2024-02-20 12:20:35 +00:00
const { data : gamesData , loading : gamesLoading } = useRewards ( {
2024-01-31 14:21:29 +00:00
onlyActive : true ,
2024-02-20 12:20:35 +00:00
scopeToTeams : true ,
2024-01-31 14:21:29 +00:00
} ) ;
2024-02-01 10:38:57 +00:00
const { data : teamsData , loading : teamsLoading } = useTeams ( ) ;
2024-01-31 14:21:29 +00:00
2024-02-02 18:07:06 +00:00
const {
team : myTeam ,
stats : myTeamStats ,
games : myTeamGames ,
rank : myTeamRank ,
} = useMyTeam ( ) ;
2024-01-31 14:21:29 +00:00
return (
< ErrorBoundary >
< CompetitionsHeader title = { t ( 'Competitions' ) } >
2024-02-20 14:39:41 +00:00
< p className = "text-lg mb-3" >
< Trans
i18nKey = {
'Check the cards below to see what community-created, on-chain games are active and how to compete. Joining a team also lets you take part in the on-chain <0>referral program</0>.'
}
components = { [
< Link className = "underline" key = "ref-prog" to = { Links . REFERRALS ( ) } >
referral program
< / Link > ,
] }
/ >
< / p >
2024-01-31 14:21:29 +00:00
< p className = "text-lg mb-1" >
2024-02-20 14:39:41 +00:00
< Trans
i18nKey = {
'Got an idea for a competition? Anyone can define and fund one -- <0>propose an on-chain game</0> yourself.'
}
components = { [
< ExternalLink
className = "underline"
key = "propose"
href = { DocsLinks ? . ASSET_TRANSFER_PROPOSAL }
>
propose an on - chain game
< / ExternalLink > ,
] }
/ >
{ /** Docs: https://docs.vega.xyz/mainnet/tutorials/proposals/asset-transfer-proposal */ }
2024-01-31 14:21:29 +00:00
< / p >
< / CompetitionsHeader >
2024-02-02 18:07:06 +00:00
{ /** Team card */ }
{ myTeam ? (
< >
< h2 className = "text-2xl mb-6" > { t ( 'My team' ) } < / h2 >
< div className = "mb-12" >
< TeamCard
team = { myTeam }
rank = { myTeamRank }
stats = { myTeamStats }
games = { myTeamGames }
/ >
< / div >
< / >
) : (
< >
{ /** Get started */ }
< h2 className = "text-2xl mb-6" > { t ( 'Get started' ) } < / h2 >
2024-01-31 14:21:29 +00:00
2024-02-02 18:07:06 +00:00
< CompetitionsActionsContainer >
< CompetitionsAction
variant = "A"
title = { t ( 'Create a team' ) }
description = { t (
2024-02-20 14:39:41 +00:00
'Create a new team, share your code with potential members, or set a whitelist for an exclusive group.'
2024-02-02 18:07:06 +00:00
) }
actionElement = {
< TradingButton
intent = { Intent . Primary }
onClick = { ( e ) = > {
e . preventDefault ( ) ;
navigate ( Links . COMPETITIONS_CREATE_TEAM ( ) ) ;
} }
data - testId = "create-public-team-button"
>
{ t ( 'Create a public team' ) }
< / TradingButton >
}
/ >
< CompetitionsAction
variant = "B"
title = { t ( 'Solo team / lone wolf' ) }
description = { t (
2024-02-20 14:39:41 +00:00
'Want to compete but think the best team size is one? This is the option for you.'
2024-02-02 18:07:06 +00:00
) }
actionElement = {
< TradingButton
intent = { Intent . Primary }
onClick = { ( e ) = > {
e . preventDefault ( ) ;
navigate ( Links . COMPETITIONS_CREATE_TEAM_SOLO ( ) ) ;
} }
>
{ t ( 'Create a private team' ) }
< / TradingButton >
}
/ >
< CompetitionsAction
variant = "C"
title = { t ( 'Join a team' ) }
description = { t (
2024-02-20 14:39:41 +00:00
'Browse existing public teams to find your perfect match.'
2024-02-02 18:07:06 +00:00
) }
actionElement = {
< TradingButton
intent = { Intent . Primary }
onClick = { ( e ) = > {
e . preventDefault ( ) ;
navigate ( Links . COMPETITIONS_TEAMS ( ) ) ;
} }
>
{ t ( 'Choose a team' ) }
< / TradingButton >
}
/ >
< / CompetitionsActionsContainer >
< / >
) }
2024-01-31 14:21:29 +00:00
{ /** List of available games */ }
2024-02-20 14:39:41 +00:00
< h2 className = "text-2xl mb-1" > { t ( 'Games' ) } < / h2 >
< p className = "mb-6 text-sm" >
< Trans
i18nKey = {
'See all the live games on the cards below. Every on-chain game is community funded and designed. <0>Find out how to create one</0>.'
}
components = { [
< ExternalLink
className = "underline"
key = "find-out"
href = { DocsLinks ? . ASSET_TRANSFER_PROPOSAL }
>
Find out how to create one
< / ExternalLink > ,
] }
/ >
{ /** Docs: https://docs.vega.xyz/mainnet/tutorials/proposals/asset-transfer-proposal */ }
< / p >
2024-01-31 14:21:29 +00:00
2024-02-20 15:17:02 +00:00
< div className = "mb-12 flex" >
{ gamesLoading ? (
< Loader size = "small" / >
) : (
< GamesContainer data = { gamesData } currentEpoch = { currentEpoch } / >
) }
< / div >
2024-01-31 14:21:29 +00:00
{ /** The teams ranking */ }
2024-02-20 14:39:41 +00:00
< div className = "mb-1 flex flex-row items-baseline gap-3 justify-between" >
< h2 className = "text-2xl" >
< Link to = { Links . COMPETITIONS_TEAMS ( ) } className = " underline" >
{ t ( 'Leaderboard' ) }
< / Link >
< / h2 >
2024-01-31 14:21:29 +00:00
< Link to = { Links . COMPETITIONS_TEAMS ( ) } className = "text-sm underline" >
{ t ( 'View all teams' ) }
< / Link >
< / div >
2024-02-20 14:39:41 +00:00
< p className = "mb-6 text-sm" >
{ t (
'Teams can earn rewards if they meet the goals set in the on-chain trading competitions. Track your earned rewards here, and see which teams are top of the leaderboard this month.'
) }
< / p >
2024-01-31 14:21:29 +00:00
2024-02-20 15:17:02 +00:00
< div className = "flex" >
{ teamsLoading ? (
< Loader size = "small" / >
) : (
< CompetitionsLeaderboard data = { take ( teamsData , 10 ) } / >
) }
< / div >
2024-01-31 14:21:29 +00:00
< / ErrorBoundary >
) ;
} ;