Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disabled send to your own wallets if there is only one wallet available #5549

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/screens/Send/SendScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Pressable,
} from 'react-native';
import { Box, useColorMode } from 'native-base';
import React, { useContext, useEffect, useState } from 'react';
import React, { useContext, useEffect, useMemo, useState } from 'react';
import { hp, windowHeight, wp } from 'src/constants/responsive';
import Text from 'src/components/KeeperText';
import Colors from 'src/theme/Colors';
Expand All @@ -23,7 +23,13 @@ import ArrowIcon from 'src/assets/images/icon_arrow.svg';
import RemoveIcon from 'src/assets/images/remove-green-icon.svg';
import RemoveIconDark from 'src/assets/images/remove-white-icon.svg';
import { LocalizationContext } from 'src/context/Localization/LocContext';
import { EntityKind, NetworkType, PaymentInfoKind, VaultType } from 'src/services/wallets/enums';
import {
EntityKind,
NetworkType,
PaymentInfoKind,
VaultType,
VisibilityType,
} from 'src/services/wallets/enums';
import ScreenWrapper from 'src/components/ScreenWrapper';
import { Wallet } from 'src/services/wallets/interfaces/wallet';
import WalletUtilities from 'src/services/wallets/operations/utils';
Expand Down Expand Up @@ -51,12 +57,17 @@ import PendingHealthCheckModal from 'src/components/PendingHealthCheckModal';
import KeeperTextInput from 'src/components/KeeperTextInput';
import ScannerIcon from 'src/assets/images/scanner-icon.svg';
import ScannerIconDark from 'src/assets/images/scanner-icon-white.svg';
import useWallets from 'src/hooks/useWallets';
import useVault from 'src/hooks/useVault';
function SendScreen({ route }) {
const { colorMode } = useColorMode();
const navigation = useNavigation();
const { showToast } = useToastMessage();
const dispatch = useDispatch();

const { wallets } = useWallets({ getAll: true });
const { allVaults: vaults } = useVault({});
const allWallets = useMemo(() => [...wallets, ...vaults], [wallets, vaults]);
const [isSendToWalletDisabled, setIsSendToWalletDisabled] = useState(false);
const { sender, selectedUTXOs, parentScreen } = route.params as {
sender: Wallet | Vault;
selectedUTXOs?: UTXO[];
Expand Down Expand Up @@ -87,6 +98,15 @@ function SendScreen({ route }) {
: sender.specs.balances.confirmed + sender.specs.balances.unconfirmed;
const avgFees = useAppSelector((state) => state.network.averageTxFees);

const visibleWallets = useMemo(
() =>
allWallets.filter(
(wallet) =>
wallet.presentationData.visibility !== VisibilityType.HIDDEN && wallet.id !== sender.id
),
[allWallets, sender.id]
);

useEffect(() => {
InteractionManager.runAfterInteractions(() => {
dispatch(sendPhasesReset());
Expand Down Expand Up @@ -118,6 +138,10 @@ function SendScreen({ route }) {
};
}, []);

useEffect(() => {
setIsSendToWalletDisabled(visibleWallets.length <= 0);
}, [visibleWallets]);

const handleSelectWallet = (wallet) => {
setSelectedWallet(wallet);
};
Expand Down Expand Up @@ -162,6 +186,10 @@ function SendScreen({ route }) {
}
};
const handleSelectWalletPress = () => {
if (isSendToWalletDisabled) {
return;
}

if (!selectedWallet) {
navigation.dispatch(
CommonActions.navigate({
Expand Down Expand Up @@ -369,16 +397,19 @@ function SendScreen({ route }) {
paddingLeft={5}
/>
<Box style={styles.sendToWalletContainer}>
<Pressable onPress={handleSelectWalletPress}>
<Pressable onPress={handleSelectWalletPress} disabled={isSendToWalletDisabled}>
<Box
flexDirection={'row'}
justifyContent={'space-between'}
alignItems={'center'}
style={styles.sendToWalletWrapper}
style={[
styles.sendToWalletWrapper,
isSendToWalletDisabled && styles.disabledButton,
]}
>
<Text color={`${colorMode}.primaryText`}>Send to one of your wallets</Text>
{!selectedWallet ? (
<ArrowIcon />
<ArrowIcon opacity={isSendToWalletDisabled ? 0.5 : 1} />
) : isDarkMode ? (
<RemoveIconDark />
) : (
Expand Down Expand Up @@ -499,5 +530,8 @@ const styles = StyleSheet.create({
sendToWalletContainer: {
gap: 10,
},
disabledButton: {
opacity: 0.5,
},
});
export default Sentry.withErrorBoundary(SendScreen, errorBourndaryOptions);
Loading