Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Safe connector not working in some Vite apps #4371

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading