diff --git a/package.json b/package.json index dd2b6a9925..488ff69517 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^2.6.2-7", - "@polkadot/api-contract": "^2.6.2-7", + "@polkadot/api": "^2.6.2-9", + "@polkadot/api-contract": "^2.6.2-9", "@polkadot/keyring": "^4.0.2-12", "@polkadot/networks": "^4.0.2-12", - "@polkadot/types": "^2.6.2-7", + "@polkadot/types": "^2.6.2-9", "@polkadot/util": "^4.0.2-12", "@polkadot/util-crypto": "^4.0.2-12", "@polkadot/wasm-crypto": "^2.0.1", diff --git a/packages/apps/public/locales/en/app-contracts.json b/packages/apps/public/locales/en/app-contracts.json index 05bfd82525..6aeed2c1c7 100644 --- a/packages/apps/public/locales/en/app-contracts.json +++ b/packages/apps/public/locales/en/app-contracts.json @@ -80,6 +80,7 @@ "read": "read", "read contract only, no execution": "read contract only, no execution", "status": "status", + "transferrable": "transferrable", "use estimated gas": "use estimated gas", "value": "value", "{{executionTime}}s execution time": "{{executionTime}}s execution time", diff --git a/packages/apps/public/locales/en/app-parachains.json b/packages/apps/public/locales/en/app-parachains.json index 82b0693e82..435a5ce33d 100644 --- a/packages/apps/public/locales/en/app-parachains.json +++ b/packages/apps/public/locales/en/app-parachains.json @@ -58,7 +58,7 @@ "the parachain that will receive the transfer of tokens.": "the parachain that will receive the transfer of tokens.", "the parachain to transfer to": "the parachain to transfer to", "transfer remark/comment": "transfer remark/comment", - "transferrable ": "transferrable ", + "transferrable": "transferrable", "validation": "validation", "validators": "validators", "yes": "yes", diff --git a/packages/apps/public/locales/fr/translation.json b/packages/apps/public/locales/fr/translation.json index 8c8cfbcc9f..f94cb6dbf7 100644 --- a/packages/apps/public/locales/fr/translation.json +++ b/packages/apps/public/locales/fr/translation.json @@ -1428,8 +1428,7 @@ "transactions": "transactions", "transfer received": "transfert reçu", "transfer remark/comment": "transférer une remarque/commentaire", - "transferrable": "transférable", - "transferrable ": "transferrable", + "transferrable": "transferrable", "transferrable minus fees": "transferable moins les frais", "trusted social recovery helpers": "assistants sociaux de confiance", "turnout": "participation", diff --git a/packages/apps/public/locales/id/translation.json b/packages/apps/public/locales/id/translation.json index e5adecc843..84f4d099ba 100644 --- a/packages/apps/public/locales/id/translation.json +++ b/packages/apps/public/locales/id/translation.json @@ -1357,8 +1357,7 @@ "transactions": "transaksi", "transfer received": "transfer diterima", "transfer remark/comment": "transfer ucapan/komentar", - "transferrable": "dapat ditransfer", - "transferrable ": "yang dapat ditransfer", + "transferrable": "yang dapat ditransfer", "transferrable minus fees": "biaya dikurangi yang dapat dialihkan", "trusted social recovery helpers": "pemulihan sosial helper terpercaya", "turnout": "beralih", diff --git a/packages/apps/public/locales/it/translation.json b/packages/apps/public/locales/it/translation.json index fcf93fc170..bf791005ba 100644 --- a/packages/apps/public/locales/it/translation.json +++ b/packages/apps/public/locales/it/translation.json @@ -1340,7 +1340,6 @@ "transfer received": "trasferimento ricevuto", "transfer remark/comment": "commento/nota sul trasferimento", "transferrable": "trasferibili", - "transferrable ": "trasferibili", "transferrable minus fees": "transferibile al netto delle commissioni", "trusted social recovery helpers": "garanti di fiducia per recupero account", "turnout": "partecipanti", diff --git a/packages/apps/public/locales/ko/translation.json b/packages/apps/public/locales/ko/translation.json index 8408001a8b..0406d72533 100644 --- a/packages/apps/public/locales/ko/translation.json +++ b/packages/apps/public/locales/ko/translation.json @@ -1389,7 +1389,6 @@ "transfer received": "트랜스퍼를 받았습니다", "transfer remark/comment": "이체할 발언/ 논평", "transferrable": "이체 가능", - "transferrable ": "이체 가능", "transferrable minus fees": "수수료를 제외하고 이체 가능", "trusted social recovery helpers": "신뢰할 수 있는 \"계정 복구 도우미\" 목록", "turnout": "투표자 수", diff --git a/packages/apps/public/locales/zh/translation.json b/packages/apps/public/locales/zh/translation.json index d272f17724..3b4953e444 100644 --- a/packages/apps/public/locales/zh/translation.json +++ b/packages/apps/public/locales/zh/translation.json @@ -1292,7 +1292,6 @@ "transfer received": "转账接收成功", "transfer remark/comment": "转账备注/评论", "transferrable": "可转账的", - "transferrable ": "可转账的", "trusted social recovery helpers": "信任的社交恢复帮手", "turnout": "结果", "twitter": "Twitter", diff --git a/packages/page-accounts/src/modals/Transfer.tsx b/packages/page-accounts/src/modals/Transfer.tsx index 8766bfe749..6652b26935 100644 --- a/packages/page-accounts/src/modals/Transfer.tsx +++ b/packages/page-accounts/src/modals/Transfer.tsx @@ -60,7 +60,6 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send } }, [api, balances, recipientId, senderId]); - const transferrable = {t('transferrable')}; const canToggleAll = !isProtected && balances && balances.accountId.eq(senderId) && maxTransfer && (!accountInfo || !accountInfo.refcount || accountInfo.refcount.isZero()); return ( @@ -80,7 +79,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send label={t('send from account')} labelExtra={ ('transferrable')} params={senderId} /> } @@ -101,7 +100,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send label={t('send to address')} labelExtra={ ('transferrable')} params={recipientId} /> } diff --git a/packages/page-contracts/package.json b/packages/page-contracts/package.json index 667e0a040e..b8060a03ad 100644 --- a/packages/page-contracts/package.json +++ b/packages/page-contracts/package.json @@ -10,6 +10,6 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.12.1", - "@polkadot/api-contract": "^2.6.2-7" + "@polkadot/api-contract": "^2.6.2-9" } } diff --git a/packages/page-contracts/src/Codes/Upload.tsx b/packages/page-contracts/src/Codes/Upload.tsx index 459f3173b8..1c34c018f8 100644 --- a/packages/page-contracts/src/Codes/Upload.tsx +++ b/packages/page-contracts/src/Codes/Upload.tsx @@ -8,6 +8,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { CodePromise } from '@polkadot/api-contract'; import { InputAddress, InputFile, Modal, TxButton } from '@polkadot/react-components'; import { useAccountId, useApi, useNonEmptyString } from '@polkadot/react-hooks'; +import { Available } from '@polkadot/react-query'; import { isNull, isWasm } from '@polkadot/util'; import { ABI, InputName } from '../shared'; @@ -69,6 +70,12 @@ function Upload ({ onClose }: Props): React.ReactElement { help={t('Specify the user account to use for this deployment. Any fees will be deducted from this account.')} isInput={false} label={t('deployment account')} + labelExtra={ + ('transferrable')} + params={accountId} + /> + } onChange={setAccountId} type='account' value={accountId} diff --git a/packages/page-contracts/src/Contracts/Call.tsx b/packages/page-contracts/src/Contracts/Call.tsx index 20c6ad56c5..ee1a6af683 100644 --- a/packages/page-contracts/src/Contracts/Call.tsx +++ b/packages/page-contracts/src/Contracts/Call.tsx @@ -11,6 +11,7 @@ import styled from 'styled-components'; import { Button, Dropdown, Expander, InputAddress, InputBalance, Modal, Toggle, TxButton } from '@polkadot/react-components'; import { ContractPromise } from '@polkadot/api-contract'; import { useAccountId, useDebounce, useFormField, useToggle } from '@polkadot/react-hooks'; +import { Available } from '@polkadot/react-query'; import { BN_ZERO } from '@polkadot/util'; import { InputMegaGas, Params } from '../shared'; @@ -125,6 +126,12 @@ function Call ({ className = '', contract, messageIndex, onCallResult, onChangeM defaultValue={accountId} help={t('Specify the user account to use for this contract call. And fees will be deducted from this account.')} label={t('call from account')} + labelExtra={ + ('transferrable')} + params={accountId} + /> + } onChange={setAccountId} type='account' value={accountId} @@ -147,6 +154,7 @@ function Call ({ className = '', contract, messageIndex, onCallResult, onChangeM ? message.args : undefined } + registry={contract.abi.registry} /> )} diff --git a/packages/page-contracts/src/Deploy.tsx b/packages/page-contracts/src/Deploy.tsx index 919149105f..ec3c9fcc41 100644 --- a/packages/page-contracts/src/Deploy.tsx +++ b/packages/page-contracts/src/Deploy.tsx @@ -10,6 +10,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { BlueprintPromise } from '@polkadot/api-contract'; import { Dropdown, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; import { useFormField, useNonEmptyString, useNonZeroBn, useApi } from '@polkadot/react-hooks'; +import { Available } from '@polkadot/react-query'; import keyring from '@polkadot/ui-keyring'; import { ABI, InputMegaGas, InputName, MessageSignature, Params } from './shared'; @@ -111,6 +112,12 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex help={t('Specify the user account to use for this deployment. Any fees will be deducted from this account.')} isInput={false} label={t('deployment account')} + labelExtra={ + ('transferrable')} + params={accountId} + /> + } onChange={setAccountId} type='account' value={accountId} @@ -133,23 +140,22 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex /> )} {contractAbi && ( - ('The deployment constructor information for this contract, as provided by the ABI.')} - isDisabled={contractAbi.constructors.length <= 1} - label={t('deployment constructor')} - onChange={setConstructorIndex} - options={constructOptions} - value={constructorIndex} - /> + <> + ('The deployment constructor information for this contract, as provided by the ABI.')} + isDisabled={contractAbi.constructors.length <= 1} + label={t('deployment constructor')} + onChange={setConstructorIndex} + options={constructOptions} + value={constructorIndex} + /> + + )} - ('The allotted endowment for this contract, i.e. the amount transferred to the contract upon instantiation.')} isError={!isEndowmentValid} diff --git a/packages/page-contracts/src/shared/Params.tsx b/packages/page-contracts/src/shared/Params.tsx index c567f1439f..c3ed746d44 100644 --- a/packages/page-contracts/src/shared/Params.tsx +++ b/packages/page-contracts/src/shared/Params.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2020 @polkadot/app-contracts authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef } from '@polkadot/types/types'; +import { Registry, TypeDef } from '@polkadot/types/types'; import { RawParams } from '@polkadot/react-params/types'; import React, { useCallback, useEffect, useState } from 'react'; @@ -12,6 +12,7 @@ interface Props { params?: ParamDef[]; onChange: (values: any[]) => void; onEnter?: () => void; + registry: Registry; } interface ParamDef { @@ -19,7 +20,7 @@ interface ParamDef { type: TypeDef; } -function Params ({ isDisabled, onChange, onEnter, params: propParams }: Props): React.ReactElement | null { +function Params ({ isDisabled, onChange, onEnter, params: propParams, registry }: Props): React.ReactElement | null { const [params, setParams] = useState([]); useEffect((): void => { @@ -41,6 +42,7 @@ function Params ({ isDisabled, onChange, onEnter, params: propParams }: Props): onChange={_onChange} onEnter={onEnter} params={params} + registry={registry} /> ); } diff --git a/packages/page-parachains/src/Transfer.tsx b/packages/page-parachains/src/Transfer.tsx index 7d17397613..f18399786a 100644 --- a/packages/page-parachains/src/Transfer.tsx +++ b/packages/page-parachains/src/Transfer.tsx @@ -81,7 +81,7 @@ function Transfer ({ className, parachains }: Props): React.ReactElement label={t('send from account')} labelExtra={ ('transferrable ')} + label={t('transferrable')} params={accountId} /> } diff --git a/packages/react-api/package.json b/packages/react-api/package.json index f127c3c93f..f4c2d51cb0 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -20,7 +20,7 @@ "homepage": "https://github.com/polkadot-js/apps/tree/master/packages/react-api#readme", "dependencies": { "@babel/runtime": "^7.12.1", - "@polkadot/api": "^2.6.2-7", + "@polkadot/api": "^2.6.2-9", "@polkadot/extension-dapp": "^0.35.0-beta.47", "rxjs-compat": "^6.6.3" } diff --git a/packages/react-components/src/InputAddress/index.tsx b/packages/react-components/src/InputAddress/index.tsx index 9d9c92f622..0e4e0226dc 100644 --- a/packages/react-components/src/InputAddress/index.tsx +++ b/packages/react-components/src/InputAddress/index.tsx @@ -289,8 +289,8 @@ const ExportedComponent = withMulti( top: -1.05rem; > div, - > img, - > svg { + img, + svg { height: 32px !important; width: 32px !important; } diff --git a/packages/react-params/src/Param/Amount.tsx b/packages/react-params/src/Param/Amount.tsx index ac205c312c..0474966d54 100644 --- a/packages/react-params/src/Param/Amount.tsx +++ b/packages/react-params/src/Param/Amount.tsx @@ -5,21 +5,20 @@ import { Props } from '../types'; import BN from 'bn.js'; import React, { useCallback, useMemo } from 'react'; -import { registry } from '@polkadot/react-api'; import { Input, InputNumber } from '@polkadot/react-components'; import { ClassOf } from '@polkadot/types/create'; import { bnToBn, formatNumber, isUndefined } from '@polkadot/util'; import Bare from './Bare'; -function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, type, withLabel }: Props): React.ReactElement { +function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, registry, type, withLabel }: Props): React.ReactElement { const defaultValue = useMemo( () => isDisabled ? value instanceof ClassOf(registry, 'AccountIndex') ? value.toString() : formatNumber(value as number) : bnToBn((value as number) || 0).toString(), - [isDisabled, value] + [isDisabled, registry, value] ); const bitLength = useMemo( @@ -30,7 +29,7 @@ function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, return 32; } }, - [type] + [registry, type] ); const _onChange = useCallback( diff --git a/packages/react-params/src/Param/Enum.tsx b/packages/react-params/src/Param/Enum.tsx index 03ee8f3e25..75992f90e9 100644 --- a/packages/react-params/src/Param/Enum.tsx +++ b/packages/react-params/src/Param/Enum.tsx @@ -5,7 +5,6 @@ import { TypeDef } from '@polkadot/types/types'; import { ParamDef, Props, RawParam } from '../types'; import React, { useCallback, useEffect, useState } from 'react'; -import { registry } from '@polkadot/react-api'; import { Dropdown } from '@polkadot/react-components'; import { Enum } from '@polkadot/types'; import { getTypeDef } from '@polkadot/types/create'; @@ -25,7 +24,7 @@ interface Options { } function EnumParam (props: Props): React.ReactElement { - const { className = '', defaultValue, isDisabled, isError, label, onChange, overrides, type, withLabel } = props; + const { className = '', defaultValue, isDisabled, isError, label, onChange, overrides, registry, type, withLabel } = props; const [current, setCurrent] = useState(null); const [initialValue, setInitialValue] = useState(null); const [{ options, subTypes }, setOptions] = useState({ options: [], subTypes: [] }); @@ -43,7 +42,7 @@ function EnumParam (props: Props): React.ReactElement { subTypes }); setCurrent([{ name: subTypes[0].name, type: subTypes[0] }]); - }, [type]); + }, [registry, type]); useEffect((): void => { setInitialValue( @@ -100,6 +99,7 @@ function EnumParam (props: Props): React.ReactElement { onChange={_onChangeParam} overrides={overrides} params={current} + registry={registry} /> )} diff --git a/packages/react-params/src/Param/Moment.tsx b/packages/react-params/src/Param/Moment.tsx index af9ba59b1b..fc582e6979 100644 --- a/packages/react-params/src/Param/Moment.tsx +++ b/packages/react-params/src/Param/Moment.tsx @@ -8,7 +8,7 @@ import { Static } from '@polkadot/react-components'; import Amount from './Amount'; -function Moment ({ className = '', defaultValue, isDisabled, isError, label, onChange, onEnter, onEscape, type, withLabel }: Props): React.ReactElement { +function Moment ({ className = '', defaultValue, isDisabled, isError, label, onChange, onEnter, onEscape, registry, type, withLabel }: Props): React.ReactElement { const _onChange = useCallback( (value: RawParamOnChangeValue) => onChange && onChange(value), @@ -41,6 +41,7 @@ function Moment ({ className = '', defaultValue, isDisabled, isError, label, onC onChange={_onChange} onEnter={onEnter} onEscape={onEscape} + registry={registry} type={type} withLabel={withLabel} /> diff --git a/packages/react-params/src/Param/OpaqueCall.tsx b/packages/react-params/src/Param/OpaqueCall.tsx index 28c249a55d..6188495893 100644 --- a/packages/react-params/src/Param/OpaqueCall.tsx +++ b/packages/react-params/src/Param/OpaqueCall.tsx @@ -4,7 +4,6 @@ import { Props } from '../types'; import React from 'react'; -import { registry } from '@polkadot/react-api'; import { Bytes } from '@polkadot/types'; import CallDisplay from './Call'; @@ -17,7 +16,7 @@ function OpaqueCall (props: Props): React.ReactElement { ); } - const value = registry.createType('Call', (props.defaultValue.value as Bytes).toHex()); + const value = props.registry.createType('Call', (props.defaultValue.value as Bytes).toHex()); return ( { +function Option ({ className = '', defaultValue, isDisabled, name, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive } }: Props): React.ReactElement { const { t } = useTranslation(); const [isActive, setIsActive] = useState(withOptionActive || false); @@ -33,6 +33,7 @@ function Option ({ className = '', defaultValue, isDisabled, name, onChange, onE onChange={onChange} onEnter={onEnter} onEscape={onEscape} + registry={registry} type={sub as TypeDef} /> {!isDisabled && ( diff --git a/packages/react-params/src/Param/Struct.tsx b/packages/react-params/src/Param/Struct.tsx index 60ffc4bf04..4ccccb2a35 100644 --- a/packages/react-params/src/Param/Struct.tsx +++ b/packages/react-params/src/Param/Struct.tsx @@ -11,7 +11,7 @@ import Static from './Static'; import useParamDefs from './useParamDefs'; function StructParam (props: Props): React.ReactElement { - const params = useParamDefs(props.type); + const params = useParamDefs(props.registry, props.type); const { className = '', isDisabled, label, onChange, overrides, withLabel } = props; const _onChangeParams = useCallback( @@ -43,6 +43,7 @@ function StructParam (props: Props): React.ReactElement { onChange={_onChangeParams} overrides={overrides} params={params} + registry={props.registry} /> ); diff --git a/packages/react-params/src/Param/Tuple.tsx b/packages/react-params/src/Param/Tuple.tsx index f3f68d601f..648d77b5a6 100644 --- a/packages/react-params/src/Param/Tuple.tsx +++ b/packages/react-params/src/Param/Tuple.tsx @@ -11,7 +11,7 @@ import Static from './Static'; import useParamDefs from './useParamDefs'; function Tuple (props: Props): React.ReactElement { - const params = useParamDefs(props.type); + const params = useParamDefs(props.registry, props.type); const { className = '', isDisabled, label, onChange, overrides, withLabel } = props; const _onChangeParams = useCallback( @@ -39,6 +39,7 @@ function Tuple (props: Props): React.ReactElement { onChange={_onChangeParams} overrides={overrides} params={params} + registry={props.registry} /> ); diff --git a/packages/react-params/src/Param/Vector.tsx b/packages/react-params/src/Param/Vector.tsx index 0a1a56e034..808e9a9db6 100644 --- a/packages/react-params/src/Param/Vector.tsx +++ b/packages/react-params/src/Param/Vector.tsx @@ -20,9 +20,9 @@ function generateParam ([{ name, type }]: ParamDef[], index: number): ParamDef { }; } -function Vector ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, type, withLabel }: Props): React.ReactElement | null { +function Vector ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, registry, type, withLabel }: Props): React.ReactElement | null { const { t } = useTranslation(); - const inputParams = useParamDefs(type); + const inputParams = useParamDefs(registry, type); const [count, setCount] = useState(0); const [params, setParams] = useState([]); const [values, setValues] = useState([]); @@ -50,14 +50,14 @@ function Vector ({ className = '', defaultValue, isDisabled = false, label, onCh } while (values.length < count) { - const value = getInitValue(inputParams[0].type); + const value = getInitValue(registry, inputParams[0].type); values.push({ isValid: !isUndefined(value), value }); } return values.slice(0, count); }); - }, [count, inputParams, isDisabled]); + }, [count, inputParams, isDisabled, registry]); // when isDisabled, set the values based on the defaultValue input useEffect((): void => { @@ -115,6 +115,7 @@ function Vector ({ className = '', defaultValue, isDisabled = false, label, onCh onChange={setValues} overrides={overrides} params={params} + registry={registry} values={values} /> diff --git a/packages/react-params/src/Param/VectorFixed.tsx b/packages/react-params/src/Param/VectorFixed.tsx index fdd2f7d21d..57e0cd27e1 100644 --- a/packages/react-params/src/Param/VectorFixed.tsx +++ b/packages/react-params/src/Param/VectorFixed.tsx @@ -18,8 +18,8 @@ function generateParam ([{ name, type }]: ParamDef[], index: number): ParamDef { }; } -function VectorFixed ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, type, withLabel }: Props): React.ReactElement | null { - const inputParams = useParamDefs(type); +function VectorFixed ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, registry, type, withLabel }: Props): React.ReactElement | null { + const inputParams = useParamDefs(registry, type); const [params, setParams] = useState([]); const [values, setValues] = useState([]); @@ -49,14 +49,14 @@ function VectorFixed ({ className = '', defaultValue, isDisabled = false, label, } while (values.length < count) { - const value = getInitValue(inputParams[0].type); + const value = getInitValue(registry, inputParams[0].type); values.push({ isValid: !isUndefined(value), value }); } return values.slice(0, count); }); - }, [inputParams, isDisabled]); + }, [inputParams, isDisabled, registry]); // when isDisabled, set the values based on the defaultValue input useEffect((): void => { @@ -90,6 +90,7 @@ function VectorFixed ({ className = '', defaultValue, isDisabled = false, label, onChange={setValues} overrides={overrides} params={params} + registry={registry} values={values} /> diff --git a/packages/react-params/src/Param/VoteThreshold.tsx b/packages/react-params/src/Param/VoteThreshold.tsx index 595d6779b6..80902147db 100644 --- a/packages/react-params/src/Param/VoteThreshold.tsx +++ b/packages/react-params/src/Param/VoteThreshold.tsx @@ -4,7 +4,6 @@ import { Props } from '../types'; import React, { useCallback } from 'react'; -import { registry } from '@polkadot/react-api'; import { Dropdown } from '@polkadot/react-components'; import { ClassOf } from '@polkadot/types/create'; import { bnToBn } from '@polkadot/util'; @@ -25,7 +24,7 @@ export const textMap = options.reduce((textMap, { text, value }): TextMap => { return textMap; }, {} as unknown as TextMap); -function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, withLabel }: Props): React.ReactElement { +function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, registry, withLabel }: Props): React.ReactElement { const _onChange = useCallback( (value: number) => onChange && onChange({ diff --git a/packages/react-params/src/Param/findComponent.ts b/packages/react-params/src/Param/findComponent.ts index 060a1eef90..9cff435212 100644 --- a/packages/react-params/src/Param/findComponent.ts +++ b/packages/react-params/src/Param/findComponent.ts @@ -1,10 +1,9 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef, TypeDefInfo } from '@polkadot/types/types'; +import { Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types'; import { Props, ComponentMap } from '../types'; -import { registry } from '@polkadot/react-api'; import { getTypeDef } from '@polkadot/types/create'; import { isBn } from '@polkadot/util'; @@ -129,7 +128,7 @@ function fromDef ({ displayName, info, sub, type }: TypeDef): string { } } -export default function findComponent (def: TypeDef, overrides: ComponentMap = {}): React.ComponentType { +export default function findComponent (registry: Registry, def: TypeDef, overrides: ComponentMap = {}): React.ComponentType { const findOne = (type: string): React.ComponentType | null => overrides[type] || components[type]; const type = fromDef(def); @@ -149,9 +148,9 @@ export default function findComponent (def: TypeDef, overrides: ComponentMap = { } else if (isBn(instance)) { return Amount; } else if ([TypeDefInfo.Enum, TypeDefInfo.Struct, TypeDefInfo.Tuple].includes(raw.info)) { - return findComponent(raw, overrides); + return findComponent(registry, raw, overrides); } else if (raw.info === TypeDefInfo.VecFixed && (raw.sub as TypeDef).type !== 'u8') { - return findComponent(raw, overrides); + return findComponent(registry, raw, overrides); } } catch (e) { error = (e as Error).message; diff --git a/packages/react-params/src/Param/index.tsx b/packages/react-params/src/Param/index.tsx index 614487785c..02b45e33a0 100644 --- a/packages/react-params/src/Param/index.tsx +++ b/packages/react-params/src/Param/index.tsx @@ -11,8 +11,8 @@ import { isUndefined } from '@polkadot/util'; import findComponent from './findComponent'; import Static from './Static'; -function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, type }: Props): React.ReactElement | null { - const compRef = useRef | null>(findComponent(type, overrides)); +function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement | null { + const compRef = useRef | null>(findComponent(registry, type, overrides)); const label = useMemo( () => isUndefined(name) @@ -46,6 +46,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption onEnter={onEnter} onEscape={onEscape} overrides={overrides} + registry={registry} type={type} /> ); diff --git a/packages/react-params/src/Param/useParamDefs.ts b/packages/react-params/src/Param/useParamDefs.ts index 713daa4f5b..75b0f311ba 100644 --- a/packages/react-params/src/Param/useParamDefs.ts +++ b/packages/react-params/src/Param/useParamDefs.ts @@ -1,14 +1,13 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef } from '@polkadot/types/types'; +import { Registry, TypeDef } from '@polkadot/types/types'; import { ParamDef } from '../types'; import { useEffect, useState } from 'react'; -import { registry } from '@polkadot/react-api'; import { getTypeDef } from '@polkadot/types/create'; -function expandDef (td: TypeDef): TypeDef { +function expandDef (registry: Registry, td: TypeDef): TypeDef { try { return getTypeDef( registry.createType(td.type as 'u32').toRawType() @@ -18,11 +17,11 @@ function expandDef (td: TypeDef): TypeDef { } } -export default function useParamDefs (type: TypeDef): ParamDef[] { +export default function useParamDefs (registry: Registry, type: TypeDef): ParamDef[] { const [params, setParams] = useState([]); useEffect((): void => { - const typeDef = expandDef(type); + const typeDef = expandDef(registry, type); if (!typeDef.sub) { return setParams([]); @@ -35,7 +34,7 @@ export default function useParamDefs (type: TypeDef): ParamDef[] { type: td // expandDef(td) })) ); - }, [type]); + }, [registry, type]); return params; } diff --git a/packages/react-params/src/ParamComp.tsx b/packages/react-params/src/ParamComp.tsx index 5cf6be0fbe..3dc316fbd3 100644 --- a/packages/react-params/src/ParamComp.tsx +++ b/packages/react-params/src/ParamComp.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef } from '@polkadot/types/types'; +import { Registry, TypeDef } from '@polkadot/types/types'; import { ComponentMap, RawParam, RawParams, RawParamOnChangeValue } from './types'; import React, { useCallback } from 'react'; @@ -17,11 +17,12 @@ interface Props { onEnter?: () => void; onEscape?: () => void; overrides?: ComponentMap; + registry: Registry; type: TypeDef; values?: RawParams | null; } -function ParamComp ({ defaultValue, index, isDisabled, name, onChange, onEnter, onEscape, overrides, type }: Props): React.ReactElement { +function ParamComp ({ defaultValue, index, isDisabled, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement { const _onChange = useCallback( (value: RawParamOnChangeValue): void => onChange(index, value), @@ -39,6 +40,7 @@ function ParamComp ({ defaultValue, index, isDisabled, name, onChange, onEnter, onEnter={onEnter} onEscape={onEscape} overrides={overrides} + registry={registry} type={type} /> diff --git a/packages/react-params/src/index.tsx b/packages/react-params/src/index.tsx index ff9d876928..4f3104a51f 100644 --- a/packages/react-params/src/index.tsx +++ b/packages/react-params/src/index.tsx @@ -1,10 +1,12 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 +import { Registry } from '@polkadot/types/types'; import { I18nProps } from '@polkadot/react-components/types'; import { ComponentMap, ParamDef, RawParam, RawParams, RawParamOnChangeValue } from './types'; import React from 'react'; +import { registry as defaultRegistry } from '@polkadot/react-api'; import { ErrorBoundary } from '@polkadot/react-components'; import Holder from './Holder'; @@ -21,6 +23,7 @@ interface Props extends I18nProps { onEscape?: () => void; overrides?: ComponentMap; params: ParamDef[]; + registry?: Registry; values?: RawParams | null; withBorder?: boolean; } @@ -37,7 +40,7 @@ class Params extends React.PureComponent { params: null }; - public static getDerivedStateFromProps ({ isDisabled, params, values }: Props, prevState: State): Pick | null { + public static getDerivedStateFromProps ({ isDisabled, params, registry = defaultRegistry, values }: Props, prevState: State): Pick | null { const isSame = JSON.stringify(prevState.params) === JSON.stringify(params); if (isDisabled || isSame) { @@ -51,7 +54,7 @@ class Params extends React.PureComponent { ...result, values && values[index] ? values[index] - : createValue(param) + : createValue(registry, param) ], [] ) @@ -75,7 +78,7 @@ class Params extends React.PureComponent { } public render (): React.ReactNode { - const { children, className = '', isDisabled, onEnter, onEscape, overrides, params, withBorder = true } = this.props; + const { children, className = '', isDisabled, onEnter, onEscape, overrides, params, registry = defaultRegistry, withBorder = true } = this.props; const { values = this.props.values } = this.state; if (!values || !values.length) { @@ -100,6 +103,7 @@ class Params extends React.PureComponent { onEnter={onEnter} onEscape={onEscape} overrides={overrides} + registry={registry} type={type} /> ))} diff --git a/packages/react-params/src/initValue.ts b/packages/react-params/src/initValue.ts index 327b1e6d1f..7f1fdeae5f 100644 --- a/packages/react-params/src/initValue.ts +++ b/packages/react-params/src/initValue.ts @@ -1,33 +1,32 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef, TypeDefInfo } from '@polkadot/types/types'; +import { Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types'; -import { registry } from '@polkadot/react-api'; import { Raw } from '@polkadot/types'; import { getTypeDef } from '@polkadot/types/create'; import { BN_ZERO, isBn } from '@polkadot/util'; const warnList: string[] = []; -export default function getInitValue (def: TypeDef): unknown { +export default function getInitValue (registry: Registry, def: TypeDef): unknown { if (def.info === TypeDefInfo.Vec) { - return [getInitValue(def.sub as TypeDef)]; + return [getInitValue(registry, def.sub as TypeDef)]; } else if (def.info === TypeDefInfo.Tuple) { return Array.isArray(def.sub) - ? def.sub.map((def) => getInitValue(def)) + ? def.sub.map((def) => getInitValue(registry, def)) : []; } else if (def.info === TypeDefInfo.Struct) { return Array.isArray(def.sub) ? def.sub.reduce((result: Record, def): Record => { - result[def.name as string] = getInitValue(def); + result[def.name as string] = getInitValue(registry, def); return result; }, {}) : {}; } else if (def.info === TypeDefInfo.Enum) { return Array.isArray(def.sub) - ? { [def.sub[0].name as string]: getInitValue(def.sub[0]) } + ? { [def.sub[0].name as string]: getInitValue(registry, def.sub[0]) } : {}; } @@ -131,7 +130,7 @@ export default function getInitValue (def: TypeDef): unknown { } else if ([TypeDefInfo.Struct].includes(raw.info)) { return undefined; } else if ([TypeDefInfo.Enum, TypeDefInfo.Tuple].includes(raw.info)) { - return getInitValue(raw); + return getInitValue(registry, raw); } } catch (e) { error = (e as Error).message; diff --git a/packages/react-params/src/types.ts b/packages/react-params/src/types.ts index 4b91af2e57..62ef0f53d3 100644 --- a/packages/react-params/src/types.ts +++ b/packages/react-params/src/types.ts @@ -1,7 +1,7 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef } from '@polkadot/types/types'; +import { Registry, TypeDef } from '@polkadot/types/types'; // FIXME Ideally, we want these as Base from api-codec - as a stop-gap, any this until we have // params returning types extending Base (i.e. anything from api-codec) @@ -42,6 +42,7 @@ export interface Props { onEscape?: RawParamOnEscape; // eslint-disable-next-line no-use-before-define overrides?: ComponentMap; + registry: Registry; type: TypeDef & { withOptionActive?: boolean }; withLabel?: boolean; } diff --git a/packages/react-params/src/values.ts b/packages/react-params/src/values.ts index 8144c6b005..3f7c5e8fdf 100644 --- a/packages/react-params/src/values.ts +++ b/packages/react-params/src/values.ts @@ -1,15 +1,15 @@ // Copyright 2017-2020 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDef } from '@polkadot/types/types'; +import { Registry, TypeDef } from '@polkadot/types/types'; import { RawParam } from './types'; import { isUndefined } from '@polkadot/util'; import getInitValue from './initValue'; -export function createValue (param: { type: TypeDef }): RawParam { - const value = getInitValue(param.type); +export function createValue (registry: Registry, param: { type: TypeDef }): RawParam { + const value = getInitValue(registry, param.type); return { isValid: !isUndefined(value), @@ -17,6 +17,6 @@ export function createValue (param: { type: TypeDef }): RawParam { }; } -export default function createValues (params: { type: TypeDef }[]): RawParam[] { - return params.map(createValue); +export default function createValues (registry: Registry, params: { type: TypeDef }[]): RawParam[] { + return params.map((param) => createValue(registry, param)); } diff --git a/packages/react-query/src/FormatBalance.tsx b/packages/react-query/src/FormatBalance.tsx index 9a1282f40c..9e78f4f0bd 100644 --- a/packages/react-query/src/FormatBalance.tsx +++ b/packages/react-query/src/FormatBalance.tsx @@ -48,7 +48,7 @@ function FormatBalance ({ children, className = '', isShort, label, labelPost, v // labelPost here looks messy, however we ensure we have one less text node return (
- {label || ''}{ + {label ? <>{label}  : ''}{ value ? value === 'all' ? t('everything{{labelPost}}', { replace: { labelPost } }) diff --git a/yarn.lock b/yarn.lock index cdd51f73ee..de3154b2b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2050,55 +2050,55 @@ __metadata: languageName: node linkType: hard -"@polkadot/api-contract@npm:^2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/api-contract@npm:2.6.2-7" +"@polkadot/api-contract@npm:^2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/api-contract@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/api": 2.6.2-7 - "@polkadot/types": 2.6.2-7 + "@polkadot/api": 2.6.2-9 + "@polkadot/types": 2.6.2-9 "@polkadot/util": ^4.0.2-12 bn.js: ^5.1.3 rxjs: ^6.6.3 - checksum: f9121764e8310575d791d92276ba9c51e5aad0c57a68c63a00655e14dc2133110344384be59b9bb4a306ef725eec6f286b2b8c8d386f2c9dbf48526c5a14c98d + checksum: 5023c7e19642d0aee31480511157f0c9b41e2f9e12875987dcf8216485dc6e525c6c431f01ac0b00e4b611259c8dacf8cc25a0d44d1829319fbc40b81bfaedae languageName: node linkType: hard -"@polkadot/api-derive@npm:2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/api-derive@npm:2.6.2-7" +"@polkadot/api-derive@npm:2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/api-derive@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/api": 2.6.2-7 - "@polkadot/rpc-core": 2.6.2-7 - "@polkadot/types": 2.6.2-7 + "@polkadot/api": 2.6.2-9 + "@polkadot/rpc-core": 2.6.2-9 + "@polkadot/types": 2.6.2-9 "@polkadot/util": ^4.0.2-12 "@polkadot/util-crypto": ^4.0.2-12 bn.js: ^5.1.3 memoizee: ^0.4.14 rxjs: ^6.6.3 - checksum: 980c6c0ab9723bc863b52afd1f921c4d58ba2aaae57c3248a4ae318344a08122f2fa28ef8304ca2928fd6f10ae22b20284ca0a14ca0555a5cb03e79410cd8dfa + checksum: c330ba78e2ebbc276fe0ac93988b5d127565601de6defd74af42e3a26c56101e2506252c3eeb34dbbf6165a83197ebe1e5edf3bb675dea080463905b2be59d21 languageName: node linkType: hard -"@polkadot/api@npm:^2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/api@npm:2.6.2-7" +"@polkadot/api@npm:^2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/api@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/api-derive": 2.6.2-7 + "@polkadot/api-derive": 2.6.2-9 "@polkadot/keyring": ^4.0.2-12 - "@polkadot/metadata": 2.6.2-7 - "@polkadot/rpc-core": 2.6.2-7 - "@polkadot/rpc-provider": 2.6.2-7 - "@polkadot/types": 2.6.2-7 - "@polkadot/types-known": 2.6.2-7 + "@polkadot/metadata": 2.6.2-9 + "@polkadot/rpc-core": 2.6.2-9 + "@polkadot/rpc-provider": 2.6.2-9 + "@polkadot/types": 2.6.2-9 + "@polkadot/types-known": 2.6.2-9 "@polkadot/util": ^4.0.2-12 "@polkadot/util-crypto": ^4.0.2-12 bn.js: ^5.1.3 eventemitter3: ^4.0.7 rxjs: ^6.6.3 - checksum: f038ac797c03b153280f5fb0eedefaade606a15e098794ffe1920c86b3c7342c579551c4fa8cb09cf7d99861dc7f00d1e16663220d1f6b1b1486932e34540373 + checksum: faff1ef235316ce666732bd478404d96e4673c6121bbde07456679e0c5415579f96805b64cec832935dae707ff9cd88dc0ce56e98b59de93618c4ef3959d2694 languageName: node linkType: hard @@ -2154,7 +2154,7 @@ __metadata: resolution: "@polkadot/app-contracts@workspace:packages/page-contracts" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/api-contract": ^2.6.2-7 + "@polkadot/api-contract": ^2.6.2-9 languageName: unknown linkType: soft @@ -2564,17 +2564,17 @@ __metadata: languageName: node linkType: hard -"@polkadot/metadata@npm:2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/metadata@npm:2.6.2-7" +"@polkadot/metadata@npm:2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/metadata@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/types": 2.6.2-7 - "@polkadot/types-known": 2.6.2-7 + "@polkadot/types": 2.6.2-9 + "@polkadot/types-known": 2.6.2-9 "@polkadot/util": ^4.0.2-12 "@polkadot/util-crypto": ^4.0.2-12 bn.js: ^5.1.3 - checksum: 124cf4735e1096b5ec5b21092e44dd653ddbb7ebff7beb4d1bdeabc00a0af51ce74e4037be64c81fec57bbd951f75b7c016a0aec3cba4259ae979e661f10aeae + checksum: e187015401126d3f122572d13310b0285a2f7741bf2e48a20a99a827f39d2927b207be9157cd76972b3feba43fd5a77b6fdb0be94be08daac45104eddec83230 languageName: node linkType: hard @@ -2592,7 +2592,7 @@ __metadata: resolution: "@polkadot/react-api@workspace:packages/react-api" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/api": ^2.6.2-7 + "@polkadot/api": ^2.6.2-9 "@polkadot/extension-dapp": ^0.35.0-beta.47 rxjs-compat: ^6.6.3 languageName: unknown @@ -2724,34 +2724,34 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/rpc-core@npm:2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/rpc-core@npm:2.6.2-7" +"@polkadot/rpc-core@npm:2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/rpc-core@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/metadata": 2.6.2-7 - "@polkadot/rpc-provider": 2.6.2-7 - "@polkadot/types": 2.6.2-7 + "@polkadot/metadata": 2.6.2-9 + "@polkadot/rpc-provider": 2.6.2-9 + "@polkadot/types": 2.6.2-9 "@polkadot/util": ^4.0.2-12 memoizee: ^0.4.14 rxjs: ^6.6.3 - checksum: b57f0bed98a490e6b79e2dc77b5120e8e6edef5e9689ecb4976d7ef12be59dc02a609cbf0cdeb59fc493f41b5843a14b6b1131941a56c66ffd3b6d03cd54f083 + checksum: b4eae0fa5f40150d4d39b8ff5da0d8a34f19e7f8bea81b5a671e104e730cb96eab07ccf3f6f4b6f0053d392cfc26da3383b8ed40733cfca89d051001600095bc languageName: node linkType: hard -"@polkadot/rpc-provider@npm:2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/rpc-provider@npm:2.6.2-7" +"@polkadot/rpc-provider@npm:2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/rpc-provider@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/types": 2.6.2-7 + "@polkadot/types": 2.6.2-9 "@polkadot/util": ^4.0.2-12 "@polkadot/util-crypto": ^4.0.2-12 "@polkadot/x-fetch": ^4.0.2-12 "@polkadot/x-ws": ^4.0.2-12 bn.js: ^5.1.3 eventemitter3: ^4.0.7 - checksum: c9ccfb3065c3ffcd8ef8f852a66914ad29cca002a32529672747c3e6a9af0146adddb48ad3b44695e7e963b146b4710ca9c7de3bbffe50baae74c0937f1bdec2 + checksum: a3074c9d20d3e67a58be1c2cb63bbea8c27c156f9ccc1b1ef77901b83f25144ce61cf0d71f11cc41254473080429c8e9b5857eacf7bdaba7092752202b5939c7 languageName: node linkType: hard @@ -2764,31 +2764,31 @@ __metadata: languageName: node linkType: hard -"@polkadot/types-known@npm:2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/types-known@npm:2.6.2-7" +"@polkadot/types-known@npm:2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/types-known@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/types": 2.6.2-7 + "@polkadot/types": 2.6.2-9 "@polkadot/util": ^4.0.2-12 bn.js: ^5.1.3 - checksum: 31309dad5a4d85ddca4b36e307a535dfd96f2706ea3ec1bc21ef5e004da362807e354bf32272683f6f19e23ea336911c7e28866d237de6f2f1681b98687536cc + checksum: fbc65b736c9ef6795464bf4ea285a508b68ff7ca9b1b539cf67f892d80b16617bd4b7f12a7ab7119cc4ce91c382643b5c51fc1d5a6cdc92f0ba1b86c12679270 languageName: node linkType: hard -"@polkadot/types@npm:^2.6.2-7": - version: 2.6.2-7 - resolution: "@polkadot/types@npm:2.6.2-7" +"@polkadot/types@npm:^2.6.2-9": + version: 2.6.2-9 + resolution: "@polkadot/types@npm:2.6.2-9" dependencies: "@babel/runtime": ^7.12.1 - "@polkadot/metadata": 2.6.2-7 + "@polkadot/metadata": 2.6.2-9 "@polkadot/util": ^4.0.2-12 "@polkadot/util-crypto": ^4.0.2-12 "@types/bn.js": ^4.11.6 bn.js: ^5.1.3 memoizee: ^0.4.14 rxjs: ^6.6.3 - checksum: 289c710a0435598656bd8b128fbea705fb70541e113197fb443dff9e320644f65cc0d79264b5d4c37b49734c0d2799ea26d35096539be030bf50c35f561f65ba + checksum: cca336752d588dac190a523daf78cbd0c584df6201c38b1dc1dfb0a0a0ccb7bcd950ff785a3f4654dfb9c166c95899bdf836d4dd3e34b1358b70144558d83696 languageName: node linkType: hard