From d9d73662e2ae09da409c5e6fa08e70502c6c52a9 Mon Sep 17 00:00:00 2001 From: myxmaster Date: Tue, 27 Jun 2023 21:07:25 +0200 Subject: [PATCH] await node info retrieval in enrichChannels() --- stores/ChannelsStore.ts | 55 ++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/stores/ChannelsStore.ts b/stores/ChannelsStore.ts index 4a0a38ec0..d0dc69eb4 100644 --- a/stores/ChannelsStore.ts +++ b/stores/ChannelsStore.ts @@ -220,33 +220,36 @@ export default class ChannelsStore { }); @action - enrichChannels = (channels: Array) => { + enrichChannels = async (channels: Array) => { this.loading = true; - channels.forEach(async (channel: Channel) => { - if (!channel.remotePubkey) return; - if ( - this.settingsStore.implementation !== 'c-lightning-REST' && - !this.nodes[channel.remotePubkey] - ) { - await this.getNodeInfo(channel.remotePubkey) - .then((nodeInfo: any) => { - if (!nodeInfo) return; - this.nodes[channel.remotePubkey] = nodeInfo; - this.aliasesById[channel.channelId] = nodeInfo.alias; - }) - .catch(() => { - // console.log( - // `Couldn't find node alias for ${channel.remotePubkey}`, - // err - // ); - }); - } - if (!channel.alias && this.aliasesById[channel.channelId]) { - channel.alias = this.aliasesById[channel.channelId]; - } - channel.displayName = - channel.alias || channel.remotePubkey || channel.channelId; - }); + await Promise.all( + channels.map(async (channel: Channel) => { + if (!channel.remotePubkey) return; + if ( + this.settingsStore.implementation !== 'c-lightning-REST' && + !this.nodes[channel.remotePubkey] + ) { + await this.getNodeInfo(channel.remotePubkey) + .then((nodeInfo: any) => { + if (!nodeInfo) return; + this.nodes[channel.remotePubkey] = nodeInfo; + this.aliasesById[channel.channelId] = + nodeInfo.alias; + }) + .catch(() => { + // console.log( + // `Couldn't find node alias for ${channel.remotePubkey}`, + // err + // ); + }); + } + if (!channel.alias && this.aliasesById[channel.channelId]) { + channel.alias = this.aliasesById[channel.channelId]; + } + channel.displayName = + channel.alias || channel.remotePubkey || channel.channelId; + }) + ); this.loading = false; return channels; };