-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: substrate-connect integration (#368)
- Loading branch information
Showing
22 changed files
with
324 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@reactive-dot/core": minor | ||
--- | ||
|
||
Added SubstrateConnect integration. |
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
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
Binary file not shown.
Binary file not shown.
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
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
Binary file not shown.
Binary file not shown.
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,43 +1,61 @@ | ||
import { kusama, polkadot, westend } from "@polkadot-api/descriptors"; | ||
import { | ||
kusama, | ||
polkadot, | ||
polkadot_asset_hub, | ||
polkadot_people, | ||
westend, | ||
} from "@polkadot-api/descriptors"; | ||
import { defineConfig } from "@reactive-dot/core"; | ||
import { createLightClientProvider } from "@reactive-dot/core/providers/light-client.js"; | ||
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js"; | ||
import { getSmProvider } from "polkadot-api/sm-provider"; | ||
import { startFromWorker } from "polkadot-api/smoldot/from-worker"; | ||
import { LedgerWallet } from "@reactive-dot/wallet-ledger"; | ||
import { WalletConnect } from "@reactive-dot/wallet-walletconnect"; | ||
|
||
const smoldot = startFromWorker( | ||
new Worker(new URL("polkadot-api/smoldot/worker", import.meta.url), { | ||
type: "module", | ||
}), | ||
); | ||
const lightClientProvider = createLightClientProvider(); | ||
|
||
const polkadotProvider = lightClientProvider.addRelayChain({ id: "polkadot" }); | ||
|
||
export const config = defineConfig({ | ||
chains: { | ||
polkadot: { | ||
descriptor: polkadot, | ||
provider: getSmProvider( | ||
import("polkadot-api/chains/polkadot").then(({ chainSpec }) => | ||
smoldot.addChain({ chainSpec }), | ||
), | ||
), | ||
provider: polkadotProvider, | ||
}, | ||
polkadot_asset_hub: { | ||
descriptor: polkadot_asset_hub, | ||
provider: polkadotProvider.addParachain({ id: "polkadot_asset_hub" }), | ||
}, | ||
polkadot_people: { | ||
descriptor: polkadot_people, | ||
provider: polkadotProvider.addParachain({ id: "polkadot_people" }), | ||
}, | ||
kusama: { | ||
descriptor: kusama, | ||
provider: getSmProvider( | ||
import("polkadot-api/chains/ksmcc3").then(({ chainSpec }) => | ||
smoldot.addChain({ chainSpec }), | ||
), | ||
), | ||
provider: lightClientProvider.addRelayChain({ id: "kusama" }), | ||
}, | ||
westend: { | ||
descriptor: westend, | ||
provider: getSmProvider( | ||
import("polkadot-api/chains/westend2").then(({ chainSpec }) => | ||
smoldot.addChain({ chainSpec }), | ||
), | ||
), | ||
provider: lightClientProvider.addRelayChain({ id: "westend" }), | ||
}, | ||
}, | ||
wallets: [ | ||
new InjectedWalletProvider({ originName: "ReactiveDOT Vue Example" }), | ||
new InjectedWalletProvider({ originName: "ReactiveDOT React Example" }), | ||
new LedgerWallet(), | ||
new WalletConnect({ | ||
projectId: "68f5b7e972a51cf379b127f51a791c34", | ||
providerOptions: { | ||
metadata: { | ||
name: "ReactiveDOT example", | ||
description: "Simple React App showcasing ReactiveDOT", | ||
url: globalThis.location.origin, | ||
icons: ["https://walletconnect.com/walletconnect-logo.png"], | ||
}, | ||
}, | ||
chainIds: [ | ||
"polkadot:91b171bb158e2d3848fa23a9f1c25182", // Polkadot | ||
"polkadot:b0a8d493285c2df73290dfb7e61f870f", // Kusama | ||
"polkadot:e143f23803ac50e8f6f8e62695d1ce9e", // Westend | ||
], | ||
}), | ||
], | ||
}); |
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,16 +1,32 @@ | ||
import type { ChainConfig } from "../config.js"; | ||
import { | ||
createClientFromLightClientProvider, | ||
isLightClientProvider, | ||
type LightClientProvider, | ||
} from "../providers/light-client/provider.js"; | ||
import { createClient } from "polkadot-api"; | ||
import type { JsonRpcProvider } from "polkadot-api/ws-provider/web"; | ||
|
||
export async function getClient(chainConfig: ChainConfig) { | ||
const providerOrGetter = await chainConfig.provider; | ||
|
||
if (isLightClientProvider(providerOrGetter)) { | ||
return createClientFromLightClientProvider(providerOrGetter); | ||
} | ||
|
||
// Hack to detect wether function is a `JsonRpcProvider` or a getter of `JsonRpcProvider` | ||
const provider = await (providerOrGetter.length > 0 | ||
? (providerOrGetter as JsonRpcProvider) | ||
const providerOrController = await (providerOrGetter.length > 0 | ||
? (providerOrGetter as JsonRpcProvider | LightClientProvider) | ||
: ( | ||
providerOrGetter as Exclude<typeof providerOrGetter, JsonRpcProvider> | ||
providerOrGetter as Exclude< | ||
typeof providerOrGetter, | ||
JsonRpcProvider | LightClientProvider | ||
> | ||
)()); | ||
|
||
return createClient(provider); | ||
if (isLightClientProvider(providerOrController)) { | ||
return createClientFromLightClientProvider(providerOrController); | ||
} | ||
|
||
return createClient(providerOrController); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { createLightClientProvider } from "./provider.js"; |
Oops, something went wrong.