diff --git a/package.json b/package.json index 79fadc0a6a..62cbf66aa1 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.91.0-beta.14", - "@polkadot/api-contract": "^0.91.0-beta.14", + "@polkadot/api": "^0.91.0-beta.15", + "@polkadot/api-contract": "^0.91.0-beta.15", "@polkadot/keyring": "^1.2.0-beta.6", - "@polkadot/types": "^0.91.0-beta.14", + "@polkadot/types": "^0.91.0-beta.15", "@polkadot/util": "^1.2.0-beta.6", "@polkadot/util-crypto": "^1.2.0-beta.6", "@types/styled-components": "4.1.8", diff --git a/packages/app-accounts/src/modals/Transfer.tsx b/packages/app-accounts/src/modals/Transfer.tsx index b8b736fc0a..f3f0968d80 100644 --- a/packages/app-accounts/src/modals/Transfer.tsx +++ b/packages/app-accounts/src/modals/Transfer.tsx @@ -17,6 +17,7 @@ import { Available } from '@polkadot/react-query'; import Checks, { calcSignatureLength } from '@polkadot/react-signer/Checks'; import { withApi, withCalls, withMulti } from '@polkadot/react-api'; import { ZERO_FEES } from '@polkadot/react-signer/Checks/constants'; +import { bnMax } from '@polkadot/util'; import translate from '../translate'; @@ -215,11 +216,11 @@ class Transfer extends React.PureComponent { const txLength = calcSignatureLength(extrinsic, accountNonce); const fees = transactionBaseFee - .add(transactionByteFee.muln(txLength)) + .add(transactionByteFee.mul(txLength)) .add(transferFee) .add(recipientBalance.isZero() ? creationFee : ZERO); - maxBalance = senderBalance.sub(fees); + maxBalance = bnMax(senderBalance.sub(fees), ZERO); } this.nextState({ diff --git a/packages/app-contracts/package.json b/packages/app-contracts/package.json index fb48a846c1..ab5ae9460d 100644 --- a/packages/app-contracts/package.json +++ b/packages/app-contracts/package.json @@ -11,7 +11,7 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.5.5", - "@polkadot/api-contract": "^0.91.0-beta.14", + "@polkadot/api-contract": "^0.91.0-beta.15", "@polkadot/react-components": "^0.35.0-beta.26" } } diff --git a/packages/app-staking/src/Actions/Account/BondExtra.tsx b/packages/app-staking/src/Actions/Account/BondExtra.tsx index 2ec2bb97c1..6d91c98ddb 100644 --- a/packages/app-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/app-staking/src/Actions/Account/BondExtra.tsx @@ -14,6 +14,7 @@ import { calcSignatureLength } from '@polkadot/react-signer/Checks'; import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { withCalls, withApi, withMulti } from '@polkadot/react-api'; import { ZERO_BALANCE, ZERO_FEES } from '@polkadot/react-signer/Checks/constants'; +import { bnMax } from '@polkadot/util'; import translate from '../../translate'; @@ -152,17 +153,14 @@ class BondExtra extends TxComponent { while (!prevMax.eq(maxBalance)) { prevMax = maxBalance; - extrinsic = (maxAdditional && maxAdditional.gte(ZERO)) ? api.tx.staking.bondExtra(maxAdditional) : null; const txLength = calcSignatureLength(extrinsic, system_accountNonce); + const fees = transactionBaseFee.add(transactionByteFee.mul(txLength)); - const fees = transactionBaseFee - .add(transactionByteFee.muln(txLength)); - - maxBalance = availableBalance.sub(fees); + maxBalance = bnMax(availableBalance.sub(fees), ZERO); } this.nextState({ diff --git a/packages/react-api/package.json b/packages/react-api/package.json index 50e79777c9..a264a8a92c 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -31,8 +31,9 @@ "homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme", "dependencies": { "@babel/runtime": "^7.5.5", - "@polkadot/api": "^0.91.0-beta.14", + "@polkadot/api": "^0.91.0-beta.15", "@polkadot/extension-dapp": "^0.10.0-beta.1", + "edgeware-node-types": "^1.0.9", "rxjs-compat": "^6.4.0" } } diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 73681d936b..82e9cb0f64 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -20,6 +20,8 @@ import ApiSigner from '@polkadot/react-signer/ApiSigner'; import { Text, u32 as U32 } from '@polkadot/types'; import { formatBalance, isTestChain } from '@polkadot/util'; +import typesChain from './overrides/chain'; +import typesSpec from './overrides/spec'; import ApiContext from './ApiContext'; let api: ApiPromise; @@ -58,7 +60,7 @@ export default class Api extends React.PureComponent { const signer = new ApiSigner(queuePayload, queueSetTxStatus); const setApi = (provider: ProviderInterface): void => { - api = new ApiPromise({ provider, signer }); + api = this.createApi(provider, signer); this.setState({ api }, (): void => { this.subscribeEvents(); @@ -67,7 +69,7 @@ export default class Api extends React.PureComponent { const setApiUrl = (url: string = defaults.WS_URL): void => setApi(new WsProvider(url)); - api = new ApiPromise({ provider, signer }); + api = this.createApi(provider, signer); this.state = { api, @@ -79,6 +81,15 @@ export default class Api extends React.PureComponent { } as unknown as State; } + private createApi (provider: ProviderInterface, signer: ApiSigner): ApiPromise { + return new ApiPromise({ + provider, + signer, + typesChain, + typesSpec + }); + } + public componentDidMount (): void { this.subscribeEvents(); diff --git a/packages/react-api/src/overrides/chain/index.ts b/packages/react-api/src/overrides/chain/index.ts new file mode 100644 index 0000000000..a31a2d0655 --- /dev/null +++ b/packages/react-api/src/overrides/chain/index.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2019 @polkadot/react-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 {}; diff --git a/packages/react-api/src/overrides/spec/edgeware.ts b/packages/react-api/src/overrides/spec/edgeware.ts new file mode 100644 index 0000000000..b070d8fe19 --- /dev/null +++ b/packages/react-api/src/overrides/spec/edgeware.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2019 @polkadot/react-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 { IdentityTypes } from 'edgeware-node-types/dist/identity'; +import { SignalingTypes } from 'edgeware-node-types/dist/signaling'; +import { VotingTypes } from 'edgeware-node-types/dist/voting'; + +export default { + ...IdentityTypes, + ...SignalingTypes, + ...VotingTypes +}; diff --git a/packages/react-api/src/overrides/spec/index.ts b/packages/react-api/src/overrides/spec/index.ts new file mode 100644 index 0000000000..f0c74b1b58 --- /dev/null +++ b/packages/react-api/src/overrides/spec/index.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2019 @polkadot/react-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 edgeware from './edgeware'; + +export default { + edgeware +}; diff --git a/packages/react-components/src/InputBalanceBonded.tsx b/packages/react-components/src/InputBalanceBonded.tsx index 3a6e674f0a..ba2f48a3da 100644 --- a/packages/react-components/src/InputBalanceBonded.tsx +++ b/packages/react-components/src/InputBalanceBonded.tsx @@ -15,6 +15,7 @@ import { InputNumber } from '@polkadot/react-components'; import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { withCalls, withMulti, withApi } from '@polkadot/react-api'; import { ZERO_BALANCE, ZERO_FEES } from '@polkadot/react-signer/Checks/constants'; +import { bnMax } from '@polkadot/util'; type Props = BareProps & ApiProps & { autoFocus?: boolean; @@ -124,10 +125,9 @@ class InputBalanceBonded extends React.PureComponent { } const txLength = calcSignatureLength(extrinsic, system_accountNonce); - const fees = transactionBaseFee - .add(transactionByteFee.muln(txLength)); + const fees = transactionBaseFee.add(transactionByteFee.mul(txLength)); - maxBalance = new BN(freeBalance).sub(fees); + maxBalance = bnMax(freeBalance.sub(fees), ZERO); } this.nextState({ diff --git a/packages/react-components/src/TxComponent.tsx b/packages/react-components/src/TxComponent.tsx index 5c16e621d4..d075d644c3 100644 --- a/packages/react-components/src/TxComponent.tsx +++ b/packages/react-components/src/TxComponent.tsx @@ -9,11 +9,13 @@ export default class TxComponent extends React.PureComponent { public constructor (props: P) { super(props); + this.button = React.createRef(); } protected sendTx = (): void => { const { component } = this.button.current; + if (component) { component.current.send(); } diff --git a/packages/react-signer/src/Checks/index.tsx b/packages/react-signer/src/Checks/index.tsx index 3633caebd8..525f6cb192 100644 --- a/packages/react-signer/src/Checks/index.tsx +++ b/packages/react-signer/src/Checks/index.tsx @@ -51,10 +51,12 @@ const LENGTH_SIGNATURE = 64; const LENGTH_ERA = 1; export const SIGNATURE_SIZE = LENGTH_PUBLICKEY + LENGTH_SIGNATURE + LENGTH_ERA; -export const calcSignatureLength = (extrinsic?: IExtrinsic | null, accountNonce?: BN): number => { - return SIGNATURE_SIZE + +export const calcSignatureLength = (extrinsic?: IExtrinsic | null, accountNonce?: BN): BN => { + return new BN( + SIGNATURE_SIZE + (accountNonce ? compactToU8a(accountNonce).length : 0) + - (extrinsic ? extrinsic.encodedLength : 0); + (extrinsic ? extrinsic.encodedLength : 0) + ); }; export class FeeDisplay extends React.PureComponent { @@ -93,14 +95,14 @@ export class FeeDisplay extends React.PureComponent { : false; const allFees = extraFees .add(balances_fees.transactionBaseFee) - .add(balances_fees.transactionByteFee.muln(txLength)); + .add(balances_fees.transactionByteFee.mul(txLength)); const allTotal = extraAmount.add(allFees); const hasAvailable = balances_all.availableBalance.gtn(0); const isRemovable = balances_all.votingBalance.sub(allTotal).lt(balances_fees.existentialDeposit); const isReserved = balances_all.freeBalance.isZero() && balances_all.reservedBalance.gtn(0); const allWarn = extraWarn; - const overLimit = txLength >= MAX_SIZE_BYTES; + const overLimit = txLength.gten(MAX_SIZE_BYTES); return { allFees, diff --git a/yarn.lock b/yarn.lock index e6304a7401..bdc1ed7d14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1930,44 +1930,44 @@ universal-user-agent "^3.0.0" url-template "^2.0.8" -"@polkadot/api-contract@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.14.tgz#412926a0e97c2660e3fefc7b824e57dadc9102c9" - integrity sha512-uL6oBR5TXygaUsegbf1UioGLLvZK4eBwqMrJ5iahhZl9echB5mkOTd/2e6B6itUrvjuQBMpqB5WL0o8pyHMbnw== +"@polkadot/api-contract@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.15.tgz#c01fdaba14acc27f4175c74581a53b3253282c09" + integrity sha512-MInJlrNK2Z61iPgfU4o7g7cmHEZyAhNR6uBMzBXqm/zI7inne5U8/FvfpkIkHyokcsXV8iyRNEirBqijPcEPAw== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/types" "^0.91.0-beta.14" + "@polkadot/types" "^0.91.0-beta.15" -"@polkadot/api-derive@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.14.tgz#ba0be5a3f40d64bc64cb7ce220423bd6908da7df" - integrity sha512-4xax1n/EqcKPty+qNDRb9FbmzHKAw3QKffkUvACU7P81MY7FT4H4IN8twrF7mGUYOlCN4u4ZhlAvUbrWYd0lsQ== +"@polkadot/api-derive@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.15.tgz#8e5efdb4e476480bc6e85f355878e41b0c5458d1" + integrity sha512-tC/iH/+G234lODxOmoFAt9NL8Gdsfmhvi6yOGYbTROzmUIX6FvXQ9U32GV0JkZdE6bJCGLlmS0gB5EjwTIyb8A== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api" "^0.91.0-beta.14" - "@polkadot/types" "^0.91.0-beta.14" + "@polkadot/api" "^0.91.0-beta.15" + "@polkadot/types" "^0.91.0-beta.15" -"@polkadot/api-metadata@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.14.tgz#e502a4dc6537754e3d3978844360a72e1a186357" - integrity sha512-g2KKf283JoJ9XosVkqy2P+PvbUX3pf6UBqty/BR3ZmlT4FHfRETT37+HhzhvilLxw/+Fx0HHUOdmDYjQTrRFhA== +"@polkadot/api-metadata@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.15.tgz#5c6550003e4ef747f18739b2d1dbb662b0028827" + integrity sha512-UXoq3On5ZDs/BFa04juZFdCyvqtX27a/IFcg+243SNBInMfhrN5wkZd5fchvtalUnIT+t6G64fNYQiqB3UIrfQ== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/types" "^0.91.0-beta.14" + "@polkadot/types" "^0.91.0-beta.15" "@polkadot/util" "^1.2.0-beta.6" "@polkadot/util-crypto" "^1.2.0-beta.6" -"@polkadot/api@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.14.tgz#a76a5ab7c904981cbffdbb990e50080d501de5f5" - integrity sha512-YSMC6FVzRsyKnwFJqhwtQ3WNmGpG5jH4Jendnd3kOuHZbzQxfU/cBqRzroawyHxVE1QoaSnLkrFvEzfH5r7g6g== +"@polkadot/api@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.15.tgz#397a2dd9cfd94df1bc3c186bff05952f625c9171" + integrity sha512-6MPpy3Eu9+qdjgvDCbsCns7zVw151bUY+HERBi7yMcNnhy36fns/ZzEch06BUSiZ73TVVzIjB04eq0PhqA5dZw== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api-derive" "^0.91.0-beta.14" - "@polkadot/api-metadata" "^0.91.0-beta.14" - "@polkadot/rpc-core" "^0.91.0-beta.14" - "@polkadot/rpc-provider" "^0.91.0-beta.14" - "@polkadot/types" "^0.91.0-beta.14" + "@polkadot/api-derive" "^0.91.0-beta.15" + "@polkadot/api-metadata" "^0.91.0-beta.15" + "@polkadot/rpc-core" "^0.91.0-beta.15" + "@polkadot/rpc-provider" "^0.91.0-beta.15" + "@polkadot/types" "^0.91.0-beta.15" "@polkadot/util-crypto" "^1.2.0-beta.6" "@polkadot/dev-react@^0.31.0-beta.6": @@ -2066,10 +2066,10 @@ dependencies: "@babel/runtime" "^7.5.5" -"@polkadot/jsonrpc@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.14.tgz#605682c9e666a579d891c97869e5c0eb20310a86" - integrity sha512-m/FVupCv37c32OQi3ZH26O3RqBASlBt4B+Nwup66R9qMP3BfTZOPa7wvFJ08iT0BGzLLIb31gPFbV2UhE2UVMw== +"@polkadot/jsonrpc@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.15.tgz#b910c3f9e98afacfa2b54d30d8a6a8225e036a47" + integrity sha512-1A2oX5FIKbGW49wE8p0zOWToARBwJLzu4aPi15OMR3/5Pa3kGTCpG2hGmnvXvLbEdbMr+W5tamot2tvedNzvlA== dependencies: "@babel/runtime" "^7.5.5" @@ -2097,25 +2097,25 @@ react-copy-to-clipboard "^5.0.1" styled-components "^4.3.1" -"@polkadot/rpc-core@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.14.tgz#2910b798c0d7121df9818987b1a84447245c707a" - integrity sha512-2Jbf6v5nq+EBRAzx5BdG8Zibr4T91vuRcJxOJqGV9jE0rDh1O/c4vOYVwJ8C7JTj/JqhkUZRolU4M6gbp0mxmA== +"@polkadot/rpc-core@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.15.tgz#c9a9c472fe6acde73e66d01b822ee980f8c1a40e" + integrity sha512-TMEmHXlib0TrBpF4V5JM3Y79x3LEndkypWGUjzAAwxmnrGuP1Fs3LEj+g5JKSafU6OQ0gJYpMHGEci2AZ9MvHA== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/jsonrpc" "^0.91.0-beta.14" - "@polkadot/rpc-provider" "^0.91.0-beta.14" - "@polkadot/types" "^0.91.0-beta.14" + "@polkadot/jsonrpc" "^0.91.0-beta.15" + "@polkadot/rpc-provider" "^0.91.0-beta.15" + "@polkadot/types" "^0.91.0-beta.15" "@polkadot/util" "^1.2.0-beta.6" rxjs "^6.5.2" -"@polkadot/rpc-provider@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.14.tgz#8d1c3da52cd7b9cdf3ebfe1b8deae2d296e7835a" - integrity sha512-lgeWt8sZnTDwCMbxT+XVzpYtAlnXM0mt6B90Nz3wTFds53f9fosleDnnJWSvZrETFBTrA7IY6piQMZeWP0x81Q== +"@polkadot/rpc-provider@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.15.tgz#d41e6e24128a9a00f85ea2b2692151e186a762b4" + integrity sha512-f1uprAxM+goXVDQnvz4VzM6oKphunz2Smej5CmsDbbNwyAzBmtdzhLlgMFIlY5nVHIrD/BemYDyWdn5V1Mgg5A== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api-metadata" "^0.91.0-beta.14" + "@polkadot/api-metadata" "^0.91.0-beta.15" "@polkadot/util" "^1.2.0-beta.6" "@polkadot/util-crypto" "^1.2.0-beta.6" "@types/nock" "^10.0.3" @@ -2130,10 +2130,10 @@ dependencies: "@types/chrome" "^0.0.88" -"@polkadot/types@^0.91.0-beta.14": - version "0.91.0-beta.14" - resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.14.tgz#d0d6f4ecb983988f0695fb4bc44ecbb3d888d510" - integrity sha512-57KdS7mMPuBUUdjMwbXkIrsVf48KWTw2CDv13Ry5+IrGUPnO+/oOC+DnegQ2Oy/+J2wI6+4emOetEh6UGVhwPQ== +"@polkadot/types@^0.91.0-beta.15": + version "0.91.0-beta.15" + resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.15.tgz#4ca731b34a62a0e109adc1941aee9b3ad7cc9e68" + integrity sha512-s85EknDqK6A7W98t8zfh0u/hBpY0gEFtahNjj5bS1bxjnkbuYGapDxvGIf27yODZiG/7Yf8kldYHWRzMfAqBMQ== dependencies: "@babel/runtime" "^7.5.5" "@polkadot/util" "^1.2.0-beta.6" @@ -5840,6 +5840,11 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" +edgeware-node-types@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/edgeware-node-types/-/edgeware-node-types-1.0.9.tgz#5aad55b0813a629bb7fe3b62ab4a94e2cfcafe5c" + integrity sha512-XVllaluYgAX1iZsfqDgMWOsp2Qry0/PEssjRTgIy0t6YIXWu3H6X7DwnfHHQ9CmcCkpJ/vWgtXczbE1Ev+Kt1Q== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"