251 lines
6.8 KiB
JavaScript
251 lines
6.8 KiB
JavaScript
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
import { CENTER, COLORS, FONT, SIZES } from '../../../../constants';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useCallback } from 'react';
|
|
import { crashlyticsLogReport } from '../../../../functions/crashlyticsLogs';
|
|
import ThemeIcon from '../../../../functions/CustomElements/themeIcon';
|
|
import { ThemeText } from '../../../../functions/CustomElements';
|
|
import GetThemeColors from '../../../../hooks/themeColors';
|
|
import useAdaptiveFontSize from '../../../../hooks/useAdaptiveFontSIze';
|
|
import useGuardedNavigation from '../../../../hooks/useGuardedNavigation';
|
|
|
|
export function SendRecieveBTNs({
|
|
theme,
|
|
darkModeType,
|
|
isConnectedToTheInternet,
|
|
isNWCWallet = false,
|
|
scrollPosition,
|
|
}) {
|
|
const navigateGuarded = useGuardedNavigation();
|
|
const { t } = useTranslation();
|
|
const { backgroundOffset, textColor } = GetThemeColors();
|
|
|
|
const handleSettingsCheck = useCallback(() => {
|
|
try {
|
|
if (!isConnectedToTheInternet)
|
|
throw new Error(t('errormessages.nointernet'));
|
|
return true;
|
|
} catch (err) {
|
|
return false;
|
|
}
|
|
}, [isConnectedToTheInternet]);
|
|
|
|
const arrowIconColor = COLORS.darkModeText;
|
|
const handleSend = useCallback(() => {
|
|
crashlyticsLogReport(
|
|
'Running in send and receive buttons on homepage for button type: send',
|
|
);
|
|
const areSettingsSet = handleSettingsCheck();
|
|
if (!areSettingsSet) {
|
|
navigateGuarded('ErrorScreen', {
|
|
errorMessage: t('errormessages.nointernet'),
|
|
});
|
|
return;
|
|
}
|
|
navigateGuarded('CustomHalfModal', {
|
|
wantedContent: 'sendOptions',
|
|
sliderHight: 0.8,
|
|
});
|
|
}, [handleSettingsCheck, navigateGuarded, t]);
|
|
|
|
const handleReceive = useCallback(() => {
|
|
crashlyticsLogReport(
|
|
'Running in send and receive buttons on homepage for button type: receive',
|
|
);
|
|
const areSettingsSet = handleSettingsCheck();
|
|
if (!areSettingsSet) {
|
|
navigateGuarded('ErrorScreen', {
|
|
errorMessage: t('errormessages.nointernet'),
|
|
});
|
|
return;
|
|
}
|
|
navigateGuarded('CustomHalfModal', {
|
|
scrollPosition: scrollPosition === 'usd' ? 'USD' : 'BTC',
|
|
wantedContent: 'receiveOptions',
|
|
sliderHight: 0.8,
|
|
});
|
|
}, [handleSettingsCheck, navigateGuarded, scrollPosition, t]);
|
|
|
|
const handleDeposit = useCallback(() => {
|
|
const areSettingsSet = handleSettingsCheck();
|
|
if (!areSettingsSet) {
|
|
navigateGuarded('ErrorScreen', {
|
|
errorMessage: t('errormessages.nointernet'),
|
|
});
|
|
return;
|
|
}
|
|
crashlyticsLogReport(
|
|
'Running in send and receive buttons on homepage for button type: deposit',
|
|
);
|
|
navigateGuarded('CustomHalfModal', {
|
|
wantedContent: 'depositFunds',
|
|
sliderHight: 0.55,
|
|
});
|
|
}, [handleSettingsCheck, navigateGuarded, t]);
|
|
|
|
const handleSwap = useCallback(() => {
|
|
const areSettingsSet = handleSettingsCheck();
|
|
if (!areSettingsSet) {
|
|
navigateGuarded('ErrorScreen', {
|
|
errorMessage: t('errormessages.nointernet'),
|
|
});
|
|
return;
|
|
}
|
|
navigateGuarded('CustomHalfModal', {
|
|
wantedContent: 'swapFlow',
|
|
sliderHight: 0.55,
|
|
});
|
|
}, [handleSettingsCheck, navigateGuarded, t]);
|
|
|
|
const { fontSize, getLabelProps } = useAdaptiveFontSize(
|
|
[
|
|
t('wallet.homeLightning.home.send'),
|
|
t('wallet.homeLightning.home.receive'),
|
|
t('wallet.homeLightning.home.scan'),
|
|
t('wallet.homeLightning.home.swap'),
|
|
],
|
|
SIZES.medium,
|
|
5,
|
|
);
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
{/* Send — primary */}
|
|
<TouchableOpacity
|
|
style={styles.buttonWrapper}
|
|
onPress={handleSend}
|
|
// activeOpacity={1}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.btn,
|
|
{
|
|
backgroundColor:
|
|
theme && darkModeType ? backgroundOffset : COLORS.primary,
|
|
},
|
|
]}
|
|
>
|
|
<ThemeIcon
|
|
size={25}
|
|
iconName="ArrowUp"
|
|
colorOverride={arrowIconColor}
|
|
/>
|
|
</View>
|
|
{/* <ThemeText
|
|
content={t('wallet.homeLightning.home.send')}
|
|
styles={[styles.labelSecondary, { fontSize }]}
|
|
{...getLabelProps(0)}
|
|
/> */}
|
|
</TouchableOpacity>
|
|
|
|
{/* Receive — primary */}
|
|
<TouchableOpacity
|
|
style={styles.buttonWrapper}
|
|
onPress={handleReceive}
|
|
// activeOpacity={1}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.btn,
|
|
{
|
|
backgroundColor:
|
|
theme && darkModeType ? backgroundOffset : COLORS.primary,
|
|
},
|
|
]}
|
|
>
|
|
<ThemeIcon
|
|
size={25}
|
|
iconName="ArrowDown"
|
|
colorOverride={arrowIconColor}
|
|
/>
|
|
</View>
|
|
{/* <ThemeText
|
|
content={t('wallet.homeLightning.home.receive')}
|
|
styles={[styles.labelSecondary, { fontSize }]}
|
|
{...getLabelProps(1)}
|
|
/> */}
|
|
</TouchableOpacity>
|
|
|
|
{/* Deposit — secondary */}
|
|
{!isNWCWallet && (
|
|
<TouchableOpacity style={styles.buttonWrapper} onPress={handleDeposit}>
|
|
<View
|
|
style={[
|
|
styles.btn,
|
|
{
|
|
backgroundColor:
|
|
theme && darkModeType ? backgroundOffset : COLORS.primary,
|
|
},
|
|
]}
|
|
>
|
|
<ThemeIcon
|
|
size={25}
|
|
iconName="Plus"
|
|
colorOverride={arrowIconColor}
|
|
/>
|
|
</View>
|
|
</TouchableOpacity>
|
|
)}
|
|
|
|
{/* Swap — secondary */}
|
|
<TouchableOpacity
|
|
style={styles.buttonWrapper}
|
|
// activeOpacity={1}
|
|
onPress={handleSwap}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.btn,
|
|
{
|
|
backgroundColor:
|
|
theme && darkModeType ? backgroundOffset : COLORS.primary,
|
|
},
|
|
]}
|
|
>
|
|
<ThemeIcon
|
|
size={25}
|
|
iconName="ArrowRightLeft"
|
|
colorOverride={arrowIconColor}
|
|
/>
|
|
</View>
|
|
{/* <ThemeText
|
|
content={t('wallet.homeLightning.home.swap')}
|
|
styles={[styles.labelSecondary, { fontSize }]}
|
|
{...getLabelProps(3)}
|
|
/> */}
|
|
</TouchableOpacity>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
maxWidth: 350,
|
|
width: '85%',
|
|
flexDirection: 'row',
|
|
justifyContent: 'center',
|
|
alignItems: 'flex-start',
|
|
gap: 8,
|
|
...CENTER,
|
|
},
|
|
buttonWrapper: {
|
|
alignItems: 'center',
|
|
// flex: 1,
|
|
},
|
|
btn: {
|
|
width: 70,
|
|
height: 70,
|
|
borderRadius: 35,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
|
|
labelSecondary: {
|
|
width: '100%',
|
|
fontSize: SIZES.small,
|
|
includeFontPadding: false,
|
|
marginTop: 5,
|
|
textAlign: 'center',
|
|
},
|
|
});
|