Update API to new jsonrpc structures (#2420)

This commit is contained in:
Jaco Greeff 2020-03-20 07:04:40 +01:00 committed by GitHub
parent d381dd1b4d
commit ac8ee10120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 98 additions and 120 deletions

View File

@ -8,10 +8,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^1.8.0-beta.1",
"@polkadot/api-contract": "^1.8.0-beta.1",
"@polkadot/api": "^1.8.0-beta.3",
"@polkadot/api-contract": "^1.8.0-beta.3",
"@polkadot/keyring": "^2.6.2",
"@polkadot/types": "^1.8.0-beta.1",
"@polkadot/types": "^1.8.0-beta.3",
"@polkadot/util": "^2.6.2",
"@polkadot/util-crypto": "^2.6.2",
"babel-core": "^7.0.0-bridge.0",

View File

@ -12,6 +12,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.8.7",
"@polkadot/api-contract": "^1.8.0-beta.1"
"@polkadot/api-contract": "^1.8.0-beta.3"
}
}

View File

@ -2,15 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { ParamDef, RawParam } from '@polkadot/react-params/types';
import { I18nProps } from '@polkadot/react-components/types';
import { QueueTxRpcAdd } from '@polkadot/react-components/Status/types';
import { DefinitionRpcExt } from '@polkadot/types/types';
import React from 'react';
import rpc from '@polkadot/jsonrpc';
import { Button, InputRpc, TxComponent } from '@polkadot/react-components';
import Params from '@polkadot/react-params';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import { getTypeDef } from '@polkadot/types';
import { isNull } from '@polkadot/util';
@ -23,11 +23,11 @@ interface Props extends I18nProps {
interface State {
isValid: boolean;
accountId?: string | null;
rpc: RpcMethod;
rpc: DefinitionRpcExt;
values: RawParam[];
}
const defaultMethod = rpc.author.methods.submitExtrinsic;
const defaultMethod = jsonrpc.author.submitExtrinsic;
class Selection extends TxComponent<Props, State> {
public state: State = {
@ -91,7 +91,7 @@ class Selection extends TxComponent<Props, State> {
);
}
private onChangeMethod = (rpc: RpcMethod): void => {
private onChangeMethod = (rpc: DefinitionRpcExt): void => {
this.nextState({
rpc,
values: [] as RawParam[]

View File

@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.8.7",
"@polkadot/api": "^1.8.0-beta.1",
"@polkadot/api": "^1.8.0-beta.3",
"@polkadot/extension-dapp": "^0.23.0-beta.4",
"rxjs-compat": "^6.5.4"
}

View File

@ -2,27 +2,27 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { DefinitionRpcExt } from '@polkadot/types/types';
import { DropdownOptions } from '../util/types';
import { BareProps } from '../types';
import React from 'react';
import map from '@polkadot/jsonrpc';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props extends BareProps {
isError?: boolean;
onChange: (value: RpcMethod) => void;
onChange: (value: DefinitionRpcExt) => void;
options: DropdownOptions;
value: RpcMethod;
value: DefinitionRpcExt;
}
function transform ({ value }: Props): (method: string) => RpcMethod {
return function (method: string): RpcMethod {
return map[value.section].methods[method];
function transform ({ value: { section } }: Props): (method: string) => DefinitionRpcExt {
return function (method: string): DefinitionRpcExt {
return jsonrpc[section][method];
};
}

View File

@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { DefinitionRpcExt } from '@polkadot/types/types';
import { DropdownOptions } from '../util/types';
import { BareProps } from '../types';
@ -16,7 +16,7 @@ interface Props extends BareProps {
isError?: boolean;
onChange: (value: string) => void;
options: DropdownOptions;
value: RpcMethod;
value: DefinitionRpcExt;
}
function SelectSection ({ className, defaultValue, isError, onChange, options, style, value }: Props): React.ReactElement<Props> {
return (

View File

@ -4,12 +4,12 @@
// TODO: We have a lot shared between this and InputExtrinsic & InputStorage
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { DefinitionRpcExt } from '@polkadot/types/types';
import { DropdownOptions } from '../util/types';
import React, { useState } from 'react';
import map from '@polkadot/jsonrpc';
import { useApi } from '@polkadot/react-hooks';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import LinkedWrapper from '../InputExtrinsic/LinkedWrapper';
import SelectMethod from './SelectMethod';
@ -19,11 +19,11 @@ import sectionOptions from './options/section';
interface Props {
className?: string;
defaultValue: RpcMethod;
defaultValue: DefinitionRpcExt;
help?: React.ReactNode;
isError?: boolean;
label: React.ReactNode;
onChange?: (value: RpcMethod) => void;
onChange?: (value: DefinitionRpcExt) => void;
style?: any;
withLabel?: boolean;
}
@ -32,15 +32,15 @@ function InputRpc ({ className, defaultValue, help, label, onChange, style, with
const { api } = useApi();
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(methodOptions(api, defaultValue.section));
const [optionsSection] = useState<DropdownOptions>(sectionOptions(api));
const [value, setValue] = useState<RpcMethod>((): RpcMethod => defaultValue);
const [value, setValue] = useState<DefinitionRpcExt>((): DefinitionRpcExt => defaultValue);
const _onMethodChange = (newValue: RpcMethod): void => {
const _onMethodChange = (newValue: DefinitionRpcExt): void => {
if (value.section === newValue.section && value.method === newValue.method) {
return;
}
// set via callback since the method is a function itself
setValue((): RpcMethod => newValue);
setValue((): DefinitionRpcExt => newValue);
onChange && onChange(newValue);
};
const _onSectionChange = (section: string): void => {
@ -51,7 +51,7 @@ function InputRpc ({ className, defaultValue, help, label, onChange, style, with
const optionsMethod = methodOptions(api, section);
setOptionsMethod(optionsMethod);
_onMethodChange(map[section].methods[optionsMethod[0].value]);
_onMethodChange(jsonrpc[section][optionsMethod[0].value]);
};
return (

View File

@ -2,14 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { DefinitionRpcExt } from '@polkadot/types/types';
import { DropdownOption, DropdownOptions } from '../../util/types';
import React from 'react';
import ApiPromise from '@polkadot/api/promise';
import map from '@polkadot/jsonrpc';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
export default function createOptions (api: ApiPromise, sectionName: string): DropdownOptions {
const section = map[sectionName];
const section = jsonrpc[sectionName];
if (!section || Object.keys((api.rpc as any)[sectionName]).length === 0) {
return [];
@ -18,33 +19,30 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr
return Object
.keys((api.rpc as any)[sectionName])
.sort()
.filter((value): boolean => {
const { isDeprecated, isHidden, isSubscription } = section.methods[value];
return !isDeprecated && !isHidden && !isSubscription;
})
.map((value): DropdownOption => {
const { description, params } = section.methods[value];
.map((methodName) => section[methodName])
.filter((ext): ext is DefinitionRpcExt => !!ext)
.filter(({ isSubscription }): boolean => !isSubscription)
.map(({ description, method, params }): DropdownOption => {
const inputs = params.map(({ name }): string => name).join(', ');
return {
className: 'ui--DropdownLinked-Item',
key: `${sectionName}_${value}`,
key: `${sectionName}_${method}`,
text: [
<div
className='ui--DropdownLinked-Item-call'
key={`${sectionName}_${value}:call`}
key={`${sectionName}_${method}:call`}
>
{value}({inputs})
{method}({inputs})
</div>,
<div
className='ui--DropdownLinked-Item-text'
key={`${sectionName}_${value}:text`}
key={`${sectionName}_${method}:text`}
>
{description || value}
{description || method}
</div>
],
value
value: method
};
});
}

View File

@ -11,7 +11,7 @@ import { ActionStatus, PartialQueueTxExtrinsic, PartialQueueTxRpc, QueueStatus,
import React, { useRef, useState } from 'react';
import { SubmittableResult } from '@polkadot/api';
import { registry } from '@polkadot/react-api';
import jsonrpc from '@polkadot/jsonrpc';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import { createType } from '@polkadot/types';
import { QueueProvider } from './Context';
@ -24,7 +24,7 @@ export interface Props extends BareProps {
let nextId = 0;
const REMOVE_TIMEOUT = 7500;
const SUBMIT_RPC = jsonrpc.author.methods.submitAndWatchExtrinsic;
const SUBMIT_RPC = jsonrpc.author.submitAndWatchExtrinsic;
function Queue ({ children }: Props): React.ReactElement<Props> {
const [_stqueue, _setStQueue] = useState<QueueStatus[]>([]);

View File

@ -5,9 +5,8 @@
import { SubmittableResult } from '@polkadot/api';
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { SignerResult } from '@polkadot/api/types';
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { AccountId, Address } from '@polkadot/types/interfaces';
import { SignerPayloadJSON } from '@polkadot/types/types';
import { DefinitionRpcExt, SignerPayloadJSON } from '@polkadot/types/types';
export type Actions = 'create' | 'edit' | 'restore' | 'forget' | 'backup' | 'changePassword' | 'transfer';
@ -38,7 +37,7 @@ export interface QueueTx extends AccountInfo {
payload?: SignerPayloadJSON;
result?: any;
removeItem: () => void;
rpc: RpcMethod;
rpc: DefinitionRpcExt;
signerCb?: SignerCallback;
txFailedCb?: TxFailedCallback;
txSuccessCb?: TxCallback;
@ -65,7 +64,7 @@ export interface QueueTxExtrinsic extends AccountInfo {
}
export interface QueueTxRpc extends AccountInfo {
rpc: RpcMethod;
rpc: DefinitionRpcExt;
values: any[];
}
@ -85,7 +84,7 @@ export interface PartialQueueTxExtrinsic extends PartialAccountInfo {
}
export interface PartialQueueTxRpc extends PartialAccountInfo {
rpc: RpcMethod;
rpc: DefinitionRpcExt;
values: any[];
}

View File

@ -6,16 +6,10 @@ import { SignerOptions, SignerResult, Signer as ApiSigner } from '@polkadot/api/
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps, BareProps } from '@polkadot/react-components/types';
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { KeyringPair } from '@polkadot/keyring/types';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import {
QueueTx,
QueueTxMessageSetStatus,
QueueTxResult,
QueueTxStatus
} from '@polkadot/react-components/Status/types';
import { SignerPayloadJSON } from '@polkadot/types/types';
import { QueueTx, QueueTxMessageSetStatus, QueueTxResult, QueueTxStatus } from '@polkadot/react-components/Status/types';
import { DefinitionRpcExt, SignerPayloadJSON } from '@polkadot/types/types';
import BN from 'bn.js';
import React from 'react';
@ -573,7 +567,7 @@ class Signer extends React.PureComponent<Props, State> {
: this.makeSignedTransaction(submittable, queueTx, keyring.getPair(accountId as string));
}
private async submitRpc ({ method, section }: RpcMethod, values: any[]): Promise<QueueTxResult> {
private async submitRpc ({ method, section }: DefinitionRpcExt, values: any[]): Promise<QueueTxResult> {
const { api } = this.props;
try {

111
yarn.lock
View File

@ -2765,56 +2765,56 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/api-contract@npm:^1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/api-contract@npm:1.8.0-beta.1"
"@polkadot/api-contract@npm:^1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/api-contract@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/api": 1.8.0-beta.1
"@polkadot/rpc-core": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.1
"@polkadot/api": 1.8.0-beta.3
"@polkadot/rpc-core": 1.8.0-beta.3
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
bn.js: ^5.1.1
rxjs: ^6.5.4
checksum: 2/6ac8d51940fecfb7eb442818f20457c4ec802d321af1044f715117a7665b32a2015a5fe13ffc9ae6f7a0d8bcc2bdfed2a0201a5fd427d4165f9aecddccbe4522
checksum: 2/3331b5350866a9139601e1cef14b77198b575bf73e0f7053488d6544f45341eb7a7f31d451855d54e92507b71c00a9f6c7fa70b704785c1f319e37d60d36bc48
languageName: node
linkType: hard
"@polkadot/api-derive@npm:1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/api-derive@npm:1.8.0-beta.1"
"@polkadot/api-derive@npm:1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/api-derive@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/api": 1.8.0-beta.1
"@polkadot/rpc-core": 1.8.0-beta.1
"@polkadot/rpc-provider": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.1
"@polkadot/api": 1.8.0-beta.3
"@polkadot/rpc-core": 1.8.0-beta.3
"@polkadot/rpc-provider": 1.8.0-beta.3
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
"@polkadot/util-crypto": ^2.6.2
bn.js: ^5.1.1
memoizee: ^0.4.14
rxjs: ^6.5.4
checksum: 2/412cec10a61361a7307587f380b2f57f3b71bbbe396cbda91b47e1b434dce07c9936d2b7b9acaafa2e4d8b18c2180aa45eecf2768c7d3565b81d90765cea4b14
checksum: 2/e65131d8ae5d94e5e437249c125552c4c21931c935121c6efff76740ada0ae7b038574d3856701b5f153d4d5de2125d961a9e53c3764efed8fe2d03f59cdae93
languageName: node
linkType: hard
"@polkadot/api@npm:^1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/api@npm:1.8.0-beta.1"
"@polkadot/api@npm:^1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/api@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/api-derive": 1.8.0-beta.1
"@polkadot/api-derive": 1.8.0-beta.3
"@polkadot/keyring": ^2.6.2
"@polkadot/metadata": 1.8.0-beta.1
"@polkadot/rpc-core": 1.8.0-beta.1
"@polkadot/rpc-provider": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.3
"@polkadot/rpc-core": 1.8.0-beta.3
"@polkadot/rpc-provider": 1.8.0-beta.3
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
"@polkadot/util-crypto": ^2.6.2
bn.js: ^5.1.1
eventemitter3: ^4.0.0
rxjs: ^6.5.4
checksum: 2/5fbe12d4f3370f55fb6313d759077730f068f74e5af6cd21119dc1f2bcd1fb9877ebfb993929cefa0e5231e8f16593363a412dd43ac1806d5d65204b88045ab7
checksum: 2/b743ad5b715fa46081744b900eb369a260582108921efd2502bb031695e7e5017177475df6b04955641e92be85e9ff5463ac4f39c5576387c298f51106a65a3b
languageName: node
linkType: hard
@ -2864,7 +2864,7 @@ __metadata:
resolution: "@polkadot/app-contracts@workspace:packages/page-contracts"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/api-contract": ^1.8.0-beta.1
"@polkadot/api-contract": ^1.8.0-beta.3
languageName: unknown
linkType: soft
@ -3186,17 +3186,6 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/jsonrpc@npm:1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/jsonrpc@npm:1.8.0-beta.1"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/types": 1.8.0-beta.1
"@polkadot/util": ^2.6.2
checksum: 2/d90c470fe309d7c9ed84feac047aa942facb68cea6e07c266d6322b7c2951ef7f193a6e21ee47b6067c5fe1f089a01ec31f17f3d11875d32b3ce9a8f303ecf2e
languageName: node
linkType: hard
"@polkadot/keyring@npm:^2.6.2":
version: 2.6.2
resolution: "@polkadot/keyring@npm:2.6.2"
@ -3208,16 +3197,16 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/metadata@npm:1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/metadata@npm:1.8.0-beta.1"
"@polkadot/metadata@npm:1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/metadata@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/types": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
"@polkadot/util-crypto": ^2.6.2
bn.js: ^5.1.1
checksum: 2/500188956412a9a4bb501c7965a7e2d89a1f0ef167e4fad766afa669d7f7bc30ea306b453ccb04d3a37a2c3826e7affed6737246191be353dc82af14c860ef91
checksum: 2/2ea61f5dc21907ed46e51d8fd85ba3e63e4b0cad4b24bdbb8c1ebdcf56bc8964b1ae4e25d591b90bc9b66bb3686321294d5adb4044b3f837da9ced08804bd3f9
languageName: node
linkType: hard
@ -3226,7 +3215,7 @@ __metadata:
resolution: "@polkadot/react-api@workspace:packages/react-api"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/api": ^1.8.0-beta.1
"@polkadot/api": ^1.8.0-beta.3
"@polkadot/extension-dapp": ^0.23.0-beta.4
rxjs-compat: ^6.5.4
languageName: unknown
@ -3343,37 +3332,35 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/rpc-core@npm:1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/rpc-core@npm:1.8.0-beta.1"
"@polkadot/rpc-core@npm:1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/rpc-core@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/jsonrpc": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.1
"@polkadot/rpc-provider": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.3
"@polkadot/rpc-provider": 1.8.0-beta.3
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
memoizee: ^0.4.14
rxjs: ^6.5.4
checksum: 2/a31090da8ba9038c887f9810c6ae7fe9ccf676cb600a0dd147f38b0eaabd6cda3c74c5fccd7e068a422db536298c6fde842232aa0d32cee3715c0ec9bf9040b7
checksum: 2/4366bb4b96822569ca941a1fd33668f0c425495adb9a08758072e7edd773aceb3e754fe0548ea56f342d2813a21364bb44d694bcc6559285159516cb840b5b87
languageName: node
linkType: hard
"@polkadot/rpc-provider@npm:1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/rpc-provider@npm:1.8.0-beta.1"
"@polkadot/rpc-provider@npm:1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/rpc-provider@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/jsonrpc": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.1
"@polkadot/types": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.3
"@polkadot/types": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
"@polkadot/util-crypto": ^2.6.2
bn.js: ^5.1.1
eventemitter3: ^4.0.0
isomorphic-fetch: ^2.2.1
websocket: ^1.0.31
checksum: 2/4cde3d317165b858940f85400a422d8dbddbf120a5e2abf9c4743cc02c27d1cabc7d586aeb4cde916e9ff29201d55299dcddc0938d5d1d5c32d20f94186265ae
checksum: 2/c98e622093252643dbb000373acfc7f1a543e08f1fafebc86ea24ffeedaefc8f4da87e637b92e1154717c62888e4176ffc773b582c95b9974971d21a91e3a2dc
languageName: node
linkType: hard
@ -3386,19 +3373,19 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/types@npm:^1.8.0-beta.1":
version: 1.8.0-beta.1
resolution: "@polkadot/types@npm:1.8.0-beta.1"
"@polkadot/types@npm:^1.8.0-beta.3":
version: 1.8.0-beta.3
resolution: "@polkadot/types@npm:1.8.0-beta.3"
dependencies:
"@babel/runtime": ^7.8.7
"@polkadot/metadata": 1.8.0-beta.1
"@polkadot/metadata": 1.8.0-beta.3
"@polkadot/util": ^2.6.2
"@polkadot/util-crypto": ^2.6.2
"@types/bn.js": ^4.11.6
bn.js: ^5.1.1
memoizee: ^0.4.14
rxjs: ^6.5.4
checksum: 2/8981486067568e45e10b62737dde9197f66724db9395e2142cef7c470ead4c515a480b9aa834c494273b5460856a3c706dc9843023f9f5d3f3688bca61bbcdd8
checksum: 2/2e1744345ae1e2b46f20f6706e02ecb2a67dddf129f8da0c71a10236f7822a55d7e934126a4fce46bf5203e232ffe09e7266d0caa30c0d87fed29e97a695b3c9
languageName: node
linkType: hard