@@ -27,27 +27,34 @@ export async function initXmtpClient(args: {
27
27
pkPath ?: string ;
28
28
} ) {
29
29
const { signer, address, ...restArgs } = args ;
30
+ logger . debug (
31
+ `[initXmtpClient] Starting with args: ${ JSON . stringify ( { address, ...restArgs } , null , 2 ) } `
32
+ ) ;
30
33
31
34
if ( ! signer || ! address ) {
35
+ logger . error ( "[initXmtpClient] Missing required params" ) ;
32
36
throw new Error ( "No signer or address" ) ;
33
37
}
34
38
35
39
try {
40
+ logger . debug ( "[initXmtpClient] Creating XMTP client from signer" ) ;
36
41
await createXmtpClientFromSigner ( signer , async ( ) => {
42
+ logger . debug ( "[initXmtpClient] Installation revoked, showing alert" ) ;
37
43
await awaitableAlert (
38
44
translate ( "current_installation_revoked" ) ,
39
45
translate ( "current_installation_revoked_description" )
40
46
) ;
41
47
throw new Error ( "Current installation revoked" ) ;
42
48
} ) ;
43
49
50
+ logger . debug ( "[initXmtpClient] Connecting with address" ) ;
44
51
await connectWithAddress ( {
45
52
address,
46
53
...restArgs ,
47
54
} ) ;
48
55
} catch ( e ) {
56
+ logger . error ( `[initXmtpClient] Error: ${ JSON . stringify ( e , null , 2 ) } ` ) ;
49
57
await logoutAccount ( { account : address } ) ;
50
- logger . error ( e ) ;
51
58
throw e ;
52
59
}
53
60
}
@@ -59,33 +66,47 @@ export async function initXmtpClientFromViemAccount(args: {
59
66
pkPath ?: string ;
60
67
} ) {
61
68
const { account, ...restArgs } = args ;
69
+ logger . debug (
70
+ `[initXmtpClientFromViemAccount] Starting with args: ${ JSON . stringify ( { account : account . address , ...restArgs } , null , 2 ) } `
71
+ ) ;
62
72
63
73
if ( ! account ) {
74
+ logger . error ( "[initXmtpClientFromViemAccount] No account provided" ) ;
64
75
throw new Error ( "No signer" ) ;
65
76
}
66
77
67
78
const { address } = account ;
68
79
69
80
if ( ! address ) {
81
+ logger . error ( "[initXmtpClientFromViemAccount] No address in account" ) ;
70
82
throw new Error ( "No address" ) ;
71
83
}
72
84
73
85
try {
86
+ logger . debug (
87
+ "[initXmtpClientFromViemAccount] Creating XMTP client from Viem account"
88
+ ) ;
74
89
await createXmtpClientFromViemAccount ( account , async ( ) => {
90
+ logger . debug (
91
+ "[initXmtpClientFromViemAccount] Installation revoked, showing alert"
92
+ ) ;
75
93
await awaitableAlert (
76
94
translate ( "current_installation_revoked" ) ,
77
95
translate ( "current_installation_revoked_description" )
78
96
) ;
79
97
throw new Error ( "Current installation revoked" ) ;
80
98
} ) ;
81
99
100
+ logger . debug ( "[initXmtpClientFromViemAccount] Connecting with address" ) ;
82
101
await connectWithAddress ( {
83
102
address,
84
103
...restArgs ,
85
104
} ) ;
86
105
} catch ( e ) {
106
+ logger . error (
107
+ `[initXmtpClientFromViemAccount] Error: ${ JSON . stringify ( e , null , 2 ) } `
108
+ ) ;
87
109
await logoutAccount ( { account : address } ) ;
88
- logger . error ( e ) ;
89
110
throw e ;
90
111
}
91
112
}
@@ -116,52 +137,73 @@ type IConnectWithAddressKeyArgs =
116
137
117
138
export async function connectWithAddress ( args : IConnectWithAddressKeyArgs ) {
118
139
const { address } = args ;
119
-
120
- logger . debug ( "In connectWithAddress" ) ;
140
+ logger . debug (
141
+ `[connectWithAddress] Starting with args: ${ JSON . stringify ( args , null , 2 ) } `
142
+ ) ;
121
143
122
144
if ( ! address ) {
145
+ logger . error ( "[connectWithAddress] No address provided" ) ;
123
146
sentryTrackMessage ( "Could not connect because no address" ) ;
124
147
return ;
125
148
}
126
149
127
150
try {
151
+ logger . debug ( "[connectWithAddress] Performing logout and saving key" ) ;
128
152
await performLogoutAndSaveKey ( address ) ;
129
153
154
+ logger . debug ( "[connectWithAddress] Setting current account" ) ;
130
155
useAccountsStore . getState ( ) . setCurrentAccount ( address , true ) ;
156
+
157
+ logger . debug ( "[connectWithAddress] Finalizing account setup" ) ;
131
158
await finalizeAccountSetup ( args ) ;
159
+
160
+ logger . debug ( "[connectWithAddress] Connection completed successfully" ) ;
132
161
sentryTrackMessage ( "Connecting done!" ) ;
133
162
} catch ( e ) {
134
- logger . error ( e , { context : "Onboarding - connectWithAddress" } ) ;
163
+ logger . error ( `[connectWithAddress] Error: ${ JSON . stringify ( e , null , 2 ) } ` , {
164
+ context : "Onboarding - connectWithAddress" ,
165
+ } ) ;
135
166
Alert . alert ( translate ( "onboarding_error" ) ) ;
136
167
throw e ;
137
168
}
138
169
}
139
170
140
171
async function performLogoutAndSaveKey ( address : string ) {
141
- logger . debug ( "Waiting for logout tasks" ) ;
172
+ logger . debug ( `[performLogoutAndSaveKey] Starting for address: ${ address } ` ) ;
173
+ logger . debug ( "[performLogoutAndSaveKey] Waiting for logout tasks" ) ;
142
174
await waitForLogoutTasksDone ( 500 ) ;
143
- logger . debug ( "Logout tasks done, saving xmtp key " ) ;
144
- logger . debug ( "XMTP Key saved" ) ;
175
+ logger . debug ( "[performLogoutAndSaveKey] Logout tasks completed " ) ;
176
+ logger . debug ( "[performLogoutAndSaveKey] XMTP Key saved" ) ;
145
177
}
146
178
147
179
async function finalizeAccountSetup ( args : IConnectWithAddressKeyArgs ) {
148
- logger . debug ( "Finalizing account setup" ) ;
180
+ logger . debug (
181
+ `[finalizeAccountSetup] Starting with args: ${ JSON . stringify ( args , null , 2 ) } `
182
+ ) ;
149
183
150
184
const { address } = args ;
151
185
186
+ logger . debug ( `[finalizeAccountSetup] Setting current account: ${ address } ` ) ;
152
187
useAccountsStore . getState ( ) . setCurrentAccount ( address , false ) ;
153
188
154
- getSettingsStore ( address )
155
- . getState ( )
156
- . setEphemeralAccount ( "isEphemeral" in args && args . isEphemeral ) ;
189
+ const isEphemeral = "isEphemeral" in args && args . isEphemeral ;
190
+ logger . debug (
191
+ `[finalizeAccountSetup] Setting ephemeral account status: ${ isEphemeral } `
192
+ ) ;
193
+ getSettingsStore ( address ) . getState ( ) . setEphemeralAccount ( isEphemeral ) ;
157
194
158
195
if ( "pkPath" in args ) {
196
+ logger . debug (
197
+ `[finalizeAccountSetup] Setting private key path: ${ args . pkPath } `
198
+ ) ;
159
199
getWalletStore ( address ) . getState ( ) . setPrivateKeyPath ( args . pkPath ) ;
160
200
}
161
201
202
+ logger . debug ( "[finalizeAccountSetup] Prefetching inbox ID" ) ;
162
203
await prefetchInboxIdQuery ( { account : address } ) ;
163
204
205
+ logger . debug ( "[finalizeAccountSetup] Getting XMTP client" ) ;
164
206
getXmtpClient ( { address } ) ;
165
207
166
- logger . debug ( "Account setup finalized " ) ;
208
+ logger . debug ( "[finalizeAccountSetup] Account setup completed " ) ;
167
209
}
0 commit comments