Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^1.0.0-beta.19",
"@polkadot/api-contract": "^1.0.0-beta.19",
"@polkadot/api": "^1.0.0-beta.25",
"@polkadot/api-contract": "^1.0.0-beta.25",
"@polkadot/keyring": "^2.0.0-beta.6",
"@polkadot/types": "^1.0.0-beta.19",
"@polkadot/types": "^1.0.0-beta.25",
"@polkadot/util": "^2.0.0-beta.6",
"@polkadot/util-crypto": "^2.0.0-beta.6",
"babel-core": "^7.0.0-bridge.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-accounts/src/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Account ({ address, className, filter, isFavorite, toggleFavorite }: Pr
useEffect((): void => {
const { identity, nickname } = info || {};

if (api.api.query.identity?.identityOf) {
if (api.api.query.identity && api.api.query.identity.identityOf) {
if (identity?.display) {
setAccName(identity.display);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-address-book/src/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Address ({ address, className, filter, isFavorite, toggleFavorite }: Pr
useEffect((): void => {
const { identity, nickname } = info || {};

if (api.api.query.identity?.identityOf) {
if (api.api.query.identity && api.api.query.identity.identityOf) {
if (identity?.display) {
setAccName(identity.display);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.8.3",
"@polkadot/api-contract": "^1.0.0-beta.19"
"@polkadot/api-contract": "^1.0.0-beta.25"
}
}
2 changes: 1 addition & 1 deletion packages/app-staking/src/Overview/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function Address ({ address, authorsMap, className, filter, filterName, hasQueri

if (accountId?.toString().includes(filterName) || accountIndex?.toString().includes(filterName)) {
isVisible = true;
} else if (api.query.identity?.identityOf) {
} else if (api.query.identity && api.query.identity.identityOf) {
if (identity?.display) {
isVisible = identity.display.toLowerCase().includes(filterLower);
}
Expand Down
107 changes: 55 additions & 52 deletions packages/app-storage/src/Selection/Modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,71 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { TypeDef } from '@polkadot/types/types';
import { I18nProps } from '@polkadot/react-components/types';
import { RawParams } from '@polkadot/react-params/types';
import { ComponentProps, StorageEntryPromise } from '../types';
import { ComponentProps as Props, StorageEntryPromise } from '../types';

import React, { useState } from 'react';
import { getTypeDef } from '@polkadot/types';
import ApiPromise from '@polkadot/api/promise';
import { Button, InputStorage } from '@polkadot/react-components';
import Params from '@polkadot/react-params';
import { useApi } from '@polkadot/react-hooks';
import Params from '@polkadot/react-params';
import { getTypeDef } from '@polkadot/types';
import { isNull, isUndefined } from '@polkadot/util';

import translate from '../translate';

interface Props extends ComponentProps, I18nProps {}
import { useTranslation } from '../translate';

type ParamsType = { type: TypeDef }[];

function areParamsValid (values: RawParams): boolean {
return values.reduce(
(isValid: boolean, value): boolean => (
isValid &&
!isUndefined(value) &&
!isUndefined(value.value) &&
value.isValid),
true
);
interface KeyState {
defaultValues: RawParams | undefined | null;
isIterable: boolean;
key: StorageEntryPromise;
params: ParamsType;
}

function areParamsValid ({ creator: { meta: { type } } }: StorageEntryPromise, values: RawParams): boolean {
return values.reduce((isValid: boolean, value): boolean => {
return isValid &&
!isUndefined(value) &&
!isUndefined(value.value) &&
value.isValid;
}, (
type.isDoubleMap
? values.length === 2
: values.length === (type.isMap ? 1 : 0)
));
}

function expandKey (api: ApiPromise, key: StorageEntryPromise): KeyState {
const { creator: { meta: { type }, section } } = key;

return {
defaultValues: section === 'session' && type.isDoubleMap
? [{ isValid: true, value: api.consts.session.dedupKeyPrefix.toHex() }]
: null,
isIterable: type.isMap && type.asMap.linked.isTrue,
key,
params: type.isDoubleMap
? [
{ type: getTypeDef(type.asDoubleMap.key1.toString()) },
{ type: getTypeDef(type.asDoubleMap.key2.toString()) }
]
: type.isMap
? [{
type: getTypeDef(
type.asMap.linked.isTrue
? `Option<${type.asMap.key.toString()}>`
: type.asMap.key.toString()
)
}]
: []
};
}

function Modules ({ onAdd, t }: Props): React.ReactElement<Props> {
export default function Modules ({ onAdd }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [{ defaultValues, isIterable, key, params }, setKey] = useState<{ defaultValues: RawParams | undefined | null; isIterable: boolean; key: StorageEntryPromise; params: ParamsType }>({ defaultValues: undefined, isIterable: false, key: api.query.timestamp.now, params: [] });
const [{ defaultValues, isIterable, key, params }, setKey] = useState<KeyState>({ defaultValues: undefined, isIterable: false, key: api.query.timestamp.now, params: [] });
const [{ isValid, values }, setValues] = useState<{ isValid: boolean; values: RawParams }>({ isValid: true, values: [] });

const _onAdd = (): void => {
Expand All @@ -43,42 +77,13 @@ function Modules ({ onAdd, t }: Props): React.ReactElement<Props> {
params: values.filter(({ value }): boolean => !isIterable || !isNull(value))
});
};
const _onChangeValues = (values: RawParams): void => {
const _onChangeValues = (values: RawParams): void =>
setValues({
isValid: (
key.creator.meta.type.isDoubleMap
? values.length === 2
: values.length === (key.creator.meta.type.isMap ? 1 : 0)
) && areParamsValid(values),
isValid: areParamsValid(key, values),
values
});
};
const _onChangeKey = (key: StorageEntryPromise): void => {
const asMap = key.creator.meta.type.isMap && key.creator.meta.type.asMap;
const isIterable = !!asMap && (asMap.kind.isLinkedMap || asMap.kind.isPrefixedMap);

setKey({
defaultValues: key.creator.section === 'session' && key.creator.meta.type.isDoubleMap
? [{ isValid: true, value: api.consts.session.dedupKeyPrefix.toHex() }]
: null,
isIterable,
key,
params: key.creator.meta.type.isDoubleMap
? [
{ type: getTypeDef(key.creator.meta.type.asDoubleMap.key1.toString()) },
{ type: getTypeDef(key.creator.meta.type.asDoubleMap.key2.toString()) }
]
: asMap
? [{
type: getTypeDef(
isIterable
? `Option<${asMap.key.toString()}>`
: asMap.key.toString()
)
}]
: []
});

setKey(expandKey(api, key));
_onChangeValues([]);
};

Expand Down Expand Up @@ -112,5 +117,3 @@ function Modules ({ onAdd, t }: Props): React.ReactElement<Props> {
</section>
);
}

export default translate(Modules);
4 changes: 2 additions & 2 deletions packages/react-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.8.3",
"@polkadot/api": "^1.0.0-beta.19",
"@polkadot/extension-dapp": "^0.15.0-beta.2",
"@polkadot/api": "^1.0.0-beta.25",
"@polkadot/extension-dapp": "^0.20.1",
"edgeware-node-types": "^1.1.0",
"rxjs-compat": "^6.5.3"
}
Expand Down
Loading