diff --git a/src/lightning-address.ts b/src/lightning-address.ts index 3409af7..a484e95 100644 --- a/src/lightning-address.ts +++ b/src/lightning-address.ts @@ -75,31 +75,45 @@ export default class LightningAddress { ); const json = await result.json(); - await this.parseResponse(json.lnurlp, json.keysend, json.nostr); + await this.parseLnUrlPayResponse(json.lnurlp); + this.parseKeysendResponse(json.keysend); + this.parseNostrResponse(json.nostr); } async fetchWithoutProxy() { if (!this.domain || !this.username) { return; } - const lnurlResult = await fetch(this.lnurlpUrl()); - const keysendResult = await fetch(this.keysendUrl()); - const nostrResult = await fetch(this.nostrUrl()); - let lnurlData: LnUrlRawData | undefined; + await Promise.all([ + this.fetchLnurlData(), + this.fetchKeysendData(), + this.fetchNostrData(), + ]); + } + + async fetchLnurlData() { + const lnurlResult = await fetch(this.lnurlpUrl()); if (lnurlResult.ok) { - lnurlData = await lnurlResult.json(); + const lnurlData = await lnurlResult.json(); + await this.parseLnUrlPayResponse(lnurlData); } - let keysendData: KeySendRawData | undefined; + } + + async fetchKeysendData() { + const keysendResult = await fetch(this.keysendUrl()); if (keysendResult.ok) { - keysendData = await keysendResult.json(); + const keysendData = await keysendResult.json(); + this.parseKeysendResponse(keysendData); } - let nostrData: NostrResponse | undefined; + } + + async fetchNostrData() { + const nostrResult = await fetch(this.nostrUrl()); if (nostrResult.ok) { - nostrData = await nostrResult.json(); + const nostrData = await nostrResult.json(); + this.parseNostrResponse(nostrData); } - - await this.parseResponse(lnurlData, keysendData, nostrData); } lnurlpUrl() { @@ -249,17 +263,19 @@ export default class LightningAddress { return response; } - private async parseResponse( - lnurlpData: LnUrlRawData | undefined, - keysendData: KeySendRawData | undefined, - nostrData: NostrResponse | undefined, - ) { + private async parseLnUrlPayResponse(lnurlpData: LnUrlRawData | undefined) { if (lnurlpData) { this.lnurlpData = await parseLnUrlPayResponse(lnurlpData); } + } + + private parseKeysendResponse(keysendData: KeySendRawData | undefined) { if (keysendData) { this.keysendData = parseKeysendResponse(keysendData); } + } + + private parseNostrResponse(nostrData: NostrResponse | undefined) { if (nostrData) { [this.nostrData, this.nostrPubkey, this.nostrRelays] = parseNostrResponse( nostrData,