Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleecode committed Jul 1, 2024
2 parents b5af5df + 5592d92 commit 4536dfe
Show file tree
Hide file tree
Showing 79 changed files with 1,622 additions and 1,093 deletions.
52 changes: 4 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

connect-flaky-tests:
needs: [build]
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/turbo-build
- run: pnpm test:flaky
working-directory: ./packages/connect

playwright-test-extension:
needs: [build]
timeout-minutes: 10
Expand Down Expand Up @@ -81,49 +71,15 @@ jobs:
working-directory: ./projects/wallet-template
- run: pnpm playwright:install
working-directory: ./projects/wallet-template
# - name: Test projects/wallet-template
# run: pnpm playwright:chromium --trace on
# working-directory: ./projects/wallet-template
- name: Test projects/wallet-template
run: pnpm playwright:chromium --trace on
working-directory: ./projects/wallet-template
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report-substrate-connect-wallet-template-mv3-chrome
path: ./projects/wallet-template/playwright-report

zombienet-tests:
needs: [build]
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/turbo-build
- name: Get zombienet
run: |
curl -L -O https://github.com/paritytech/zombienet/releases/download/v1.3.91/zombienet-linux-x64
chmod +x zombienet-linux-x64
- name: Get polkadot
run: |
curl -L -O https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.6.0/polkadot
chmod +x polkadot
- name: Get polkadot execute worker
run: |
curl -L -O https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.6.0/polkadot-execute-worker
chmod +x polkadot-execute-worker
- name: Get polkadot prepare worker
run: |
curl -L -O https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.6.0/polkadot-prepare-worker
chmod +x polkadot-prepare-worker
- name: Get polkadot-parachain
run: |
curl -L -O https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.6.0/polkadot-parachain
chmod +x polkadot-parachain
- name: Run test
run: |
export PATH=$(pwd):$PATH
cd zombienet-tests/src
zombienet-linux-x64 -p native test 0001-relay-smoke-test.zndsl
zombienet-linux-x64 -p native test 0002-parachain.zndsl
npm-publish:
if: github.ref == 'refs/heads/main'
needs: [build]
Expand Down Expand Up @@ -202,7 +158,7 @@ jobs:
all:
# This dummy job depends on all the mandatory checks. It succeeds if and only if all CI checks
# are successful.
needs: [build, playwright-test-extension, playwright-test-examples, zombienet-tests, playwright-test-wallet-template]
needs: [build, playwright-test-extension, playwright-test-examples, playwright-test-wallet-template]
runs-on: ubuntu-latest
steps:
- run: echo Success
112 changes: 67 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,96 @@
# Substrate Connect

Substrate connect provides a way to interact with [substrate](https://substrate.dev/)
based blockchains in the browser without using an RPC server. Substrate connect
uses a [smoldot](https://github.com/smol-dot/smoldot) WASM light client to
securely connect to the blockchain network without relying on specific 3rd parties.
Substrate Connect offers an innovative way to interact with
[Substrate](https://substrate.dev/)-based blockchains directly in your browser,
eliminating the need for an RPC server. By leveraging the
[smoldot](https://github.com/smol-dot/smoldot) WASM light client, it ensures a
secure and efficient connection to the blockchain network without dependency
on specific third parties.

Due to browser limitations on websockets from https pages, establishing a good
number of peers is difficult as many nodes need to be available with TLS. Substrate
connect provides a browser extension to overcome this limitation and to keep
the chains synced in the background, which makes your apps faster.
### Overcoming Browser Limitations

When building an app with substrate connect, it will detect whether the user has
the extension and use it, or create the WASM light client in-page for them.
Browser limitations on websockets from HTTPS pages make establishing a robust
number of peers challenging, as many nodes must be available with TLS.
Substrate Connect addresses this issue through a powerful browser extension,
allowing chains to stay synced in the background, thereby significantly
enhancing the performance of your applications.

Substrate connect builds on [Polkadot JS](https://polkadot.js.org/docs/api) so
building an app is the same experience as with using a traditional RPC server
node.
### Seamless Integration

The substrate connect [API documentation is published here](https://paritytech.github.io/substrate-connect/api/).
When building an application with Substrate Connect, it automatically detects
whether the user has the extension installed and utilizes it. If not, it
seamlessly creates the WASM light client in-page for them. Built on
[Polkadot JS](https://polkadot.js.org/docs/api), Substrate Connect ensures
that your development experience is as smooth as using a traditional RPC
server node.

## Development
### Comprehensive API Documentation

This repository is using [pnpm workspaces](https://pnpm.io/workspaces).
For detailed API usage, refer to the [Substrate Connect API
documentation](https://paritytech.github.io/substrate-connect/api/).

We also use `corepack`, which ensures that the correct version of `pnpm` is used.
## Development

Please see our [contributing guidelines](./CONTRIBUTING.md) for details on how
we like to work and how to smoothly contribute to the project.
This repository utilizes [pnpm workspaces](https://pnpm.io/workspaces) and
`corepack`, ensuring the correct version of `pnpm` is used. For contributions,
please review our [contributing guidelines](./CONTRIBUTING.md) to understand
our workflow and how to smoothly integrate your contributions to the project.

### Getting Started

If you're hacking on this repository, here's how to install everything and spin up a demo:
Follow these steps to install everything and launch a demo if you're hacking
on this repository:

1. Install any prerequisites. These steps were tested with:
- Node.js (node) v20.9.0.
- pnpm 9.0.6 (`npm install -g pnpm`).
- corepack 0.20.0 (This should be bundled with recent Node.js versions).
2. Clone the repository.
1. **Install Prerequisites** (tested with the following versions):
- Node.js (node) v20.9.0
- pnpm 9.0.6 (`npm install -g pnpm`)
- corepack 0.20.0 (bundled with recent Node.js versions)

2. **Clone the Repository**:
- `git clone https://github.com/paritytech/substrate-connect.git`
- `cd substrate-connect` to navigate to the repository root.
3. Install the dependencies.
- Navigate to the repository root: `cd substrate-connect`

3. **Install Dependencies**:
- `corepack pnpm install`
4. In terminal A, run `cd projects/extension && corepack pnpm dev`.
5. In terminal B, run `cd projects/extension && corepack pnpm start`.
- This will open a Chrome browser window with the extension pre-loaded.
- Make sure that the extension is running.
6. In terminal C, run `cd projects/demo && corepack pnpm dev`.
- Navigate to the URL that this logs in the Chrome browser that opened in 5.
- You should see the extension come to life and the demo app log latest blocks.

To clean up all build artefacts in workspaces in the repository, run:


4. **Run the Extension in Development Mode**:
- In terminal A: `cd projects/extension && corepack pnpm dev`

5. **Launch the Extension**:
- In terminal B: `cd projects/extension && corepack pnpm start`
- This opens a Chrome browser window with the extension pre-loaded. Ensure
the extension is running.

6. **Run the Demo Application**:
- In terminal C: `cd projects/demo && corepack pnpm dev`
- Navigate to the URL logged in the Chrome browser opened in step 5. You
should see the extension activate and the demo app log the latest blocks.

### Cleanup Commands

To clean up all build artifacts in workspaces in the repository:
```bash
corepack pnpm clean
```

To clean up all build artefacts and dependencies in workspaces in the repository, run:

To clean up all build artifacts and dependencies in workspaces in the repository:
```bash
corepack pnpm deep-clean
```

## Wallet Template

To understand how to use Substrate Connect as a fully functional light client
wallet, visit the [wallet template directory](./projects/wallet-template/).

## Releasing

Visit [the release doc](./DEPLOY-RELEASE.md) and follow the steps there to release a new version of the extension.
For releasing a new version of the extension, follow the steps outlined in
[the release doc](./DEPLOY-RELEASE.md).

## Useful Links

[Substrate Connect Documentation Page](https://substrate.io/developers/substrate-connect/)

Download at:
- [Chrome Store](https://chrome.google.com/webstore/detail/substrate-connect-extensi/khccbhhbocaaklceanjginbdheafklai)
- [Mozilla Addons](https://addons.mozilla.org/en-US/firefox/addon/substrate-connect/)
- [Substrate Connect Documentation Page](https://substrate.io/developers/substrate-connect/)
- Download from:
- [Chrome Store](https://chrome.google.com/webstore/detail/substrate-connect-extensi/khccbhhbocaaklceanjginbdheafklai)
- [Mozilla Addons](https://addons.mozilla.org/en-US/firefox/addon/substrate-connect/)
38 changes: 16 additions & 22 deletions examples/light-client-dapp/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
# React + TypeScript + Vite
# Light Client DApp Example

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
This project is an example of a decentralized application (DApp) using Substrate Connect's light client. It demonstrates how to set up and integrate a light client into a React application using TypeScript and Vite.

Currently, two official plugins are available:
## Technologies Used

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
- **React**: A JavaScript library for building user interfaces.
- **TypeScript**: A strongly typed programming language that builds on JavaScript.
- **Vite**: A build tool that aims to provide a faster and leaner development experience for modern web projects.

## Expanding the ESLint configuration
## Installation

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
To get started with the project, follow these steps:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```bash
corepack pnpm i
corepack pnpm turbo build
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
Then to run the project

```bash
corepack pnpm dev
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"@substrate/connect": "workspace:^"
"@substrate/connect": "workspace:^",
"smoldot": "2.0.29"
}
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/connect-known-chains/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# @substrate/connect-known-chains

Substrate-connect well known chain specifications
This package contains all the well known chain specifications. It is updated
daily by a bot via pull request.

You can find the chainspecs in the [specs](./specs/) directory.
2 changes: 1 addition & 1 deletion packages/connect-known-chains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@substrate/connect-known-chains",
"version": "1.1.6",
"version": "1.1.7",
"description": "Substrate-connect well known chain specifications",
"author": "Parity Team <[email protected]>",
"license": "GPL-3.0-only",
Expand Down
8 changes: 4 additions & 4 deletions packages/connect-known-chains/specs/ksmcc3.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/connect-known-chains/specs/polkadot.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/connect-known-chains/specs/rococo_v2_2.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/connect-known-chains/specs/westend2.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/connect/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### Changed

## 1.0.3 - 2024-06-27

- Update internal usage of discovery protocol to use @substrate/smoldot-discovery instead of @substrate/connect-discovery
- Bump light client extension helpers

## 1.0.2 - 2024-06-17

- Bump light client extension helpers
Expand Down
6 changes: 2 additions & 4 deletions packages/connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@substrate/connect",
"version": "1.0.2",
"version": "1.0.3",
"description": "Substrate-connect to Smoldot clients. Using either substrate extension with predefined clients or an internal smoldot client based on chainSpecs provided.",
"author": "Parity Team <[email protected]>",
"license": "GPL-3.0-only",
Expand Down Expand Up @@ -35,8 +35,7 @@
"homepage": "https://github.com/paritytech/substrate-connect#readme",
"scripts": {
"pretest": "pnpm build",
"test": "vitest --dangerouslyIgnoreUnhandledErrors --environment jsdom --exclude \"test/flaky/**\"",
"test:flaky": "vitest test/flaky",
"test": "vitest --dangerouslyIgnoreUnhandledErrors --environment jsdom",
"deep-clean": "pnpm clean && rm -rf node_modules",
"clean": "rm -rf dist",
"build": "tsc --noEmit && tsup-node src/index.ts src/worker.ts src/worker-node.ts --clean --sourcemap --platform neutral --target=es2015 --format esm,cjs --dts",
Expand All @@ -46,7 +45,6 @@
"@substrate/connect-extension-protocol": "workspace:^",
"@substrate/connect-known-chains": "workspace:^",
"@substrate/smoldot-discovery": "workspace:^",
"@substrate/connect-discovery": "workspace:^",
"smoldot": "2.0.29"
},
"devDependencies": {
Expand Down
16 changes: 7 additions & 9 deletions packages/connect/src/connector/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SmoldotExtensionAPI } from "@substrate/smoldot-discovery/types"
import {
createScClient as smoldotScClient,
type Config as EmbeddedNodeConfig,
} from "./smoldot-light.js"
import { createScClient as extensionScClient } from "./extension.js"
import type { ScClient } from "./types.js"
import { Unstable } from "@substrate/connect-discovery"
import { getSmoldotExtensionProviders } from "@substrate/smoldot-discovery"

export * from "./types.js"
export type { EmbeddedNodeConfig }
Expand Down Expand Up @@ -39,9 +39,9 @@ export const createScClient = (config?: Config): ScClient => {
if (config?.forceEmbeddedNode)
return smoldotScClient(config?.embeddedNodeConfig)

const lightClientProviderPromise = getExtensionLightClientProviderPromise()
const client = lightClientProviderPromise
? extensionScClient(lightClientProviderPromise)
const smoldotProviderPromise = getSmoldotProviderPromise()
const client = smoldotProviderPromise
? smoldotProviderPromise
: smoldotScClient(config?.embeddedNodeConfig)

return {
Expand All @@ -62,11 +62,9 @@ export const createScClient = (config?: Config): ScClient => {
}
}

function getExtensionLightClientProviderPromise():
| Promise<Unstable.Provider>
| undefined {
function getSmoldotProviderPromise(): Promise<SmoldotExtensionAPI> | undefined {
if (typeof document !== "object" || typeof CustomEvent !== "function") return
const lightClientProvider = Unstable.getSubstrateConnectExtensionProviders()
const lightClientProvider = getSmoldotExtensionProviders()
.filter((detail) =>
detail.info.rdns.startsWith("io.github.paritytech.SubstrateConnect"),
)
Expand Down
Loading

0 comments on commit 4536dfe

Please sign in to comment.