MCPcopy
hub / github.com/BlueWallet/BlueWallet / SelectWallet

Function SelectWallet

screen/wallets/SelectWallet.tsx:23–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21type RouteProps = RouteProp<SendDetailsStackParamList, 'SelectWallet'>;
22
23const SelectWallet: React.FC = () => {
24 const route = useRoute<RouteProps>();
25 const {
26 chainType,
27 onWalletSelect,
28 availableWallets,
29 noWalletExplanationText,
30 onChainRequireSend = false,
31 selectedWalletID,
32 } = route.params;
33 const [isLoading, setIsLoading] = useState(true);
34 const navigation = useExtendedNavigation<NavigationProps>();
35 const { wallets } = useStorage();
36 const { colors } = useTheme();
37 const isModal = useNavigationState(state => state.routes.length > 1);
38 const walletsCarousel = useRef<any>(null);
39 const previousRouteName = useNavigationState(state => state.routes[state.routes.length - 2]?.name);
40 const [filteredWallets, setFilteredWallets] = useState<TWallet[]>([]);
41
42 const stylesHook = StyleSheet.create({
43 loading: {
44 backgroundColor: colors.background,
45 },
46 });
47
48 const filterWallets = useCallback(() => {
49 if (availableWallets && availableWallets.length > 0) {
50 return availableWallets;
51 }
52
53 if (!onChainRequireSend && chainType === Chain.ONCHAIN) {
54 return wallets.filter(item => item.chain === Chain.ONCHAIN);
55 }
56
57 if (chainType) {
58 return wallets.filter(item => item.chain === chainType && item.allowSend());
59 }
60
61 return wallets.filter(item => item.allowSend());
62 }, [availableWallets, chainType, onChainRequireSend, wallets]);
63
64 // Initialize filtered wallets and handle loading state
65 useEffect(() => {
66 console.log('SelectWallet - useEffect');
67 const filtered = filterWallets();
68 setFilteredWallets(filtered);
69 setIsLoading(false);
70 }, [filterWallets]);
71
72 // Scroll to the selected wallet if provided
73 useEffect(() => {
74 if (!isLoading && selectedWalletID && walletsCarousel.current) {
75 const walletIndex = filteredWallets.findIndex(wallet => wallet.getID() === selectedWalletID);
76
77 if (walletIndex !== -1) {
78 // Add a slight delay to ensure the carousel is fully rendered
79 setTimeout(() => {
80 if (walletsCarousel.current) {

Callers

nothing calls this directly

Calls 6

useExtendedNavigationFunction · 0.90
useStorageFunction · 0.90
useThemeFunction · 0.90
setIsLoadingFunction · 0.70
allowSendMethod · 0.45
getIDMethod · 0.45

Tested by

no test coverage detected