diff --git a/packages/app-accounts/package.json b/packages/app-accounts/package.json index 1e486a06a2..b9ea869c0b 100644 --- a/packages/app-accounts/package.json +++ b/packages/app-accounts/package.json @@ -16,7 +16,7 @@ "@types/yargs": "^12.0.5", "babel-plugin-module-resolver": "^3.1.1", "file-saver": "^2.0.0", - "libsodium-wrappers": "^0.7.4", + "libsodium-wrappers": "^0.7.3", "yargs": "^12.0.5" }, "optionalDependencies": { diff --git a/packages/app-accounts/src/Creator.tsx b/packages/app-accounts/src/Creator.tsx index 78a86e0838..245eccccc5 100644 --- a/packages/app-accounts/src/Creator.tsx +++ b/packages/app-accounts/src/Creator.tsx @@ -89,8 +89,6 @@ class Creator extends React.PureComponent { render () { const { address, isSeedValid } = this.state; - console.error('passthrough', this.props.passthrough); - return (
@@ -390,7 +388,6 @@ class Creator extends React.PureComponent { this.onHideWarning(); onCreateAccount(); - onStatusChange(status); } diff --git a/packages/app-democracy/src/Referendum.tsx b/packages/app-democracy/src/Referendum.tsx index b168f886a4..c2ec7bef5d 100644 --- a/packages/app-democracy/src/Referendum.tsx +++ b/packages/app-democracy/src/Referendum.tsx @@ -2,9 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { DerivedReferendumVote } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { RawParam } from '@polkadot/ui-params/types'; -import { DerivedReferendumVote } from '@polkadot/ui-api/derive/types'; import BN from 'bn.js'; import React from 'react'; diff --git a/packages/app-extrinsics/src/Selection.tsx b/packages/app-extrinsics/src/Selection.tsx index b92fce67fb..75db699d87 100644 --- a/packages/app-extrinsics/src/Selection.tsx +++ b/packages/app-extrinsics/src/Selection.tsx @@ -8,7 +8,6 @@ import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/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-api/index'; @@ -131,11 +130,13 @@ class Selection extends React.PureComponent { return; } + const fn = Method.findFunction(method.callIndex); + queueExtrinsic({ accountId: isUnsigned ? undefined : accountId, - extrinsic: new SubmittableExtrinsic(apiPromise, method), + extrinsic: apiPromise.tx[fn.section][fn.method](...method.args), isUnsigned }); } diff --git a/packages/app-staking/src/Overview/CurrentList.tsx b/packages/app-staking/src/Overview/CurrentList.tsx index f70faa8c62..5490c3eb44 100644 --- a/packages/app-staking/src/Overview/CurrentList.tsx +++ b/packages/app-staking/src/Overview/CurrentList.tsx @@ -2,8 +2,8 @@ // 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/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; -import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types'; import React from 'react'; import { AccountId, Balance } from '@polkadot/types'; diff --git a/packages/app-staking/src/Overview/Summary.tsx b/packages/app-staking/src/Overview/Summary.tsx index 4f9a4087de..c2b449eef4 100644 --- a/packages/app-staking/src/Overview/Summary.tsx +++ b/packages/app-staking/src/Overview/Summary.tsx @@ -2,8 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { DerivedBalances, DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; -import { DerivedBalances, DerivedBalancesMap } from '@polkadot/ui-api/derive/types'; import BN from 'bn.js'; import React from 'react'; diff --git a/packages/app-staking/src/Overview/index.tsx b/packages/app-staking/src/Overview/index.tsx index 08b9dc2461..974834c604 100644 --- a/packages/app-staking/src/Overview/index.tsx +++ b/packages/app-staking/src/Overview/index.tsx @@ -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-api/derive/types'; +import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import './index.css'; diff --git a/packages/app-staking/src/StakeList/Account.tsx b/packages/app-staking/src/StakeList/Account.tsx index b582332a18..08696b38e2 100644 --- a/packages/app-staking/src/StakeList/Account.tsx +++ b/packages/app-staking/src/StakeList/Account.tsx @@ -2,13 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; +import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/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-api/index'; diff --git a/packages/app-staking/src/StakeList/index.tsx b/packages/app-staking/src/StakeList/index.tsx index 98693724d8..dd81ac5bbb 100644 --- a/packages/app-staking/src/StakeList/index.tsx +++ b/packages/app-staking/src/StakeList/index.tsx @@ -2,9 +2,9 @@ // 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/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { QueueProps } from '@polkadot/ui-app/Status/types'; -import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types'; import { AccountId, Balance } from '@polkadot/types'; import React from 'react'; diff --git a/packages/app-staking/src/index.tsx b/packages/app-staking/src/index.tsx index 3f88137b6b..4535410cd1 100644 --- a/packages/app-staking/src/index.tsx +++ b/packages/app-staking/src/index.tsx @@ -2,9 +2,9 @@ // 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/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { ActionStatus } from '@polkadot/ui-app/Status/types'; -import { DerivedBalancesMap } from '@polkadot/ui-api/derive/types'; import React from 'react'; import { AccountId, Balance } from '@polkadot/types'; @@ -21,10 +21,10 @@ type Actions = 'actions' | 'overview'; type Props = I18nProps & { basePath: string, + balances?: DerivedBalancesMap, + intentions?: Array, onStatusChange: (status: ActionStatus) => void, - query_staking_intentions?: Array, - query_session_validators?: Array, - derive_balances_validatingBalances?: DerivedBalancesMap + query_session_validators?: Array }; type State = { @@ -51,9 +51,9 @@ class App extends React.PureComponent { }; } - static getDerivedStateFromProps ({ query_session_validators, query_staking_intentions }: Props): State { + static getDerivedStateFromProps ({ query_session_validators, intentions }: Props): State { return { - intentions: (query_staking_intentions || []).map((accountId) => + intentions: (intentions || []).map((accountId) => accountId.toString() ), validators: (query_session_validators || []).map((authorityId) => @@ -64,7 +64,7 @@ class App extends React.PureComponent { render () { const { action, intentions, validators } = this.state; - const { t, derive_balances_validatingBalances = {} } = this.props; + const { t, balances = {} } = this.props; const Component = Components[action]; const items = [ { @@ -87,7 +87,7 @@ class App extends React.PureComponent { /> { } private balanceArray = (_address: AccountId | string): Array | undefined => { - const { derive_balances_validatingBalances = {} } = this.props; + const { balances = {} } = this.props; if (!_address) { return undefined; @@ -109,10 +109,10 @@ class App extends React.PureComponent { const address = _address.toString(); - return derive_balances_validatingBalances[address] + return balances[address] ? [ - derive_balances_validatingBalances[address].stakingBalance, - derive_balances_validatingBalances[address].nominatedBalance + balances[address].stakingBalance, + balances[address].nominatedBalance ] : undefined; } @@ -121,7 +121,7 @@ class App extends React.PureComponent { export default withMulti( App, translate, - withCall('query.staking.intentions'), withCall('query.session.validators'), - withCall('derive.balances.validatingBalances', { paramProp: 'stakingIntentions' }) + withCall('query.staking.intentions', { propName: 'intentions' }), + withCall('derive.staking.intentionsBalances', { propName: 'balances' }) ); diff --git a/packages/app-transfer/src/Submit.tsx b/packages/app-transfer/src/Submit.tsx index 659176861b..988e7e0aa6 100644 --- a/packages/app-transfer/src/Submit.tsx +++ b/packages/app-transfer/src/Submit.tsx @@ -2,11 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { QueueTx$Extrinsic, QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types'; 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-api/index'; diff --git a/packages/app-transfer/src/Transfer.tsx b/packages/app-transfer/src/Transfer.tsx index 161d02b56c..d938dce8ee 100644 --- a/packages/app-transfer/src/Transfer.tsx +++ b/packages/app-transfer/src/Transfer.tsx @@ -139,6 +139,8 @@ class Transfer extends React.PureComponent { ? apiPromise.tx.balances.transfer(recipientId, amount) : null; + console.log('extrinsic', extrinsic); + return { accountId, amount, diff --git a/packages/ui-api/package.json b/packages/ui-api/package.json index c33ff32b36..042d02be26 100644 --- a/packages/ui-api/package.json +++ b/packages/ui-api/package.json @@ -31,8 +31,8 @@ "homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/api": "^0.39.12", - "@polkadot/types": "^0.39.12", + "@polkadot/api": "^0.40.5", + "@polkadot/types": "^0.40.5", "rxjs-compat": "^6.3.2" } } diff --git a/packages/ui-api/src/Api.tsx b/packages/ui-api/src/Api.tsx index 34b1915051..90eb26816f 100644 --- a/packages/ui-api/src/Api.tsx +++ b/packages/ui-api/src/Api.tsx @@ -76,8 +76,8 @@ export default class ApiWrapper extends React.PureComponent { private subscribeChain = async (api: ApiPromise) => { const [properties = new ChainProperties(), value] = await Promise.all([ - api.rpc.system.properties(), - api.rpc.system.chain() + api.rpc.system.properties() as Promise, + api.rpc.system.chain() as Promise ]); const chain = value @@ -90,7 +90,7 @@ export default class ApiWrapper extends React.PureComponent { tokenSymbol: undefined }; - console.log('found chain', chain, [...properties.entries()]); + console.log('api: found chain', chain, [...properties.entries()]); balanceFormat.setDefaultDecimals(properties.get('tokenDecimals') || found.tokenDecimals); InputNumber.setUnit(properties.get('tokenSymbol') || found.tokenSymbol); diff --git a/packages/ui-api/src/derive/balances/accountIdAndIndex.ts b/packages/ui-api/src/derive/balances/accountIdAndIndex.ts deleted file mode 100644 index e02652e746..0000000000 --- a/packages/ui-api/src/derive/balances/accountIdAndIndex.ts +++ /dev/null @@ -1,47 +0,0 @@ -// 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 } from '../types'; - -import { decodeAddress } from '@polkadot/keyring'; -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, AccountIndex } from '@polkadot/types'; - -import accountIdToIndex from './accountIdToIndex'; -import accountIndexToId from './accountIndexToId'; - -export type IdAndIndex = [AccountId | undefined, AccountIndex | undefined]; - -export default function accountIdAndIndex (api: ApiPromise): DeriveSubscription { - 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 decoded = decodeAddress((address as any).toString()); - - if (decoded.length === 32) { - const accountId = new AccountId(decoded); - - return accountIdToIndex(api)(accountId, (accountIndex?: AccountIndex) => - cb([accountId, accountIndex]) - ); - } - - const accountIndex = new AccountIndex(address as string); - - return accountIndexToId(api)(accountIndex, (accountId?: AccountId) => - cb([accountId, accountIndex]) - ); - } catch (error) { - // swallow - } - - cb([undefined, undefined]); - - // just return empties - return (): void => { - // nothing to unsubscribe from - }; - }; -} diff --git a/packages/ui-api/src/derive/balances/accountIdToIndex.ts b/packages/ui-api/src/derive/balances/accountIdToIndex.ts deleted file mode 100644 index 28713733db..0000000000 --- a/packages/ui-api/src/derive/balances/accountIdToIndex.ts +++ /dev/null @@ -1,18 +0,0 @@ -// 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 } from '../types'; - -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, AccountIndex } from '@polkadot/types'; - -import accountIndexes, { AccountIndexes } from './accountIndexes'; - -export default function accountIdToIndex (api: ApiPromise): DeriveSubscription { - return async (accountId: AccountId | string | null, cb: (index?: AccountIndex) => any): PromiseSubscription => - accountIndexes(api)((indexes?: AccountIndexes) => - cb((indexes || {})[(accountId || '').toString()]) - ); -} diff --git a/packages/ui-api/src/derive/balances/accountIndexToId.ts b/packages/ui-api/src/derive/balances/accountIndexToId.ts deleted file mode 100644 index 22bcbd537d..0000000000 --- a/packages/ui-api/src/derive/balances/accountIndexToId.ts +++ /dev/null @@ -1,22 +0,0 @@ -// 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 } from '../types'; - -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, AccountIndex } from '@polkadot/types'; -import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex'; - -export default function accountIndexToId (api: ApiPromise): DeriveSubscription { - return async (_accountIndex: AccountIndex | string, cb: (accountId?: AccountId) => any): PromiseSubscription => { - const accountIndex = _accountIndex instanceof AccountIndex - ? _accountIndex - : new AccountIndex(_accountIndex); - - return api.query.balances.enumSet(accountIndex, (accounts: Array) => - cb((accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]) - ); - }; -} diff --git a/packages/ui-api/src/derive/balances/accountIndexes.ts b/packages/ui-api/src/derive/balances/accountIndexes.ts deleted file mode 100644 index 3b3e0b75ce..0000000000 --- a/packages/ui-api/src/derive/balances/accountIndexes.ts +++ /dev/null @@ -1,57 +0,0 @@ -// 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, PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, AccountIndex } from '@polkadot/types'; -import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex'; - -export type AccountIndexes = { [index: string]: AccountIndex }; - -export default function accountIndexes (api: ApiPromise): DeriveSubscription { - 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] - ); - - if (combineDestroy) { - const unsubscribe = await combineDestroy; - - unsubscribe(); - } - - combineDestroy = api.combineLatest(enumRange, (all: Array | undefined>) => { - cb( - (all || []).reduce((result, list, outerIndex) => { - (list || []).forEach((accountId, innerIndex) => { - const index = (outerIndex * setSize) + innerIndex; - - result[accountId.toString()] = new AccountIndex(index); - }); - - return result; - }, {} as AccountIndexes) - ); - }); - }) as any as PromiseSubscription; // wtf??? - - return async (): Promise => { - let unsubscribe = await nextEnumSetDestory; - - unsubscribe(); - - if (combineDestroy) { - unsubscribe = await combineDestroy; - - unsubscribe(); - } - }; - }; -} diff --git a/packages/ui-api/src/derive/balances/fees.ts b/packages/ui-api/src/derive/balances/fees.ts deleted file mode 100644 index c77f2784e0..0000000000 --- a/packages/ui-api/src/derive/balances/fees.ts +++ /dev/null @@ -1,28 +0,0 @@ -// 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, DerivedBalancesFees } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; - -export default function fees (api: ApiPromise): DeriveSubscription { - return async (cb: (fees: DerivedBalancesFees) => any): PromiseSubscription => - api.combineLatest([ - api.query.balances.creationFee, - api.query.balances.existentialDeposit, - api.query.balances.transactionBaseFee, - api.query.balances.transactionByteFee, - api.query.balances.transferFee - ], ([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => - cb({ - creationFee: creationFee || new BN(0), - existentialDeposit: existentialDeposit || new BN(0), - transactionBaseFee: transactionBaseFee || new BN(0), - transactionByteFee: transactionByteFee || new BN(0), - transferFee: transferFee || new BN(0) - }) - ); -} diff --git a/packages/ui-api/src/derive/balances/index.ts b/packages/ui-api/src/derive/balances/index.ts deleted file mode 100644 index 5c8919b84d..0000000000 --- a/packages/ui-api/src/derive/balances/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -export { default as accountIdAndIndex } from './accountIdAndIndex'; -export { default as accountIdToIndex } from './accountIdToIndex'; -export { default as accountIndexes } from './accountIndexes'; -export { default as accountIndexToId } from './accountIndexToId'; -export { default as fees } from './fees'; -export { default as validatingBalance } from './votingBalance'; -export { default as validatingBalances } from './validatingBalances'; -export { default as votingBalance } from './votingBalance'; -export { default as votingBalances } from './votingBalances'; -export { default as votingBalancesNominatorsFor } from './votingBalancesNominatorsFor'; diff --git a/packages/ui-api/src/derive/balances/validatingBalance.ts b/packages/ui-api/src/derive/balances/validatingBalance.ts deleted file mode 100644 index 34290c78ee..0000000000 --- a/packages/ui-api/src/derive/balances/validatingBalance.ts +++ /dev/null @@ -1,35 +0,0 @@ -// 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 { PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription, DerivedBalances } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, Balance } from '@polkadot/types'; - -import votingBalance from './votingBalance'; -import votingBalancesNominatorsFor from './votingBalancesNominatorsFor'; - -export default function validatingBalance (api: ApiPromise): DeriveSubscription { - return async (accountId: AccountId | string, cb: (balance: DerivedBalances) => any): PromiseSubscription => - api.combineLatest([ - [votingBalance(api), accountId] as [CombinatorFunction, ...Array], - [votingBalancesNominatorsFor(api), accountId] as [CombinatorFunction, ...Array] - ], ([balance, nominators]) => { - const nominatedBalance = nominators.reduce((total: BN, nominatorBalance: DerivedBalances) => { - return total.add(nominatorBalance.votingBalance); - }, new BN(0)); - - cb({ - ...balance, - nominators, - nominatedBalance: new Balance(nominatedBalance), - stakingBalance: new Balance( - nominatedBalance.add(balance.votingBalance) - ) - }); - }); -} diff --git a/packages/ui-api/src/derive/balances/validatingBalances.ts b/packages/ui-api/src/derive/balances/validatingBalances.ts deleted file mode 100644 index d4da9ed8ce..0000000000 --- a/packages/ui-api/src/derive/balances/validatingBalances.ts +++ /dev/null @@ -1,32 +0,0 @@ -// 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 { PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription, DerivedBalancesMap } from '../types'; - -import ApiPromise from '@polkadot/api/promise'; -import { AccountId } from '@polkadot/types'; - -import validatingBalance from './validatingBalance'; - -export default function votingBalances (api: ApiPromise): DeriveSubscription { - return async (...params: Array): PromiseSubscription => { - const accountIds: Array = params.slice(0, params.length - 1); - const cb: (balanceMap: DerivedBalancesMap) => any = params[params.length - 1]; - - return api.combineLatest( - accountIds.map((accountId) => - [validatingBalance(api), accountId] as [CombinatorFunction, ...Array] - ), (result) => - cb( - result.reduce((balances, balance) => { - balances[balance.address.toString()] = balance; - - return balances; - }, {} as DerivedBalancesMap) - ) - ); - }; -} diff --git a/packages/ui-api/src/derive/balances/votingBalance.ts b/packages/ui-api/src/derive/balances/votingBalance.ts deleted file mode 100644 index 013a3e67c9..0000000000 --- a/packages/ui-api/src/derive/balances/votingBalance.ts +++ /dev/null @@ -1,63 +0,0 @@ -// 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, AccountIndex, Balance } from '@polkadot/types'; - -import accountIdAndIndex from './accountIdAndIndex'; - -const EMPTY_ACCOUNT = new AccountId(new Uint8Array(32)); - -export default function votingBalance (api: ApiPromise): DeriveSubscription { - 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, - freeBalance: freeBalance || new Balance(0), - nominatedBalance: new Balance(0), - reservedBalance: reservedBalance || new Balance(0), - stakingBalance: new Balance(0), - votingBalance: new Balance( - (freeBalance || new Balance(0)).add(reservedBalance || new Balance(0)) - ) - }); - }; - - if (combineDestroy) { - const unsubscribe = await combineDestroy; - - unsubscribe(); - combineDestroy = undefined; - } - - if (!accountId) { - return handler(); - } - - combineDestroy = api.combineLatest([ - [api.query.balances.freeBalance, accountId], - [api.query.balances.reservedBalance, accountId] - ], ([freeBalance, reservedBalance]) => - handler(freeBalance, reservedBalance) - ); - }); - - return async () => { - let unsubscribe = await idDestory; - - unsubscribe(); - - if (combineDestroy) { - let unsubscribe = await combineDestroy; - - unsubscribe(); - } - }; - }; -} diff --git a/packages/ui-api/src/derive/balances/votingBalances.ts b/packages/ui-api/src/derive/balances/votingBalances.ts deleted file mode 100644 index d04fa7cbed..0000000000 --- a/packages/ui-api/src/derive/balances/votingBalances.ts +++ /dev/null @@ -1,25 +0,0 @@ -// 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 { PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription, DerivedBalances } from '../types'; - -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, AccountIndex } from '@polkadot/types'; - -import votingBalance from './votingBalance'; - -export default function votingBalances (api: ApiPromise): DeriveSubscription { - return async (...params: Array): PromiseSubscription => { - const addresses: Array = params.slice(0, params.length - 1); - const cb: (balance: Array) => any = params[params.length - 1]; - - return api.combineLatest( - addresses.map((address) => - [votingBalance(api), address] as [CombinatorFunction, ...Array] - ), cb - ); - }; -} diff --git a/packages/ui-api/src/derive/balances/votingBalancesNominatorsFor.ts b/packages/ui-api/src/derive/balances/votingBalancesNominatorsFor.ts deleted file mode 100644 index 350395d08c..0000000000 --- a/packages/ui-api/src/derive/balances/votingBalancesNominatorsFor.ts +++ /dev/null @@ -1,38 +0,0 @@ -// 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) => any): PromiseSubscription => { - let combineDestroy: PromiseSubscription | undefined; - const nominatorDestroy = api.query.staking.nominatorsFor(accountId, async (nominators?: Array) => { - 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(); - } - }; - }; -} diff --git a/packages/ui-api/src/derive/chain/bestNumber.ts b/packages/ui-api/src/derive/chain/bestNumber.ts deleted file mode 100644 index 932b798155..0000000000 --- a/packages/ui-api/src/derive/chain/bestNumber.ts +++ /dev/null @@ -1,18 +0,0 @@ -// 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 } 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): PromiseSubscription => - api.rpc.chain.subscribeNewHead((header?: Header) => { - if (header && header.blockNumber) { - cb(header.blockNumber); - } - }) as PromiseSubscription; -} diff --git a/packages/ui-api/src/derive/chain/bestNumberFinalised.ts b/packages/ui-api/src/derive/chain/bestNumberFinalised.ts deleted file mode 100644 index 0507f0d28f..0000000000 --- a/packages/ui-api/src/derive/chain/bestNumberFinalised.ts +++ /dev/null @@ -1,18 +0,0 @@ -// 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 } 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): PromiseSubscription => - api.rpc.chain.subscribeFinalisedHeads((header?: Header) => { - if (header && header.blockNumber) { - cb(header.blockNumber); - } - }) as PromiseSubscription; -} diff --git a/packages/ui-api/src/derive/chain/index.ts b/packages/ui-api/src/derive/chain/index.ts deleted file mode 100644 index 08efa1ab73..0000000000 --- a/packages/ui-api/src/derive/chain/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// 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. - -export { default as bestNumber } from './bestNumber'; -export { default as bestNumberFinalised } from './bestNumberFinalised'; diff --git a/packages/ui-api/src/derive/democracy/index.ts b/packages/ui-api/src/derive/democracy/index.ts deleted file mode 100644 index c3184be560..0000000000 --- a/packages/ui-api/src/derive/democracy/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -// 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. - -export { default as referendumInfos } from './referendumInfos'; -export { default as referendums } from './referendums'; -export { default as referendumVotesFor } from './referendumVotesFor'; -export { default as votes } from './votes'; diff --git a/packages/ui-api/src/derive/democracy/referendumInfos.ts b/packages/ui-api/src/derive/democracy/referendumInfos.ts deleted file mode 100644 index b18d859855..0000000000 --- a/packages/ui-api/src/derive/democracy/referendumInfos.ts +++ /dev/null @@ -1,27 +0,0 @@ -// 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 { PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; -import { ReferendumInfo } from '@polkadot/types'; - -export default function referendumInfos (api: ApiPromise): DeriveSubscription { - return async (...params: Array): PromiseSubscription => { - const ids: Array = params.slice(0, params.length - 1); - const cb: (infos: Array) => any = params[params.length - 1]; - - return api.combineLatest( - ids.map((id) => - [api.query.democracy.referendumInfoOf, id] as [CombinatorFunction, ...Array] - ), (infos: Array) => - cb( - (infos || []).filter((info) => info) as Array - ) - ); - }; -} diff --git a/packages/ui-api/src/derive/democracy/referendumVotesFor.ts b/packages/ui-api/src/derive/democracy/referendumVotesFor.ts deleted file mode 100644 index 7d77ccc7dc..0000000000 --- a/packages/ui-api/src/derive/democracy/referendumVotesFor.ts +++ /dev/null @@ -1,57 +0,0 @@ -// 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 { PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription, DerivedReferendumVote } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, Balance, Vote } from '@polkadot/types'; - -import votingBalances from '../balances/votingBalances'; -import votes from './votes'; - -export default function referendumVotesFor (api: ApiPromise): DeriveSubscription { - return async (referendumId: BN | number, cb: (votes: Array) => any): PromiseSubscription => { - let innerDispose: PromiseSubscription | undefined; - const outerDispose = api.query.democracy.votersFor(referendumId, async (votersFor: Array) => { - if (innerDispose) { - const unsubscribe = await innerDispose; - - unsubscribe(); - innerDispose = undefined; - } - - if (!votersFor || !votersFor.length) { - return cb([]); - } - - innerDispose = api.combineLatest([ - [votes(api), referendumId, ...votersFor] as [CombinatorFunction, ...Array], - [votingBalances(api), ...votersFor] as [CombinatorFunction, ...Array] - ], ([votes, balances]) => - cb( - votersFor.map((accountId, index): DerivedReferendumVote => ({ - accountId, - balance: balances[index].votingBalance || new Balance(0), - vote: votes[index] || new Vote(0) - })) - ) - ); - }); - - return async () => { - let unsubscribe = await outerDispose; - - unsubscribe(); - - if (innerDispose) { - unsubscribe = await innerDispose; - - unsubscribe(); - } - }; - }; -} diff --git a/packages/ui-api/src/derive/democracy/referendums.ts b/packages/ui-api/src/derive/democracy/referendums.ts deleted file mode 100644 index 6bc6585f73..0000000000 --- a/packages/ui-api/src/derive/democracy/referendums.ts +++ /dev/null @@ -1,50 +0,0 @@ -// 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 } from '../types'; - -import ApiPromise from '@polkadot/api/promise'; -import { ReferendumInfo } from '@polkadot/types'; - -import referendumInfos from './referendumInfos'; - -export default function referendums (api: ApiPromise): DeriveSubscription { - return async (cb: (referendums: Array) => any): PromiseSubscription => { - let innerDispose: PromiseSubscription | undefined; - const outerDispose = api.combineLatest([ - api.query.democracy.nextTally, - api.query.democracy.referendumCount - ], async ([nextTally, referendumCount]) => { - if (innerDispose) { - const unsubscribe = await innerDispose; - - unsubscribe(); - innerDispose = undefined; - } - - if (referendumCount && nextTally && referendumCount.gt(nextTally) && referendumCount.gtn(0)) { - innerDispose = referendumInfos(api)( - ...[...Array(referendumCount.sub(nextTally).toNumber())].map((_, i) => - nextTally.addn(i) - ), cb - ); - } else { - cb([]); - } - }); - - return async () => { - let unsubscribe = await outerDispose; - - unsubscribe(); - - if (innerDispose) { - unsubscribe = await innerDispose; - - unsubscribe(); - } - }; - }; -} diff --git a/packages/ui-api/src/derive/democracy/votes.tsx b/packages/ui-api/src/derive/democracy/votes.tsx deleted file mode 100644 index 65e3272ebd..0000000000 --- a/packages/ui-api/src/derive/democracy/votes.tsx +++ /dev/null @@ -1,23 +0,0 @@ -// 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, PromiseSubscription } from '@polkadot/api/promise/types'; -import { DeriveSubscription } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; -import { AccountId, bool as Bool } from '@polkadot/types'; - -export default function votes (api: ApiPromise): DeriveSubscription { - return async (...params: Array): PromiseSubscription => { - const referendumId: BN = params[0]; - const accountIds: Array = params.slice(1, params.length - 1); - const cb: (infos: Array) => any = params[params.length - 1]; - - return api.combineLatest( - accountIds.map((accountId) => - [api.query.democracy.voteOf, [referendumId, accountId]] as [QueryableStorageFunction, ...Array] - ), cb); - }; -} diff --git a/packages/ui-api/src/derive/index.ts b/packages/ui-api/src/derive/index.ts deleted file mode 100644 index e6cc49681b..0000000000 --- a/packages/ui-api/src/derive/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// 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 * as balances from './balances'; -import * as chain from './chain'; -import * as democracy from './democracy'; -import * as session from './session'; - -export default { - balances, - chain, - democracy, - session -}; diff --git a/packages/ui-api/src/derive/session/eraLength.ts b/packages/ui-api/src/derive/session/eraLength.ts deleted file mode 100644 index 6a70261eaf..0000000000 --- a/packages/ui-api/src/derive/session/eraLength.ts +++ /dev/null @@ -1,19 +0,0 @@ -// 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 } 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): PromiseSubscription => - api.combineLatest([ - api.query.session.sessionLength, - api.query.staking.sessionsPerEra - ], ([sessionLength, sessionsPerEra]) => - cb((sessionLength || new BN(1)).mul(sessionsPerEra || new BN(1))) - ); -} diff --git a/packages/ui-api/src/derive/session/eraProgress.ts b/packages/ui-api/src/derive/session/eraProgress.ts deleted file mode 100644 index 3c11120e4e..0000000000 --- a/packages/ui-api/src/derive/session/eraProgress.ts +++ /dev/null @@ -1,30 +0,0 @@ -// 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 } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; - -import sessionProgress from './sessionProgress'; - -export default function eraProgress (api: ApiPromise): DeriveSubscription { - return (cb: (count: BN) => any): PromiseSubscription => - api.combineLatest([ - sessionProgress(api), - api.query.session.currentIndex, - api.query.session.sessionLength, - api.query.staking.lastEraLengthChange, - api.query.staking.sessionsPerEra - ], ([sessionProgress, currentIndex, sessionLength, lastEraLengthChange, sessionsPerEra]) => - cb( - (currentIndex || new BN(0)) - .sub(lastEraLengthChange || new BN(0)) - .mod(sessionsPerEra || new BN(1)) - .mul(sessionLength || new BN(1)) - .add(sessionProgress || new BN(0)) - ) - ); -} diff --git a/packages/ui-api/src/derive/session/index.ts b/packages/ui-api/src/derive/session/index.ts deleted file mode 100644 index a038a7a6c0..0000000000 --- a/packages/ui-api/src/derive/session/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// 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. - -export { default as eraLength } from './eraLength'; -export { default as eraProgress } from './eraProgress'; -export { default as sessionProgress } from './sessionProgress'; diff --git a/packages/ui-api/src/derive/session/sessionProgress.ts b/packages/ui-api/src/derive/session/sessionProgress.ts deleted file mode 100644 index f0d337fa2b..0000000000 --- a/packages/ui-api/src/derive/session/sessionProgress.ts +++ /dev/null @@ -1,27 +0,0 @@ -// 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 } from '../types'; - -import BN from 'bn.js'; -import ApiPromise from '@polkadot/api/promise'; - -import bestNumber from '../chain/bestNumber'; - -export default function sessionProgress (api: ApiPromise): DeriveSubscription { - return (cb: (count: BN) => any): PromiseSubscription => - api.combineLatest([ - bestNumber(api), - api.query.session.sessionLength, - api.query.session.lastLengthChange - ], ([bestNumber, sessionLength, lastLengthChange]) => - cb( - (bestNumber || new BN(0)) - .sub(lastLengthChange || new BN(0)) - .add(sessionLength || new BN(1)) - .mod(sessionLength || new BN(1)) - ) - ); -} diff --git a/packages/ui-api/src/derive/types.ts b/packages/ui-api/src/derive/types.ts deleted file mode 100644 index 10f4e4e8ca..0000000000 --- a/packages/ui-api/src/derive/types.ts +++ /dev/null @@ -1,40 +0,0 @@ -// 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 BN from 'bn.js'; -import { AccountId, Balance, Vote } from '@polkadot/types'; - -export interface DeriveSubscription { - (...params: Array): PromiseSubscription; -} - -export type DerivedBalancesFees = { - creationFee: BN, - existentialDeposit: BN, - transactionBaseFee: BN, - transactionByteFee: BN, - transferFee: BN -}; - -export type DerivedBalances = { - accountId: AccountId, - freeBalance: Balance, - nominatedBalance: Balance, - reservedBalance: Balance, - votingBalance: Balance, - stakingBalance: Balance, - nominators?: Array -}; - -export type DerivedBalancesMap = { - [index: string]: DerivedBalances -}; - -export type DerivedReferendumVote = { - accountId: AccountId, - balance: Balance, - vote: Vote -}; diff --git a/packages/ui-api/src/util/index.ts b/packages/ui-api/src/util/index.ts index 6dbbbc9273..f100f44e8b 100644 --- a/packages/ui-api/src/util/index.ts +++ b/packages/ui-api/src/util/index.ts @@ -3,14 +3,12 @@ // of the Apache-2.0 license. See the LICENSE file for details. import intervalObservable from './intervalObservable'; -import intervalTimer from './intervalTimer'; import isEqual from './isEqual'; import isTestChain from './isTestChain'; import triggerChange from './triggerChange'; export { intervalObservable, - intervalTimer, isEqual, isTestChain, triggerChange diff --git a/packages/ui-api/src/util/intervalTimer.ts b/packages/ui-api/src/util/intervalTimer.ts deleted file mode 100644 index 75e4d005dd..0000000000 --- a/packages/ui-api/src/util/intervalTimer.ts +++ /dev/null @@ -1,18 +0,0 @@ -// 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 { CallProps } from '../types'; - -const TIMEOUT = 500; - -export default function intervalTimer (that: React.Component): number { - return window.setInterval(() => { - const elapsed = Date.now() - ((that.state.callUpdatedAt as number) || 0); - const callUpdated = elapsed <= 1500; - - if (callUpdated !== that.state.callUpdated) { - that.setState({ callUpdated }); - } - }, TIMEOUT); -} diff --git a/packages/ui-api/src/with/api.tsx b/packages/ui-api/src/with/api.tsx index 2750321ba6..3f93f1663e 100644 --- a/packages/ui-api/src/with/api.tsx +++ b/packages/ui-api/src/with/api.tsx @@ -12,16 +12,10 @@ import { ApiConsumer } from '../ApiContext'; export default function withApi

(Inner: React.ComponentType

, defaultProps: DefaultProps = {}): React.ComponentType { return class WithApi extends React.PureComponent> { - constructor (props: any) { - super(props); - - assert(Inner, `Expected 'withApi' to wrap a React Component`); - } - render () { return ( - {(apiProps: ApiProps) => { + {(apiProps?: ApiProps) => { assert(apiProps && apiProps.apiPromise, `Application root must be wrapped inside 'rx-react/Api' to provide API context`); return ( diff --git a/packages/ui-api/src/with/call.tsx b/packages/ui-api/src/with/call.tsx index 0d6f9b7a2b..3f55ad00f8 100644 --- a/packages/ui-api/src/with/call.tsx +++ b/packages/ui-api/src/with/call.tsx @@ -8,8 +8,7 @@ import { HOC, Options } from './types'; import React from 'react'; import { assert, isUndefined } from '@polkadot/util'; -import derive from '../derive/index'; -import { intervalTimer, isEqual, triggerChange } from '../util/index'; +import { isEqual, triggerChange } from '../util/index'; import echoTransform from '../transform/echo'; import withApi from './api'; @@ -32,6 +31,7 @@ export default function withCall

(endpoint: string, { at, at return (Inner: React.ComponentType): React.ComponentType => { class WithPromise extends React.Component { state: State; + isActive: boolean = true; constructor (props: P) { super(props); @@ -51,7 +51,7 @@ export default function withCall

(endpoint: string, { at, at const newParams = this.getParams(this.props); const oldParams = this.getParams(prevProps); - if (!isEqual(newParams, oldParams)) { + if (this.isActive && !isEqual(newParams, oldParams)) { this .subscribe(newParams) .then(NOOP) @@ -60,8 +60,17 @@ export default function withCall

(endpoint: string, { at, at } componentDidMount () { - this.setState({ - timerId: intervalTimer(this) + const timerId = window.setInterval(() => { + const elapsed = Date.now() - (this.state.callUpdatedAt || 0); + const callUpdated = elapsed <= 1500; + + if (callUpdated !== this.state.callUpdated) { + this.nextState({ callUpdated }); + } + }, 500); + + this.nextState({ + timerId }); this @@ -73,6 +82,8 @@ export default function withCall

(endpoint: string, { at, at componentWillUnmount () { const { timerId } = this.state; + this.isActive = false; + if (timerId !== -1) { clearInterval(timerId); } @@ -80,6 +91,12 @@ export default function withCall

(endpoint: string, { at, at this.unsubscribe(); } + private nextState (state: Partial) { + if (this.isActive) { + this.setState(state as State); + } + } + private getParams (props: any): Array { const paramValue = props[paramProp]; @@ -115,18 +132,6 @@ export default function withCall

(endpoint: string, { at, at assert(['rpc', 'query', 'derive'].includes(area), `Unknown api.${area}, expected rpc, query or derive`); assert(!at || area === 'query', 'Only able todo an at query on the api.query interface'); - if (area === 'derive') { - const apiSection = (derive as any)[section]; - - assert(apiSection && apiSection[method], `Unable to find api.derive.${section}.${method}`); - - return [ - apiSection[method](apiPromise), - newParams, - true - ]; - } - const apiSection = (apiPromise as any)[area][section]; assert(apiSection && apiSection[method], `Unable to find api.${area}.${section}.${method}`); @@ -134,7 +139,7 @@ export default function withCall

(endpoint: string, { at, at return [ apiSection[method], newParams, - (area === 'query' && (!at && !atProp)) || method.startsWith('subscribe') + area === 'derive' || (area === 'query' && (!at && !atProp)) || method.startsWith('subscribe') ]; } @@ -155,7 +160,7 @@ export default function withCall

(endpoint: string, { at, at this.triggerUpdate(this.props, value) ); - this.setState({ destroy }); + this.nextState({ destroy }); } else { const value: any = at ? await apiMethod.at(at, ...params) @@ -180,13 +185,13 @@ export default function withCall

(endpoint: string, { at, at try { const callResult = (props.transform || transform)(value); - if (isEqual(callResult, this.state.callResult)) { + if (!this.isActive || isEqual(callResult, this.state.callResult)) { return; } triggerChange(callResult, callOnResult, props.callOnResult); - this.setState({ + this.nextState({ callResult, callUpdated: true, callUpdatedAt: Date.now() diff --git a/packages/ui-app/package.json b/packages/ui-app/package.json index 8a6f89c73d..388000e4c8 100644 --- a/packages/ui-app/package.json +++ b/packages/ui-app/package.json @@ -11,10 +11,10 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/extrinsics": "^0.39.12", + "@polkadot/extrinsics": "^0.40.5", "@polkadot/keyring": "^0.33.34", - "@polkadot/storage": "^0.39.12", - "@polkadot/types": "^0.39.12", + "@polkadot/storage": "^0.40.5", + "@polkadot/types": "^0.40.5", "@polkadot/ui-api": "^0.22.21", "@polkadot/ui-identicon": "^0.25.5", "@polkadot/ui-keyring": "^0.25.5", diff --git a/packages/ui-app/src/Status/types.ts b/packages/ui-app/src/Status/types.ts index fc107dc199..35eff3028f 100644 --- a/packages/ui-app/src/Status/types.ts +++ b/packages/ui-app/src/Status/types.ts @@ -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 SubmittableExtrinsic from '@polkadot/api/promise/SubmittableExtrinsic'; +import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { RpcMethod } from '@polkadot/jsonrpc/types'; import { AccountId, Address } from '@polkadot/types'; diff --git a/packages/ui-reactive/package.json b/packages/ui-reactive/package.json index e68f147bd3..e6061a911e 100644 --- a/packages/ui-reactive/package.json +++ b/packages/ui-reactive/package.json @@ -31,8 +31,8 @@ "homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/api": "^0.39.12", - "@polkadot/types": "^0.39.12", + "@polkadot/api": "^0.40.5", + "@polkadot/types": "^0.40.5", "rxjs-compat": "^6.3.2" } } diff --git a/packages/ui-signer/src/Fees/Proposal.tsx b/packages/ui-signer/src/Fees/Proposal.tsx index 3edeea4e15..49cc593676 100644 --- a/packages/ui-signer/src/Fees/Proposal.tsx +++ b/packages/ui-signer/src/Fees/Proposal.tsx @@ -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 { DerivedBalancesFees } from '@polkadot/ui-api/derive/types'; +import { DerivedFees } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { ExtraFees } from './types'; @@ -17,7 +17,7 @@ import translate from '../translate'; type Props = I18nProps & { deposit: BN | Compact, - fees: DerivedBalancesFees, + fees: DerivedFees, query_democracy_minimumDeposit?: BN onChange: (fees: ExtraFees) => void }; diff --git a/packages/ui-signer/src/Fees/Transfer.tsx b/packages/ui-signer/src/Fees/Transfer.tsx index 6bb79714bf..6c07b43051 100644 --- a/packages/ui-signer/src/Fees/Transfer.tsx +++ b/packages/ui-signer/src/Fees/Transfer.tsx @@ -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 { DerivedBalances, DerivedBalancesFees } from '@polkadot/ui-api/derive/types'; +import { DerivedBalances, DerivedFees } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { ExtraFees } from './types'; @@ -18,7 +18,7 @@ import { ZERO_BALANCE } from './constants'; type Props = I18nProps & { amount: BN | Compact, - fees: DerivedBalancesFees, + fees: DerivedFees, derive_balances_votingBalance?: DerivedBalances, recipientId: string, onChange: (fees: ExtraFees) => void diff --git a/packages/ui-signer/src/Fees/constants.ts b/packages/ui-signer/src/Fees/constants.ts index d58b1309ac..2446baa5fd 100644 --- a/packages/ui-signer/src/Fees/constants.ts +++ b/packages/ui-signer/src/Fees/constants.ts @@ -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 { DerivedBalancesFees, DerivedBalances } from '@polkadot/ui-api/derive/types'; +import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types'; import BN from 'bn.js'; @@ -18,4 +18,4 @@ export const ZERO_FEES = { creationFee: new BN(0), existentialDeposit: new BN(0), transferFee: new BN(0) -} as DerivedBalancesFees; +} as DerivedFees; diff --git a/packages/ui-signer/src/Fees/index.tsx b/packages/ui-signer/src/Fees/index.tsx index 41076d4c04..05babcaf80 100644 --- a/packages/ui-signer/src/Fees/index.tsx +++ b/packages/ui-signer/src/Fees/index.tsx @@ -3,7 +3,7 @@ // 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-api/derive/types'; +import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types'; import { ExtraFees } from './types'; import BN from 'bn.js'; @@ -31,7 +31,7 @@ type State = ExtraFees & { }; type Props = I18nProps & { - derive_balances_fees?: DerivedBalancesFees, + derive_balances_fees?: DerivedFees, derive_balances_votingBalance?: DerivedBalances, accountId?: string | null, extrinsic: Extrinsic | null, diff --git a/packages/ui-signer/src/Modal.tsx b/packages/ui-signer/src/Modal.tsx index 7b96bdd837..b050a4dacd 100644 --- a/packages/ui-signer/src/Modal.tsx +++ b/packages/ui-signer/src/Modal.tsx @@ -3,14 +3,13 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { SubmittableSendResult } from '@polkadot/api/types'; -import { PromiseSubscription } from '@polkadot/api/promise/types'; +import { PromiseSubscription, SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { ApiProps } from '@polkadot/ui-api/types'; import { I18nProps, BareProps } from '@polkadot/ui-app/types'; import { RpcMethod } from '@polkadot/jsonrpc/types'; import { QueueTx, QueueTx$MessageSetStatus, QueueTx$Result, QueueTx$Status } from '@polkadot/ui-app/Status/types'; import React from 'react'; -import SubmittableExtrinsic from '@polkadot/api/promise/SubmittableExtrinsic'; import { Button, Modal } from '@polkadot/ui-app/index'; import keyring from '@polkadot/ui-keyring'; import { withApi, withMulti } from '@polkadot/ui-api/index'; diff --git a/yarn.lock b/yarn.lock index 2e0ac9ebae..ac66609555 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1385,31 +1385,31 @@ resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw== -"@polkadot/api-derive@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.39.12.tgz#ba71228bdbeedc19fee309aa9433a47a227160a5" - integrity sha512-oIzedZur3dl4tgZyrEUd0CZY3E1gp3jZKUokshEqqUqL2ZpDAGLJzmd2OIghgg4BOpTDCQ+DA0xheP43s+W/kw== +"@polkadot/api-derive@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.40.5.tgz#eb70c942c1a027c5e4dfceab37acb63b00397ef0" + integrity sha512-c7s7PLDTJRdIkP7mtwsuEAx9A2T6vM3w1mWDgwQdJOVAHE8dYD2ntEkgBjzHdZZW1OBqYiAQf00KaPoJH2eevg== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/api" "^0.39.12" - "@polkadot/types" "^0.39.12" + "@polkadot/api" "^0.40.5" + "@polkadot/types" "^0.40.5" "@types/memoizee" "^0.4.2" "@types/rx" "^4.1.1" memoizee "^0.4.14" rxjs "^6.3.3" -"@polkadot/api@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.39.12.tgz#97f2573b85cdf8c522ff64f9f4c39eb50c1b251e" - integrity sha512-KvljNOWGUPlW4QXEjmUQwK4OE19t+veoCNfpk9U9wwHs+96qBdznBXvU79IMb3mJn3sH/TV6Nj8Ac7kCL0ForA== +"@polkadot/api@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.40.5.tgz#710445599743f7b6d0b1c56a6bb149c145e31fb6" + integrity sha512-fAWQmvOWmxrexVwyUOB/c4nzkk93/Ydc0yXboFfE71l6NYBbf42nf6cha3WP7gY39iRVFX2rpgSUg6Lva65StA== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/api-derive" "^0.39.12" - "@polkadot/extrinsics" "^0.39.12" - "@polkadot/rpc-provider" "^0.39.12" - "@polkadot/rpc-rx" "^0.39.12" - "@polkadot/storage" "^0.39.12" - "@polkadot/types" "^0.39.12" + "@polkadot/api-derive" "^0.40.5" + "@polkadot/extrinsics" "^0.40.5" + "@polkadot/rpc-provider" "^0.40.5" + "@polkadot/rpc-rx" "^0.40.5" + "@polkadot/storage" "^0.40.5" + "@polkadot/types" "^0.40.5" "@types/rx" "^4.1.1" rxjs "^6.3.3" @@ -1503,19 +1503,19 @@ typedoc-plugin-no-inherit "^1.1.2" typescript "^3.2.2" -"@polkadot/extrinsics@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.39.12.tgz#dc0ed7c4cf46d6709d2647dd7e8bad0e6f2df609" - integrity sha512-hOCh+dnjBhLG0j+YxX40qCe6ftGRVjr9M7vScz4ZLSiSq7AtBOaYwj4/J5qUdyEnrKLlxCEqN1DCUzS7PMtYbA== +"@polkadot/extrinsics@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.40.5.tgz#0db250d23dbc8c64df1aed59c8bac4cb90eb0321" + integrity sha512-+a2XSHOY1vPbxSRr9FLJieOKcpNZE/vEjeXrQD6CxtH+PJIFY/1Cfg/qNYNRH5/68ezwceWbYPr/rM47MJWp5w== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/types" "^0.39.12" + "@polkadot/types" "^0.40.5" "@polkadot/util" "^0.33.34" -"@polkadot/jsonrpc@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.39.12.tgz#1cddca39fbcd4d6782c2ffc14896180ab87f1071" - integrity sha512-MhtC3pqW4XS+b184RxAoNfKCriw7gAy5oSI1nx/AbsHpMikjzRLgg9PDVo2M9vgAL2cvPlQkq8WcP2GcWZ1iiQ== +"@polkadot/jsonrpc@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.40.5.tgz#df35983cea429a4252967daa9cb0678a79b2750c" + integrity sha512-y1e9rodqQ4zxpn02vRM5eOMK63mnRuEv9t7KAxOowK67Hg8qaY86eEMjaquBGtso8qPK87qRX7FWhBwOGAHdog== dependencies: "@babel/runtime" "^7.2.0" @@ -1530,25 +1530,25 @@ "@types/bs58" "^4.0.0" bs58 "^4.0.1" -"@polkadot/rpc-core@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.39.12.tgz#065eacdd15fa05f496115fb0f4d4dbed95110418" - integrity sha512-IIuJDmr9z3txC7WZPon5kBQDJJbjODeoFEdqY1oZUnm/Ikxzwd+CW1VvWtgjYmfJvm4JNyqp+z5bzSFV6AA9lQ== +"@polkadot/rpc-core@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.40.5.tgz#94ae335cda19d7e0477e1382d90e0b32aa5fc649" + integrity sha512-tX9KFHNViaHJ0/BH5eFEsoDsL4TqJnifLPv+bseNJvsVANm4/z1BykBudezkXKM5FzbPcsJbOFeh9if7ucYa/Q== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/jsonrpc" "^0.39.12" - "@polkadot/rpc-provider" "^0.39.12" - "@polkadot/types" "^0.39.12" + "@polkadot/jsonrpc" "^0.40.5" + "@polkadot/rpc-provider" "^0.40.5" + "@polkadot/types" "^0.40.5" "@polkadot/util" "^0.33.34" -"@polkadot/rpc-provider@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.39.12.tgz#4edbffac1cb867a72dc79be9db3cb67da6826346" - integrity sha512-0HAwhELx1AnWQixNIwaRWF1zdX/t9gd3pA+/TFLQ6KZs9TjgQlELDeFcwqHzY755Ce4yrFq5SX9zHO+z7UKS4A== +"@polkadot/rpc-provider@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.40.5.tgz#86343190a8e604171eb815e86a00d1ce415965cb" + integrity sha512-NZnpP19izoaaoUCtF0MKYzraqdnJX4/xbm8cP+O4Q3scW6VJR0WP+MLqgRQZirA44lsy7Qh0+HTaLqYIv6dKUw== dependencies: "@babel/runtime" "^7.2.0" "@polkadot/keyring" "^0.33.34" - "@polkadot/storage" "^0.39.12" + "@polkadot/storage" "^0.40.5" "@polkadot/util" "^0.33.34" "@polkadot/util-crypto" "^0.33.34" "@types/nock" "^9.3.0" @@ -1556,25 +1556,25 @@ isomorphic-fetch "^2.2.1" websocket "^1.0.28" -"@polkadot/rpc-rx@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-rx/-/rpc-rx-0.39.12.tgz#b71cffb43790ee794a14c8581375aa14f8d4cf08" - integrity sha512-syGXoFwsh1DZrlpzqQqvjMz3BYJ14IU80eraWOml7dQXEE19f+2qkWTogxQ0YnYBBbI5EJE/PwjbrnsoQ76ySg== +"@polkadot/rpc-rx@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-rx/-/rpc-rx-0.40.5.tgz#cfd078aa500e2f6d9e762ef36842b5210a7947c9" + integrity sha512-ZqcynFZioS9QeGwTVL3VarFwwEtnL89AjYdpW0PuViE4nqXd4TJzxG8TL9gaklPIwrZH3CJUZa+tyTpvJ3dDsw== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/rpc-core" "^0.39.12" - "@polkadot/rpc-provider" "^0.39.12" + "@polkadot/rpc-core" "^0.40.5" + "@polkadot/rpc-provider" "^0.40.5" "@types/rx" "^4.1.1" rxjs "^6.3.3" -"@polkadot/storage@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.39.12.tgz#cab5d86eec3620a61921983a44dcb8263d0e38ee" - integrity sha512-9+OfUVa7OpOED9nQNvEGtocZhIeMl4HNZbFYuNkyy6kFxeOv9gavm4rBgH+keBGTxjqQ3+WcFrUXBPQn+pWobg== +"@polkadot/storage@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.40.5.tgz#9a82c662913bbe28a787993ce5a4f09b990423e1" + integrity sha512-d95FojPAmSDPmLckqw0PP6yDXQstEHhRsEtlEAKGAYdebANluP1b5LX9qzBaYhE9n1BINFOC8ifFl4hvbWUZ/Q== dependencies: "@babel/runtime" "^7.2.0" "@polkadot/keyring" "^0.33.34" - "@polkadot/types" "^0.39.12" + "@polkadot/types" "^0.40.5" "@polkadot/util" "^0.33.34" "@polkadot/util-crypto" "^0.33.34" @@ -1583,10 +1583,10 @@ resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.50.tgz#29a7982203f34e1b6a1215ddaab4efdc4010a099" integrity sha512-yKRJ7+EKW4rZxuSyAvQvjJsImNBqMsWF1NZTkMSfPsLFC5daC9eFuL6O+DdpvOnIKWbrLu2iLCwC9pzFLe7Low== -"@polkadot/types@^0.39.12": - version "0.39.12" - resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.39.12.tgz#2c9e085589b6dc49eb3f28faaec5e0f2953cb946" - integrity sha512-pwjf9YBh4osJ/alnFBvZ0I/TUyZrDstz3DSpGT1g6aBGrAZTnXFLu5GTSaGogOUj6i86UdboI7QwNtf/7WaIQg== +"@polkadot/types@^0.40.5": + version "0.40.5" + resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.40.5.tgz#ff35d953f6277049eb69b990fc36874b47fbe8a8" + integrity sha512-OcBvydAtHkrIkKJHxHVftllhQQfRRZpXVqBuJN7/5pxlQOhnA76FFiFhtXhdM8a8rbdz9dbKeOiMC2SN1lQAVA== dependencies: "@babel/runtime" "^7.2.0" "@polkadot/keyring" "^0.33.34" @@ -7972,23 +7972,11 @@ libsodium-wrappers@^0.7.3: dependencies: libsodium "0.7.3" -libsodium-wrappers@^0.7.4: - version "0.7.4" - resolved "https://registry.yarnpkg.com/libsodium-wrappers/-/libsodium-wrappers-0.7.4.tgz#cdb3ce6553e4864c0a68070c4313583489bd765d" - integrity sha512-axKkW01L0q+urLeE7UMSZKWwk4LrRbi6s5pjKBAvbgDBYnsSaolK1oN/Syilm1dqJFkJQNi6qodwOp8dzSoc9Q== - dependencies: - libsodium "0.7.4" - libsodium@0.7.3: version "0.7.3" resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.3.tgz#35faf57293ba5485049d5072d0e96feda12f1f35" integrity sha512-ld+deUNqSsZYbAobUs63UyduPq8ICp/Ul/5lbvBIYpuSNWpPRU0PIxbW+xXipVZtuopR6fIz9e0tTnNuPMNeqw== -libsodium@0.7.4: - version "0.7.4" - resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.4.tgz#a5bccd65e3a13b34147ea109be3c65d89f90b074" - integrity sha512-fTU3vUdrxQzhPAAjmTSqKk4LzYbR0OtcYjp1P92AlH50JIxXZFEIXWh1yryCmU6RLGfwS2IzBdZjbmpYf/TlyQ== - lightercollective@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/lightercollective/-/lightercollective-0.1.0.tgz#70df102c530dcb8d0ccabfe6175a8d00d5f61300"