Skip to content

Commit fc2efa7

Browse files
authored
Merge pull request #211 from 0xsequence/v6-web-sdk-update
2 parents 3b3d713 + d0ba4d5 commit fc2efa7

32 files changed

+1550
-181
lines changed

docs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@
278278
"sdk/web/wallet-sdk/ecosystem/hooks/useOpenConnectModal",
279279
"sdk/web/wallet-sdk/ecosystem/hooks/useChain",
280280
"sdk/web/wallet-sdk/ecosystem/hooks/useFeeOptions",
281+
"sdk/web/wallet-sdk/ecosystem/hooks/useHasPermission",
282+
"sdk/web/wallet-sdk/ecosystem/hooks/useSendWalletTransaction",
281283
"sdk/web/wallet-sdk/ecosystem/hooks/useExplicitSessions",
282284
"sdk/web/wallet-sdk/ecosystem/hooks/useListAccounts",
283285
"sdk/web/wallet-sdk/ecosystem/hooks/useSignInEmail",
@@ -1288,6 +1290,8 @@
12881290
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useOpenConnectModal",
12891291
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useChain",
12901292
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useFeeOptions",
1293+
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useHasPermission",
1294+
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useSendWalletTransaction",
12911295
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useExplicitSessions",
12921296
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useListAccounts",
12931297
"ja/sdk/web/wallet-sdk/ecosystem/hooks/useSignInEmail",
@@ -2268,6 +2272,8 @@
22682272
"es/sdk/web/wallet-sdk/ecosystem/hooks/useOpenConnectModal",
22692273
"es/sdk/web/wallet-sdk/ecosystem/hooks/useChain",
22702274
"es/sdk/web/wallet-sdk/ecosystem/hooks/useFeeOptions",
2275+
"es/sdk/web/wallet-sdk/ecosystem/hooks/useHasPermission",
2276+
"es/sdk/web/wallet-sdk/ecosystem/hooks/useSendWalletTransaction",
22712277
"es/sdk/web/wallet-sdk/ecosystem/hooks/useExplicitSessions",
22722278
"es/sdk/web/wallet-sdk/ecosystem/hooks/useListAccounts",
22732279
"es/sdk/web/wallet-sdk/ecosystem/hooks/useSignInEmail",

es/sdk/web/wallet-sdk/ecosystem/getting-started.mdx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,39 @@ Primero, asegúrese de haber creado una cuenta de Sequence Project. Si aún no t
2626
<Step title="Cree su configuración de Wallet">
2727
A continuación, cree la configuración de Ecosystem Wallet.
2828

29+
**Requerido para Ecosystem Wallet**
30+
31+
- `projectAccessKey`
32+
- `walletUrl`
33+
34+
**Opcional**
35+
36+
- `dappOrigin`
37+
- `signIn.projectName`, `appName`
38+
- `chainIds`, `defaultChainId`
39+
- `explicitSessionParams` (opcional; `nativeTokenSpending` por defecto es `valueLimit: 0`)
40+
- `includeFeeOptionPermissions`, `enableImplicitSession`
41+
- `nodesUrl`, `relayerUrl`
42+
- `walletConnect`
43+
2944
```typescript [config.ts]
3045
import { createConfig } from "@0xsequence/connect";
3146

3247
export const config: any = createConfig({
3348
projectAccessKey: "AQAAAAAAAABtDHG1It7lxRF_9bbxw4diip8",
34-
signIn: {
35-
projectName: 'Sequence Web SDK Demo',
36-
},
3749
walletUrl: 'https://next-acme-wallet.sequence-dev.app',
50+
// Optional
3851
dappOrigin: window.location.origin,
52+
signIn: {
53+
projectName: 'Sequence Web SDK Demo'
54+
},
3955
appName: 'Sequence Web SDK Demo',
4056
chainIds: [42161],
4157
defaultChainId: 42161,
4258
google: true,
4359
apple: true,
4460
email: true,
45-
explicitSessionParams: {...}
61+
explicitSessionParams: { ... }
4662
});
4763
```
4864

@@ -53,6 +69,8 @@ Primero, asegúrese de haber creado una cuenta de Sequence Project. Si aún no t
5369
El objeto `explicitSessionParams` permite que su dapp solicite permisos específicos al usuario al conectarse.
5470
Estos permisos pueden autorizar a su dapp a realizar ciertas acciones en nombre del usuario durante un período definido, creando una experiencia más fluida sin solicitudes de transacción o permitiendo automatizaciones.
5571

72+
`nativeTokenSpending` es opcional. Si se omite, la sesión tendrá por defecto un `valueLimit` de token nativo de `0`.
73+
5674
Por ejemplo, creemos una sesión explícita que permita a su dapp `depositar 100 USDC en el pool de AAVE V3 en Arbitrum, en nombre del usuario durante las próximas 24 horas`
5775

5876
```typescript [config.ts]
@@ -64,11 +82,12 @@ Primero, asegúrese de haber creado una cuenta de Sequence Project. Si aún no t
6482

6583
export const config: any = createConfig({
6684
projectAccessKey: "AQAAAAAAAABtDHG1It7lxRF_9bbxw4diip8",
85+
walletUrl: 'https://next-acme-wallet.sequence-dev.app',
86+
// Optional
87+
dappOrigin: window.location.origin,
6788
signIn: {
6889
projectName: 'Sequence Web SDK Demo',
6990
},
70-
walletUrl: 'https://next-acme-wallet.sequence-dev.app',
71-
dappOrigin: window.location.origin,
7291
appName: 'Sequence Web SDK Demo',
7392
chainIds: [42161],
7493
defaultChainId: 42161,
@@ -184,6 +203,21 @@ Primero, asegúrese de haber creado una cuenta de Sequence Project. Si aún no t
184203
<Step title="Cree su configuración de Wallet">
185204
A continuación, cree la configuración de Ecosystem Wallet.
186205

206+
**Requerido para Ecosystem Wallet**
207+
208+
- `projectAccessKey`
209+
- `walletUrl`
210+
211+
**Opcional**
212+
213+
- `dappOrigin`
214+
- `signIn.projectName`, `appName`
215+
- `chainIds`, `defaultChainId`
216+
- `explicitSessionParams` (opcional; `nativeTokenSpending` por defecto es `valueLimit: 0`)
217+
- `includeFeeOptionPermissions`, `enableImplicitSession`
218+
- `nodesUrl`, `relayerUrl`
219+
- `walletConnect`
220+
187221
```typescript [config.ts]
188222
import { createConfig } from "@0xsequence/connect";
189223

@@ -211,6 +245,8 @@ Primero, asegúrese de haber creado una cuenta de Sequence Project. Si aún no t
211245
El objeto `explicitSessionParams` permite que su dapp solicite permisos específicos al usuario al conectarse.
212246
Estos permisos pueden autorizar a su dapp a realizar ciertas acciones en nombre del usuario durante un período definido, creando una experiencia más fluida sin solicitudes de transacción.
213247

248+
`nativeTokenSpending` es opcional. Si se omite, la sesión tendrá por defecto un `valueLimit` de token nativo de `0`.
249+
214250
Por ejemplo, creemos una sesión explícita que permita a su dapp `depositar 100 USDC en el pool de AAVE V3 en Arbitrum, en nombre del usuario durante las próximas 24 horas`
215251

216252
```typescript [config.ts]

es/sdk/web/wallet-sdk/ecosystem/hooks/useExplicitSessions.mdx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useExplicitSessions } from '@0xsequence/connect'
1313
## Uso
1414

1515
```tsx
16-
import { createContractPermission, createExplicitSession, useExplicitSessions, type Permission, type Session } from '@0xsequence/connect'
16+
import { createContractPermission, useExplicitSessions, type ExplicitSessionParams, type ExplicitSession } from '@0xsequence/connect'
1717
import { useEffect, useState } from 'react'
1818
import { parseUnits } from 'viem'
1919

@@ -22,10 +22,11 @@ function App() {
2222
isLoading,
2323
error,
2424
addExplicitSession,
25+
modifyExplicitSession,
2526
getExplicitSessions
2627
} = useExplicitSessions()
2728

28-
const [sessions, setSessions] = useState<Session[]>([])
29+
const [sessions, setSessions] = useState<ExplicitSession[]>([])
2930

3031
// Load existing sessions
3132
useEffect(() => {
@@ -47,15 +48,15 @@ function App() {
4748
address: '0x...',
4849
functionSignature: 'function testContract() public'
4950
})
50-
const currentSession = sessions[0];
51+
const currentSession = sessions[0]
5152
const modifiedSession = { ...currentSession, permissions: [...currentSession.permissions!, newPermission] }
5253
modifyExplicitSession(modifiedSession)
5354
}
5455

5556
// Handle creating a new explicit session
5657
const handleCreateSession = async () => {
5758
try {
58-
const tokenSpendingSession = createExplicitSession({
59+
const tokenSpendingSession: ExplicitSessionParams = {
5960
chainId: 42161,
6061
nativeTokenSpending: {
6162
valueLimit: 0n,
@@ -78,9 +79,9 @@ function App() {
7879
]
7980
})
8081
]
81-
})
82+
}
8283

83-
await addExplicitSession(42161, tokenSpendingSession)
84+
await addExplicitSession(tokenSpendingSession)
8485

8586
// Refresh sessions after creating a new one
8687
const updatedSessions = await getExplicitSessions()
@@ -113,10 +114,9 @@ function App() {
113114
<h3>Existing Sessions ({sessions.length})</h3>
114115
{sessions.map((session, index) => (
115116
<div key={index}>
116-
<p>Session Address: {session.address}</p>
117+
<p>Session Address: {session.sessionAddress}</p>
117118
<p>Chain ID: {session.chainId}</p>
118-
<p>Is Implicit: {session.isImplicit ? 'Yes' : 'No'}</p>
119-
<p>Permissions: {session.permissions?.permissions?.map((permission: Permission) => permission.target).join(', ')}</p>
119+
<p>Permissions: {session.permissions?.map(permission => permission.target).join(', ')}</p>
120120
</div>
121121
))}
122122
</div>
@@ -132,8 +132,9 @@ El hook retorna un objeto con las siguientes propiedades:
132132
type UseExplicitSessionsReturnType = {
133133
isLoading: boolean
134134
error: Error | null
135-
addExplicitSession: (chainId: ChainId, explicitSession: ExplicitSession) => Promise<void>
136-
getExplicitSessions: () => Promise<Session[]>
135+
addExplicitSession: (params: ExplicitSessionParams, includeFeeOptionPermissions?: boolean) => Promise<void>
136+
modifyExplicitSession: (explicitSession: ExplicitSession) => Promise<void>
137+
getExplicitSessions: () => Promise<ExplicitSession[]>
137138
}
138139
```
139140
@@ -150,7 +151,7 @@ Un booleano que indica si la operación de solicitud de sesión está en curso.
150151
Un objeto de error si la última operación falló, de lo contrario `null`.
151152
152153
#### addExplicitSession
153-
`(chainId: ChainId, explicitSession: ExplicitSession) => Promise<void>`
154+
`(params: ExplicitSessionParams, includeFeeOptionPermissions?: boolean) => Promise<void>`
154155
155156
```typescript
156157
type ExplicitSession = {
@@ -182,20 +183,9 @@ type ExplicitSession = {
182183
Función para modificar una sesión explícita existente.
183184
184185
#### getExplicitSessions
185-
`() => Promise<Session[]>`
186-
187-
```typescript
188-
type Session = {
189-
type: 'explicit' | 'implicit'
190-
sessionAddress: Address.Address
191-
valueLimit?: bigint
192-
deadline?: bigint
193-
permissions?: Permission.Permission[]
194-
chainId?: number
195-
}
196-
```
186+
`() => Promise<ExplicitSession[]>`
197187
198-
Función para obtener todas las sesiones de la wallet conectada.
188+
Función para obtener todas las sesiones explícitas de la wallet conectada.
199189
200190
## Notas
201191
Este hook proporciona funcionalidad para gestionar sesiones explícitas en conexiones de wallet Sequence V3.

es/sdk/web/wallet-sdk/ecosystem/hooks/useFeeOptions.mdx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sidebarTitle: useFeeOptions
88

99
```tsx
1010
import { useFeeOptions } from '@0xsequence/connect'
11+
import { zeroAddress } from 'viem'
1112
```
1213

1314
## Uso
@@ -69,8 +70,8 @@ function App() {
6970
<input
7071
type="radio"
7172
name="feeOption"
72-
checked={selectedFeeOptionTokenAddress === (option.token.contractAddress || '')}
73-
onChange={() => setSelectedFeeOptionTokenAddress(option.token.contractAddress || '')}
73+
checked={selectedFeeOptionTokenAddress === (option.token.contractAddress || zeroAddress)}
74+
onChange={() => setSelectedFeeOptionTokenAddress(option.token.contractAddress || zeroAddress)}
7475
/>
7576
<label>
7677
{option.token.symbol} - {option.token.contractAddress || 'Native Token'}
@@ -85,7 +86,7 @@ function App() {
8586
</div>
8687
<div>
8788
<button
88-
onClick={() => handleConfirmFee(selectedFeeOptionTokenAddress || '')}
89+
onClick={() => handleConfirmFee(selectedFeeOptionTokenAddress || zeroAddress)}
8990
disabled={!selectedFeeOptionTokenAddress}
9091
>
9192
Confirm
@@ -109,7 +110,7 @@ interface FeeOptionsConfig {
109110
}
110111
```
111112

112-
| Parámetro | Type | Description |
113+
| Parámetro | Tipo | Descripción |
113114
| --------------------- | --------- | ------------------------------------------------------------------------------- |
114115
| `skipFeeBalanceCheck` | `boolean` | Indica si se omite la verificación de balances de tokens (por defecto: `false`) |
115116

@@ -154,17 +155,17 @@ type FeeOptionExtended = Relayer.FeeOption & {
154155
155156
Función para confirmar la opción de tarifa seleccionada.
156157
157-
| Parámetro | Type | Description |
158+
| Parámetro | Tipo | Descripción |
158159
| ----------------- | -------- | ------------------------------------------------------------------------------------------------- |
159160
| `id` | `string` | El ID de confirmación de tarifa |
160-
| `feeTokenAddress` | `string` | La dirección del token a usar para el pago de la comisión (use cadena vacía para el token nativo) |
161+
| `feeTokenAddress` | `string` | La dirección del token a usar para el pago de comisiones (use `zeroAddress` para el token nativo) |
161162
162163
#### rejectPendingFeeOption
163164
`(id: string) => void`
164165
165166
Función para rechazar la selección de la opción de tarifa actual.
166167
167-
| Parámetro | Type | Description |
168+
| Parámetro | Tipo | Descripción |
168169
| --------- | -------- | ------------------------------------------ |
169170
| `id` | `string` | El ID de confirmación de tarifa a rechazar |
170171
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: useHasPermission
3+
description: Hook para verificar si la sesión actual de Sequence V3 puede ejecutar un conjunto de transacciones
4+
sidebarTitle: useHasPermission
5+
---
6+
7+
## Importar
8+
9+
```tsx
10+
import { useHasPermission } from '@0xsequence/connect'
11+
```
12+
13+
## Uso
14+
15+
```tsx
16+
import { useHasPermission } from '@0xsequence/connect'
17+
import { encodeFunctionData, type TransactionRequest } from 'viem'
18+
19+
function App() {
20+
const { checkPermission, isLoading, error, data } = useHasPermission()
21+
22+
const check = async () => {
23+
const txs: TransactionRequest[] = [
24+
{
25+
to: '0x0000000000000000000000000000000000000000',
26+
data: encodeFunctionData({
27+
abi: [
28+
{
29+
type: 'function',
30+
name: 'foo',
31+
stateMutability: 'nonpayable',
32+
inputs: [],
33+
outputs: []
34+
}
35+
],
36+
functionName: 'foo'
37+
})
38+
}
39+
]
40+
41+
const allowed = await checkPermission({ chainId: 42161, transactions: txs })
42+
console.log('Allowed:', allowed)
43+
}
44+
45+
return (
46+
<div>
47+
<button onClick={check}>Check permission</button>
48+
{isLoading && <div>Checking...</div>}
49+
{error && <div>Error: {error.message}</div>}
50+
{data !== undefined && <div>Allowed: {data ? 'Yes' : 'No'}</div>}
51+
</div>
52+
)
53+
}
54+
```
55+
56+
## Parámetros
57+
58+
```tsx
59+
type HasPermissionParams = {
60+
chainId: number
61+
transactions: TransactionRequest[]
62+
}
63+
```
64+
65+
## Tipo de retorno
66+
67+
```tsx
68+
type UseHasPermissionReturnType = {
69+
isLoading: boolean
70+
error: Error | null
71+
data: boolean | undefined
72+
checkPermission: (params: HasPermissionParams) => Promise<boolean>
73+
}
74+
```
75+
76+
## Notas
77+
78+
- Este hook utiliza internamente el conector de Sequence V3.
79+
- Cada transacción debe incluir una dirección `to`.

0 commit comments

Comments
 (0)