({ data }: Props)
| 50 | |
| 51 | type StatType = "dailyStats" | "newDailyStats" |
| 52 | export default function Stats({ data }: Props) { |
| 53 | const [type, setType] = useState<StatType>("dailyStats") |
| 54 | |
| 55 | const { chartData, keys } = useMemo(() => { |
| 56 | const times = data[0][type] |
| 57 | .map(t => formatDate(t.date)) |
| 58 | .sort((a, b) => new Date(a).getTime() - new Date(b).getTime()) |
| 59 | const launchpads = data.slice(0, 5) |
| 60 | const chartData = times.map(t => { |
| 61 | const item: Record<string, any> = { |
| 62 | date: t, |
| 63 | } |
| 64 | let total = 0 |
| 65 | launchpads.forEach(d => { |
| 66 | const stat = d[type].find(s => formatDate(s.date) === t) |
| 67 | total += stat?.marketShare || 0 |
| 68 | item[d.id] = stat?.marketShare |
| 69 | chartConfig[d.id] = { |
| 70 | label: d.launchpad, |
| 71 | } |
| 72 | }) |
| 73 | item.others = 100 - total |
| 74 | return item |
| 75 | }) |
| 76 | return { chartData, keys: launchpads.map(d => d.id).concat("others") } |
| 77 | }, [data, type]) |
| 78 | |
| 79 | function getVolume(launchpad: string, date: string) { |
| 80 | const d = data.find(d => d.id === launchpad) |
| 81 | const stat = d?.[type].find(s => formatDate(s.date) === date) |
| 82 | if (stat) { |
| 83 | return formatNumber(stat.volume) |
| 84 | } |
| 85 | return "-" |
| 86 | } |
| 87 | |
| 88 | return ( |
| 89 | <Card className="pt-0"> |
| 90 | <CardHeader className="flex items-center gap-2 space-y-0 border-b py-5 sm:flex-row"> |
| 91 | <div className="grid flex-1 gap-1"> |
| 92 | <CardTitle>Launchpad Stats</CardTitle> |
| 93 | <CardDescription> |
| 94 | Showing marketShare and volume for the last months |
| 95 | </CardDescription> |
| 96 | </div> |
| 97 | <Select value={type} onValueChange={val => setType(val as StatType)}> |
| 98 | <SelectTrigger |
| 99 | className="hidden w-[160px] rounded-lg sm:ml-auto sm:flex" |
| 100 | aria-label="Select a value" |
| 101 | > |
| 102 | <SelectValue placeholder="Last 3 months" /> |
| 103 | </SelectTrigger> |
| 104 | <SelectContent className="rounded-xl"> |
| 105 | <SelectItem value="dailyStats" className="rounded-lg"> |
| 106 | Total Volumn |
| 107 | </SelectItem> |
| 108 | <SelectItem value="newDailyStats" className="rounded-lg"> |
| 109 | New Volumn |
nothing calls this directly
no test coverage detected