Skip to content

Commit 1ff5f2d

Browse files
authored
feat: accounts sdk docs (#219)
* wip * accounts docs: guides sidebar, update deps, vocs Amp-Thread-ID: https://ampcode.com/threads/T-019d6176-f3a7-71b8-a7e9-3fc5fbf3911a * wip Amp-Thread-ID: https://ampcode.com/threads/T-019d6478-0703-7239-b479-27de573344e6 * accounts: remove WebAuthnCeremony.local, fix guide links, rename adapter to connector Amp-Thread-ID: https://ampcode.com/threads/T-019d652c-8d5d-723f-9b1a-41076bcc23ba * fix: import Expiry, Dialog, WebAuthnCeremony from accounts instead of accounts/wagmi Amp-Thread-ID: https://ampcode.com/threads/T-019d652c-8d5d-723f-9b1a-41076bcc23ba * fix: update gitpick examples to tempoxyz/accounts repo Amp-Thread-ID: https://ampcode.com/threads/T-019d652c-8d5d-723f-9b1a-41076bcc23ba * accounts: polish getting started, examples table, remove connectors overview, use /auth Amp-Thread-ID: https://ampcode.com/threads/T-019d652c-8d5d-723f-9b1a-41076bcc23ba * accounts: add quick prompt, examples table, getting help section Amp-Thread-ID: https://ampcode.com/threads/T-019d652c-8d5d-723f-9b1a-41076bcc23ba
1 parent 7d3c640 commit 1ff5f2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3979
-1010
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@vercel/analytics": "^1.6.1",
2121
"@vercel/speed-insights": "^1.3.1",
2222
"abitype": "^1.2.3",
23+
"accounts": "^0.4.23",
2324
"cva": "1.0.0-beta.4",
2425
"mermaid": "^11.12.2",
2526
"monaco-editor": "^0.55.1",
@@ -33,10 +34,9 @@
3334
"sql-formatter": "^15.7.0",
3435
"tailwind-merge": "^3.4.0",
3536
"tailwindcss": "^4.1.18",
36-
"tempo.ts": "^0.14.0",
3737
"unplugin-auto-import": "^21.0.0",
3838
"unplugin-icons": "^23.0.1",
39-
"viem": "^2.47.5",
39+
"viem": "^2.47.10",
4040
"vocs": "https://pkg.pr.new/vocs@70a7c8c",
4141
"wagmi": "^3.5.0",
4242
"waku": "1.0.0-alpha.4",
@@ -54,7 +54,8 @@
5454
"tsx": "^4.21.0",
5555
"typescript": "^5.9.3",
5656
"use-sync-external-store": "^1.6.0",
57-
"vite": "^7.3.1"
57+
"vite": "^7.3.1",
58+
"vite-plugin-mkcert": "^1.17.10"
5859
},
5960
"devEngines": {
6061
"runtime": {

pnpm-lock.yaml

Lines changed: 613 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ patchedDependencies:
33
dayjs@1.11.19: patches/dayjs@1.11.19.patch
44

55
minimumReleaseAge: 1440
6+
minimumReleaseAgeExclude:
7+
- accounts
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use client'
2+
import { useConnect, useConnection, useConnectors, useDisconnect } from 'wagmi'
3+
import { Button } from './Demo'
4+
5+
export function AccountsSignIn() {
6+
const account = useConnection()
7+
const connect = useConnect()
8+
const disconnect = useDisconnect()
9+
const connector = useTempoWalletConnector()
10+
11+
if (!connector) return null
12+
13+
if (account.address)
14+
return (
15+
<div className="flex items-center gap-2">
16+
<Button onClick={() => disconnect.disconnect()} variant="destructive">
17+
Sign out
18+
</Button>
19+
</div>
20+
)
21+
22+
if (connect.isPending)
23+
return (
24+
<div>
25+
<Button disabled>Check prompt</Button>
26+
</div>
27+
)
28+
29+
return (
30+
<div className="flex gap-1">
31+
<Button variant="accent" onClick={() => connect.connect({ connector })} type="button">
32+
Sign in
33+
</Button>
34+
</div>
35+
)
36+
}
37+
38+
function useTempoWalletConnector() {
39+
const connectors = useConnectors()
40+
return connectors.find((c) => c.id === 'xyz.tempo')
41+
}

src/components/guides/CreatePasskeyAccount.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/components/guides/Demo.tsx

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from 'react'
55
import type { Address, BaseError } from 'viem'
66
import { formatUnits } from 'viem'
77
import { tempoModerato } from 'viem/chains'
8-
import { useAccount, useConnect, useConnections, useConnectors, useDisconnect } from 'wagmi'
8+
import { useAccount, useConnect, useConnections, useDisconnect } from 'wagmi'
99
import { Hooks } from 'wagmi/tempo'
1010
import LucideCheck from '~icons/lucide/check'
1111
import LucideCopy from '~icons/lucide/copy'
@@ -15,6 +15,7 @@ import LucideRotateCcw from '~icons/lucide/rotate-ccw'
1515
import LucideWalletCards from '~icons/lucide/wallet-cards'
1616
import { cva, cx } from '../../../cva.config'
1717
import { usePostHogTracking } from '../../lib/posthog'
18+
import { useTempoWalletConnector } from '../../wagmi.config'
1819
import { Container as ParentContainer } from '../Container'
1920
import { alphaUsd } from './tokens'
2021

@@ -23,15 +24,6 @@ export { alphaUsd, betaUsd, pathUsd, thetaUsd } from './tokens'
2324
export const FAKE_RECIPIENT = '0xbeefcafe54750903ac1c8909323af7beb21ea2cb'
2425
export const FAKE_RECIPIENT_2 = '0xdeadbeef54750903ac1c8909323af7beb21ea2cb'
2526

26-
export function useWebAuthnConnector() {
27-
const connectors = useConnectors()
28-
return React.useMemo(
29-
// biome-ignore lint/style/noNonNullAssertion: webAuthn connector always defined in wagmi.config.ts
30-
() => connectors.find((connector) => connector.id === 'webAuthn')!,
31-
[connectors],
32-
)
33-
}
34-
3527
function getExplorerHost() {
3628
const { VITE_TEMPO_ENV, VITE_EXPLORER_OVERRIDE } = import.meta.env
3729

@@ -117,12 +109,16 @@ export function Container(
117109
if (!source) return address
118110

119111
if (source === 'webAuthn') {
120-
const webAuthnConnection = connections.find((c) => c.connector.id === 'webAuthn')
112+
const webAuthnConnection = connections.find(
113+
(c) => c.connector.id === 'webAuthn' || c.connector.id === 'xyz.tempo',
114+
)
121115
return webAuthnConnection?.accounts[0]
122116
}
123117

124118
if (source === 'wallet') {
125-
const walletConnection = connections.find((c) => c.connector.id !== 'webAuthn')
119+
const walletConnection = connections.find(
120+
(c) => c.connector.id !== 'webAuthn' && c.connector.id !== 'xyz.tempo',
121+
)
126122
return walletConnection?.accounts[0]
127123
}
128124

@@ -363,7 +359,7 @@ export namespace StringFormatter {
363359

364360
export function Login() {
365361
const connect = useConnect()
366-
const connector = useWebAuthnConnector()
362+
const connector = useTempoWalletConnector()
367363

368364
return (
369365
<div>
@@ -373,32 +369,14 @@ export function Login() {
373369
Check prompt
374370
</Button>
375371
) : (
376-
<div className="flex gap-1">
377-
<Button
378-
variant="accent"
379-
className="font-normal text-[14px] -tracking-[2%]"
380-
onClick={() => connect.connect({ connector })}
381-
type="button"
382-
>
383-
Sign in
384-
</Button>
385-
<Button
386-
variant="default"
387-
className="font-normal text-[14px] -tracking-[2%]"
388-
onClick={() =>
389-
connect.connect({
390-
connector,
391-
capabilities: {
392-
label: 'Tempo Docs',
393-
type: 'sign-up',
394-
},
395-
})
396-
}
397-
type="button"
398-
>
399-
Sign up
400-
</Button>
401-
</div>
372+
<Button
373+
variant="accent"
374+
className="font-normal text-[14px] -tracking-[2%]"
375+
onClick={() => connect.connect({ connector })}
376+
type="button"
377+
>
378+
Sign in
379+
</Button>
402380
)}
403381
</div>
404382
)

src/components/guides/EmbedPasskeys.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22
import { useAccount, useConnect, useDisconnect } from 'wagmi'
3-
import { Button, useWebAuthnConnector } from './Demo'
3+
import { useWebAuthnConnector } from '../../wagmi.config'
4+
import { Button } from './Demo'
45

56
export function EmbedPasskeys() {
67
const account = useAccount()

src/components/guides/steps/wallet/AddFundsToWallet.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import type { DemoStepProps } from '../types'
1414
export function AddFundsToWallet(props: DemoStepProps) {
1515
const { stepNumber = 2, last = false } = props
1616
const { address, connector } = useConnection()
17-
const hasNonWebAuthnWallet = Boolean(address && connector?.id !== 'webAuthn')
17+
const hasNonWebAuthnWallet = Boolean(
18+
address && connector?.id !== 'webAuthn' && connector?.id !== 'xyz.tempo',
19+
)
1820
const queryClient = useQueryClient()
1921

2022
const { data: balance, refetch: balanceRefetch } = Hooks.token.useGetBalance({

src/components/guides/steps/wallet/AddTokensToWallet.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function AddTokenButton(props: {
5858
export function AddTokensToWallet(props: DemoStepProps) {
5959
const { stepNumber = 3, last = false } = props
6060
const { address, connector } = useConnection()
61-
const hasNonWebAuthnWallet = Boolean(address && connector?.id !== 'webAuthn')
61+
const hasNonWebAuthnWallet = Boolean(
62+
address && connector?.id !== 'webAuthn' && connector?.id !== 'xyz.tempo',
63+
)
6264

6365
const [addedTokens, setAddedTokens] = React.useState<Set<string>>(new Set())
6466
const [expanded, setExpanded] = React.useState(false)

src/components/guides/steps/wallet/SetFeeToken.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const DEFAULT_FEE_TOKEN_OPTION = FEE_TOKEN_OPTIONS[0]
2727
export function SetFeeToken(props: DemoStepProps) {
2828
const { stepNumber = 1 } = props
2929
const { address, connector } = useConnection()
30-
const hasNonWebAuthnWallet = Boolean(address && connector?.id !== 'webAuthn')
30+
const hasNonWebAuthnWallet = Boolean(
31+
address && connector?.id !== 'webAuthn' && connector?.id !== 'xyz.tempo',
32+
)
3133
const chainId = useChainId()
3234
const config = useConfig()
3335

0 commit comments

Comments
 (0)