Skip to content

Commit 629efc1

Browse files
[SDK] Add Monad chain definition (#8465)
1 parent 512f9dd commit 629efc1

File tree

8 files changed

+75
-7
lines changed

8 files changed

+75
-7
lines changed

.changeset/angry-monkeys-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add customization options for the signIn modal shown from useFetchWithPayment

.changeset/moody-camels-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add monad chain definition
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineChain } from "../utils.js";
2+
3+
/**
4+
* @chain
5+
*/
6+
export const monad = /*@__PURE__*/ defineChain({
7+
blockExplorers: [
8+
{
9+
name: "Monad Vision",
10+
url: "https://monadvision.com/",
11+
},
12+
{
13+
name: "Monad Scan",
14+
url: "https://monadscan.com/",
15+
},
16+
],
17+
id: 143,
18+
name: "Monad",
19+
nativeCurrency: { decimals: 18, name: "Mon", symbol: "MON" },
20+
});

packages/thirdweb/src/exports/chains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export { mantaPacificTestnet } from "../chains/chain-definitions/manta-pacific-t
5252
export { metalL2Testnet } from "../chains/chain-definitions/metal-l2-testnet.js";
5353
export { mode } from "../chains/chain-definitions/mode.js";
5454
export { modeTestnet } from "../chains/chain-definitions/mode-testnet.js";
55+
export { monad } from "../chains/chain-definitions/monad.js";
5556
export { monadTestnet } from "../chains/chain-definitions/monad-testnet.js";
5657
export { moonbeam } from "../chains/chain-definitions/moonbeam.js";
5758
export { optimism } from "../chains/chain-definitions/optimism.js";

packages/thirdweb/src/react/core/hooks/others/useInvalidateBalances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { invalidateWalletBalance } from "../../providers/invalidateWalletBalance
1212
export function useInvalidateBalances() {
1313
const queryClient = useQueryClient();
1414

15-
return ({ chainId }: { chainId?: number }) => {
15+
return ({ chainId }: { chainId?: number } = {}) => {
1616
invalidateWalletBalance(queryClient, chainId);
1717
};
1818
}

packages/thirdweb/src/react/core/hooks/x402/useFetchWithPaymentCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ export function useFetchWithPaymentCore(
9999
errorData: errorBody,
100100
onRetry: async () => {
101101
// Retry the entire fetch+error handling logic recursively
102+
// Pass currentWallet to avoid re-showing connect modal with stale wallet state
102103
try {
103-
const result = await executeFetch();
104+
const result = await executeFetch(currentWallet);
104105
resolve(result);
105106
} catch (error) {
106107
reject(error);

packages/thirdweb/src/react/web/hooks/x402/useFetchWithPayment.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ type UseFetchWithPaymentConfig = UseFetchWithPaymentOptions & {
4646
* These options will be merged with the client, theme, and chain from the hook.
4747
*/
4848
connectOptions?: Omit<UseConnectModalOptions, "client" | "theme">;
49+
/**
50+
* Options to customize the SignInRequiredModal that appears when the user needs to sign in.
51+
*/
52+
signInRequiredModal?: {
53+
/** Custom title for the modal header */
54+
title?: string;
55+
/** Custom description text */
56+
description?: string;
57+
/** Custom label for the sign in button */
58+
buttonLabel?: string;
59+
};
4960
};
5061

5162
/**
@@ -73,6 +84,7 @@ type UseFetchWithPaymentConfig = UseFetchWithPaymentOptions & {
7384
* @param options.theme - Theme for the payment error modal (defaults to "dark")
7485
* @param options.fundWalletOptions - Customize the BuyWidget shown when user needs to fund their wallet
7586
* @param options.connectOptions - Customize the ConnectModal shown when user needs to sign in
87+
* @param options.signInRequiredModal - Customize the SignInRequiredModal shown when user needs to sign in (title, description, buttonLabel)
7688
* @returns An object containing:
7789
* - `fetchWithPayment`: Function to make fetch requests with automatic payment handling (returns parsed data)
7890
* - `isPending`: Boolean indicating if a request is in progress
@@ -146,6 +158,17 @@ type UseFetchWithPaymentConfig = UseFetchWithPaymentOptions & {
146158
* });
147159
* ```
148160
*
161+
* ### Customize the sign in required modal
162+
* ```tsx
163+
* const { fetchWithPayment } = useFetchWithPayment(client, {
164+
* signInRequiredModal: {
165+
* title: "Authentication Required",
166+
* description: "Please sign in to access this paid content.",
167+
* buttonLabel: "Connect Wallet",
168+
* }
169+
* });
170+
* ```
171+
*
149172
* ### Disable the UI and handle errors yourself
150173
* ```tsx
151174
* const { fetchWithPayment, error } = useFetchWithPayment(client, {
@@ -201,6 +224,9 @@ export function useFetchWithPayment(
201224
setRootEl(
202225
<SignInRequiredModal
203226
theme={theme}
227+
title={options?.signInRequiredModal?.title}
228+
description={options?.signInRequiredModal?.description}
229+
buttonLabel={options?.signInRequiredModal?.buttonLabel}
204230
onSignIn={async () => {
205231
// Close the SignInRequiredModal
206232
setRootEl(null);

packages/thirdweb/src/react/web/ui/x402/SignInRequiredModal.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ type SignInRequiredModalProps = {
1515
theme: Theme | "light" | "dark";
1616
onSignIn: () => void;
1717
onCancel: () => void;
18+
title?: string;
19+
description?: string;
20+
buttonLabel?: string;
1821
};
1922

2023
/**
2124
* @internal
2225
*/
2326
export function SignInRequiredModal(props: SignInRequiredModalProps) {
24-
const { theme, onSignIn, onCancel } = props;
27+
const {
28+
theme,
29+
onSignIn,
30+
onCancel,
31+
title = "Sign in required",
32+
description = "Account required to complete payment, please sign in to continue.",
33+
buttonLabel = "Sign in",
34+
} = props;
2535

2636
return (
2737
<CustomThemeProvider theme={theme}>
@@ -35,10 +45,10 @@ export function SignInRequiredModal(props: SignInRequiredModalProps) {
3545
}
3646
}}
3747
size="compact"
38-
title="Sign in required"
48+
title={title}
3949
>
4050
<Container p="lg">
41-
<ModalHeader title="Sign in required" />
51+
<ModalHeader title={title} />
4252

4353
<Container
4454
flex="column"
@@ -55,15 +65,15 @@ export function SignInRequiredModal(props: SignInRequiredModalProps) {
5565
lineHeight: 1.5,
5666
}}
5767
>
58-
Account required to complete payment, please sign in to continue.
68+
{description}
5969
</Text>
6070
</Container>
6171
</Container>
6272

6373
{/* Action Buttons */}
6474
<ScreenBottomContainer>
6575
<Button fullWidth gap="xs" onClick={onSignIn} variant="accent">
66-
Sign in
76+
{buttonLabel}
6777
</Button>
6878
<Button fullWidth gap="xs" onClick={onCancel} variant="secondary">
6979
Cancel

0 commit comments

Comments
 (0)