Refactor api-promise/rx (#566)

* Use a generic abstract OnCall

* Add OnCall for Promise

* First run at fixing extrinsics

* Fix types

* Make submittable extrinsic work

* Move file

* Make derive work

* Fix types

* Only call metadata once

* Make tests pass

* Put event emitter in apirx

* Fix small bugs

* Fix tests

* Fix bug decorateStorage

* Make tests pass for tx

* Move rpc base to apirx

* Fix lint

* Fix small bugs

* Fix bug with isSubscription

* Fix codeclimate

* Revert

* Add tslint disable line

* Fix lint

* Skip e2e

* Typo

* Lint

* Re-add combinator back

* Add ._rx in Base

* Make extrinsics work

* Update derivex

* Fix bug lint

* Fix circular dep

* Fix bug e2e

* Remove useless check

* Add description comment

* Clean stuff

* Move assert to Base

* Bump version, update CHANGELOG

* Make _rx private

* Private emit
This commit is contained in:
Amaury Martiny
2019-01-16 15:42:59 +01:00
committed by Jaco Greeff
parent 38d2d06772
commit d07ed8ac38
49 changed files with 523 additions and 617 deletions
@@ -4,7 +4,7 @@
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { decodeAddress } from '@polkadot/keyring';
import { AccountId, AccountIndex } from '@polkadot/types/index';
@@ -14,7 +14,7 @@ import { drr } from '../util/drr';
export type IdAndIndex = [AccountId | undefined, AccountIndex | undefined];
export function accountIdAndIndex (api: ApiRx) {
export function accountIdAndIndex (api: ApiInterface$Rx) {
return (address: AccountId | AccountIndex | string | null | undefined)
: Observable<(AccountIndex | AccountId | undefined)[]> => {
try {
@@ -4,13 +4,13 @@
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex } from '@polkadot/types/index';
import { accountIndexes, AccountIndexes } from './accountIndexes';
import { drr } from '../util/drr';
export function accountIdToIndex (api: ApiRx) {
export function accountIdToIndex (api: ApiInterface$Rx) {
return (accountId: AccountId | string): Observable<AccountIndex> =>
accountIndexes(api)()
.pipe(
@@ -4,14 +4,14 @@
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
import { Vector } from '@polkadot/types/codec';
import { AccountId, AccountIndex } from '@polkadot/types/index';
import { drr } from '../util/drr';
export function accountIndexToId (api: ApiRx) {
export function accountIndexToId (api: ApiInterface$Rx) {
return (accountIndex: AccountIndex | string): Observable<AccountId> => {
const _accountIndex = accountIndex instanceof AccountIndex
? accountIndex
@@ -5,7 +5,7 @@
import BN from 'bn.js';
import { combineLatest, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
import { AccountId, AccountIndex } from '@polkadot/types/index';
@@ -13,7 +13,7 @@ import { drr } from '../util/drr';
export type AccountIndexes = { [index: string]: AccountIndex };
export function accountIndexes (api: ApiRx) {
export function accountIndexes (api: ApiInterface$Rx) {
return (): Observable<AccountIndexes> =>
(api.query.balances.nextEnumSet() as Observable<AccountIndex>)
.pipe(
+2 -2
View File
@@ -5,11 +5,11 @@
import BN from 'bn.js';
import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { drr } from '../util/drr';
export function fees (api: ApiRx) {
export function fees (api: ApiInterface$Rx) {
return () =>
combineLatest(
api.query.balances.creationFee(),
@@ -5,7 +5,7 @@
import BN from 'bn.js';
import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, Balance } from '@polkadot/types/index';
import { DerivedBalances } from '../types';
@@ -13,7 +13,7 @@ import { drr } from '../util/drr';
import { votingBalance } from './votingBalance';
import { votingBalancesNominatorsFor } from './votingBalancesNominatorsFor';
export function validatingBalance (api: ApiRx) {
export function validatingBalance (api: ApiInterface$Rx) {
return (address: AccountId | string): Observable<DerivedBalances> =>
combineLatest(
votingBalance(api)(address),
@@ -4,14 +4,14 @@
import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId } from '@polkadot/types/index';
import { DerivedBalancesMap } from '../types';
import { drr } from '../util/drr';
import { validatingBalance } from './validatingBalance';
export function validatingBalances (api: ApiRx) {
export function validatingBalances (api: ApiInterface$Rx) {
return (...params: Array<any>): Observable<DerivedBalancesMap> => {
const accountIds: Array<AccountId | string> = params.slice(0, params.length - 1);
@@ -4,7 +4,7 @@
import { combineLatest, of, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Balance } from '@polkadot/types/index';
import { accountIdAndIndex } from './accountIdAndIndex';
@@ -13,7 +13,7 @@ import { drr } from '../util/drr';
const EMPTY_ACCOUNT = new AccountId(new Uint8Array(32));
export function votingBalance (api: ApiRx) {
export function votingBalance (api: ApiInterface$Rx) {
return (address: AccountIndex | AccountId | string): Observable<DerivedBalances> =>
accountIdAndIndex(api)(address).pipe(
switchMap(([accountId]) =>
@@ -3,14 +3,14 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { combineLatest, Observable } from 'rxjs';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex } from '@polkadot/types/index';
import { DerivedBalances } from '../types';
import { drr } from '../util/drr';
import { votingBalance } from './votingBalance';
export function votingBalances (api: ApiRx) {
export function votingBalances (api: ApiInterface$Rx) {
return (...params: Array<any>): Observable<Array<DerivedBalances>> => {
const addresses: Array<AccountIndex | AccountId | string> = params.slice(0, params.length - 1);
@@ -4,14 +4,14 @@
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId } from '@polkadot/types/index';
import { DerivedBalances } from '../types';
import { drr } from '../util/drr';
import { votingBalances } from './votingBalances';
export function votingBalancesNominatorsFor (api: ApiRx) {
export function votingBalancesNominatorsFor (api: ApiInterface$Rx) {
return (accountId: AccountId | string): Observable<Array<DerivedBalances>> =>
(api.query.staking.nominatorsFor(accountId) as Observable<Array<AccountId | undefined | null> | undefined>).pipe(
map((nominators) => nominators || []),