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

@wagmi/svelte #4365

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8f18445
feat: init svelte
ByteAtATime Oct 22, 2024
acb9888
feat: configure tests for svelte
ByteAtATime Oct 22, 2024
40a8cdb
feat: add useConfig hook
ByteAtATime Oct 24, 2024
15df9ea
ci: ignore .svelte files
ByteAtATime Oct 24, 2024
993c5c3
feat: add WagmiProvider component
ByteAtATime Oct 24, 2024
5d20e42
fix: add "@wagmi/svelte" prefix to version
ByteAtATime Oct 24, 2024
5ea08c3
test: add tests for version
ByteAtATime Oct 24, 2024
b2bdb19
test: add tests for errors
ByteAtATime Oct 24, 2024
a8894cf
refactor: use RuneReturnType instead of () => T
ByteAtATime Oct 24, 2024
0e5c463
refactor: use RuneParameters type for parameters
ByteAtATime Oct 24, 2024
c9241f0
feat: create `readParameters` function
ByteAtATime Oct 24, 2024
80f0e88
test: refactor svelte tests into packages/svelte folder
ByteAtATime Oct 24, 2024
a2f270d
feat: add useChainId
ByteAtATime Oct 25, 2024
30a9574
feat: add useChainId hook
ByteAtATime Oct 25, 2024
520af73
feat: add useWatchBlockNumber hook
ByteAtATime Oct 25, 2024
d3b838c
feat: remove non-function parameter option
ByteAtATime Oct 25, 2024
1dcdbef
feat: add useBlockNumber hook
ByteAtATime Oct 25, 2024
663e516
feat: add useBalance hook
ByteAtATime Oct 26, 2024
5af6c65
refactor: change `useBlockNumber` to use the same custom `createQuery…
ByteAtATime Oct 26, 2024
35e0c55
Merge branch 'wevm:main' into feat/svelte
ByteAtATime Oct 26, 2024
4fe43d0
feat: useChains hook
ByteAtATime Oct 28, 2024
5f2b8b7
feat: useReadContract hook
ByteAtATime Oct 28, 2024
f2becb9
feat: ReadContract playground
ByteAtATime Oct 29, 2024
db8bbd6
feat: useConnections hook
ByteAtATime Oct 29, 2024
b217be9
fix: remove "use client" from svelte hook
ByteAtATime Oct 29, 2024
1f371ca
feat: useConnectors hook
ByteAtATime Oct 29, 2024
ddd909f
feat: useAccount hook
ByteAtATime Oct 29, 2024
4be7ddd
feat; useConnect hook
ByteAtATime Oct 29, 2024
a8ae0fb
refactor: formatting
ByteAtATime Oct 29, 2024
072a84f
feat: add useAccount to playground
ByteAtATime Oct 29, 2024
c0bfcff
refactor: remove unused imports in +page.svelte
ByteAtATime Oct 29, 2024
92d0400
feat: useDisconnect hook
ByteAtATime Oct 29, 2024
b772015
fix: don't get context when parameters change
ByteAtATime Oct 29, 2024
a83c89e
refactor: remove unused imports in useConfig.svelte.ts
ByteAtATime Oct 29, 2024
1694af7
feat: add optimism chain support in +layout.svelte
ByteAtATime Oct 29, 2024
e9eb337
feat: add Balance, BlockNumber, and Connections components playground
ByteAtATime Oct 29, 2024
3578f1a
feat: add viem as peerDep
ByteAtATime Oct 30, 2024
9453e6e
docs: add basic svelte documentation
ByteAtATime Oct 31, 2024
310f3b4
feat: export chains & hooks
ByteAtATime Oct 31, 2024
aa07613
fix: don't throw early if missing Wagmi context
ByteAtATime Oct 31, 2024
93eca29
feat: useEnsName hook
ByteAtATime Oct 31, 2024
17c34c4
feat: add ens name in playground
ByteAtATime Oct 31, 2024
ca097fb
feat; useSwitchAccount hook
ByteAtATime Oct 31, 2024
4242d66
feat: add SwitchAccount component to playground
ByteAtATime Oct 31, 2024
9a59af0
feat: useSwitchChain hook
ByteAtATime Oct 31, 2024
cda9ce7
feat: add SwitchChain component to playground
ByteAtATime Oct 31, 2024
e3ae569
feat: useSignMessage hook
ByteAtATime Oct 31, 2024
1e98452
feat: add SignMessage component to playground
ByteAtATime Oct 31, 2024
bdc6457
feat: useWriteContract hook
ByteAtATime Oct 31, 2024
dda0aca
feat: useWaitForTransactionReceipt hook
ByteAtATime Oct 31, 2024
0de269a
feat: add WriteContract component to playground
ByteAtATime Oct 31, 2024
40d9799
feat: useSendTransaction hook
ByteAtATime Nov 1, 2024
df90bbe
feat: add SendTransaction component to playground
ByteAtATime Nov 1, 2024
a45dbaf
refactor: formatting
ByteAtATime Nov 1, 2024
9d5e06d
fix: actually add SendTransaction to playground
ByteAtATime Nov 1, 2024
3ab060d
feat: useReadContracts hook
ByteAtATime Nov 1, 2024
cb934d1
feat: add ReadContracts component to playground
ByteAtATime Nov 1, 2024
7e731ca
feat: useAccountEffect hook
ByteAtATime Nov 1, 2024
c29735c
feat: useEsnAvatar hook
ByteAtATime Nov 5, 2024
a3137dd
feat: useGasPrice hook
ByteAtATime Nov 5, 2024
bf9220a
test: overhaul testing system
ByteAtATime Nov 10, 2024
2c96b38
chore: consolidate gitignore and npmrc
ByteAtATime Nov 11, 2024
df5a521
docs: replace readme
ByteAtATime Nov 11, 2024
e986dc0
feat: move playground into a seperate folder
ByteAtATime Nov 11, 2024
2917d42
refactor: change svelte folders to align with other projects
ByteAtATime Nov 11, 2024
9d2c30a
deps: remove eslint-related packages
ByteAtATime Nov 11, 2024
a8d8df8
deps: use * instead of ^ for workspace
ByteAtATime Nov 11, 2024
de9b8d8
test: refactor test snapshots
ByteAtATime Nov 12, 2024
fe4fcc5
test: remove duplicate setup files from svelte local config
ByteAtATime Nov 12, 2024
ffb16a1
test: move testing system to @wagmi/test/svelte
ByteAtATime Nov 12, 2024
bd3b925
docs: correct installation instructions to install @wagmi/svelte
ByteAtATime Nov 13, 2024
d5e6ff4
Merge branch 'main' into feat/svelte
ByteAtATime Nov 18, 2024
c489000
deps: update pnpm-lock.yaml
ByteAtATime Nov 18, 2024
b48d6d2
Merge branch 'wevm:main' into feat/svelte
ByteAtATime Dec 6, 2024
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ packages/vue/chains
packages/vue/connectors
packages/vue/nuxt
packages/vue/query
packages/svelte/.svelte-kit
5 changes: 4 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"lineWidth": 80
},
"linter": {
"ignore": ["packages/create-wagmi/templates/*"],
"ignore": [
"packages/create-wagmi/templates/*",
"packages/svelte/**/*.svelte"
],
"enabled": true,
"rules": {
"recommended": true,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dev:nuxt": "pnpm --filter nuxt-app dev",
"dev:react": "pnpm --filter vite-react dev",
"dev:vue": "pnpm --filter vite-vue dev",
"dev:svelte": "pnpm --filter svelte dev",
"docs:dev": "pnpm --filter site dev",
"check": "biome check --write",
"check:repo": "sherif -i viem",
Expand All @@ -37,6 +38,7 @@
"test:update": "vitest --update",
"test:ui": "vitest --ui",
"test:vue": "vitest --project @wagmi/vue",
"test:svelte": "pnpm --filter svelte test",
"version:update": "bun scripts/updateVersion.ts",
"version:update:viem": "bun scripts/updateViemVersion.ts"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/svelte/.gitignore
ByteAtATime marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules

# Output
.output
.vercel
/.svelte-kit
/build
/dist

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions packages/svelte/.npmrc
ByteAtATime marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
4 changes: 4 additions & 0 deletions packages/svelte/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Package Managers
package-lock.json
pnpm-lock.yaml
yarn.lock
15 changes: 15 additions & 0 deletions packages/svelte/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
}
]
}
58 changes: 58 additions & 0 deletions packages/svelte/README.md
ByteAtATime marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# create-svelte

Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```bash
# create a new project in the current directory
npx sv create

# create a new project in my-app
npx sv create my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.

## Building

To build your library:

```bash
npm run package
```

To create a production version of your showcase app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

## Publishing

Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).

To publish your library to [npm](https://www.npmjs.com):

```bash
npm publish
```
33 changes: 33 additions & 0 deletions packages/svelte/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import js from '@eslint/js'
import prettier from 'eslint-config-prettier'
import svelte from 'eslint-plugin-svelte'
import globals from 'globals'
import ts from 'typescript-eslint'

export default ts.config(
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs['flat/recommended'],
prettier,
...svelte.configs['flat/prettier'],
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
},
{
files: ['**/*.svelte'],

languageOptions: {
parserOptions: {
parser: ts.parser,
},
},
},
{
ignores: ['build/', '.svelte-kit/', 'dist/'],
},
)
63 changes: 63 additions & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@wagmi/svelte",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build && npm run package",
"preview": "vite preview",
"package": "svelte-kit sync && svelte-package && publint",
"prepublishOnly": "npm run package",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint . && prettier --check .",
"format": "prettier --write .",
"test:unit": "vitest",
"test": "pnpm run test:unit -- --run --watch"
},
"files": ["dist", "!dist/**/*.test.*", "!dist/**/*.spec.*"],
"sideEffects": ["**/*.css"],
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
},
"./chains": {
"types": "./dist/exports/chains.d.ts",
"default": "./dist/exports/chains.js"
}
},
"peerDependencies": {
"@tanstack/svelte-query": "https://pkg.pr.new/@tanstack/svelte-query@ccce0b8",
"viem": "2.x",
"svelte": "^5.0.0"
},
"devDependencies": {
ByteAtATime marked this conversation as resolved.
Show resolved Hide resolved
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/package": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tanstack/svelte-query": "https://pkg.pr.new/@tanstack/svelte-query@ccce0b8",
"@types/eslint": "^9.6.0",
"@wagmi/test": "workspace:^",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.6",
"publint": "^0.2.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^5.0.11",
"vitest": "^2.0.4"
},
"dependencies": {
"@wagmi/connectors": "workspace:^",
"@wagmi/core": "workspace:^"
}
}
15 changes: 15 additions & 0 deletions packages/svelte/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// See https://svelte.dev/docs/kit/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}

const __VERSION__: string
}

export {}
12 changes: 12 additions & 0 deletions packages/svelte/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div>%sveltekit.body%</div>
</body>
</html>
43 changes: 43 additions & 0 deletions packages/svelte/src/lib/WagmiProvider.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import { type ResolvedRegister, type State, hydrate } from '@wagmi/core'
import type { Snippet } from 'svelte'
import { setWagmiConfig } from './context.js'

type WagmiProviderProps = {
children: Snippet
config: ResolvedRegister['config']
initialState?: State | undefined
reconnectOnMount?: boolean | undefined
}

const {
children,
config,
initialState,
reconnectOnMount = true,
}: WagmiProviderProps = $props()

const { onMount } = hydrate(config, {
initialState,
reconnectOnMount,
})

setWagmiConfig(config)

if (!config._internal.ssr) onMount()

let active = $state(true)

$effect(() => {
if (!active) return
if (!config._internal.ssr) return

onMount()

return () => {
active = false
}
})
</script>

{@render children()}
15 changes: 15 additions & 0 deletions packages/svelte/src/lib/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ResolvedRegister } from '@wagmi/core'
import { getContext, setContext } from 'svelte'

type ContextConfig = ResolvedRegister['config']
const WAGMI_CONFIG_KEY = Symbol('WAGMI_CONFIG')

export const getWagmiConfig = (): ContextConfig => {
const client = getContext<ContextConfig>(WAGMI_CONFIG_KEY)

return client
}

export const setWagmiConfig = (config: ContextConfig) => {
setContext(WAGMI_CONFIG_KEY, config)
}
Loading