Adjust query type display (#6150)

* Adjust query type display

* linting

* Fix test page
This commit is contained in:
Jaco 2021-09-19 18:58:56 +03:00 committed by GitHub
parent 0f9e5be7aa
commit 829830b83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 107 additions and 93 deletions

View File

@ -12,15 +12,15 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^6.0.2",
"@polkadot/api-contract": "^6.0.2",
"@polkadot/api": "^6.0.3-0",
"@polkadot/api-contract": "^6.0.3-0",
"@polkadot/hw-ledger": "^7.4.1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/networks": "^7.4.1",
"@polkadot/phishing": "^0.6.297",
"@polkadot/types": "^6.0.2",
"@polkadot/types-known": "^6.0.2",
"@polkadot/types-support": "^6.0.2",
"@polkadot/types": "^6.0.3-0",
"@polkadot/types-known": "^6.0.3-0",
"@polkadot/types-support": "^6.0.3-0",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"@polkadot/wasm-crypto": "^4.2.1",

View File

@ -5,7 +5,7 @@ import { screen } from '@testing-library/react';
import BN from 'bn.js';
import i18next from '@polkadot/react-components/i18n';
import toShortAddress from '@polkadot/react-components/util/toShortAddress';
import { toShortAddress } from '@polkadot/react-components/util/toShortAddress';
import { anAccountWithBalance, anAccountWithBalanceAndMeta, anAccountWithInfo, anAccountWithMeta, anAccountWithStaking } from '@polkadot/test-support/creation/account';
import { makeStakingLedger as ledger } from '@polkadot/test-support/creation/stakingInfo/stakingLedger';
import { alice, MemoryStore } from '@polkadot/test-support/keyring';

View File

@ -6,6 +6,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/api-contract": "^6.0.2"
"@polkadot/api-contract": "^6.0.3-0"
}
}

View File

@ -13,6 +13,7 @@ import styled from 'styled-components';
import { withCallDiv } from '@polkadot/react-api/hoc';
import { Button, Labelled } from '@polkadot/react-components';
import { getSiName } from '@polkadot/react-components/util';
import { useApi } from '@polkadot/react-hooks';
import valueToText from '@polkadot/react-params/valueToText';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
@ -87,7 +88,7 @@ function getCachedComponent (registry: Registry, query: QueryTypes): CacheInstan
const { meta, method, section } = key as unknown as ConstValue;
renderHelper = withCallDiv(`consts.${section}.${method}`, { withIndicator: true });
type = registry.lookup.getTypeDef(meta.type).type;
type = getSiName(registry.lookup, meta.type);
} else {
if (isU8a(key)) {
// subscribe to the raw key here

View File

@ -6,7 +6,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^6.0.2",
"@polkadot/api": "^6.0.3-0",
"@polkadot/extension-compat-metamask": "^0.40.3",
"@polkadot/extension-dapp": "^0.40.3",
"@substrate/connect": "^0.3.18",

View File

@ -15,8 +15,7 @@ import { isNull, isUndefined } from '@polkadot/util';
import Dropdown from '../Dropdown';
import Static from '../Static';
import { getAddressName } from '../util';
import addressToAddress from '../util/toAddress';
import { getAddressName, toAddress } from '../util';
import createHeader from './createHeader';
import createItem from './createItem';
@ -59,7 +58,7 @@ const MULTI_DEFAULT: string[] = [];
function transformToAddress (value?: string | Uint8Array | null): string | null {
try {
return addressToAddress(value) || null;
return toAddress(value) || null;
} catch (error) {
// noop, handled by return
}
@ -125,8 +124,8 @@ class InputAddress extends React.PureComponent<Props, State> {
return {
lastValue: lastValue || getLastValue(type),
value: Array.isArray(value)
? value.map((v) => addressToAddress(v))
: (addressToAddress(value) || undefined)
? value.map((v) => toAddress(v))
: (toAddress(value) || undefined)
};
} catch (error) {
return null;

View File

@ -4,9 +4,9 @@
import React, { useCallback, useState } from 'react';
import styled from 'styled-components';
import addressToAddress from './util/toAddress';
import IdentityIcon from './IdentityIcon';
import Input from './Input';
import { toAddress } from './util';
interface Props {
autoFocus?: boolean;
@ -27,7 +27,7 @@ function InputAddressSimple ({ autoFocus, children, className = '', defaultValue
const _onChange = useCallback(
(_address: string): void => {
const address = addressToAddress(_address) || null;
const address = toAddress(_address) || null;
setAddress(address);

View File

@ -8,6 +8,8 @@ import React from 'react';
import { ApiPromise } from '@polkadot/api';
import { getSiName } from '../../util';
export default function createOptions (api: ApiPromise, sectionName: string): DropdownOptions {
const section = api.consts[sectionName];
@ -29,7 +31,7 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr
className='ui--DropdownLinked-Item-call'
key={`${sectionName}_${value}:call`}
>
{value}: {api.registry.lookup.getTypeDef(method.meta.type).type}
{value}: {getSiName(api.registry.lookup, method.meta.type)}
</div>,
<div
className='ui--DropdownLinked-Item-text'

View File

@ -20,8 +20,7 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr
.map((value): DropdownOption => {
const method = section[value];
const inputs = method.meta.args
.filter((arg) => arg.type.toString() !== 'Origin')
.map((arg): string => arg.name.toString())
.map((arg) => arg.name.toString())
.join(', ');
return {

View File

@ -9,6 +9,8 @@ import React from 'react';
import { ApiPromise } from '@polkadot/api';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { getSiName } from '../../util';
export default function createOptions (api: ApiPromise, sectionName: string): DropdownOptions {
const section = api.query[sectionName];
@ -28,13 +30,13 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr
const { hashers, key } = type.asMap;
if (hashers.length === 1) {
input = api.registry.lookup.getTypeDef(key).type;
input = getSiName(api.registry.lookup, key);
} else {
const si = api.registry.lookup.getSiType(key).def;
if (si.isTuple) {
input = si.asTuple
.map((t) => api.registry.lookup.getTypeDef(t).type)
.map((t) => getSiName(api.registry.lookup, t))
.join(', ');
} else {
input = si.asHistoricMetaCompat.toString();

View File

@ -7,7 +7,7 @@ import { ApiPromise } from '@polkadot/api';
import { keyring } from '@polkadot/ui-keyring';
import { isFunction } from '@polkadot/util';
export default function checkVisibility (api: ApiPromise, address: string, accountInfo: DeriveAccountInfo, filterName = '', onlyNamed = false): boolean {
export function checkVisibility (api: ApiPromise, address: string, accountInfo: DeriveAccountInfo, filterName = '', onlyNamed = false): boolean {
let isVisible = false;
const filterLower = filterName.toLowerCase();

View File

@ -5,7 +5,7 @@ import { keyring } from '@polkadot/ui-keyring';
import { AccountIdIsh } from '../types';
export default function getAccountCryptoType (accountId: AccountIdIsh): string {
export function getAccountCryptoType (accountId: AccountIdIsh): string {
try {
const current = accountId
? keyring.getPair(accountId.toString())

View File

@ -5,7 +5,7 @@ import type { KeyringItemType, KeyringJson$Meta } from '@polkadot/ui-keyring/typ
import { keyring } from '@polkadot/ui-keyring';
export default function getAddressMeta (address: string, type: KeyringItemType | null = null): KeyringJson$Meta {
export function getAddressMeta (address: string, type: KeyringItemType | null = null): KeyringJson$Meta {
let meta: KeyringJson$Meta | undefined;
try {

View File

@ -3,11 +3,11 @@
import type { KeyringItemType } from '@polkadot/ui-keyring/types';
import getAddressMeta from './getAddressMeta';
import toShortAddress from './toShortAddress';
import { getAddressMeta } from './getAddressMeta';
import { toShortAddress } from './toShortAddress';
// isName, isDefault, name
export default function getAddressName (address: string, type: KeyringItemType | null = null, defaultName?: string): [boolean, boolean, string] {
export function getAddressName (address: string, type: KeyringItemType | null = null, defaultName?: string): [boolean, boolean, string] {
const meta = getAddressMeta(address, type);
return meta.name

View File

@ -3,8 +3,8 @@
import type { KeyringItemType } from '@polkadot/ui-keyring/types';
import getAddressMeta from './getAddressMeta';
import { getAddressMeta } from './getAddressMeta';
export default function getAddressTags (address: string, type: KeyringItemType | null = null): string[] {
export function getAddressTags (address: string, type: KeyringItemType | null = null): string[] {
return getAddressMeta(address, type).tags as string[] || [];
}

View File

@ -6,9 +6,9 @@ import type { AnyJson } from '@polkadot/types/types';
import { Abi } from '@polkadot/api-contract';
import { api } from '@polkadot/react-api';
import getAddressMeta from './getAddressMeta';
import { getAddressMeta } from './getAddressMeta';
export default function getContractAbi (address: string | null): Abi | null {
export function getContractAbi (address: string | null): Abi | null {
if (!address) {
return null;
}

View File

@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, SiLookupTypeId } from '@polkadot/types/interfaces';
export function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
const typeDef = lookup.getTypeDef(type);
return typeDef.lookupName || typeDef.type;
}

View File

@ -1,12 +1,13 @@
// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as checkVisibility } from './checkVisibility';
export { default as getAddressMeta } from './getAddressMeta';
export { default as getAddressName } from './getAddressName';
export { default as getAddressTags } from './getAddressTags';
export { default as getContractAbi } from './getContractAbi';
export { default as isTreasuryProposalVote } from './isTreasuryProposalVote';
export { default as toAddress } from './toAddress';
export { default as toShortAddress } from './toShortAddress';
export { default as getAccountCryptoType } from './getAccountCryptoType';
export { checkVisibility } from './checkVisibility';
export { getAddressMeta } from './getAddressMeta';
export { getAddressName } from './getAddressName';
export { getAddressTags } from './getAddressTags';
export { getContractAbi } from './getContractAbi';
export { getSiName } from './getSiName';
export { isTreasuryProposalVote } from './isTreasuryProposalVote';
export { toAddress } from './toAddress';
export { toShortAddress } from './toShortAddress';
export { getAccountCryptoType } from './getAccountCryptoType';

View File

@ -3,7 +3,7 @@
import type { Proposal } from '@polkadot/types/interfaces';
export default function isTreasuryProposalVote (proposal?: Proposal | null): boolean {
export function isTreasuryProposalVote (proposal?: Proposal | null): boolean {
if (!proposal) {
return false;
}

View File

@ -5,7 +5,7 @@ import { keyring } from '@polkadot/ui-keyring';
import { assert, hexToU8a, isHex } from '@polkadot/util';
import { ethereumEncode } from '@polkadot/util-crypto';
export default function toAddress (value?: string | Uint8Array | null, allowIndices = false): string | undefined {
export function toAddress (value?: string | Uint8Array | null, allowIndices = false): string | undefined {
if (value) {
try {
const u8a = isHex(value)

View File

@ -3,7 +3,7 @@
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
export default function toShortAddress (_address?: AccountId | AccountIndex | Address | string | null | Uint8Array): string {
export function toShortAddress (_address?: AccountId | AccountIndex | Address | string | null | Uint8Array): string {
const address = (_address || '').toString();
return (address.length > 13)

View File

@ -9,7 +9,7 @@
"testcontainers": "^7.20.2"
},
"devDependencies": {
"@polkadot/types-support": "^6.0.2",
"@polkadot/types-support": "^6.0.3-0",
"@testing-library/jest-dom": "^5.14.1",
"tsconfig-paths": "^3.11.0"
}

View File

@ -2513,50 +2513,50 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/api-contract@npm:^6.0.2":
version: 6.0.2
resolution: "@polkadot/api-contract@npm:6.0.2"
"@polkadot/api-contract@npm:^6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/api-contract@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/api": 6.0.3-0
"@polkadot/types": 6.0.3-0
"@polkadot/util": ^7.4.1
rxjs: ^7.3.0
checksum: 5d660ff7a08ededa4ac6dd9ca2d4b4ab271f7664380c674e81bc1f84fbbf6b400d47532f27810c96a82ea2c5399a40d2dfe999911bf34e38af47bee62213f362
checksum: dc2e34b34d4c21a02c130e4fc593f8dc69b4872dfb58880130c70baa0e1e431adddb5d6424b5ab1485a43fca2a69ba82b51c3c840afff8d0c8893209a92e2766
languageName: node
linkType: hard
"@polkadot/api-derive@npm:6.0.2":
version: 6.0.2
resolution: "@polkadot/api-derive@npm:6.0.2"
"@polkadot/api-derive@npm:6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/api-derive@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api": 6.0.2
"@polkadot/rpc-core": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/api": 6.0.3-0
"@polkadot/rpc-core": 6.0.3-0
"@polkadot/types": 6.0.3-0
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
rxjs: ^7.3.0
checksum: eb25c10aec6448a0a7987b99f75e1941555aef15782d92b40a84056c43fc3edb6eb8477d83e01ca7cd0923fdaf12c0fc2d1367dbc8940c0ef1502b5fcb726f3f
checksum: 41f0c5ceccda5c67bc25526d01e85dd1abde182331a472c45ca3a1d747b75191f6d5f6680fa8beb2b358d0ca993c28fe8701007ffff7404018b82bb1e7aef3db
languageName: node
linkType: hard
"@polkadot/api@npm:^6.0.2":
version: 6.0.2
resolution: "@polkadot/api@npm:6.0.2"
"@polkadot/api@npm:^6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/api@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api-derive": 6.0.2
"@polkadot/api-derive": 6.0.3-0
"@polkadot/keyring": ^7.4.1
"@polkadot/rpc-core": 6.0.2
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/types-known": 6.0.2
"@polkadot/rpc-core": 6.0.3-0
"@polkadot/rpc-provider": 6.0.3-0
"@polkadot/types": 6.0.3-0
"@polkadot/types-known": 6.0.3-0
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
eventemitter3: ^4.0.7
rxjs: ^7.3.0
checksum: ed4a905a7e403f1358065349f4cb670a15e538ddd9b6d9f1b7b829094a70ff8dfce7f537d24dfb5e490ac8077645392c886f14aae2066e21b2970d0050e60ab1
checksum: 5e83fa71899c56daad1c7a820698a0a1171661e8c2a8f89d5e3ea22fe974f863a4d38412bf84132a2f5aad284c9ae1a774df3f2c75ff7f5677853f1c7ac9c97e
languageName: node
linkType: hard
@ -2629,7 +2629,7 @@ __metadata:
resolution: "@polkadot/app-contracts@workspace:packages/page-contracts"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api-contract": ^6.0.2
"@polkadot/api-contract": ^6.0.3-0
languageName: unknown
linkType: soft
@ -3123,7 +3123,7 @@ __metadata:
resolution: "@polkadot/react-api@workspace:packages/react-api"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api": ^6.0.2
"@polkadot/api": ^6.0.3-0
"@polkadot/extension-compat-metamask": ^0.40.3
"@polkadot/extension-dapp": ^0.40.3
"@substrate/connect": ^0.3.18
@ -3256,32 +3256,32 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/rpc-core@npm:6.0.2":
version: 6.0.2
resolution: "@polkadot/rpc-core@npm:6.0.2"
"@polkadot/rpc-core@npm:6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/rpc-core@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/rpc-provider": 6.0.3-0
"@polkadot/types": 6.0.3-0
"@polkadot/util": ^7.4.1
rxjs: ^7.3.0
checksum: e71a66001258be19b5be7b83a90a52587fd5380e62ca3c59f3968beeefda8daafd9b42a2e49796d007795714f3c381c65720d246ffa9393e5d8313fb3943e0cf
checksum: 0c78dc600f3a0b16ee83609d6a1e59e0346a573197b6bb3d495477dd5e40edd6ec3428060e350cb20163f06675fc9aa5831a082ed383e5de344e8b33ebd3a5b2
languageName: node
linkType: hard
"@polkadot/rpc-provider@npm:6.0.2":
version: 6.0.2
resolution: "@polkadot/rpc-provider@npm:6.0.2"
"@polkadot/rpc-provider@npm:6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/rpc-provider@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/types": 6.0.2
"@polkadot/types": 6.0.3-0
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
"@polkadot/x-fetch": ^7.4.1
"@polkadot/x-global": ^7.4.1
"@polkadot/x-ws": ^7.4.1
eventemitter3: ^4.0.7
checksum: 48593bb9f0714ca22cefea6924b1088450c1f281c14157c23fbf7323e8d8c4117404f35c30c8dc1b01187769f0aaabe77fd8cb46e8cca520240c8e98d328e66e
checksum: 6a1c0a4757e8357894fcc9c5e3ae28ee3512705d8c6e425772635764d0fc03d060326b66235affffc70133d780ac53289a8d54b657b6301036c934bab58b2718
languageName: node
linkType: hard
@ -3305,7 +3305,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@polkadot/test-support@workspace:packages/test-support"
dependencies:
"@polkadot/types-support": ^6.0.2
"@polkadot/types-support": ^6.0.3-0
"@testing-library/jest-dom": ^5.14.1
"@testing-library/react": ^12.1.0
testcontainers: ^7.20.2
@ -3322,37 +3322,37 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/types-known@npm:^6.0.2":
version: 6.0.2
resolution: "@polkadot/types-known@npm:6.0.2"
"@polkadot/types-known@npm:^6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/types-known@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/networks": ^7.4.1
"@polkadot/types": 6.0.2
"@polkadot/types": 6.0.3-0
"@polkadot/util": ^7.4.1
checksum: 5ed010d36c69347fc20d14eac760582b8152f348d3c36c739cdcebe283897fb0db8f65a051b810bc901f290240d3b03f5d85701673254d32ebcbcf35f6bb925d
checksum: e2fd7006153c390dd8da893ae0dcabe7927f136d4a3b4c90fdc02802cd99d0be499733de51627fe4eaa87a2b5c755ac5dbcbdf8e7790c3c4740ea8db5c595b8b
languageName: node
linkType: hard
"@polkadot/types-support@npm:^6.0.2":
version: 6.0.2
resolution: "@polkadot/types-support@npm:6.0.2"
"@polkadot/types-support@npm:^6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/types-support@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/util": ^7.4.1
checksum: f39485f6e3030c226a016daa5ed43872c627f58be05182d401ce9447d00845dd8d1d0d9092bb39abd0fab69d3059b4d8ff7eb1a9284b7ffe8394a05172e4ead3
checksum: 9b98d6fbec600ba83305726db85e7e81c2a85a495160936b9b74fcb669a28f7f5ef172a827ed09b17a12e86dd7bcaa01079b843843152fb06ca3c3f40985f121
languageName: node
linkType: hard
"@polkadot/types@npm:^6.0.2":
version: 6.0.2
resolution: "@polkadot/types@npm:6.0.2"
"@polkadot/types@npm:^6.0.3-0":
version: 6.0.3-0
resolution: "@polkadot/types@npm:6.0.3-0"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
rxjs: ^7.3.0
checksum: 9b70f2e6526c1472cda43209852d5741d1099be2ecf27ebff16a9a449272bb0ff847d7498427b24de606f328126074862e5f8c4f14750e11aff5cd41f1451895
checksum: e15690d67aeb323160fcbe5b2f2e6680c7996dc339b97c489c967fddfd519ea1284b7798db69c803aaa096b4db61867d5e415488db96de000ee0ee6a59275061
languageName: node
linkType: hard