Skip to content

Commit

Permalink
fix: Safe connector not working in some Vite apps (#4371)
Browse files Browse the repository at this point in the history
* Fix Safe connector not working in some Vite apps

* Fix Safe connector not working in some Vite apps

* chore: tweaks

---------

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
iceanddust and tmm authored Nov 5, 2024
1 parent 2b0d4c3 commit b6861a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-chefs-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/connectors": patch
---

Fixed Safe connector not working in some Vite apps
14 changes: 11 additions & 3 deletions packages/connectors/src/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ export function safe(parameters: SafeParameters = {}) {
timeout: parameters.unstable_getInfoTimeout ?? 10,
})
if (!safe) throw new Error('Could not load Safe information')
const { SafeAppProvider } = await import(
'@safe-global/safe-apps-provider'
)
// Unwrapping import for Vite compatibility.
// See: https://github.com/vitejs/vite/issues/9703
const SafeAppProvider = await (async () => {
const Provider = await import('@safe-global/safe-apps-provider')
if (
typeof Provider.SafeAppProvider !== 'function' &&
typeof Provider.default.SafeAppProvider === 'function'
)
return Provider.default.SafeAppProvider
return Provider.SafeAppProvider
})()
provider_ = new SafeAppProvider(safe, sdk)
}
return provider_
Expand Down

0 comments on commit b6861a4

Please sign in to comment.