Skip to content

Commit 4b1a034

Browse files
committed
Small improvements to AccountDialogComponent
1 parent 03bf236 commit 4b1a034

5 files changed

Lines changed: 30 additions & 29 deletions

File tree

src/app/components/account-dialog/account-dialog.component.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ describe('AccountDialogComponent', () => {
194194
fixture.detectChanges();
195195
tick();
196196
fixture.detectChanges();
197-
spyOn(web3Mock.eth, 'requestAccounts').and.rejectWith();
197+
spyOn(web3Mock.eth, 'requestAccounts').and.rejectWith(
198+
new Error('User rejected.')
199+
);
198200
clickElement(fixture.debugElement, '#accept');
199201
fixture.detectChanges();
200202
tick();

src/app/components/account-dialog/account-dialog.component.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ export class AccountDialogComponent implements OnInit, OnDestroy {
135135
filter((provider) => !!provider),
136136
map((provider: any) => this.web3Factory.create(provider)),
137137
tap((web3) => (this.web3 = web3)),
138-
switchMap((web3) =>
139-
from<Promise<string[]>>(web3.eth.getAccounts())
140-
)
138+
switchMap(async (web3) => web3.eth.getAccounts())
141139
)
142140
.subscribe((accounts) => {
143141
if (accounts.length > 0) {
@@ -171,7 +169,7 @@ export class AccountDialogComponent implements OnInit, OnDestroy {
171169
).toFixed();
172170
let notificationIdentifier: number;
173171

174-
defer(() => {
172+
defer(async () => {
175173
this.dialogRef.close();
176174
notificationIdentifier = this.notificationService.addPendingAction({
177175
title: `Sending ${symbol} to account`,
@@ -185,23 +183,19 @@ export class AccountDialogComponent implements OnInit, OnDestroy {
185183
).toFixed();
186184

187185
if (this.ethSelected) {
188-
return from(
189-
this.web3.eth.sendTransaction({
190-
from: this.defaultAccount,
191-
to: raidenAddress,
192-
value: transferValue,
193-
})
194-
);
186+
return this.web3.eth.sendTransaction({
187+
from: this.defaultAccount,
188+
to: raidenAddress,
189+
value: transferValue,
190+
});
195191
} else {
196192
const tokenContract = new this.web3.eth.Contract(
197193
tokenabi,
198194
this.token.address
199195
);
200-
return from(
201-
tokenContract.methods
202-
.transfer(raidenAddress, transferValue)
203-
.send({ from: this.defaultAccount })
204-
);
196+
return tokenContract.methods
197+
.transfer(raidenAddress, transferValue)
198+
.send({ from: this.defaultAccount });
205199
}
206200
})
207201
.pipe(
@@ -232,8 +226,8 @@ export class AccountDialogComponent implements OnInit, OnDestroy {
232226
}
233227

234228
private connectWallet() {
235-
const requestAccounts$ = defer(() =>
236-
from(this.web3.eth.requestAccounts())
229+
const requestAccounts$ = defer(async () =>
230+
this.web3.eth.requestAccounts()
237231
).pipe(
238232
catchError((error) => {
239233
this.accountRequestRejected = true;
@@ -245,24 +239,21 @@ export class AccountDialogComponent implements OnInit, OnDestroy {
245239
this.requesting = true;
246240
this.accountRequestRejected = false;
247241
this.wrongChainID = false;
248-
return zip(
249-
from(this.web3.eth.getChainId()),
250-
this.raidenService.network$
251-
);
242+
return zip(this.web3.eth.getChainId(), this.raidenService.network$);
252243
})
253244
.pipe(
254245
switchMap(([web3ChainId, network]) => {
255246
if (web3ChainId !== network.chainId) {
256247
this.wrongChainID = true;
257-
return throwError('Chain ids not matching.');
248+
throw new Error('Chain ids not matching.');
258249
}
259250
return requestAccounts$;
260251
}),
261252
finalize(() => (this.requesting = false))
262253
)
263254
.subscribe({
264255
next: (accounts) => (this.defaultAccount = accounts[0]),
265-
error: console.error,
256+
error: (error) => console.error(error?.message),
266257
});
267258
}
268259
}

src/app/components/token-network-selector/token-network-selector.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ export class TokenNetworkSelectorComponent
6565
this.tokens$,
6666
this.userDepositService.servicesToken$,
6767
]).pipe(
68-
map(([tokens, servicesToken]) => [servicesToken, ...tokens])
68+
map(([tokens, servicesToken]) => {
69+
const servicesTokenRegistered = !!tokens.find(
70+
(item) => servicesToken.address === item.address
71+
);
72+
if (servicesTokenRegistered) {
73+
return tokens;
74+
}
75+
return [servicesToken, ...tokens];
76+
})
6977
);
7078
}
7179
}

src/app/pipes/shorten-address.pipe.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ describe('ShortenAddressPipe', () => {
1818
it('should return the address truncated to 6 characters without touching the 0x prefix', function () {
1919
expect(
2020
pipe.transform('0x0123456789012345678901234567890123456789')
21-
).toEqual('0x012...789');
21+
).toEqual('0x012789');
2222
});
2323

2424
it('should return the value truncated', function () {
25-
expect(pipe.transform('12345678', 4)).toEqual('12...78');
25+
expect(pipe.transform('12345678', 4)).toEqual('1278');
2626
});
2727

2828
it('should return an empty string if no value', function () {

src/app/pipes/shorten-address.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Pipe, PipeTransform } from '@angular/core';
55
})
66
export class ShortenAddressPipe implements PipeTransform {
77
transform(value?: string, width: number = 6): string {
8-
const separator = '...';
8+
const separator = '';
99
if (!value) {
1010
return '';
1111
} else if (value.length <= width) {

0 commit comments

Comments
 (0)