Skip to content

Commit 1c533ef

Browse files
fix: respect transaction button theme prop (#3341)
<!-- start pr-codex --> ## PR-Codex overview This PR fixes the issue where the transaction button did not respect the theme prop in the `SponsoredTxPreview` component. ### Detailed summary - Fixed transaction button theme prop issue in `SponsoredTxPreview` - Added `isValidTheme` and `parseTheme` functions in `buttons.tsx` - Updated `parseTheme` to validate theme and return default if invalid > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent eca6217 commit 1c533ef

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

.changeset/dull-steaks-roll.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+
Fix transaction button not respecting theme prop

apps/playground-web/src/components/account-abstraction/sponsored-tx.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
useReadContract,
1313
} from "thirdweb/react";
1414
import { THIRDWEB_CLIENT } from "../../lib/client";
15-
import { CodeExample } from "../code/code-example";
1615
import { editionDropContract, editionDropTokenId } from "./constants";
1716

1817
export function SponsoredTxPreview() {

packages/thirdweb/src/react/core/design-system/CustomThemeProvider.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function CustomThemeProvider(props: {
2222
}
2323

2424
export function parseTheme(theme: "light" | "dark" | Theme | undefined): Theme {
25-
if (!theme) {
25+
if (!theme || !isValidTheme(theme)) {
2626
return darkThemeObj;
2727
}
2828

@@ -37,6 +37,19 @@ export function parseTheme(theme: "light" | "dark" | Theme | undefined): Theme {
3737
return themeObj;
3838
}
3939

40+
export function isValidTheme(theme: unknown): theme is Theme {
41+
return (
42+
theme === "dark" ||
43+
theme === "light" ||
44+
(typeof theme === "object" &&
45+
theme !== null &&
46+
"colors" in theme &&
47+
"fontSizes" in theme &&
48+
"radii" in theme &&
49+
"space" in theme)
50+
);
51+
}
52+
4053
/**
4154
*
4255
* @internal

packages/thirdweb/src/react/web/ui/components/buttons.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use client";
2-
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
2+
import {
3+
isValidTheme,
4+
parseTheme,
5+
useCustomTheme,
6+
} from "../../../core/design-system/CustomThemeProvider.js";
37
import {
48
type Theme,
59
fontSize,
@@ -17,7 +21,8 @@ export type ButtonProps = {
1721
};
1822

1923
export const Button = /* @__PURE__ */ StyledButton((props: ButtonProps) => {
20-
const theme = useCustomTheme();
24+
const _theme = useCustomTheme();
25+
const theme = isValidTheme(props.theme) ? parseTheme(props.theme) : _theme;
2126
if (props.unstyled) {
2227
return {};
2328
}

0 commit comments

Comments
 (0)