Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ it('should fire an event when polling pubsub publishes', done => {
});
});

it('should fire an event when polling pubsub publishes, with object', done => {
setApi(resolveApi({ result: 'foo' }, false));
createPubsubObservable('fake_method').subscribe(data => {
expect(data).toBe('foo');
done();
});
});

it('should fire an error when polling pubsub errors', done => {
setApi(rejectApi(new Error('bar'), false));
createPubsubObservable('fake_method').subscribe(null, err => {
Expand Down
12 changes: 11 additions & 1 deletion packages/light.js/src/frequency/utils/createPubsubObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ const createPubsubObservableWithApi = memoizee(
);

return timer(0, 1000).pipe(
switchMap(() => api[namespace][method]())
switchMap(() =>
api[namespace][method]().then((response: any) => {
// For responses by MetaMask, the object is not parsed by
// `@parity/api`. We parse it manually here.
// TODO Put this logic in `@parity/api`
if (typeof response === 'object' && response.result !== undefined) {
return response.result;
}
return response;
})
)
) as Observable<T>;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/light.js/src/utils/testHelpers/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const listOfMockRps: { [index: string]: string[] } = {
* @ignore
*/
const createApi = (
resolveWith: string | { error: string } | Error,
resolveWith: string | object | { error: string } | Error,
isPubSub: boolean,
isError: boolean
) => {
Expand Down Expand Up @@ -111,6 +111,6 @@ export const rejectApi = (
* @ignore
*/
export const resolveApi = (
resolveWith: string | { error: string } = 'foo',
resolveWith: string | object | { error: string } = 'foo',
isPubsub: boolean = true
) => createApi(resolveWith, isPubsub, false);