Skip to content

Commit fe1beab

Browse files
committed
Open QuickConnectDialog from TokenComponent
1 parent 66f152b commit fe1beab

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

src/app/components/token/token.component.spec.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createAddress,
1515
createTestChannels,
1616
createTestTokens,
17+
createConnectionChoices,
1718
} from '../../../testing/test-data';
1819
import { By } from '@angular/platform-browser';
1920
import {
@@ -29,10 +30,6 @@ import {
2930
} from '../payment-dialog/payment-dialog.component';
3031
import BigNumber from 'bignumber.js';
3132
import { of, BehaviorSubject } from 'rxjs';
32-
import {
33-
ConnectionManagerDialogPayload,
34-
ConnectionManagerDialogComponent,
35-
} from '../connection-manager-dialog/connection-manager-dialog.component';
3633
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3734
import {
3835
ConfirmationDialogPayload,
@@ -45,6 +42,11 @@ import { ChannelPollingService } from '../../services/channel-polling.service';
4542
import { stub } from '../../../testing/stub';
4643
import { BalanceWithSymbolComponent } from '../balance-with-symbol/balance-with-symbol.component';
4744
import { TokenNetworkSelectorComponent } from '../token-network-selector/token-network-selector.component';
45+
import {
46+
QuickConnectDialogComponent,
47+
QuickConnectDialogPayload,
48+
QuickConnectDialogResult,
49+
} from '../quick-connect-dialog/quick-connect-dialog.component';
4850

4951
describe('TokenComponent', () => {
5052
let component: TokenComponent;
@@ -184,12 +186,12 @@ describe('TokenComponent', () => {
184186
fixture.detectChanges();
185187

186188
const dialogSpy = spyOn(dialog, 'open').and.callThrough();
187-
const dialogResult: ConnectionManagerDialogPayload = {
189+
const dialogResult: QuickConnectDialogResult = {
188190
token: unconnectedToken,
189-
funds: new BigNumber(10),
191+
connectionChoices: createConnectionChoices(),
190192
};
191193
spyOn(dialog, 'returns').and.returnValues(true, dialogResult);
192-
spyOn(raidenService, 'connectTokenNetwork').and.returnValue(
194+
spyOn(raidenService, 'openBatchOfChannels').and.returnValue(
193195
of(null)
194196
);
195197

@@ -201,9 +203,8 @@ describe('TokenComponent', () => {
201203
message:
202204
'Do you want to use quick connect to automatically open channels?',
203205
};
204-
const connectionManagerPayload: ConnectionManagerDialogPayload = {
206+
const quickConnectPayload: QuickConnectDialogPayload = {
205207
token: undefined,
206-
funds: undefined,
207208
};
208209
expect(dialogSpy).toHaveBeenCalledTimes(2);
209210
expect(dialogSpy.calls.first().args).toEqual([
@@ -213,9 +214,10 @@ describe('TokenComponent', () => {
213214
},
214215
]);
215216
expect(dialogSpy.calls.mostRecent().args).toEqual([
216-
ConnectionManagerDialogComponent,
217+
QuickConnectDialogComponent,
217218
{
218-
data: connectionManagerPayload,
219+
data: quickConnectPayload,
220+
width: '400px',
219221
},
220222
]);
221223
});
@@ -306,14 +308,14 @@ describe('TokenComponent', () => {
306308
fixture.detectChanges();
307309

308310
const dialogSpy = spyOn(dialog, 'open').and.callThrough();
309-
const dialogResult: ConnectionManagerDialogPayload = {
311+
const dialogResult: QuickConnectDialogResult = {
310312
token: unconnectedToken,
311-
funds: new BigNumber(10),
313+
connectionChoices: createConnectionChoices(),
312314
};
313315
spyOn(dialog, 'returns').and.returnValues(true, dialogResult);
314-
const connectSpy = spyOn(
316+
const openBatchSpy = spyOn(
315317
raidenService,
316-
'connectTokenNetwork'
318+
'openBatchOfChannels'
317319
).and.returnValue(of(null));
318320

319321
clickElement(fixture.debugElement, '#transfer');
@@ -323,9 +325,8 @@ describe('TokenComponent', () => {
323325
title: `No open ${unconnectedToken.symbol} channels`,
324326
message: `Do you want to use quick connect to automatically open ${unconnectedToken.symbol} channels?`,
325327
};
326-
const connectionManagerPayload: ConnectionManagerDialogPayload = {
328+
const quickConnectPayload: QuickConnectDialogPayload = {
327329
token: unconnectedToken,
328-
funds: undefined,
329330
};
330331
expect(dialogSpy).toHaveBeenCalledTimes(2);
331332
expect(dialogSpy.calls.first().args).toEqual([
@@ -335,15 +336,16 @@ describe('TokenComponent', () => {
335336
},
336337
]);
337338
expect(dialogSpy.calls.mostRecent().args).toEqual([
338-
ConnectionManagerDialogComponent,
339+
QuickConnectDialogComponent,
339340
{
340-
data: connectionManagerPayload,
341+
data: quickConnectPayload,
342+
width: '400px',
341343
},
342344
]);
343-
expect(connectSpy).toHaveBeenCalledTimes(1);
344-
expect(connectSpy).toHaveBeenCalledWith(
345-
dialogResult.funds,
346-
dialogResult.token.address
345+
expect(openBatchSpy).toHaveBeenCalledTimes(1);
346+
expect(openBatchSpy).toHaveBeenCalledWith(
347+
dialogResult.token,
348+
dialogResult.connectionChoices
347349
);
348350
});
349351

@@ -366,16 +368,16 @@ describe('TokenComponent', () => {
366368

367369
const dialogSpy = spyOn(dialog, 'open').and.callThrough();
368370
spyOn(dialog, 'returns').and.returnValues(true, null);
369-
const connectSpy = spyOn(
371+
const openBatchSpy = spyOn(
370372
raidenService,
371-
'connectTokenNetwork'
373+
'openBatchOfChannels'
372374
).and.returnValue(of(null));
373375

374376
clickElement(fixture.debugElement, '#transfer');
375377
fixture.detectChanges();
376378

377379
expect(dialogSpy).toHaveBeenCalledTimes(2);
378-
expect(connectSpy).toHaveBeenCalledTimes(0);
380+
expect(openBatchSpy).toHaveBeenCalledTimes(0);
379381
});
380382

381383
it('should mint 0.5 tokens when token has 18 decimals', () => {

src/app/components/token/token.component.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import {
1515
PaymentDialogPayload,
1616
PaymentDialogComponent,
1717
} from '../payment-dialog/payment-dialog.component';
18-
import {
19-
ConnectionManagerDialogPayload,
20-
ConnectionManagerDialogComponent,
21-
} from '../connection-manager-dialog/connection-manager-dialog.component';
2218
import { PendingTransferPollingService } from '../../services/pending-transfer-polling.service';
2319
import { ChannelPollingService } from '../../services/channel-polling.service';
2420
import { SelectedTokenService } from '../../services/selected-token.service';
2521
import { PaymentHistoryPollingService } from '../../services/payment-history-polling.service';
22+
import {
23+
QuickConnectDialogComponent,
24+
QuickConnectDialogPayload,
25+
QuickConnectDialogResult,
26+
} from '../quick-connect-dialog/quick-connect-dialog.component';
2627

2728
@Component({
2829
selector: 'app-token',
@@ -203,33 +204,33 @@ export class TokenComponent implements OnInit, OnDestroy {
203204

204205
dialog.afterClosed().subscribe((result) => {
205206
if (result) {
206-
this.openConnectionManager();
207+
this.openQuickConnect();
207208
}
208209
});
209210
}
210211

211-
private openConnectionManager() {
212-
const payload: ConnectionManagerDialogPayload = {
212+
private openQuickConnect() {
213+
const payload: QuickConnectDialogPayload = {
213214
token: this.selectedToken,
214-
funds: undefined,
215215
};
216216

217-
const dialog = this.dialog.open(ConnectionManagerDialogComponent, {
217+
const dialog = this.dialog.open(QuickConnectDialogComponent, {
218218
data: payload,
219+
width: '400px',
219220
});
220221

221222
dialog
222223
.afterClosed()
223224
.pipe(
224-
mergeMap((result: ConnectionManagerDialogPayload) => {
225+
mergeMap((result: QuickConnectDialogResult) => {
225226
if (!result) {
226227
return EMPTY;
227228
}
228229
this.selectedTokenService.setToken(result.token);
229230

230-
return this.raidenService.connectTokenNetwork(
231-
result.funds,
232-
result.token.address
231+
return this.raidenService.openBatchOfChannels(
232+
result.token,
233+
result.connectionChoices
233234
);
234235
})
235236
)

0 commit comments

Comments
 (0)