From 077e20d7dabf05b045d6a85f51c5b2d73cdf30ba Mon Sep 17 00:00:00 2001 From: AP Date: Sat, 23 May 2020 19:23:09 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20channels=20with=20unfound?= =?UTF-8?q?=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/schemas/query/channels/channels.ts | 15 ++---- api/schemas/query/channels/closedChannels.ts | 50 +++++++++---------- api/schemas/query/channels/pendingChannels.ts | 50 +++++++++---------- src/views/channels/channels/ChannelCard.tsx | 27 ++++++---- .../channels/pendingChannels/PendingCard.tsx | 22 +++++--- 5 files changed, 86 insertions(+), 78 deletions(-) diff --git a/api/schemas/query/channels/channels.ts b/api/schemas/query/channels/channels.ts index 704d9f0e..0726bb71 100644 --- a/api/schemas/query/channels/channels.ts +++ b/api/schemas/query/channels/channels.ts @@ -6,14 +6,10 @@ import { getWalletInfo, } from 'ln-service'; import { ContextType } from 'api/types/apiTypes'; -import { toWithError } from 'api/helpers/async'; +import { toWithError, to } from 'api/helpers/async'; import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from '../../../helpers/helpers'; +import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers'; import { defaultParams } from '../../../helpers/defaultProps'; import { ChannelType } from '../../types/QueryType'; @@ -35,18 +31,13 @@ export const getChannels = { walletError && logger.debug('Error getting wallet info in getChannels: %o', walletError); - const [channelList, channelListError] = await toWithError( + const channelList = await to( getLnChannels({ lnd, is_active: params.active, }) ); - if (channelListError) { - logger.error('Error getting channels: %o', channelListError); - throw new Error(getErrorMsg(channelListError)); - } - const getChannelList = () => Promise.all( channelList.channels.map(async channel => { diff --git a/api/schemas/query/channels/closedChannels.ts b/api/schemas/query/channels/closedChannels.ts index 9d5b14e7..35158697 100644 --- a/api/schemas/query/channels/closedChannels.ts +++ b/api/schemas/query/channels/closedChannels.ts @@ -1,14 +1,10 @@ import { GraphQLList, GraphQLString } from 'graphql'; import { getClosedChannels as getLnClosedChannels, getNode } from 'ln-service'; import { ContextType } from 'api/types/apiTypes'; +import { to, toWithError } from 'api/helpers/async'; import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from '../../../helpers/helpers'; - +import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers'; import { defaultParams } from '../../../helpers/defaultProps'; import { ClosedChannelType } from '../../types/QueryType'; @@ -45,28 +41,32 @@ export const getClosedChannels = { const auth = getCorrectAuth(params.auth, context); const lnd = getAuthLnd(auth); - try { - const closedChannels: ChannelListProps = await getLnClosedChannels({ - lnd, - }); - const channels = closedChannels.channels.map(async channel => { - const nodeInfo = await getNode({ + const closedChannels: ChannelListProps = await to( + getLnClosedChannels({ lnd }) + ); + + const channels = closedChannels.channels.map(async channel => { + const [nodeInfo, nodeError] = await toWithError( + getNode({ lnd, is_omitting_channels: true, public_key: channel.partner_public_key, - }); + }) + ); - return { - ...channel, - partner_node_info: { - ...nodeInfo, - }, - }; - }); - return channels; - } catch (error) { - logger.error('Error getting closed channels: %o', error); - throw new Error(getErrorMsg(error)); - } + nodeError && + logger.debug( + `Error getting node with public key ${channel.partner_public_key}: %o`, + nodeError + ); + + return { + ...channel, + partner_node_info: { + ...(!nodeError && nodeInfo), + }, + }; + }); + return channels; }, }; diff --git a/api/schemas/query/channels/pendingChannels.ts b/api/schemas/query/channels/pendingChannels.ts index 58ee7bea..6fea98db 100644 --- a/api/schemas/query/channels/pendingChannels.ts +++ b/api/schemas/query/channels/pendingChannels.ts @@ -4,13 +4,10 @@ import { } from 'ln-service'; import { GraphQLList } from 'graphql'; import { ContextType } from 'api/types/apiTypes'; +import { to, toWithError } from 'api/helpers/async'; import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from '../../../helpers/helpers'; +import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers'; import { defaultParams } from '../../../helpers/defaultProps'; import { PendingChannelType } from '../../types/QueryType'; @@ -44,31 +41,32 @@ export const getPendingChannels = { const auth = getCorrectAuth(params.auth, context); const lnd = getAuthLnd(auth); - try { - const pendingChannels: PendingChannelListProps = await getLnPendingChannels( - { - lnd, - } - ); + const pendingChannels: PendingChannelListProps = await to( + getLnPendingChannels({ lnd }) + ); - const channels = pendingChannels.pending_channels.map(async channel => { - const nodeInfo = await getNode({ + const channels = pendingChannels.pending_channels.map(async channel => { + const [nodeInfo, nodeError] = await toWithError( + getNode({ lnd, is_omitting_channels: true, public_key: channel.partner_public_key, - }); + }) + ); - return { - ...channel, - partner_node_info: { - ...nodeInfo, - }, - }; - }); - return channels; - } catch (error) { - logger.error('Error getting pending channels: %o', error); - throw new Error(getErrorMsg(error)); - } + nodeError && + logger.debug( + `Error getting node with public key ${channel.partner_public_key}: %o`, + nodeError + ); + + return { + ...channel, + partner_node_info: { + ...(!nodeError && nodeInfo), + }, + }; + }); + return channels; }, }; diff --git a/src/views/channels/channels/ChannelCard.tsx b/src/views/channels/channels/ChannelCard.tsx index e471def5..7592f9bd 100644 --- a/src/views/channels/channels/ChannelCard.tsx +++ b/src/views/channels/channels/ChannelCard.tsx @@ -187,6 +187,23 @@ export const ChannelCard = ({ }); }; + const renderPartner = () => + alias ? ( + <> + {renderLine('Node Capacity:', nodeCapacity)} + {renderLine('Channel Count:', channel_count)} + {renderLine( + 'Last Update:', + `${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})` + )} + {renderLine('Base Fee:', `${base_fee} mSats`)} + {renderLine('Fee Rate:', `${fee_rate} sats/MSats`)} + {renderLine('CTLV Delta:', cltv_delta)} + + ) : ( + Partner node not found + ); + const renderDetails = () => { return ( <> @@ -215,15 +232,7 @@ export const ChannelCard = ({ {renderLine('Transaction Vout:', transaction_vout)} {renderLine('Unsettled Balance:', unsettled_balance)} Partner Node Info - {renderLine('Node Capacity:', nodeCapacity)} - {renderLine('Channel Count:', channel_count)} - {renderLine( - 'Last Update:', - `${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})` - )} - {renderLine('Base Fee:', `${base_fee} mSats`)} - {renderLine('Fee Rate:', `${fee_rate} sats/MSats`)} - {renderLine('CTLV Delta:', cltv_delta)} + {renderPartner()} diff --git a/src/views/channels/pendingChannels/PendingCard.tsx b/src/views/channels/pendingChannels/PendingCard.tsx index f23a4da0..ccb62d58 100644 --- a/src/views/channels/pendingChannels/PendingCard.tsx +++ b/src/views/channels/pendingChannels/PendingCard.tsx @@ -16,6 +16,7 @@ import { ResponsiveLine, ResponsiveSingle, ResponsiveCol, + DarkSubTitle, } from '../../../components/generic/Styled'; import { useConfigState } from '../../../context/ConfigContext'; import { @@ -89,6 +90,20 @@ export const PendingCard = ({ } }; + const renderPartner = () => + alias ? ( + <> + {renderLine('Node Capacity:', capacity)} + {renderLine('Channels:', channel_count)} + {renderLine( + 'Last Update:', + `${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})` + )} + + ) : ( + Partner node not found + ); + const renderDetails = () => { return ( <> @@ -108,12 +123,7 @@ export const PendingCard = ({ {renderLine('Local Reserve:', local_reserve)} {renderLine('Remote Reserve:', remote_reserve)} Partner Node Info - {renderLine('Node Capacity:', capacity)} - {renderLine('Channels:', channel_count)} - {renderLine( - 'Last Update:', - `${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})` - )} + {renderPartner()} ); };