Skip to content

Commit

Permalink
fix: Removes sign listeners after auth completion
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jan 13, 2024
1 parent d5ac040 commit 807f491
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export class Client<ContentTypes> {
conversations: Conversations<ContentTypes>
contacts: Contacts
codecRegistry: { [key: string]: XMTPModule.ContentCodec<unknown> }
private static signSubscription: Subscription | null = null;

Check warning on line 32 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
private static authSubscription: Subscription | null = null;

Check warning on line 33 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;⏎`


/**
* Creates a new instance of the Client class using the provided signer.
Expand Down Expand Up @@ -58,7 +61,7 @@ export class Client<ContentTypes> {
>
>((resolve, reject) => {
;(async () => {
XMTPModule.emitter.addListener(
this.signSubscription = XMTPModule.emitter.addListener(
'sign',
async (message: { id: string; message: string }) => {
const request: { id: string; message: string } = message
Expand All @@ -80,14 +83,18 @@ export class Client<ContentTypes> {
console.info(errorMessage, e)
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
this.removeSignSubscription()
this.removeAuthSubscription()
reject(errorMessage)
}
}
)

XMTPModule.emitter.addListener('authed', async () => {
this.authSubscription = XMTPModule.emitter.addListener('authed', async () => {

Check warning on line 93 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'authed',` with `⏎··········'authed',⏎·········`
this.removeSubscription(enableSubscription)

Check warning on line 94 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
this.removeSubscription(createSubscription)

Check warning on line 95 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `··········` with `············`
this.removeSignSubscription()

Check warning on line 96 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
this.removeAuthSubscription()

Check warning on line 97 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
const address = await signer.getAddress()

Check warning on line 98 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `··········` with `············`
resolve(new Client(address, opts?.codecs || []))

Check warning on line 99 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
})

Check warning on line 100 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `}` with `··}⏎········`
Expand All @@ -102,6 +109,20 @@ export class Client<ContentTypes> {
})
}

private static removeSignSubscription(): void {
if (this.signSubscription) {
this.signSubscription.remove();
this.signSubscription = null;
}
}

private static removeAuthSubscription(): void {
if (this.authSubscription) {
this.authSubscription.remove();
this.authSubscription = null;
}
}

/**
* Creates a new instance of the XMTP Client with a randomly generated address.
*
Expand Down

0 comments on commit 807f491

Please sign in to comment.