Remove derive {Struct,Vector}Any (new typing magic) (#1019)

* Remove derive {Struct,Vector}Any (new typing magic)

* Import ordering

* Small lint fix
This commit is contained in:
Jaco Greeff
2019-06-17 10:41:32 +02:00
committed by GitHub
parent 683ed396c2
commit 22bf06e6e0
11 changed files with 57 additions and 73 deletions
+3 -3
View File
@@ -5,7 +5,7 @@
import { combineLatest, of, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, StructAny, Option, VestingSchedule } from '@polkadot/types';
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, Option, VestingSchedule } from '@polkadot/types';
import { bnMax } from '@polkadot/util';
import { idAndIndex } from '../accounts/idAndIndex';
@@ -44,7 +44,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
// (most probably due to movements from stash -> controller -> free)
const availableBalance = bnMax(ZERO, vestedBalance.sub(lockedBalance));
return new StructAny({
return {
accountId,
accountNonce,
availableBalance,
@@ -53,7 +53,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
reservedBalance,
vestedBalance,
votingBalance: freeBalance.add(reservedBalance)
}) as DerivedBalances;
} as DerivedBalances;
}
/**
+7 -9
View File
@@ -8,7 +8,6 @@ import { DerivedFees } from '../types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { StructAny } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -34,14 +33,13 @@ export function fees (api: ApiInterface$Rx) {
api.query.balances.transactionByteFee,
api.query.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>).pipe(
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) =>
new StructAny({
creationFee,
existentialDeposit,
transactionBaseFee,
transactionByteFee,
transferFee
}) as DerivedFees),
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => ({
creationFee,
existentialDeposit,
transactionBaseFee,
transactionByteFee,
transferFee
} as DerivedFees)),
drr()
);
};
@@ -3,24 +3,20 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { combineLatest, Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, VectorAny } from '@polkadot/types';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { DerivedBalances } from '../types';
import { drr } from '../util/drr';
import { all } from './all';
export function votingBalances (api: ApiInterface$Rx) {
return (addresses?: Array<AccountId | AccountIndex | Address | string>): Observable<VectorAny<DerivedBalances>> => {
return (addresses?: Array<AccountId | AccountIndex | Address | string>): Observable<Array<DerivedBalances>> => {
return (
!addresses || !addresses.length
? of([] as Array<DerivedBalances>)
: combineLatest(addresses.map(all(api)))
).pipe(
map((balances) =>
new VectorAny(...balances)
),
drr()
);
};
@@ -5,7 +5,7 @@
import { Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Vector, VectorAny } from '@polkadot/types';
import { AccountId, AccountIndex, Address, Vector } from '@polkadot/types';
import { idAndIndex } from '../accounts/idAndIndex';
import { DerivedBalances } from '../types';
@@ -13,7 +13,7 @@ import { drr } from '../util/drr';
import { votingBalances } from './votingBalances';
export function votingBalancesNominatorsFor (api: ApiInterface$Rx) {
return (address: AccountId | AccountIndex | Address | string): Observable<VectorAny<DerivedBalances>> => {
return (address: AccountId | AccountIndex | Address | string): Observable<Array<DerivedBalances>> => {
return idAndIndex(api)(address).pipe(
switchMap(([accountId]) =>
accountId