Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.
Prev Previous commit
Next Next commit
Fix ts in light.js
  • Loading branch information
amaury1093 committed Nov 22, 2018
commit ddafdf6fe20533e9fdd5b6bd94803950bdc00df3
4 changes: 2 additions & 2 deletions packages/light.js/src/frequency/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import createPubsubObservable from './utils/createPubsubObservable';
*
* @param options - Options to pass to {@link FrequencyObservable}.
*/
export function onAccountsChanged$(options?: FrequencyObservableOptions) {
export function onAccountsChanged$ (options?: FrequencyObservableOptions) {
return createPubsubObservable<Address[]>('eth_accounts', options);
}

Expand All @@ -20,6 +20,6 @@ export function onAccountsChanged$(options?: FrequencyObservableOptions) {
*
* @param options - Options to pass to {@link FrequencyObservable}.
*/
export function onAccountsInfoChanged$(options?: FrequencyObservableOptions) {
export function onAccountsInfoChanged$ (options?: FrequencyObservableOptions) {
return createPubsubObservable<AccountsInfo>('parity_accountsInfo', options);
}
4 changes: 2 additions & 2 deletions packages/light.js/src/frequency/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { onSyncingChanged$ } from './health';
* @ignore
*/
const onEveryBlockWithApi$ = memoizee(
(api: any, options: FrequencyObservableOptions) =>
(api: any, options?: FrequencyObservableOptions) =>
createPubsubObservable('eth_blockNumber', options).pipe(
withLatestFrom(onSyncingChanged$(options)),
filter(([_, isSyncing]) => isSyncing === false),
Expand All @@ -34,7 +34,7 @@ const onEveryBlockWithApi$ = memoizee(
*
* @param options - Options to pass to {@link FrequencyObservable}.
*/
export function onEveryBlock$(options?: FrequencyObservableOptions) {
export function onEveryBlock$ (options?: FrequencyObservableOptions) {
const api =
options && options.provider
? createApiFromProvider(options.provider)
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/frequency/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import { FrequencyObservableOptions } from '../types';
*
* @param options - Options to pass to {@link FrequencyObservable}.
*/
export function onSyncingChanged$(options?: FrequencyObservableOptions) {
export function onSyncingChanged$ (options?: FrequencyObservableOptions) {
return createPubsubObservable<object | false>('eth_syncing', options);
}
2 changes: 1 addition & 1 deletion packages/light.js/src/frequency/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FrequencyObservableOptions } from '../types';
*
* @param options - Options to pass to {@link FrequencyObservable}.
*/
function onStartup$(options?: FrequencyObservableOptions) {
function onStartup$ (options?: FrequencyObservableOptions) {
return of(0);
}
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions packages/light.js/src/frequency/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FrequencyObservableOptions } from '../types';
/**
* Observable that emits on every second.
*/
function onEverySecond$(options?: FrequencyObservableOptions) {
function onEverySecond$ (options?: FrequencyObservableOptions) {
return timer(0, 1000);
}
// @ts-ignore
Expand All @@ -20,7 +20,7 @@ onEverySecond$ = memoizee(onEverySecond$);
/**
* Observable that emits on every other second.
*/
function onEvery2Seconds$(options?: FrequencyObservableOptions) {
function onEvery2Seconds$ (options?: FrequencyObservableOptions) {
return timer(0, 2000);
}
// @ts-ignore
Expand All @@ -29,7 +29,7 @@ onEvery2Seconds$ = memoizee(onEvery2Seconds$);
/**
* Observable that emits every five seconds.
*/
function onEvery5Seconds$(options?: FrequencyObservableOptions) {
function onEvery5Seconds$ (options?: FrequencyObservableOptions) {
return timer(0, 5000);
}
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('should fire an event when pubsub publishes', done => {

it('should fire an error when pubsub errors', done => {
setApi(rejectApi());
createPubsubObservable('fake_method').subscribe(null, err => {
createPubsubObservable('fake_method').subscribe(undefined, err => {
expect(err).toEqual(new Error('bar'));
done();
});
Expand All @@ -47,7 +47,7 @@ it('should fire an event when polling pubsub publishes, with object', done => {

it('should fire an error when polling pubsub errors', done => {
setApi(rejectApi(new Error('bar'), false));
createPubsubObservable('fake_method').subscribe(null, err => {
createPubsubObservable('fake_method').subscribe(undefined, err => {
expect(err).toEqual(new Error('bar'));
done();
});
Expand Down
12 changes: 6 additions & 6 deletions packages/light.js/src/rpc/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { switchMapPromise } from '../utils/operators';
* @param options - Options to pass to {@link RpcObservableOptions}.
* @return - An Observable containing the list of public addresses.
*/
export function accounts$(options?: RpcObservableOptions) {
export function accounts$ (options?: RpcObservableOptions) {
return createRpc$<Address[], Address[]>({
frequency: [frequency.onAccountsChanged$],
name: 'accounts$'
Expand All @@ -36,7 +36,7 @@ export function accounts$(options?: RpcObservableOptions) {
* @param options - Options to pass to {@link RpcObservableOptions}.
* @return - An Observable containing the balance.
*/
export function balanceOf$(address: Address, options?: RpcObservableOptions) {
export function balanceOf$ (address: Address, options?: RpcObservableOptions) {
return createRpc$<any, BigNumber | Symbol>({
calls: ['eth_getBalance'],
frequency: [frequency.onEveryBlock$, frequency.onStartup$],
Expand All @@ -52,7 +52,7 @@ export function balanceOf$(address: Address, options?: RpcObservableOptions) {
* @return - An Observable containing the public address
* of the default account.
*/
export function defaultAccount$(options?: RpcObservableOptions) {
export function defaultAccount$ (options?: RpcObservableOptions) {
return createRpc$<Address[], Address>({
dependsOn: accounts$,
name: 'defaultAccount$',
Expand All @@ -65,7 +65,7 @@ export function defaultAccount$(options?: RpcObservableOptions) {
*
* @return {Observable<Number>} - An Observable containing the block height.
*/
export function blockNumber$(options?: RpcObservableOptions) {
export function blockNumber$ (options?: RpcObservableOptions) {
return createRpc$<BigNumber, BigNumber>({
frequency: [frequency.onEveryBlock$],
name: 'blockNumber$'
Expand All @@ -75,7 +75,7 @@ export function blockNumber$(options?: RpcObservableOptions) {
/**
* Shorthand for fetching the current account's balance.
*/
export function myBalance$(options?: RpcObservableOptions) {
export function myBalance$ (options?: RpcObservableOptions) {
return createRpc$<Address, BigNumber | Symbol>({
calls: [`eth_getBalance`],
dependsOn: defaultAccount$,
Expand All @@ -96,7 +96,7 @@ export function myBalance$(options?: RpcObservableOptions) {
*
* @return - An Observable containing the syncing state object, or false.
*/
export function syncStatus$(options?: RpcObservableOptions) {
export function syncStatus$ (options?: RpcObservableOptions) {
return createRpc$<object | boolean, object | boolean>({
frequency: [frequency.onSyncingChanged$],
name: 'syncStatus$'
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/rpc/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { switchMapPromise } from '../utils/operators';
* @param options - Options to pass to {@link RpcObservableOptions}.
* @return - An Observable containing the number.
*/
export function peerCount$(options?: RpcObservableOptions) {
export function peerCount$ (options?: RpcObservableOptions) {
return createRpc$<number, BigNumber>({
calls: ['net_peerCount'],
frequency: [frequency.onEvery5Seconds$],
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/rpc/other/makeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const makeContractWithApi = memoizee(
const result: MakeContract = {
abi,
address,
get contractObject() {
get contractObject () {
return getContract(address, abiJson, api);
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/rpc/other/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface PostOptions extends RpcObservableOptions {
* @param options? - Options to pass to the {@link RpcObservable}.
* @return - The status of the transaction.
*/
export function post$(tx: Tx, options: PostOptions = {}) {
export function post$ (tx: Tx, options: PostOptions = {}) {
const { estimate, provider } = options;
const api = provider ? createApiFromProvider(provider) : getApi();

Expand Down
4 changes: 2 additions & 2 deletions packages/light.js/src/rpc/parity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { switchMapPromise } from '../utils/operators';
* @return - An Observable containing all info that can be
* accessed by user concerning accounts.
*/
export function accountsInfo$(options?: RpcObservableOptions) {
export function accountsInfo$ (options?: RpcObservableOptions) {
return createRpc$<AccountsInfo, AccountsInfo>({
frequency: [frequency.onAccountsInfoChanged$],
name: 'accountsInfo$'
Expand All @@ -29,7 +29,7 @@ export function accountsInfo$(options?: RpcObservableOptions) {
* @return - An Observable containing the name of the
* current chain.
*/
export function chainName$(options?: RpcObservableOptions) {
export function chainName$ (options?: RpcObservableOptions) {
return createRpc$<any, string>({
calls: ['parity_chain'],
frequency: [frequency.onStartup$],
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type RpcKey = keyof typeof rpc;
export interface RpcObservable<Source, Out> {
(...args: any[]): Observable<Out>;
metadata?: Metadata<Source, Out>;
setFrequency?(frequency: FrequencyObservable<Source>[]): void; // post$, makeContract... don't have setFrequency
setFrequency? (frequency: FrequencyObservable<Source>[]): void; // post$, makeContract... don't have setFrequency
}

export type RpcMap = { [index in RpcKey]: RpcObservable<any, any> };
Expand Down
4 changes: 2 additions & 2 deletions packages/light.js/src/utils/isLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const RPC_LOADING = Symbol('Fetching RPC...');
* @param {Any} value - The value to test.
* @return {Boolean} - Returns true if it's loading.
*/
export function isLoading(value: any) {
export function isLoading (value: any) {
return value === RPC_LOADING;
}

Expand All @@ -21,6 +21,6 @@ export function isLoading(value: any) {
* @param {Any} value - The value to test.
* @return {Boolean} - Returns true if it's `null, `undefined` or loading.
*/
export function isNullOrLoading(value: any) {
export function isNullOrLoading (value: any) {
return value == null || isLoading(value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { switchMapPromise } from './switchMapPromise';
it('should not error when the promise resolves with an error', done => {
mockRpc$()
.pipe(switchMapPromise(resolveApi({ error: 'bar' }).fake.method))
.subscribe(null, () => done.fail('It should not error.'));
.subscribe(undefined, () => done.fail('It should not error.'));

// If after 0.1s, nothing has been called, then our Observable has not fired
// any event, which is what we want
Expand All @@ -23,7 +23,7 @@ it('should not error when the promise resolves with an error', done => {
it('should not error when the promise rejects', done => {
mockRpc$()
.pipe(switchMapPromise(rejectApi().fake.method))
.subscribe(null, () => done.fail('It should not error.'));
.subscribe(undefined, () => done.fail('It should not error.'));

// If after 0.1s, nothing has been called, then our Observable has not fired
// any event, which is what we want
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/utils/operators/switchMapPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const switchMapPromise = <T>(promise: () => Promise<T>) => (
return Promise.resolve(result);
})
).pipe(
startWith(RPC_LOADING),
startWith(RPC_LOADING as any),
catchError(err => {
console.group();
console.error({ call: promise.toString(), err });
Expand Down
16 changes: 8 additions & 8 deletions packages/light.js/src/utils/testHelpers/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let providerCount = 0;
* @ignore
*/
export class MockProvider extends EventEmitter {
send() {
send () {
return Promise.resolve();
}
}
Expand Down Expand Up @@ -56,13 +56,13 @@ const createApi = (
listOfMockRps[namespace].forEach(method => {
apiObject.pubsub[namespace][method] = isError
? (callback: Function) => {
callback(resolveWith, null);
return Promise.resolve(1); // Resolves to subscriptionId
}
callback(resolveWith, null);
return Promise.resolve(1); // Resolves to subscriptionId
}
: (callback: Function) => {
callback(null, resolveWith);
return Promise.resolve(1); // Resolves to subscriptionId
};
callback(null, resolveWith);
return Promise.resolve(1); // Resolves to subscriptionId
};
});

// For eth.syncing pubsub, always return false
Expand All @@ -75,7 +75,7 @@ const createApi = (
},
{
isPubSub,
pollMethod() {
pollMethod () {
return isError
? Promise.reject(resolveWith)
: Promise.resolve(resolveWith);
Expand Down