Skip to content

Commit 654b277

Browse files
authored
Merge branch 'main' into am/json
2 parents 4727187 + 208b038 commit 654b277

File tree

110 files changed

+1414
-1295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1414
-1295
lines changed

.changeset/rotten-lions-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
use internals wherever possible to allow wider usecases with `<ThirdwebSDKProvider>` & add invariants to catch improper use of functionality that requires the full `<ThirdwebProvider` earlier

.changeset/sharp-dodos-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
fix case where `<ConnectWallet />` button would get stuck when user cancels connection

.changeset/slimy-dolls-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Switch naming of exported prebuilt contract types back from `<name>Impl` to `<name>` for easier use

.changeset/tiny-trees-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
allow passing `className` to `<ConnectWallet />` and `<Web3Button />` for possible style overrides

packages/auth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"eslint-plugin-tsdoc": "^0.2.16",
6161
"ethers": "^5.7.0",
6262
"express": "^4.18.1",
63-
"next": "12.2.0",
63+
"next": "^12.2.0",
6464
"next-auth": "^4.10.3",
6565
"prettier": "^2.7.1",
6666
"typescript": "^4.7.4"
@@ -69,7 +69,7 @@
6969
"@thirdweb-dev/sdk": "*",
7070
"ethers": ">=5.5.1",
7171
"express": "^4.18.1",
72-
"next": "12.2.0",
72+
"next": "^12.2.0",
7373
"next-auth": "^4.10.3"
7474
},
7575
"peerDependenciesMeta": {

packages/cli/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"prettier": "^2.7.1",
2626
"ts-jest": "^28.0.8",
2727
"ts-node": "^10.7.0",
28-
"tsc": "^2.0.4",
2928
"tsup": "^6.2.3",
3029
"typescript": "^4.7.4"
3130
},
@@ -81,4 +80,4 @@
8180
"sourcemap": true,
8281
"clean": true
8382
}
84-
}
83+
}

packages/eslint-config-thirdweb/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"main": "index.js",
55
"license": "Apache-2.0",
66
"dependencies": {
7-
"@typescript-eslint/eslint-plugin": "^5.36.2",
8-
"@typescript-eslint/parser": "^5.36.2",
7+
"@typescript-eslint/eslint-plugin": "^5.33.0",
8+
"@typescript-eslint/parser": "^5.33.0",
99
"eslint-config-next": "^12.0.8",
1010
"eslint-config-prettier": "^8.3.0",
1111
"eslint-config-turbo": "latest",

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"@microsoft/api-documenter": "^7.19.4",
3434
"@microsoft/api-extractor": "^7.29.2",
3535
"@microsoft/tsdoc": "^0.14.1",
36-
"@playwright/experimental-ct-react": "^1.25.1",
37-
"@playwright/test": "^1.25.1",
36+
"@playwright/experimental-ct-react": "1.25.1",
37+
"@playwright/test": "1.25.1",
3838
"@preconstruct/cli": "^2.2.1",
3939
"@thirdweb-dev/sdk": "*",
4040
"@types/color": "^3.0.3",

packages/react/src/components/ConnectWallet/ConnectWallet.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ConnectWallet } from ".";
2-
import { ThirdwebProvider } from "../..";
2+
import { ThirdwebProvider } from "../../providers/full";
33
import { test, expect } from "@playwright/experimental-ct-react";
44

55
test.use({ viewport: { width: 500, height: 500 } });
@@ -10,5 +10,6 @@ test("should render the connect wallet button", async ({ mount }) => {
1010
<ConnectWallet />
1111
</ThirdwebProvider>,
1212
);
13+
1314
await expect(component).toContainText("Connect Wallet");
1415
});

packages/react/src/components/ConnectWallet/index.tsx

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { useThirdwebAuthConfig } from "../../contexts/thirdweb-auth";
2-
import { useBalance } from "../../hooks/async/wallet";
32
import { LoginConfig, useAuth } from "../../hooks/auth";
43
import { useMetamask } from "../../hooks/connectors/useMetamask";
5-
import { useAddress } from "../../hooks/useAddress";
6-
import { useChainId } from "../../hooks/useChainId";
7-
import { useConnect } from "../../hooks/useConnect";
8-
import { useDisconnect } from "../../hooks/useDisconnect";
9-
import { useNetwork } from "../../hooks/useNetwork";
4+
import { useConnect } from "../../hooks/wagmi-required/useConnect";
5+
import { useDisconnect } from "../../hooks/wagmi-required/useDisconnect";
6+
import { useNetwork } from "../../hooks/wagmi-required/useNetwork";
7+
import { useAddress, useBalance, useChainId } from "../../hooks/wallet";
108
import { Portal } from "../../lib/portal";
119
import { shortenIfAddress } from "../../utils/addresses";
1210
import { useClipboard } from "../hooks/useCopyClipboard";
13-
import { useIsMounted } from "../hooks/useIsMounted";
1411
import { Box } from "../shared/Box";
1512
import { Button } from "../shared/Button";
1613
import { Icon } from "../shared/Icon";
@@ -30,8 +27,8 @@ import { FiXCircle } from "@react-icons/all-files/fi/FiXCircle";
3027
import { ChainId, LoginOptions, SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk";
3128
import * as menu from "@zag-js/menu";
3229
import { normalizeProps, useMachine } from "@zag-js/react";
33-
import React, { useId, useMemo } from "react";
34-
import { Connector } from "wagmi";
30+
import React, { useId } from "react";
31+
import type { Connector } from "wagmi";
3532

3633
const SUPPORTED_CONNECTORS = [
3734
"injected",
@@ -65,6 +62,7 @@ interface ConnectWalletProps extends ThemeProviderProps {
6562
loginConfig?: LoginConfig;
6663
loginOptional?: boolean;
6764
};
65+
className?: string;
6866
}
6967

7068
let connecting = false;
@@ -124,15 +122,12 @@ const chainIdToCurrencyMap: Record<
124122
*/
125123
export const ConnectWallet: React.FC<ConnectWalletProps> = ({
126124
auth,
125+
className,
127126
...themeProps
128127
}) => {
129128
const id = useId();
130-
const isMounted = useIsMounted();
131-
const address = useAddress();
132129

133-
const mountedAddress = useMemo(() => {
134-
return isMounted ? address : null;
135-
}, [address, isMounted]);
130+
const walletAddress = useAddress();
136131

137132
const [state, send] = useMachine(
138133
menu.machine({
@@ -165,24 +160,26 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
165160

166161
const balanceQuery = useBalance();
167162

168-
const { onCopy, hasCopied } = useClipboard(mountedAddress || "");
163+
const { onCopy, hasCopied } = useClipboard(walletAddress || "");
169164

170165
const authConfig = useThirdwebAuthConfig();
171166
const { user, isLoading, login, logout } = useAuth(auth?.loginConfig);
172167

173168
const requiresSignIn = auth?.loginOptional
174169
? false
175-
: !!authConfig?.authUrl && !!mountedAddress && !user?.address;
170+
: !!authConfig?.authUrl && !!walletAddress && !user?.address;
176171

177172
return (
178173
<ThemeProvider {...themeProps}>
179174
<div
180175
style={{
181176
position: "relative",
177+
width: "100%",
182178
}}
183179
>
184180
<Button
185-
style={{ height: "50px", minWidth: "200px" }}
181+
className={className}
182+
style={{ height: "50px", minWidth: "200px", width: "100%" }}
186183
onClick={async (e) => {
187184
if (requiresSignIn) {
188185
e.preventDefault();
@@ -204,7 +201,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
204201
) : (
205202
<FiLock />
206203
)
207-
) : mountedAddress && chainId && chainId in chainIdToCurrencyMap ? (
204+
) : walletAddress && chainId && chainId in chainIdToCurrencyMap ? (
208205
<Icon
209206
boxSize="1.5em"
210207
name={chainIdToCurrencyMap[chainId as SUPPORTED_CHAIN_ID]}
@@ -225,7 +222,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
225222
)
226223
}
227224
>
228-
{mountedAddress ? (
225+
{walletAddress ? (
229226
requiresSignIn ? (
230227
<span style={{ whiteSpace: "nowrap" }}>Sign in</span>
231228
) : (
@@ -249,7 +246,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
249246
)}
250247
</span>
251248
<span style={{ fontSize: "0.9em" }}>
252-
{shortenIfAddress(mountedAddress)}
249+
{shortenIfAddress(walletAddress)}
253250
</span>
254251
</span>
255252
)
@@ -267,7 +264,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
267264
}}
268265
>
269266
<Menu {...api.contentProps}>
270-
{!api.isOpen ? null : mountedAddress ? (
267+
{!api.isOpen ? null : walletAddress ? (
271268
<>
272269
{authConfig?.authUrl && !user?.address && !requiresSignIn ? (
273270
<MenuItem
@@ -396,10 +393,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
396393
})}
397394
onClick={async () => {
398395
if (!connecting) {
399-
connecting = true;
400-
await connectWithMetamask();
401-
connecting = false;
402-
api.close();
396+
try {
397+
connecting = true;
398+
await connectWithMetamask();
399+
api.close();
400+
} finally {
401+
connecting = false;
402+
}
403403
}
404404
}}
405405
leftElement={<Icon boxSize="1.5em" name="metamask" />}
@@ -421,10 +421,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
421421
})}
422422
onClick={async () => {
423423
if (!connecting) {
424-
connecting = true;
425-
await connect(c);
426-
connecting = false;
427-
api.close();
424+
try {
425+
connecting = true;
426+
await connect(c);
427+
api.close();
428+
} finally {
429+
connecting = false;
430+
}
428431
}
429432
}}
430433
leftElement={getIconForConnector(c)}

0 commit comments

Comments
 (0)