Skip to content

Commit 89641e3

Browse files
tommaayMananTank
andauthoredJan 17, 2024
[react] Add switchNetworkBtnTitle prop in ConnectWallet and Web3Button (thirdweb-dev#1884)
Co-authored-by: Manan Tank <[email protected]>
1 parent dcb6afa commit 89641e3

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
 

‎.changeset/five-walls-smash.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
Add prop `switchNetworkBtnTitle` to `ConnectWallet` and `Web3Button` components to allow changing the "Switch Network" label on the button which is displayed when user needs to switch the network in the connected wallet.
6+
7+
```tsx
8+
<ConnectWallet switchNetworkBtnTitle="Switch Chain" />
9+
```
10+
11+
```tsx
12+
<Web3Button
13+
switchNetworkBtnTitle="Switch Chain"
14+
contractAddress="0x..."
15+
action={someAction}
16+
/>
17+
```

‎packages/react/src/evm/components/Web3Button/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ export interface Web3ButtonProps<TActionFn extends ActionFn> {
186186
*/
187187
welcomeScreen?: WelcomeScreen;
188188
};
189+
190+
/**
191+
* Set a custom label for the "Switch Network" button
192+
*/
193+
switchNetworkBtnTitle?: string;
189194
}
190195

191196
/**
@@ -255,6 +260,8 @@ export const Web3Button = <TAction extends ActionFn>(
255260
const theme = props.theme || contextTheme || "dark";
256261

257262
const locale = useTWLocale();
263+
const switchNetworkLabel =
264+
props.switchNetworkBtnTitle || locale.connectWallet.switchNetwork;
258265

259266
const [confirmStatus, setConfirmStatus] = useState<"idle" | "waiting">(
260267
"idle",
@@ -337,7 +344,7 @@ export const Web3Button = <TAction extends ActionFn>(
337344
{confirmStatus === "waiting" ? (
338345
<Spinner size="sm" color={"primaryButtonText"} />
339346
) : (
340-
locale.connectWallet.switchNetwork
347+
switchNetworkLabel
341348
)}
342349
</Button>
343350
);

‎packages/react/src/wallet/ConnectWallet/ConnectWallet.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export type ConnectWalletProps = {
7979
*/
8080
btnTitle?: string;
8181

82+
/**
83+
* Set a custom label for the "Switch Network" button
84+
*/
85+
switchNetworkBtnTitle?: string;
86+
8287
/**
8388
* Change the title of ConnectWallet Modal
8489
*
@@ -722,6 +727,7 @@ export function ConnectWallet(props: ConnectWalletProps) {
722727
<SwitchNetworkButton
723728
style={props.style}
724729
className={props.className}
730+
switchNetworkBtnTitle={props.switchNetworkBtnTitle}
725731
/>
726732
);
727733
}
@@ -784,12 +790,16 @@ export function ConnectWallet(props: ConnectWalletProps) {
784790
function SwitchNetworkButton(props: {
785791
style?: React.CSSProperties;
786792
className?: string;
793+
switchNetworkBtnTitle?: string;
787794
}) {
788795
const { activeChain } = useWalletContext();
789796
const switchChain = useSwitchChain();
790797
const [switching, setSwitching] = useState(false);
791798
const locale = useTWLocale();
792799

800+
const switchNetworkBtnTitle =
801+
props.switchNetworkBtnTitle ?? locale.connectWallet.switchNetwork;
802+
793803
return (
794804
<AnimatedButton
795805
className={`${TW_CONNECT_WALLET}--switch-network ${
@@ -818,7 +828,7 @@ function SwitchNetworkButton(props: {
818828
{switching ? (
819829
<Spinner size="sm" color="primaryButtonText" />
820830
) : (
821-
locale.connectWallet.switchNetwork
831+
switchNetworkBtnTitle
822832
)}
823833
</AnimatedButton>
824834
);

0 commit comments

Comments
 (0)
Please sign in to comment.