()
| 21 | type RouteProps = RouteProp<SendDetailsStackParamList, 'SelectWallet'>; |
| 22 | |
| 23 | const 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) { |
nothing calls this directly
no test coverage detected