Bump API (incl. staking ledger fixes) (#2156)

* Bump API (incl. staking ledger fixes)

* Api context

* Replace counter

* Linting

* Swap t -> useTranslation

* Cleanup unwrap

* Rebuild i18n (& make auto-config)

* Remove old eslint override
This commit is contained in:
Jaco Greeff 2020-01-20 15:08:03 +01:00 committed by GitHub
parent 5f00e4dcd6
commit 03a5b2726c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 113 additions and 170 deletions

View File

@ -1,7 +1,38 @@
// Copyright 2017-2020 @polkadot/apps authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const fs = require('fs');
const path = require('path');
const typescript = require('typescript');
const findPackages = require('./scripts/findPackages');
function transform (file, enc, done) {
const { ext } = path.parse(file.path);
if (ext === '.tsx') {
const content = fs.readFileSync(file.path, enc);
const { outputText } = typescript.transpileModule(content, {
compilerOptions: {
target: 'es2018'
},
fileName: path.basename(file.path)
});
const parserHandler = (key, options) => {
options.defaultValue = key;
options.ns = /packages\/(.*?)\/src/g.exec(file.path)[1];
this.parser.set(key, options);
};
this.parser.parseFuncFromString(outputText, parserHandler);
}
done();
}
module.exports = {
input: [
'packages/*/src/**/*.{ts,tsx}',
@ -22,38 +53,7 @@ module.exports = {
},
lngs: ['en'],
defaultLng: 'en',
ns: [
'app-123code',
'app-accounts',
'app-address-book',
'app-claims',
'app-contracts',
'app-council',
'app-dashboard',
'app-democracy',
'app-explorer',
'app-extrinsics',
'app-generic-asset',
'app-js',
'app-parachains',
'app-settings',
'app-society',
'app-staking',
'app-storage',
'app-sudo',
'app-tech-comm',
'app-toolbox',
'app-transfer',
'app-treasury',
'apps',
'apps-routing',
'react-api',
'react-components',
'react-params',
'react-query',
'react-signer',
'ui'
],
ns: findPackages().map(({ dir }) => dir),
defaultNs: 'ui',
resource: {
loadPath: 'packages/apps/public/locales/{{lng}}/{{ns}}.json',
@ -64,28 +64,5 @@ module.exports = {
nsSeparator: false, // namespace separator
keySeparator: false // key separator
},
transform: function transform (file, enc, done) {
const { ext } = path.parse(file.path);
if (ext === '.tsx') {
const content = fs.readFileSync(file.path, enc);
const { outputText } = typescript.transpileModule(content, {
compilerOptions: {
target: 'es2018'
},
fileName: path.basename(file.path)
});
const parserHandler = (key, options) => {
options.defaultValue = key;
options.ns = /packages\/(.*?)\/src/g.exec(file.path)[1];
this.parser.set(key, options);
};
this.parser.parseFuncFromString(outputText, parserHandler);
}
done();
}
transform
};

View File

@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^1.0.0-beta.12",
"@polkadot/api-contract": "^1.0.0-beta.12",
"@polkadot/api": "^1.0.0-beta.13",
"@polkadot/api-contract": "^1.0.0-beta.13",
"@polkadot/keyring": "^2.0.0-beta.4",
"@polkadot/types": "^1.0.0-beta.12",
"@polkadot/types": "^1.0.0-beta.13",
"@polkadot/util": "^2.0.0-beta.4",
"@polkadot/util-crypto": "^2.0.0-beta.4",
"babel-core": "^7.0.0-bridge.0",

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.7.7",
"@polkadot/api-contract": "^1.0.0-beta.12"
"@polkadot/api-contract": "^1.0.0-beta.13"
}
}

View File

@ -7,12 +7,9 @@ import { AppProps, BareProps } from '@polkadot/react-components/types';
import React from 'react';
import { Tabs } from '@polkadot/react-components';
import useCheck from './useCheck';
import Overview from './Overview';
import { useTranslation } from './translate';
export { useCheck };
interface Props extends AppProps, BareProps {}
export default function SocietyApp ({ basePath, className }: Props): React.ReactElement<Props> {

View File

@ -1,21 +0,0 @@
// Copyright 2017-2020 @polkadot/app-society authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId } from '@polkadot/types/interfaces';
import { useState, useEffect } from 'react';
import { useApi, useCall } from '@polkadot/react-hooks';
import { Option } from '@polkadot/types';
export default function useCheck (): boolean {
const { api, isApiReady } = useApi();
const founder = useCall<Option<AccountId>>(isApiReady ? api.query.society?.founder : undefined, []);
const [check, setCheck] = useState(false);
useEffect((): void => {
setCheck(founder?.isSome || false);
}, [founder]);
return check;
}

View File

@ -2,7 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, StakingLedger } from '@polkadot/types/interfaces';
import React, { useEffect, useState } from 'react';
@ -10,9 +9,9 @@ import { Icon } from '@polkadot/react-components';
import { Option } from '@polkadot/types';
import { useApi, useCall } from '@polkadot/react-hooks';
import translate from '../../translate';
import { useTranslation } from '../../translate';
interface Props extends I18nProps {
interface Props {
accountId: string | null;
controllerId: string | null;
defaultController?: string;
@ -22,25 +21,20 @@ interface Props extends I18nProps {
const DISTINCT = 'Distinct stash and controller accounts are recommended to ensure fund security.';
function ValidateController ({ accountId, controllerId, defaultController, isUnsafeChain, onError, t }: Props): React.ReactElement<Props> | null {
export default function ValidateController ({ accountId, controllerId, defaultController, isUnsafeChain, onError }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const bondedId = useCall<string | null>(api.query.staking.bonded, [controllerId], {
transform: (value: Option<AccountId>): string | null => {
const extracted = value.unwrapOr(null);
return extracted
? extracted.toString()
: null;
}
transform: (value: Option<AccountId>): string | null =>
value.isSome
? value.unwrap().toString()
: null
});
const stashId = useCall<string | null>(api.query.staking.ledger, [controllerId], {
transform: (value: Option<StakingLedger>): string | null => {
const extracted = value.unwrapOr({ stash: null }).stash;
return extracted
? extracted.toString()
: null;
}
const stashId = useCall<string | null>(controllerId ? api.query.staking.ledger : null, [controllerId], {
transform: (value: Option<StakingLedger>): string | null =>
value.isSome
? value.unwrap().stash.toString()
: null
});
const [error, setError] = useState<string | null>(null);
@ -77,5 +71,3 @@ function ValidateController ({ accountId, controllerId, defaultController, isUns
</article>
);
}
export default translate(ValidateController);

View File

@ -4,12 +4,11 @@
import { Routes } from './types';
import Society, { useCheck } from '@polkadot/app-society';
import Society from '@polkadot/app-society';
export default ([
{
Component: Society,
useCheck,
display: {
needsApi: [
'query.society.pot'

View File

@ -0,0 +1 @@
{}

View File

@ -15,7 +15,6 @@ import { isFunction } from '@polkadot/util';
import { useTranslation } from '../translate';
const DUMMY_CHECK = (): boolean => true;
const DUMMY_COUNTER = (): number => 0;
interface Props {
@ -74,14 +73,13 @@ function checkVisible (name: string, { api, isApiReady, isApiConnected }: ApiPro
return notFound.length === 0;
}
export default function Item ({ route: { Modal, useCheck = DUMMY_CHECK, useCounter = DUMMY_COUNTER, display, i18n, icon, name }, isCollapsed, onClick }: Props): React.ReactElement<Props> | null {
export default function Item ({ route: { Modal, useCounter = DUMMY_COUNTER, display, i18n, icon, name }, isCollapsed, onClick }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { allAccounts, hasAccounts } = useAccounts();
const apiProps = useApi();
const sudoKey = useCall<AccountId>(apiProps.isApiReady ? apiProps.api.query.sudo?.key : undefined, []);
const [hasSudo, setHasSudo] = useState(false);
const [isVisible, setIsVisible] = useState(false);
const checkState = useCheck();
const count = useCounter();
useEffect((): void => {
@ -89,8 +87,8 @@ export default function Item ({ route: { Modal, useCheck = DUMMY_CHECK, useCount
}, [allAccounts, sudoKey]);
useEffect((): void => {
setIsVisible(checkState && checkVisible(name, apiProps, hasAccounts, hasSudo, display));
}, [apiProps, checkState, hasAccounts, hasSudo]);
setIsVisible(checkVisible(name, apiProps, hasAccounts, hasSudo, display));
}, [apiProps, hasAccounts, hasSudo]);
if (!isVisible) {
return null;

View File

@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.7.6",
"@polkadot/api": "^1.0.0-beta.12",
"@polkadot/api": "^1.0.0-beta.13",
"@polkadot/extension-dapp": "^0.15.0-beta.1",
"edgeware-node-types": "^1.0.10",
"rxjs-compat": "^6.5.3"

View File

@ -140,11 +140,13 @@ export default function Api ({ children, queuePayload, queueSetTxStatus, url }:
setIsApiLoading(false);
}, []);
return api
? (
<ApiContext.Provider value={{ ...state, api, isApiConnected, isApiLoading, isWaitingInjected }}>
{children}
</ApiContext.Provider>
)
: null;
if (isApiLoading) {
return null;
}
return (
<ApiContext.Provider value={{ ...state, api, isApiConnected, isWaitingInjected }}>
{children}
</ApiContext.Provider>
);
}

View File

@ -30,7 +30,6 @@ export interface ApiProps extends ApiState {
api: ApiPromise;
isWaitingInjected: boolean;
isApiConnected: boolean;
isApiLoading: boolean;
}
export interface OnChangeCbObs {

View File

@ -98,7 +98,7 @@ function subscribe <T> (mounted: MountedRef, tracker: TrackerRef, fn: TrackFn |
// - returns a promise with an unsubscribe function
// - has a callback to set the value
// FIXME The typings here need some serious TLC
export default function useCall <T> (fn: TrackFn | undefined, params: CallParams, options: CallOptions<T> = {}): T | undefined {
export default function useCall <T> (fn: TrackFn | undefined | null, params: CallParams, options: CallOptions<T> = {}): T | undefined {
const mounted = useIsMountedRef();
const tracker = useRef<Tracker>({ isActive: false, count: 0, serialized: null, subscriber: null });
const [value, setValue] = useState<T | undefined>(options.defaultValue);

View File

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
// Copyright 2017-2020 @polkadot/react-query authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@ -23,7 +22,7 @@ export default function BondedDisplay ({ children, className, label, params }: P
transform: (value): AccountId | null =>
value.unwrapOr(null)
});
const stakingLedger = useCall<StakingLedger | null>(api.query.staking.ledger, [controllerId], {
const stakingLedger = useCall<StakingLedger | null>(controllerId && api.query.staking.ledger, [controllerId], {
transform: (value): StakingLedger | null =>
value.unwrapOr(null)
});

View File

@ -2093,35 +2093,35 @@
dependencies:
"@types/node" ">= 8"
"@polkadot/api-contract@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-1.0.0-beta.12.tgz#0611968e8b459f92c5d0f7d2d98eb1c97bce01f9"
integrity sha512-9hA5+VzLDVqQW00ewc7nFf+bS5hJEVittjvlJXWZoXSAAERFmsr5OEmESkz+Ku8j4W/yQn2XChRbv4WsX35Srg==
"@polkadot/api-contract@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-1.0.0-beta.13.tgz#2eabe3802ecee55ed90ebffc50ca39bbd2cad375"
integrity sha512-3FIyfMVvbH7Mj1R66oWtSIrPbpZ415D956jyUoCPrhctUrnJ9O+kNryDXw7ufZAX6Da4g81uyrrTihsnId+DTg==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/types" "^1.0.0-beta.12"
"@polkadot/types" "^1.0.0-beta.13"
"@polkadot/api-derive@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.0.0-beta.12.tgz#ee0bb0e0dc916a610c48aa5dbb975e2b9f6b0064"
integrity sha512-oxYMc+Rkg1FhHCHiF1PPLGxzWYt9/q2u/IzP7R2SOQI3CivbU8Io97+AQrlUHcxeOcvRnb8hofFvcKhvfytO/g==
"@polkadot/api-derive@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.0.0-beta.13.tgz#abd10706c6517047098d262328bc55fdceb4e6cb"
integrity sha512-u6PVepsWD6lwispR+Fz49DpgMUZS0zXS/lEJpHB6ScYvxBu1FYiDW7fP1KMTZjaWzZ5iZCbUiPm5+/k+0kiiqA==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/api" "^1.0.0-beta.12"
"@polkadot/types" "^1.0.0-beta.12"
"@polkadot/api" "^1.0.0-beta.13"
"@polkadot/types" "^1.0.0-beta.13"
"@polkadot/api@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.0.0-beta.12.tgz#60985ab369389957f3e0fac0630c91e4d8b6aa53"
integrity sha512-bWZ34qW/SyhWDUFaK+VUMW2XAlamGx6A9En2nrdcrztxY9iHLUB6Dpa28lvfZKBw4rlm1fq2mcWlk6fKPkyqdw==
"@polkadot/api@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.0.0-beta.13.tgz#e6b93ea4c4717676ccc13ba89b43fbfdeaf8613a"
integrity sha512-MhO9KwWc1j/hgy3uo26MnXNgZ9Lr8VYiGYkdhaX4Rgck+nIYqT6X9lOeGBF87jUC0v09tY0igsKSPhJYthodVg==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/api-derive" "^1.0.0-beta.12"
"@polkadot/api-derive" "^1.0.0-beta.13"
"@polkadot/keyring" "^2.0.0-beta.4"
"@polkadot/metadata" "^1.0.0-beta.12"
"@polkadot/rpc-core" "^1.0.0-beta.12"
"@polkadot/rpc-provider" "^1.0.0-beta.12"
"@polkadot/types" "^1.0.0-beta.12"
"@polkadot/metadata" "^1.0.0-beta.13"
"@polkadot/rpc-core" "^1.0.0-beta.13"
"@polkadot/rpc-provider" "^1.0.0-beta.13"
"@polkadot/types" "^1.0.0-beta.13"
"@polkadot/util-crypto" "^2.0.0-beta.4"
"@polkadot/dev-react@^0.32.14":
@ -2226,10 +2226,10 @@
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/jsonrpc@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-1.0.0-beta.12.tgz#22219c7e210d5a4877db5a610299a556e8450027"
integrity sha512-ms+wUv2uRX59iLvx3K+ci6yBOsvb+Xl3ZjWNVjIKBmr8FjzxMkLNd8h3FCz6UxyiYPGs0Y3OLqZbV/K4d1vkLg==
"@polkadot/jsonrpc@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-1.0.0-beta.13.tgz#c1591b732b881ff124783d5ad88783de43429fc0"
integrity sha512-JKhUBx5ADp0CkhZmpaBRbZcFEOhGN7woY0GnVVPYS958KX44dGm/dKLyHP8TfeltXaM6moFoM9pUcBo/4NdZpA==
dependencies:
"@babel/runtime" "^7.7.7"
@ -2242,13 +2242,13 @@
"@polkadot/util" "^2.0.0-beta.4"
"@polkadot/util-crypto" "^2.0.0-beta.4"
"@polkadot/metadata@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.0.0-beta.12.tgz#338e3ac7f323acf8c6d119c1bd91178767e71c36"
integrity sha512-86tE7uNX/6aaqgUMGr3ejQgEEdN4o0iYAB7ew3pMtXAdtYaAl2mGQkZWUNuXT7iT8XcwcUqVtPd48EWNuDm/PA==
"@polkadot/metadata@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.0.0-beta.13.tgz#14a98ba637b1a7fc3af1555d5ab96d62b332f1d4"
integrity sha512-Kaira59039p/41WDp+DG9gfWA0wv+vfYaYL7+T3kFguuANvp0vqK66p8VSdaYYpL3IF4alQdUoneHBDOUnFaAA==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/types" "^1.0.0-beta.12"
"@polkadot/types" "^1.0.0-beta.13"
"@polkadot/util" "^2.0.0-beta.4"
"@polkadot/util-crypto" "^2.0.0-beta.4"
@ -2276,25 +2276,25 @@
qrcode-generator "^1.4.4"
react-qr-reader "^2.2.1"
"@polkadot/rpc-core@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.0.0-beta.12.tgz#81d5eca3e540d607fd66f16412e9d9ef7e9c2999"
integrity sha512-4OfZp+MZEdvw0wLeaKP5r4ZvWVkSFtWKyWK4lyRTqId0zmLHmBtITxGCkFlteSxn7d6+RO+FeoBbxAE94kqf0g==
"@polkadot/rpc-core@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.0.0-beta.13.tgz#818ce991a2431e1ed9b71b0e8d5dd5c226330444"
integrity sha512-gtArQw056i/6ptsn+XZo6YsMX8yeXwEgryxhBjJVPwjhF3XuHPq3kmCaLyJlbmZQo775hUsWMGHTjr8JNyt6HQ==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/jsonrpc" "^1.0.0-beta.12"
"@polkadot/rpc-provider" "^1.0.0-beta.12"
"@polkadot/types" "^1.0.0-beta.12"
"@polkadot/jsonrpc" "^1.0.0-beta.13"
"@polkadot/rpc-provider" "^1.0.0-beta.13"
"@polkadot/types" "^1.0.0-beta.13"
"@polkadot/util" "^2.0.0-beta.4"
rxjs "^6.5.4"
"@polkadot/rpc-provider@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.0.0-beta.12.tgz#dfe15322e4abf2e12f7b9e9cad4710a79215fa33"
integrity sha512-0hFZnelNVZVvrM5MMTAOSjzXegDT4Zxi0Shdr268lacM85K270UGW1jjCL57qsUgGB9DhZE//7nnu8Osi9Pk7g==
"@polkadot/rpc-provider@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.0.0-beta.13.tgz#dc54532ac421f1126e8b91197b6a6e7d3f30f4af"
integrity sha512-c2gxxZCLdSEiLv6P3+JPBjndZ62GIeNylRuk7lq4mqSqc3NRrRQJ8gRySNz07CWJNglEWpEMlQ44jlGq+IExZA==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/metadata" "^1.0.0-beta.12"
"@polkadot/metadata" "^1.0.0-beta.13"
"@polkadot/util" "^2.0.0-beta.4"
"@polkadot/util-crypto" "^2.0.0-beta.4"
eventemitter3 "^4.0.0"
@ -2308,13 +2308,13 @@
dependencies:
"@types/chrome" "^0.0.91"
"@polkadot/types@^1.0.0-beta.12":
version "1.0.0-beta.12"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.0.0-beta.12.tgz#314015f5f4d42c118fcf8d8353902d9524bd7cca"
integrity sha512-zlKT+UFCfYmAbkqmSXloKumatIk1u5N3vgzHKir9rgG6eqsvRWkhxxjxvkARKvQUFWjY2dwvVy6g7263Rz35Ng==
"@polkadot/types@^1.0.0-beta.13":
version "1.0.0-beta.13"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.0.0-beta.13.tgz#200e9468285920ad6ed3749ca4022adc46fe8ecf"
integrity sha512-iDrCMqdy5g087yEeKXGlzMehFgg3jVcTerhJTckh0RQEE91IzMh7TWj9rBubB5ym3HhjKWxdEpEhtbiIfOiqJA==
dependencies:
"@babel/runtime" "^7.7.7"
"@polkadot/metadata" "^1.0.0-beta.12"
"@polkadot/metadata" "^1.0.0-beta.13"
"@polkadot/util" "^2.0.0-beta.4"
"@polkadot/util-crypto" "^2.0.0-beta.4"
"@types/memoizee" "^0.4.3"