Skip to content

Commit 0770404

Browse files
Fixing it up
1 parent e27566f commit 0770404

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
### Added
88

9-
- Added `onClose` callback to `connectAccount` method that fires whenever the Connect iFrame is closed (success or cancel)
10-
- Added `onCancel` callback to `connectAccount` method that fires when the Connect iFrame is closed without successfully connecting
9+
- Added `onClose` callback to `connectAccount` method that receives a
10+
`ConnectStatus` object with `successful` and `completed` boolean properties
1111

1212
## [1.6.3] - 2025-05-20b
1313

packages/sdk/src/browser/index.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ type ConnectResult = {
7070
id: string;
7171
};
7272

73+
/**
74+
* The status when the Connect dialog is closed.
75+
*/
76+
type ConnectStatus = {
77+
/**
78+
* Whether the connection was successful (account was connected).
79+
*/
80+
successful: boolean;
81+
/**
82+
* Whether the connection process was completed (vs user closing early).
83+
*/
84+
completed: boolean;
85+
};
86+
7387
/**
7488
* Custom error class for handling connection errors.
7589
*/
@@ -112,14 +126,10 @@ type StartConnectOpts = {
112126

113127
/**
114128
* Callback function to be called when the Connect iFrame is closed.
129+
*
130+
* @param status - The status of the connection when closed.
115131
*/
116-
onClose?: () => void;
117-
118-
/**
119-
* Callback function to be called when the user cancels/closes the Connect
120-
* iFrame without successfully connecting an account.
121-
*/
122-
onCancel?: () => void;
132+
onClose?: (status: ConnectStatus) => void;
123133
};
124134

125135
/**
@@ -234,36 +244,37 @@ export class BrowserClient extends BaseClient {
234244
* onError: (err) => {
235245
* console.error("Connection error:", err);
236246
* },
237-
* onClose: () => {
238-
* console.log("Connect iFrame closed");
239-
* },
240-
* onCancel: () => {
241-
* console.log("User cancelled without connecting");
247+
* onClose: (status) => {
248+
* if (!status.successful) {
249+
* console.log("User closed without connecting");
250+
* }
242251
* },
243252
* });
244253
* ```
245254
*/
246255
public async connectAccount(opts: StartConnectOpts) {
247256
let connectionSuccessful = false;
257+
let connectionCompleted = false;
248258

249259
const onMessage = (e: MessageEvent) => {
250260
switch (e.data?.type) {
251261
case "success":
252262
connectionSuccessful = true;
263+
connectionCompleted = true;
253264
opts.onSuccess?.({
254265
id: e.data?.authProvisionId,
255266
});
256267
break;
257268
case "error":
269+
connectionCompleted = true;
258270
opts.onError?.(new ConnectError(e.data.error));
259271
break;
260272
case "close":
261273
this.cleanup(onMessage);
262-
opts.onClose?.();
263-
// Call onCancel if the connection wasn't successful
264-
if (!connectionSuccessful) {
265-
opts.onCancel?.();
266-
}
274+
opts.onClose?.({
275+
successful: connectionSuccessful,
276+
completed: connectionCompleted,
277+
});
267278
break;
268279
default:
269280
break;

0 commit comments

Comments
 (0)