Skip to content

Commit 267aa5d

Browse files
authored
Add render inline option and onConnectSuccess callback (#547)
1 parent 7868a7e commit 267aa5d

File tree

15 files changed

+561
-119
lines changed

15 files changed

+561
-119
lines changed

MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ie.
3434
- `SequenceWalletProvider` (previously KitWalletProvider)
3535
- `SequenceHooksProvider`
3636

37-
Also for builder integration KitPreviewProvider was renamed `SequenceConnectPreviewProvider`
37+
Also for builder integration KitPreviewProvider was renamed `SequenceConnectInlineProvider`
3838

3939
### Hooks
4040

examples/react/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom'
55

66
import { Homepage } from './components/Homepage'
77
import { ImmutableCallback } from './components/ImmutableCallback'
8+
import { InlineDemo } from './components/InlineDemo'
89
import { XAuthCallback } from './components/XAuthCallback'
910
import { checkoutConfig, config } from './config'
1011

@@ -16,6 +17,7 @@ export const App = () => {
1617
<BrowserRouter>
1718
<Routes>
1819
<Route path="/" element={<Homepage />} />
20+
<Route path="/inline" element={<InlineDemo />} />
1921
<Route path="/auth-callback" element={<ImmutableCallback />} />
2022
<Route path="/auth-callback-X" element={<XAuthCallback />} />
2123
</Routes>

examples/react/src/components/Homepage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useOpenConnectModal, useWallets, WalletType } from '@0xsequence/connect
22
import { Button, Card, CheckmarkIcon, Image, Text } from '@0xsequence/design-system'
33
import { clsx } from 'clsx'
44
import { Footer } from 'example-shared-components'
5+
import { Link } from 'react-router-dom'
56

67
import { Connected } from './Connected'
78

@@ -34,6 +35,9 @@ export const Homepage = () => {
3435

3536
<div className="flex gap-2 flex-row items-center">
3637
<Button onClick={onClickConnect} variant="feature" label="Connect" />
38+
<Link to="/inline">
39+
<Button variant="primary" label="Inline Demo" />
40+
</Link>
3741
</div>
3842

3943
<div className="flex gap-2 flex-col px-4 mt-10 w-full max-w-[480px]">
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { SequenceConnectInline, type SequenceConnectConfig } from '@0xsequence/connect'
2+
import { Text } from '@0xsequence/design-system'
3+
import { Footer } from 'example-shared-components'
4+
import { useMemo } from 'react'
5+
import { useNavigate } from 'react-router-dom'
6+
7+
import { config } from '../config'
8+
9+
export const InlineDemo = () => {
10+
const navigate = useNavigate()
11+
12+
const inlineConfig: SequenceConnectConfig = useMemo(
13+
() => ({
14+
...config,
15+
connectConfig: {
16+
...config.connectConfig,
17+
onConnectSuccess: (address: string) => {
18+
console.log('Connected successfully with address:', address)
19+
// Redirect to homepage after successful connection
20+
navigate('/')
21+
}
22+
}
23+
}),
24+
[navigate]
25+
)
26+
27+
return (
28+
<main className="flex flex-col h-screen">
29+
<div className="flex-1 flex items-center justify-center p-8">
30+
<div className="flex flex-row gap-8 max-w-6xl w-full">
31+
{/* Left side - Description */}
32+
<div className="flex-1 flex flex-col justify-center gap-4">
33+
<Text variant="xlarge" fontWeight="bold" color="primary">
34+
Inline Connect Demo
35+
</Text>
36+
<Text variant="large" color="secondary">
37+
This demonstrates the SequenceConnectInline component, which renders the connect UI inline within your layout
38+
instead of in a modal.
39+
</Text>
40+
<Text variant="normal" color="muted">
41+
Perfect for custom layouts, embedded wallet experiences, or when you want the connect UI to be part of your page
42+
flow.
43+
</Text>
44+
<Text variant="small" color="muted" className="mt-4">
45+
Connect with your wallet and you'll be redirected to the homepage automatically.
46+
</Text>
47+
</div>
48+
49+
{/* Right side - Inline Connect UI */}
50+
<div className="flex-1 flex items-center justify-center">
51+
<div className="w-full max-w-[390px]">
52+
<SequenceConnectInline config={inlineConfig} />
53+
</div>
54+
</div>
55+
</div>
56+
</div>
57+
<Footer />
58+
</main>
59+
)
60+
}

packages/connect/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Sequence Web SDK 🧰 is a library enabling developers to easily integrate web3
66
- Connect to popular web3 wallets eg: walletConnect, metamask ! 🦊 ⛓️
77
- Full-fledged embedded wallet for coins and collectibles 👛 🖼️ 🪙
88
- Fiat onramp 💵 💶 💴 💷
9+
- Inline connect UI for custom layouts and embedded experiences 🎨
910

1011
View the [demo](https://0xsequence.github.io/web-sdk)! 👀
1112

@@ -52,6 +53,7 @@ interface CreateConfigOptions {
5253
chainId: number
5354
}>
5455
ethAuth?: EthAuthSettings
56+
onConnectSuccess?: (address: string) => void // callback fired when wallet connects
5557

5658
wagmiConfig?: WagmiConfig // optional wagmiConfig overrides
5759

@@ -243,6 +245,76 @@ const MyReactComponent = () => {
243245
}
244246
```
245247

248+
### Inline Connect UI
249+
250+
<div align="center">
251+
<img src="public/docs/inline-connect.png" alt="Inline Connect UI">
252+
</div>
253+
254+
Instead of using a modal, you can render the connect UI inline within your layout using the `SequenceConnectInline` component. This is perfect for custom layouts, embedded wallet experiences, or when you want the connect UI to be part of your page flow.
255+
256+
```js
257+
import { SequenceConnectInline, createConfig } from '@0xsequence/connect'
258+
import { useNavigate } from 'react-router-dom'
259+
260+
const config = createConfig('waas', {
261+
projectAccessKey: '<your-project-access-key>',
262+
chainIds: [1, 137],
263+
defaultChainId: 1,
264+
appName: 'Demo Dapp',
265+
waasConfigKey: '<your-waas-config-key>',
266+
267+
// Optional: callback fired when wallet connects successfully
268+
onConnectSuccess: (address) => {
269+
console.log('Connected wallet:', address)
270+
// Redirect or perform other actions
271+
},
272+
273+
google: { clientId: '<your-google-client-id>' },
274+
email: true
275+
})
276+
277+
function InlinePage() {
278+
return (
279+
<div className="my-custom-layout">
280+
<h1>Connect Your Wallet</h1>
281+
<SequenceConnectInline config={config} />
282+
</div>
283+
)
284+
}
285+
```
286+
287+
#### Key Differences from Modal UI:
288+
289+
- **No padding/margins**: The inline UI removes the default padding designed for modal display
290+
- **Full width**: The component fills its container width
291+
- **No modal backdrop**: Renders directly in your layout
292+
- **Custom positioning**: You control the placement with your own CSS/layout
293+
294+
#### Advanced: Using SequenceConnectInlineProvider
295+
296+
For more control, you can use the lower-level `SequenceConnectInlineProvider`:
297+
298+
```js
299+
import { SequenceConnectInlineProvider } from '@0xsequence/connect'
300+
import { WagmiProvider } from 'wagmi'
301+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
302+
303+
const queryClient = new QueryClient()
304+
305+
function App() {
306+
return (
307+
<WagmiProvider config={wagmiConfig}>
308+
<QueryClientProvider client={queryClient}>
309+
<SequenceConnectInlineProvider config={connectConfig}>
310+
<YourContent />
311+
</SequenceConnectInlineProvider>
312+
</QueryClientProvider>
313+
</WagmiProvider>
314+
)
315+
}
316+
```
317+
246318
## Hooks
247319

248320
### useOpenConnectModal
@@ -294,6 +366,11 @@ The settings are described in more detailed in the Sequence Web SDK documentatio
294366
}
295367
],
296368
readOnlyNetworks: [10],
369+
// callback fired when wallet connects successfully
370+
onConnectSuccess: (address) => {
371+
console.log('Wallet connected:', address)
372+
// Perform actions like redirecting, analytics tracking, etc.
373+
},
297374
}
298375

299376
<SequenceConnectProvider config={connectConfig}>

packages/connect/src/components/Connect/Connect.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const SEQUENCE_UNIVERSAL_CONNECTOR_NAME = 'Sequence'
4343
interface ConnectProps extends SequenceConnectProviderProps {
4444
emailConflictInfo?: FormattedEmailConflictInfo | null
4545
onClose: () => void
46-
isPreview?: boolean
46+
isInline?: boolean
4747
}
4848

4949
export const Connect = (props: ConnectProps) => {
@@ -52,7 +52,7 @@ export const Connect = (props: ConnectProps) => {
5252
const { analytics } = useAnalyticsContext()
5353
const { hideExternalConnectOptions, hideConnectedWallets, hideSocialConnectOptions } = useWalletSettings()
5454

55-
const { onClose, emailConflictInfo, config = {} as ConnectConfig, isPreview = false } = props
55+
const { onClose, emailConflictInfo, config = {} as ConnectConfig, isInline = false } = props
5656
const { signIn = {} } = config
5757
const storage = useStorage()
5858

@@ -256,6 +256,11 @@ export const Connect = (props: ConnectProps) => {
256256
connect(
257257
{ connector },
258258
{
259+
onSuccess: result => {
260+
if (result?.accounts[0]) {
261+
config.onConnectSuccess?.(result.accounts[0])
262+
}
263+
},
259264
onSettled: result => {
260265
setLastConnectedWallet(result?.accounts[0])
261266
}
@@ -377,14 +382,14 @@ export const Connect = (props: ConnectProps) => {
377382
: `Something went wrong. (${waasStatusData.errorResponse.msg})`
378383

379384
return (
380-
<div className="p-4">
385+
<div className={isInline ? 'p-0' : 'p-4'}>
381386
<div
382387
className="flex flex-col justify-center text-primary items-center font-medium"
383388
style={{
384-
marginTop: '2px'
389+
marginTop: isInline ? '0' : '2px'
385390
}}
386391
>
387-
<TitleWrapper isPreview={isPreview}>
392+
<TitleWrapper isInline={isInline}>
388393
<Text color="secondary">
389394
{isLoading
390395
? `Connecting...`
@@ -406,14 +411,14 @@ export const Connect = (props: ConnectProps) => {
406411
}
407412

408413
return (
409-
<div className="p-4">
414+
<div className={isInline ? 'p-0' : 'p-4'}>
410415
<div
411416
className="flex flex-col justify-center text-primary items-center font-medium"
412417
style={{
413-
marginTop: '2px'
418+
marginTop: isInline ? '0' : '2px'
414419
}}
415420
>
416-
<TitleWrapper isPreview={isPreview}>
421+
<TitleWrapper isInline={isInline}>
417422
<Text color="secondary">
418423
{isLoading
419424
? `Connecting...`
@@ -595,8 +600,8 @@ export const Connect = (props: ConnectProps) => {
595600
)
596601
}
597602

598-
const TitleWrapper = ({ children, isPreview }: { children: ReactNode; isPreview: boolean }) => {
599-
if (isPreview) {
603+
const TitleWrapper = ({ children, isInline }: { children: ReactNode; isInline: boolean }) => {
604+
if (isInline) {
600605
return <>{children}</>
601606
}
602607

packages/connect/src/components/SequenceConnectPreview/SequenceConnectPreview.tsx renamed to packages/connect/src/components/SequenceConnectInline/SequenceConnectInline.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,30 @@ import type { ReactNode } from 'react'
33
import { WagmiProvider, type State } from 'wagmi'
44

55
import type { SequenceConnectConfig } from '../../config/createConfig.js'
6-
import { SequenceConnectPreviewProvider } from '../SequenceConnectPreviewProvider/SequenceConnectPreviewProvider.js'
6+
import { SequenceConnectInlineProvider } from '../SequenceConnectInlineProvider/SequenceConnectInlineProvider.js'
77

88
const defaultQueryClient = new QueryClient()
99

10-
interface SequenceConnectPreviewProps {
10+
export interface SequenceConnectInlineProps {
1111
config: SequenceConnectConfig
1212
queryClient?: QueryClient
1313
initialState?: State | undefined
14-
children: ReactNode
14+
children?: ReactNode
1515
}
1616

1717
/**
18-
* @internal
19-
* Preview version of SequenceConnect component.
20-
* This component should only be used for testing purposes.
21-
* It provides the same functionality as SequenceConnect but only for preview purposes.
18+
* Inline version of SequenceConnect component.
19+
* This component renders the connect UI inline within your layout instead of in a modal.
20+
* Ideal for embedded wallet experiences or custom layouts.
2221
*/
23-
export const SequenceConnectPreview = (props: SequenceConnectPreviewProps) => {
22+
export const SequenceConnectInline = (props: SequenceConnectInlineProps) => {
2423
const { config, queryClient, initialState, children } = props
2524
const { connectConfig, wagmiConfig } = config
2625

2726
return (
2827
<WagmiProvider config={wagmiConfig} initialState={initialState}>
2928
<QueryClientProvider client={queryClient || defaultQueryClient}>
30-
<SequenceConnectPreviewProvider
31-
config={{
32-
...connectConfig,
33-
hideConnectedWallets: true
34-
}}
35-
>
36-
{children}
37-
</SequenceConnectPreviewProvider>
29+
<SequenceConnectInlineProvider config={connectConfig}>{children}</SequenceConnectInlineProvider>
3830
</QueryClientProvider>
3931
</WagmiProvider>
4032
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './SequenceConnectInline.js'

0 commit comments

Comments
 (0)