@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
27 lines • 1.14 kB
JavaScript
import { Subject, merge, throwError, interval, concat, of } from "rxjs";
import { mergeMap, take, map, ignoreElements } from "rxjs/operators";
export const socketErrorSubject = new Subject();
export const withSocketErrors = (observable) => merge(observable, socketErrorSubject.pipe(mergeMap(e => throwError(() => e))));
const pause = ms => interval(ms).pipe(take(1), ignoreElements());
export const secureChannelMock = (managerGranted = false) => !managerGranted
? concat(pause(500), of({
type: "device-permission-requested",
}), pause(500), of({
type: "device-permission-granted",
}), pause(500))
: pause(1000);
export const bulkSocketMock = (duration = 1000) => {
const total = Math.floor((duration - 100) / 100);
return interval(100).pipe(take(total + 1), map(index => ({
type: "bulk-progress",
progress: index / total,
index,
total,
})));
};
export const resultMock = (payload) => of({
type: "result",
payload,
});
export const createMockSocket = (...observables) => withSocketErrors(concat(...observables));
//# sourceMappingURL=socket.mock.js.map