Skip to content

Commit

Permalink
error refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jul 3, 2024
1 parent dbfeb2b commit 5978975
Show file tree
Hide file tree
Showing 35 changed files with 302 additions and 416 deletions.
203 changes: 100 additions & 103 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@
"husky": "^9.0.11",
"lerna": "^8.1.5",
"lint-staged": "^15.2.7",
"mocha": "^10.5.1",
"mocha": "^10.6.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tslib": "^2.6.3",
"typescript": "^5.5.2"
"typescript": "^5.5.3"
},
"optionalDependencies": {
"@nx/nx-linux-x64-gnu": "^19.3.1",
"@nx/nx-linux-x64-gnu": "^19.4.0",
"@rollup/rollup-linux-x64-gnu": "^4.18.0"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/base-evm-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"pre-commit": "lint-staged --cwd ."
},
"dependencies": {
"@toruslabs/base-controllers": "^5.9.0",
"@toruslabs/base-controllers": "^5.9.2",
"@web3auth/base": "^8.7.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/base-solana-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"pre-commit": "lint-staged --cwd ."
},
"dependencies": {
"@toruslabs/base-controllers": "^5.9.0",
"@toruslabs/base-controllers": "^5.9.2",
"@web3auth/base": "^8.7.0",
"bs58": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/coinbase-adapter/src/coinbaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CoinbaseAdapter extends BaseEvmAdapter<void> {
this.rehydrated = false;
this.emit(ADAPTER_EVENTS.ERRORED, error);
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError("Failed to login with coinbase wallet");
throw WalletLoginError.connectionError("Failed to login with coinbase wallet", error);
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/adapters/default-evm-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base";
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions, WalletInitializationError } from "@web3auth/base";

export const getDefaultExternalAdapters = async (params: { options: IWeb3AuthCoreOptions }): Promise<IAdapter<unknown>[]> => {
const { options } = params;
const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options;
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) throw new Error(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace))
throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
const finalChainConfig = {
...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig),
...(chainConfig || {}),
Expand Down
5 changes: 3 additions & 2 deletions packages/adapters/default-solana-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base";
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions, WalletInitializationError } from "@web3auth/base";

export const getDefaultExternalAdapters = async (params: { options: IWeb3AuthCoreOptions }): Promise<IAdapter<unknown>[]> => {
const { options } = params;
const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options;
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) throw new Error(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace))
throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
const finalChainConfig = {
...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig),
...(chainConfig || {}),
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/metamask-adapter/src/metamaskAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class MetamaskAdapter extends BaseEvmAdapter<void> {
this.rehydrated = false;
this.emit(ADAPTER_EVENTS.ERRORED, error);
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError("Failed to login with metamask wallet");
throw WalletLoginError.connectionError("Failed to login with metamask wallet", error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/openlogin-adapter/src/openloginAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class OpenloginAdapter extends BaseAdapter<OpenloginLoginParams> {
} else if (error instanceof Web3AuthError) {
throw error;
}
throw WalletLoginError.connectionError("Failed to login with openlogin");
throw WalletLoginError.connectionError("Failed to login with openlogin", error);
}
}

Expand All @@ -153,7 +153,7 @@ export class OpenloginAdapter extends BaseAdapter<OpenloginLoginParams> {
if (error instanceof Web3AuthError) {
throw error;
}
throw WalletLoginError.connectionError((error as Error).message || "Failed to enable MFA with openlogin");
throw WalletLoginError.connectionError("Failed to enable MFA with openlogin", error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/phantom-adapter/src/phantomAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class PhantomAdapter extends BaseSolanaAdapter<void> {
});
} catch (error: unknown) {
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError((error as Error)?.message);
throw WalletLoginError.connectionError((error as Error)?.message, error);
} finally {
this._wallet._handleDisconnect = handleDisconnect;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/slope-adapter/src/slopeAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class SlopeAdapter extends BaseSolanaAdapter<void> {
await this.connectWithProvider(this._wallet);
} catch (error: unknown) {
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError((error as Error)?.message);
throw WalletLoginError.connectionError((error as Error)?.message, error);
}

return this.provider;
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/solflare-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"bn.js": "^5.2.1"
},
"devDependencies": {
"@solana/web3.js": "^1.93.2",
"@solana/web3.js": "^1.94.0",
"@solflare-wallet/sdk": "^1.4.2"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/solflare-adapter/src/solflareAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class SolflareAdapter extends BaseSolanaAdapter<void> {
await wallet.connect();
} catch (error: unknown) {
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError((error as Error)?.message);
throw WalletLoginError.connectionError((error as Error)?.message, error);
}
}
await this.connectWithProvider(wallet as SolflareWallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TorusWalletAdapter extends BaseEvmAdapter<never> {
this.status = ADAPTER_STATUS.READY;
this.rehydrated = false;
this.emit(ADAPTER_STATUS.ERRORED, error);
throw error instanceof Web3AuthError ? error : WalletLoginError.connectionError("Failed to login with torus wallet");
throw error instanceof Web3AuthError ? error : WalletLoginError.connectionError("Failed to login with torus wallet", error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class SolanaWalletAdapter extends BaseSolanaAdapter<void> {
this.rehydrated = false;
this.emit(ADAPTER_EVENTS.ERRORED, error);
if (error instanceof Web3AuthError) throw error;
throw WalletLoginError.connectionError("Failed to login with torus solana wallet");
throw WalletLoginError.connectionError("Failed to login with torus solana wallet", error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
import type { JRPCRequest } from "@toruslabs/openlogin-jrpc";
import type { ISignClient, SessionTypes } from "@walletconnect/types";
import { getAccountsFromNamespaces, parseAccountId } from "@walletconnect/utils";
import { WalletLoginError } from "@web3auth/base";
import type { AddEthereumChainParameter, IProviderHandlers, MessageParams, TransactionParams, TypedMessageParams } from "@web3auth/ethereum-provider";

async function getLastActiveSession(signClient: ISignClient): Promise<SessionTypes.Struct | null> {
Expand Down Expand Up @@ -43,7 +44,7 @@ export async function getAccounts(signClient: ISignClient): Promise<string[]> {
),
];
}
throw new Error("Failed to get accounts");
throw WalletLoginError.connectionError("Failed to get accounts");
}

export function getProviderHandlers({ connector, chainId }: { connector: ISignClient; chainId: number }): IProviderHandlers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class WalletConnectV2Adapter extends BaseEvmAdapter<void> {
const finalError =
error instanceof Web3AuthError
? error
: WalletLoginError.connectionError(`Failed to login with wallet connect: ${(error as Error)?.message || ""}`);
: WalletLoginError.connectionError(`Failed to login with wallet connect: ${(error as Error)?.message || ""}`, error);
throw finalError;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/base/src/chain/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WalletInitializationError } from "../errors";
import { CHAIN_NAMESPACES, ChainNamespaceType, CustomChainConfig } from "./IChainInterface";
const getDefaultNetworkId = (chainNamespace: ChainNamespaceType): number => {
if (chainNamespace === CHAIN_NAMESPACES.EIP155) {
Expand All @@ -7,7 +8,7 @@ const getDefaultNetworkId = (chainNamespace: ChainNamespaceType): number => {
} else if (chainNamespace === CHAIN_NAMESPACES.XRPL) {
return 1;
}
throw new Error(`Chain namespace ${chainNamespace} is not supported`);
throw WalletInitializationError.invalidParams(`Chain namespace ${chainNamespace} is not supported`);
};

export const getEvmChainConfig = (chainId: number): CustomChainConfig | null => {
Expand Down
Loading

0 comments on commit 5978975

Please sign in to comment.