diff --git a/.changeset/tricky-lemons-yell.md b/.changeset/tricky-lemons-yell.md new file mode 100644 index 00000000..71f9d36f --- /dev/null +++ b/.changeset/tricky-lemons-yell.md @@ -0,0 +1,5 @@ +--- +"@fuel-connectors/bako-safe": patch +--- + +fix(bako-safe): prevents events from remaining active diff --git a/packages/bako-safe/src/BakoSafeConnector.ts b/packages/bako-safe/src/BakoSafeConnector.ts index 28a189e0..b53b7c80 100644 --- a/packages/bako-safe/src/BakoSafeConnector.ts +++ b/packages/bako-safe/src/BakoSafeConnector.ts @@ -23,6 +23,7 @@ import { APP_VERSION, HAS_WINDOW, HOST_URL, + IS_SAFARI, SESSION_ID, WINDOW, } from './constants'; @@ -47,7 +48,7 @@ export class BakoSafeConnector extends FuelConnector { description: APP_DESCRIPTION, }, }; - installed = true; + installed = !IS_SAFARI; connected = false; external = false; @@ -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 }) => { @@ -203,35 +204,33 @@ 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}`); }, ); @@ -239,6 +238,9 @@ export class BakoSafeConnector extends FuelConnector { } async ping() { + if (IS_SAFARI) { + return false; + } await this.setup(); return this.setupReady ?? false; } diff --git a/packages/bako-safe/src/constants.ts b/packages/bako-safe/src/constants.ts index 4f0348ab..995e6e60 100644 --- a/packages/bako-safe/src/constants.ts +++ b/packages/bako-safe/src/constants.ts @@ -16,6 +16,8 @@ export const SOCKET_URL = 'https://api.bako.global'; export const HAS_WINDOW = typeof window !== 'undefined'; // biome-ignore lint/suspicious/noExplicitAny: 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';