@@ -25,7 +25,12 @@ import {
2525 hasWritePermission ,
2626} from ' ../../fixtures/memberships'
2727import { JsonRpcProvider } from ' ethers'
28- import { getSignature , getMessage , consoleWarn } from ' ../../fixtures/session'
28+ import {
29+ getSignature ,
30+ getMessage ,
31+ checkSession ,
32+ consoleWarn ,
33+ } from ' ../../fixtures/session'
2934import { Strings } from ' ../../i18n'
3035
3136type Props = {
@@ -108,25 +113,30 @@ const testPermission = async (
108113}
109114
110115const handleConnection = async (signer : UndefinedOr <Signer >) => {
116+ let newSigner: Signer = signer as Signer
117+ console .log ({ signer })
111118 if (! signer ) {
112- return
119+ const { connection : conct } = await import (
120+ ' @devprotocol/clubs-core/connection'
121+ )
122+ connection .value = conct
123+ newSigner = conct ().signer .value
124+ console .log ({ newSigner })
113125 }
114-
126+ console . log ( ' inside Handle Connection ' )
115127 // get wallet address
116- const connectedAddress = await signer .getAddress ()
117- // const connectedAddress = '0x57E21bd98612DE0Bd1723F4bf81A944eF7BfF526'
118- walletAddress .value = connectedAddress
119-
120- const hash = getMessage (connectedAddress )
128+ const connectedAddress = signer
129+ ? await signer .getAddress ()
130+ : await newSigner .getAddress ()
121131
122- let sig = await getSignature (connectedAddress , signer )
123-
124- fetchPosts ({ hash , sig })
132+ walletAddress .value = connectedAddress
125133
126- hasEditableRole .value = await testPermission (
127- walletAddress .value ,
128- new JsonRpcProvider (props .rpcUrl ),
129- )
134+ if (isVerified .value ) {
135+ hasEditableRole .value = await testPermission (
136+ walletAddress .value ,
137+ new JsonRpcProvider (props .rpcUrl ),
138+ )
139+ }
130140}
131141
132142const fetchPosts = async ({ hash , sig }: { hash? : string ; sig? : string }) => {
@@ -172,27 +182,32 @@ onMounted(async () => {
172182 ' @devprotocol/clubs-core/connection'
173183 )
174184 connection .value = conct
175- conct ().signer .subscribe ((signer : UndefinedOr <Signer >) => {
176- walletSigner = signer
185+ conct ().signer .subscribe (async (signer : UndefinedOr <Signer >) => {
186+ if (signer ) {
187+ const connectedAddress = await signer .getAddress ()
188+ walletAddress .value = connectedAddress
189+ isVerified .value = await checkSession (connectedAddress )
190+ console .log (' isverfied' , isVerified .value )
191+ walletSigner = signer
192+ handleConnection (signer )
193+ }
177194 })
178- const signer = conct ().signer .value
179- if (signer ) {
180- const connectedAddress = await signer .getAddress ()
181- walletAddress .value = connectedAddress
182- isVerified .value = true
183- }
184-
185195 i18n .value = i18nBase (navigator .languages )
186196})
187197
188198const isVerified = ref (false )
189199
190200const handleVerify = async () => {
191- handleConnection (walletSigner )
201+ const walletAddres = (await walletSigner ?.getAddress ()) as string
202+ const hash = getMessage (walletAddres )
203+ let sig = await getSignature (walletAddres , walletSigner as Signer )
204+ fetchPosts ({ hash , sig })
192205 //
193206 if (connection .value ?.().signer .value ) {
194207 isVerified .value = true
195208 }
209+
210+ handleConnection (walletSigner )
196211}
197212
198213const handlePostSuccess = (post : Posts ) => {
0 commit comments