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

Connection manager replacement #573

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('ChannelListComponent', () => {

const dialogSpy = spyOn(dialog, 'open').and.callThrough();
const dialogResult: OpenDialogResult = {
tokenAddress: token1.address,
token: token1,
partnerAddress: createAddress(),
balance: new BigNumber(1000),
settleTimeout: raidenConfig.config.settle_timeout,
Expand All @@ -226,7 +226,7 @@ describe('ChannelListComponent', () => {
clickElement(fixture.debugElement, '#open-channel');

const payload: OpenDialogPayload = {
tokenAddress: '',
token: undefined,
defaultSettleTimeout: raidenConfig.config.settle_timeout,
revealTimeout: raidenConfig.config.reveal_timeout,
};
Expand All @@ -236,7 +236,7 @@ describe('ChannelListComponent', () => {
});
expect(openSpy).toHaveBeenCalledTimes(1);
expect(openSpy).toHaveBeenCalledWith(
dialogResult.tokenAddress,
dialogResult.token.address,
dialogResult.partnerAddress,
dialogResult.settleTimeout,
dialogResult.balance
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('ChannelListComponent', () => {
clickElement(fixture.debugElement, '#open-channel');

const payload: OpenDialogPayload = {
tokenAddress: token1.address,
token: token1,
defaultSettleTimeout: raidenConfig.config.settle_timeout,
revealTimeout: raidenConfig.config.reveal_timeout,
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/channel-list/channel-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AfterViewInit,
} from '@angular/core';
import { Channel } from '../../models/channel';
import { EMPTY, Subject, Observable, fromEvent } from 'rxjs';
import { EMPTY, Subject, fromEvent } from 'rxjs';
import { ChannelPollingService } from '../../services/channel-polling.service';
import { amountToDecimal } from '../../utils/amount.converter';
import { UserToken } from '../../models/usertoken';
Expand Down Expand Up @@ -120,7 +120,7 @@ export class ChannelListComponent implements OnInit, OnDestroy, AfterViewInit {
const rdnConfig = this.raidenConfig.config;

const payload: OpenDialogPayload = {
tokenAddress: this.selectedToken ? this.selectedToken.address : '',
token: this.selectedToken,
revealTimeout: rdnConfig.reveal_timeout,
defaultSettleTimeout: rdnConfig.settle_timeout,
};
Expand All @@ -138,7 +138,7 @@ export class ChannelListComponent implements OnInit, OnDestroy, AfterViewInit {
}

return this.raidenService.openChannel(
result.tokenAddress,
result.token.address,
result.partnerAddress,
result.settleTimeout,
result.balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('ContactActionsComponent', () => {
it('should open payment dialog', () => {
const dialogSpy = spyOn(dialog, 'open').and.callThrough();
const dialogResult: PaymentDialogPayload = {
tokenAddress: token.address,
token: token,
targetAddress: contact.address,
amount: new BigNumber(10),
paymentIdentifier: undefined,
Expand All @@ -126,7 +126,7 @@ describe('ContactActionsComponent', () => {
clickElement(fixture.debugElement, '#transfer');

const payload: PaymentDialogPayload = {
tokenAddress: '',
token: undefined,
targetAddress: contact.address,
amount: undefined,
};
Expand All @@ -136,7 +136,7 @@ describe('ContactActionsComponent', () => {
});
expect(initiatePaymentSpy).toHaveBeenCalledTimes(1);
expect(initiatePaymentSpy).toHaveBeenCalledWith(
dialogResult.tokenAddress,
dialogResult.token.address,
dialogResult.targetAddress,
dialogResult.amount,
dialogResult.paymentIdentifier
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('ContactActionsComponent', () => {
clickElement(fixture.debugElement, '#transfer');

const payload: PaymentDialogPayload = {
tokenAddress: connectedToken.address,
token: connectedToken,
targetAddress: contact.address,
amount: undefined,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ContactActionsComponent implements OnInit, OnDestroy {
this.actionClicked.emit(true);

const payload: PaymentDialogPayload = {
tokenAddress: this.selectedToken ? this.selectedToken.address : '',
token: this.selectedToken,
targetAddress: this.contact.address,
amount: undefined,
};
Expand All @@ -111,7 +111,7 @@ export class ContactActionsComponent implements OnInit, OnDestroy {
}

return this.raidenService.initiatePayment(
result.tokenAddress,
result.token.address,
result.targetAddress,
result.amount,
result.paymentIdentifier
Expand Down
1 change: 0 additions & 1 deletion src/app/components/open-dialog/open-dialog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
>
<app-token-network-selector
formControlName="token"
(tokenChanged)="tokenNetworkSelected($event)"
[showOnChainBalance]="true"
>
</app-token-network-selector>
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/open-dialog/open-dialog.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('OpenDialogComponent', () => {
beforeEach(
waitForAsync(() => {
const payload: OpenDialogPayload = {
tokenAddress: token.address,
token: token,
defaultSettleTimeout: defaultSettleTimeout,
revealTimeout: revealTimeout,
};
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('OpenDialogComponent', () => {

expect(closeSpy).toHaveBeenCalledTimes(1);
expect(closeSpy).toHaveBeenCalledWith({
tokenAddress: token.address,
token: token,
partnerAddress: addressInput,
settleTimeout: defaultSettleTimeout,
balance: new BigNumber(amountInput),
Expand Down
52 changes: 27 additions & 25 deletions src/app/components/open-dialog/open-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject, ViewChild, OnDestroy } from '@angular/core';
import { Component, Inject, ViewChild, OnDestroy, OnInit } from '@angular/core';
import {
AbstractControl,
FormBuilder,
Expand All @@ -14,19 +14,19 @@ import BigNumber from 'bignumber.js';
import { Animations } from '../../animations/animations';
import { TokenPollingService } from '../../services/token-polling.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { switchMap, takeUntil, tap } from 'rxjs/operators';

export interface OpenDialogPayload {
readonly tokenAddress: string;
readonly token: UserToken;
readonly defaultSettleTimeout: number;
readonly revealTimeout: number;
}

export interface OpenDialogResult {
tokenAddress: string;
partnerAddress: string;
settleTimeout: number;
balance: BigNumber;
readonly token: UserToken;
readonly partnerAddress: string;
readonly settleTimeout: number;
readonly balance: BigNumber;
}

@Component({
Expand All @@ -35,7 +35,7 @@ export interface OpenDialogResult {
styleUrls: ['./open-dialog.component.scss'],
animations: Animations.fallDown,
})
export class OpenDialogComponent implements OnDestroy {
export class OpenDialogComponent implements OnInit, OnDestroy {
@ViewChild(TokenInputComponent, { static: true })
private tokenInput: TokenInputComponent;

Expand All @@ -53,7 +53,7 @@ export class OpenDialogComponent implements OnDestroy {
this.revealTimeout = data.revealTimeout;
this.form = this.fb.group({
address: ['', Validators.required],
token: [data.tokenAddress, Validators.required],
token: [data.token, Validators.required],
amount: ['', Validators.required],
settle_timeout: [
data.defaultSettleTimeout,
Expand All @@ -66,6 +66,23 @@ export class OpenDialogComponent implements OnDestroy {
});
}

ngOnInit() {
this.form.controls.token.valueChanges
.pipe(
tap((token) => (this.tokenInput.selectedToken = token)),
switchMap((token) =>
this.tokenPollingService.getTokenUpdates(
token?.address ?? ''
)
),
takeUntil(this.ngUnsubscribe)
)
.subscribe((updatedToken) => {
this.tokenInput.maxAmount = updatedToken?.balance;
});
this.form.controls.token.updateValueAndValidity();
}

ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
Expand All @@ -74,7 +91,7 @@ export class OpenDialogComponent implements OnDestroy {
accept() {
const value = this.form.value;
const result: OpenDialogResult = {
tokenAddress: value.token,
token: value.token,
partnerAddress: value.address,
settleTimeout: value.settle_timeout,
balance: value.amount,
Expand All @@ -87,21 +104,6 @@ export class OpenDialogComponent implements OnDestroy {
this.dialogRef.close();
}

tokenNetworkSelected(token: UserToken) {
this.tokenInput.selectedToken = token;
this.subscribeToTokenUpdates(token.address);
}

subscribeToTokenUpdates(tokenAddress: string) {
this.ngUnsubscribe.next();
this.tokenPollingService
.getTokenUpdates(tokenAddress)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe((updatedToken: UserToken) => {
this.tokenInput.maxAmount = updatedToken.balance;
});
}

private settleTimeoutValidator(): ValidatorFn {
return (control: AbstractControl): ValidationErrors => {
const value = parseInt(control.value, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
>
<app-token-network-selector
formControlName="token"
(tokenChanged)="tokenNetworkSelected($event)"
[onlyConnectedTokens]="true"
>
</app-token-network-selector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('PaymentDialogComponent', () => {
beforeEach(
waitForAsync(() => {
const payload: PaymentDialogPayload = {
tokenAddress: '',
token: undefined,
amount: undefined,
targetAddress: '',
};
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('PaymentDialogComponent', () => {

expect(closeSpy).toHaveBeenCalledTimes(1);
expect(closeSpy).toHaveBeenCalledWith({
tokenAddress: token.address,
token: token,
targetAddress: addressInput,
amount: new BigNumber(amountInput),
paymentIdentifier: undefined,
Expand All @@ -202,7 +202,7 @@ describe('PaymentDialogComponent', () => {

expect(closeSpy).toHaveBeenCalledTimes(1);
expect(closeSpy).toHaveBeenCalledWith({
tokenAddress: token.address,
token: token,
targetAddress: addressInput,
amount: new BigNumber(amountInput),
paymentIdentifier: new BigNumber(identifierInput),
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('PaymentDialogComponent', () => {
});
expect(close).toHaveBeenCalledTimes(1);
expect(close).toHaveBeenCalledWith({
tokenAddress: token.address,
token: token,
targetAddress: addressInput,
amount: new BigNumber(amountInput),
paymentIdentifier: new BigNumber(identifierInput),
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('PaymentDialogComponent', () => {
expect(dialogSpy).toHaveBeenCalledTimes(0);
expect(closeSpy).toHaveBeenCalledTimes(1);
expect(closeSpy).toHaveBeenCalledWith({
tokenAddress: token.address,
token: token,
targetAddress: addressInput,
amount: new BigNumber(amountInput),
paymentIdentifier: differentIdentifier,
Expand Down
Loading