Skip to content

Commit cd01e2c

Browse files
lint
1 parent 5c35be4 commit cd01e2c

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

packages/thirdweb/src/bridge/Routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
131131
sortBy,
132132
limit,
133133
offset,
134-
includePrices,
134+
includePrices,
135135
chainIds,
136136
} = options;
137137

packages/thirdweb/src/chains/utils.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const CUSTOM_CHAIN_MAP = new Map<number, Chain>();
4040
* @chain
4141
*/
4242
export function defineChain(
43-
options: number | ChainOptions | ViemChain | LegacyChain
43+
options: number | ChainOptions | ViemChain | LegacyChain,
4444
): Chain {
4545
const RPC_URL = getThirdwebDomains().rpc;
4646
if (typeof options === "number") {
@@ -97,7 +97,7 @@ export function getCachedChainIfExists(id: number) {
9797
}
9898

9999
function isLegacyChain(
100-
chain: ChainOptions | ViemChain | LegacyChain
100+
chain: ChainOptions | ViemChain | LegacyChain,
101101
): chain is LegacyChain {
102102
return "rpc" in chain && Array.isArray(chain.rpc) && "slug" in chain;
103103
}
@@ -128,7 +128,7 @@ export function convertLegacyChain(legacyChain: LegacyChain): Chain {
128128
}
129129

130130
function isViemChain(
131-
chain: ChainOptions | ViemChain | LegacyChain
131+
chain: ChainOptions | ViemChain | LegacyChain,
132132
): chain is ViemChain {
133133
return "rpcUrls" in chain && !("rpc" in chain);
134134
}
@@ -192,7 +192,7 @@ export function getRpcUrlForChain(options: GetRpcUrlForChainOptions): string {
192192
// add on the client ID to the RPC URL if it's a thirdweb URL
193193
if (isThirdwebUrl(rpc)) {
194194
const rpcUrl = new URL(
195-
options.chain.rpc.replace(DEFAULT_RPC_URL, baseRpcUrl)
195+
options.chain.rpc.replace(DEFAULT_RPC_URL, baseRpcUrl),
196196
);
197197
if (rpcUrl.pathname === "/" || rpcUrl.pathname.startsWith("/$")) {
198198
rpcUrl.pathname = `/${options.client.clientId}`;
@@ -250,7 +250,7 @@ export async function getChainDecimals(chain: Chain): Promise<number> {
250250
* @internal
251251
*/
252252
export async function getChainNativeCurrencyName(
253-
chain: Chain
253+
chain: Chain,
254254
): Promise<string> {
255255
if (!chain.nativeCurrency?.name) {
256256
return getChainMetadata(chain)
@@ -293,11 +293,11 @@ export function getChainMetadata(chain: Chain): Promise<ChainMetadata> {
293293
async () => {
294294
try {
295295
const res = await fetch(
296-
`https://api.thirdweb.com/v1/chains/${chainId}`
296+
`https://api.thirdweb.com/v1/chains/${chainId}`,
297297
);
298298
if (!res.ok) {
299299
throw new Error(
300-
`Failed to fetch chain data for chainId ${chainId}. ${res.status} ${res.statusText}`
300+
`Failed to fetch chain data for chainId ${chainId}. ${res.status} ${res.statusText}`,
301301
);
302302
}
303303

@@ -319,7 +319,7 @@ export function getChainMetadata(chain: Chain): Promise<ChainMetadata> {
319319
{
320320
cacheKey: `chain:${chainId}`,
321321
cacheTime: 5 * 60 * 1000, // 5 minutes
322-
}
322+
},
323323
);
324324
}
325325

@@ -354,11 +354,11 @@ export function getChainServices(chain: Chain): Promise<ChainService[]> {
354354
async () => {
355355
try {
356356
const res = await fetch(
357-
`https://api.thirdweb.com/v1/chains/${chainId}/services`
357+
`https://api.thirdweb.com/v1/chains/${chainId}/services`,
358358
);
359359
if (!res.ok) {
360360
throw new Error(
361-
`Failed to fetch services for chainId ${chainId}. ${res.status} ${res.statusText}`
361+
`Failed to fetch services for chainId ${chainId}. ${res.status} ${res.statusText}`,
362362
);
363363
}
364364

@@ -380,19 +380,19 @@ export function getChainServices(chain: Chain): Promise<ChainService[]> {
380380
{
381381
cacheKey: `chain:${chainId}:services`,
382382
cacheTime: 24 * 60 * 60 * 1000, // 1 day
383-
}
383+
},
384384
);
385385
}
386386

387387
export async function getInsightEnabledChainIds(): Promise<number[]> {
388388
return withCache(
389389
async () => {
390390
const res = await fetch(
391-
`https://api.thirdweb.com/v1/chains/services?service=insight`
391+
`https://api.thirdweb.com/v1/chains/services?service=insight`,
392392
);
393393
if (!res.ok) {
394394
throw new Error(
395-
`Failed to fetch services. ${res.status} ${res.statusText}`
395+
`Failed to fetch services. ${res.status} ${res.statusText}`,
396396
);
397397
}
398398
const response = (await res.json()) as { data: Record<number, boolean> };
@@ -401,7 +401,7 @@ export async function getInsightEnabledChainIds(): Promise<number[]> {
401401
{
402402
cacheKey: `chain:insight-enabled`,
403403
cacheTime: 24 * 60 * 60 * 1000, // 1 day
404-
}
404+
},
405405
);
406406
}
407407

@@ -430,7 +430,7 @@ export function convertApiChainToChain(apiChain: ChainMetadata): Chain {
430430

431431
function createChainMetadata(
432432
chain: Chain,
433-
data?: ChainMetadata
433+
data?: ChainMetadata,
434434
): ChainMetadata {
435435
const nativeCurrency = chain.nativeCurrency
436436
? {

packages/thirdweb/src/insight/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Chain } from "../chains/types.js";
22
import { getInsightEnabledChainIds } from "../chains/utils.js";
33

44
export async function assertInsightEnabled(chains: Chain[]) {
5-
const chainIds = await getInsightEnabledChainIds();
5+
const chainIds = await getInsightEnabledChainIds();
66
const insightEnabled = chains.every((c) => chainIds.includes(c.id));
77

88
if (!insightEnabled) {

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { useQuery } from "@tanstack/react-query";
22
import { chains } from "../../../bridge/Chains.js";
33
import { routes } from "../../../bridge/Routes.js";
44
import type { Token } from "../../../bridge/types/Token.js";
5-
import { getCachedChain, getInsightEnabledChainIds } from "../../../chains/utils.js";
5+
import {
6+
getCachedChain,
7+
getInsightEnabledChainIds,
8+
} from "../../../chains/utils.js";
69
import type { ThirdwebClient } from "../../../client/client.js";
710
import { getOwnedTokens } from "../../../insight/get-tokens.js";
811
import { toTokens } from "../../../utils/units.js";
@@ -58,10 +61,15 @@ export function usePaymentMethods(options: {
5861
}
5962

6063
// 1. Get all supported chains
61-
const [allChains, insightEnabledChainIds] = await Promise.all([chains({ client }), getInsightEnabledChainIds()]);
64+
const [allChains, insightEnabledChainIds] = await Promise.all([
65+
chains({ client }),
66+
getInsightEnabledChainIds(),
67+
]);
6268

6369
// 2. Check insight availability for all chains
64-
const insightEnabledChains = allChains.filter((c) => insightEnabledChainIds.includes(c.chainId));
70+
const insightEnabledChains = allChains.filter((c) =>
71+
insightEnabledChainIds.includes(c.chainId),
72+
);
6573

6674
// 3. Get all owned tokens for insight-enabled chains
6775
let allOwnedTokens: Array<{
@@ -120,36 +128,21 @@ export function usePaymentMethods(options: {
120128
allValidOriginTokens.set(tokenKey, destinationToken);
121129
}
122130

123-
// const routesForChain = await routes({
124-
// client,
125-
// destinationChainId: destinationToken.chainId,
126-
// destinationTokenAddress: destinationToken.address,
127-
// includePrices: true,
128-
// limit: 1000,
129-
// maxSteps: 3,
130-
// sortBy: "popularity",
131-
// chainIds: chainsWithOwnedTokens,
132-
// });
133-
134-
// for (const route of routesForChain) {
135-
// const tokenKey = `${route.originToken.chainId}-${route.originToken.address.toLowerCase()}`;
136-
// allValidOriginTokens.set(tokenKey, route.originToken);
137-
// }
138-
139131
// Fetch routes for each chain with owned tokens
140132
await Promise.all(
141133
chainsWithOwnedTokens.map(async (chainId) => {
142134
try {
135+
// TODO (bridge): this is quite inefficient, need to fix the popularity sorting to really capture all users tokens
143136
const routesForChain = await routes({
137+
chainIds: chainsWithOwnedTokens,
144138
client,
145139
destinationChainId: destinationToken.chainId,
146140
destinationTokenAddress: destinationToken.address,
147-
originChainId: chainId,
148141
includePrices: true,
149142
limit: 100,
150143
maxSteps: 3,
144+
originChainId: chainId,
151145
sortBy: "popularity",
152-
chainIds: chainsWithOwnedTokens,
153146
});
154147

155148
// Add all origin tokens from this chain's routes

0 commit comments

Comments
 (0)