Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial branch with api-types replaced in types #186

Merged
merged 10 commits into from
Oct 22, 2020
2 changes: 1 addition & 1 deletion jest/initApiRx.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {WsProvider} from '@polkadot/api';
import config from '../config';
import {ApiRx} from '../packages/api/src/ApiRx';
import { TypeRegistry } from '@cennznet/types';
import { TypeRegistry } from '@polkadot/types';
KarishmaBothara marked this conversation as resolved.
Show resolved Hide resolved

const initApiRx = async () => {
const providerUrl = config.wsProvider[`${process.env.TEST_TYPE}`] || 'ws://localhost:9944';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"resolutions": {
"babel-core": "^7.0.0-bridge.0",
"typescript": "^3.7.2",
"typescript": "^4.0.2",
"braces": "^2.3.2",
"fstream": "^1.0.12",
"handlebars": "^4.5.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
},
"dependencies": {
"@cennznet/types": "^1.2.1",
"@polkadot/api": "^1.1.1",
"@polkadot/metadata": "1.1.1",
"@polkadot/rpc-core": "^1.1.1",
"@polkadot/rpc-provider": "^1.1.1",
"@polkadot/types": "^1.1.1",
"@polkadot/api": "2.1.2-2",
"@polkadot/metadata": "2.1.2-2",
"@polkadot/rpc-core": "2.1.2-2",
"@polkadot/rpc-provider": "2.1.2-2",
"@polkadot/types": "2.1.2-2",
"eventemitter3": "^4.0.0"
},
"resolution": {
Expand Down
26 changes: 14 additions & 12 deletions packages/api/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Types from '@cennznet/types/injects';
// import Types from '@cennznet/types/injects';
import Types from '@cennznet/types/interfaces/injects';
import { ApiPromise } from '@polkadot/api';
import { ApiOptions as ApiOptionsBase } from '@polkadot/api/types';
import { ApiOptions as ApiOptionsBase, ApiTypes, SubmittableExtrinsics } from '@polkadot/api/types';

import derives from './derives';
import rpc from './rpc';
// import derives from './derives';
// import rpc from './rpc';
import staticMetadata from './staticMetadata';
import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
// import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
import { ApiOptions } from './types';
import { mergeDeriveOptions } from './util/derives';
import { getProvider } from './util/getProvider';
import { getTimeout } from './util/getTimeout';
Expand All @@ -40,11 +42,11 @@ export class Api extends ApiPromise {

api.isReady.then(res => {
// Remove error listener if API initialization success.
(api as any)._eventemitter.removeListener('error', rejectError);
// (api as any).emitter.removeListener('error', rejectError);
KarishmaBothara marked this conversation as resolved.
Show resolved Hide resolved
resolve((res as unknown) as Api);
}, reject);

api.once('error', rejectError);
// api.once('error', rejectError);
}),
getTimeout(options)
);
Expand All @@ -54,9 +56,9 @@ export class Api extends ApiPromise {
return super.tx as SubmittableExtrinsics<'promise'>;
}

get derive(): Derives<'promise'> {
return super.derive as Derives<'promise'>;
}
// get derive(): Derives<'promise'> {
// return super.derive as Derives<'promise'>;
// }

constructor(_options: ApiOptions = {}) {
const options = { ..._options };
Expand All @@ -66,8 +68,8 @@ export class Api extends ApiPromise {
}
options.metadata = Object.assign(staticMetadata, options.metadata);
options.types = { ...options.types, ...Types };
options.derives = mergeDeriveOptions(derives, options.derives);
options.rpc = { ...(rpc as any), ...options.rpc };
// options.derives = mergeDeriveOptions(derives, options.derives);
// options.rpc = { ...(rpc as any), ...options.rpc };

super(options as ApiOptionsBase);
}
Expand Down
22 changes: 12 additions & 10 deletions packages/api/src/ApiRx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
// limitations under the License.

import { mergeDeriveOptions } from '@cennznet/api/util/derives';
import Types from '@cennznet/types/injects';
// import Types from '@cennznet/types/injects';
import Types from '@cennznet/types/interfaces/injects';
import { ApiRx as ApiRxBase } from '@polkadot/api';
import { ApiOptions as ApiOptionsBase } from '@polkadot/api/types';
import { ApiOptions as ApiOptionsBase, SubmittableExtrinsics } from '@polkadot/api/types';
import { fromEvent, Observable, race, throwError } from 'rxjs';
import { switchMap, timeout } from 'rxjs/operators';

import rpc from '@cennznet/api/rpc';
// import rpc from '@cennznet/api/rpc';
import { DEFAULT_TIMEOUT } from './Api';
import derives from './derives';
// import derives from './derives';
import staticMetadata from './staticMetadata';
import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
// import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
import { ApiOptions } from './types';
import { getProvider } from './util/getProvider';
import { getTimeout } from './util/getTimeout';

Expand Down Expand Up @@ -53,9 +55,9 @@ export class ApiRx extends ApiRxBase {
return super.tx as SubmittableExtrinsics<'rxjs'>;
}

get derive(): Derives<'rxjs'> {
return super.derive as Derives<'rxjs'>;
}
// get derive(): Derives<'rxjs'> {
// return super.derive as Derives<'rxjs'>;
// }

constructor(_options: ApiOptions = {}) {
const options = { ..._options };
Expand All @@ -64,8 +66,8 @@ export class ApiRx extends ApiRxBase {
}
options.metadata = Object.assign(staticMetadata, options.metadata);
options.types = { ...options.types, ...Types };
options.derives = mergeDeriveOptions(derives as any, options.derives);
options.rpc = { ...(rpc as any), ...options.rpc };
// options.derives = mergeDeriveOptions(derives as any, options.derives);
// options.rpc = { ...(rpc as any), ...options.rpc };

super(options as ApiOptionsBase);
}
Expand Down
Loading