Skip to content

Commit

Permalink
Add OpenSats' lifetime statistics to /transparency page (#417)
Browse files Browse the repository at this point in the history
* 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
dergigi authored Mar 4, 2025
1 parent c68e4c0 commit 310a3d1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
51 changes: 51 additions & 0 deletions components/LifetimeStats.tsx
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
2 changes: 2 additions & 0 deletions components/MDXComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import DesignTeam from './DesignTeam'
import Credits from './Supporters'
import YouTubeEmbed from './YouTubeEmbed'
import Members from './Members'
import LifetimeStats from './LifetimeStats'

export const Wrapper = ({ layout, content, ...rest }: MDXLayout) => {
const Layout = require(`../layouts/${layout}`).default
Expand All @@ -40,4 +41,5 @@ export const MDXComponents: ComponentMap = {
YouTubeEmbed,
Credits,
Members,
LifetimeStats,
}
2 changes: 2 additions & 0 deletions data/pages/transparency.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ transparency, integrity, and legal compliance standards. As an organization that
is embedded in the free and open-source movement, we cherish the principles of
transparency, openness, as well as conversing and working in public.

<LifetimeStats/>

By adhering to these principles, we aim to demonstrate our commitment to
responsible bitcoin treasury management, good corporate citizenship, and the long-term
sustainability of our organization.
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"next-themes": "^0.2.0",
"pliny": "0.0.10",
"postcss": "^8.4.16",
"public-google-sheets-parser": "^1.5.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.43.9",
Expand Down

0 comments on commit 310a3d1

Please sign in to comment.