Skip to content

Commit 15f5437

Browse files
committed
Fix loading toast hiding when there is a failure
1 parent 6ae2770 commit 15f5437

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

app/core/SDKConnectV2/services/connection-registry.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ describe('ConnectionRegistry', () => {
502502
]);
503503
});
504504

505-
it('does NOT dismiss the loading toast for QR flows even when connect() fails', async () => {
505+
it('dismisses the loading toast for QR flows when connect() fails so it does not overlap the error toast', async () => {
506506
registry = new ConnectionRegistry(
507507
RELAY_URL,
508508
mockKeyManager,
@@ -527,7 +527,7 @@ describe('ConnectionRegistry', () => {
527527

528528
expect(mockHostApp.showConnectionLoading).toHaveBeenCalledTimes(1);
529529
expect(mockHostApp.showConnectionError).toHaveBeenCalledTimes(1);
530-
expect(mockHostApp.hideConnectionLoading).not.toHaveBeenCalled();
530+
expect(mockHostApp.hideConnectionLoading).toHaveBeenCalledTimes(1);
531531
});
532532
});
533533

app/core/SDKConnectV2/services/connection-registry.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export class ConnectionRegistry {
247247
let conn: Connection | undefined;
248248
let connInfo: ConnectionInfo | undefined;
249249
let connReq: ConnectionRequest | undefined;
250+
let didConnectionFail = false;
250251

251252
try {
252253
connReq = this.parseConnectionRequest(url);
@@ -297,6 +298,7 @@ export class ConnectionRegistry {
297298
} catch (error) {
298299
logger.error('Failed to handle connect deeplink:', error, redactUrl(url));
299300
this.hostapp.showConnectionError();
301+
didConnectionFail = true;
300302

301303
// Track the failure before cleanup so the event fires even if
302304
// disconnect() throws.
@@ -315,13 +317,22 @@ export class ConnectionRegistry {
315317

316318
if (conn) await this.disconnect(conn.id);
317319
} finally {
318-
// For direct deeplink flows from native browser / react native, the connection request will have an initial message in the session request.
319-
// This means an approval will be shown to the user soon after the MWP handshake is complete, so we can safely dismiss the loading toast.
320-
// For QR flow, the connection request will not have an initial message in the session request because the dapp is expected to send it separately after the MWP handshake is complete.
321-
// Because there may be a longer delay until the wallet receives the initial message from the dapp directly, we should not dismiss the loading toast immediately after the MWP handshake is complete.
322-
320+
// Loading-toast dismissal rules:
321+
// - On failure, always dismiss the loading toast. Otherwise the user
322+
// would briefly see both a "loading" toast and the error toast at
323+
// the same time, and the loading toast would linger after the error
324+
// toast auto-dismisses.
325+
// - On success for direct deeplink flows (initialMessage present), the
326+
// connection request includes the initial RPC, so an approval will
327+
// surface immediately after the MWP handshake — it's safe to dismiss
328+
// the loading toast right away.
329+
// - On success for QR flows (no initialMessage), the dapp sends
330+
// wallet_createSession separately after the handshake. There may be
331+
// a noticeable delay before the approval appears, so we keep the
332+
// loading toast visible and let it autodismiss naturally.
323333
const isQrFlow = connReq?.sessionRequest.initialMessage === undefined;
324-
if (connInfo && !isQrFlow) {
334+
const shouldHideLoadingToast = didConnectionFail || !isQrFlow;
335+
if (connInfo && shouldHideLoadingToast) {
325336
this.hostapp.hideConnectionLoading(connInfo);
326337
}
327338
}

0 commit comments

Comments
 (0)