Skip to content

Commit

Permalink
Set providers defensively (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmjee authored May 22, 2023
1 parent e01a68a commit aa15153
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,20 @@ class AuthProvider {

/* eslint-disable @typescript-eslint/no-explicit-any */
private setProviders() {
if (!(window as Record<string, any>).arcana) {
;(window as Record<string, any>).arcana = {}
const w = window as Record<string, any>
try {
w.arcana = w.arcana ?? {}
w.arcana.provider = this._provider
} catch (e) {
console.error(e)
}
;(window as Record<string, any>).arcana.provider = this._provider
if (!(window as Record<string, any>).ethereum) {
;(window as Record<string, any>).ethereum = {}
try {
w.ethereum = w.ethereum ?? this._provider
w.ethereum.providers = w.ethereum.providers ?? []
w.ethereum.providers.push(this._provider)
} catch (e) {
console.error(e)
}
if (!(window as Record<string, any>).providers) {
;(window as Record<string, any>).ethereum.providers = []
}
;(window as Record<string, any>).ethereum.providers.push(this._provider)
}
/* eslint-enable */
}
Expand Down

0 comments on commit aa15153

Please sign in to comment.