-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenSats' lifetime statistics to /transparency page (#417)
* npm i public-google-sheets-parser * Create LifetimeStats.tsx * Add to MDXComponents * Render in /transparency * Extract label & value ...and do an ugly design * `formatNumber` * Prettier widget design (basically copied from Jason's PR) * Add `$` sign & move ~
- Loading branch information
Showing
5 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import PublicGoogleSheetsParser from 'public-google-sheets-parser' | ||
|
||
export function formatNumber(num: number): string { | ||
const abbreviations = ['k', 'M', 'B', 'T'] | ||
let i = 0 | ||
while (num > 1e3 && i < abbreviations.length) { | ||
num /= 1e3 | ||
if (num < 1e3) { | ||
return `${num.toFixed(1)} ${abbreviations[i]}` | ||
} | ||
i += 1 | ||
} | ||
return num.toString() | ||
} | ||
|
||
const LifetimeStats = () => { | ||
const [items, setItems] = useState([]) | ||
|
||
useEffect(() => { | ||
const parser = new PublicGoogleSheetsParser( | ||
'1mLEbHcrJibLN2PKxYq1LHJssq0CGuJRRoaZwot-ncZQ' | ||
) | ||
parser.parse().then((data) => { | ||
setItems(data) | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<div className="py-4"> | ||
<div className="mx-auto"> | ||
<dl className="grid grid-cols-1 gap-x-2 gap-y-4 md:grid-cols-3"> | ||
{items.map((item, index) => ( | ||
<div key={index} className="mx-auto grid grid-cols-1"> | ||
<dt className="text-center text-base/7 text-gray-600 dark:text-gray-300"> | ||
{item.label} | ||
</dt> | ||
<dt className="order-first text-center text-4xl font-semibold tracking-tight text-orange-600"> | ||
{index == 1 ? '$ ' : ''} | ||
{index == 2 ? '~' : ''} | ||
{formatNumber(item.value)} | ||
</dt> | ||
</div> | ||
))} | ||
</dl> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default LifetimeStats |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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