Skip to content

Commit 9a459d9

Browse files
committed
fetch gas sponsored chains from API instead of hardcoding
1 parent 39a5b5c commit 9a459d9

File tree

4 files changed

+55
-94
lines changed

4 files changed

+55
-94
lines changed

apps/dashboard/src/@/api/chain.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import "server-only";
2+
import { API_SERVER_URL, THIRDWEB_API_SECRET } from "../constants/env";
3+
4+
export async function getGasSponsoredChains() {
5+
if (!THIRDWEB_API_SECRET) {
6+
throw new Error("API_SERVER_SECRET is not set");
7+
}
8+
const res = await fetch(`${API_SERVER_URL}/v1/chains/gas-sponsored`, {
9+
headers: {
10+
"Content-Type": "application/json",
11+
"x-service-api-key": THIRDWEB_API_SECRET,
12+
},
13+
next: {
14+
revalidate: 15 * 60, //15 minutes
15+
},
16+
});
17+
18+
if (!res.ok) {
19+
console.error(
20+
"Failed to fetch gas sponsored chains",
21+
res.status,
22+
res.statusText,
23+
);
24+
res.body?.cancel();
25+
return [];
26+
}
27+
28+
try {
29+
return (await res.json()).data as number[];
30+
} catch (e) {
31+
console.error("Failed to parse gas sponsored chains", e);
32+
return [];
33+
}
34+
}

apps/dashboard/src/@/constants/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const DASHBOARD_THIRDWEB_CLIENT_ID =
44
export const DASHBOARD_THIRDWEB_SECRET_KEY =
55
process.env.DASHBOARD_SECRET_KEY || "";
66

7+
export const THIRDWEB_API_SECRET = process.env.API_SERVER_SECRET || "";
8+
79
export const IPFS_GATEWAY_URL =
810
(process.env.NEXT_PUBLIC_IPFS_GATEWAY_URL as string) ||
911
"https://{clientId}.ipfscdn.io/ipfs/{cid}/{path}";

apps/dashboard/src/app/(dashboard)/(chain)/utils.ts

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import zytronCTA from "./temp-assets/zytronCTA.jpg";
7474

7575
import { API_SERVER_URL } from "@/constants/env";
7676
import type { ChainMetadata } from "thirdweb/chains";
77+
import { getGasSponsoredChains } from "../../../@/api/chain";
7778
import type {
7879
ChainMetadataWithServices,
7980
ChainService,
@@ -133,7 +134,6 @@ export async function getChain(
133134
type ExtraChainMetadata = Partial<{
134135
headerImgUrl: string;
135136
about: string;
136-
gasSponsored: boolean;
137137
cta: ChainCTAProps;
138138
}>;
139139

@@ -167,34 +167,6 @@ const chainMetaRecord = {
167167
headerImgUrl: baseBanner.src,
168168
about:
169169
"Base is a secure, low-cost, builder-friendly Ethereum L2 built to bring the next billion users onchain.",
170-
gasSponsored: true,
171-
172-
cta: OP_CTA,
173-
},
174-
//celo Mainnet
175-
42220: {
176-
cta: OP_CTA,
177-
gasSponsored: true,
178-
},
179-
// optimism
180-
10: {
181-
cta: OP_CTA,
182-
gasSponsored: true,
183-
},
184-
// fraxtal
185-
252: {
186-
cta: OP_CTA,
187-
gasSponsored: true,
188-
},
189-
// zora
190-
7777777: {
191-
cta: OP_CTA,
192-
gasSponsored: true,
193-
},
194-
// mode
195-
34443: {
196-
cta: OP_CTA,
197-
gasSponsored: true,
198170
},
199171
// cyber
200172
7560: {
@@ -207,21 +179,13 @@ const chainMetaRecord = {
207179
buttonLink: "https://cyber.co/",
208180
buttonText: "Learn more",
209181
},
210-
gasSponsored: true,
211-
},
212-
// redstone
213-
690: {
214-
cta: OP_CTA,
215-
gasSponsored: true,
216182
},
183+
217184
// ancient8
218185
888888888: {
219186
about:
220187
"Ancient8 is building an ETH gaming Layer 2 built with OP Stack, offering a suite of Web3 gaming infrastructure tools that serve as the distribution and marketing channel for games globally. With Space3 Game Publishing Platform, Ancient8 Gaming Guild, Reneverse Web3 Ads engine, A8ID, and Gosu Network, Ancient8 is dedicated to onboard millions of gamers to Web3 gaming, while providing unparalleled support to game developers looking to reach more players. Ancient8’s products have helped 100+ Web3 games and 200K+ users better navigate Web3.\n\nAncient8 has raised $10M in total financing from leading investors including Pantera, Dragonfly, Hashed, Makers Fund, Mechanism, Coinbase, IOSG, Jump and Animoca.",
221-
// TODO: add CTA
222188
headerImgUrl: ancient8Banner.src,
223-
cta: OP_CTA,
224-
gasSponsored: true,
225189
},
226190
// mantle
227191
5000: {
@@ -233,7 +197,6 @@ const chainMetaRecord = {
233197
buttonText: "Learn More",
234198
buttonLink: "https://x.com/0xMantleDevs",
235199
},
236-
gasSponsored: true,
237200
},
238201
// Flare
239202
14: {
@@ -252,18 +215,12 @@ const chainMetaRecord = {
252215
buttonText: "Learn more",
253216
},
254217
},
255-
//Superseed
256-
5330: {
257-
cta: OP_CTA,
258-
gasSponsored: true,
259-
},
218+
260219
// Ink
261220
57073: {
262221
headerImgUrl: inkBanner.src,
263222
about:
264223
"Ink is an Ethereum OP Stack layer 2 blockchain designed to be the house of DeFi for the Superchain, a powerful base layer for deploying innovative DeFi protocols.",
265-
cta: OP_CTA,
266-
gasSponsored: true,
267224
},
268225
// vanar
269226
2040: {
@@ -341,11 +298,6 @@ const chainMetaRecord = {
341298
buttonText: "Learn more",
342299
},
343300
},
344-
//Arena Z Mainnet
345-
7897: {
346-
cta: OP_CTA,
347-
gasSponsored: true,
348-
},
349301
//Appchain
350302
466: {
351303
headerImgUrl: appChainBanner.src,
@@ -399,8 +351,6 @@ const chainMetaRecord = {
399351
headerImgUrl: thirdwebBanner.src,
400352
about:
401353
"Monetize your passion, your way. Discover the freedom to grow with our creator-focused platform.",
402-
cta: OP_CTA,
403-
gasSponsored: true,
404354
},
405355
//Etherlink Testnet
406356
128123: {
@@ -554,33 +504,12 @@ const chainMetaRecord = {
554504
headerImgUrl: liskBanner.src,
555505
about:
556506
"Lisk is focused on serving builders in high-growth markets like Africa and Southeast Asia. When you build on Lisk, you become part of the strongest Ethereum collective, alongside Coinbase, Sony, World, Kraken and Uniswap -- the OP Superchain.",
557-
// cta: {
558-
// backgroundImageUrl: liskCTA.src,
559-
// title: "Ready to reshape the world?",
560-
// buttonLink: "https://lisk.com",
561-
// buttonText: "Learn more",
562-
// },
563-
cta: OP_CTA,
564-
gasSponsored: true,
565507
},
566508
//Metal L2
567509
1750: {
568510
headerImgUrl: metalBanner.src,
569511
about:
570512
"Metal L2 is a banking-focused Layer 2 blockchain built on the Optimism Superchain, designed to enable direct on-chain fiat deposits through its connection to The Digital Banking Network—an open-source blockchain banking protocol developed by Metallicus",
571-
// cta: {
572-
// backgroundImageUrl: metalCTA.src,
573-
// title: "Connect to The Banking Layer, Metal L2",
574-
// buttonLink: "https://metall2.com/",
575-
// buttonText: "Connect Here",
576-
// },
577-
cta: OP_CTA,
578-
gasSponsored: true,
579-
},
580-
//Ozean Testnet
581-
7849306: {
582-
cta: OP_CTA,
583-
gasSponsored: true,
584513
},
585514
//0G-Newton-Testnet
586515
16600: {
@@ -678,11 +607,6 @@ const chainMetaRecord = {
678607
buttonText: "Learn More",
679608
},
680609
},
681-
//Unichain Sepolis Testnet
682-
1301: {
683-
cta: OP_CTA,
684-
gasSponsored: true,
685-
},
686610
//viction Mainnet
687611
88: {
688612
headerImgUrl: victionBanner.src,
@@ -714,14 +638,6 @@ const chainMetaRecord = {
714638
headerImgUrl: worldChainBanner.src,
715639
about:
716640
"World Chain is the blockchain for real humans, offering priority blockspace and gas-free transactions for World ID-verified users.",
717-
// cta: {
718-
// backgroundImageUrl: worldChainCTA.src,
719-
// title: "Build for real humans with World Chain",
720-
// buttonLink: "https://world.org/world-chain",
721-
// buttonText: "Learn More",
722-
// },
723-
cta: OP_CTA,
724-
gasSponsored: true,
725641
},
726642
//World Chain Testnet
727643
4801: {
@@ -848,14 +764,12 @@ const chainMetaRecord = {
848764
headerImgUrl: soneiumBanner.src,
849765
about:
850766
"Soneium, an Ethereum layer-2 developed by Sony Block Solutions Labs. This versatile chain is a general-purpose blockchain platform that aims to evoke emotion, empower creativity, and meet diverse needs to go mainstream. Soneium will be simplifying blockchain experiences while empowering developers, creators, and communities. Built on accessibility, scalability, and efficiency, it aims to solve real-world problems across industries globally. Soneium will change the way we interact with the internet, opening up a world of innovative applications and unlimited potential for users worldwide.",
851-
cta: OP_CTA,
852767
},
853768
//Soneium Mainnet
854769
1868: {
855770
headerImgUrl: soneiumBanner.src,
856771
about:
857772
"Soneium, an Ethereum layer-2 developed by Sony Block Solutions Labs. This versatile chain is a general-purpose blockchain platform that aims to evoke emotion, empower creativity, and meet diverse needs to go mainstream. Soneium will be simplifying blockchain experiences while empowering developers, creators, and communities. Built on accessibility, scalability, and efficiency, it aims to solve real-world problems across industries globally. Soneium will change the way we interact with the internet, opening up a world of innovative applications and unlimited potential for users worldwide.",
858-
cta: OP_CTA,
859773
},
860774
//Shido
861775
9008: {
@@ -874,10 +788,23 @@ const chainMetaRecord = {
874788

875789
export async function getChainMetadata(
876790
chainId: number,
877-
): Promise<ExtraChainMetadata | null> {
791+
): Promise<(ExtraChainMetadata & { gasSponsored?: true }) | null> {
792+
const gasSponsoredChains = await getGasSponsoredChains();
793+
794+
const isGasSponsored = gasSponsoredChains.includes(chainId);
795+
878796
// TODO: fetch this from the API
879797
if (chainId in chainMetaRecord) {
880-
return chainMetaRecord[chainId as keyof typeof chainMetaRecord];
798+
return {
799+
...(isGasSponsored ? { cta: OP_CTA, gasSponsored: true } : {}),
800+
// this will OVERRIDE the op CTA if there is a custom one configured
801+
...chainMetaRecord[chainId as keyof typeof chainMetaRecord],
802+
};
803+
} else if (isGasSponsored) {
804+
return {
805+
cta: OP_CTA,
806+
gasSponsored: true,
807+
};
881808
}
882809
return null;
883810
}

apps/dashboard/src/app/login/auth-actions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import "server-only";
33

44
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
5-
import { API_SERVER_URL } from "@/constants/env";
5+
import { API_SERVER_URL, THIRDWEB_API_SECRET } from "@/constants/env";
66
import { cookies } from "next/headers";
77
import { getAddress } from "thirdweb";
88
import type {
@@ -11,8 +11,6 @@ import type {
1111
VerifyLoginPayloadParams,
1212
} from "thirdweb/auth";
1313

14-
const THIRDWEB_API_SECRET = process.env.API_SERVER_SECRET || "";
15-
1614
export async function getLoginPayload(
1715
params: GenerateLoginPayloadParams,
1816
): Promise<LoginPayload> {

0 commit comments

Comments
 (0)