feat: upgrade to substrate-connect v0.8.4 (#5776)

* feat: upgrade to substrate-connect v0.8.4

* feat(rpc-provider): re-write addChain for @substrate/connect

* fix: linting
This commit is contained in:
Matias Volpe
2024-01-26 15:11:58 +01:00
committed by GitHub
parent de30dd5bfe
commit bc3f066c3b
4 changed files with 141 additions and 20 deletions
@@ -6,7 +6,7 @@
import type * as Sc from '@substrate/connect';
import type { HealthChecker, SmoldotHealth } from './types.js';
import { stringify } from '@polkadot/util';
import { noop, stringify } from '@polkadot/util';
import { ScProvider } from './index.js';
@@ -107,6 +107,8 @@ function getFakeChain (spec: string, callback: Sc.JsonRpcCallback): MockChain {
: stringify(response)
);
},
addChain: (chainSpec, jsonRpcCallback) =>
Promise.resolve(getFakeChain(chainSpec, jsonRpcCallback ?? noop)),
remove: () => {
terminateInterceptor();
_isTerminated = true;
@@ -154,9 +154,17 @@ export class ScProvider implements ProviderInterface {
callback?.(decodedResponse);
};
const addChain = this.#wellKnownChains.has(this.#spec as ScType.WellKnownChain)
? client.addWellKnownChain
: client.addChain;
const addChain = this.#sharedSandbox
? (async (...args) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const source = this.#sharedSandbox!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return (await source.#chain)!.addChain(...args);
}) as ScType.AddChain
: this.#wellKnownChains.has(this.#spec as ScType.WellKnownChain)
? client.addWellKnownChain
: client.addChain;
this.#chain = addChain(this.#spec as ScType.WellKnownChain, onResponse).then((chain) => {
hc.setSendJsonRpc(chain.sendJsonRpc);