Skip to content

Commit c36e615

Browse files
committed
revert connection to dynamic importing
1 parent 74846b2 commit c36e615

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/components/ConnectButton/Button.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Signer } from 'ethers'
88
import { useEffect, useMemo, useState } from 'react'
99
import { whenDefined, whenDefinedAll } from '@devprotocol/util-ts'
1010
import { i18nFactory, Signal } from '@devprotocol/clubs-core'
11-
import { connection } from '@devprotocol/clubs-core/connection'
11+
import type { connection as Connection } from '@devprotocol/clubs-core/connection'
1212
import {
1313
DynamicUserProfile,
1414
useDynamicContext,
@@ -34,6 +34,7 @@ export default ({
3434
}) => {
3535
const dynamic = useDynamicContext()
3636
const [signer, setSigner] = useState<Signer>()
37+
const [connection, setConnection] = useState<ReturnType<typeof Connection>>()
3738
const [walletName, setWalletName] = useState<string>()
3839
const [isWalletNeeded, setIsWalletNeeded] = useState<boolean>(false)
3940
const [isUnexpectedNetwork, setUnexpectedNetwork] = useState<boolean>(false)
@@ -52,6 +53,12 @@ export default ({
5253

5354
const loggedIn = useMemo(() => dynamic?.user !== undefined, [dynamic?.user])
5455

56+
useEffect(() => {
57+
import('@devprotocol/clubs-core/connection').then((it) => {
58+
setConnection(it.connection())
59+
})
60+
}, [])
61+
5562
useEffect(() => {
5663
const cryptoWallet = dynamic.user?.verifiedCredentials.find(
5764
(c) => c.format === 'blockchain' && Boolean(c.embeddedWalletId),
@@ -84,24 +91,24 @@ export default ({
8491
setUnexpectedNetwork(
8592
typeof chainId === 'number' && connectedChain !== chainId,
8693
)
87-
whenDefinedAll([connection()], ([_connection]) =>
94+
whenDefinedAll([connection], ([_connection]) =>
8895
_connection.chain.next(Number(dynamic.network)),
8996
)
90-
}, [dynamic.network])
97+
}, [dynamic.network, connection])
9198

9299
useEffect(() => {
93100
const emailCredential = dynamic.user?.verifiedCredentials?.find(
94101
(c) => c.format === 'email',
95102
)
96103
console.log('**', { emailCredential })
97-
whenDefinedAll([connection()], ([_connection]) =>
104+
whenDefinedAll([connection], ([_connection]) =>
98105
_connection.identifiers.next(
99106
whenDefined(emailCredential?.publicIdentifier, (email) => ({
100107
email,
101108
})),
102109
),
103110
)
104-
}, [dynamic.user])
111+
}, [dynamic.user, connection])
105112

106113
useEffect(() => {
107114
const eoa = dynamic?.primaryWallet?.address
@@ -115,14 +122,14 @@ export default ({
115122
}, [dynamic?.primaryWallet?.address])
116123

117124
useEffect(() => {
118-
whenDefinedAll([connection()], ([_connection]) => {
125+
whenDefinedAll([connection], ([_connection]) => {
119126
// console.log('Called here', signer)
120127
_connection.signer.next(signer)
121128
})
122-
}, [signer])
129+
}, [signer, connection])
123130

124131
useEffect(() => {
125-
whenDefinedAll([connection()], ([_connection]) => {
132+
whenDefinedAll([connection], ([_connection]) => {
126133
// console.log('$$$ Called here', signer)
127134

128135
// signal
@@ -144,7 +151,7 @@ export default ({
144151
}
145152
})
146153
})
147-
}, [])
154+
}, [connection])
148155

149156
return (
150157
<span className="group/awesome-onboarding relative block">

0 commit comments

Comments
 (0)