* Bump API

* Rebuild i18n

* Fix InputAddress

* Pass through registry where applicable
This commit is contained in:
Jaco Greeff 2020-11-12 15:43:19 +01:00 committed by GitHub
parent 5ebc883926
commit e10d56d0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 172 additions and 146 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -1389,7 +1389,6 @@
"transfer received": "트랜스퍼를 받았습니다",
"transfer remark/comment": "이체할 발언/ 논평",
"transferrable": "이체 가능",
"transferrable ": "이체 가능",
"transferrable minus fees": "수수료를 제외하고 이체 가능",
"trusted social recovery helpers": "신뢰할 수 있는 \"계정 복구 도우미\" 목록",
"turnout": "투표자 수",

View File

@ -1292,7 +1292,6 @@
"transfer received": "转账接收成功",
"transfer remark/comment": "转账备注/评论",
"transferrable": "可转账的",
"transferrable ": "可转账的",
"trusted social recovery helpers": "信任的社交恢复帮手",
"turnout": "结果",
"twitter": "Twitter",

View File

@ -60,7 +60,6 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send
}
}, [api, balances, recipientId, senderId]);
const transferrable = <span className='label'>{t<string>('transferrable')}</span>;
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<string>('send from account')}
labelExtra={
<Available
label={transferrable}
label={t<string>('transferrable')}
params={senderId}
/>
}
@ -101,7 +100,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send
label={t<string>('send to address')}
labelExtra={
<Available
label={transferrable}
label={t<string>('transferrable')}
params={recipientId}
/>
}

View File

@ -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"
}
}

View File

@ -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={
<Available
label={t<string>('transferrable')}
params={accountId}
/>
}
onChange={setAccountId}
type='account'
value={accountId}

View File

@ -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<string>('Specify the user account to use for this contract call. And fees will be deducted from this account.')}
label={t<string>('call from account')}
labelExtra={
<Available
label={t<string>('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}
/>
</>
)}

View File

@ -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={
<Available
label={t<string>('transferrable')}
params={accountId}
/>
}
onChange={setAccountId}
type='account'
value={accountId}
@ -133,23 +140,22 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
/>
)}
{contractAbi && (
<Dropdown
help={t<string>('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}
/>
<>
<Dropdown
help={t<string>('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}
/>
<Params
onChange={setParams}
params={contractAbi.constructors[constructorIndex].args}
registry={contractAbi.registry}
/>
</>
)}
<Params
onChange={setParams}
params={
contractAbi
? contractAbi.constructors[constructorIndex].args
: []
}
/>
<InputBalance
help={t<string>('The allotted endowment for this contract, i.e. the amount transferred to the contract upon instantiation.')}
isError={!isEndowmentValid}

View File

@ -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<Props> | null {
function Params ({ isDisabled, onChange, onEnter, params: propParams, registry }: Props): React.ReactElement<Props> | null {
const [params, setParams] = useState<ParamDef[]>([]);
useEffect((): void => {
@ -41,6 +42,7 @@ function Params ({ isDisabled, onChange, onEnter, params: propParams }: Props):
onChange={_onChange}
onEnter={onEnter}
params={params}
registry={registry}
/>
);
}

View File

@ -81,7 +81,7 @@ function Transfer ({ className, parachains }: Props): React.ReactElement<Props>
label={t<string>('send from account')}
labelExtra={
<Available
label={t<string>('transferrable ')}
label={t<string>('transferrable')}
params={accountId}
/>
}

View File

@ -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"
}

View File

@ -289,8 +289,8 @@ const ExportedComponent = withMulti(
top: -1.05rem;
> div,
> img,
> svg {
img,
svg {
height: 32px !important;
width: 32px !important;
}

View File

@ -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<Props> {
function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, registry, type, withLabel }: Props): React.ReactElement<Props> {
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(

View File

@ -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<Props> {
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<ParamDef[] | null>(null);
const [initialValue, setInitialValue] = useState<string | null>(null);
const [{ options, subTypes }, setOptions] = useState<Options>({ options: [], subTypes: [] });
@ -43,7 +42,7 @@ function EnumParam (props: Props): React.ReactElement<Props> {
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<Props> {
onChange={_onChangeParam}
overrides={overrides}
params={current}
registry={registry}
/>
)}
</Bare>

View File

@ -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<Props> {
function Moment ({ className = '', defaultValue, isDisabled, isError, label, onChange, onEnter, onEscape, registry, type, withLabel }: Props): React.ReactElement<Props> {
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}
/>

View File

@ -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<Props> {
);
}
const value = registry.createType('Call', (props.defaultValue.value as Bytes).toHex());
const value = props.registry.createType('Call', (props.defaultValue.value as Bytes).toHex());
return (
<CallDisplay

View File

@ -11,7 +11,7 @@ import { Toggle } from '@polkadot/react-components';
import { useTranslation } from '../translate';
import Param from './index';
function Option ({ className = '', defaultValue, isDisabled, name, onChange, onEnter, onEscape, type: { sub, withOptionActive } }: Props): React.ReactElement<Props> {
function Option ({ className = '', defaultValue, isDisabled, name, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive } }: Props): React.ReactElement<Props> {
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 && (

View File

@ -11,7 +11,7 @@ import Static from './Static';
import useParamDefs from './useParamDefs';
function StructParam (props: Props): React.ReactElement<Props> {
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<Props> {
onChange={_onChangeParams}
overrides={overrides}
params={params}
registry={props.registry}
/>
</div>
);

View File

@ -11,7 +11,7 @@ import Static from './Static';
import useParamDefs from './useParamDefs';
function Tuple (props: Props): React.ReactElement<Props> {
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<Props> {
onChange={_onChangeParams}
overrides={overrides}
params={params}
registry={props.registry}
/>
</div>
);

View File

@ -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<Props> | null {
function Vector ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, registry, type, withLabel }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const inputParams = useParamDefs(type);
const inputParams = useParamDefs(registry, type);
const [count, setCount] = useState(0);
const [params, setParams] = useState<ParamDef[]>([]);
const [values, setValues] = useState<RawParam[]>([]);
@ -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}
/>
</Base>

View File

@ -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<Props> | null {
const inputParams = useParamDefs(type);
function VectorFixed ({ className = '', defaultValue, isDisabled = false, label, onChange, overrides, registry, type, withLabel }: Props): React.ReactElement<Props> | null {
const inputParams = useParamDefs(registry, type);
const [params, setParams] = useState<ParamDef[]>([]);
const [values, setValues] = useState<RawParam[]>([]);
@ -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}
/>
</Base>

View File

@ -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<Props> {
function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, registry, withLabel }: Props): React.ReactElement<Props> {
const _onChange = useCallback(
(value: number) =>
onChange && onChange({

View File

@ -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<Props> {
export default function findComponent (registry: Registry, def: TypeDef, overrides: ComponentMap = {}): React.ComponentType<Props> {
const findOne = (type: string): React.ComponentType<Props> | 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;

View File

@ -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<Props> | null {
const compRef = useRef<React.ComponentType<CProps> | null>(findComponent(type, overrides));
function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
const compRef = useRef<React.ComponentType<CProps> | 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}
/>
);

View File

@ -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<ParamDef[]>([]);
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;
}

View File

@ -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<Props> {
function ParamComp ({ defaultValue, index, isDisabled, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> {
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}
/>
</div>

View File

@ -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<Props, State> {
params: null
};
public static getDerivedStateFromProps ({ isDisabled, params, values }: Props, prevState: State): Pick<State, never> | null {
public static getDerivedStateFromProps ({ isDisabled, params, registry = defaultRegistry, values }: Props, prevState: State): Pick<State, never> | null {
const isSame = JSON.stringify(prevState.params) === JSON.stringify(params);
if (isDisabled || isSame) {
@ -51,7 +54,7 @@ class Params extends React.PureComponent<Props, State> {
...result,
values && values[index]
? values[index]
: createValue(param)
: createValue(registry, param)
],
[]
)
@ -75,7 +78,7 @@ class Params extends React.PureComponent<Props, State> {
}
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<Props, State> {
onEnter={onEnter}
onEscape={onEscape}
overrides={overrides}
registry={registry}
type={type}
/>
))}

View File

@ -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<string, unknown>, def): Record<string, unknown> => {
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;

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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 (
<div className={`ui--FormatBalance ${className}`}>
{label || ''}<span className='ui--FormatBalance-value'>{
{label ? <>{label}&nbsp;</> : ''}<span className='ui--FormatBalance-value'>{
value
? value === 'all'
? t<string>('everything{{labelPost}}', { replace: { labelPost } })

106
yarn.lock
View File

@ -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