1515 */
1616
1717import { 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' ;
2220import { AccountInfo } from '../model/account/AccountInfo' ;
2321import { Address } from '../model/account/Address' ;
2422import { 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}
0 commit comments