Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Solid.js support #1886

Merged
merged 23 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
72a2bce
feat: add solidjs support
yisacc Aug 27, 2023
a7820c3
chore: update version
yisacc Aug 27, 2023
86282f9
Merge branch 'develop' into feature/web3-onboarding-solidjs
Adamj1232 Sep 5, 2023
2afe195
fix: export the interfaces
yisacc Sep 13, 2023
c16452f
Merge branch 'develop' into feature/web3-onboarding-solidjs
Adamj1232 Sep 13, 2023
e3b07c1
feat: update the export
yisacc Sep 13, 2023
79ea7f3
revise: update solid package to use yarn + include examples on the re…
yisacc Sep 16, 2023
d0e7c14
Update packages/solid/package.json
Adamj1232 Sep 18, 2023
5e02fb1
fix: the engine node incompatible issue
yisacc Oct 15, 2023
23146b2
Merge branch 'develop' into feature/web3-onboarding-solidjs
yisacc Oct 15, 2023
7fc690f
Merge branch 'develop' into feature/web3-onboarding-solidjs
Adamj1232 Oct 16, 2023
3c8dee6
fix: node incompatible issue
yisacc Oct 16, 2023
914a49e
Merge branch 'develop' into feature/web3-onboarding-solidjs
yisacc Oct 16, 2023
e89c269
fix: node version incompatible issue
yisacc Oct 16, 2023
2afa159
Merge branch 'develop' into feature/web3-onboarding-solidjs
yisacc Oct 16, 2023
3080544
fix: add solid-js as a dependency
yisacc Oct 16, 2023
616f9ac
fix: peer dependency issue
yisacc Oct 17, 2023
efe2926
Fix failing typecheck caused by missing command in solidjs package
Adamj1232 Oct 17, 2023
65363fe
Add solid to docs site
Adamj1232 Oct 17, 2023
112721d
Update docs pages
Adamj1232 Oct 17, 2023
f49c8a7
feat: add example to work with solid
yisacc Oct 17, 2023
30ebf0a
Merge in upstream develop
Adamj1232 Oct 18, 2023
5f582ef
Merge upstream develop and handle conflicts
Adamj1232 Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ For full documentation, check out the README.md for each package or the [docs pa
**Frameworks**

- [React](packages/react/README.md)
- [Solid](packages/solid/README.md)
- [Vue](packages/vue/README.md)

## Test out the demo app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ We recommend you add the [Core Repo](../../modules/core.md#install) and consider
**Frameworks**

- [React](../../modules/react.md#quickstart-with-injected-wallets-and-ethers-provider)
- [Solid](../../modules/solid.md#install)
- [Vue](../../modules/vue.md#install)

## Test out the demo app
Expand Down
1 change: 1 addition & 0 deletions docs/src/routes/docs/[...3]modules/[...1]core/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ npm install @web3-onboard/coinbase @web3-onboard/metamask @web3-onboard/fortmati

- All wallet modules (except for `injected-wallets`) require extra dependencies and may require polyfilling the node built in modules for the browser. See the [Build Environments](#build-environments) section for more info
- **If using React** you may be interested in checking out the React Hooks package here - https://www.npmjs.com/package/@web3-onboard/react
- **If using Solid** you may be interested in checking out the Solid package here - https://www.npmjs.com/package/@web3-onboard/solid
- **If using Vue** you may be interested in checking out the Vue package here - https://www.npmjs.com/package/@web3-onboard/vue
:::

Expand Down
271 changes: 271 additions & 0 deletions docs/src/routes/docs/[...3]modules/[...4]solid/+page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
---
title: Solid.js
---

# {$frontmatter.title}

A collection of composable functions for implementing web3-onboard in to a Solid project;

## Quickstart with Injected Wallets and Ethers Provider

### Install

<Tabs values={['yarn', 'npm']}>
<TabPanel value="yarn">

```sh copy
yarn add @web3-onboard/solid @web3-onboard/injected-wallets
```

</TabPanel>
<TabPanel value="npm">

```sh copy
npm install @web3-onboard/solid @web3-onboard/injected-wallets
```

</TabPanel>
</Tabs>


## Quickstart

```typescript
import { init } from '@web3-onboard/solid'
import injectedModule from '@web3-onboard/injected-wallets'

const injected = injectedModule()

// Only one RPC endpoint required per chain
const rpcAPIKey = '<INFURA_KEY>' || '<ALCHEMY_KEY>'
const rpcUrl =
`https://eth-mainnet.g.alchemy.com/v2/${rpcAPIKey}` ||
`https://mainnet.infura.io/v3/${rpcAPIKey}`

const web3Onboard = init({
wallets: [injected],
chains: [
{
id: '0x1',
token: 'ETH',
label: 'Ethereum Mainnet',
rpcUrl
},
{
id: '0x2105',
token: 'ETH',
label: 'Base',
rpcUrl: 'https://mainnet.base.org'
}
]
})

const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } =
useOnboard()

if (connectedWallet) {
// if using ethers v6 this is:
// ethersProvider = new ethers.BrowserProvider(wallet.provider, 'any')
const ethersProvider = new ethers.providers.Web3Provider(
connectedWallet.provider,
'any'
)
// ..... do stuff with the provider
}
```

## Functions

### `init`

The `init` function initializes `web3-onboard` and makes it available to the `useOnboard()` composable. For references check out the [initialization docs for `@web3-onboard/core`](../core/README.md#initialization)

#### Example usage

```typescript
import { init } from '@web3-onboard/solid'
import injectedModule from '@web3-onboard/injected-wallets'

const injected = injectedModule()
const infuraKey = '<INFURA_KEY>'
const rpcUrl = `https://mainnet.infura.io/v3/${infuraKey}`

const web3Onboard = init({
wallets: [injected],
chains: [
{
id: '0x1',
token: 'ETH',
label: 'Ethereum Mainnet',
rpcUrl
}
]
})
```

### `useOnboard`

`useOnboard` must be used after the `init` function has been called - it will return an object that can be destructured to obtain the following reactive variables and functions:

#### Example usage

```typescript
import { useOnboard } from '@web3-onboard/solid'
// Use the composable
const onboard = useOnboard()
// Or destructure it
const {
wallets,
connectedWallet,
connectedChain,
connectWallet,
disconnectConnectedWallet
} = useOnboard()
// do stuff
```

### `connectWallet`

Function to open the onboard modal and connect to a wallet provider. For reference check out the [connecting a wallet for `@web3-onboard/core`](../core/README.md#connecting-a-wallet)

#### Example usage

```tsx
function SampleConnect() {
const { connectWallet } = useOnboard()

return <button onClick={() => connectWallet()}> connect wallet</button>
}
```

### `connectedChain`

Property that contains the current chain to which `connectedChain` is connected

#### Example usage

```tsx
function SampleConnect() {
const { connectedChain } = useOnboard()

return <span>Connected Chain: { connectedChain() }</span>
```

### `connectedWallet`

Property that contains the latest connected wallet

#### Example usage

```tsx
function SampleConnect() {
const { connectedWallet } = useOnboard()
return <span>Connected Wallet: {connectedWallet()?.label}</span>
}
```

### `disconnectConnectedWallet`

Function to disconnect the `connectedWallet`

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { disconnectConnectedWallet } = useOnboard()
return (
<button onClick={() => disconnectConnectedWallet()}>
{' '}
disconnect wallet
</button>
)
}
```

### `getChain`

Function that returns the current chain a wallet is connected to

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { getChain } = useOnboard()
return <span>MetaMask is connected to: {getChain('MetaMask')}</span>
}
```

### `setChain`

Function to set the chain of a wallet

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { setChain } = useOnboard()
const set = () => setChain({ wallet: 'MetaMask', chainId: '0x1' })
return (
<button type="button" onClick={set}>
Set MetaMask chain to mainnet
</button>
)
}
```

### `settingChain`

Readonly boolean ref that tracks the status of setting the chain

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { settingChain } = useOnboard()
return { settingChain }
}
```

### `wallets`

Readonly ref that contains every wallet that has been connected

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { wallets } = useOnboard()
return(
<ul>
<For each={wallets()}>{wallet=>{
return <li>
{wallet.label}
</li>
}}
</For>
</ul>
)
}
}
```

### `lastConnectedTimestamp`

Readonly ref that contains the last time that the user connected a wallet in milliseconds

#### Example usage

```tsx
import { useOnboard } from '@web3-onboard/solid'
function SampleConnect() {
const { lastConnectedTimestamp } = useOnboard()
return (
<span>Your last connection timestamp was: {lastConnectedTimestamp}</span>
)
}
```
24 changes: 24 additions & 0 deletions examples/with-solidjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
28 changes: 28 additions & 0 deletions examples/with-solidjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Usage

```bash
$ npm install # or pnpm install or yarn install
```

### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs)

## Available Scripts

In the project directory, you can run:

### `npm run dev`

Runs the app in the development mode.<br>
Open [http://localhost:5173](http://localhost:5173) to view it in the browser.

### `npm run build`

Builds the app for production to the `dist` folder.<br>
It correctly bundles Solid in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

## Deployment

Learn more about deploying your application with the [documentations](https://vitejs.dev/guide/static-deploy.html)
13 changes: 13 additions & 0 deletions examples/with-solidjs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Solid</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions examples/with-solidjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "with-solidjs",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"solid-js": "^1.7.8"
},
"devDependencies": {
"vite": "^4.4.5",
"vite-plugin-solid": "^2.7.0"
}
}
1 change: 1 addition & 0 deletions examples/with-solidjs/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading