Skip to content

Commit

Permalink
feat: /sns page rework
Browse files Browse the repository at this point in the history
  • Loading branch information
olaszakos committed Jan 16, 2024
1 parent e856ef4 commit a73b242
Show file tree
Hide file tree
Showing 32 changed files with 832 additions and 543 deletions.
2 changes: 2 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
const fs = require("fs");
const validateShowcasePlugin = require("./plugins/validate-showcase.js");
const contentfulPlugin = require("./plugins/contentful");
const snsDataPlugin = require("./plugins/sns-data");

const isDeployPreview = !!process.env.PREVIEW_CANISTER_ID;

Expand Down Expand Up @@ -494,6 +495,7 @@ const config = {
matomoPlugin,
blogPostsPlugin,
contentfulPlugin,
snsDataPlugin,
validateShowcasePlugin,
externalRedirectsPlugin({
redirects: [...getExternalRedirects(), ...getExactUrlRedirects()],
Expand Down
180 changes: 99 additions & 81 deletions plugins/data/contentful-mock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,104 @@
{
"press": [
{
"id": "5IhITSSs3EKCXC8DO4cArn",
"title": "Web3 Gamer: 1 trillion Notcoins farmed, Neopets meets ICP, Trickshot Blitz is awesome",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "Cointelegraph Magazine",
"url": "https://cointelegraph.com/magazine/web3-gamer-notcoin-neopets-icp-trickshot-blitz/",
"tags": [
"Press Coverage"
]
},
{
"id": "2d4bgyO0Pz9TcyIOFcPyDm",
"title": "Bitfinity Network Raises $7M for Bitcoin Integration with Internet Computer",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "alexablockchain.com",
"url": "https://alexablockchain.com/bitfinity-network-raises-7m-funding/",
"tags": [
"Press Coverage"
]
},
{
"id": "1w86h8amwTE7xLo8fBPk4O",
"title": "Bitfinity to create a Bitcoin sidechain solution on Internet Computer",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "invezz.com",
"url": "https://invezz.com/news/2024/01/11/bitfinity-to-create-a-bitcoin-sidechain-solution-on-internet-computer/",
"tags": [
"Press Coverage"
]
},
{
"id": "5RaJh55xqPGFWxZHEIhFKG",
"title": "Bitfinity Secures $7M for Bitcoin Sidechain Solution On Internet Computer",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "nftgators.com",
"url": "https://www.nftgators.com/bitfinity-secures-7m-for-bitcoin-sidechain-solution-on-internet-computer/",
"tags": [
"Press Coverage"
]
},
{
"id": "57AvMm2F4VfbYbxhzPkOQ1",
"title": "Bitfinity Network Raises $7M for Bitcoin Sidechain Development on Internet Computer",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "Metaverse Post",
"url": "https://mpost.io/bitfinity-network-raises-7m-for-bitcoin-sidechain-development-on-internet-computer",
"tags": [
"Press Coverage"
]
},
{
"id": "1qwxc3XOKb8dKibOGrfMjD",
"title": "Bitfinity raises $7M to advance Bitcoin and Ordinal assets' on-chain security",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "tech.eu",
"url": "https://tech.eu/2024/01/11/bitfinity-raises-7m-to-advance-bitcoin-and-ordinal-assets-on-chain-security/",
"tags": [
"Press Coverage"
]
},
{
"id": "1uIFJXPfhhnn0jWfKjTE5U",
"title": "Bitfinity Aims to Enhance Bitcoin Ordinals With An Ethereum Virtual Machine On ICP",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "Decrypt",
"url": "https://decrypt.co/212411/bitfinity-aims-to-enhance-bitcoin-ordinals-with-ethereum-virtual-machine-integration-on-icp",
"tags": [
"Press Coverage"
]
},
{
"id": "21Ng4kpYLvlzG9X8TOslZM",
"title": "Bitcoin Layer 2 Bitfinity raises token round at $130 million valuation",
"date": "2024-01-11",
"dateHuman": "Jan 11, 2024",
"press": "TheBlock",
"url": "https://www.theblock.co/post/271885/bitcoin-l2-bitfinity-token-round",
"tags": [
"Press Coverage"
]
},
{
"id": "2X2KHhHxGAhL0I754oMcXt",
"title": "DFINITY’s Dominic Williams Says Enterprises Will Be Key for ICP's Growth",
"date": "2024-01-10",
"dateHuman": "Jan 10, 2024",
"press": "The Defiant",
"url": "https://thedefiant.io/dfinity-s-dominic-williams-says-enterprises-will-be-key-for-icp-s-growth",
"tags": [
"Press Coverage"
]
},
{
"id": "6YR7IJMlAPLn8zpY8LhV7U",
"title": "A game-changing subnet launches on the Internet Computer to help devs build GDPR-compliant dApps",
Expand Down Expand Up @@ -989,51 +1088,6 @@
"url": "https://coincodex.com/article/14198/layer-1-performance-comparing-6-leading-blockchains/",
"tags": []
},
{
"id": "1FYird2MBPJzsJnpW8GYOq",
"title": "DAOs could revolutionize how startups are run",
"date": "2022-04-01",
"dateHuman": "Apr 1, 2022",
"press": "VentureBeat",
"url": "https://venturebeat.com/2022/04/02/daos-could-revolutionize-how-startups-are-run/",
"tags": []
},
{
"id": "fqKWEbKY6CMCSXCenWxNk",
"title": "XR Foundation: Building a cross-chain gaming engine on Web3",
"date": "2022-04-01",
"dateHuman": "Apr 1, 2022",
"press": "AMB Crypto",
"url": "https://ambcrypto.com/xr-foundation-building-a-cross-chain-gaming-engine-on-web3/",
"tags": []
},
{
"id": "5L3g5EtBedis4Yiw3S9MEr",
"title": "The Internet Computer: We Have Restarted the Internet. Here’s Why.",
"date": "2022-04-01",
"dateHuman": "Apr 1, 2022",
"press": "BeIn Crypto",
"url": "https://beincrypto.com/the-internet-computer-we-have-restarted-the-internet-heres-why/",
"tags": []
},
{
"id": "7i6PSaeOMjETDJb1OH3VAR",
"title": "ICP Crypto: Can Embracing NFTs Help Internet Computer Climb to the Top?",
"date": "2022-04-01",
"dateHuman": "Apr 1, 2022",
"press": "Investor Place",
"url": "https://investorplace.com/2022/04/icp-crypto-can-embracing-nfts-help-internet-computer-climb-to-the-top/",
"tags": []
},
{
"id": "7xlZyqlTpdNGqN8e4pynDX",
"title": "Better Blockchain Interoperability will Attract Users, Developers, Traders",
"date": "2022-04-01",
"dateHuman": "Apr 1, 2022",
"press": "BeIn Crypto",
"url": "https://beincrypto.com/better-blockchain-interoperability-will-attract-users-developers-traders/",
"tags": []
},
{
"id": "2NeQ6WoPH3A9NqDJ0Z7kGD",
"title": "Bridgeless Crypto: Promise of Direct Blockchain Integrations",
Expand All @@ -1042,42 +1096,6 @@
"press": "Coinspeaker",
"url": "https://www.coinspeaker.com/bridgeless-crypto-blockchain-integrations/",
"tags": []
},
{
"id": "2wW3A8XBrasUgQhvWR7Vx7",
"title": "Internet Computer (ICP) A General-Purpose Blockchain for Building Applications.",
"date": "2022-03-01",
"dateHuman": "Mar 1, 2022",
"press": "Binance Research",
"url": "https://research.binance.com/en/projects/dfinity",
"tags": []
},
{
"id": "66Thhqowm8fiNJO30UUcKx",
"title": "SocialFi: Social DApps Meet Bitcoin and Crypto",
"date": "2022-03-01",
"dateHuman": "Mar 1, 2022",
"press": "CoinPedia",
"url": "https://coinpedia.org/news/socialfi-social-dapps-meet-bitcoin-and-crypto/",
"tags": []
},
{
"id": "6CCQTSIZeuMhkEXa3YDuOd",
"title": "OpenChat Instant Messaging Allows Crypto Transfers",
"date": "2022-03-01",
"dateHuman": "Mar 1, 2022",
"press": "Tech Times",
"url": "https://www.techtimes.com/articles/273458/20220324/openchat-instant-messaging-allows-crypto-transfers.htm",
"tags": []
},
{
"id": "78XyGsAdOaGCAfcyW4uRZd",
"title": "Unusual $250 million scheme by the founder of Internet Computer to help Ukraine",
"date": "2022-03-01",
"dateHuman": "Mar 1, 2022",
"press": "The Coin Republic",
"url": "https://www.thecoinrepublic.com/2022/03/19/unusual-250-million-scheme-by-the-founder-of-internet-computer-to-help-ukraine/",
"tags": []
}
]
}
114 changes: 114 additions & 0 deletions plugins/sns-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const fetch = require("node-fetch-retry");
const logger = require("@docusaurus/logger");
const chunkedParallel = require("./utils/chunked-parallel");

function fetchAggregatorPage(page) {
return fetch(
`https://3r4gx-wqaaa-aaaaq-aaaia-cai.icp0.io/v1/sns/list/page/${page}/slow.json`
).then((res) => res.json());
}

/**
* Fetches all aggregator pages and returns a list of all dao data
* @returns {Promise<Array>}
*/
async function fetchAllAggregatorPages() {
const allDaos = [];
let page = 0;
while (true) {
try {
const pageData = await fetchAggregatorPage(page);
allDaos.push(...pageData);
if (pageData.length < 10) {
// reached end
break;
}
page++;
} catch {
// reached page which doesn't exist
break;
}
}
return allDaos;
}

/**
* Gets the number of proposals for a given SNS
* @param {string} root_canister_id
* @returns {Promise<number>}
*/
function getProposalCount(root_canister_id) {
return fetch(
`https://sns-api.internetcomputer.org/api/v1/snses/${root_canister_id}/proposals?limit=0`
)
.then((res) => res.json())
.then((res) => res.max_proposal_index);
}

function getBuyersFromSwapMetrics(swap_canister_id) {
return fetch(`https://${swap_canister_id}.raw.icp0.io/metrics`)
.then((res) => res.text())
.then((res) => +res.match(/sale_buyer_count (\d+)/)[1]);
}

/** @type {import('@docusaurus/types').PluginModule} */
const snsDataPlugin = async function (context, options) {
return {
name: "sns-data",
async loadContent() {
// get all sns daos from aggregator
const snsList = await fetchAllAggregatorPages();

// keep only launched daos
const completedDaos = snsList.filter(
(dao) => dao.lifecycle.lifecycle === 3
);

logger.info(
`Loaded ${snsList.length} daos from the aggregator, out of which ${completedDaos.length} are launched.`
);

const websiteDaoData = completedDaos.map((dao) => ({
name: dao.meta.name,
description: dao.meta.description,
url: dao.meta.url,
logo: dao.meta.logo,
rootCanisterId: dao.canister_ids.root_canister_id,
swapCanisterId: dao.canister_ids.swap_canister_id,
icpRaised: Math.floor(dao.derived_state.buyer_total_icp_e8s / 1e8),
participants: dao.derived_state.direct_participant_count,
proposalCount: 0,
}));

// some DAO's have missing sale participants, get those from swap canister metrics
const missingBuyersPromises = websiteDaoData
.filter((dao) => dao.participants === null)
.map(
(dao) => () =>
getBuyersFromSwapMetrics(dao.swapCanisterId).then(
(buyers) => (dao.participants = buyers)
)
);
await chunkedParallel(missingBuyersPromises, 5);

// get proposal count for all daos
const proposalFillPromises = websiteDaoData.map(
(dao) => () =>
getProposalCount(dao.rootCanisterId).then(
(count) => (dao.proposalCount = count)
)
);
await chunkedParallel(proposalFillPromises, 5);

return websiteDaoData;
},
async contentLoaded({ content, actions }) {
const { createData } = actions;
createData("sns-data.json", JSON.stringify(content, null, 2));
},
};
};

module.exports = snsDataPlugin;

// snsDataPlugin().then((r) => r.loadContent());
17 changes: 14 additions & 3 deletions src/components/Common/AnimateSpawn/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useSpawnAnimation } from "@site/src/utils/use-spawn-animation";
import { ForwardRefComponent, motion, Variants } from "framer-motion";
import React from "react";
import React, { useEffect } from "react";

type Props<A, B> = {
el?: ForwardRefComponent<A, B>;
children?: React.ReactNode;
variants: Variants;
className?: string;
id?: string;

onShow?: () => void;
threshold?: number;
// todo: fix this hack
src?: string;
alt?: string;
Expand All @@ -19,10 +20,20 @@ function AnimateSpawn<A, B>({
children,
variants,
className,
onShow,
id,
threshold = 0,
...rest
}: Props<A, B>) {
const { controls, ref } = useSpawnAnimation();
const { controls, ref, inView } = useSpawnAnimation({ threshold });
const [started, setStarted] = React.useState(false);

useEffect(() => {
if (inView && !started) {
setStarted(true);
onShow?.();
}
}, [inView]);

const El = el as any; // todo: fix this hack

Expand Down
Loading

0 comments on commit a73b242

Please sign in to comment.