-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
166 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,18 @@ | ||
import { createClient, ProviderStatus } from "@unstoppablejs/client" | ||
import { WsProvider } from "@unstoppablejs/ws-provider" | ||
import { storageClient } from "@unstoppablejs/substrate-bindings" | ||
|
||
let onMessagePort: (port: MessagePort) => void | ||
const smPortPromise: Promise<MessagePort> = new Promise((res) => { | ||
onMessagePort = res | ||
}) | ||
|
||
export const setSmPort = (smPort: MessagePort) => { | ||
onMessagePort(smPort) | ||
} | ||
|
||
export const client = createClient((onMessage, onStatus) => { | ||
let port: MessagePort | null = null | ||
|
||
const onPortMessage = (e: MessageEvent) => { | ||
onMessage(e.data) | ||
} | ||
|
||
const onHalt = () => { | ||
onStatus(ProviderStatus.halt) | ||
} | ||
|
||
const open = () => { | ||
smPortPromise | ||
.then((_port) => { | ||
if (!(_port instanceof MessagePort)) throw null | ||
|
||
port = _port | ||
port.onmessage = onPortMessage | ||
self.addEventListener("message", onHalt, { | ||
once: true, | ||
}) | ||
onStatus(ProviderStatus.ready) | ||
}) | ||
.catch(() => { | ||
onStatus(ProviderStatus.halt) | ||
}) | ||
} | ||
|
||
const close = () => { | ||
self.removeEventListener("message", onHalt) | ||
port?.removeEventListener("message", onPortMessage) | ||
port = null | ||
} | ||
|
||
const send = (msg: string) => { | ||
port?.postMessage(msg) | ||
} | ||
|
||
return { open, close, send } | ||
}) | ||
client.connect() | ||
|
||
export const { getFromStorage } = storageClient(client) | ||
|
||
// We only use the WsProvider for iterating over the keys | ||
// of Stake.Nominators. We can't use smoldot for doing | ||
// that until the following issue gets solved: | ||
// https://github.com/smol-dot/smoldot/issues/692 | ||
const wsProvider = WsProvider("wss://rpc.polkadot.io") | ||
const wsClient = createClient(wsProvider) | ||
wsClient.connect() | ||
export const { getKeys } = storageClient(wsClient) | ||
import { createClient } from "@polkadot-api/client" | ||
import { getLegacyProvider } from "@polkadot-api/legacy-polkadot-provider" | ||
import { createScClient, WellKnownChain } from "@substrate/connect" | ||
// @ts-ignore | ||
import ScWorker from "./substrate-worker?worker" | ||
import dot from "./descriptors/dot" | ||
import roc from "./descriptors/roc" | ||
|
||
const provider = getLegacyProvider( | ||
createScClient({ | ||
embeddedNodeConfig: { | ||
workerFactory: ScWorker, | ||
}, | ||
}), | ||
) | ||
|
||
const chain = provider.relayChains[WellKnownChain.polkadot] | ||
export const client = createClient(chain.connect, { dot, roc }) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export * from "./generated/storage-identity" | ||
export * from "./generated/storage-session" | ||
export * from "./generated/storage-staking" | ||
export { client } from "./client" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "@substrate/connect/worker" |
Oops, something went wrong.
3c4c9b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Polkadot Forum. There might be relevant details there:
https://forum.polkadot.network/t/papi-is-coming-showcasing-the-validator-selector-tool-dapp/5756/1