Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/safe-global/safe-docs into …
Browse files Browse the repository at this point in the history
…smart-account-reference
  • Loading branch information
louis-md committed Oct 22, 2024
2 parents ea0cc50 + 51252b9 commit ee3c536
Show file tree
Hide file tree
Showing 42 changed files with 4,221 additions and 552 deletions.
2 changes: 2 additions & 0 deletions .github/styles/config/vocabularies/default/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ peaq
pluggable
polyfills
precompile(?s)
refetch
refetching
saltNonce
stablecoin
superset
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.16.0",
"version": "4.17.1",
"description": "Safe docs",
"scripts": {
"build": "next build",
Expand Down Expand Up @@ -35,52 +35,52 @@
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^5.16.7",
"@mui/material": "^5.16.7",
"@next/third-parties": "^14.2.13",
"@next/third-parties": "^14.2.15",
"@svgr/webpack": "^8.1.0",
"cuid": "^3.0.0",
"fuse.js": "^7.0.0",
"lodash": "^4.17.21",
"next": "^14.2.13",
"next": "^14.2.15",
"nextra": "2.13.4",
"nextra-theme-docs": "2.13.4",
"node-fetch": "^3.3.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"release-it": "^17.6.0",
"release-it": "^17.10.0",
"shelljs": "^0.8.5",
"swr": "^2.2.5"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.13",
"@types/lodash": "^4.17.7",
"@next/eslint-plugin-next": "^14.2.15",
"@types/lodash": "^4.17.10",
"@types/node": "20.14.11",
"@types/react": "18.3.8",
"@types/react-dom": "^18.3.0",
"@types/react": "18.3.11",
"@types/react-dom": "^18.3.1",
"@types/shelljs": "^0.8.15",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"cypress": "^13.14.2",
"cypress": "^13.15.0",
"env-cmd": "^10.1.0",
"eslint": "8.57.1",
"eslint-config-next": "^14.2.13",
"eslint-config-next": "^14.2.15",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-config-standard-jsx": "^11.0.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-react": "^7.36.1",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-security": "^3.0.1",
"husky": "^9.1.6",
"markdown-link-check": "^3.12.2",
"open-graph-scraper": "^6.8.2",
"prettier": "^3.3.3",
"serve": "^14.2.3",
"serve": "^14.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"release-it": {
"github": {
Expand Down
5 changes: 5 additions & 0 deletions pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"type": "page",
"display": "hidden"
},
"reference-sdk-react-hooks": {
"title": "React Hooks Reference",
"type": "page",
"display": "hidden"
},
"core-api": {
"title": "API",
"type": "page"
Expand Down
18 changes: 18 additions & 0 deletions pages/reference-sdk-react-hooks/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"home": {
"title": "← Go Back",
"href": "/sdk/react-hooks"
},
"overview": "Overview",
"-- React Hooks Reference": {
"type": "separator",
"title": "React Hooks Reference"
},
"safeprovider": "SafeProvider",
"createconfig": "createConfig",
"useconfirmtransaction": "useConfirmTransaction",
"usesafe": "useSafe",
"usesendtransaction": "useSendTransaction",
"useupdateowners": "useUpdateOwners",
"useupdatethreshold": "useUpdateThreshold"
}
242 changes: 242 additions & 0 deletions pages/reference-sdk-react-hooks/createconfig.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import { Tabs } from 'nextra/components'

# `createConfig`

Returns the configuration object required to initialize the Safe React Hooks.

## Usage

It can be used to initialize the [`SafeProvider`](./safeprovider.mdx) or any of the Safe React Hooks. The global configuration will be overwritten within the scope of a hook if a hook is created with a custom configuration.

{/* <!-- vale off --> */}

<Tabs items={['SafeProvider configuration', 'Hook configuration']}>
<Tabs.Tab>
```typescript
import ReactDOM from 'react-dom/client'
import { createConfig, SafeProvider } from '@safe-global/safe-react-hooks'
import App from './App.tsx'

const config = createConfig({
// ...
})

const root = document.getElementById('root')

ReactDOM.createRoot(root).render(
<SafeProvider config={config}>
<App />
</SafeProvider>
)
```
</Tabs.Tab>
<Tabs.Tab>
```typescript
import { createConfig, useSafe } from '@safe-global/safe-react-hooks'

const config = createConfig({
// ...
})

function CustomComponent() {
const {
getChain,
// ...
} = useSafe()
const { name } = getChain({ config })

return (
<div>
{name}
</div>
)
}

export default CustomComponent
```
</Tabs.Tab>
</Tabs>

{/* <!-- vale on --> */}

The `createConfig` parameters vary depending on if you want to connect a Safe account that is already deployed or you want to deploy a new one.

{/* <!-- vale off --> */}

<Tabs items={['Existing Safe', 'New Safe']}>
<Tabs.Tab>
Use the `safeAddress` property to use an existing Safe account.

```typescript
import { createConfig } from '@safe-global/safe-react-hooks'
import { sepolia } from 'viem/chains'

const config = createConfig({
chain: sepolia
provider,
signer,
safeAddress: '0x...'
})
```
</Tabs.Tab>
<Tabs.Tab>
Use the `safeOptions` property to configure and deploy a new Safe account. The Safe address generation is deterministic based on the `owners`, `threshold`, and `saltNonce` values.

```typescript
import { createConfig } from '@safe-global/safe-react-hooks'
import { sepolia } from 'viem/chains'

const config = createConfig({
chain: sepolia
provider,
signer,
safeOptions: {
owners: ['0x...', '0x...', '0x...'],
threshold: 2,
saltNonce: 123n // Optional
}
})
```
</Tabs.Tab>
</Tabs>

{/* <!-- vale on --> */}

## Parameters

`CreateConfigParams`

```typescript
import { CreateConfigParams } from '@safe-global/safe-react-hooks'
```

### `chain`
- **Type:** `Chain`

The connected chain.

```typescript focus=2
const config = createConfig({
chain: sepolia,
provider,
signer,
safeAddress: '0x...'
})
```

### `provider`

- **Type:** `Eip1193Provider | HttpTransport | SocketTransport`

The provider connected to the blockchain.

```typescript focus=3
const config = createConfig({
chain: sepolia,
provider,
signer,
safeAddress: '0x...'
})
```

### `signer`

- **Type:** `HexAddress | PrivateKey | PasskeyClient`

The signer connected to the Safe as an owner.
- If it's an address, the same address from the `provider` will be used to sign.
- If it's a private key, its derived address will be used to sign.
- If it's a passkey, the passkey will be used to sign.

```typescript focus=4
const config = createConfig({
chain: sepolia
provider,
signer,
safeAddress: '0x...'
})
```

### `safeAddress` (Optional)

- **Type:** `HexAddress`

The address of the connected Safe.

```typescript focus=5
const config = createConfig({
chain: sepolia
provider,
signer,
safeAddress: '0x...'
})
```

### `safeOptions` (Optional)

#### `owners`

- **Type:** `string[]`

The list of owners to configure in the Safe.

```typescript focus=6
const config = createConfig({
chain: sepolia
provider,
signer,
safeOptions: {
owners: ['0x...', '0x...', '0x...'],
threshold: 2,
saltNonce: 123n
}
})
```

#### `threshold`

- **Type:** `number`

The threshold of the Safe. It must be lower or equal to the number of owners.

```typescript focus=7
const config = createConfig({
chain: sepolia
provider,
signer,
safeOptions: {
owners: ['0x...', '0x...', '0x...'],
threshold: 2,
saltNonce: 123n
}
})
```

#### `saltNonce` (Optional)

- **Type:** `string`

The salt introduces randomness or predictability when the Safe address is generated.

```typescript focus=8
const config = createConfig({
chain: sepolia
provider,
signer,
safeOptions: {
owners: ['0x...', '0x...', '0x...'],
threshold: 2,
saltNonce: 123n
}
})
```

## Returns

`SafeConfig`

The Safe React Hooks configuration.

```typescript
import { SafeConfig } from '@safe-global/safe-react-hooks'
```
27 changes: 27 additions & 0 deletions pages/reference-sdk-react-hooks/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Safe React Hooks Reference

[Safe React Hooks](../sdk/react-hooks) is a collection of React hooks written in TypeScript that simplify the usage of the Safe\{Core\} SDK for React developers.

## Install dependencies

To add the Safe React Hooks to your project, run:

{/* <!-- vale off --> */}

<CH.Section>
<CH.Code style={{ boxShadow: 'none' }}>
```bash pnpm
pnpm add @safe-global/safe-react-hooks
```

```bash npm
npm install @safe-global/safe-react-hooks
```

```bash yarn
yarn add @safe-global/safe-react-hooks
```
</CH.Code>
</CH.Section>

{/* <!-- vale on --> */}
Loading

0 comments on commit ee3c536

Please sign in to comment.