From db7205769a6ca358014faf3c39829e12f7d78756 Mon Sep 17 00:00:00 2001 From: brown Date: Mon, 16 Dec 2024 17:26:56 -0500 Subject: [PATCH 1/2] feat(hub): update loading times of tokens for swaps and pools --- .scripts/set-local-install.js | 16 +++ .scripts/vercel-local-install.sh | 5 + apps/hub/next.config.mjs | 3 + apps/hub/src/app/Providers.tsx | 35 +++-- apps/hub/src/app/layout.tsx | 13 +- package.json | 3 +- packages/berajs/src/actions/dex/getTokens.ts | 64 +-------- packages/berajs/src/hooks/useTokens.ts | 8 +- packages/berajs/src/types/dex.ts | 1 + packages/berajs/src/utils/formatTokenList.ts | 60 ++++++++ packages/berajs/src/utils/index.ts | 1 + packages/shared-ui/src/token-icon.tsx | 43 ++++-- packages/ui/package.json | 7 + packages/ui/src/custom-avatar.tsx | 144 +++++++++++++++++++ packages/ui/tsup.config.ts | 1 + 15 files changed, 319 insertions(+), 85 deletions(-) create mode 100644 .scripts/set-local-install.js create mode 100644 .scripts/vercel-local-install.sh create mode 100644 packages/berajs/src/utils/formatTokenList.ts create mode 100644 packages/ui/src/custom-avatar.tsx diff --git a/.scripts/set-local-install.js b/.scripts/set-local-install.js new file mode 100644 index 000000000..2ad93e82d --- /dev/null +++ b/.scripts/set-local-install.js @@ -0,0 +1,16 @@ +const { execSync } = require("child_process"); +const path = require("path"); + +try { + const scriptPath = path.resolve(__dirname, "vercel-local-install.sh"); + console.log("Running local installation script..."); + + execSync(`bash ${scriptPath}`, { + stdio: "inherit", + }); + + console.log("Local installation completed successfully"); +} catch (error) { + console.error("Error during local installation:", error.message); + process.exit(1); +} diff --git a/.scripts/vercel-local-install.sh b/.scripts/vercel-local-install.sh new file mode 100644 index 000000000..736093fd6 --- /dev/null +++ b/.scripts/vercel-local-install.sh @@ -0,0 +1,5 @@ +# if secrets folder exists, copy the static folder to the apps +if [ -d "secrets/static" ]; then + mkdir -p apps/hub/public/internal-env + cp -r secrets/static/* apps/hub/public/internal-env +fi \ No newline at end of file diff --git a/apps/hub/next.config.mjs b/apps/hub/next.config.mjs index 767aa5474..87bf03362 100755 --- a/apps/hub/next.config.mjs +++ b/apps/hub/next.config.mjs @@ -39,6 +39,9 @@ const config = { "res.cloudinary.com", "raw.githubusercontent.com", "s3.amazonaws.com", + "assets.coingecko.com", + "artio-static-asset-public.s3.ap-southeast-1.amazonaws.com", // clean this up with new links + // Add google cdn here as well ], }, }; diff --git a/apps/hub/src/app/Providers.tsx b/apps/hub/src/app/Providers.tsx index b8a4caa23..e7f7160da 100755 --- a/apps/hub/src/app/Providers.tsx +++ b/apps/hub/src/app/Providers.tsx @@ -1,14 +1,24 @@ "use client"; import React, { useEffect, type PropsWithChildren } from "react"; -import { BeraJsProvider, BlockTimeProvider } from "@bera/berajs"; +import { + BeraJsProvider, + BlockTimeProvider, + SWRFallback, + formatTokenList, +} from "@bera/berajs"; +import { chainId, tokenListUrl } from "@bera/config"; import { BeraWagmi } from "@bera/wagmi"; import posthog from "posthog-js"; import { PostHogProvider } from "posthog-js/react"; +import { unstable_serialize } from "swr"; import { ThemeProvider } from "~/components/theme-provider"; -export default function Providers({ children }: PropsWithChildren) { +export default function Providers({ + children, + content, +}: PropsWithChildren) { useEffect(() => { if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) { return; @@ -24,14 +34,21 @@ export default function Providers({ children }: PropsWithChildren) { - - {children} - + + {children} + + diff --git a/apps/hub/src/app/layout.tsx b/apps/hub/src/app/layout.tsx index 262f83adf..c8eb9e5e7 100755 --- a/apps/hub/src/app/layout.tsx +++ b/apps/hub/src/app/layout.tsx @@ -1,9 +1,11 @@ import "../styles/globals.css"; +import { readFileSync } from "fs"; +import path from "path"; import { Metadata } from "next"; import dynamic from "next/dynamic"; import { IBM_Plex_Sans } from "next/font/google"; import Script from "next/script"; -import { hubName, hubUrl } from "@bera/config"; +import { chainId, hubName, hubUrl, tokenListUrl } from "@bera/config"; import { Footer, Header, @@ -35,7 +37,12 @@ const PostHogPageView = dynamic(() => import("./PostHogPageView"), { ssr: false, }); -export default function RootLayout(props: { children: React.ReactNode }) { +export default async function RootLayout(props: { children: React.ReactNode }) { + const fileContent = readFileSync( + path.join(process.cwd(), `public/${tokenListUrl}`), + "utf8", + ); + const fetchedTokenList = JSON.parse(fileContent); return (