Skip to content

Commit

Permalink
chore: simplify example smoldot worker
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Jun 12, 2024
1 parent 9460ad3 commit 76f0187
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions apps/docs/docs/getting-started/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ import { chainSpec } from "polkadot-api/chains/polkadot";
import { getSmProvider } from "polkadot-api/sm-provider";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";

const smoldot = startFromWorker(new SmWorker());
const chain = smoldot.addChain({ chainSpec });
const smoldot = startFromWorker(
new Worker(new URL("polkadot-api/smoldot/worker", import.meta.url), {
type: "module",
}),
);

const config: Config = {
chains: {
polkadot: {
descriptor: polkadot,
provider: getSmProvider(chain),
provider: getSmProvider(smoldot.addChain({ chainSpec })),
},
},
wallets: [new InjectedConnector()],
Expand Down
11 changes: 6 additions & 5 deletions apps/example/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@ import type { Config } from "@reactive-dot/types";
import { getSmProvider } from "polkadot-api/sm-provider";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";

const createSmoldotWorker = () =>
const smoldotPromise = startFromWorker(
new Worker(new URL("polkadot-api/smoldot/worker", import.meta.url), {
type: "module",
});
}),
);

const config: Config = {
chains: {
polkadot: {
descriptor: polkadot,
provider: getSmProvider(
import("polkadot-api/chains/polkadot").then(({ chainSpec }) =>
startFromWorker(createSmoldotWorker()).addChain({ chainSpec }),
smoldotPromise.addChain({ chainSpec }),
),
),
},
kusama: {
descriptor: kusama,
provider: getSmProvider(
import("polkadot-api/chains/ksmcc3").then(({ chainSpec }) =>
startFromWorker(createSmoldotWorker()).addChain({ chainSpec }),
smoldotPromise.addChain({ chainSpec }),
),
),
},
westend: {
descriptor: westend,
provider: getSmProvider(
import("polkadot-api/chains/westend2").then(({ chainSpec }) =>
startFromWorker(createSmoldotWorker()).addChain({ chainSpec }),
smoldotPromise.addChain({ chainSpec }),
),
),
},
Expand Down

0 comments on commit 76f0187

Please sign in to comment.