mirror of
https://github.com/apotdevin/thunderhub.git
synced 2024-11-19 18:00:05 +01:00
refactor: ♻️ getChannels query
This commit is contained in:
parent
0be677a446
commit
9a5a21032f
@ -12,9 +12,11 @@ import { getClosedChannels } from './resolvers/query/getClosedChannels';
|
||||
import { getPendingChannels } from './resolvers/query/getPendingChannels';
|
||||
|
||||
type ParentType = {
|
||||
lnd: {};
|
||||
id: String;
|
||||
localKey: String;
|
||||
id: string;
|
||||
partner_fee_info: {
|
||||
lnd: {};
|
||||
localKey: String;
|
||||
};
|
||||
};
|
||||
|
||||
export const channelResolvers = {
|
||||
@ -30,10 +32,11 @@ export const channelResolvers = {
|
||||
updateFees,
|
||||
updateMultipleFees,
|
||||
},
|
||||
Channel: {
|
||||
channel: async (parent: ParentType) => {
|
||||
const { lnd, id, localKey } = parent;
|
||||
|
||||
channelType: {
|
||||
partner_fee_info: async ({
|
||||
id,
|
||||
partner_fee_info: { lnd, localKey },
|
||||
}: ParentType) => {
|
||||
if (!lnd) {
|
||||
logger.debug('ExpectedLNDToGetChannel');
|
||||
return null;
|
||||
@ -44,7 +47,9 @@ export const channelResolvers = {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [channel, error] = await toWithError(getChannel({ lnd, id }));
|
||||
const [channel, error] = await toWithError<GetChannelType>(
|
||||
getChannel({ lnd, id })
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.debug(`Error getting channel with id ${id}: %o`, error);
|
||||
@ -54,19 +59,21 @@ export const channelResolvers = {
|
||||
let node_policies = null;
|
||||
let partner_node_policies = null;
|
||||
|
||||
(channel as GetChannelType).policies.forEach(policy => {
|
||||
if (localKey && localKey === policy.public_key) {
|
||||
node_policies = {
|
||||
...policy,
|
||||
node: { lnd, publicKey: policy.public_key },
|
||||
};
|
||||
} else {
|
||||
partner_node_policies = {
|
||||
...policy,
|
||||
node: { lnd, publicKey: policy.public_key },
|
||||
};
|
||||
}
|
||||
});
|
||||
if (channel) {
|
||||
channel.policies.forEach(policy => {
|
||||
if (localKey && localKey === policy.public_key) {
|
||||
node_policies = {
|
||||
...policy,
|
||||
node: { lnd, publicKey: policy.public_key },
|
||||
};
|
||||
} else {
|
||||
partner_node_policies = {
|
||||
...policy,
|
||||
node: { lnd, publicKey: policy.public_key },
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...(channel as GetChannelType),
|
||||
@ -74,8 +81,6 @@ export const channelResolvers = {
|
||||
partner_node_policies,
|
||||
};
|
||||
},
|
||||
},
|
||||
channelType: {
|
||||
pending_resume({ pending_payments }: ChannelType) {
|
||||
const total = pending_payments.reduce(
|
||||
(prev, current) => {
|
||||
|
@ -9,11 +9,9 @@ import { GetChannelsType } from 'server/types/ln-service.types';
|
||||
export const getChannels = async (
|
||||
_: undefined,
|
||||
params: any,
|
||||
context: ContextType
|
||||
{ ip, lnd }: ContextType
|
||||
) => {
|
||||
await requestLimiter(context.ip, 'channels');
|
||||
|
||||
const { lnd } = context;
|
||||
await requestLimiter(ip, 'channels');
|
||||
|
||||
const { public_key, current_block_height } = await to(getWalletInfo({ lnd }));
|
||||
|
||||
@ -29,7 +27,7 @@ export const getChannels = async (
|
||||
time_offline: Math.round((channel.time_offline || 0) / 1000),
|
||||
time_online: Math.round((channel.time_online || 0) / 1000),
|
||||
partner_node_info: { lnd, publicKey: channel.partner_public_key },
|
||||
partner_fee_info: { lnd, id: channel.id, localKey: public_key },
|
||||
partner_fee_info: { lnd, localKey: public_key },
|
||||
channel_age: getChannelAge(channel.id, current_block_height),
|
||||
}));
|
||||
};
|
||||
|
@ -47,10 +47,6 @@ export const channelTypes = gql`
|
||||
partner_node_policies: nodePolicyType
|
||||
}
|
||||
|
||||
type Channel {
|
||||
channel: singleChannelType
|
||||
}
|
||||
|
||||
type channelBalanceType {
|
||||
confirmedBalance: Int!
|
||||
pendingBalance: Int!
|
||||
@ -96,7 +92,7 @@ export const channelTypes = gql`
|
||||
transaction_vout: Int!
|
||||
unsettled_balance: Int!
|
||||
partner_node_info: Node!
|
||||
partner_fee_info: Channel
|
||||
partner_fee_info: singleChannelType
|
||||
channel_age: Int!
|
||||
pending_payments: [pendingPaymentType]!
|
||||
pending_resume: pendingResumeType!
|
||||
|
@ -18,16 +18,13 @@ export type ChannelFeesQuery = (
|
||||
& Pick<Types.NodeType, 'alias' | 'color'>
|
||||
) }
|
||||
), partner_fee_info?: Types.Maybe<(
|
||||
{ __typename?: 'Channel' }
|
||||
& { channel?: Types.Maybe<(
|
||||
{ __typename?: 'singleChannelType' }
|
||||
& { node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)>, partner_node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)> }
|
||||
{ __typename?: 'singleChannelType' }
|
||||
& { node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)>, partner_node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)> }
|
||||
)> }
|
||||
)>> }
|
||||
@ -48,21 +45,19 @@ export const ChannelFeesDocument = gql`
|
||||
}
|
||||
}
|
||||
partner_fee_info {
|
||||
channel {
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,13 @@ export type GetChannelsQuery = (
|
||||
& Pick<Types.NodeType, 'alias' | 'capacity' | 'channel_count' | 'color' | 'updated_at'>
|
||||
) }
|
||||
), partner_fee_info?: Types.Maybe<(
|
||||
{ __typename?: 'Channel' }
|
||||
& { channel?: Types.Maybe<(
|
||||
{ __typename?: 'singleChannelType' }
|
||||
& { node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)>, partner_node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta'>
|
||||
)> }
|
||||
{ __typename?: 'singleChannelType' }
|
||||
& { node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta' | 'max_htlc_mtokens' | 'min_htlc_mtokens'>
|
||||
)>, partner_node_policies?: Types.Maybe<(
|
||||
{ __typename?: 'nodePolicyType' }
|
||||
& Pick<Types.NodePolicyType, 'base_fee_mtokens' | 'fee_rate' | 'cltv_delta'>
|
||||
)> }
|
||||
)> }
|
||||
)>> }
|
||||
@ -83,19 +80,17 @@ export const GetChannelsDocument = gql`
|
||||
}
|
||||
}
|
||||
partner_fee_info {
|
||||
channel {
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
}
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,15 +180,13 @@ Object {
|
||||
Object {
|
||||
"id": "100x1x1",
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
@ -204,15 +202,13 @@ Object {
|
||||
Object {
|
||||
"id": "100x1x1",
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
@ -228,15 +224,13 @@ Object {
|
||||
Object {
|
||||
"id": "100x1x1",
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
"max_htlc_mtokens": "10000",
|
||||
"min_htlc_mtokens": "10000",
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
@ -280,13 +274,11 @@ Object {
|
||||
"local_balance": 1000,
|
||||
"local_reserve": 1000,
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
@ -332,13 +324,11 @@ Object {
|
||||
"local_balance": 1000,
|
||||
"local_reserve": 1000,
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
@ -384,13 +374,11 @@ Object {
|
||||
"local_balance": 1000,
|
||||
"local_reserve": 1000,
|
||||
"partner_fee_info": Object {
|
||||
"channel": Object {
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
"node_policies": null,
|
||||
"partner_node_policies": Object {
|
||||
"base_fee_mtokens": "2000",
|
||||
"cltv_delta": 1000,
|
||||
"fee_rate": 1000,
|
||||
},
|
||||
},
|
||||
"partner_node_info": Object {
|
||||
|
@ -14,21 +14,19 @@ export const CHANNEL_FEES = gql`
|
||||
}
|
||||
}
|
||||
partner_fee_info {
|
||||
channel {
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,19 +44,17 @@ export const GET_CHANNELS = gql`
|
||||
}
|
||||
}
|
||||
partner_fee_info {
|
||||
channel {
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
}
|
||||
node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
max_htlc_mtokens
|
||||
min_htlc_mtokens
|
||||
}
|
||||
partner_node_policies {
|
||||
base_fee_mtokens
|
||||
fee_rate
|
||||
cltv_delta
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -627,11 +627,6 @@ export type SingleChannelType = {
|
||||
partner_node_policies?: Maybe<NodePolicyType>;
|
||||
};
|
||||
|
||||
export type Channel = {
|
||||
__typename?: 'Channel';
|
||||
channel?: Maybe<SingleChannelType>;
|
||||
};
|
||||
|
||||
export type ChannelBalanceType = {
|
||||
__typename?: 'channelBalanceType';
|
||||
confirmedBalance: Scalars['Int'];
|
||||
@ -681,7 +676,7 @@ export type ChannelType = {
|
||||
transaction_vout: Scalars['Int'];
|
||||
unsettled_balance: Scalars['Int'];
|
||||
partner_node_info: Node;
|
||||
partner_fee_info?: Maybe<Channel>;
|
||||
partner_fee_info?: Maybe<SingleChannelType>;
|
||||
channel_age: Scalars['Int'];
|
||||
pending_payments: Array<Maybe<PendingPaymentType>>;
|
||||
pending_resume: PendingResumeType;
|
||||
|
@ -155,7 +155,7 @@ export const ChannelCard: React.FC<ChannelCardProps> = ({
|
||||
} = partner_node_info?.node || {};
|
||||
|
||||
const { base_fee_mtokens, fee_rate, cltv_delta } =
|
||||
partner_fee_info?.channel?.partner_node_policies || {};
|
||||
partner_fee_info?.partner_node_policies || {};
|
||||
|
||||
const {
|
||||
base_fee_mtokens: node_base,
|
||||
@ -163,7 +163,7 @@ export const ChannelCard: React.FC<ChannelCardProps> = ({
|
||||
cltv_delta: node_cltv,
|
||||
max_htlc_mtokens,
|
||||
min_htlc_mtokens,
|
||||
} = partner_fee_info?.channel?.node_policies || {};
|
||||
} = partner_fee_info?.node_policies || {};
|
||||
|
||||
const formatBalance = format({ amount: capacity });
|
||||
const formatLocal = format({ amount: local_balance });
|
||||
|
@ -72,10 +72,10 @@ export const Channels: React.FC = () => {
|
||||
|
||||
const { capacity, channel_count } = partner_node_info?.node || {};
|
||||
const { base_fee_mtokens, fee_rate } =
|
||||
partner_fee_info?.channel?.partner_node_policies || {};
|
||||
partner_fee_info?.partner_node_policies || {};
|
||||
|
||||
const { base_fee_mtokens: nodeBase, fee_rate: nodeRate } =
|
||||
partner_fee_info?.channel?.node_policies || {};
|
||||
partner_fee_info?.node_policies || {};
|
||||
|
||||
const partner = Number(capacity) || 0;
|
||||
const channels = Number(channel_count) || 0;
|
||||
@ -157,8 +157,7 @@ export const Channels: React.FC = () => {
|
||||
case 'feeRate': {
|
||||
const newArray = sortBy(
|
||||
channels,
|
||||
channel =>
|
||||
channel?.partner_fee_info?.channel?.partner_node_policies?.fee_rate
|
||||
channel => channel?.partner_fee_info?.partner_node_policies?.fee_rate
|
||||
);
|
||||
return sortDirection === 'increase' ? newArray : newArray.reverse();
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export const DetailsTable = ({ channels }: DetailsTableType) => {
|
||||
|
||||
return (
|
||||
channels.map(channel => {
|
||||
const policies = channel?.partner_fee_info?.channel?.node_policies;
|
||||
const policies = channel?.partner_fee_info?.node_policies;
|
||||
let finalPolicies = {};
|
||||
if (policies) {
|
||||
finalPolicies = {
|
||||
|
Loading…
Reference in New Issue
Block a user