Skip to content

Commit f2ff7b1

Browse files
author
Aleix602
committed
FIX MosaicService mosaicsAmountView
1 parent ace648f commit f2ff7b1

File tree

4 files changed

+132
-9
lines changed

4 files changed

+132
-9
lines changed

e2e/service/MosaicService.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'rxjs/add/operator/toPromise';
2+
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
3+
import {MosaicHttp} from '../../src/infrastructure/MosaicHttp';
4+
import {NamespaceHttp} from '../../src/infrastructure/NamespaceHttp';
5+
import {Address} from '../../src/model/account/Address';
6+
import {MosaicService} from '../../src/service/MosaicService';
7+
import {APIUrl} from '../conf/conf.spec';
8+
9+
describe('MosaicService', () => {
10+
11+
it('should return the mosaic list skipping the expired mosaics', () => {
12+
const mosaicService = new MosaicService(
13+
new AccountHttp(APIUrl),
14+
new MosaicHttp(APIUrl),
15+
new NamespaceHttp(APIUrl),
16+
);
17+
18+
const address = Address.createFromRawAddress('SCO2JY-N6OJSM-CJPPVS-Z3OX7P-TWPQEJ-GZTI6W-GLKK');
19+
20+
return mosaicService.mosaicsAmountViewFromAddress(address)
21+
.flatMap((_) => _)
22+
.map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName()))
23+
.toArray()
24+
.toPromise();
25+
});
26+
});

package-lock.json

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nem2-sdk",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"description": "Reactive Nem2 sdk for typescript and javascript",
55
"scripts": {
66
"pretest": "npm run build",
@@ -32,20 +32,22 @@
3232
"typings": "dist/index.d.ts",
3333
"devDependencies": {
3434
"@types/chai": "^4.0.4",
35-
"@types/mocha": "^2.2.44",
3635
"@types/lodash": "^4.14.85",
37-
"@types/utf8": "^2.1.6",
36+
"@types/mocha": "^2.2.44",
3837
"@types/request": "^2.47.0",
3938
"@types/request-promise-native": "^1.0.14",
39+
"@types/utf8": "^2.1.6",
4040
"@types/ws": "^3.2.0",
4141
"assert": "^1.4.1",
4242
"chai": "^4.1.2",
4343
"coveralls": "^3.0.0",
4444
"mocha": "^4.0.1",
4545
"nyc": "^11.3.0",
4646
"ts-mockito": "^2.2.7",
47+
"ts-node": "^5.0.1",
4748
"tslint": "^5.8.0",
48-
"typescript": "^2.5.3"
49+
"typescript": "^2.5.3",
50+
"typescript-require": "^0.2.9-1"
4951
},
5052
"dependencies": {
5153
"js-joda": "^1.6.2",

src/service/MosaicService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import 'rxjs/add/observable/of';
1818
import 'rxjs/add/operator/catch';
19+
import 'rxjs/add/operator/filter';
1920
import 'rxjs/add/operator/mergeMap';
2021
import 'rxjs/add/operator/toArray';
2122
import {Observable} from 'rxjs/Observable';
@@ -71,16 +72,15 @@ export class MosaicService {
7172
mosaicsAmountView(mosaics: Mosaic[]): Observable<MosaicAmountView[]> {
7273
return Observable.of(mosaics)
7374
.flatMap((_) => _)
74-
.flatMap((mosaic) => this.mosaicsView([mosaic.id]).map((mosaicViews) => {
75+
.flatMap((mosaic) => this.mosaicsView([mosaic.id])
76+
.filter((_) => _.length !== 0)
77+
.map((mosaicViews) => {
7578
return new MosaicAmountView(mosaicViews[0].mosaicInfo,
7679
mosaicViews[0].namespaceName,
7780
mosaicViews[0].mosaicName,
7881
mosaic.amount);
7982
}))
80-
.toArray()
81-
.catch(() => {
82-
return Observable.of([]);
83-
});
83+
.toArray();
8484
}
8585

8686
/**

0 commit comments

Comments
 (0)