diff --git a/frontend/src/app/interfaces/node-api.interface.ts b/frontend/src/app/interfaces/node-api.interface.ts index d32e641f7..2e6b94988 100644 --- a/frontend/src/app/interfaces/node-api.interface.ts +++ b/frontend/src/app/interfaces/node-api.interface.ts @@ -217,8 +217,8 @@ export interface IChannel { updated_at: string; created: string; status: number; - node_left: Node, - node_right: Node, + node_left: INode, + node_right: INode, } @@ -236,4 +236,6 @@ export interface INode { updated_at: string; longitude: number; latitude: number; + funding_balance?: number; + closing_balance?: number; } diff --git a/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.html b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.html new file mode 100644 index 000000000..ae59767ff --- /dev/null +++ b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.html @@ -0,0 +1,19 @@ +
+ + + + + + + + + + + + + + + + +
Starting balance{{ minStartingBalance | number : '1.0-0' }} - {{ maxStartingBalance | number : '1.0-0' }}?
Closing balance{{ minClosingBalance | number : '1.0-0' }} - {{ maxClosingBalance | number : '1.0-0' }}?
+
\ No newline at end of file diff --git a/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.scss b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.scss new file mode 100644 index 000000000..a42871308 --- /dev/null +++ b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.scss @@ -0,0 +1,9 @@ +.box { + margin-top: 20px; +} + +@media (max-width: 768px) { + .box { + margin-bottom: 20px; + } +} \ No newline at end of file diff --git a/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.spec.ts b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.spec.ts new file mode 100644 index 000000000..eea4ee99c --- /dev/null +++ b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ChannelCloseBoxComponent } from './channel-close-box.component'; + +describe('ChannelCloseBoxComponent', () => { + let component: ChannelCloseBoxComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ChannelCloseBoxComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ChannelCloseBoxComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.ts b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.ts new file mode 100644 index 000000000..05cc31434 --- /dev/null +++ b/frontend/src/app/lightning/channel/channel-close-box/channel-close-box.component.ts @@ -0,0 +1,58 @@ +import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; + +@Component({ + selector: 'app-channel-close-box', + templateUrl: './channel-close-box.component.html', + styleUrls: ['./channel-close-box.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ChannelCloseBoxComponent implements OnChanges { + @Input() channel: any; + @Input() local: any; + @Input() remote: any; + + showStartingBalance: boolean = false; + showClosingBalance: boolean = false; + minStartingBalance: number; + maxStartingBalance: number; + minClosingBalance: number; + maxClosingBalance: number; + + constructor() { } + + ngOnChanges(changes: SimpleChanges): void { + if (this.channel && this.local && this.remote) { + this.showStartingBalance = (this.local.funding_balance || this.remote.funding_balance) && this.channel.funding_ratio; + this.showClosingBalance = this.local.closing_balance || this.remote.closing_balance; + + if (this.channel.single_funded) { + if (this.local.funding_balance) { + this.minStartingBalance = this.channel.capacity; + this.maxStartingBalance = this.channel.capacity; + } else if (this.remote.funding_balance) { + this.minStartingBalance = 0; + this.maxStartingBalance = 0; + } + } else { + this.minStartingBalance = clampRound(0, this.channel.capacity, this.local.funding_balance * this.channel.funding_ratio); + this.maxStartingBalance = clampRound(0, this.channel.capacity, this.channel.capacity - (this.remote.funding_balance * this.channel.funding_ratio)); + } + + const closingCapacity = this.channel.capacity - this.channel.closing_fee; + this.minClosingBalance = clampRound(0, closingCapacity, this.local.closing_balance); + this.maxClosingBalance = clampRound(0, closingCapacity, closingCapacity - this.remote.closing_balance); + + // margin of error to account for 2 x 330 sat anchor outputs + if (Math.abs(this.minClosingBalance - this.maxClosingBalance) <= 660) { + this.maxClosingBalance = this.minClosingBalance; + } + } else { + this.showStartingBalance = false; + this.showClosingBalance = false; + } + } +} + +function clampRound(min: number, max: number, value: number): number { + return Math.max(0, Math.min(max, Math.round(value))); +} diff --git a/frontend/src/app/lightning/channel/channel.component.html b/frontend/src/app/lightning/channel/channel.component.html index c25af5377..f52b85762 100644 --- a/frontend/src/app/lightning/channel/channel.component.html +++ b/frontend/src/app/lightning/channel/channel.component.html @@ -48,6 +48,15 @@ Capacity + + Closed by + + + {{ channel.node_left.alias }} + {{ channel.node_right.alias }} + + + @@ -59,9 +68,11 @@
+
+
diff --git a/frontend/src/app/lightning/channel/channel.component.ts b/frontend/src/app/lightning/channel/channel.component.ts index d64d388ea..379e8a005 100644 --- a/frontend/src/app/lightning/channel/channel.component.ts +++ b/frontend/src/app/lightning/channel/channel.component.ts @@ -78,4 +78,9 @@ export class ChannelComponent implements OnInit { ); } + showCloseBoxes(channel: IChannel): boolean { + return !!(channel.node_left.funding_balance || channel.node_left.closing_balance + || channel.node_right.funding_balance || channel.node_right.closing_balance); + } + } diff --git a/frontend/src/app/lightning/lightning.module.ts b/frontend/src/app/lightning/lightning.module.ts index fa2f1a1ec..5d67433c7 100644 --- a/frontend/src/app/lightning/lightning.module.ts +++ b/frontend/src/app/lightning/lightning.module.ts @@ -12,6 +12,7 @@ import { ChannelsListComponent } from './channels-list/channels-list.component'; import { ChannelComponent } from './channel/channel.component'; import { LightningWrapperComponent } from './lightning-wrapper/lightning-wrapper.component'; import { ChannelBoxComponent } from './channel/channel-box/channel-box.component'; +import { ChannelCloseBoxComponent } from './channel/channel-close-box/channel-close-box.component'; import { ClosingTypeComponent } from './channel/closing-type/closing-type.component'; import { LightningStatisticsChartComponent } from './statistics-chart/lightning-statistics-chart.component'; import { NodeStatisticsChartComponent } from './node-statistics-chart/node-statistics-chart.component'; @@ -45,6 +46,7 @@ import { GroupComponent } from './group/group.component'; ChannelComponent, LightningWrapperComponent, ChannelBoxComponent, + ChannelCloseBoxComponent, ClosingTypeComponent, LightningStatisticsChartComponent, NodesNetworksChartComponent, @@ -81,6 +83,7 @@ import { GroupComponent } from './group/group.component'; ChannelComponent, LightningWrapperComponent, ChannelBoxComponent, + ChannelCloseBoxComponent, ClosingTypeComponent, LightningStatisticsChartComponent, NodesNetworksChartComponent,