BlueWallet/screen/send/success.js

179 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-09-21 19:47:10 +02:00
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import LottieView from 'lottie-react-native';
import { View, StyleSheet, SafeAreaView } from 'react-native';
2020-06-02 16:15:08 +02:00
import { Text } from 'react-native-elements';
import BigNumber from 'bignumber.js';
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
import { BlueButton, BlueCard } from '../../BlueComponents';
import { BitcoinUnit } from '../../models/bitcoinUnits';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
2020-09-21 19:47:10 +02:00
const Success = () => {
2020-11-22 08:41:59 +01:00
const pop = () => {
dangerouslyGetParent().pop();
};
2020-09-21 19:47:10 +02:00
const { colors } = useTheme();
const { dangerouslyGetParent } = useNavigation();
const { amount, fee, amountUnit = BitcoinUnit.BTC, invoiceDescription = '', onDonePressed = pop } = useRoute().params;
2020-09-21 19:47:10 +02:00
const stylesHook = StyleSheet.create({
root: {
backgroundColor: colors.elevated,
},
amountValue: {
color: colors.alternativeTextColor2,
},
amountUnit: {
color: colors.alternativeTextColor2,
},
});
useEffect(() => {
console.log('send/success - useEffect');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
2020-11-25 04:01:51 +01:00
return (
<SafeAreaView style={[styles.root, stylesHook.root]}>
<SuccessView
amount={amount}
amountUnit={amountUnit}
fee={fee}
invoiceDescription={invoiceDescription}
onDonePressed={onDonePressed}
/>
<View style={styles.buttonContainer}>
<BlueButton onPress={onDonePressed} title={loc.send.success_done} />
</View>
</SafeAreaView>
);
};
export default Success;
export const SuccessView = ({ amount, amountUnit, fee, invoiceDescription, shouldAnimate = true }) => {
const animationRef = useRef();
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
amountValue: {
color: colors.alternativeTextColor2,
},
amountUnit: {
color: colors.alternativeTextColor2,
},
});
2020-09-21 19:47:10 +02:00
useEffect(() => {
2020-11-25 04:01:51 +01:00
if (shouldAnimate) {
animationRef.current.reset();
animationRef.current.resume();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
2020-09-21 19:47:10 +02:00
}, [colors]);
return (
2020-11-25 04:01:51 +01:00
<View style={styles.root}>
<BlueCard style={styles.amount}>
<View style={styles.view}>
2021-09-09 13:00:11 +02:00
{amount ? (
<>
<Text style={[styles.amountValue, stylesHook.amountValue]}>{amount}</Text>
2020-12-21 19:27:49 +01:00
<Text style={[styles.amountUnit, stylesHook.amountUnit]}>{' ' + loc.units[amountUnit]}</Text>
</>
2021-09-09 13:00:11 +02:00
) : null}
</View>
2020-09-21 19:47:10 +02:00
{fee > 0 && (
<Text style={styles.feeText}>
{loc.send.create_fee}: {new BigNumber(fee).toFixed()} {loc.units[BitcoinUnit.BTC]}
2020-09-21 19:47:10 +02:00
</Text>
)}
2020-11-25 04:01:51 +01:00
<Text numberOfLines={0} style={styles.feeText}>
{invoiceDescription}
</Text>
2020-09-21 19:47:10 +02:00
</BlueCard>
<View style={styles.ready}>
<LottieView
style={styles.lottie}
source={require('../../img/bluenice.json')}
2020-11-25 04:01:51 +01:00
autoPlay={shouldAnimate}
2020-09-21 19:47:10 +02:00
ref={animationRef}
loop={false}
2020-11-25 04:01:51 +01:00
progress={shouldAnimate ? 0 : 1}
2020-09-21 19:47:10 +02:00
colorFilters={[
{
keypath: 'spark',
color: colors.success,
},
{
keypath: 'circle',
color: colors.success,
},
{
keypath: 'Oval',
color: colors.successCheck,
},
]}
/>
</View>
2020-11-25 04:01:51 +01:00
</View>
2020-09-21 19:47:10 +02:00
);
};
2020-11-25 04:01:51 +01:00
SuccessView.propTypes = {
amount: PropTypes.number,
amountUnit: PropTypes.string,
fee: PropTypes.number,
invoiceDescription: PropTypes.string,
shouldAnimate: PropTypes.bool,
};
const styles = StyleSheet.create({
root: {
flex: 1,
paddingTop: 19,
},
buttonContainer: {
2021-09-13 18:31:41 +02:00
paddingHorizontal: 58,
paddingBottom: 16,
},
amount: {
alignItems: 'center',
},
view: {
flexDirection: 'row',
justifyContent: 'center',
},
amountValue: {
fontSize: 36,
fontWeight: '600',
},
amountUnit: {
fontSize: 16,
marginHorizontal: 4,
paddingBottom: 6,
fontWeight: '600',
alignSelf: 'flex-end',
},
feeText: {
color: '#37c0a1',
fontSize: 14,
marginHorizontal: 4,
2021-09-13 18:31:41 +02:00
paddingVertical: 6,
fontWeight: '500',
alignSelf: 'center',
},
ready: {
width: 120,
height: 120,
borderRadius: 60,
alignSelf: 'center',
alignItems: 'center',
marginBottom: 53,
},
lottie: {
width: 400,
height: 400,
},
});