diff --git a/src/data/ethereumProvider.jsx b/src/data/ethereumProvider.jsx index 400ba47d..d9696188 100644 --- a/src/data/ethereumProvider.jsx +++ b/src/data/ethereumProvider.jsx @@ -27,7 +27,6 @@ export const networkMap = { const LONGPOLLING_PERIOD_MS = 20000; -const isSupportedChain = (chainId) => Object.keys(networkMap).includes(chainId); const initializeContract = (chainId) => new ethers.Contract(Object.keys(networkMap[chainId].deployments)[0], ABI); const getDefaultNetwork = () => { const defaultNetworkKeys = Object.keys(networkMap).filter((key) => networkMap[key].default); diff --git a/src/routes/account/index.jsx b/src/routes/account/index.jsx index de4239f1..67508f3d 100644 --- a/src/routes/account/index.jsx +++ b/src/routes/account/index.jsx @@ -3,28 +3,11 @@ import * as styles from "./index.module.scss"; import ListArticles from "/src/components/others/listArticles"; import { getArticlesByAuthor } from "/src/data/ethereumProvider"; -import { ipfsGateway } from "/src/utils/addToIPFS"; +import populateArticleContents from "../../utils/populateArticleContents"; export async function loader({ params }) { const articles = await getArticlesByAuthor(params.chain, params.id); - const fetchPromises = articles.map(async (article) => { - if (!article) return null; - try { - const response = await fetch(ipfsGateway + article?.articleID); - if (!response.ok) { - throw new Error("Network response was not OK"); - } - const { title, description } = await response.json(); - article.title = title; - article.description = description; - } catch (error) { - console.error(error); - throw new Error(error.message); - } - }); - - await Promise.all(fetchPromises); - return articles; + return await populateArticleContents(articles); } export default function Account() { diff --git a/src/routes/browse/index.jsx b/src/routes/browse/index.jsx index 94977358..ca1102c2 100644 --- a/src/routes/browse/index.jsx +++ b/src/routes/browse/index.jsx @@ -7,28 +7,11 @@ import ListArticles from "/src/components/others/listArticles"; import SyncStatus from "/src/components/presentational/syncStatus"; import { EthereumContext, networkMap, getAllArticles } from "/src/data/ethereumProvider"; -import { ipfsGateway } from "/src/utils/addToIPFS"; +import populateArticleContents from "../../utils/populateArticleContents"; export async function loader({ params }) { const articles = await getAllArticles(params.chain); - const fetchPromises = articles.map(async (article) => { - if (!article) return null; - try { - const response = await fetch(ipfsGateway + article?.articleID); - if (!response.ok) { - throw new Error("Network response was not OK"); - } - const { title, description } = await response.json(); - article.title = title; - article.description = description; - } catch (error) { - console.error(error); - throw new Error(error.message); - } - }); - - await Promise.all(fetchPromises); - return articles; + return await populateArticleContents(articles); } export default function Browse() { diff --git a/src/utils/populateArticleContents.js b/src/utils/populateArticleContents.js new file mode 100644 index 00000000..beb5ee6a --- /dev/null +++ b/src/utils/populateArticleContents.js @@ -0,0 +1,22 @@ +import { ipfsGateway } from "/src/utils/addToIPFS"; + +export default async function populateArticleContents(articles) { + const fetchPromises = articles.map(async (article) => { + if (!article) return null; + try { + const response = await fetch(ipfsGateway + article?.articleID); + if (!response.ok) { + throw new Error("Network response was not OK"); + } + const { title, description } = await response.json(); + article.title = title; + article.description = description; + } catch (error) { + console.error(error); + throw new Error(error.message); + } + }); + + await Promise.all(fetchPromises); + return articles; +} \ No newline at end of file