Skip to content

Commit

Permalink
feat: basic working sveltekit
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanaden committed Sep 23, 2024
1 parent d8a8243 commit b3dbbef
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 13 deletions.
6 changes: 4 additions & 2 deletions examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"dependencies": {
"@solana-wallets-solid/core": "workspace:*",
"@solana-wallets-solid/unified": "workspace:*",
"@solana-wallets-solid/unified": "workspace:*"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
Expand Down
50 changes: 50 additions & 0 deletions examples/sveltekit/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script lang="ts">
import { initStore } from "@solana-wallets-solid/core"
import { onMount, setContext } from "svelte"
import "@solana-wallets-solid/unified/index.css"
const {
$env: env,
$wallet: wallet,
$wallets: wallets,
$connecting: connecting,
$walletsMap: walletsMap,
initOnMount,
signMessage,
$isConnected: isConnected,
$disconnecting: disconnecting,
$connectedAccount: connectedAccount,
sendTransactionV1,
signTransactionV1,
signAllTransactionsV1,
getTransactionSendingSigner,
} = initStore({ autoConnect: true, disconnectOnAccountChange: true })
onMount(() => {
const cleanup = initOnMount()
return cleanup
})
setContext("unified", {
env,
wallet,
connectedAccount,
wallets,
walletsMap,
connecting,
disconnecting,
signMessage,
signTransactionV1,
signAllTransactionsV1,
sendTransactionV1,
getTransactionSendingSigner,
})
onMount(() => {
import("@solana-wallets-solid/unified").then(r => r.loadCustomElements())
})
</script>

<unified-wallet-modal />

<slot />
6 changes: 6 additions & 0 deletions examples/sveltekit/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<script lang="ts">
import Button from "./button.svelte"
</script>

<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>

<Button />
1 change: 1 addition & 0 deletions examples/sveltekit/src/routes/button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<unified-wallet-modal-button />
1 change: 1 addition & 0 deletions examples/sveltekit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"module": "esnext",
"target": "es2017",
Expand Down
23 changes: 13 additions & 10 deletions packages/react/src/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export type WalletContext = {
connecting: ReturnType<ReturnType<typeof initStore>["$connecting"]["get"]>
disconnecting: ReturnType<ReturnType<typeof initStore>["$disconnecting"]["get"]>
signMessage: ReturnType<typeof initStore>["signMessage"]
signTransaction: ReturnType<typeof initStore>["signTransaction"]
signAllTransactions: ReturnType<typeof initStore>["signAllTransactions"]
sendTransaction: ReturnType<typeof initStore>["sendTransaction"]
signTransactionV1: ReturnType<typeof initStore>["signTransactionV1"]
signAllTransactionsV1: ReturnType<typeof initStore>["signAllTransactionsV1"]
sendTransactionV1: ReturnType<typeof initStore>["sendTransactionV1"]
getTransactionSendingSigner: ReturnType<typeof initStore>["getTransactionSendingSigner"]
}
const WalletContext = createContext<WalletContext>({} as WalletContext)

Expand All @@ -37,10 +38,11 @@ const {
$wallets,
$walletsMap,
signMessage,
sendTransaction,
signTransaction,
signAllTransactions,
} = initStore()
signTransactionV1,
signAllTransactionsV1,
sendTransactionV1,
getTransactionSendingSigner,
} = initStore({ autoConnect: true, disconnectOnAccountChange: true })

const WalletProvider: React.FC<WalletProviderProps> = ({ children, ...config }) => {
const wallets = useStore($wallets)
Expand Down Expand Up @@ -69,9 +71,10 @@ const WalletProvider: React.FC<WalletProviderProps> = ({ children, ...config })
connecting,
disconnecting,
signMessage,
signTransaction,
signAllTransactions,
sendTransaction,
signTransactionV1,
signAllTransactionsV1,
sendTransactionV1,
getTransactionSendingSigner,
}}
>
{children}
Expand Down
3 changes: 2 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3dbbef

Please sign in to comment.