Split ui-api, update API version (#589)
* Split ui-api, update API version * Update (awaiting API changes to go through) * Cleanup ui-api exports * Bump API (SubscriptionPromise support) * Linting fixes * Update renames * Do display balances.Transfer (shows for non-owned accounts) * Bump API
This commit is contained in:
parent
21cc608ee9
commit
014ae780e4
@ -3,7 +3,7 @@ const config = require('@polkadot/dev-react/config/jest');
|
||||
module.exports = Object.assign({}, config, {
|
||||
moduleNameMapper: {
|
||||
'@polkadot/app-(accounts|addresses|democracy|explorer|extrinsics|rpc|settings|staking|storage|toolbox|transfer|vanitygen)(.*)$': '<rootDir>/packages/app-$1/src/$2',
|
||||
'@polkadot/ui-(app|params|react-rx|signer)(.*)$': '<rootDir>/packages/ui-$1/src/$2',
|
||||
'@polkadot/ui-(api|app|params|reactive|signer)(.*)$': '<rootDir>/packages/ui-$1/src/$2',
|
||||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'empty/object',
|
||||
'\\.(css|less)$': 'empty/object'
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import './index.css';
|
||||
import React from 'react';
|
||||
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { Tabs } from '@polkadot/ui-app/index';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-api/index';
|
||||
|
||||
import Creator from './Creator';
|
||||
import Editor from './Editor';
|
||||
|
||||
@ -12,7 +12,7 @@ import React from 'react';
|
||||
|
||||
import addressObservable from '@polkadot/ui-keyring/observable/addresses';
|
||||
import Tabs, { TabItem } from '@polkadot/ui-app/Tabs';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-api/index';
|
||||
|
||||
import Creator from './Creator';
|
||||
import Editor from './Editor';
|
||||
|
||||
@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/ui-app": "^0.22.8",
|
||||
"@polkadot/ui-react-rx": "^0.22.8"
|
||||
"@polkadot/ui-reactive": "^0.22.8"
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { Method, Proposal } from '@polkadot/types';
|
||||
import { Call } from '@polkadot/ui-app/index';
|
||||
import numberFormat from '@polkadot/ui-react-rx/util/numberFormat';
|
||||
import numberFormat from '@polkadot/ui-reactive/util/numberFormat';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -9,8 +9,8 @@ import React from 'react';
|
||||
import { AccountId, Balance, Proposal } from '@polkadot/types';
|
||||
import { Tuple, Vector } from '@polkadot/types/codec';
|
||||
import { AddressMini, Labelled, Static } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { balanceFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { balanceFormat } from '@polkadot/ui-reactive/util/index';
|
||||
|
||||
import Item from './Item';
|
||||
import translate from './translate';
|
||||
|
||||
@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Tuple } from '@polkadot/types/codec';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import Proposal from './Proposal';
|
||||
import translate from './translate';
|
||||
|
||||
@ -4,15 +4,15 @@
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { RawParam } from '@polkadot/ui-params/types';
|
||||
import { DerivedReferendumVote } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedReferendumVote } from '@polkadot/ui-api/derive/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { ReferendumInfo } from '@polkadot/types';
|
||||
import { Chart, Static } from '@polkadot/ui-app/index';
|
||||
import VoteThreshold from '@polkadot/ui-params/Param/VoteThreshold';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { balanceFormat, numberFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { balanceFormat, numberFormat } from '@polkadot/ui-reactive/util/index';
|
||||
import settings from '@polkadot/ui-settings';
|
||||
|
||||
import Item from './Item';
|
||||
|
||||
@ -7,7 +7,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { ReferendumInfo } from '@polkadot/types';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import Referendum from './Referendum';
|
||||
import translate from './translate';
|
||||
|
||||
@ -7,8 +7,8 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { CardSummary } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { numberFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { numberFormat } from '@polkadot/ui-reactive/util/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { Button } from '@polkadot/ui-app/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-reactive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BareProps } from '@polkadot/ui-react-rx//types';
|
||||
import { BareProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Header } from '@polkadot/types';
|
||||
import { withCall } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall } from '@polkadot/ui-api/index';
|
||||
|
||||
type Props = BareProps & {
|
||||
label?: string,
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import { AddressMini, Call } from '@polkadot/ui-app/index';
|
||||
import { Extrinsic, Method, SignedBlock } from '@polkadot/types';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { numberFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { numberFormat } from '@polkadot/ui-reactive/util/index';
|
||||
|
||||
import BlockHeader from '../BlockHeader';
|
||||
import translate from '../translate';
|
||||
|
||||
@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { withCall } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall } from '@polkadot/ui-api/index';
|
||||
import { BlockNumber, Hash } from '@polkadot/types';
|
||||
|
||||
type Props = I18nProps & {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import './BlockHeader.css';
|
||||
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import numberFormat from '@polkadot/ui-react-rx/util/numberFormat';
|
||||
import numberFormat from '@polkadot/ui-reactive/util/numberFormat';
|
||||
|
||||
// FIXME 7 Nov 2018 Due to mismatches with block hashes between Substrate and BBQ,
|
||||
// the hashes are retrieved and not calculated (go back to calculated once resolved)
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { Header } from '@polkadot/types';
|
||||
|
||||
import React from 'react';
|
||||
import { withCall } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall } from '@polkadot/ui-api/index';
|
||||
|
||||
import BlockHeader from './BlockHeader';
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import React from 'react';
|
||||
import { Event, EventRecord } from '@polkadot/types';
|
||||
import { Event as EventDisplay } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import { xxhashAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { CardSummary } from '@polkadot/ui-app/index';
|
||||
import { BestFinalised, BestNumber, TimeNow, TimePeriod } from '@polkadot/ui-react-rx/index';
|
||||
import { BestFinalised, BestNumber, TimeNow, TimePeriod } from '@polkadot/ui-reactive/index';
|
||||
|
||||
import SummarySession from './SummarySession';
|
||||
import translate from './translate';
|
||||
|
||||
@ -8,7 +8,7 @@ import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { BlockNumber } from '@polkadot/types';
|
||||
import { CardSummary } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { InputAddress, Labelled } from '@polkadot/ui-app/index';
|
||||
import { Balance } from '@polkadot/ui-react-rx/index';
|
||||
import { Balance } from '@polkadot/ui-reactive/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
import { MethodFunction } from '@polkadot/types/Method';
|
||||
import { BareProps } from '@polkadot/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { RawParam } from '@polkadot/ui-params/types';
|
||||
|
||||
import React from 'react';
|
||||
@ -13,7 +13,7 @@ import { Method } from '@polkadot/types';
|
||||
|
||||
import { InputExtrinsic } from '@polkadot/ui-app/index';
|
||||
import Params from '@polkadot/ui-params/index';
|
||||
import { withApi } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withApi } from '@polkadot/ui-api/index';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
import paramComponents from './Params';
|
||||
|
||||
@ -7,7 +7,7 @@ import { BareProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Labelled } from '@polkadot/ui-app/index';
|
||||
import RxNonce from '@polkadot/ui-react-rx/Nonce';
|
||||
import RxNonce from '@polkadot/ui-reactive/Nonce';
|
||||
|
||||
type Props = BareProps & {
|
||||
label: string,
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Props as BaseProps } from '@polkadot/ui-params/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import { withApi } from '@polkadot/ui-react-rx/with';
|
||||
import { withApi } from '@polkadot/ui-api/index';
|
||||
|
||||
import Extrinsic from './Extrinsic';
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Props as BaseProps, RawParam } from '@polkadot/ui-params/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Proposal } from '@polkadot/types';
|
||||
import { withApi } from '@polkadot/ui-react-rx/with';
|
||||
import { withApi } from '@polkadot/ui-api/index';
|
||||
|
||||
import ExtrinsicDisplay from './Extrinsic';
|
||||
|
||||
|
||||
@ -5,13 +5,13 @@
|
||||
import BN from 'bn.js';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import SubmittableExtrinsic from '@polkadot/api/promise/SubmittableExtrinsic';
|
||||
import { Method } from '@polkadot/types';
|
||||
import { Button } from '@polkadot/ui-app/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import Account from './Account';
|
||||
import ExtrinsicDisplay from './Extrinsic';
|
||||
|
||||
@ -11,7 +11,7 @@ import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
|
||||
import accountsObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-api/index';
|
||||
import translate from './translate';
|
||||
|
||||
import Selection from './Selection';
|
||||
|
||||
@ -7,7 +7,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { InputAddress, Labelled } from '@polkadot/ui-app/index';
|
||||
import { Nonce } from '@polkadot/ui-react-rx/index';
|
||||
import { Nonce } from '@polkadot/ui-reactive/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/ui-app": "^0.22.8",
|
||||
"@polkadot/ui-react-rx": "^0.22.8"
|
||||
"@polkadot/ui-reactive": "^0.22.8"
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,6 @@
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/app-explorer": "^0.22.8",
|
||||
"@polkadot/ui-app": "^0.22.8",
|
||||
"@polkadot/ui-react-rx": "^0.22.8"
|
||||
"@polkadot/ui-reactive": "^0.22.8"
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
|
||||
import React from 'react';
|
||||
import { AccountId, Balance } from '@polkadot/types';
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { DerivedBalances, DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalances, DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { CardSummary } from '@polkadot/ui-app/index';
|
||||
import SummarySession from '@polkadot/app-explorer/SummarySession';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { balanceFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { balanceFormat } from '@polkadot/ui-reactive/util/index';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import './index.css';
|
||||
|
||||
@ -4,14 +4,14 @@
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import SubmittableExtrinsic from '@polkadot/api/promise/SubmittableExtrinsic';
|
||||
import { AccountId, Balance } from '@polkadot/types';
|
||||
import { AddressMini, AddressSummary, Button } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import Nominating from './Nominating';
|
||||
import UnnominateButton from './UnnominateButton';
|
||||
|
||||
@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Button } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueProps } from '@polkadot/ui-app/Status/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
import { AccountId, Balance } from '@polkadot/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ActionStatus } from '@polkadot/ui-app/Status/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types';
|
||||
|
||||
import React from 'react';
|
||||
import { AccountId, Balance } from '@polkadot/types';
|
||||
import { Tabs } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import './index.css';
|
||||
|
||||
|
||||
@ -10,11 +10,11 @@ import React from 'react';
|
||||
import { Compact } from '@polkadot/types/codec';
|
||||
import { Button, Labelled } from '@polkadot/ui-app/index';
|
||||
import valueToText from '@polkadot/ui-params/valueToText';
|
||||
import { withCallDiv } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCallDiv } from '@polkadot/ui-api/index';
|
||||
import { isU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
||||
|
||||
import translate from './translate';
|
||||
import { RenderFn, DefaultProps, ComponentRenderer } from '@polkadot/ui-react-rx/with/types';
|
||||
import { RenderFn, DefaultProps, ComponentRenderer } from '@polkadot/ui-api/with/types';
|
||||
|
||||
type Props = I18nProps & {
|
||||
onRemove: (id: number) => void,
|
||||
|
||||
@ -6,13 +6,13 @@ import { TypeDef, getTypeDef } from '@polkadot/types/codec';
|
||||
import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { RawParams } from '@polkadot/ui-params/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { PartialModuleQuery } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
import { Button, InputStorage, Labelled } from '@polkadot/ui-app/index';
|
||||
import Params from '@polkadot/ui-params/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/ui-app": "^0.22.8",
|
||||
"@polkadot/ui-react-rx": "^0.22.8"
|
||||
"@polkadot/ui-reactive": "^0.22.8"
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,15 +3,15 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { DerivedBalancesFees, DerivedBalances } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { DerivedBalancesFees, DerivedBalances } from '@polkadot/ui-api/derive/types';
|
||||
import { Fees } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { Balance, Extrinsic } from '@polkadot/types';
|
||||
import { Static } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { balanceFormat } from '@polkadot/ui-react-rx/util/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { balanceFormat } from '@polkadot/ui-reactive/util/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import React from 'react';
|
||||
import SubmittableExtrinsic from '@polkadot/api/promise/SubmittableExtrinsic';
|
||||
import { Index } from '@polkadot/types';
|
||||
import Button from '@polkadot/ui-app/Button';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
|
||||
import { BitLength, I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueProps } from '@polkadot/ui-app/Status/types';
|
||||
import { DerivedBalancesFees } from '@polkadot/ui-react-rx/derive/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { DerivedBalancesFees } from '@polkadot/ui-api/derive/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { Fees } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -14,7 +14,7 @@ import { decodeAddress } from '@polkadot/keyring';
|
||||
import { Extrinsic } from '@polkadot/types';
|
||||
import { BitLengthOption } from '@polkadot/ui-app/constants';
|
||||
import { AddressSummary, InputAddress, InputNumber } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api/index';
|
||||
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
|
||||
|
||||
import FeeDisplay from './Fees';
|
||||
|
||||
@ -8,7 +8,7 @@ import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
import React from 'react';
|
||||
import { Trans } from 'react-i18next';
|
||||
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withMulti, withObservable } from '@polkadot/ui-api/index';
|
||||
|
||||
import './index.css';
|
||||
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import './Connecting.css';
|
||||
|
||||
import React from 'react';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
import settings from '@polkadot/ui-settings';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { QueueProps } from '@polkadot/ui-app/Status/types';
|
||||
|
||||
import './Content.css';
|
||||
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
|
||||
|
||||
import Status from '../Status';
|
||||
|
||||
@ -6,7 +6,7 @@ import { BareProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { BestNumber, Chain, NodeName, NodeVersion } from '@polkadot/ui-react-rx/index';
|
||||
import { BestNumber, Chain, NodeName, NodeVersion } from '@polkadot/ui-reactive/index';
|
||||
|
||||
type Props = BareProps & {};
|
||||
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-react-rx/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { Route } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { Icon, Menu } from '@polkadot/ui-app/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-react-rx/with/index';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api/index';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
type Props = I18nProps & ApiProps & {
|
||||
|
||||
@ -10,7 +10,7 @@ import React from 'react';
|
||||
import keyringOption from '@polkadot/ui-keyring/options';
|
||||
import { EventRecord } from '@polkadot/types';
|
||||
import { Status as StatusDisplay } from '@polkadot/ui-app/index';
|
||||
import { withCall, withMulti, withObservable } from '@polkadot/ui-react-rx/with';
|
||||
import { withCall, withMulti, withObservable } from '@polkadot/ui-api/index';
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import { xxhashAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
|
||||
@ -23,9 +23,10 @@ const packages = [
|
||||
'app-toolbox',
|
||||
'app-transfer',
|
||||
'app-vanitygen',
|
||||
'ui-api',
|
||||
'ui-app',
|
||||
'ui-params',
|
||||
'ui-react-rx',
|
||||
'ui-reactive',
|
||||
'ui-signer'
|
||||
];
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# @polkadot/ui-react-rx
|
||||
# @polkadot/ui-reactive
|
||||
|
||||
A collection of RxJS enabled React components that operate with the [@polkadot/api-rx](https://github.com/polkadot-js/api) library. It automatically manages subscriptions on behalf of the developer, providing a number of unstyled components that can be used to construct UIs.
|
||||
|
||||
@ -10,7 +10,7 @@ Basic usage entails creating a `ContextProvider` and just using the components.
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { Api, NodeTime } from '@polkadot/ui-react-rx';
|
||||
import { Api, NodeTime } from '@polkadot/ui-reactive';
|
||||
|
||||
...
|
||||
ReactDOM.render(
|
||||
38
packages/ui-api/package.json
Normal file
38
packages/ui-api/package.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@polkadot/ui-api",
|
||||
"version": "0.22.6",
|
||||
"description": "A collection of RxJs React components the Polkadot JS API",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"Polkadot",
|
||||
"React",
|
||||
"RxJs"
|
||||
],
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [
|
||||
"Jaco Greeff <jacogr@gmail.com>"
|
||||
],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=8.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/polkadot-js/ui.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/polkadot-js/ui/issues"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/api": "^0.39.6",
|
||||
"@polkadot/types": "^0.39.6",
|
||||
"rxjs-compat": "^6.3.2"
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { ApiProps } from '../types';
|
||||
import { ApiProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -11,12 +11,11 @@ import defaults from '@polkadot/rpc-provider/defaults';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { InputNumber } from '@polkadot/ui-app/InputNumber';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { isTestChain } from '@polkadot/ui-react-rx/util';
|
||||
import settings from '@polkadot/ui-settings';
|
||||
import { ChainProperties } from '@polkadot/types';
|
||||
|
||||
import { balanceFormat } from '../util';
|
||||
import ApiContext from './Context';
|
||||
import ApiContext from './ApiContext';
|
||||
import { balanceFormat, isTestChain } from './util';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode,
|
||||
18
packages/ui-api/src/ApiContext.ts
Normal file
18
packages/ui-api/src/ApiContext.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
const ApiContext: React.Context<ApiProps> = React.createContext({} as ApiProps);
|
||||
const ApiConsumer: React.Consumer<ApiProps> = ApiContext.Consumer;
|
||||
const ApiProvider: React.Provider<ApiProps> = ApiContext.Provider;
|
||||
|
||||
export default ApiContext;
|
||||
|
||||
export {
|
||||
ApiConsumer,
|
||||
ApiProvider
|
||||
};
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import { decodeAddress } from '@polkadot/keyring';
|
||||
@ -15,7 +15,7 @@ import accountIndexToId from './accountIndexToId';
|
||||
export type IdAndIndex = [AccountId | undefined, AccountIndex | undefined];
|
||||
|
||||
export default function accountIdAndIndex (api: ApiPromise): DeriveSubscription {
|
||||
return (address: AccountId | AccountIndex | string | null | undefined, cb: (idAndIndex: IdAndIndex) => any): UnsubFunction => {
|
||||
return async (address: AccountId | AccountIndex | string | null | undefined, cb: (idAndIndex: IdAndIndex) => any): PromiseSubscription => {
|
||||
try {
|
||||
// yes, this can fail, don't care too much, catch will catch it
|
||||
const length = decodeAddress((address as any).toString()).length;
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -11,7 +11,7 @@ import { AccountId, AccountIndex } from '@polkadot/types';
|
||||
import accountIndexes, { AccountIndexes } from './accountIndexes';
|
||||
|
||||
export default function accountIdToIndex (api: ApiPromise): DeriveSubscription {
|
||||
return (accountId: AccountId | string, cb: (index?: AccountIndex) => any): UnsubFunction =>
|
||||
return async (accountId: AccountId | string, cb: (index?: AccountIndex) => any): PromiseSubscription =>
|
||||
accountIndexes(api)((indexes?: AccountIndexes) =>
|
||||
cb((indexes || {})[accountId.toString()])
|
||||
);
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -10,7 +10,7 @@ import { AccountId, AccountIndex } from '@polkadot/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
|
||||
|
||||
export default function accountIndexToId (api: ApiPromise): DeriveSubscription {
|
||||
return (_accountIndex: AccountIndex | string, cb: (accountId?: AccountId) => any): UnsubFunction => {
|
||||
return async (_accountIndex: AccountIndex | string, cb: (accountId?: AccountId) => any): PromiseSubscription => {
|
||||
const accountIndex = _accountIndex instanceof AccountIndex
|
||||
? _accountIndex
|
||||
: new AccountIndex(_accountIndex);
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { QueryableStorageFunction, UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { QueryableStorageFunction, PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -13,16 +13,18 @@ import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
|
||||
export type AccountIndexes = { [index: string]: AccountIndex };
|
||||
|
||||
export default function accountIndexes (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (indexes: AccountIndexes) => any): UnsubFunction => {
|
||||
let combineDestroy: UnsubFunction | undefined;
|
||||
const nextEnumSetDestory = api.query.balances.nextEnumSet((next: AccountIndex) => {
|
||||
return async (cb: (indexes: AccountIndexes) => any): PromiseSubscription => {
|
||||
let combineDestroy: PromiseSubscription | undefined;
|
||||
const nextEnumSetDestory = api.query.balances.nextEnumSet(async (next: AccountIndex) => {
|
||||
const setSize = ENUMSET_SIZE.toNumber();
|
||||
const enumRange = [...Array((next || new BN(0)).div(ENUMSET_SIZE).toNumber() + 1).keys()].map((index) =>
|
||||
[api.query.balances.enumSet, index] as [QueryableStorageFunction, ...Array<any>]
|
||||
);
|
||||
|
||||
if (combineDestroy) {
|
||||
combineDestroy();
|
||||
const unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
combineDestroy = api.combineLatest(enumRange, (all: Array<Array<AccountId> | undefined>) => {
|
||||
@ -38,13 +40,17 @@ export default function accountIndexes (api: ApiPromise): DeriveSubscription {
|
||||
}, {} as AccountIndexes)
|
||||
);
|
||||
});
|
||||
}) as any as UnsubFunction; // FIXME? wtf?
|
||||
}) as any as PromiseSubscription; // wtf???
|
||||
|
||||
return (): void => {
|
||||
nextEnumSetDestory();
|
||||
return async (): Promise<void> => {
|
||||
let unsubscribe = await nextEnumSetDestory;
|
||||
|
||||
unsubscribe();
|
||||
|
||||
if (combineDestroy) {
|
||||
combineDestroy();
|
||||
unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -1,15 +1,15 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalancesFees } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
|
||||
export default function fees (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (fees: DerivedBalancesFees) => any): UnsubFunction =>
|
||||
return async (cb: (fees: DerivedBalancesFees) => any): PromiseSubscription =>
|
||||
api.combineLatest([
|
||||
api.query.balances.creationFee,
|
||||
api.query.balances.existentialDeposit,
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CombinatorFunction } from '@polkadot/api/promise/Combinator';
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalances } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -14,7 +14,7 @@ import votingBalance from './votingBalance';
|
||||
import votingBalancesNominatorsFor from './votingBalancesNominatorsFor';
|
||||
|
||||
export default function validatingBalance (api: ApiPromise): DeriveSubscription {
|
||||
return (accountId: AccountId | string, cb: (balance: DerivedBalances) => any): UnsubFunction =>
|
||||
return async (accountId: AccountId | string, cb: (balance: DerivedBalances) => any): PromiseSubscription =>
|
||||
api.combineLatest([
|
||||
[votingBalance(api), accountId] as [CombinatorFunction, ...Array<any>],
|
||||
[votingBalancesNominatorsFor(api), accountId] as [CombinatorFunction, ...Array<any>]
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CombinatorFunction } from '@polkadot/api/promise/Combinator';
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalancesMap } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -12,7 +12,7 @@ import { AccountId } from '@polkadot/types';
|
||||
import validatingBalance from './validatingBalance';
|
||||
|
||||
export default function votingBalances (api: ApiPromise): DeriveSubscription {
|
||||
return (...params: Array<any>): UnsubFunction => {
|
||||
return async (...params: Array<any>): PromiseSubscription => {
|
||||
const accountIds: Array<AccountId | string> = params.slice(0, params.length - 1);
|
||||
const cb: (balanceMap: DerivedBalancesMap) => any = params[params.length - 1];
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalances } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -13,9 +13,9 @@ import accountIdAndIndex from './accountIdAndIndex';
|
||||
const EMPTY_ACCOUNT = new AccountId(new Uint8Array(32));
|
||||
|
||||
export default function votingBalance (api: ApiPromise): DeriveSubscription {
|
||||
return (address: AccountIndex | AccountId | string, cb: (balance: DerivedBalances) => any): UnsubFunction => {
|
||||
let combineDestroy: UnsubFunction | undefined;
|
||||
const idDestory = accountIdAndIndex(api)(address, ([accountId]: [AccountId | undefined]) => {
|
||||
return async (address: AccountIndex | AccountId | string, cb: (balance: DerivedBalances) => any): PromiseSubscription => {
|
||||
let combineDestroy: PromiseSubscription | undefined;
|
||||
const idDestory = accountIdAndIndex(api)(address, async ([accountId]: [AccountId | undefined]) => {
|
||||
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
|
||||
cb({
|
||||
accountId: accountId || EMPTY_ACCOUNT,
|
||||
@ -30,7 +30,9 @@ export default function votingBalance (api: ApiPromise): DeriveSubscription {
|
||||
};
|
||||
|
||||
if (combineDestroy) {
|
||||
combineDestroy();
|
||||
const unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
combineDestroy = undefined;
|
||||
}
|
||||
|
||||
@ -46,11 +48,15 @@ export default function votingBalance (api: ApiPromise): DeriveSubscription {
|
||||
);
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
idDestory();
|
||||
return async () => {
|
||||
let unsubscribe = await idDestory;
|
||||
|
||||
unsubscribe();
|
||||
|
||||
if (combineDestroy) {
|
||||
combineDestroy();
|
||||
let unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CombinatorFunction } from '@polkadot/api/promise/Combinator';
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalances } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -12,7 +12,7 @@ import { AccountId, AccountIndex } from '@polkadot/types';
|
||||
import votingBalance from './votingBalance';
|
||||
|
||||
export default function votingBalances (api: ApiPromise): DeriveSubscription {
|
||||
return (...params: Array<any>): UnsubFunction => {
|
||||
return async (...params: Array<any>): PromiseSubscription => {
|
||||
const addresses: Array<AccountIndex | AccountId | string> = params.slice(0, params.length - 1);
|
||||
const cb: (balance: Array<DerivedBalances>) => any = params[params.length - 1];
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedBalances } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
import { AccountId } from '@polkadot/types';
|
||||
|
||||
import votingBalances from './votingBalances';
|
||||
|
||||
export default function votingBalancesNominatorsFor (api: ApiPromise): DeriveSubscription {
|
||||
return async (accountId: AccountId | string, cb: (balance: Array<DerivedBalances>) => any): PromiseSubscription => {
|
||||
let combineDestroy: PromiseSubscription | undefined;
|
||||
const nominatorDestroy = api.query.staking.nominatorsFor(accountId, async (nominators?: Array<AccountId>) => {
|
||||
if (combineDestroy) {
|
||||
const unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
combineDestroy = votingBalances(api)(...(nominators || []), cb);
|
||||
});
|
||||
|
||||
return async () => {
|
||||
let unsubscribe = await nominatorDestroy;
|
||||
|
||||
unsubscribe();
|
||||
|
||||
if (combineDestroy) {
|
||||
unsubscribe = await combineDestroy;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
@ -1,18 +1,18 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
import { BlockNumber, Header } from '@polkadot/types';
|
||||
|
||||
export default function bestNumber (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (blockNumber: BlockNumber) => any): UnsubFunction =>
|
||||
return (cb: (blockNumber: BlockNumber) => any): PromiseSubscription =>
|
||||
api.rpc.chain.subscribeNewHead((header?: Header) => {
|
||||
if (header && header.blockNumber) {
|
||||
cb(header.blockNumber);
|
||||
}
|
||||
}) as UnsubFunction;
|
||||
}) as PromiseSubscription;
|
||||
}
|
||||
@ -1,18 +1,18 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
import { BlockNumber, Header } from '@polkadot/types';
|
||||
|
||||
export default function bestNumberFinalised (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (blockNumber: BlockNumber) => any): UnsubFunction =>
|
||||
return (cb: (blockNumber: BlockNumber) => any): PromiseSubscription =>
|
||||
api.rpc.chain.subscribeFinalisedHeads((header?: Header) => {
|
||||
if (header && header.blockNumber) {
|
||||
cb(header.blockNumber);
|
||||
}
|
||||
}) as UnsubFunction;
|
||||
}) as PromiseSubscription;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CombinatorFunction } from '@polkadot/api/promise/Combinator';
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -11,7 +11,7 @@ import ApiPromise from '@polkadot/api/promise';
|
||||
import { ReferendumInfo } from '@polkadot/types';
|
||||
|
||||
export default function referendumInfos (api: ApiPromise): DeriveSubscription {
|
||||
return (...params: Array<any>): UnsubFunction => {
|
||||
return async (...params: Array<any>): PromiseSubscription => {
|
||||
const ids: Array<BN | number> = params.slice(0, params.length - 1);
|
||||
const cb: (infos: Array<ReferendumInfo>) => any = params[params.length - 1];
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CombinatorFunction } from '@polkadot/api/promise/Combinator';
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription, DerivedReferendumVote } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -14,19 +14,21 @@ import votingBalances from '../balances/votingBalances';
|
||||
import votes from './votes';
|
||||
|
||||
export default function referendumVotesFor (api: ApiPromise): DeriveSubscription {
|
||||
return (referendumId: BN | number, cb: (votes: Array<DerivedReferendumVote>) => any): UnsubFunction => {
|
||||
let innerDestroy: UnsubFunction | undefined;
|
||||
const outerDestroy = api.query.democracy.votersFor(referendumId, (votersFor: Array<AccountId>) => {
|
||||
if (innerDestroy) {
|
||||
innerDestroy();
|
||||
innerDestroy = undefined;
|
||||
return async (referendumId: BN | number, cb: (votes: Array<DerivedReferendumVote>) => any): PromiseSubscription => {
|
||||
let innerDispose: PromiseSubscription | undefined;
|
||||
const outerDispose = api.query.democracy.votersFor(referendumId, async (votersFor: Array<AccountId>) => {
|
||||
if (innerDispose) {
|
||||
const unsubscribe = await innerDispose;
|
||||
|
||||
unsubscribe();
|
||||
innerDispose = undefined;
|
||||
}
|
||||
|
||||
if (!votersFor || !votersFor.length) {
|
||||
return cb([]);
|
||||
}
|
||||
|
||||
innerDestroy = api.combineLatest([
|
||||
innerDispose = api.combineLatest([
|
||||
[votes(api), referendumId, ...votersFor] as [CombinatorFunction, ...Array<any>],
|
||||
[votingBalances(api), ...votersFor] as [CombinatorFunction, ...Array<any>]
|
||||
], ([votes, balances]) =>
|
||||
@ -40,12 +42,16 @@ export default function referendumVotesFor (api: ApiPromise): DeriveSubscription
|
||||
);
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
if (innerDestroy) {
|
||||
innerDestroy();
|
||||
}
|
||||
return async () => {
|
||||
let unsubscribe = await outerDispose;
|
||||
|
||||
outerDestroy();
|
||||
unsubscribe();
|
||||
|
||||
if (innerDispose) {
|
||||
unsubscribe = await innerDispose;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -11,14 +11,16 @@ import { ReferendumInfo } from '@polkadot/types';
|
||||
import referendumInfos from './referendumInfos';
|
||||
|
||||
export default function referendums (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (referendums: Array<ReferendumInfo>) => any): UnsubFunction => {
|
||||
let innerDispose: UnsubFunction | undefined;
|
||||
return async (cb: (referendums: Array<ReferendumInfo>) => any): PromiseSubscription => {
|
||||
let innerDispose: PromiseSubscription | undefined;
|
||||
const outerDispose = api.combineLatest([
|
||||
api.query.democracy.nextTally,
|
||||
api.query.democracy.referendumCount
|
||||
], ([nextTally, referendumCount]) => {
|
||||
], async ([nextTally, referendumCount]) => {
|
||||
if (innerDispose) {
|
||||
innerDispose();
|
||||
const unsubscribe = await innerDispose;
|
||||
|
||||
unsubscribe();
|
||||
innerDispose = undefined;
|
||||
}
|
||||
|
||||
@ -33,11 +35,15 @@ export default function referendums (api: ApiPromise): DeriveSubscription {
|
||||
}
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
outerDispose();
|
||||
return async () => {
|
||||
let unsubscribe = await outerDispose;
|
||||
|
||||
unsubscribe();
|
||||
|
||||
if (innerDispose) {
|
||||
innerDispose();
|
||||
unsubscribe = await innerDispose;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { QueryableStorageFunction, UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { QueryableStorageFunction, PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -10,7 +10,7 @@ import ApiPromise from '@polkadot/api/promise';
|
||||
import { AccountId, bool as Bool } from '@polkadot/types';
|
||||
|
||||
export default function votes (api: ApiPromise): DeriveSubscription {
|
||||
return (...params: Array<any>): UnsubFunction => {
|
||||
return async (...params: Array<any>): PromiseSubscription => {
|
||||
const referendumId: BN = params[0];
|
||||
const accountIds: Array<AccountId> = params.slice(1, params.length - 1);
|
||||
const cb: (infos: Array<Bool>) => any = params[params.length - 1];
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
|
||||
export default function eraLength (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (count: BN) => any): UnsubFunction =>
|
||||
return (cb: (count: BN) => any): PromiseSubscription =>
|
||||
api.combineLatest([
|
||||
api.query.session.sessionLength,
|
||||
api.query.staking.sessionsPerEra
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -11,7 +11,7 @@ import ApiPromise from '@polkadot/api/promise';
|
||||
import sessionProgress from './sessionProgress';
|
||||
|
||||
export default function eraProgress (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (count: BN) => any): UnsubFunction =>
|
||||
return (cb: (count: BN) => any): PromiseSubscription =>
|
||||
api.combineLatest([
|
||||
sessionProgress(api),
|
||||
api.query.session.currentIndex,
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
import { DeriveSubscription } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -11,7 +11,7 @@ import ApiPromise from '@polkadot/api/promise';
|
||||
import bestNumber from '../chain/bestNumber';
|
||||
|
||||
export default function sessionProgress (api: ApiPromise): DeriveSubscription {
|
||||
return (cb: (count: BN) => any): UnsubFunction =>
|
||||
return (cb: (count: BN) => any): PromiseSubscription =>
|
||||
api.combineLatest([
|
||||
bestNumber(api),
|
||||
api.query.session.sessionLength,
|
||||
@ -1,14 +1,14 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { UnsubFunction } from '@polkadot/api/promise/types';
|
||||
import { PromiseSubscription } from '@polkadot/api/promise/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { AccountId, Balance, Vote } from '@polkadot/types';
|
||||
|
||||
export interface DeriveSubscription {
|
||||
(...params: Array<any>): UnsubFunction;
|
||||
(...params: Array<any>): PromiseSubscription;
|
||||
}
|
||||
|
||||
export type DerivedBalancesFees = {
|
||||
13
packages/ui-api/src/index.ts
Normal file
13
packages/ui-api/src/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Api from './Api';
|
||||
import ApiContext from './ApiContext';
|
||||
|
||||
export * from './with';
|
||||
|
||||
export {
|
||||
Api,
|
||||
ApiContext
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
95
packages/ui-api/src/util/balanceFormat.ts
Normal file
95
packages/ui-api/src/util/balanceFormat.ts
Normal file
@ -0,0 +1,95 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import decimalFormat from './decimalFormat';
|
||||
|
||||
type SiDef = {
|
||||
power: number,
|
||||
text: string,
|
||||
value: string
|
||||
};
|
||||
|
||||
interface BalanceFormatter {
|
||||
(input: string | BN, withSi?: boolean, decimals?: number): string;
|
||||
findSi (type: string): SiDef;
|
||||
getDefaultDecimals (): number;
|
||||
getOptions (decimals?: number): Array<SiDef>;
|
||||
setDefaultDecimals (decimals: number): void;
|
||||
}
|
||||
|
||||
const SI: Array<SiDef> = [
|
||||
{ power: -24, value: 'y', text: 'yocto' },
|
||||
{ power: -21, value: 'z', text: 'zepto' },
|
||||
{ power: -18, value: 'a', text: 'atto' },
|
||||
{ power: -15, value: 'f', text: 'femto' },
|
||||
{ power: -12, value: 'p', text: 'pico' },
|
||||
{ power: -9, value: 'n', text: 'nano' },
|
||||
{ power: -6, value: 'µ', text: 'micro' },
|
||||
{ power: -3, value: 'm', text: 'milli' },
|
||||
{ power: 0, value: '-', text: '----' }, // position 8
|
||||
{ power: 3, value: 'k', text: 'Kilo' },
|
||||
{ power: 6, value: 'M', text: 'Mega' },
|
||||
{ power: 9, value: 'G', text: 'Giga' },
|
||||
{ power: 12, value: 'T', text: 'Tera' },
|
||||
{ power: 15, value: 'P', text: 'Peta' },
|
||||
{ power: 18, value: 'E', text: 'Exa' },
|
||||
{ power: 21, value: 'Z', text: 'Zeta' },
|
||||
{ power: 24, value: 'Y', text: 'Yotta' }
|
||||
];
|
||||
|
||||
const SI_MID = 8;
|
||||
|
||||
let defaultDecimals = 0;
|
||||
|
||||
export function calcSi (text: string, decimals: number = defaultDecimals): SiDef {
|
||||
return SI[(SI_MID - 1) + Math.ceil((text.length - decimals) / 3)];
|
||||
}
|
||||
|
||||
// Formats a string/number with <prefix>.<postfix><type> notation
|
||||
function _balanceFormat (input: string | BN, withSi: boolean = true, decimals: number = defaultDecimals): string {
|
||||
const text = (input || '').toString();
|
||||
|
||||
if (text.length === 0 || text === '0') {
|
||||
return text;
|
||||
}
|
||||
|
||||
// NOTE We start at midpoint (8) minus 1 - this means that values display as
|
||||
// 123.456 instead of 0.123k (so always 6 relevant). Additionally we us ceil
|
||||
// so there are at most 3 decimal before the decimal seperator
|
||||
const si = calcSi(text, decimals);
|
||||
const mid = text.length - (decimals + si.power);
|
||||
const prefix = text.substr(0, mid);
|
||||
const postfix = `${text.substr(mid)}000`.substr(0, 3);
|
||||
|
||||
return `${decimalFormat(prefix || '0')}.${postfix}${withSi ? (si.value === '-' ? '' : si.value) : ''}`;
|
||||
}
|
||||
|
||||
const balanceFormat = _balanceFormat as BalanceFormatter;
|
||||
|
||||
// Given a SI type (e.g. k, m, Y) find the SI definition
|
||||
balanceFormat.findSi = (type: string): SiDef => {
|
||||
return SI.find(({ value }) => value === type) || SI[SI_MID];
|
||||
};
|
||||
|
||||
balanceFormat.getDefaultDecimals = (): number => {
|
||||
return defaultDecimals;
|
||||
};
|
||||
|
||||
// get allowable options to display in a dropdown
|
||||
balanceFormat.getOptions = (decimals: number = defaultDecimals): Array<SiDef> => {
|
||||
return SI.filter(({ power }) =>
|
||||
power < 0
|
||||
? (decimals + power) >= 0
|
||||
: true
|
||||
);
|
||||
};
|
||||
|
||||
// Sets the default decimals to use for formatting (chain-wide)
|
||||
balanceFormat.setDefaultDecimals = (decimals: number = 0): void => {
|
||||
defaultDecimals = decimals;
|
||||
};
|
||||
|
||||
export default balanceFormat;
|
||||
9
packages/ui-api/src/util/decimalFormat.ts
Normal file
9
packages/ui-api/src/util/decimalFormat.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g');
|
||||
|
||||
export default function decimalFormat (value: string): string {
|
||||
return (value.match(NUMBER_REGEX) || []).join(',');
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
21
packages/ui-api/src/util/numberFormat.ts
Normal file
21
packages/ui-api/src/util/numberFormat.ts
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Compact } from '@polkadot/types/codec';
|
||||
import { bnToBn } from '@polkadot/util';
|
||||
|
||||
import decimalFormat from './decimalFormat';
|
||||
|
||||
export default function numberFormat (_value?: Compact | BN | number | null): string {
|
||||
if (!_value) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
const value = _value instanceof Compact
|
||||
? _value.toBn()
|
||||
: bnToBn(_value);
|
||||
|
||||
return decimalFormat(value.toString());
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -8,7 +8,7 @@ import { DefaultProps } from './types';
|
||||
import React from 'react';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { ApiConsumer } from '../Api/Context';
|
||||
import { ApiConsumer } from '../ApiContext';
|
||||
|
||||
export default function withApi <T, P extends ApiProps> (Inner: React.ComponentType<P>, defaultProps: DefaultProps<T> = {}): React.ComponentType<any> {
|
||||
return class WithApi extends React.PureComponent<any> {
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -12,7 +12,7 @@ import { assert, isUndefined } from '@polkadot/util';
|
||||
|
||||
import derive from '../derive/index';
|
||||
import { intervalTimer, isEqual, triggerChange } from '../util/index';
|
||||
import echoTransform from './transform/echo';
|
||||
import echoTransform from '../transform/echo';
|
||||
import withApi from './api';
|
||||
|
||||
type State<T> = RxProps<T> & {
|
||||
@ -92,7 +92,7 @@ export default function withCall<T, P> (endpoint: string, { rxChange, params = [
|
||||
);
|
||||
}
|
||||
|
||||
private getApiMethod (newParams: Array<any>) {
|
||||
private getApiMethod (newParams: Array<any>): [(...params: Array<any>) => Promise<any>, Array<any>, boolean] {
|
||||
const { apiPromise } = this.props;
|
||||
|
||||
if (endpoint === 'subscribe') {
|
||||
@ -144,17 +144,18 @@ export default function withCall<T, P> (endpoint: string, { rxChange, params = [
|
||||
this.unsubscribe();
|
||||
|
||||
if (isSubscription) {
|
||||
this.setState({
|
||||
destroy: apiMethod(...params, (value?: T) =>
|
||||
this.triggerUpdate(this.props, value))
|
||||
});
|
||||
const destroy = await apiMethod(...params, (value?: T) =>
|
||||
this.triggerUpdate(this.props, value)
|
||||
);
|
||||
|
||||
this.setState({ destroy });
|
||||
} else {
|
||||
const value: T = await apiMethod(...params);
|
||||
|
||||
this.triggerUpdate(this.props, value);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(endpoint, '::', error);
|
||||
// console.error(endpoint, '::', error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/ui-api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -11,8 +11,8 @@ import React from 'react';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
import echoTransform from '../transform/echo';
|
||||
import { intervalObservable, isEqual, triggerChange } from '../util/index';
|
||||
import echoTransform from './transform/echo';
|
||||
|
||||
type State<T> = RxProps<T> & {
|
||||
subscriptions: Array<any>; // FIXME subscriptions
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user