onready
This commit is contained in:
parent
412bf4716d
commit
5902e6cc72
2 changed files with 20 additions and 0 deletions
|
|
@ -56,7 +56,17 @@ export class LiquidityProvider {
|
|||
retrieveNostrGuestWithPubAuth: async () => this.localPubkey
|
||||
}, this.clientSend, this.clientSub)
|
||||
|
||||
this.utils.nostrSender.OnReady(() => {
|
||||
this.setSetIfConfigured()
|
||||
if (this.configured) {
|
||||
clearInterval(this.configuredInterval)
|
||||
this.Connect()
|
||||
}
|
||||
})
|
||||
this.configuredInterval = setInterval(() => {
|
||||
if (!this.configured && this.utils.nostrSender.IsReady()) {
|
||||
this.setSetIfConfigured()
|
||||
}
|
||||
if (this.configured) {
|
||||
clearInterval(this.configuredInterval)
|
||||
this.Connect()
|
||||
|
|
|
|||
|
|
@ -2,9 +2,19 @@ import { NostrSend, SendData, SendInitiator } from "./nostrPool.js"
|
|||
export class NostrSender {
|
||||
private _nostrSend: NostrSend = () => { throw new Error('nostr send not initialized yet') }
|
||||
private isReady: boolean = false
|
||||
private onReadyCallbacks: (() => void)[] = []
|
||||
AttachNostrSend(nostrSend: NostrSend) {
|
||||
this._nostrSend = nostrSend
|
||||
this.isReady = true
|
||||
this.onReadyCallbacks.forEach(cb => cb())
|
||||
this.onReadyCallbacks = []
|
||||
}
|
||||
OnReady(callback: () => void) {
|
||||
if (this.isReady) {
|
||||
callback()
|
||||
} else {
|
||||
this.onReadyCallbacks.push(callback)
|
||||
}
|
||||
}
|
||||
Send(initiator: SendInitiator, data: SendData, relays?: string[] | undefined) {
|
||||
if (!this._nostrSend) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue