Skip to content

Commit

Permalink
Merge branch 'main' into ag/fix/fe-751
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron authored Oct 15, 2024
2 parents 54d7f94 + 46000eb commit 68a91c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-lemons-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-connectors/bako-safe": patch
---

fix(bako-safe): prevents events from remaining active
22 changes: 12 additions & 10 deletions packages/bako-safe/src/BakoSafeConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
APP_VERSION,
HAS_WINDOW,
HOST_URL,
IS_SAFARI,
SESSION_ID,
WINDOW,
} from './constants';
Expand All @@ -47,7 +48,7 @@ export class BakoSafeConnector extends FuelConnector {
description: APP_DESCRIPTION,
},
};
installed = true;
installed = !IS_SAFARI;
connected = false;
external = false;

Expand Down Expand Up @@ -163,12 +164,12 @@ export class BakoSafeConnector extends FuelConnector {

//events controll
// @ts-ignore
this.on(BakoSafeConnectorEvents.CLIENT_DISCONNECTED, () => {
this.once(BakoSafeConnectorEvents.CLIENT_DISCONNECTED, () => {
this.dAppWindow?.close();
reject(false);
});

this.on(
this.once(
//@ts-ignore
BakoSafeConnectorEvents.AUTH_CONFIRMED,
async ({ data }: { data: IResponseAuthConfirmed }) => {
Expand Down Expand Up @@ -203,42 +204,43 @@ export class BakoSafeConnector extends FuelConnector {
this.checkWindow();

//events controll

this.on(
this.once(
//@ts-ignore
BakoSafeConnectorEvents.CLIENT_DISCONNECTED,
() => {
this.dAppWindow?.close();
reject();
reject(new Error('Client disconnected'));
},
);

// @ts-ignore
this.on(BakoSafeConnectorEvents.TX_TIMEOUT, () => {
this.once(BakoSafeConnectorEvents.TX_TIMEOUT, () => {
this.dAppWindow?.close();
reject(new Error('Transaction timeout'));
});

// @ts-ignore
this.on(BakoSafeConnectorEvents.CLIENT_CONNECTED, () => {
this.once(BakoSafeConnectorEvents.CLIENT_CONNECTED, () => {
this.socket?.server.emit(BakoSafeConnectorEvents.TX_PENDING, {
_transaction,
_address,
});
});

this.on(
this.once(
// @ts-ignore
BakoSafeConnectorEvents.TX_CONFIRMED,
({ data }: { data: IResponseTxCofirmed }) => {
this.dAppWindow?.close();
resolve(`0x${data.id}`);
},
);
});
}

async ping() {
if (IS_SAFARI) {
return false;
}
await this.setup();
return this.setupReady ?? false;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/bako-safe/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const SOCKET_URL = 'https://api.bako.global';
export const HAS_WINDOW = typeof window !== 'undefined';
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
export const WINDOW: any = HAS_WINDOW ? window : {};

export const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(
WINDOW.navigator?.userAgent ?? '',
);
//storage
export const SESSION_ID = 'sessionId';

0 comments on commit 68a91c8

Please sign in to comment.