Skip to content

Commit

Permalink
[React Native] Option to hide [Switch to Personal Wallet] button (#1908)
Browse files Browse the repository at this point in the history
Co-authored-by: ikethirdweb <jorge@thirdweb.com>
  • Loading branch information
Kien Ngo and ikethirdweb authored Nov 9, 2023
1 parent 9187e0f commit 18552f3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-pillows-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/react-native": patch
---

Add `hideSwitchToPersonalWallet` prop on `ConnectWallet` component to hide the "Switch to Personal wallet" option in the ConnectWallet modal which is shown when wallet is connected as a Smart Wallet
9 changes: 9 additions & 0 deletions packages/react-native/src/evm/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export type ConnectWalletProps = {
* ```
*/
displayBalanceToken?: Record<number, string>;

/**
* Hide the "switch to Personal wallet" option in the wallet modal which is shown when wallet is connected to a Smart Wallet
*
* @default false
*/
hideSwitchToPersonalWallet?: boolean;
} & ConnectWalletButtonProps;

export const ConnectWallet = ({
Expand All @@ -84,6 +91,7 @@ export const ConnectWallet = ({
termsOfServiceUrl,
privacyPolicyUrl,
supportedTokens,
hideSwitchToPersonalWallet,
}: ConnectWalletProps) => {
const globalTheme = useGlobalTheme();
const l = useLocale();
Expand Down Expand Up @@ -163,6 +171,7 @@ export const ConnectWallet = ({
hideTestnetFaucet={hideTestnetFaucet}
supportedTokens={supportedTokensMemo}
displayBalanceToken={displayBalanceToken}
hideSwitchToPersonalWallet={hideSwitchToPersonalWallet}
/>
)
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ConnectWalletDetailsModal = ({
hideTestnetFaucet,
supportedTokens,
displayBalanceToken,
hideSwitchToPersonalWallet,
}: {
isVisible: boolean;
onClosePress: () => void;
Expand All @@ -50,6 +51,7 @@ export const ConnectWalletDetailsModal = ({
hideTestnetFaucet?: boolean;
supportedTokens: SupportedTokens;
displayBalanceToken?: Record<number, string>;
hideSwitchToPersonalWallet?: boolean;
}) => {
const l = useLocale();
const [isExportModalVisible, setIsExportModalVisible] = useState(false);
Expand Down Expand Up @@ -131,6 +133,7 @@ export const ConnectWalletDetailsModal = ({
return (
<SmartWalletAdditionalActions
onExportPress={onExportLocalWalletPress}
hideSwitchToPersonalWallet={hideSwitchToPersonalWallet}
/>
);
}
Expand Down Expand Up @@ -208,6 +211,7 @@ export const ConnectWalletDetailsModal = ({
onWalletImported,
smartWallet,
l,
hideSwitchToPersonalWallet,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { useGlobalTheme, useLocale } from "../../providers/ui-context-provider";

export const SmartWalletAdditionalActions = ({
onExportPress,
hideSwitchToPersonalWallet,
}: {
onExportPress: () => void;
hideSwitchToPersonalWallet?: boolean;
}) => {
const l = useLocale();
const { setConnectedWallet } = useWalletContext();
Expand Down Expand Up @@ -61,22 +63,25 @@ export const SmartWalletAdditionalActions = ({

return (
<>
<IconTextButton
mt="xs"
text={
showSmartWallet
? l.smart_wallet.switch_to_smart
: l.smart_wallet.switch_to_personal
}
icon={
<DisconnectIcon
width={14}
height={14}
color={theme.colors.iconPrimary}
/>
}
onPress={onWalletPress}
/>
{(showSmartWallet || !hideSwitchToPersonalWallet) && (
<IconTextButton
mt="xs"
text={
showSmartWallet
? l.smart_wallet.switch_to_smart
: l.smart_wallet.switch_to_personal
}
icon={
<DisconnectIcon
width={14}
height={14}
color={theme.colors.iconPrimary}
/>
}
onPress={onWalletPress}
/>
)}

{!showSmartWallet && smartWallet?.enableConnectApp ? (
<ConnectAppField />
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export type ConnectWalletDetailsProps = {
* ```
*/
displayBalanceToken?: Record<number, string>;
/**
* Hide the "switch to Personal wallet" option in the dropdown which is shown when wallet is connected to a Smart Wallet
*
* @default false
*/
hideSwitchToPersonalWallet?: boolean;
};

export const WalletDetailsButton = ({
Expand All @@ -45,6 +51,7 @@ export const WalletDetailsButton = ({
hideTestnetFaucet,
supportedTokens,
displayBalanceToken,
hideSwitchToPersonalWallet,
}: ConnectWalletDetailsProps) => {
const l = useLocale();
const activeWallet = useWallet();
Expand Down Expand Up @@ -76,6 +83,7 @@ export const WalletDetailsButton = ({
hideTestnetFaucet={hideTestnetFaucet}
supportedTokens={supportedTokens}
displayBalanceToken={displayBalanceToken}
hideSwitchToPersonalWallet={hideSwitchToPersonalWallet}
/>
{detailsButton ? (
detailsButton({ onPress })
Expand Down

0 comments on commit 18552f3

Please sign in to comment.