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(solid): Implement solid playground and core hooks #1947

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
df93f54
saving progress
gabrieldemian Jan 8, 2023
04a66f8
Forgot wagmi-react rename
Jan 9, 2023
bafaff1
Implement client using solid-query
Jan 9, 2023
a489c33
Migrate types
Jan 9, 2023
0196a28
added vanilla solid to examples
gabrieldemian Jan 10, 2023
f588902
fixed docs imports to use wagmi-react
gabrieldemian Jan 10, 2023
fdac4dd
Use solid-query with the context
Jan 10, 2023
8ccf57b
Rollback wagmi-react and add @wagmi/solid
Jan 10, 2023
40cb45f
Add useContract, useProvider and useWebSocketProvider
Jan 10, 2023
2301b68
added solid-devtools, refactored useProvider hook
gabrieldemian Jan 11, 2023
5414114
removed index.html and index.tsx from package/solid
gabrieldemian Jan 11, 2023
d928c78
refactored useWebSocketProvider hook
gabrieldemian Jan 11, 2023
a256fd5
updated useContract: props.address is now of type Accessor<Address>
gabrieldemian Jan 11, 2023
f456b53
created solid test folder
gabrieldemian Jan 11, 2023
13fab7e
saving progress on tests
gabrieldemian Jan 11, 2023
cc3b385
saving progress
gabrieldemian Jan 11, 2023
6c9430b
updated solid query
gabrieldemian Jan 11, 2023
882663a
POC
Jan 12, 2023
75ccf09
Show that hooks are working
Jan 12, 2023
394a34e
Write most of useAccount tests
Jan 12, 2023
289c339
Test solid testing library
Jan 13, 2023
6677427
Update solid testing package
Jan 13, 2023
132a3ac
Remove wrapper param
Jan 13, 2023
fedbece
Fix useAccount test with new solid-testing lib
Jan 13, 2023
9bf8865
Begin useBalance tests
Jan 13, 2023
fc2c02f
added query to useBalance
gabrieldemian Jan 14, 2023
89ae6dc
added generic types to renderHook, fixed useBalance test to use the n…
gabrieldemian Jan 14, 2023
73e9fec
fix renderHook generics
gabrieldemian Jan 14, 2023
e28b05c
added onDisconnect and onConnect to useAccount hook
gabrieldemian Jan 14, 2023
e3ca238
added mutation to useConnect
gabrieldemian Jan 14, 2023
cc7adf7
added mutation to onDisconnect
gabrieldemian Jan 14, 2023
0b69a27
Fix wrong createMemo ReturnType and wrong queryFn type
Jan 14, 2023
1dd5a0b
added query to useSigner
gabrieldemian Jan 14, 2023
b99d845
added mutation to useSignMessage
gabrieldemian Jan 14, 2023
73dd207
added mutation to useSwitchNetwork
gabrieldemian Jan 14, 2023
3afc253
Fix tests
Jan 14, 2023
b8c6ea3
Update snapshots
Jan 14, 2023
c006dd9
Remove unwanted console logs
Jan 14, 2023
d6fb1d5
fixed enabled on useBalance and created utils/useChainId, fixed test
gabrieldemian Jan 15, 2023
c55bd1b
updated .eslintrc, removed react rules from solid packages, and added…
gabrieldemian Jan 15, 2023
41d1002
Add useDisconnect tests
Jan 16, 2023
0058a5d
Add useContract tests
Jan 16, 2023
05435d7
Add useNetwork tests
Jan 16, 2023
f1a14b5
Add useSigner tests
Jan 16, 2023
f1d87ec
Remove refetch useSigner as it should be reactive
Jan 16, 2023
6f3a586
Convert useSigner test to ts instead of tsx
Jan 16, 2023
39ed616
Add a few tests and fix a few things
Jan 16, 2023
ae5a638
Rollback wrong changes
Jan 16, 2023
c94f34f
Rollback wrong changes
Jan 16, 2023
6e545e1
Rollback changeset
Jan 16, 2023
c87aefb
Merge pull request #2 from gabrieldemian/development
gabrieldemian Jan 17, 2023
619de31
fixed all solid tests
gabrieldemian Mar 1, 2023
4c6e4ef
removed pnpm lock
gabrieldemian Mar 1, 2023
96866ef
Merge pull request #5 from gabrieldemian/merge-main
gabrieldemian Mar 1, 2023
b34d89e
pnpm i
gabrieldemian Mar 1, 2023
56be178
pnpm i
gabrieldemian Mar 1, 2023
9a8e7f0
updated useAccount test
gabrieldemian Mar 1, 2023
7a4cc94
fixed useAccount test
gabrieldemian Mar 1, 2023
b90855f
updated references/ submodule and updated chains
gabrieldemian Mar 1, 2023
5f895ff
improved useAccount callbacks
gabrieldemian Mar 2, 2023
53a1f1f
initiated solid docs
gabrieldemian Mar 2, 2023
70f8427
wrote getting-started
gabrieldemian Mar 2, 2023
8207fcc
added all hooks documentation
gabrieldemian Mar 3, 2023
e65469e
fixed tests
gabrieldemian Mar 3, 2023
8b04596
fixed provider not reactive
gabrieldemian Mar 3, 2023
0e2da0f
fixed useProvider
gabrieldemian Mar 3, 2023
8b0f90e
tanstack query v5
gabrieldemian Mar 4, 2023
c896629
fix tests because of breaking chances from solid query
gabrieldemian Mar 4, 2023
312eb64
changed useProvider and docs
gabrieldemian Mar 4, 2023
9710cbe
simple chances
gabrieldemian Mar 4, 2023
363310a
Merge branch 'wagmi-dev:main' into tests
gabrieldemian Mar 4, 2023
fff7857
Merge pull request #6 from gabrieldemian/tests
gabrieldemian Mar 4, 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
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
},
"ignore": ["docs", "example-dev"]
"ignore": ["docs", "example-dev", "example-dev-solid"]
}
7 changes: 6 additions & 1 deletion docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const withNextra = nextra({
/** @type {import('next').NextConfig} */
const config = {
i18n: {
locales: ['en-US','zh-CN'],
locales: ['en-US', 'zh-CN'],
defaultLocale: 'en-US',
},
reactStrictMode: true,
Expand Down Expand Up @@ -42,6 +42,11 @@ const config = {
destination: '/react/getting-started',
permanent: true,
},
{
source: '/solid',
destination: '/solid/getting-started',
permanent: true,
},
{
source: '/core',
destination: '/core/getting-started',
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/_meta.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"title": "React",
"type": "page"
},
"solid": {
"title": "Solid",
"type": "page"
},
"core": {
"title": "Core",
"type": "page"
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/_meta.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"title": "React",
"type": "page"
},
"solid": {
"title": "Solid",
"type": "page"
},
"core": {
"title": "Core",
"type": "page",
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/solid/_meta.en-US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"getting-started": "Getting Started",
"hooks": "Hooks"
}
129 changes: 129 additions & 0 deletions docs/pages/solid/getting-started.en-US.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
title: 'Getting Started'
description: 'Get started building with wagmi!'
---

import { Callout, Tabs, Tab } from 'nextra-theme-docs'

# Getting Started

## Overview

The setup and use of the Solid hooks are very similar to the React package, but there are some differences:
- ❌ do NOT destructure proxies and signals (most of the return objects from the hooks are), you will [lose reactivity](https://dev.to/ryansolid/answering-common-questions-about-solidjs-23ea).
- Import modules from `@wagmi/solid` instead of from `wagmi`.
- Most of the hooks props are reactive, you can pass in a signal, or a function that return the value, if you don't need it to be reactive.

## Manual setup

### Installation

Install wagmi and its ethers peer dependency.

{/* prettier-ignore-start */}
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tab>
```bash
npm i @wagmi/solid ethers@^5
```
</Tab>
<Tab>
```bash
pnpm i @wagmi/solid ethers@^5
```
</Tab>
<Tab>
```bash
yarn add @wagmi/solid ethers@^5
```
</Tab>
</Tabs>
{/* prettier-ignore-end */}

### Configure chains

First, configure your desired chains to be used by wagmi, and the providers you want to use.

```tsx
import { configureChains, mainnet, publicProvider } from '@wagmi/solid'

const { chains, provider, webSocketProvider } = configureChains(
[mainnet],
[publicProvider()],
)
```

This example uses the Ethereum Mainnet chain (`mainnet`) from `wagmi`, however, you can also pass in any [EVM-compatible chain](/solid/chains).

Note: In a production app, it is not recommended to only pass `publicProvider` to `configureChains` as you will probably face rate-limiting on the public provider endpoints. It is recommended to also pass an [`alchemyProvider`](/react/providers/alchemy) or [`infuraProvider`](/react/providers/infura) as well.

[Read more about configuring chains](/solid/providers/configuring-chains)

### Create a wagmi client

Next, create a wagmi `Client` instance using [`createClient`](/solid/client), and pass the result from `configureChains` to it.

```tsx {9-13}
import { WagmiConfig, createClient, configureChains, mainnet, publicProvider } from '@wagmi/solid'

const { chains, provider, webSocketProvider } = configureChains(
[mainnet],
[publicProvider()],
)

const client = createClient({
autoConnect: true,
provider,
webSocketProvider,
})
```

[Read more about client configuration](/solid/client)

### Wrap app with `WagmiConfig`

Finally, wrap your app with the [`WagmiConfig`](/solid/WagmiConfig) component, passing `client` to it.

```tsx {9-11}
const client = createClient({
autoConnect: true,
provider,
webSocketProvider,
})

function App() {
return (
<WagmiConfig client={client}>
<YourRoutes />
</WagmiConfig>
)
}
```

### You're good to go!

Use hooks! Every component inside the `WagmiConfig` is now set up to use the wagmi hooks.

```tsx {5,6,7-11}
import { useAccount, useConnect, useEnsName, InjectedConnector } from '@wagmi/solid'
import { createSignal } from 'solid-js'

function Profile() {
const [chainId, setChainId] = createSignal(1)
const accData = useAccount()

const { connect } = useConnect({
chainId
// chainId: () => 1
})

return (
<>
<button onClick={() => setChainId(5)}>Change chainId to 5</button>
<button onClick={() => connect()}>Connect Wallet</button>
</>
)
}
```

Want to learn more? Check out the [examples](/examples/connect-wallet) to learn how to use wagmi in real-world scenarios or continue on reading the documentation.
13 changes: 13 additions & 0 deletions docs/pages/solid/hooks/_meta.en-US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"useAccount": "useAccount",
"useBalance": "useBalance",
"useConnect": "useConnect",
"useContract": "useContract",
"useDisconnect": "useDisconnect",
"useNetwork": "useNetwork",
"useProvider": "useProvider",
"useSigner": "useSigner",
"useSignMessage": "useSignMessage",
"useSwitchNetwork": "useSwitchNetwork",
"useWebSocketProvider": "useWebSocketProvider"
}
78 changes: 78 additions & 0 deletions docs/pages/solid/hooks/useAccount.en-US.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: 'useAccount'
description: 'React Hook for accessing account data and connection status.'
---

# useAccount

Solid hook for accessing account data and connection status.

```ts
import { useAccount } from '@wagmi/solid'
```

## Usage

```tsx
import { useAccount } from '@wagmi/solid'

function App() {
// do not destructure this object,
// it will lose reactivity if you do.
const accData = useAccount()

if (accData().isConnecting) return <div>Connecting…</div>
if (accData().isDisconnected) return <div>Disconnected</div>
return <div>{accData().address}</div>
}
```

## Return Value

```ts
Accessor<{
address?: string
connector?: Connector
isConnecting: boolean
isReconnecting: boolean
isConnected: boolean
isDisconnected: boolean
status: 'connecting' | 'reconnecting' | 'connected' | 'disconnected'
}>
```

## Configuration

### onConnect (optional)

Function to invoke when account connects.

It provides the connected address & connector, as well as a `isReconnected` flag for if the user reconnected via `autoConnect`.

```tsx {5-7}
import { useAccount } from '@wagmi/solid'

function App() {
const account = useAccount({
onConnect({ address, connector, isReconnected }) {
console.log('Connected', { address, connector, isReconnected })
},
})
}
```

### onDisconnect (optional)

Function to invoke when account disconnects.

```tsx {5-7}
import { useAccount } from '@wagmi/solid'

function App() {
const account = useAccount({
onDisconnect() {
console.log('Disconnected')
},
})
}
```
Loading