@zerodev/wallet-react-ui 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -7
- package/dist/_types/auth/brandAssets.d.ts +2 -0
- package/dist/_types/auth/brandAssets.d.ts.map +1 -0
- package/dist/_types/auth/components/WalletSheet/index.d.ts +20 -0
- package/dist/_types/auth/components/WalletSheet/index.d.ts.map +1 -0
- package/dist/_types/auth/hooks/useWalletConnectPairing.d.ts +19 -0
- package/dist/_types/auth/hooks/useWalletConnectPairing.d.ts.map +1 -0
- package/dist/_types/auth/hooks/useWalletInfo.d.ts +32 -0
- package/dist/_types/auth/hooks/useWalletInfo.d.ts.map +1 -0
- package/dist/_types/auth/pages/SignUp/MoreWallets.d.ts.map +1 -1
- package/dist/_types/auth/pages/SignUp/Wallet.d.ts.map +1 -1
- package/dist/_types/auth/pages/SignUp/WalletConnect.d.ts +5 -0
- package/dist/_types/auth/pages/SignUp/WalletConnect.d.ts.map +1 -0
- package/dist/_types/auth/pages/SignUp/context.d.ts +4 -0
- package/dist/_types/auth/pages/SignUp/context.d.ts.map +1 -1
- package/dist/_types/auth/pages/SignUp/index.d.ts +2 -0
- package/dist/_types/auth/pages/SignUp/index.d.ts.map +1 -1
- package/dist/_types/auth/utils/isMobile.d.ts +2 -0
- package/dist/_types/auth/utils/isMobile.d.ts.map +1 -0
- package/dist/_types/auth/utils/isZeroDevWalletConnect.d.ts +6 -0
- package/dist/_types/auth/utils/isZeroDevWalletConnect.d.ts.map +1 -0
- package/dist/_types/auth/utils/walletDeepLink.d.ts +18 -0
- package/dist/_types/auth/utils/walletDeepLink.d.ts.map +1 -0
- package/dist/_types/auth/walletGuide.d.ts +21 -3
- package/dist/_types/auth/walletGuide.d.ts.map +1 -1
- package/dist/_types/index.d.ts +3 -0
- package/dist/_types/index.d.ts.map +1 -1
- package/dist/_types/zeroDevWalletConnect.d.ts +13 -0
- package/dist/_types/zeroDevWalletConnect.d.ts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1009 -659
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -5
- package/src/assets.d.ts +5 -0
- package/src/auth/brandAssets.ts +5 -0
- package/src/auth/components/WalletSheet/index.tsx +220 -0
- package/src/auth/hooks/useWalletConnectPairing.ts +134 -0
- package/src/auth/hooks/useWalletInfo.ts +145 -0
- package/src/auth/pages/SignUp/InstalledWallets.tsx +1 -1
- package/src/auth/pages/SignUp/MoreWallets.tsx +44 -9
- package/src/auth/pages/SignUp/Wallet.tsx +43 -13
- package/src/auth/pages/SignUp/WalletConnect.tsx +32 -0
- package/src/auth/pages/SignUp/context.tsx +4 -0
- package/src/auth/pages/SignUp/index.tsx +31 -0
- package/src/auth/utils/isMobile.ts +9 -0
- package/src/auth/utils/isZeroDevWalletConnect.ts +8 -0
- package/src/auth/utils/walletDeepLink.ts +23 -0
- package/src/auth/walletGuide.ts +42 -8
- package/src/index.ts +7 -2
- package/src/zeroDevWalletConnect.ts +95 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { CreateConnectorFn } from 'wagmi'
|
|
2
|
+
import { type WalletConnectParameters, walletConnect } from 'wagmi/connectors'
|
|
3
|
+
import { isMobile } from './auth/utils/isMobile'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* localStorage key `@walletconnect/sign-client` reads before publishing each
|
|
7
|
+
* session request — when set, the SDK deep-links back into the chosen wallet
|
|
8
|
+
* app (`{href}/wc?requestId=…&sessionTopic=…`) so the approval prompt is in
|
|
9
|
+
* front of the user. Same key AppKit writes; the SDK no-ops when it's absent.
|
|
10
|
+
*/
|
|
11
|
+
const DEEPLINK_CHOICE_KEY = 'WALLETCONNECT_DEEPLINK_CHOICE'
|
|
12
|
+
|
|
13
|
+
/** The slice of `@walletconnect/ethereum-provider` this module touches. */
|
|
14
|
+
type WcSessionProvider = {
|
|
15
|
+
on: (event: 'connect' | 'disconnect', listener: () => void) => unknown
|
|
16
|
+
session?: {
|
|
17
|
+
peer?: {
|
|
18
|
+
metadata?: { name?: string; redirect?: { native?: string } }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const watched = new WeakSet<object>()
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Arm the SDK's redirect-on-request with the connected wallet's own
|
|
27
|
+
* registered scheme (`session.peer.metadata.redirect.native`) — authoritative
|
|
28
|
+
* for whichever wallet actually claimed the pairing. Desktop sessions and
|
|
29
|
+
* wallets that register no native redirect stay unarmed.
|
|
30
|
+
*/
|
|
31
|
+
function storeDeepLinkChoice(provider: WcSessionProvider) {
|
|
32
|
+
const metadata = provider.session?.peer?.metadata
|
|
33
|
+
const href = metadata?.redirect?.native
|
|
34
|
+
if (!href || !isMobile()) {
|
|
35
|
+
clearDeepLinkChoice()
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
localStorage.setItem(
|
|
40
|
+
DEEPLINK_CHOICE_KEY,
|
|
41
|
+
JSON.stringify({ href, name: metadata?.name ?? '' }),
|
|
42
|
+
)
|
|
43
|
+
} catch {
|
|
44
|
+
// Storage unavailable — requests still work, minus the app hop.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function clearDeepLinkChoice() {
|
|
49
|
+
try {
|
|
50
|
+
localStorage.removeItem(DEEPLINK_CHOICE_KEY)
|
|
51
|
+
} catch {
|
|
52
|
+
// Nothing to clear if storage is unavailable.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function watchSession(provider: WcSessionProvider) {
|
|
57
|
+
if (watched.has(provider)) return
|
|
58
|
+
watched.add(provider)
|
|
59
|
+
provider.on('connect', () => storeDeepLinkChoice(provider))
|
|
60
|
+
// A stale choice would deep-link a future session to the wrong app.
|
|
61
|
+
provider.on('disconnect', clearDeepLinkChoice)
|
|
62
|
+
// Session restored from storage (page reload) — re-arm without an event.
|
|
63
|
+
if (provider.session) storeDeepLinkChoice(provider)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* WalletConnect connector preconfigured for the kit. `showQrModal: false` is
|
|
68
|
+
* required — the kit renders its own pairing UI, and WalletConnect's bundled
|
|
69
|
+
* Reown modal would pop over it otherwise. All other WalletConnect
|
|
70
|
+
* parameters (e.g. `metadata`) are forwarded as-is.
|
|
71
|
+
*
|
|
72
|
+
* The kit only pairs through connectors created here — a raw `walletConnect()`
|
|
73
|
+
* in the config is ignored, since its `showQrModal` can't be read back.
|
|
74
|
+
*/
|
|
75
|
+
export function zeroDevWalletConnect(
|
|
76
|
+
params: Omit<WalletConnectParameters, 'showQrModal'>,
|
|
77
|
+
): CreateConnectorFn {
|
|
78
|
+
if (!params.projectId) {
|
|
79
|
+
throw new Error('zeroDevWalletConnect requires a WalletConnect projectId')
|
|
80
|
+
}
|
|
81
|
+
const create = walletConnect({ ...params, showQrModal: false })
|
|
82
|
+
return (config) => {
|
|
83
|
+
// Stamp the connector instance so the kit's discovery can tell a
|
|
84
|
+
// correctly-configured connector from a raw walletConnect(), where
|
|
85
|
+
// showQrModal defaults to true.
|
|
86
|
+
const connector = Object.assign(create(config), { zdWalletConnect: true })
|
|
87
|
+
const getProvider = connector.getProvider.bind(connector)
|
|
88
|
+
connector.getProvider = async (...args: Parameters<typeof getProvider>) => {
|
|
89
|
+
const provider = await getProvider(...args)
|
|
90
|
+
watchSession(provider as WcSessionProvider)
|
|
91
|
+
return provider
|
|
92
|
+
}
|
|
93
|
+
return connector
|
|
94
|
+
}
|
|
95
|
+
}
|