Skip to content

Commit

Permalink
chore: revert vite imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 1, 2024
1 parent 95965c1 commit c98f6f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ function version4(parameters: Version4Parameters) {
},
async getProvider() {
if (!walletProvider) {
const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk')
// Unwrapping import for Vite compatibility.
// See: https://github.com/vitejs/vite/issues/9703
const CoinbaseWalletSDK = await (async () => {
const { default: SDK } = await import('@coinbase/wallet-sdk')
if (typeof SDK !== 'function' && typeof SDK.default === 'function')
return SDK.default
return SDK as unknown as typeof SDK.default
})()

sdk = new CoinbaseWalletSDK({
...parameters,
appChainIds: config.chains.map((x) => x.id),
Expand Down Expand Up @@ -396,7 +404,15 @@ function version3(parameters: Version3Parameters) {
},
async getProvider() {
if (!walletProvider) {
const { CoinbaseWalletSDK } = await import('cbw-sdk')
// Unwrapping import for Vite compatibility.
// See: https://github.com/vitejs/vite/issues/9703
const CoinbaseWalletSDK = await (async () => {
const { default: SDK } = await import('cbw-sdk')
if (typeof SDK !== 'function' && typeof SDK.default === 'function')
return SDK.default
return SDK as unknown as typeof SDK.default
})()

sdk = new CoinbaseWalletSDK({ reloadOnDisconnect, ...parameters })

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

sdk = new MetaMaskSDK({
dappMetadata: {},
...parameters,
Expand Down

0 comments on commit c98f6f0

Please sign in to comment.