Skip to content

Commit 4400a13

Browse files
author
Aleix Morgadas
committed
upgraded to version 6.0
1 parent 2bc153f commit 4400a13

18 files changed

+232
-251
lines changed

e2e/service/MosaicService.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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';
1+
import { map, mergeMap, toArray } from 'rxjs/operators';
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';
88

99
describe('MosaicService', () => {
1010

@@ -17,10 +17,10 @@ describe('MosaicService', () => {
1717

1818
const address = Address.createFromRawAddress('SCO2JY-N6OJSM-CJPPVS-Z3OX7P-TWPQEJ-GZTI6W-GLKK');
1919

20-
return mosaicService.mosaicsAmountViewFromAddress(address)
21-
.flatMap((_) => _)
22-
.map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName()))
23-
.toArray()
24-
.toPromise();
20+
return mosaicService.mosaicsAmountViewFromAddress(address).pipe(
21+
mergeMap((_) => _),
22+
map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName())),
23+
toArray(),
24+
).toPromise();
2525
});
2626
});

src/infrastructure/AccountHttp.ts

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
*/
1616

1717
import {AccountRoutesApi} from 'nem2-library';
18-
import 'rxjs/add/observable/fromPromise';
19-
import 'rxjs/add/operator/map';
20-
import 'rxjs/add/operator/mergeMap';
21-
import {Observable} from 'rxjs/Observable';
18+
import {from as observableFrom, Observable} from 'rxjs';
19+
import {map, mergeMap} from 'rxjs/operators';
2220
import {AccountInfo} from '../model/account/AccountInfo';
2321
import {Address} from '../model/account/Address';
2422
import {MultisigAccountGraphInfo} from '../model/account/MultisigAccountGraphInfo';
@@ -64,7 +62,7 @@ export class AccountHttp extends Http implements AccountRepository {
6462
* @returns Observable<AccountInfo>
6563
*/
6664
public getAccountInfo(address: Address): Observable<AccountInfo> {
67-
return Observable.fromPromise(this.accountRoutesApi.getAccountInfo(address.plain())).map((accountInfoDTO) => {
65+
return observableFrom(this.accountRoutesApi.getAccountInfo(address.plain())).pipe(map((accountInfoDTO) => {
6866
return new AccountInfo(
6967
accountInfoDTO.meta,
7068
Address.createFromEncoded(accountInfoDTO.account.address),
@@ -78,7 +76,7 @@ export class AccountHttp extends Http implements AccountRepository {
7876
new UInt64(accountInfoDTO.account.importance),
7977
new UInt64(accountInfoDTO.account.importanceHeight),
8078
);
81-
});
79+
}));
8280
}
8381

8482
/**
@@ -90,8 +88,8 @@ export class AccountHttp extends Http implements AccountRepository {
9088
const accountIdsBody = {
9189
accountIds: addresses.map((address) => address.plain()),
9290
};
93-
return Observable.fromPromise(
94-
this.accountRoutesApi.getAccountsInfo(accountIdsBody)).map((accountsInfoMetaDataDTO) => {
91+
return observableFrom(
92+
this.accountRoutesApi.getAccountsInfo(accountIdsBody)).pipe(map((accountsInfoMetaDataDTO) => {
9593
return accountsInfoMetaDataDTO.map((accountInfoDTO) => {
9694
return new AccountInfo(
9795
accountInfoDTO.meta,
@@ -104,7 +102,7 @@ export class AccountHttp extends Http implements AccountRepository {
104102
new UInt64(accountInfoDTO.account.importanceHeight),
105103
);
106104
});
107-
});
105+
}));
108106
}
109107

110108
/**
@@ -113,9 +111,9 @@ export class AccountHttp extends Http implements AccountRepository {
113111
* @returns Observable<MultisigAccountInfo>
114112
*/
115113
public getMultisigAccountInfo(address: Address): Observable<MultisigAccountInfo> {
116-
return this.getNetworkTypeObservable()
117-
.flatMap((networkType) => Observable.fromPromise(
118-
this.accountRoutesApi.getAccountMultisig(address.plain())).map((multisigAccountInfoDTO) => {
114+
return this.getNetworkTypeObservable().pipe(
115+
mergeMap((networkType) => observableFrom(
116+
this.accountRoutesApi.getAccountMultisig(address.plain())).pipe(map((multisigAccountInfoDTO) => {
119117
return new MultisigAccountInfo(
120118
PublicAccount.createFromPublicKey(multisigAccountInfoDTO.multisig.account, networkType),
121119
multisigAccountInfoDTO.multisig.minApproval,
@@ -125,7 +123,7 @@ export class AccountHttp extends Http implements AccountRepository {
125123
multisigAccountInfoDTO.multisig.multisigAccounts
126124
.map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)),
127125
);
128-
}));
126+
}))));
129127
}
130128

131129
/**
@@ -134,9 +132,9 @@ export class AccountHttp extends Http implements AccountRepository {
134132
* @returns Observable<MultisigAccountGraphInfo>
135133
*/
136134
public getMultisigAccountGraphInfo(address: Address): Observable<MultisigAccountGraphInfo> {
137-
return this.getNetworkTypeObservable()
138-
.flatMap((networkType) => Observable.fromPromise(
139-
this.accountRoutesApi.getAccountMultisigGraph(address.plain())).map((multisigAccountGraphInfosDTO) => {
135+
return this.getNetworkTypeObservable().pipe(
136+
mergeMap((networkType) => observableFrom(
137+
this.accountRoutesApi.getAccountMultisigGraph(address.plain())).pipe(map((multisigAccountGraphInfosDTO) => {
140138
const multisigAccounts = new Map<number, MultisigAccountInfo[]>();
141139
multisigAccountGraphInfosDTO.map((multisigAccountGraphInfoDTO) => {
142140
multisigAccounts.set(multisigAccountGraphInfoDTO.level,
@@ -153,7 +151,7 @@ export class AccountHttp extends Http implements AccountRepository {
153151
);
154152
});
155153
return new MultisigAccountGraphInfo(multisigAccounts);
156-
}));
154+
}))));
157155
}
158156

159157
/**
@@ -164,13 +162,13 @@ export class AccountHttp extends Http implements AccountRepository {
164162
*/
165163
public transactions(publicAccount: PublicAccount,
166164
queryParams?: QueryParams): Observable<Transaction[]> {
167-
return Observable.fromPromise(
168-
this.accountRoutesApi.transactions(publicAccount.publicKey, queryParams != null ? queryParams : {}))
169-
.map((transactionsDTO) => {
165+
return observableFrom(
166+
this.accountRoutesApi.transactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
167+
map((transactionsDTO) => {
170168
return transactionsDTO.map((transactionDTO) => {
171169
return CreateTransactionFromDTO(transactionDTO);
172170
});
173-
});
171+
}));
174172
}
175173

176174
/**
@@ -182,13 +180,13 @@ export class AccountHttp extends Http implements AccountRepository {
182180
*/
183181
public incomingTransactions(publicAccount: PublicAccount,
184182
queryParams?: QueryParams): Observable<Transaction[]> {
185-
return Observable.fromPromise(
186-
this.accountRoutesApi.incomingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {}))
187-
.map((transactionsDTO) => {
183+
return observableFrom(
184+
this.accountRoutesApi.incomingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
185+
map((transactionsDTO) => {
188186
return transactionsDTO.map((transactionDTO) => {
189187
return CreateTransactionFromDTO(transactionDTO);
190188
});
191-
});
189+
}));
192190
}
193191

194192
/**
@@ -200,13 +198,13 @@ export class AccountHttp extends Http implements AccountRepository {
200198
*/
201199
public outgoingTransactions(publicAccount: PublicAccount,
202200
queryParams?: QueryParams): Observable<Transaction[]> {
203-
return Observable.fromPromise(
204-
this.accountRoutesApi.outgoingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {}))
205-
.map((transactionsDTO) => {
201+
return observableFrom(
202+
this.accountRoutesApi.outgoingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
203+
map((transactionsDTO) => {
206204
return transactionsDTO.map((transactionDTO) => {
207205
return CreateTransactionFromDTO(transactionDTO);
208206
});
209-
});
207+
}));
210208
}
211209

212210
/**
@@ -219,13 +217,13 @@ export class AccountHttp extends Http implements AccountRepository {
219217
*/
220218
public unconfirmedTransactions(publicAccount: PublicAccount,
221219
queryParams?: QueryParams): Observable<Transaction[]> {
222-
return Observable.fromPromise(
223-
this.accountRoutesApi.unconfirmedTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {}))
224-
.map((transactionsDTO) => {
220+
return observableFrom(
221+
this.accountRoutesApi.unconfirmedTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
222+
map((transactionsDTO) => {
225223
return transactionsDTO.map((transactionDTO) => {
226224
return CreateTransactionFromDTO(transactionDTO);
227225
});
228-
});
226+
}));
229227
}
230228

231229
/**
@@ -238,12 +236,12 @@ export class AccountHttp extends Http implements AccountRepository {
238236
public aggregateBondedTransactions(publicAccount: PublicAccount,
239237
queryParams?: QueryParams): Observable<AggregateTransaction[]> {
240238

241-
return Observable.fromPromise(
242-
this.accountRoutesApi.partialTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {}))
243-
.map((transactionsDTO) => {
239+
return observableFrom(
240+
this.accountRoutesApi.partialTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
241+
map((transactionsDTO) => {
244242
return transactionsDTO.map((transactionDTO) => {
245243
return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction;
246244
});
247-
});
245+
}));
248246
}
249247
}

src/infrastructure/AccountRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Observable} from 'rxjs/Observable';
17+
import {Observable} from 'rxjs';
1818
import {AccountInfo} from '../model/account/AccountInfo';
1919
import {Address} from '../model/account/Address';
2020
import {MultisigAccountGraphInfo} from '../model/account/MultisigAccountGraphInfo';

src/infrastructure/BlockchainHttp.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616

1717
import {BlockchainRoutesApi} from 'nem2-library';
18-
import 'rxjs/add/observable/fromPromise';
19-
import 'rxjs/add/operator/map';
20-
import {Observable} from 'rxjs/Observable';
18+
import {from as observableFrom, Observable} from 'rxjs';
19+
import {map} from 'rxjs/operators';
2120
import {PublicAccount} from '../model/account/PublicAccount';
2221
import {BlockchainScore} from '../model/blockchain/BlockchainScore';
2322
import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo';
@@ -56,7 +55,7 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
5655
* @returns Observable<BlockInfo>
5756
*/
5857
public getBlockByHeight(height: number): Observable<BlockInfo> {
59-
return Observable.fromPromise(this.blockchainRoutesApi.getBlockByHeight(height)).map((blockDTO) => {
58+
return observableFrom(this.blockchainRoutesApi.getBlockByHeight(height)).pipe(map((blockDTO) => {
6059
const networkType = parseInt(blockDTO.block.version.toString(16).substr(0, 2), 16);
6160
return new BlockInfo(
6261
blockDTO.meta.hash,
@@ -74,7 +73,7 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
7473
blockDTO.block.previousBlockHash,
7574
blockDTO.block.blockTransactionsHash,
7675
);
77-
});
76+
}));
7877
}
7978

8079
/**
@@ -85,12 +84,12 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
8584
*/
8685
public getBlockTransactions(height: number,
8786
queryParams?: QueryParams): Observable<Transaction[]> {
88-
return Observable.fromPromise(
89-
this.blockchainRoutesApi.getBlockTransactions(height, queryParams != null ? queryParams : {})).map((transactionsDTO) => {
87+
return observableFrom(
88+
this.blockchainRoutesApi.getBlockTransactions(height, queryParams != null ? queryParams : {})).pipe(map((transactionsDTO) => {
9089
return transactionsDTO.map((transactionDTO) => {
9190
return CreateTransactionFromDTO(transactionDTO);
9291
});
93-
});
92+
}));
9493
}
9594

9695
/**
@@ -100,8 +99,8 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
10099
* @returns Observable<BlockInfo[]>
101100
*/
102101
public getBlocksByHeightWithLimit(height: number, limit: number = 1): Observable<BlockInfo[]> {
103-
return Observable.fromPromise(
104-
this.blockchainRoutesApi.getBlocksByHeightWithLimit(height, limit)).map((blocksDTO) => {
102+
return observableFrom(
103+
this.blockchainRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe(map((blocksDTO) => {
105104
return blocksDTO.map((blockDTO) => {
106105
const networkType = parseInt(blockDTO.block.version.toString(16).substr(0, 2), 16);
107106
return new BlockInfo(
@@ -121,44 +120,44 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
121120
blockDTO.block.blockTransactionsHash,
122121
);
123122
});
124-
});
123+
}));
125124
}
126125

127126
/**
128127
* Gets current blockchain height
129128
* @returns Observable<UInt64>
130129
*/
131130
public getBlockchainHeight(): Observable<UInt64> {
132-
return Observable.fromPromise(this.blockchainRoutesApi.getBlockchainHeight()).map((heightDTO) => {
131+
return observableFrom(this.blockchainRoutesApi.getBlockchainHeight()).pipe(map((heightDTO) => {
133132
return new UInt64(heightDTO.height);
134-
});
133+
}));
135134
}
136135

137136
/**
138137
* Gets current blockchain score
139138
* @returns Observable<BlockchainScore>
140139
*/
141140
public getBlockchainScore(): Observable<BlockchainScore> {
142-
return Observable.fromPromise(this.blockchainRoutesApi.getBlockchainScore()).map((blockchainScoreDTO) => {
141+
return observableFrom(this.blockchainRoutesApi.getBlockchainScore()).pipe(map((blockchainScoreDTO) => {
143142
return new BlockchainScore(
144143
new UInt64(blockchainScoreDTO.scoreLow),
145144
new UInt64(blockchainScoreDTO.scoreHigh),
146145
);
147-
});
146+
}));
148147
}
149148

150149
/**
151150
* Gets blockchain storage info.
152151
* @returns Observable<BlockchainStorageInfo>
153152
*/
154153
public getDiagnosticStorage(): Observable<BlockchainStorageInfo> {
155-
return Observable.fromPromise(
156-
this.blockchainRoutesApi.getDiagnosticStorage()).map((blockchainStorageInfoDTO) => {
154+
return observableFrom(
155+
this.blockchainRoutesApi.getDiagnosticStorage()).pipe(map((blockchainStorageInfoDTO) => {
157156
return new BlockchainStorageInfo(
158157
blockchainStorageInfoDTO.numBlocks,
159158
blockchainStorageInfoDTO.numTransactions,
160159
blockchainStorageInfoDTO.numAccounts,
161160
);
162-
});
161+
}));
163162
}
164163
}

src/infrastructure/BlockchainRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Observable} from 'rxjs/Observable';
17+
import {Observable} from 'rxjs';
1818
import {BlockchainScore} from '../model/blockchain/BlockchainScore';
1919
import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo';
2020
import {BlockInfo} from '../model/blockchain/BlockInfo';

src/infrastructure/Http.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
import {ApiClient} from 'nem2-library';
18-
import 'rxjs/add/observable/of';
19-
import {Observable} from 'rxjs/Observable';
18+
import {Observable, of as observableOf} from 'rxjs';
19+
import {map} from 'rxjs/operators';
2020
import {NetworkType} from '../model/blockchain/NetworkType';
2121
import {NetworkHttp} from './NetworkHttp';
2222

@@ -50,12 +50,12 @@ export abstract class Http {
5050
getNetworkTypeObservable(): Observable<NetworkType> {
5151
let networkTypeResolve;
5252
if (this.networkType == null) {
53-
networkTypeResolve = this.networkHttp.getNetworkType().map((networkType) => {
53+
networkTypeResolve = this.networkHttp.getNetworkType().pipe(map((networkType) => {
5454
this.networkType = networkType;
5555
return networkType;
56-
});
56+
}));
5757
} else {
58-
networkTypeResolve = Observable.of(this.networkType);
58+
networkTypeResolve = observableOf(this.networkType);
5959
}
6060
return networkTypeResolve;
6161
}

0 commit comments

Comments
 (0)