Skip to content

Commit

Permalink
Merge pull request #133 from argentlabs/chore/starknet-react-comments
Browse files Browse the repository at this point in the history
Improve: Add comment explaining phantom `emits`
  • Loading branch information
Cussone authored Oct 3, 2024
2 parents 3a15950 + 5690e4f commit 932bfe9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/connectors/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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 {
Expand All @@ -195,6 +198,9 @@ export class InjectedConnector extends Connector {
throw new ConnectorNotFoundError()
}

/**
* @dev This emit ensures compatibility with starknet-react
*/
this.emit("disconnect")
}

Expand Down Expand Up @@ -237,14 +243,23 @@ export class InjectedConnector extends Connector {

private async onAccountsChanged(accounts?: string[]): Promise<void> {
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")
}
}
Expand All @@ -254,8 +269,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", {})
}
}
Expand Down

0 comments on commit 932bfe9

Please sign in to comment.