-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 🔧 add bos score to channels (#207)
- Loading branch information
Showing
18 changed files
with
726 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/graphql/queries/__generated__/getChannels.generated.tsx
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,13 @@ export const GET_CHANNELS = gql` | |
cltv_delta | ||
} | ||
} | ||
bosScore { | ||
alias | ||
public_key | ||
score | ||
updated | ||
position | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { FC } from 'react'; | ||
import { BalanceBars, SingleBar, SumBar } from 'src/components/balance'; | ||
import { ProgressBar } from 'src/components/generic/CardGeneric'; | ||
import { FormatFnType } from 'src/components/price/Price'; | ||
import { useConfigState } from 'src/context/ConfigContext'; | ||
import { ChannelType } from 'src/graphql/types'; | ||
import { getPercent } from 'src/utils/helpers'; | ||
import { ChannelStatsColumn, ChannelStatsLine } from './Channel.style'; | ||
import { WUMBO_MIN_SIZE } from './Channels'; | ||
|
||
const MAX_HTLCS = 483; | ||
|
||
const getBar = (top: number, bottom: number) => { | ||
const percent = (top / bottom) * 100; | ||
return Math.min(percent, 100); | ||
}; | ||
|
||
type ChannelBarsProps = { | ||
info: ChannelType; | ||
format: FormatFnType; | ||
details: { | ||
biggestRateFee: number; | ||
biggestBaseFee: number; | ||
biggestPartner: number; | ||
mostChannels: number; | ||
biggest: number; | ||
}; | ||
}; | ||
|
||
export const ChannelBars: FC<ChannelBarsProps> = ({ | ||
info, | ||
format, | ||
details: { | ||
biggestRateFee, | ||
biggestBaseFee, | ||
biggestPartner, | ||
mostChannels, | ||
biggest, | ||
}, | ||
}) => { | ||
const { | ||
partner_fee_info, | ||
partner_node_info, | ||
local_balance, | ||
remote_balance, | ||
pending_resume, | ||
} = info; | ||
|
||
const { incoming_amount = 200, outgoing_amount = 150 } = pending_resume; | ||
|
||
const { capacity: partnerNodeCapacity = 0, channel_count } = | ||
partner_node_info?.node || {}; | ||
|
||
const { base_fee_mtokens, fee_rate } = | ||
partner_fee_info?.partner_node_policies || {}; | ||
|
||
const { base_fee_mtokens: node_base, fee_rate: node_rate } = | ||
partner_fee_info?.node_policies || {}; | ||
|
||
const { channelBarType, subBar } = useConfigState(); | ||
|
||
const maxRate = Math.min(fee_rate || 0, 10000); | ||
const maxNodeRate = Math.min(node_rate || 0, 10000); | ||
|
||
const localBalance = format({ | ||
amount: local_balance, | ||
breakNumber: true, | ||
noUnit: true, | ||
}); | ||
const remoteBalance = format({ | ||
amount: remote_balance, | ||
breakNumber: true, | ||
noUnit: true, | ||
}); | ||
|
||
switch (channelBarType) { | ||
case 'fees': | ||
return ( | ||
<ChannelStatsColumn> | ||
<BalanceBars | ||
local={getBar(maxNodeRate, biggestRateFee)} | ||
remote={getBar(maxRate, biggestRateFee)} | ||
height={10} | ||
/> | ||
<BalanceBars | ||
local={getBar(Number(node_base), biggestBaseFee)} | ||
remote={getBar(Number(base_fee_mtokens), biggestBaseFee)} | ||
height={10} | ||
/> | ||
</ChannelStatsColumn> | ||
); | ||
case 'size': | ||
return ( | ||
<ChannelStatsColumn> | ||
<ChannelStatsLine> | ||
<ProgressBar | ||
order={0} | ||
percent={getBar(Number(partnerNodeCapacity), biggestPartner)} | ||
/> | ||
<ProgressBar | ||
order={4} | ||
percent={getBar( | ||
biggestPartner - Number(partnerNodeCapacity), | ||
biggestPartner | ||
)} | ||
/> | ||
</ChannelStatsLine> | ||
{channel_count && ( | ||
<ChannelStatsLine> | ||
<ProgressBar | ||
order={6} | ||
percent={getBar(channel_count, mostChannels)} | ||
/> | ||
<ProgressBar | ||
order={4} | ||
percent={getBar(mostChannels - channel_count, mostChannels)} | ||
/> | ||
</ChannelStatsLine> | ||
)} | ||
</ChannelStatsColumn> | ||
); | ||
case 'proportional': | ||
return ( | ||
<ChannelStatsColumn> | ||
{subBar === 'fees' && ( | ||
<SingleBar value={getBar(maxRate, 2000)} height={4} /> | ||
)} | ||
<BalanceBars | ||
local={getBar(local_balance, biggest)} | ||
remote={getBar(remote_balance, biggest)} | ||
formatLocal={localBalance} | ||
formatRemote={remoteBalance} | ||
withBorderColor={local_balance + remote_balance >= WUMBO_MIN_SIZE} | ||
/> | ||
</ChannelStatsColumn> | ||
); | ||
case 'htlcs': | ||
return ( | ||
<ChannelStatsColumn> | ||
{subBar === 'fees' && ( | ||
<SingleBar value={getBar(maxRate, 2000)} height={4} /> | ||
)} | ||
<SumBar | ||
values={[ | ||
getPercent(incoming_amount, MAX_HTLCS - incoming_amount), | ||
getPercent(outgoing_amount, MAX_HTLCS - outgoing_amount), | ||
]} | ||
/> | ||
</ChannelStatsColumn> | ||
); | ||
default: | ||
return ( | ||
<ChannelStatsColumn> | ||
{subBar === 'fees' && ( | ||
<SingleBar value={getBar(maxRate, 2000)} height={4} /> | ||
)} | ||
<BalanceBars | ||
local={getPercent(local_balance, remote_balance)} | ||
remote={getPercent(remote_balance, local_balance)} | ||
formatLocal={localBalance} | ||
formatRemote={remoteBalance} | ||
/> | ||
</ChannelStatsColumn> | ||
); | ||
} | ||
}; |
Oops, something went wrong.