Skip to content

Commit 709c059

Browse files
chore: improved custom wallet image loading
1 parent b6acddd commit 709c059

File tree

10 files changed

+45
-19
lines changed

10 files changed

+45
-19
lines changed

packages/appkit/src/partials/w3m-all-wallets-list/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSnapshot } from 'valtio';
33
import { FlatList, View } from 'react-native';
44
import {
55
ApiController,
6+
AssetController,
67
AssetUtil,
78
OptionsController,
89
SnackController,
@@ -33,6 +34,7 @@ export function AllWalletsList({ columns, itemWidth, onItemPress }: AllWalletsLi
3334
const [pageLoading, setPageLoading] = useState<boolean>(false);
3435
const { maxWidth, padding } = useCustomDimensions();
3536
const { installed, featured, recommended, wallets } = useSnapshot(ApiController.state);
37+
const { walletImages } = useSnapshot(AssetController.state);
3638
const { customWallets } = useSnapshot(OptionsController.state) as OptionsControllerState;
3739
const imageHeaders = ApiController._getApiHeaders();
3840
const preloadedWallets = installed.length + featured.length + recommended.length;
@@ -89,7 +91,7 @@ export function AllWalletsList({ columns, itemWidth, onItemPress }: AllWalletsLi
8991
return (
9092
<View style={[styles.itemContainer, { width: itemWidth }]}>
9193
<CardSelect
92-
imageSrc={AssetUtil.getWalletImage(item)}
94+
imageSrc={AssetUtil.getWalletImage(item, walletImages)}
9395
imageHeaders={imageHeaders}
9496
name={item?.name ?? 'Unknown'}
9597
onPress={() => onItemPress(item)}

packages/appkit/src/partials/w3m-all-wallets-search/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { FlatList, View } from 'react-native';
3-
import { ApiController, AssetUtil, SnackController } from '@reown/appkit-core-react-native';
3+
import {
4+
ApiController,
5+
AssetController,
6+
AssetUtil,
7+
SnackController
8+
} from '@reown/appkit-core-react-native';
49
import { type WcWallet } from '@reown/appkit-common-react-native';
510
import {
611
CardSelect,
@@ -12,6 +17,7 @@ import {
1217
import { useCustomDimensions } from '../../hooks/useCustomDimensions';
1318
import { Placeholder } from '../w3m-placeholder';
1419
import styles from './styles';
20+
import { useSnapshot } from 'valtio';
1521

1622
export interface AllWalletsSearchProps {
1723
columns: number;
@@ -31,6 +37,7 @@ export function AllWalletsSearch({
3137
const [prevSearchQuery, setPrevSearchQuery] = useState<string>('');
3238
const imageHeaders = ApiController._getApiHeaders();
3339
const { maxWidth, padding, isLandscape } = useCustomDimensions();
40+
const { walletImages } = useSnapshot(AssetController.state);
3441

3542
const ITEM_HEIGHT = CardSelectHeight + Spacing.xs * 2;
3643

@@ -40,7 +47,7 @@ export function AllWalletsSearch({
4047
return (
4148
<View key={item?.id} style={[styles.itemContainer, { width: itemWidth }]}>
4249
<CardSelect
43-
imageSrc={AssetUtil.getWalletImage(item)}
50+
imageSrc={AssetUtil.getWalletImage(item, walletImages)}
4451
imageHeaders={imageHeaders}
4552
name={item?.name ?? 'Unknown'}
4653
onPress={() => onItemPress(item)}

packages/appkit/src/partials/w3m-connecting-mobile/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
CoreHelperUtil,
1010
OptionsController,
1111
EventsController,
12-
ConstantsUtil
12+
ConstantsUtil,
13+
AssetController
1314
} from '@reown/appkit-core-react-native';
1415
import {
1516
Button,
@@ -35,6 +36,7 @@ export function ConnectingMobile({ onRetry, onCopyUri, isInstalled }: Props) {
3536
const { data } = RouterController.state;
3637
const { maxWidth: width } = useCustomDimensions();
3738
const { wcUri, wcError } = useSnapshot(WcController.state);
39+
const { walletImages } = useSnapshot(AssetController.state);
3840
const [errorType, setErrorType] = useState<BodyErrorType>();
3941
const showCopy =
4042
OptionsController.isClipboardAvailable() &&
@@ -108,7 +110,7 @@ export function ConnectingMobile({ onRetry, onCopyUri, isInstalled }: Props) {
108110
<LoadingThumbnail paused={!!errorType || wcError}>
109111
<WalletImage
110112
size="xl"
111-
imageSrc={AssetUtil.getWalletImage(RouterController.state.data?.wallet)}
113+
imageSrc={AssetUtil.getWalletImage(RouterController.state.data?.wallet, walletImages)}
112114
imageHeaders={ApiController._getApiHeaders()}
113115
/>
114116
{wcError ? (

packages/appkit/src/partials/w3m-connecting-web/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
WcController,
99
CoreHelperUtil,
1010
OptionsController,
11-
EventsController
11+
EventsController,
12+
AssetController
1213
} from '@reown/appkit-core-react-native';
1314
import {
1415
Button,
@@ -29,6 +30,7 @@ interface ConnectingWebProps {
2930
export function ConnectingWeb({ onCopyUri }: ConnectingWebProps) {
3031
const { data } = RouterController.state;
3132
const { wcUri, wcError } = useSnapshot(WcController.state);
33+
const { walletImages } = useSnapshot(AssetController.state);
3234
const showCopy = OptionsController.isClipboardAvailable();
3335
const bodyMessage = getMessage({
3436
walletName: data?.wallet?.name,
@@ -68,7 +70,7 @@ export function ConnectingWeb({ onCopyUri }: ConnectingWebProps) {
6870
<LoadingThumbnail paused={wcError}>
6971
<WalletImage
7072
size="xl"
71-
imageSrc={AssetUtil.getWalletImage(data?.wallet)}
73+
imageSrc={AssetUtil.getWalletImage(data?.wallet, walletImages)}
7274
imageHeaders={ApiController._getApiHeaders()}
7375
/>
7476
{wcError ? (

packages/appkit/src/views/w3m-connect-view/components/all-wallet-list.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type StyleProp, type ViewStyle } from 'react-native';
22
import { useSnapshot } from 'valtio';
33
import {
44
ApiController,
5+
AssetController,
56
AssetUtil,
67
WcController,
78
type WcControllerState
@@ -19,6 +20,7 @@ interface Props {
1920
export function AllWalletList({ itemStyle, onWalletPress }: Props) {
2021
const { installed, featured, recommended, prefetchLoading } = useSnapshot(ApiController.state);
2122
const { recentWallets } = useSnapshot(WcController.state) as WcControllerState;
23+
const { walletImages } = useSnapshot(AssetController.state);
2224
const imageHeaders = ApiController._getApiHeaders();
2325
const RECENT_COUNT = recentWallets?.length && installed.length ? 1 : recentWallets?.length ?? 0;
2426

@@ -47,7 +49,7 @@ export function AllWalletList({ itemStyle, onWalletPress }: Props) {
4749
list.map(wallet => (
4850
<ListWallet
4951
key={wallet?.id}
50-
imageSrc={AssetUtil.getWalletImage(wallet)}
52+
imageSrc={AssetUtil.getWalletImage(wallet, walletImages)}
5153
imageHeaders={imageHeaders}
5254
name={wallet?.name ?? 'Unknown'}
5355
onPress={() => onWalletPress(wallet)}

packages/appkit/src/views/w3m-connect-view/components/custom-wallet-list.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
ApiController,
77
WcController,
88
type WcControllerState,
9-
AssetUtil
9+
AssetUtil,
10+
AssetController
1011
} from '@reown/appkit-core-react-native';
1112
import { type CustomWallet } from '@reown/appkit-common-react-native';
1213
import { ListWallet } from '@reown/appkit-ui-react-native';
@@ -19,6 +20,7 @@ interface Props {
1920

2021
export function CustomWalletList({ itemStyle, onWalletPress }: Props) {
2122
const { installed } = useSnapshot(ApiController.state);
23+
const { walletImages } = useSnapshot(AssetController.state);
2224
const imageHeaders = ApiController._getApiHeaders();
2325
const { recentWallets } = useSnapshot(WcController.state) as WcControllerState;
2426
const { customWallets } = useSnapshot(OptionsController.state) as OptionsControllerState;
@@ -33,7 +35,7 @@ export function CustomWalletList({ itemStyle, onWalletPress }: Props) {
3335
return list.map(wallet => (
3436
<ListWallet
3537
key={wallet.id}
36-
imageSrc={AssetUtil.getWalletImage(wallet)}
38+
imageSrc={AssetUtil.getWalletImage(wallet, walletImages)}
3739
imageHeaders={imageHeaders}
3840
name={wallet.name}
3941
onPress={() => onWalletPress(wallet)}

packages/appkit/src/views/w3m-connect-view/components/recent-wallet-list.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { useSnapshot } from 'valtio';
2-
import { ApiController, AssetUtil, WcController } from '@reown/appkit-core-react-native';
2+
import {
3+
ApiController,
4+
AssetController,
5+
AssetUtil,
6+
WcController
7+
} from '@reown/appkit-core-react-native';
38
import { type WcWallet } from '@reown/appkit-common-react-native';
49
import { ListWallet } from '@reown/appkit-ui-react-native';
510
import type { StyleProp, ViewStyle } from 'react-native';
@@ -12,6 +17,7 @@ interface Props {
1217
export function RecentWalletList({ itemStyle, onWalletPress }: Props) {
1318
const installed = ApiController.state.installed;
1419
const { recentWallets } = useSnapshot(WcController.state);
20+
const { walletImages } = useSnapshot(AssetController.state);
1521
const imageHeaders = ApiController._getApiHeaders();
1622
const RECENT_COUNT = recentWallets?.length && installed.length ? 1 : recentWallets?.length ?? 0;
1723

@@ -25,7 +31,7 @@ export function RecentWalletList({ itemStyle, onWalletPress }: Props) {
2531
return (
2632
<ListWallet
2733
key={wallet?.id}
28-
imageSrc={AssetUtil.getWalletImage(wallet)}
34+
imageSrc={AssetUtil.getWalletImage(wallet, walletImages)}
2935
imageHeaders={imageHeaders}
3036
name={wallet?.name ?? 'Unknown'}
3137
onPress={() => onWalletPress(wallet, isInstalled)}

packages/appkit/src/views/w3m-connecting-external-view/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
ApiController,
77
EventsController,
88
WcController,
9-
AssetUtil
9+
AssetUtil,
10+
AssetController
1011
} from '@reown/appkit-core-react-native';
1112
import {
1213
Button,
@@ -24,6 +25,7 @@ import { ConstantsUtil } from '@reown/appkit-common-react-native';
2425

2526
export function ConnectingExternalView() {
2627
const { data } = useSnapshot(RouterController.state);
28+
const { walletImages } = useSnapshot(AssetController.state);
2729
const { connect } = useInternalAppKit();
2830
const { maxWidth: width } = useCustomDimensions();
2931
const [errorType, setErrorType] = useState<BodyErrorType>();
@@ -90,7 +92,7 @@ export function ConnectingExternalView() {
9092
<LoadingThumbnail paused={!!errorType}>
9193
<WalletImage
9294
size="xl"
93-
imageSrc={AssetUtil.getWalletImage(data?.wallet)}
95+
imageSrc={AssetUtil.getWalletImage(data?.wallet, walletImages)}
9496
imageHeaders={ApiController._getApiHeaders()}
9597
/>
9698
{errorType ? (

packages/appkit/src/views/w3m-get-wallet-view/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Linking, Platform, ScrollView } from 'react-native';
22
import { FlexView, ListWallet } from '@reown/appkit-ui-react-native';
3-
import { ApiController, AssetUtil } from '@reown/appkit-core-react-native';
3+
import { ApiController, AssetController, AssetUtil } from '@reown/appkit-core-react-native';
44
import { type WcWallet } from '@reown/appkit-common-react-native';
55
import { useCustomDimensions } from '../../hooks/useCustomDimensions';
66
import styles from './styles';
7+
import { useSnapshot } from 'valtio';
78

89
export function GetWalletView() {
10+
const { walletImages } = useSnapshot(AssetController.state);
911
const { padding } = useCustomDimensions();
1012
const imageHeaders = ApiController._getApiHeaders();
1113

@@ -22,7 +24,7 @@ export function GetWalletView() {
2224
<ListWallet
2325
key={wallet.id}
2426
name={wallet.name}
25-
imageSrc={AssetUtil.getWalletImage(wallet)}
27+
imageSrc={AssetUtil.getWalletImage(wallet, walletImages)}
2628
imageHeaders={imageHeaders}
2729
onPress={() => onWalletPress(wallet)}
2830
style={styles.item}

packages/core/src/utils/AssetUtil.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type { AppKitNetwork, WcWallet } from '@reown/appkit-common-react-native';
2-
import { AssetController } from '../controllers/AssetController';
32

43
export const AssetUtil = {
5-
getWalletImage(wallet?: WcWallet) {
4+
getWalletImage(wallet?: WcWallet, walletImages?: Record<string, string>) {
65
if (wallet?.image_url) {
76
return wallet?.image_url;
87
}
98

109
if (wallet?.image_id) {
11-
return AssetController.state.walletImages[wallet.image_id];
10+
return walletImages?.[wallet.image_id];
1211
}
1312

1413
return undefined;

0 commit comments

Comments
 (0)