Await switch relays in the correct places to ensure clean switch and avoid interfering with nostrconnect error handling logic
This commit is contained in:
@@ -396,10 +396,10 @@ export class Nip46Broker extends Emitter {
|
|||||||
return `nostrconnect://${clientPubkey}?${params.toString()}`
|
return `nostrconnect://${clientPubkey}?${params.toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForNostrconnect = (url: string, signal: AbortSignal) => {
|
waitForNostrconnect = async (url: string, signal: AbortSignal) => {
|
||||||
const secret = new URL(url).searchParams.get("secret")
|
const secret = new URL(url).searchParams.get("secret")
|
||||||
|
|
||||||
return makePromise<Nip46ResponseWithResult, Nip46Response | undefined>(
|
const result = await makePromise<Nip46ResponseWithResult, Nip46Response | undefined>(
|
||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
const onReceive = async (response: Nip46Response) => {
|
const onReceive = async (response: Nip46Response) => {
|
||||||
if (response.result === "auth_url") return
|
if (response.result === "auth_url") return
|
||||||
@@ -413,8 +413,6 @@ export class Nip46Broker extends Emitter {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.switchRelays()
|
|
||||||
|
|
||||||
resolve(response as Nip46ResponseWithResult)
|
resolve(response as Nip46ResponseWithResult)
|
||||||
} else {
|
} else {
|
||||||
reject(response)
|
reject(response)
|
||||||
@@ -436,6 +434,10 @@ export class Nip46Broker extends Emitter {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await this.switchRelays()
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods for serializing a connection
|
// Methods for serializing a connection
|
||||||
@@ -474,7 +476,7 @@ export class Nip46Broker extends Emitter {
|
|||||||
|
|
||||||
const result = await this.send("connect", [this.params.signerPubkey, connectSecret, perms])
|
const result = await this.send("connect", [this.params.signerPubkey, connectSecret, perms])
|
||||||
|
|
||||||
this.switchRelays()
|
await this.switchRelays()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user