Update Api, remove poc-1 compatibility (#318)

* Update Api, remove poc-1 compatibility

* Update deps
This commit is contained in:
Jaco Greeff 2018-09-18 10:31:48 +02:00 committed by GitHub
parent 9848ecbb65
commit 2aea3178bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 1261 additions and 223 deletions

View File

@ -29,8 +29,8 @@
"start": "cd packages/apps && webpack-serve --config webpack.config.js --port 3000"
},
"devDependencies": {
"@polkadot/dev-react": "^0.20.19",
"@polkadot/ts": "^0.1.27",
"@polkadot/dev-react": "^0.20.20",
"@polkadot/ts": "^0.1.29",
"autoprefixer": "^9.1.5",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/storage": "^0.28.35",
"@polkadot/storage": "^0.29.4",
"@polkadot/ui-react": "^0.20.10",
"@polkadot/ui-react-rx": "^0.20.10",
"@polkadot/util-keyring": "^0.30.3"

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/storage": "^0.28.35",
"@polkadot/storage": "^0.29.4",
"@polkadot/ui-react": "^0.20.10",
"@polkadot/ui-react-rx": "^0.20.10",
"@polkadot/util-keyring": "^0.30.3"

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/primitives": "^0.28.35",
"@polkadot/primitives": "^0.29.4",
"@polkadot/ui-app": "^0.20.10",
"@polkadot/util-crypto": "^0.30.3"
}

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/extrinsics": "^0.28.35",
"@polkadot/extrinsics": "^0.29.4",
"@polkadot/ui-app": "^0.20.10",
"@polkadot/ui-signer": "^0.20.10"
}

View File

@ -12,7 +12,7 @@
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/app-explorer": "^0.20.10",
"@polkadot/storage": "^0.28.35",
"@polkadot/storage": "^0.29.4",
"@polkadot/ui-app": "^0.20.10",
"@polkadot/ui-keyring": "^0.20.10",
"@polkadot/ui-react": "^0.20.10",

View File

@ -11,8 +11,8 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/extrinsics": "^0.28.35",
"@polkadot/storage": "^0.28.35",
"@polkadot/extrinsics": "^0.29.4",
"@polkadot/storage": "^0.29.4",
"@polkadot/ui-keyring": "^0.20.10",
"@polkadot/ui-react": "^0.20.10",
"@polkadot/ui-react-rx": "^0.20.10",

View File

@ -31,9 +31,9 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-react-rx#readme",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/api-rx": "^0.28.35",
"@polkadot/extrinsics": "^0.28.35",
"@polkadot/storage": "^0.28.35",
"@polkadot/api-rx": "^0.29.4",
"@polkadot/extrinsics": "^0.29.4",
"@polkadot/storage": "^0.29.4",
"rxjs-compat": "^6.3.2"
},
"devDependencies": {

View File

@ -4,15 +4,13 @@
import { ProviderInterface } from '@polkadot/api-provider/types';
import { RxApiInterface } from '@polkadot/api-rx/types';
import { EncodingVersions } from '@polkadot/params/types';
import { Header } from '@polkadot/primitives/header';
import { ApiProps } from '../types';
import React from 'react';
import shouldUseLatestChain from '@polkadot/ui-react-rx/util/shouldUseLatestChain';
import WsProvider from '@polkadot/api-provider/ws';
import createApi from '@polkadot/api-rx';
import RxApi from '@polkadot/api-rx';
import defaults from '@polkadot/api-rx/defaults';
import isUndefined from '@polkadot/util/is/undefined';
@ -30,10 +28,6 @@ type State = ApiProps & {
subscriptions: Array<any> // rxjs$ISubscription | null>;
};
function apiSupport (chain?: string): EncodingVersions {
return shouldUseLatestChain(chain) ? 'latest' : 'poc-1';
}
export default class Api extends React.PureComponent<Props, State> {
state: State = {} as State;
@ -41,7 +35,7 @@ export default class Api extends React.PureComponent<Props, State> {
super(props);
const { provider, url = '' } = props;
const api = props.api || createApi(
const api = props.api || new RxApi(
url && url.length
? new WsProvider(url)
: provider
@ -54,7 +48,7 @@ export default class Api extends React.PureComponent<Props, State> {
});
};
const setApiProvider = (provider?: ProviderInterface): void =>
setApi(createApi(provider));
setApi(new RxApi(provider));
const setApiWsUrl = (url: string = defaults.WS_URL): void =>
setApiProvider(new WsProvider(url));
@ -63,7 +57,7 @@ export default class Api extends React.PureComponent<Props, State> {
apiConnected: false,
apiMethods: {},
apiObservable: new ApiObservable(api),
apiSupport: 'poc-1',
apiSupport: 'latest',
setApi,
setApiProvider,
setApiWsUrl,
@ -87,7 +81,6 @@ export default class Api extends React.PureComponent<Props, State> {
subscriptions:
[
this.subscribeIsConnected,
this.subscribeChain,
this.subscribeMethodCheck
].map((fn: Function) => {
try {
@ -108,14 +101,6 @@ export default class Api extends React.PureComponent<Props, State> {
});
}
private subscribeChain = (api: RxApiInterface): void => {
api.system
.chain()
.subscribe((chain?: string) => {
this.setState({ apiSupport: apiSupport(chain) });
});
}
private subscribeMethodCheck = (api: RxApiInterface): void => {
api.chain
.newHead()

View File

@ -1,25 +0,0 @@
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import shouldUseLatestChain from './shouldUseLatestChain';
describe('check chain spec to configure encoding', () => {
it('enables PoC-1 encoding when chain specification is PoC-1 or undefined', () => {
let validChainSpecWithPoC1 = ['try poc-1 now', 'testing PoC-1 Testnet'];
const validChainSpecWithUndefinedOrNumber = [undefined];
for (let s of validChainSpecWithPoC1.concat(validChainSpecWithUndefinedOrNumber)) {
expect(shouldUseLatestChain(s)).toEqual(false);
}
});
it('enables Latest encoding when chain specification is NOT PoC-1 or undefined', () => {
const invalidChainSpecWithoutPoC1OrUndefined = ['poc-2', 'PoC-2 Testnet', 'staging',
'Staging Testnet', 'Local', 'Development', ' development', 'dev', 'Local', ' local ', 'loc', 0];
for (let s of invalidChainSpecWithoutPoC1OrUndefined) {
expect(shouldUseLatestChain(s)).toEqual(true);
}
});
});

View File

@ -1,17 +0,0 @@
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isUndefined from '@polkadot/util/is/undefined';
const re = new RegExp('(poc-1)', 'i');
export default function shouldUseLatestChain (chain?: string): boolean {
if (isUndefined(chain)) {
return false;
}
const match = re.test(chain.toString().toLowerCase());
return match ? false : true;
}

View File

@ -11,8 +11,7 @@ import decodeParams from '@polkadot/params/decode';
export default function storageTransform ({ type }: SectionItem<Storages>): StorageTransform {
return (input: Uint8Array = new Uint8Array(0), index: number): Param$Values | null => {
try {
// FIXME We don't do any conversion checks for the type, currently not an issue, but _could_ turn out to be problematic (since this is storage, apply no transforms)
return decodeParams(type, input, 'poc-1').value;
return decodeParams(type, input, 'latest', true).value;
} catch (error) {
console.error('Decoding', type, '::', error);
return null;

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/extrinsics": "^0.28.35",
"@polkadot/extrinsics": "^0.29.4",
"@polkadot/ui-app": "^0.20.10",
"@polkadot/ui-keyring": "^0.20.10"
},

View File

@ -17,9 +17,7 @@ export default function signMessage (publicKey: Uint8Array, nonce: BN | number,
const message = encodeCall(publicKey, nonce, value, apiSupport);
const signature = keyring.getPair(publicKey).sign(message);
const data = u8aConcat(
apiSupport === 'poc-1'
? new Uint8Array([])
: prefixes.publicKey,
prefixes.publicKey,
message,
signature
);
@ -30,10 +28,7 @@ export default function signMessage (publicKey: Uint8Array, nonce: BN | number,
return {
data: u8aConcat(
// TODO We append the length here, but it probably needs to be done in the actual formatter - however there are differences between different encodings, here the extrinsic requires a length, where some other 'Bytes' types do not
apiSupport === 'poc-1'
? new Uint8Array([])
: bnToU8a(data.length, 32, true),
bnToU8a(data.length, 32, true),
data
),
message,

1381
yarn.lock

File diff suppressed because it is too large Load Diff