diff --git a/src/app/components/quick-connect-dialog/connection-selector/connection-selector.component.spec.ts b/src/app/components/quick-connect-dialog/connection-selector/connection-selector.component.spec.ts index 9215d5fe..eca46102 100644 --- a/src/app/components/quick-connect-dialog/connection-selector/connection-selector.component.spec.ts +++ b/src/app/components/quick-connect-dialog/connection-selector/connection-selector.component.spec.ts @@ -26,7 +26,7 @@ import { amountToDecimal } from 'app/utils/amount.converter'; import BigNumber from 'bignumber.js'; import { ClipboardModule } from 'ngx-clipboard'; import { clickElement, mockInput } from 'testing/interaction-helper'; -import { createSuggestedConnections, createToken } from 'testing/test-data'; +import { createTestSuggestedConnections, createToken } from 'testing/test-data'; import { TestProviders } from 'testing/test-providers'; import { ConnectionSelectorComponent } from './connection-selector.component'; @@ -40,7 +40,7 @@ describe('ConnectionSelectorComponent', () => { balance: new BigNumber('10000000000000000000'), }); const totalAmount = new BigNumber('3000000000000000000'); - const suggestions = createSuggestedConnections(); + const suggestions = createTestSuggestedConnections(); function initComponentForFakeAsync() { fixture.detectChanges(); diff --git a/src/app/components/quick-connect-dialog/quick-connect-dialog.component.spec.ts b/src/app/components/quick-connect-dialog/quick-connect-dialog.component.spec.ts index ab2fd353..2faf1bc5 100644 --- a/src/app/components/quick-connect-dialog/quick-connect-dialog.component.spec.ts +++ b/src/app/components/quick-connect-dialog/quick-connect-dialog.component.spec.ts @@ -41,7 +41,8 @@ import { createAddress, createChannel, createSettings, - createSuggestedConnections, + createSuggestedConnection, + createTestSuggestedConnections, createToken, } from 'testing/test-data'; import { TestProviders } from 'testing/test-providers'; @@ -59,7 +60,7 @@ describe('QuickConnectDialogComponent', () => { let component: QuickConnectDialogComponent; let fixture: ComponentFixture; - const suggestions = createSuggestedConnections(); + const suggestions = createTestSuggestedConnections(); const token = createToken({ decimals: 0, balance: new BigNumber(1000), @@ -69,6 +70,7 @@ describe('QuickConnectDialogComponent', () => { }, }); const tokenNetworkAddress = createAddress(); + const raidenAddress = createAddress(); const settings = createSettings(); const totalAmountInput = '70'; const totalAmountValue = amountFromDecimal( @@ -84,6 +86,9 @@ describe('QuickConnectDialogComponent', () => { spyOn(raidenService, 'getTokenNetworkAddress').and.returnValue( of(tokenNetworkAddress) ); + spyOnProperty(raidenService, 'raidenAddress').and.returnValue( + raidenAddress + ); settingsSubject = new BehaviorSubject(settings); spyOn(raidenService, 'getSettings').and.returnValue( settingsSubject.asObservable() @@ -260,6 +265,19 @@ describe('QuickConnectDialogComponent', () => { expect(component.suggestions).toEqual(suggestions.slice(1)); })); + it('should filter the suggestions by the address of the user account', fakeAsync(() => { + const suggestedConnections = [ + createSuggestedConnection({ address: raidenAddress }), + createSuggestedConnection(), + ]; + initComponentForFakeAsync(suggestedConnections); + + expect(component.suggestions.length).toEqual(1); + expect(component.suggestions).toEqual( + suggestedConnections.slice(1) + ); + })); + it('should show an error if there are no suggestions', fakeAsync(() => { initComponentForFakeAsync([]); diff --git a/src/app/components/quick-connect-dialog/quick-connect-dialog.component.ts b/src/app/components/quick-connect-dialog/quick-connect-dialog.component.ts index 429ebe27..6089e688 100644 --- a/src/app/components/quick-connect-dialog/quick-connect-dialog.component.ts +++ b/src/app/components/quick-connect-dialog/quick-connect-dialog.component.ts @@ -9,14 +9,7 @@ import { ChannelPollingService } from 'app/services/channel-polling.service'; import { RaidenService } from 'app/services/raiden.service'; import { TokenPollingService } from 'app/services/token-polling.service'; import BigNumber from 'bignumber.js'; -import { - combineLatest, - EMPTY, - Observable, - Subject, - throwError, - zip, -} from 'rxjs'; +import { combineLatest, EMPTY, Observable, Subject, zip } from 'rxjs'; import { catchError, delay, @@ -160,14 +153,16 @@ export class QuickConnectDialogComponent implements OnInit, OnDestroy { zip(suggestions$, existingChannels$) .pipe( map(([suggestions, channels]) => - suggestions.filter( - (suggestion) => - !channels.find( - (channel) => - channel.partner_address === - suggestion.address - ) - ) + suggestions.filter((suggestion) => { + const channelExisting = !!channels.find( + (channel) => + channel.partner_address === suggestion.address + ); + const isOwnAddress = + suggestion.address === + this.raidenService.raidenAddress; + return !channelExisting && !isOwnAddress; + }) ), catchError((error, caught) => { this.loading = false; diff --git a/src/testing/test-data.ts b/src/testing/test-data.ts index 8cab36df..bf5ef9e9 100644 --- a/src/testing/test-data.ts +++ b/src/testing/test-data.ts @@ -192,18 +192,23 @@ export function createContractsInfo(obj: any = {}): ContractsInfo { return Object.assign(contracts, obj); } -export function createSuggestedConnections( +export function createSuggestedConnection(obj: any = {}): SuggestedConnection { + const suggestedConnection: SuggestedConnection = { + address: createAddress(), + score: BigNumber.random(19).times(10 ** 19), + centrality: BigNumber.random(21), + uptime: BigNumber.random(5).times(10 ** 5), + capacity: BigNumber.random(19).times(10 ** 19), + }; + return Object.assign(suggestedConnection, obj); +} + +export function createTestSuggestedConnections( count: number = 5 ): SuggestedConnection[] { const suggestions: SuggestedConnection[] = []; for (let i = 0; i < count; i++) { - suggestions.push({ - address: createAddress(), - score: BigNumber.random(19).times(10 ** 19), - centrality: BigNumber.random(21), - uptime: BigNumber.random(5).times(10 ** 5), - capacity: BigNumber.random(19).times(10 ** 19), - }); + suggestions.push(createSuggestedConnection()); } suggestions.sort((a, b) => a.score.minus(b.score).toNumber()); return suggestions;