Skip to content

Commit

Permalink
Support empty warp route whitelists (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy authored Jun 13, 2024
1 parent 2528086 commit 25a5158
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/consts/warpRouteWhitelist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// A list of warp route config IDs to be included in the app
// Warp Route IDs use format `SYMBOL/chainname1-chainname2...` where chains are ordered alphabetically
// If left empty, all warp routes in the configured registry will be included
export const warpRouteWhitelist: Array<string> | undefined = [
// Example:
// 'ETH/ethereum-viction'
];
// If left null, all warp routes in the configured registry will be included
// If set to a list (including an empty list), only the specified routes will be included
export const warpRouteWhitelist: Array<string> | null = null;
// Example:
// [
// // 'ETH/ethereum-viction'
// ];
13 changes: 8 additions & 5 deletions src/context/WarpContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { initWarpContext } from './context';
export function WarpContext({ children }: PropsWithChildren<unknown>) {
const {
data: warpContext,
isError,
error,
isLoading,
} = useQuery({
queryKey: ['warpContext'],
Expand All @@ -20,11 +20,14 @@ export function WarpContext({ children }: PropsWithChildren<unknown>) {
refetchOnReconnect: false,
});

if (isError)
if (error) {
// Fallback to outer error boundary
throw new Error(
'Failed to initialize warp context. Please check your registry URL and connection status.',
);
const message =
error instanceof Error
? error.message
: 'Please check your registry URL and connection status.';
throw new Error(`Failed to initialize warp context. ${message}`);
}

if (isLoading || !warpContext)
return (
Expand Down
7 changes: 6 additions & 1 deletion src/context/warpCoreConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function assembleWarpCoreConfig(): WarpCoreConfig {
const resultTs = WarpCoreConfigSchema.safeParse(WarpRoutesTs);
const configTs = validateZodResult(resultTs, 'warp core typescript config');

const filteredWarpRouteConfigs = warpRouteWhitelist?.length
const filteredWarpRouteConfigs = warpRouteWhitelist
? filterToIds(warpRouteConfigs, warpRouteWhitelist)
: warpRouteConfigs;

Expand All @@ -22,6 +22,11 @@ export function assembleWarpCoreConfig(): WarpCoreConfig {
const configTokens = configValues.map((c) => c.tokens).flat();
const tokens = dedupeTokens([...configTokens, ...configTs.tokens, ...configYaml.tokens]);

if (!tokens.length)
throw new Error(
'No warp route configs provided. Please check your registry, warp route whitelist, and custom route configs for issues.',
);

const configOptions = configValues.map((c) => c.options).flat();
const combinedOptions = [...configOptions, configTs.options, configYaml.options];
const options = combinedOptions.reduce<WarpCoreConfig['options']>((acc, o) => {
Expand Down

0 comments on commit 25a5158

Please sign in to comment.