Skip to content

Commit 7a52723

Browse files
authored
Merge pull request #23 from cometh-hq/develop
fix: IsAuthorized (#22)
2 parents e2fc564 + bd17d63 commit 7a52723

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cometh/connect-sdk-viem",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Viem SDK Cometh Connect",
@@ -55,10 +55,10 @@
5555
},
5656
"dependencies": {
5757
"@babel/traverse": "^7.23.4",
58-
"@cometh/connect-sdk": "^1.2.11",
58+
"@cometh/connect-sdk": "^1.2.12",
5959
"@rainbow-me/rainbowkit": "^1.3.0",
6060
"@types/babel__core": "^7.20.0",
61-
"viem": "^1.16.2",
62-
"wagmi": "^1.4.7"
61+
"viem": "^1.19.11",
62+
"wagmi": "^1.4.13"
6363
}
6464
}

src/wagmi/connector.ts

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
webAuthnOptions
77
} from '@cometh/connect-sdk'
88
import { toHex } from 'viem'
9-
import { Chain, Connector, ConnectorNotFoundError } from 'wagmi'
9+
import { Chain, Connector } from 'wagmi'
1010

1111
import {
1212
ConnectClient,
@@ -51,6 +51,7 @@ export class ComethConnectConnector extends Connector<
5151
ready = false
5252
wallet?: ComethWallet
5353
client?: ConnectClient
54+
supportedChains?: SupportedNetworks[]
5455

5556
protected shimDisconnectKey = `${this.id}.shimDisconnect`
5657

@@ -145,27 +146,38 @@ export class ComethConnectConnector extends Connector<
145146
throw new Error('Network not supported')
146147

147148
return providedChainId
148-
} else {
149-
const supportedChains = this.chains.reduce(
150-
(chains: SupportedNetworks[], chain: Chain) => {
151-
const chainId = toHex(chain.id)
152-
if (!isSupportedNetwork(chainId)) {
153-
console.warn(`${chain.name} not yet supported by cometh connect`)
154-
} else {
155-
chains.push(chainId)
156-
}
157-
return chains
158-
},
159-
[]
160-
)
161-
if (supportedChains.length === 0)
162-
throw new Error('Cometh Connect does not support the provided chains')
149+
}
163150

164-
if (supportedChains.length > 1)
165-
console.warn(`Cometh connect does not support multichain`)
151+
// if autoconnect already provided
152+
if (this.supportedChains) {
153+
return this.supportedChains[0]
154+
} else {
155+
return this._getConfigChain()
156+
}
157+
}
166158

167-
return supportedChains[0]
159+
private _getConfigChain() {
160+
this.supportedChains = this.chains.reduce(
161+
(chains: SupportedNetworks[], chain: Chain) => {
162+
const chainId = toHex(chain.id)
163+
if (!isSupportedNetwork(chainId)) {
164+
console.warn(`${chain.name} not yet supported by cometh connect`)
165+
} else {
166+
chains.push(chainId)
167+
}
168+
return chains
169+
},
170+
[]
171+
)
172+
if (this.supportedChains.length === 0) {
173+
console.warn('Cometh Connect does not support any the provided chains')
174+
throw new Error('Cometh Connect does not support the provided chains')
168175
}
176+
177+
if (this.supportedChains.length > 1)
178+
console.warn(`Cometh connect does not support multichain`)
179+
180+
return this.supportedChains[0]
169181
}
170182
disconnect(): Promise<void> {
171183
if (!this.wallet) throw new Error('no')
@@ -203,8 +215,8 @@ export class ComethConnectConnector extends Connector<
203215
)
204216
return false
205217

206-
const provider = await this.getProvider()
207-
if (!provider) throw new ConnectorNotFoundError()
218+
this._getConfigChain()
219+
208220
return true
209221
} catch {
210222
return false

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@
185185
stream-browserify "^3.0.0"
186186
util "^0.12.4"
187187

188-
"@cometh/connect-sdk@^1.2.11":
189-
version "1.2.11"
190-
resolved "https://registry.yarnpkg.com/@cometh/connect-sdk/-/connect-sdk-1.2.11.tgz#cb797d59ce48d9b29eee52fb24f80f2cf1f9c9ca"
191-
integrity sha512-wCGzM7tbbnEAl1QnivWjVU20VdhQZj45W1KRoRaHsZfFsfiiA7xCYMmSwlSpRZRvgXW/vIuH1RaFsKQzklD1/Q==
188+
"@cometh/connect-sdk@^1.2.12":
189+
version "1.2.12"
190+
resolved "https://registry.yarnpkg.com/@cometh/connect-sdk/-/connect-sdk-1.2.12.tgz#b380c9224cde8773c57a5c8aec2555a019f36a5f"
191+
integrity sha512-SlG8AI9ruW/05ExJ9+8l8Xd/N/ZmSLkYmOUOnBgzJmxkz6DRu5yCJ3DHkNnFP0YTvzmX3ucl/IH+6w4eXmP1hQ==
192192
dependencies:
193193
"@alembic/ui" "^1.5.4"
194194
"@babel/traverse" "^7.23.4"
@@ -6299,7 +6299,7 @@ [email protected]:
62996299
proxy-compare "2.5.1"
63006300
use-sync-external-store "1.2.0"
63016301

6302-
viem@^1.0.0, viem@^1.16.2, viem@^1.6.0:
6302+
viem@^1.0.0, viem@^1.19.11, viem@^1.6.0:
63036303
version "1.21.4"
63046304
resolved "https://registry.yarnpkg.com/viem/-/viem-1.21.4.tgz#883760e9222540a5a7e0339809202b45fe6a842d"
63056305
integrity sha512-BNVYdSaUjeS2zKQgPs+49e5JKocfo60Ib2yiXOWBT6LuVxY1I/6fFX3waEtpXvL1Xn4qu+BVitVtMh9lyThyhQ==
@@ -6313,7 +6313,7 @@ viem@^1.0.0, viem@^1.16.2, viem@^1.6.0:
63136313
isows "1.0.3"
63146314
ws "8.13.0"
63156315

6316-
wagmi@^1.4.7:
6316+
wagmi@^1.4.13:
63176317
version "1.4.13"
63186318
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-1.4.13.tgz#dc8dc077c7c2195877d7e33477b0417f5d2add4f"
63196319
integrity sha512-AScVYFjqNt1wMgL99Bob7MLdhoTZ3XKiOZL5HVBdy4W1sh7QodA3gQ8IsmTuUrQ7oQaTxjiXEhwg7sWNrPBvJA==

0 commit comments

Comments
 (0)