Skip to content

Commit adcbec6

Browse files
[SDK] Fix: Add custom title & icon to wagmi connectors (#6858)
Co-authored-by: Joaquim Verges <[email protected]>
1 parent d43ad17 commit adcbec6

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

.changeset/fuzzy-paws-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/wagmi-adapter": patch
3+
---
4+
5+
Respect inAppWallet metadata props

.changeset/solid-numbers-return.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 name and icon to inAppWallet metadata props to customize in-app wallets inside the connect modal

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/AllWalletsUI.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function AllWalletsUI(props: {
130130
>
131131
{walletInfosToShow.map((walletInfo, i) => {
132132
const isLast = i === walletInfosToShow.length - 1;
133+
const wallet = createWallet(walletInfo.id);
133134

134135
return (
135136
<li
@@ -140,9 +141,8 @@ function AllWalletsUI(props: {
140141
}}
141142
>
142143
<WalletEntryButton
143-
walletId={walletInfo.id}
144+
wallet={wallet}
144145
selectWallet={() => {
145-
const wallet = createWallet(walletInfo.id);
146146
props.onSelect(wallet);
147147
if (!props.disableSelectionDataReset) {
148148
setSelectionData({});

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletEntryButton.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22
import type { ThirdwebClient } from "../../../../client/client.js";
3+
import type { InAppWalletCreationOptions } from "../../../../wallets/in-app/core/wallet/types.js";
34
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
45
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
5-
import type { WalletId } from "../../../../wallets/wallet-types.js";
66
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
77
import {
88
fontSize,
@@ -11,6 +11,7 @@ import {
1111
spacing,
1212
} from "../../../core/design-system/index.js";
1313
import { useWalletInfo } from "../../../core/utils/wallet.js";
14+
import { Img } from "../components/Img.js";
1415
import { Skeleton } from "../components/Skeleton.js";
1516
import { WalletImage } from "../components/WalletImage.js";
1617
import { Container } from "../components/basic.js";
@@ -22,15 +23,16 @@ import type { ConnectLocale } from "./locale/types.js";
2223
* @internal
2324
*/
2425
export function WalletEntryButton(props: {
25-
walletId: WalletId;
26+
wallet: Wallet;
2627
selectWallet: () => void;
2728
connectLocale: ConnectLocale;
2829
recommendedWallets: Wallet[] | undefined;
2930
client: ThirdwebClient;
3031
isActive: boolean;
3132
badge: string | undefined;
3233
}) {
33-
const { walletId, selectWallet } = props;
34+
const { selectWallet, wallet } = props;
35+
const walletId = wallet.id;
3436
const isRecommended = props.recommendedWallets?.find(
3537
(w) => w.id === walletId,
3638
);
@@ -45,23 +47,39 @@ export function WalletEntryButton(props: {
4547
(p) => p.info.rdns === walletId,
4648
);
4749

50+
const customMeta =
51+
wallet && walletId === "inApp"
52+
? (wallet.getConfig() as InAppWalletCreationOptions)?.metadata
53+
: undefined;
54+
const nameOverride = customMeta?.name || walletName;
55+
const iconOverride = customMeta?.icon;
56+
4857
return (
4958
<WalletButtonEl
5059
type="button"
5160
onClick={selectWallet}
5261
data-active={props.isActive}
5362
>
54-
<WalletImage id={walletId} size={iconSize.xl} client={props.client} />
63+
{iconOverride ? (
64+
<Img
65+
client={props.client}
66+
src={iconOverride}
67+
alt={nameOverride}
68+
width={`${iconSize.xl}`}
69+
height={`${iconSize.xl}`}
70+
/>
71+
) : (
72+
<WalletImage id={walletId} size={iconSize.xl} client={props.client} />
73+
)}
5574

5675
<Container flex="column" gap="xxs" expand>
57-
{walletName ? (
76+
{nameOverride ? (
5877
<Text color="primaryText" weight={600}>
59-
{walletName}
78+
{nameOverride}
6079
</Text>
6180
) : (
6281
<Skeleton width="100px" height={fontSize.md} />
6382
)}
64-
6583
{props.badge ? (
6684
<Text size="sm">{props.badge}</Text>
6785
) : isRecommended ? (

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletSelector.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
218218
);
219219

220220
const handleSelect = async (wallet: Wallet) => {
221-
// if (connectionStatus !== "disconnected") {
222-
// await disconnect();
223-
// }
224221
props.selectWallet(wallet);
225222
};
226223

@@ -640,7 +637,7 @@ const WalletSelection: React.FC<{
640637
</Suspense>
641638
) : (
642639
<WalletEntryButton
643-
walletId={wallet.id}
640+
wallet={wallet}
644641
selectWallet={() => {
645642
if (!props.diableSelectionDataReset) {
646643
setSelectionData({});

packages/thirdweb/src/react/web/wallets/in-app/InAppWalletSelectionUI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function InAppWalletSelectionUI(props: {
4141
) {
4242
return (
4343
<WalletEntryButton
44-
walletId={props.wallet.id}
44+
wallet={props.wallet}
4545
selectWallet={() => {
4646
setData({});
4747
props.select();

packages/thirdweb/src/wallets/in-app/core/wallet/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export type InAppWalletCreationOptions =
6969
* Metadata to display in the Connect Modal
7070
*/
7171
metadata?: {
72+
name?: string;
73+
icon?: string;
7274
image?: {
7375
src: string;
7476
width?: number;

packages/wagmi-adapter/src/connector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ export function inAppWalletConnector(
9494
const client = args.client;
9595
return createConnector<Provider, Properties, StorageItem>((config) => ({
9696
id: "in-app-wallet",
97-
name: "In-App wallet",
97+
name: args.metadata?.name || "In-App wallet",
9898
type: "in-app",
99+
icon: args.metadata?.icon,
99100
connect: async (params) => {
100101
const rawStorage =
101102
typeof window !== "undefined" && window.localStorage

0 commit comments

Comments
 (0)