From a22b714bb6aa077c5c92224364755c308e5fcb7d Mon Sep 17 00:00:00 2001 From: Yuri Volkov <0@mcornholio.ru> Date: Tue, 14 May 2024 15:29:18 +0200 Subject: [PATCH] Fixing "Invalid" error (#405) The source of the error was, that I treated the observables the wrong way. I expected `submitAndWatch()` to return a chain of events, to which I could subscribe from a bunch of sources, while it actually led to side effects being multiplied in the sources. `shareReplay()` returns a multicast observable that actually behaves the way I expected it to. --- src/dripper/polkadot/PolkadotActions.ts | 4 ++-- yarn.lock | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/dripper/polkadot/PolkadotActions.ts b/src/dripper/polkadot/PolkadotActions.ts index 3a6842a9..3d039468 100644 --- a/src/dripper/polkadot/PolkadotActions.ts +++ b/src/dripper/polkadot/PolkadotActions.ts @@ -1,6 +1,6 @@ import { ss58Address } from "@polkadot-labs/hdkd-helpers"; import { AccountId, Binary } from "polkadot-api"; -import { filter, firstValueFrom } from "rxjs"; +import { filter, firstValueFrom, shareReplay } from "rxjs"; import { config } from "src/config"; import { logger } from "src/logger"; @@ -101,7 +101,7 @@ export class PolkadotActions { // client.submit(tx) waits for the finalized value, which might be important for real money, // but for the faucet drips, early respond is better UX - const submit$ = client.submitAndWatch(tx); + const submit$ = client.submitAndWatch(tx).pipe(shareReplay(1)); const hash = (await firstValueFrom(submit$.pipe(filter((value) => value.type === "broadcasted")))).txHash; diff --git a/yarn.lock b/yarn.lock index 26535fe7..cb731086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2342,13 +2342,6 @@ bl@^4.0.3: inherits "^2.0.4" readable-stream "^3.4.0" -blake2@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/blake2/-/blake2-5.0.0.tgz#6306e49d974fb051b6fb2aad669307b9838bfbaa" - integrity sha512-MLpq1DwBB9rC0IHuRc2gXLEAeNNTTYHEtvYCA5lK4RmoUPRmQLSLQrwgJvou62BvH9KP7whe8n+xxw45++fnYg== - dependencies: - nan "^2.17.0" - body-parser@1.20.2, body-parser@^1.20.0: version "1.20.2" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.2.tgz#6feb0e21c4724d06de7ff38da36dad4f57a747fd"