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

Commit c3cf2bc

Browse files
adam-majjnsdls
andauthored
am/connectors (#25)
* Add gnosis connector * Add magic connector * Add autoconnect option * Magic support for autoconnect * v2.0.6-0 * Update connector * v2.0.6-1 * Update connector name * v2.0.6-2 * Reinstantiate magic every time * it works now * v2.0.6-3 * add switch Network support * v2.0.6-4 * slightly better handling of autoconnect? * v2.0.6-5 Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent b3b2ea0 commit c3cf2bc

14 files changed

Lines changed: 1373 additions & 387 deletions

docs/react.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| [useDisconnect()](./react.usedisconnect.md) | |
1515
| [useEdition(contractAddress)](./react.useedition.md) | Returns a Edition contract instance |
1616
| [useEditionDrop(contractAddress)](./react.useeditiondrop.md) | Returns a Edition Drop contract instance |
17+
| [useMagic()](./react.usemagic.md) | Convienience hook for connecting to magic link |
1718
| [useMarketplace(contractAddress)](./react.usemarketplace.md) | Returns a Marketplace contract instance |
1819
| [useMetamask()](./react.usemetamask.md) | Convienience hook for connecting to a metamask (or any injected) wallet |
1920
| [useNetworkMismatch()](./react.usenetworkmismatch.md) | |

docs/react.thirdwebprovider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The `<ThirdwebProvider />` component, you need to wrap your application with thi
99
<b>Signature:</b>
1010

1111
```typescript
12-
ThirdwebProvider: <TSupportedChain extends SupportedChain = SupportedChain>({ sdkOptions, chainRpc, supportedChains, walletConnectors, dAppMeta, desiredChainId, storageInterface, children, }: React.PropsWithChildren<ThirdwebProviderProps<TSupportedChain>>) => JSX.Element
12+
ThirdwebProvider: <TSupportedChain extends SupportedChain = SupportedChain>({ sdkOptions, chainRpc, supportedChains, walletConnectors, dAppMeta, desiredChainId, storageInterface, autoConnect, children, }: React.PropsWithChildren<ThirdwebProviderProps<TSupportedChain>>) => JSX.Element
1313
```
1414

1515
## Example
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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; [ThirdwebProviderProps](./react.thirdwebproviderprops.md) &gt; [autoConnect](./react.thirdwebproviderprops.autoconnect.md)
4+
5+
## ThirdwebProviderProps.autoConnect property
6+
7+
Whether or not to attempt auto-connect to a wallet.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
autoConnect?: boolean;
13+
```

docs/react.thirdwebproviderprops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ThirdwebProviderProps<TSupportedChain extends SupportedChain =
1616

1717
| Property | Type | Description |
1818
| --- | --- | --- |
19+
| [autoConnect?](./react.thirdwebproviderprops.autoconnect.md) | boolean | <i>(Optional)</i> Whether or not to attempt auto-connect to a wallet. |
1920
| [chainRpc?](./react.thirdwebproviderprops.chainrpc.md) | Partial&lt;ChainRpc&lt;TSupportedChain&gt;&gt; | <i>(Optional)</i> A partial map of chainIds to rpc urls to use for certain chains If not provided, will default to the rpcUrls of the chain objects for the supported chains |
2021
| [dAppMeta?](./react.thirdwebproviderprops.dappmeta.md) | [DAppMetaData](./react.dappmetadata.md) | <i>(Optional)</i> Metadata to pass to wallet connect and walletlink wallet connect. (Used to show \*which\* dApp is being connected to in mobile wallets that support it) Defaults to just the name being passed as <code>thirdweb powered dApp</code>. |
2122
| [desiredChainId](./react.thirdwebproviderprops.desiredchainid.md) | TSupportedChain extends Chain ? TSupportedChain\["id"\] : TSupportedChain \| undefined | The chainId that your dApp is running on. While this \*can\* be <code>undefined</code> it is required to be passed. Passing <code>undefined</code> will cause no SDK to be instantiated. When passing a chainId, it \*\*must\*\* be part of the <code>supportedChains</code> array. |

docs/react.usemagic.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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; [useMagic](./react.usemagic.md)
4+
5+
## useMagic() function
6+
7+
Convienience hook for connecting to magic link
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare function useMagic(): (configuration: LoginWithMagicLinkConfiguration) => Promise<{
13+
data?: import("wagmi-core").ConnectorData<any> | undefined;
14+
error?: Error | undefined;
15+
}>;
16+
```
17+
<b>Returns:</b>
18+
19+
(configuration: LoginWithMagicLinkConfiguration) =&gt; Promise&lt;{ data?: import("wagmi-core").ConnectorData&lt;any&gt; \| undefined; error?: Error \| undefined; }&gt;
20+
21+
a function that will prompt the user to connect their magic link
22+

etc/react.api.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import type { Chain as Chain_2 } from 'wagmi';
88
import { ChainId } from '@thirdweb-dev/sdk';
9+
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet';
910
import { Connector } from 'wagmi';
1011
import { ConnectorData } from 'wagmi';
1112
import { ConnectorData as ConnectorData_2 } from 'wagmi-core';
@@ -18,6 +19,8 @@ import { EditionDrop } from '@thirdweb-dev/sdk';
1819
import { InjectedConnector } from 'wagmi/connectors/injected';
1920
import { IpfsStorage } from '@thirdweb-dev/sdk';
2021
import { IStorage } from '@thirdweb-dev/sdk';
22+
import { LoginWithMagicLinkConfiguration } from 'magic-sdk';
23+
import { MagicSDKAdditionalConfiguration } from 'magic-sdk';
2124
import { Marketplace } from '@thirdweb-dev/sdk';
2225
import { NFTCollection } from '@thirdweb-dev/sdk';
2326
import { NFTDrop } from '@thirdweb-dev/sdk';
@@ -33,7 +36,6 @@ import { useAccount } from 'wagmi';
3336
import { useNetwork } from 'wagmi';
3437
import { Vote } from '@thirdweb-dev/sdk';
3538
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect';
36-
import { WalletLinkConnector } from 'wagmi/connectors/walletLink';
3739

3840
export { ChainId }
3941

@@ -67,6 +69,14 @@ export type InjectedConnectorType = "injected" | "metamask" | {
6769

6870
export { IpfsStorage }
6971

72+
// Warning: (ae-internal-missing-underscore) The name "MagicConnectorType" should be prefixed with an underscore because the declaration is marked as @internal
73+
//
74+
// @internal (undocumented)
75+
export type MagicConnectorType = "magic" | {
76+
name: "magic";
77+
options: Omit<MagicConnectorArguments, "network">;
78+
};
79+
7080
// @public
7181
export const MediaRenderer: React_2.ForwardRefExoticComponent<MediaRendererProps & React_2.RefAttributes<HTMLMediaElement>>;
7282

@@ -108,10 +118,11 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
108118
}
109119

110120
// @public
111-
export const ThirdwebProvider: <TSupportedChain extends SupportedChain = SupportedChain>({ sdkOptions, chainRpc, supportedChains, walletConnectors, dAppMeta, desiredChainId, storageInterface, children, }: React_2.PropsWithChildren<ThirdwebProviderProps<TSupportedChain>>) => JSX.Element;
121+
export const ThirdwebProvider: <TSupportedChain extends SupportedChain = SupportedChain>({ sdkOptions, chainRpc, supportedChains, walletConnectors, dAppMeta, desiredChainId, storageInterface, autoConnect, children, }: React_2.PropsWithChildren<ThirdwebProviderProps<TSupportedChain>>) => JSX.Element;
112122

113123
// @public
114124
export interface ThirdwebProviderProps<TSupportedChain extends SupportedChain = SupportedChain> {
125+
autoConnect?: boolean;
115126
// Warning: (ae-incompatible-release-tags) The symbol "chainRpc" is marked as @public, but its signature references "ChainRpc" which is marked as @internal
116127
chainRpc?: Partial<ChainRpc<TSupportedChain>>;
117128
dAppMeta?: DAppMetaData;
@@ -172,6 +183,12 @@ export function useEdition(contractAddress?: string): Edition | undefined;
172183
// @public
173184
export function useEditionDrop(contractAddress?: string): EditionDrop | undefined;
174185

186+
// @public
187+
export function useMagic(): (configuration: LoginWithMagicLinkConfiguration) => Promise<{
188+
data?: ConnectorData_2<any> | undefined;
189+
error?: Error | undefined;
190+
}>;
191+
175192
// @public
176193
export function useMarketplace(contractAddress?: string): Marketplace | undefined;
177194

@@ -250,16 +267,20 @@ export type WalletConnectConnectorType = "walletConnect" | {
250267
// Warning: (ae-internal-missing-underscore) The name "WalletConnector" should be prefixed with an underscore because the declaration is marked as @internal
251268
//
252269
// @internal (undocumented)
253-
export type WalletConnector = InjectedConnectorType | WalletConnectConnectorType | WalletLinkConnectorType;
270+
export type WalletConnector = InjectedConnectorType | WalletConnectConnectorType | WalletLinkConnectorType | MagicConnectorType;
254271

255272
// Warning: (ae-internal-missing-underscore) The name "WalletLinkConnectorType" should be prefixed with an underscore because the declaration is marked as @internal
256273
//
257274
// @internal (undocumented)
258275
export type WalletLinkConnectorType = "walletLink" | "coinbase" | {
259276
name: "walletLink" | "coinbase";
260-
options: WalletLinkConnector["options"];
277+
options: CoinbaseWalletConnector["options"];
261278
};
262279

280+
// Warnings were encountered during analysis:
281+
//
282+
// dist/Provider.d.ts:34:5 - (ae-forgotten-export) The symbol "MagicConnectorArguments" needs to be exported by the entry point index.d.ts
283+
263284
// (No @packageDocumentation comment for this package)
264285

265286
```

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thirdweb-dev/react",
3-
"version": "2.0.5",
3+
"version": "2.0.6-5",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com:thirdweb-dev/react.git"
@@ -55,11 +55,14 @@
5555
"vitest": "^0.9.3"
5656
},
5757
"dependencies": {
58+
"@gnosis.pm/safe-apps-provider": "^0.11.0",
59+
"@gnosis.pm/safe-apps-sdk": "^7.3.0",
60+
"magic-sdk": "^8.1.1",
5861
"mime": "^3.0.0",
5962
"react-cool-dimensions": "^2.0.7",
6063
"swr": "^1.2.2",
6164
"tiny-invariant": "^1.2.0",
62-
"wagmi": "0.2.26"
65+
"wagmi": "^0.2.28"
6366
},
6467
"peerDependencies": {
6568
"@thirdweb-dev/sdk": "^2.0.15",

src/Provider.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MagicConnector, MagicConnectorArguments } from "./connectors/magic";
12
import {
23
Chain,
34
SupportedChain,
@@ -12,9 +13,9 @@ import {
1213
ProviderProps as WagmiproviderProps,
1314
useProvider,
1415
} from "wagmi";
16+
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
1517
import { InjectedConnector } from "wagmi/connectors/injected";
1618
import { WalletConnectConnector } from "wagmi/connectors/walletConnect";
17-
import { WalletLinkConnector } from "wagmi/connectors/walletLink";
1819

1920
/**
2021
* @internal
@@ -39,7 +40,17 @@ export type WalletLinkConnectorType =
3940
| "coinbase"
4041
| {
4142
name: "walletLink" | "coinbase";
42-
options: WalletLinkConnector["options"];
43+
options: CoinbaseWalletConnector["options"];
44+
};
45+
46+
/**
47+
* @internal
48+
*/
49+
export type MagicConnectorType =
50+
| "magic"
51+
| {
52+
name: "magic";
53+
options: Omit<MagicConnectorArguments, "network">;
4354
};
4455

4556
/**
@@ -48,7 +59,8 @@ export type WalletLinkConnectorType =
4859
export type WalletConnector =
4960
| InjectedConnectorType
5061
| WalletConnectConnectorType
51-
| WalletLinkConnectorType;
62+
| WalletLinkConnectorType
63+
| MagicConnectorType;
5264

5365
/**
5466
* @internal
@@ -130,6 +142,11 @@ export interface ThirdwebProviderProps<
130142
* The storage interface to use with the sdk.
131143
*/
132144
storageInterface?: IStorage;
145+
146+
/**
147+
* Whether or not to attempt auto-connect to a wallet.
148+
*/
149+
autoConnect?: boolean;
133150
}
134151

135152
const defaultChainRpc: ChainRpc<SupportedChain> = defaultSupportedChains.reduce(
@@ -180,6 +197,7 @@ export const ThirdwebProvider = <
180197
dAppMeta = defaultdAppMeta,
181198
desiredChainId,
182199
storageInterface,
200+
autoConnect = true,
183201
children,
184202
}: React.PropsWithChildren<ThirdwebProviderProps<TSupportedChain>>) => {
185203
// construct the wagmi options
@@ -221,7 +239,7 @@ export const ThirdwebProvider = <
221239
};
222240

223241
return {
224-
autoConnect: true,
242+
autoConnect,
225243
connectorStorageKey: "tw:provider:connectors",
226244
connectors: ({ chainId }: { chainId?: number }) => {
227245
return walletConnectors
@@ -275,7 +293,7 @@ export const ThirdwebProvider = <
275293
connector.name === "walletLink"))
276294
) {
277295
const jsonRpcUrl = _rpcUrlMap[chainId || desiredChainId || 1];
278-
return new WalletLinkConnector({
296+
return new CoinbaseWalletConnector({
279297
chains: _supporrtedChains,
280298
options:
281299
typeof connector === "string"
@@ -290,6 +308,17 @@ export const ThirdwebProvider = <
290308
},
291309
});
292310
}
311+
if (typeof connector === "object" && connector.name === "magic") {
312+
const jsonRpcUrl = _rpcUrlMap[chainId || desiredChainId || 1];
313+
return new MagicConnector({
314+
chains: _supporrtedChains,
315+
options: {
316+
...connector.options,
317+
network: { rpcUrl: jsonRpcUrl, chainId: desiredChainId || 1 },
318+
rpcUrls: _rpcUrlMap,
319+
},
320+
});
321+
}
293322
return null;
294323
})
295324
.filter((c) => c !== null);

0 commit comments

Comments
 (0)