Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 9a593b3

Browse files
add custom gnosis wagmi connector (#33)
* first pass at custom gnosis wagmi connector * arguments, clean up code * update docs * add address map * implement disconnect * fix url * make gnosis safe re-connect to previous connector * fix package version? * fix package version? * v2.2.0-0 * patch gnosis connector to work reliably in the browser * v2.2.0-1 * enable minify again * v2.2.0-2 * update build again * v2.2.0-3 Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent ee2c7b8 commit 9a593b3

File tree

13 files changed

+665
-378
lines changed

13 files changed

+665
-378
lines changed

docs/react.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ import { useCoinbaseWallet } from "@thirdweb-dev/react"
2727
| [useContractPublishMetadata(contractAddress)](./react.usecontractpublishmetadata.md) | <b><i>(BETA)</i></b> Use this to get the publish metadata for a deployed contract. |
2828
| [useContractType(contractAddress)](./react.usecontracttype.md) | <b><i>(BETA)</i></b> Use this to get the contract type for a (built-in or custom) contract. |
2929
| [useCustomContract(contractAddress)](./react.usecustomcontract.md) | <b><i>(BETA)</i></b> Use this resolve a contract address to a thirdweb (built-in / custom) contract instance. |
30-
| [useDisconnect()](./react.usedisconnect.md) | Hook for disconnecting the currently connected wallet
30+
| [useDisconnect(options)](./react.usedisconnect.md) | Hook for disconnecting the currently connected wallet
3131
```javascript
3232
import { useDisconnect } from "@thirdweb-dev/react"
3333
```
3434
|
3535
| [useEdition(contractAddress)](./react.useedition.md) | Hook for getting an instance of an <code>Edition</code> contract. This contract is used to interface with ERC1155 compliant NFTs. |
3636
| [useEditionDrop(contractAddress)](./react.useeditiondrop.md) | Hook for getting an instance of an <code>EditionDrop</code> contract. This conract is used to interface with ERC1155 compliant NFTs that can be lazily minted. |
37+
| [useGnosis()](./react.usegnosis.md) | Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
38+
```javascript
39+
import { useGnosis } from "@thirdweb-dev/react"
40+
```
41+
|
3742
| [useMagic()](./react.usemagic.md) | Hook for connecting to an email wallet using magic link. This enables users without their own wallets to connect to your application and sign transactions securely using their email.
3843
```javascript
3944
import { useMagic } from "@thirdweb-dev/react"

docs/react.usedisconnect.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,23 @@ import { useDisconnect } from "@thirdweb-dev/react"
1313
<b>Signature:</b>
1414

1515
```typescript
16-
declare function useDisconnect(): () => void;
16+
declare function useDisconnect(options?: {
17+
reconnectAfterGnosis?: boolean;
18+
}): () => Promise<void | {
19+
data?: wagmi.ConnectorData<any> | undefined;
20+
error?: Error | undefined;
21+
}>;
1722
```
23+
24+
## Parameters
25+
26+
| Parameter | Type | Description |
27+
| --- | --- | --- |
28+
| options | { reconnectAfterGnosis?: boolean; } | <i>(Optional)</i> |
29+
1830
<b>Returns:</b>
1931

20-
() =&gt; void
32+
() =&gt; Promise&lt;void \| { data?: wagmi.ConnectorData&lt;any&gt; \| undefined; error?: Error \| undefined; }&gt;
2133

2234
## Example
2335

docs/react.usegnosis.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@thirdweb-dev/react](./react.md) &gt; [useGnosis](./react.usegnosis.md)
4+
5+
## useGnosis() function
6+
7+
Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
8+
9+
```javascript
10+
import { useGnosis } from "@thirdweb-dev/react"
11+
```
12+
13+
<b>Signature:</b>
14+
15+
```typescript
16+
declare function useGnosis(): (config: GnosisConnectorArguments) => Promise<{
17+
data?: wagmi_core.ConnectorData<any> | undefined;
18+
error?: Error | undefined;
19+
}>;
20+
```
21+
<b>Returns:</b>
22+
23+
(config: GnosisConnectorArguments) =&gt; Promise&lt;{ data?: wagmi\_core.ConnectorData&lt;any&gt; \| undefined; error?: Error \| undefined; }&gt;
24+
25+
## Example
26+
27+
28+
```javascript
29+
import { useGnosis } from "@thirdweb-dev/react"
30+
31+
const App = () => {
32+
const connectWithGnosis = useGnosis()
33+
34+
return (
35+
<button onClick={() => connectWithGnosis({ safeAddress: "0x...", safeChainId: 1 })}>
36+
Connect Gnosis Safe
37+
</button>
38+
)
39+
}
40+
```
41+

etc/react.api.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ export { defaultL2Chains }
151151
// @internal (undocumented)
152152
export function detectErc721Instance(contract?: ValidContractInstance | CustomContract | null): Erc721<any> | undefined;
153153

154+
// Warning: (ae-internal-missing-underscore) The name "GnosisConnectorType" should be prefixed with an underscore because the declaration is marked as @internal
155+
//
156+
// @internal (undocumented)
157+
export type GnosisConnectorType = "gnosis" | {
158+
name: "gnosis";
159+
options: GnosisConnectorArguments;
160+
};
161+
154162
// Warning: (ae-internal-missing-underscore) The name "InjectedConnectorType" should be prefixed with an underscore because the declaration is marked as @internal
155163
//
156164
// @internal (undocumented)
@@ -419,14 +427,25 @@ export function useCustomContract(contractAddress?: string): {
419427
export function useDesiredChainId(): number;
420428

421429
// @public
422-
export function useDisconnect(): () => void;
430+
export function useDisconnect(options?: {
431+
reconnectAfterGnosis?: boolean;
432+
}): () => Promise<void | {
433+
data?: wagmi.ConnectorData<any> | undefined;
434+
error?: Error | undefined;
435+
}>;
423436

424437
// @public
425438
export function useEdition(contractAddress?: string): Edition | undefined;
426439

427440
// @public
428441
export function useEditionDrop(contractAddress?: string): EditionDrop | undefined;
429442

443+
// @public
444+
export function useGnosis(): (config: GnosisConnectorArguments) => Promise<{
445+
data?: wagmi_core.ConnectorData<any> | undefined;
446+
error?: Error | undefined;
447+
}>;
448+
430449
// @public
431450
export function useMagic(): (configuration: LoginWithMagicLinkConfiguration) => Promise<{
432451
data?: wagmi_core.ConnectorData<any> | undefined;
@@ -574,7 +593,7 @@ export type WalletConnectConnectorType = "walletConnect" | {
574593
// Warning: (ae-internal-missing-underscore) The name "WalletConnector" should be prefixed with an underscore because the declaration is marked as @internal
575594
//
576595
// @internal (undocumented)
577-
export type WalletConnector = InjectedConnectorType | WalletConnectConnectorType | WalletLinkConnectorType | MagicConnectorType;
596+
export type WalletConnector = InjectedConnectorType | WalletConnectConnectorType | WalletLinkConnectorType | MagicConnectorType | GnosisConnectorType;
578597

579598
// Warning: (ae-internal-missing-underscore) The name "WalletLinkConnectorType" should be prefixed with an underscore because the declaration is marked as @internal
580599
//
@@ -586,8 +605,9 @@ export type WalletLinkConnectorType = "walletLink" | "coinbase" | {
586605

587606
// Warnings were encountered during analysis:
588607
//
589-
// dist/index.d.ts:391:5 - (ae-forgotten-export) The symbol "MagicConnectorArguments" needs to be exported by the entry point index.d.ts
590-
// dist/index.d.ts:960:5 - (ae-forgotten-export) The symbol "wagmi_core" needs to be exported by the entry point index.d.ts
608+
// dist/index.d.ts:396:5 - (ae-forgotten-export) The symbol "MagicConnectorArguments" needs to be exported by the entry point index.d.ts
609+
// dist/index.d.ts:403:5 - (ae-forgotten-export) The symbol "GnosisConnectorArguments" needs to be exported by the entry point index.d.ts
610+
// dist/index.d.ts:977:5 - (ae-forgotten-export) The symbol "wagmi_core" needs to be exported by the entry point index.d.ts
591611

592612
// (No @packageDocumentation comment for this package)
593613

package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thirdweb-dev/react",
3-
"version": "2.1.0",
3+
"version": "2.2.0-3",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com:thirdweb-dev/react.git"
@@ -18,7 +18,7 @@
1818
],
1919
"private": false,
2020
"scripts": {
21-
"build:lib": "tsup --env.NODE_ENV production --minify --format esm,cjs --dts-resolve",
21+
"build:lib": "tsup --dts-resolve",
2222
"lint": "eslint src/",
2323
"fix": "eslint src/ --fix",
2424
"extract-api": "api-extractor run --local",
@@ -54,8 +54,9 @@
5454
"vitest": "^0.10.0"
5555
},
5656
"dependencies": {
57-
"@gnosis.pm/safe-apps-provider": "^0.11.0",
58-
"@gnosis.pm/safe-apps-sdk": "^7.3.0",
57+
"@gnosis.pm/safe-core-sdk": "^2.1.0",
58+
"@gnosis.pm/safe-ethers-adapters": "^0.1.0-alpha.9",
59+
"@gnosis.pm/safe-ethers-lib": "^1.1.0",
5960
"magic-sdk": "^8.1.1",
6061
"mime": "^3.0.0",
6162
"react-cool-dimensions": "^2.0.7",
@@ -72,14 +73,5 @@
7273
"resolutions": {
7374
"ansi-regex": "^6.0.1",
7475
"typescript": "^4.6.2"
75-
},
76-
"tsup": {
77-
"entry": [
78-
"src/index.ts"
79-
],
80-
"splitting": false,
81-
"sourcemap": true,
82-
"clean": true,
83-
"dtsRollup": true
8476
}
8577
}

src/Provider.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
GnosisConnectorArguments,
3+
GnosisSafeConnector,
4+
} from "./connectors/gnosis-safe";
15
import { MagicConnector, MagicConnectorArguments } from "./connectors/magic";
26
import {
37
Chain,
@@ -61,14 +65,25 @@ export type MagicConnectorType =
6165
options: Omit<MagicConnectorArguments, "network">;
6266
};
6367

68+
/**
69+
* @internal
70+
*/
71+
export type GnosisConnectorType =
72+
| "gnosis"
73+
| {
74+
name: "gnosis";
75+
options: GnosisConnectorArguments;
76+
};
77+
6478
/**
6579
* @internal
6680
*/
6781
export type WalletConnector =
6882
| InjectedConnectorType
6983
| WalletConnectConnectorType
7084
| WalletLinkConnectorType
71-
| MagicConnectorType;
85+
| MagicConnectorType
86+
| GnosisConnectorType;
7287

7388
/**
7489
* @internal
@@ -333,6 +348,14 @@ export const ThirdwebProvider = <
333348
},
334349
});
335350
}
351+
if (
352+
(typeof connector === "string" && connector === "gnosis") ||
353+
(typeof connector === "object" && connector.name === "gnosis")
354+
) {
355+
return new GnosisSafeConnector({
356+
chains: _supporrtedChains,
357+
});
358+
}
336359
return null;
337360
})
338361
.filter((c) => c !== null);

0 commit comments

Comments
 (0)