import { useSnapshot } from 'valtio'; import { useCallback, useEffect, useState } from 'react'; import { Platform, ScrollView } from 'react-native'; import { RouterController, ApiController, EventsController, WcController, AssetUtil, AssetController, CoreHelperUtil, LogController, ConnectionsController } from '@reown/appkit-core-react-native'; import { Button, FlexView, IconBox, LoadingThumbnail, WalletImage, useCustomDimensions } from '@reown/appkit-ui-react-native'; import { ConnectingBody, getMessage, type BodyErrorType } from '../../partials/w3m-connecting-body'; import styles from './styles'; import { useInternalAppKit } from '../../AppKitContext'; import { StoreLink } from '../../partials/w3m-connecting-mobile/components/StoreLink'; import { WcHelpersUtil } from '../../utils/HelpersUtil'; import { ErrorUtil } from '@reown/appkit-common-react-native'; export function ConnectingExternalView() { const { data } = useSnapshot(RouterController.state); const { walletImages } = useSnapshot(AssetController.state); const { connect } = useInternalAppKit(); const { padding } = useCustomDimensions(); const [errorType, setErrorType] = useState(); const bodyMessage = getMessage({ walletName: data?.wallet?.name, errorType }); const storeUrl = Platform.select({ ios: data?.wallet?.app_store, android: data?.wallet?.play_store }); const onStorePress = () => { if (storeUrl) { CoreHelperUtil.openLink(storeUrl); EventsController.sendEvent({ type: 'track', event: 'GET_WALLET', properties: { name: RouterController.state.data?.wallet?.name ?? 'Unknown', link: storeUrl, linkType: Platform.select({ ios: 'appstore', android: 'playstore', default: undefined }), explorerId: RouterController.state.data?.wallet?.id, walletRank: RouterController.state.data?.wallet?.order } }); } }; const onRetryPress = () => { setErrorType(undefined); onConnect(); }; const onConnect = useCallback(async () => { try { const wallet = RouterController.state.data?.wallet; if (wallet) { if (WcHelpersUtil.isExternalWallet(wallet)) { await connect({ wallet }); } else { // All other wallets are handled by WalletConnect connector return; } WcController.addRecentWallet(wallet); WcController.setPressedWallet(wallet); const address = ConnectionsController.state.activeAddress; const caipNetworkId = ConnectionsController.state.activeNetwork?.caipNetworkId; EventsController.sendEvent({ type: 'track', event: 'CONNECT_SUCCESS', address: CoreHelperUtil.getPlainAddress(address), properties: { name: wallet?.name ?? 'Unknown', method: 'mobile', caipNetworkId, explorerId: wallet?.id } }); } } catch (error) { LogController.sendError(error, 'ConnectingExternalView.tsx', 'onConnect'); const type = ErrorUtil.categorizeConnectionError(error); setErrorType(type); EventsController.sendEvent({ type: 'track', event: type === 'declined' ? 'USER_REJECTED' : 'CONNECT_ERROR', properties: { message: (error as Error)?.message ?? 'Unknown' } }); } }, [connect]); useEffect(() => { onConnect(); }, [onConnect]); return ( {errorType ? ( ) : null} {errorType !== 'not_installed' && ( )} ); }