| 14 | }; |
| 15 | |
| 16 | const showAlertWithWalletOptions = ( |
| 17 | wallets: TWallet[], |
| 18 | title: string, |
| 19 | message: string, |
| 20 | onWalletSelected: (wallet: TWallet) => void, |
| 21 | filterFn?: (wallet: TWallet) => boolean, |
| 22 | ) => { |
| 23 | const filteredWallets = filterFn ? wallets.filter(filterFn) : wallets; |
| 24 | |
| 25 | const showWallet = (index: number) => { |
| 26 | if (index >= filteredWallets.length) return; |
| 27 | const wallet = filteredWallets[index]; |
| 28 | |
| 29 | if (Platform.OS === 'android') { |
| 30 | // Android: Use a limited number of buttons since the alert dialog has a limit |
| 31 | Alert.alert( |
| 32 | `${title}: ${wallet.getLabel()}`, |
| 33 | `${message}\n\nSelected Wallet: ${wallet.getLabel()}\n\nWould you like to select this wallet or see the next one?`, |
| 34 | [ |
| 35 | { |
| 36 | text: 'Select This Wallet', |
| 37 | onPress: () => onWalletSelected(wallet), |
| 38 | }, |
| 39 | { |
| 40 | text: 'Show Next Wallet', |
| 41 | onPress: () => showWallet(index + 1), |
| 42 | }, |
| 43 | { |
| 44 | text: 'Cancel', |
| 45 | style: 'cancel', |
| 46 | }, |
| 47 | ], |
| 48 | { cancelable: true }, |
| 49 | ); |
| 50 | } else { |
| 51 | const options: AlertButton[] = filteredWallets.map(w => ({ |
| 52 | text: w.getLabel(), |
| 53 | onPress: () => onWalletSelected(w), |
| 54 | })); |
| 55 | |
| 56 | options.push({ |
| 57 | text: 'Cancel', |
| 58 | style: 'cancel', |
| 59 | }); |
| 60 | |
| 61 | Alert.alert(title, message, options, { cancelable: true }); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | if (filteredWallets.length > 0) { |
| 66 | showWallet(0); |
| 67 | } else { |
| 68 | Alert.alert('No wallets available'); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | const DevMenu: React.FC = () => { |
| 73 | const { wallets, addWallet } = useStorage(); |