Skip to content

Commit

Permalink
refactor(connectors): use named exports for async imports (#4096)
Browse files Browse the repository at this point in the history
* refactor(connectors): use named exports

* chore: changeset
  • Loading branch information
tmm authored Jun 28, 2024
1 parent ff0760b commit f5c1585
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-peas-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/connectors": patch
---

Switched to named imports for connector async imports.
24 changes: 4 additions & 20 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,8 @@ function version4(parameters: Version4Parameters) {
},
async getProvider() {
if (!walletProvider) {
// Unwrapping import for Vite compatibility.
// See: https://github.com/vitejs/vite/issues/9703
const { default: CoinbaseSDK_ } = await import('@coinbase/wallet-sdk')
const CoinbaseSDK = (() => {
if (
typeof CoinbaseSDK_ !== 'function' &&
typeof CoinbaseSDK_.default === 'function'
)
return CoinbaseSDK_.default
return CoinbaseSDK_ as unknown as typeof CoinbaseSDK_.default
})()

sdk = new CoinbaseSDK({
const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk')
sdk = new CoinbaseWalletSDK({
...parameters,
appChainIds: config.chains.map((x) => x.id),
})
Expand Down Expand Up @@ -407,13 +396,8 @@ function version3(parameters: Version3Parameters) {
},
async getProvider() {
if (!walletProvider) {
const { default: SDK_ } = await import('cbw-sdk')
let SDK: typeof SDK_.default
if (typeof SDK_ !== 'function' && typeof SDK_.default === 'function')
SDK = SDK_.default
else SDK = SDK_ as unknown as typeof SDK_.default

sdk = new SDK({ reloadOnDisconnect, ...parameters })
const { CoinbaseWalletSDK } = await import('cbw-sdk')
sdk = new CoinbaseWalletSDK({ reloadOnDisconnect, ...parameters })

// Force types to retrieve private `walletExtension` method from the Coinbase Wallet SDK.
const walletExtensionChainId = (
Expand Down
13 changes: 1 addition & 12 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,7 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
},
async getProvider() {
async function initProvider() {
// Unwrapping import for Vite compatibility.
// See: https://github.com/vitejs/vite/issues/9703
const { default: MetaMaskSDK_ } = await import('@metamask/sdk')
const MetaMaskSDK = (() => {
if (
typeof MetaMaskSDK_ !== 'function' &&
typeof MetaMaskSDK_.default === 'function'
)
return MetaMaskSDK_.default
return MetaMaskSDK_ as unknown as typeof MetaMaskSDK_.default
})()

const { MetaMaskSDK } = await import('@metamask/sdk')
sdk = new MetaMaskSDK({
dappMetadata: {},
...parameters,
Expand Down

0 comments on commit f5c1585

Please sign in to comment.