FIX: broadcast wasn't dark mode friendly

This commit is contained in:
marcosrdz 2020-12-12 20:51:39 -05:00
parent 391c26764b
commit e792f3bf5f
2 changed files with 54 additions and 36 deletions

View File

@ -277,6 +277,7 @@
"network_electrum": "Electrum Server", "network_electrum": "Electrum Server",
"not_a_valid_uri": "Not a valid URI", "not_a_valid_uri": "Not a valid URI",
"notifications": "Notifications", "notifications": "Notifications",
"open_link_in_explorer" : "Open link in explorer",
"password": "Password", "password": "Password",
"password_explain": "Create the password you will use to decrypt the storage", "password_explain": "Create the password you will use to decrypt the storage",
"passwords_do_not_match": "Passwords do not match", "passwords_do_not_match": "Passwords do not match",
@ -291,7 +292,8 @@
"push_notifications": "Push Notifications", "push_notifications": "Push Notifications",
"retype_password": "Re-type password", "retype_password": "Re-type password",
"save": "Save", "save": "Save",
"saved": "Saved" "saved": "Saved",
"success_transaction_broadcasted" : "Success! You transaction has been broadcasted!"
}, },
"notifications": { "notifications": {
"would_you_like_to_receive_notifications": "Would you like to receive notifications when you get incoming payments?", "would_you_like_to_receive_notifications": "Would you like to receive notifications when you get incoming payments?",

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ActivityIndicator, Linking, StyleSheet, View, KeyboardAvoidingView, Platform, Text, TextInput } from 'react-native'; import { ActivityIndicator, Linking, StyleSheet, View, KeyboardAvoidingView, Platform, TextInput } from 'react-native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import loc from '../../loc'; import loc from '../../loc';
import { HDSegwitBech32Wallet } from '../../class'; import { HDSegwitBech32Wallet } from '../../class';
@ -14,10 +14,11 @@ import {
BlueTextCentered, BlueTextCentered,
BlueBigCheckmark, BlueBigCheckmark,
BlueNavigationStyle, BlueNavigationStyle,
BlueButtonLink,
} from '../../BlueComponents'; } from '../../BlueComponents';
import { BlueCurrentTheme } from '../../components/themes';
import BlueElectrum from '../../blue_modules/BlueElectrum'; import BlueElectrum from '../../blue_modules/BlueElectrum';
import Notifications from '../../blue_modules/notifications'; import Notifications from '../../blue_modules/notifications';
import { useTheme } from '@react-navigation/native';
const bitcoin = require('bitcoinjs-lib'); const bitcoin = require('bitcoinjs-lib');
const BROADCAST_RESULT = Object.freeze({ const BROADCAST_RESULT = Object.freeze({
@ -28,9 +29,23 @@ const BROADCAST_RESULT = Object.freeze({
}); });
const Broadcast = () => { const Broadcast = () => {
const [tx, setTx] = useState(''); const [tx, setTx] = useState();
const [txHex, setTxHex] = useState(''); const [txHex, setTxHex] = useState();
const { colors } = useTheme();
const [broadcastResult, setBroadcastResult] = useState(BROADCAST_RESULT.none); const [broadcastResult, setBroadcastResult] = useState(BROADCAST_RESULT.none);
const stylesHooks = StyleSheet.create({
blueArea: {
backgroundColor: colors.background,
},
text: {
color: colors.foregroundColor,
},
input: {
borderColor: colors.formBorder,
borderBottomColor: colors.formBorder,
backgroundColor: colors.inputBackgroundColor,
},
});
const handleUpdateTxHex = nextValue => setTxHex(nextValue.trim()); const handleUpdateTxHex = nextValue => setTxHex(nextValue.trim());
const handleBroadcast = async () => { const handleBroadcast = async () => {
setBroadcastResult(BROADCAST_RESULT.pending); setBroadcastResult(BROADCAST_RESULT.pending);
@ -43,7 +58,9 @@ const Broadcast = () => {
const tx = bitcoin.Transaction.fromHex(txHex); const tx = bitcoin.Transaction.fromHex(txHex);
const txid = tx.getId(); const txid = tx.getId();
setTx(txid); setTx(txid);
setBroadcastResult(BROADCAST_RESULT.success); setBroadcastResult(BROADCAST_RESULT.success);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
Notifications.majorTomToGroundControl([], [], [txid]); Notifications.majorTomToGroundControl([], [], [txid]);
} else { } else {
setBroadcastResult(BROADCAST_RESULT.error); setBroadcastResult(BROADCAST_RESULT.error);
@ -82,17 +99,21 @@ const Broadcast = () => {
<BlueFormLabel>{status}</BlueFormLabel> <BlueFormLabel>{status}</BlueFormLabel>
{BROADCAST_RESULT.pending === broadcastResult && <ActivityIndicator size="small" />} {BROADCAST_RESULT.pending === broadcastResult && <ActivityIndicator size="small" />}
</View> </View>
<TextInput
style={styles.text} <View style={[styles.input, stylesHooks.input]}>
maxHeight={100} <TextInput
minHeight={100} style={styles.text}
maxWidth="100%" maxHeight={100}
minWidth="100%" minHeight={100}
multiline maxWidth="100%"
editable minWidth="100%"
value={txHex} multiline
onChangeText={handleUpdateTxHex} editable
/> placeholderTextColor="#81868e"
value={txHex}
onChangeText={handleUpdateTxHex}
/>
</View>
<BlueSpacing10 /> <BlueSpacing10 />
<BlueButton <BlueButton
@ -133,9 +154,6 @@ const styles = StyleSheet.create({
height: '100%', height: '100%',
width: '100%', width: '100%',
}, },
link: {
color: BlueCurrentTheme.colors.foregroundColor,
},
mainCard: { mainCard: {
padding: 0, padding: 0,
display: 'flex', display: 'flex',
@ -155,41 +173,39 @@ const styles = StyleSheet.create({
height: 30, height: 30,
maxHeight: 30, maxHeight: 30,
}, },
text: { input: {
flex: 1, flexDirection: 'row',
borderColor: '#ebebeb', borderWidth: 1,
backgroundColor: '#d2f8d6', borderBottomWidth: 0.5,
alignItems: 'center',
borderRadius: 4, borderRadius: 4,
marginTop: 20, },
color: BlueCurrentTheme.colors.foregroundColor, text: {
fontWeight: '500', padding: 8,
fontSize: 14, minHeight: 33,
paddingHorizontal: 16, color: '#81868e',
paddingBottom: 16,
paddingTop: 16,
}, },
}); });
function SuccessScreen({ tx }) { const SuccessScreen = ({ tx }) => {
if (!tx) { if (!tx) {
return null; return null;
} }
return ( return (
<View style={styles.wrapper}> <View style={styles.wrapper}>
<BlueCard> <BlueCard>
<View style={styles.broadcastResultWrapper}> <View style={styles.broadcastResultWrapper}>
<BlueBigCheckmark /> <BlueBigCheckmark />
<BlueSpacing20 /> <BlueSpacing20 />
<BlueTextCentered>Success! You transaction has been broadcasted!</BlueTextCentered> <BlueTextCentered>{loc.settings.success_transaction_broadcasted}</BlueTextCentered>
<BlueSpacing10 /> <BlueSpacing10 />
<Text style={styles.link} onPress={() => Linking.openURL(`https://blockstream.info/tx/${tx}`)}> <BlueButtonLink title={loc.settings.open_link_in_explorer} onPress={() => Linking.openURL(`https://blockstream.info/tx/${tx}`)} />
Open link in explorer
</Text>
</View> </View>
</BlueCard> </BlueCard>
</View> </View>
); );
} };
SuccessScreen.propTypes = { SuccessScreen.propTypes = {
tx: PropTypes.string.isRequired, tx: PropTypes.string.isRequired,