Skip to content

Commit 9cb940e

Browse files
kelsosandrevmatos
authored andcommitted
Add identicon caching to the webui
1 parent d68f002 commit 9cb940e

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

raiden/ui/web/src/app/components/channel-table/channel-table.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { animate, state, style, transition, trigger } from '@angular/animations';
22
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
33
import { MatDialog, MatPaginator, PageEvent } from '@angular/material';
4-
import { default as makeBlockie } from 'ethereum-blockies-base64';
54
import { EMPTY, Subscription } from 'rxjs';
65
import { Observable } from 'rxjs/internal/Observable';
76
import { flatMap } from 'rxjs/operators';
87
import { Channel } from '../../models/channel';
98
import { SortingData } from '../../models/sorting.data';
109
import { ChannelPollingService } from '../../services/channel-polling.service';
10+
import { IdenticonCacheService } from '../../services/identicon-cache.service';
1111
import { RaidenConfig } from '../../services/raiden.config';
1212
import { RaidenService } from '../../services/raiden.service';
1313
import { StringUtils } from '../../utils/string.utils';
@@ -89,7 +89,8 @@ export class ChannelTableComponent implements OnInit, OnDestroy {
8989
public dialog: MatDialog,
9090
private raidenConfig: RaidenConfig,
9191
private raidenService: RaidenService,
92-
private channelPollingService: ChannelPollingService
92+
private channelPollingService: ChannelPollingService,
93+
private identiconCacheService: IdenticonCacheService
9394
) {
9495
}
9596

@@ -137,7 +138,7 @@ export class ChannelTableComponent implements OnInit, OnDestroy {
137138

138139
// noinspection JSMethodCanBeStatic
139140
identicon(channel: Channel): string {
140-
return makeBlockie(channel.partner_address);
141+
return this.identiconCacheService.getIdenticon(channel.partner_address);
141142
}
142143

143144
public onPay(channel: Channel) {

raiden/ui/web/src/app/components/open-dialog/open-dialog.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Component, Inject, OnInit } from '@angular/core';
22
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
33
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
44
import { BigNumber } from 'bignumber.js';
5-
import { default as makeBlockie } from 'ethereum-blockies-base64';
65
import { from, Observable } from 'rxjs';
76
import { filter, flatMap, share, startWith, takeWhile, toArray } from 'rxjs/operators';
87
import { UserToken } from '../../models/usertoken';
8+
import { IdenticonCacheService } from '../../services/identicon-cache.service';
99
import { RaidenService } from '../../services/raiden.service';
1010

1111
export class OpenDialogPayload {
@@ -45,6 +45,7 @@ export class OpenDialogComponent implements OnInit {
4545
@Inject(MAT_DIALOG_DATA) public data: OpenDialogPayload,
4646
public dialogRef: MatDialogRef<OpenDialogComponent>,
4747
public raidenService: RaidenService,
48+
private identiconCacheService: IdenticonCacheService,
4849
private fb: FormBuilder,
4950
) {
5051
}
@@ -128,7 +129,7 @@ export class OpenDialogComponent implements OnInit {
128129
if (!address) {
129130
return '';
130131
}
131-
return makeBlockie(address);
132+
return this.identiconCacheService.getIdenticon(address);
132133
}
133134

134135
tokenSelected(value: UserToken) {

raiden/ui/web/src/app/components/payment-dialog/payment-dialog.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h1 mat-dialog-title>Pay</h1>
4949
<mat-autocomplete #auto="matAutocomplete"
5050
[autoActiveFirstOption]="'true'"
5151
(optionSelected)="tokenSelected($event.option.value)">
52-
<mat-option *ngFor="let option of filteredOptions$ | async"
52+
<mat-option *ngFor="let option of filteredOptions$ | async; trackBy: trackByFn"
5353
[value]="option">
5454
{{option | token }}
5555
</mat-option>

raiden/ui/web/src/app/components/payment-dialog/payment-dialog.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Component, Inject, OnInit } from '@angular/core';
22
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
33
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
44
import { BigNumber } from 'bignumber.js';
5-
import { default as makeBlockie } from 'ethereum-blockies-base64';
65
import { from, Observable } from 'rxjs';
76
import { filter, flatMap, share, startWith, toArray } from 'rxjs/operators';
87
import { UserToken } from '../../models/usertoken';
98
import { TokenPipe } from '../../pipes/token.pipe';
9+
import { IdenticonCacheService } from '../../services/identicon-cache.service';
1010

1111
import { RaidenService } from '../../services/raiden.service';
1212

@@ -40,6 +40,7 @@ export class PaymentDialogComponent implements OnInit {
4040
@Inject(MAT_DIALOG_DATA) public data: PaymentDialogPayload,
4141
public dialogRef: MatDialogRef<PaymentDialogComponent>,
4242
private raidenService: RaidenService,
43+
private identiconCacheService: IdenticonCacheService,
4344
private fb: FormBuilder
4445
) {
4546
this.tokenPipe = new TokenPipe();
@@ -120,7 +121,12 @@ export class PaymentDialogComponent implements OnInit {
120121
if (!address) {
121122
return '';
122123
}
123-
return makeBlockie(address);
124+
return this.identiconCacheService.getIdenticon(address);
125+
}
126+
127+
// noinspection JSMethodCanBeStatic
128+
trackByFn(token: UserToken): string {
129+
return token.address;
124130
}
125131

126132
private _filter(value?: string): Observable<UserToken[]> {

raiden/ui/web/src/app/services/channel-polling.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class ChannelPollingService {
4141
this.checkForNewChannels(oldChannels, newChannels);
4242
return newChannels;
4343
}, []),
44-
tap(console.log),
4544
share()
4645
);
4746
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { IdenticonCacheService } from './identicon-cache.service';
4+
5+
describe('IdenticonCacheService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [IdenticonCacheService]
9+
});
10+
});
11+
12+
it('should be created', inject([IdenticonCacheService], (service: IdenticonCacheService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Injectable } from '@angular/core';
2+
import makeBlockie from 'ethereum-blockies-base64';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class IdenticonCacheService {
8+
9+
private cache: { [id: string]: string } = {};
10+
11+
constructor() {
12+
}
13+
14+
public getIdenticon(address: string): string {
15+
const cached = this.cache[address];
16+
17+
if (!cached) {
18+
const generated = makeBlockie(address);
19+
this.cache[address] = generated;
20+
return generated;
21+
} else {
22+
return cached;
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)