Skip to content

Commit

Permalink
/environment updates (#132)
Browse files Browse the repository at this point in the history
* Init environment page updates

* Add redirect back for now
  • Loading branch information
catalinred authored Dec 19, 2024
1 parent 6d9e201 commit d03a27b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 294 deletions.
Binary file not shown.
10 changes: 0 additions & 10 deletions assets/environment/logo.svg

This file was deleted.

37 changes: 0 additions & 37 deletions src/components/environment/EnvironmentEnergyUsage.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/components/environment/EnvironmentHero.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from "classnames";
import { useTranslation } from "next-i18next";
import styles from "./EnvironmentHero.module.scss";
import { Button } from "@solana-foundation/solana-lib";

export default function EnvironmentHero() {
const { t } = useTranslation();
Expand All @@ -23,6 +24,23 @@ export default function EnvironmentHero() {
>
{t("environment.hero.subtitle")}
</p>
<Button
url={"https://solanaclimate.com/"}
hierarchy={"outline"}
endIcon={"arrow-up-right"}
size={"lg"}
iconSize={"md"}
className="me-2 mb-2"
>
{t("environment.cta-data")}
</Button>
<Button
url="https://solana.com/news/announcing-real-time-emissions-measurement-on-the-solana-blockchain"
hierarchy={"outline"}
size={"lg"}
>
{t("environment.energy.cta")}
</Button>
</div>
</div>
</section>
Expand Down
12 changes: 0 additions & 12 deletions src/components/environment/EnvironmentReport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import classNames from "classnames";
import Image from "next/legacy/image";
import { useTranslation } from "next-i18next";
import FoundationLogo from "../../../assets/environment/logo.svg";
import styles from "./EnvironmentReport.module.scss";

export default function EnvironmentReport() {
Expand All @@ -21,16 +19,6 @@ export default function EnvironmentReport() {
styles["environment-report__main"],
)}
>
<div className="mb-5">
<Image
alt="Solana Foundation"
src={FoundationLogo}
width={188}
height={40}
loading="eager"
priority
/>
</div>
<h2 className="mb-5">{t("environment.report.title")}</h2>
<div
className={classNames(
Expand Down
142 changes: 0 additions & 142 deletions src/components/environment/EnvironmentStats.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/components/environment/EnvironmentStats.module.scss

This file was deleted.

55 changes: 1 addition & 54 deletions src/pages/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { useTranslation } from "next-i18next";
import HTMLHead from "../components/HTMLHead";
import Layout from "../components/layout";
import EnvironmentHero from "../components/environment/EnvironmentHero";
import EnvironmentStats from "../components/environment/EnvironmentStats";
import EnvironmentReport from "../components/environment/EnvironmentReport";
import EnvironmentWhatYouCanDo from "../components/environment/EnvironmentWhatYouCanDo";
import EnvironmentFeaturedProjects from "../components/environment/EnvironmentFeaturedProjects";
import EnvironmentEnergyUsage from "../components/environment/EnvironmentEnergyUsage";

const EnvironmentPage = ({ envData }) => {
const EnvironmentPage = () => {
const { t } = useTranslation();

return (
Expand All @@ -19,8 +17,6 @@ const EnvironmentPage = ({ envData }) => {
description={t("environment.description")}
/>
<EnvironmentHero />
<EnvironmentStats envData={envData} />
<EnvironmentEnergyUsage envData={envData} />
<EnvironmentReport />
<EnvironmentFeaturedProjects />
<EnvironmentWhatYouCanDo />
Expand All @@ -29,57 +25,8 @@ const EnvironmentPage = ({ envData }) => {
};

export async function getStaticProps({ locale }) {
// Math.trunc() and remove existing commas from the API response
const toTrunc = (s) => Math.trunc(s.replace(/,/g, ""));

const getEnvironmentData = async () => {
try {
const responses = await Promise.all([
fetch(
// Average energy used per Solana transaction, in Joules
"https://carbonara.metabaseapp.com/public/question/48d65369-6baf-4f3e-9fab-be198187a1a1.json",
),
fetch(
// Average energy used per Solana nonvoting transaction, in Joules
"https://carbonara.metabaseapp.com/public/question/d9faf5b6-f2ad-4e41-b5e0-32b881d6a9e3.json",
),
fetch(
// Annual carbon footprint, in tonnes CO2 equivalent (tCO2e)
"https://carbonara.metabaseapp.com/public/question/b4c1bed0-961d-4350-8859-e7ecb66a6ed3.json",
),
]);

const [data1, data2, data3] = [
await responses[0].json(),
await responses[1].json(),
await responses[2].json(),
];

return {
solTransaction: toTrunc(data1[0]["?column?"]),
solNonVotingTransaction: toTrunc(data2[0]["?column?"]),
annualCarbonFootprint: toTrunc(data3[0]["sum"]),
};
} catch (err) {
console.warn("Unable to fetch the environmental data from Carbonara");
console.warn(err);

// manually return some hardcoded values to prevent errors
// note: these values were last updated on Jan 30 2024
// and should likely be updated at some periodicity
return {
solTransaction: 636,
solNonVotingTransaction: 6674,
annualCarbonFootprint: 9160,
};
}
};

const envData = await getEnvironmentData();

return {
props: {
envData,
...(await serverSideTranslations(locale, ["common"])),
},
revalidate: 30,
Expand Down

0 comments on commit d03a27b

Please sign in to comment.