Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize channel reserve capacity #2522

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion components/BalanceSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ChannelItem } from '../components/Channels/ChannelItem';
interface BalanceSliderProps {
localBalance: string | number;
remoteBalance: string | number;
localReserveBalance?: string | number;
remoteReserveBalance?: string | number;
list?: boolean;
}

Expand All @@ -13,12 +15,19 @@ export default class BalanceSlider extends React.Component<
{}
> {
render() {
const { localBalance, remoteBalance } = this.props;
const {
localBalance,
remoteBalance,
localReserveBalance,
remoteReserveBalance
} = this.props;
return (
<View style={styles.slider}>
<ChannelItem
inbound={remoteBalance}
outbound={localBalance}
inboundReserve={localReserveBalance}
outboundReserve={remoteReserveBalance}
noBorder
hideLabels
/>
Expand Down
39 changes: 31 additions & 8 deletions components/Channels/BalanceBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import { Row } from '../layout/Row';
import { themeColor } from '../../utils/ThemeUtils';

export function BalanceBar({
left,
right,
outbound,
inbound,
outboundReserve = 0,
inboundReserve = 0,
offline,
percentOfLargest,
showProportionally = true
}: {
left: number;
right: number;
outbound: number;
inbound: number;
outboundReserve: number;
inboundReserve: number;
offline: boolean;
// How big is this channel relative to the largest channel
// A float from 0.0 -> 1.0, 1 being the largest channel
percentOfLargest: number;
showProportionally: boolean;
}) {
const total = left + right;
const total = outboundReserve + outbound + inbound + inboundReserve;

// If we're supposed to show proportionally set the miniumum to 20% of the width
// Otherwise take the full width
Expand All @@ -28,7 +32,15 @@ export function BalanceBar({
<View
style={{
height: 8,
flex: left / total,
flex: outboundReserve / total,
backgroundColor: themeColor('outboundReserve'),
marginRight: 1
}}
/>
<View
style={{
height: 8,
flex: outbound / total,
backgroundColor: offline
? '#E5E5E5'
: themeColor('outbound'),
Expand All @@ -38,8 +50,19 @@ export function BalanceBar({
<View
style={{
height: 8,
flex: right / total,
backgroundColor: offline ? '#A7A9AC' : themeColor('inbound')
flex: inbound / total,
backgroundColor: offline
? '#A7A9AC'
: themeColor('inbound'),
marginRight: 1
}}
/>
<View
style={{
height: 8,
flex: inboundReserve / total,
backgroundColor: themeColor('inboundReserve'),
marginRight: 1
}}
/>
</Row>
Expand Down
12 changes: 10 additions & 2 deletions components/Channels/ChannelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function ChannelItem({
secondTitle,
inbound,
outbound,
inboundReserve = 0,
outboundReserve = 0,
largestTotal,
status,
pendingHTLCs,
Expand All @@ -35,6 +37,8 @@ export function ChannelItem({
secondTitle?: string;
inbound: string | number;
outbound: string | number;
inboundReserve?: string | number;
outboundReserve?: string | number;
largestTotal?: number;
status?: Status;
pendingHTLCs?: boolean;
Expand Down Expand Up @@ -128,8 +132,12 @@ export function ChannelItem({
{inbound && outbound && !(inbound == 0 && outbound == 0) && (
<Row style={{ marginTop: 15, marginBottom: 15 }}>
<BalanceBar
left={lurkerMode ? 50 : Number(outbound)}
right={lurkerMode ? 50 : Number(inbound)}
outbound={lurkerMode ? 50 : Number(outbound)}
inbound={lurkerMode ? 50 : Number(inbound)}
outboundReserve={
lurkerMode ? 0 : Number(outboundReserve)
}
inboundReserve={lurkerMode ? 0 : Number(inboundReserve)}
offline={isOffline}
percentOfLargest={percentOfLargest}
showProportionally={lurkerMode ? false : true}
Expand Down
4 changes: 4 additions & 0 deletions components/HopPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export default class ChannelPicker extends React.Component<
title={item.displayName}
inbound={item.remoteBalance}
outbound={item.localBalance}
inboundReserve={item.remoteReserveBalance}
outboundReserve={item.localReserveBalance}
largestTotal={largestChannelSats}
selected={selected}
/>
Expand All @@ -159,6 +161,8 @@ export default class ChannelPicker extends React.Component<
title={item.displayName}
inbound={item.remoteBalance}
outbound={item.localBalance}
inboundReserve={item.remoteReserveBalance}
outboundReserve={item.localReserveBalance}
selected={selected}
/>
</TouchableHighlight>
Expand Down
13 changes: 13 additions & 0 deletions components/KeyValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface KeyValueProps {
keyValue: string;
value?: any;
color?: string;
indicatorColor?: string;
sensitive?: boolean;
infoText?: string | Array<string>;
infoLink?: string;
Expand All @@ -40,6 +41,7 @@ export default class KeyValue extends React.Component<KeyValueProps, {}> {
keyValue,
value,
color,
indicatorColor,
sensitive,
infoText,
infoLink,
Expand All @@ -63,6 +65,17 @@ export default class KeyValue extends React.Component<KeyValueProps, {}> {
const rtl = false;
const KeyBase = (
<Body>
{indicatorColor && (
<View
style={{
width: 12,
height: 12,
borderRadius: 12 / 2,
backgroundColor: indicatorColor,
marginRight: 7
}}
></View>
)}
<Text
style={{
color:
Expand Down
31 changes: 29 additions & 2 deletions models/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ export default class Channel extends BaseModel {

@computed
public get localBalance(): string {
return this.to_us
const totalLocalBalance = this.to_us
? (Number(this.to_us) / 1000).toString()
: this.to_us_msat
? (Number(this.to_us_msat) / 1000).toString()
: this.msatoshi_to_us
? (Number(this.msatoshi_to_us) / 1000).toString()
: this.local_balance || '0';
return (
Number(totalLocalBalance) - Number(this.localReserveBalance)
).toString();
}

@computed
public get remoteBalance(): string {
return this.total
const totalRemoteBalance = this.total
? ((Number(this.total) - Number(this.to_us)) / 1000).toString()
: this.total_msat
? (
Expand All @@ -119,6 +122,30 @@ export default class Channel extends BaseModel {
1000
).toString()
: this.remote_balance || '0';
return (
Number(totalRemoteBalance) - Number(this.remoteReserveBalance)
).toString();
}

@computed
public get localReserveBalance(): string {
return this.local_chan_reserve_sat
? Number(this.local_chan_reserve_sat).toString()
: '0';
}

@computed
public get remoteReserveBalance(): string {
return this.remote_chan_reserve_sat
? Number(this.remote_chan_reserve_sat).toString()
: '0';
}

@computed
public get totalReserveBalance(): string {
return (
Number(this.localReserveBalance) + Number(this.remoteReserveBalance)
).toString();
}

/** Channel id
Expand Down
2 changes: 2 additions & 0 deletions utils/ThemeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const Dark: { [key: string]: any } = {
separator: '#31363F',
outbound: '#FFD93F',
inbound: '#FFF0CA',
outboundReserve: '#B7B7B7',
inboundReserve: '#636569',
success: '#46BE43',
warning: '#E14C4C',
bitcoin: '#FFB040',
Expand Down
14 changes: 13 additions & 1 deletion views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ export default class ChannelView extends React.Component<
channel_point,
commit_weight,
localBalance,
remoteBalance,
localReserveBalance,
remoteReserveBalance,
commit_fee,
csv_delay,
total_satoshis_received,
isActive,
remoteBalance,
unsettled_balance,
total_satoshis_sent,
remotePubkey,
Expand Down Expand Up @@ -358,6 +360,12 @@ export default class ChannelView extends React.Component<
<BalanceSlider
localBalance={lurkerMode ? 50 : localBalance}
remoteBalance={lurkerMode ? 50 : remoteBalance}
localReserveBalance={
lurkerMode ? 50 : localReserveBalance
}
remoteReserveBalance={
lurkerMode ? 50 : remoteReserveBalance
}
/>
<Text
style={{ ...styles.status, color: themeColor('text') }}
Expand Down Expand Up @@ -572,12 +580,14 @@ export default class ChannelView extends React.Component<
value={
<Amount sats={localBalance} sensitive toggleable />
}
indicatorColor={themeColor('outbound')}
/>
<KeyValue
keyValue={localeString('views.Channel.Total.inbound')}
value={
<Amount sats={remoteBalance} sensitive toggleable />
}
indicatorColor={themeColor('inbound')}
/>
{unsettled_balance && (
<KeyValue
Expand Down Expand Up @@ -621,6 +631,7 @@ export default class ChannelView extends React.Component<
'views.Channel.localReserve.info'
)}
infoLink="https://bitcoin.design/guide/how-it-works/liquidity/#what-is-a-channel-reserve"
indicatorColor={themeColor('outboundReserve')}
/>
)}
{!!remote_chan_reserve_sat && (
Expand All @@ -639,6 +650,7 @@ export default class ChannelView extends React.Component<
'views.Channel.remoteReserve.info'
)}
infoLink="https://bitcoin.design/guide/how-it-works/liquidity/#what-is-a-channel-reserve"
indicatorColor={themeColor('inboundReserve')}
/>
)}
{capacity && (
Expand Down
Loading