Skip to content

Commit

Permalink
fix(connect): make the imports of the dynamic connect methods "static…
Browse files Browse the repository at this point in the history
…" without template variables in the paths
  • Loading branch information
vojtatranta committed Feb 26, 2025
1 parent aaf4ed6 commit c7f857b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions packages/connect/src/core/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@ import type { AbstractMethod } from './AbstractMethod';
const getMethodModule = (method: IFrameCallMessage['payload']['method']) =>
MODULES.find(module => method.startsWith(module));

const importMethodModule = async (methodModule: ReturnType<typeof getMethodModule>) => {
switch (methodModule) {
case 'binance':
return await import(/* webpackChunkName: "[request]" */ `../api/binance/api`);
case 'cardano':
return await import(/* webpackChunkName: "[request]" */ `../api/cardano/api`);
case 'eos':
return await import(/* webpackChunkName: "[request]" */ `../api/eos/api`);
case 'ethereum':
return await import(/* webpackChunkName: "[request]" */ `../api/ethereum/api`);
case 'nem':
return await import(/* webpackChunkName: "[request]" */ `../api/nem/api`);
case 'ripple':
return await import(/* webpackChunkName: "[request]" */ `../api/ripple/api`);
case 'solana':
return await import(/* webpackChunkName: "[request]" */ `../api/solana/api`);
case 'stellar':
return await import(/* webpackChunkName: "[request]" */ `../api/stellar/api`);
case 'tezos':
return await import(/* webpackChunkName: "[request]" */ `../api/tezos/api`);
default:
return Methods;
}
};

export const getMethod = async (message: IFrameCallMessage): Promise<AbstractMethod<any>> => {
const { method } = message.payload;
if (typeof method !== 'string') {
throw TypedError('Method_InvalidParameter', 'Message method is not set');
}

const methodModule = getMethodModule(method);
const methods = methodModule
? await import(
/* webpackChunkName: "[request]" */ /* @vite-ignore */ `../api/${methodModule}/api`
)
: Methods;
const methods = await importMethodModule(methodModule);

// @ts-expect-error: obviously, types won't work here properly
const MethodConstructor = methods[method];

if (MethodConstructor) {
Expand Down

0 comments on commit c7f857b

Please sign in to comment.