Skip to content

Commit 5aec286

Browse files
committed
Small refactor:
* Fixes issue where there was an undefined wallet in the list of wallets returned * getModule return type more specific and no longer returns undefined which simplifies things for the method's caller
1 parent 7cadbc5 commit 5aec286

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/modules/select/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,17 @@ function select(
3535
if (isWalletInit(wallet)) {
3636
const { walletName, ...initParams } = wallet
3737

38-
let module
3938
try {
40-
module = getModule(walletName)
39+
return getModule(walletName).then((m: any) =>
40+
m.default({ ...initParams, networkId })
41+
)
4142
} catch (error) {
42-
console.warn(error)
43+
if (error.name === 'DeprecatedWalletError') {
44+
console.warn(error.message)
45+
} else {
46+
throw error
47+
}
4348
}
44-
45-
if (!module) {
46-
throw new Error(`${walletName} is not a valid walletName.`)
47-
}
48-
49-
return (
50-
module &&
51-
module.then((m: any) => m.default({ ...initParams, networkId }))
52-
)
5349
}
5450

5551
return Promise.resolve(wallet)
@@ -58,22 +54,26 @@ function select(
5854
}
5955

6056
return Promise.all(
61-
defaultWalletNames.map(walletName => {
62-
const module = getModule(walletName)
63-
if (module) {
64-
return module.then((m: any) => m.default({ networkId }))
65-
}
66-
})
57+
defaultWalletNames.map(walletName =>
58+
getModule(walletName).then((m: any) => m.default({ networkId }))
59+
)
6760
)
6861
}
6962

70-
function getModule(name: string): Promise<any> | undefined {
63+
function getModule(
64+
name: string
65+
): Promise<{
66+
default: (options: any) => WalletModule
67+
}> {
7168
switch (name) {
7269
// Deprecated wallets
7370
case 'dapper':
7471
case 'squarelink':
7572
case 'unilogin':
76-
throw new Error(`${name.toUpperCase()} wallet has been deprecated`)
73+
throw {
74+
name: 'DeprecatedWalletError',
75+
message: `${name} wallet has been deprecated`
76+
}
7777
case 'meetone':
7878
return import('./wallets/meetone')
7979
case 'metamask':
@@ -123,7 +123,7 @@ function getModule(name: string): Promise<any> | undefined {
123123
case 'atoken':
124124
return import('./wallets/atoken')
125125
default:
126-
return
126+
throw new Error(`${name} is not a valid walletName.`)
127127
}
128128
}
129129

0 commit comments

Comments
 (0)