Skip to content

Commit

Permalink
A scope bug fix and event correction on Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed Apr 12, 2024
1 parent 33e7434 commit b9d054c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/wallet/messaging/wallet/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ export default class Provider extends EventEmitter {
if (!this.ports.get(url)) throw Error('No port found')

this.connection = this.ports.get(url)!

this.connection.onMessage.addListener(this.handleMessage)

this.connection.onDisconnect.addListener(() => {
this.connection!.onMessage.removeListener(this.handleMessage)
})

this.connection.onMessage.addListener((request) => this.handleMessage(request))

this.connection.postMessage({
event: 'account',
Expand All @@ -72,7 +68,7 @@ export default class Provider extends EventEmitter {
private handleEvent <E extends keyof EventMappings>(event: E, data: EventMappings[E]) {
if (!this.connection) return

this.connection.postMessage(event)
this.connection.postMessage({ event, data })
}

private async handleMessage (request: Request) {
Expand Down

0 comments on commit b9d054c

Please # to comment.