From 5690e4f25392a7e60d0a8691a23901a9f4b88ebe Mon Sep 17 00:00:00 2001 From: cussone Date: Tue, 1 Oct 2024 14:16:38 +0200 Subject: [PATCH] chore: add comment explaining phantom `emits` --- src/connectors/injected/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index 968c152..e117fab 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -171,6 +171,9 @@ export class InjectedConnector extends Connector { const [account] = accounts const chainId = await this.chainId() + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("connect", { account, chainId }) return { @@ -187,6 +190,9 @@ export class InjectedConnector extends Connector { throw new ConnectorNotFoundError() } + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("disconnect") } @@ -229,14 +235,23 @@ export class InjectedConnector extends Connector { private async onAccountsChanged(accounts?: string[]): Promise { if (!accounts) { + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("disconnect") } else { const [account] = accounts if (account) { const chainId = await this.chainId() + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("change", { account, chainId }) } else { + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("disconnect") } } @@ -246,8 +261,14 @@ export class InjectedConnector extends Connector { if (chainIdHex) { const chainId = BigInt(chainIdHex) const [account] = accounts || [] + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("change", { chainId, account }) } else { + /** + * @dev This emit ensures compatibility with starknet-react + */ this.emit("change", {}) } }