diff --git a/src/components/Button/index.js b/src/components/Button/index.js index c6f15cd6..a44449c2 100644 --- a/src/components/Button/index.js +++ b/src/components/Button/index.js @@ -1,13 +1,31 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import { TouchableOpacity, Text } from 'react-native'; import styles from './styles'; -let Button = ({ text, style, disabled, textStyle, ...restProps }) => { +const Button = ({ text, style, disabled, textStyle, ...restProps }) => { + const buttonStyles = useMemo( + () => { + let stylesObject = { + ...styles.button, + ...style + }; + if (disabled) { + stylesObject = { + ...stylesObject, + ...styles.disabled + } + } + return stylesObject; + }, + [disabled, style] + ); + return ( {text} @@ -18,12 +36,14 @@ let Button = ({ text, style, disabled, textStyle, ...restProps }) => { Button.defaultProps = { style: {}, textStyle: {}, + disabled: false }; Button.propTypes = { text: PropTypes.string.isRequired, style: PropTypes.object, textStyle: PropTypes.object, + disabled: PropTypes.bool }; export default Button; diff --git a/src/components/Button/styles.js b/src/components/Button/styles.js index 172effe4..a01fb740 100644 --- a/src/components/Button/styles.js +++ b/src/components/Button/styles.js @@ -15,4 +15,7 @@ export default StyleSheet.create({ color: colors.white, fontSize: 20, }, + disabled: { + backgroundColor: colors.grey.light + } }); diff --git a/src/navigation/Root.js b/src/navigation/Root.js index f8a17fd9..5f16e728 100644 --- a/src/navigation/Root.js +++ b/src/navigation/Root.js @@ -9,6 +9,7 @@ import PaymentScreen, { Methods } from './../screens/PaymentScreen'; import SeedWordsScreen from './../screens/SeedWordsScreen'; import TransactionInfoScreen from './../screens/TransactionInfoScreen'; import ChatScreen from '../screens/ChatScreen'; +import PairInputScreen from '../screens/PairInput'; const RootNav = createStackNavigator( { @@ -28,6 +29,10 @@ const RootNav = createStackNavigator( screen: (props, compProps) => , path: 'qrCode' }, + PairInput: { + screen: (props, compProps) => , + path: 'pairInput' + }, MakePayment: { screen: props => ( - {/** - - + + this.props.navigation.navigate('PairInput') + } + > + - */} diff --git a/src/screens/ChatScreen/ActionsBar.js b/src/screens/ChatScreen/ActionsBar.js index b78ff38b..3a6467dd 100644 --- a/src/screens/ChatScreen/ActionsBar.js +++ b/src/screens/ChatScreen/ActionsBar.js @@ -17,7 +17,8 @@ const ActionsBar = ({ myWalletAddress, correspondentWalletAddress, correspondentAddress, - insertAddress + insertAddress, + onRequestSignMessage }) => { const actionSheet = useRef(); @@ -60,6 +61,11 @@ const ActionsBar = ({ ); }, [correspondentAddress]); + const handleRequestToSignMessage = useCallback( + () => {}, + [] + ); + const handleActionPress = useCallback( index => { switch (index) { @@ -72,6 +78,9 @@ const ActionsBar = ({ case 2: handleDeleteContact(); break; + case 3: + onRequestSignMessage(); + break; default: } }, @@ -149,10 +158,11 @@ const ActionsBar = ({ 'Insert my address', 'Clear chat history', 'Delete contact', + 'Request to Sign a Message', 'Cancel', ]} - cancelButtonIndex={3} - destructiveButtonIndex={3} + cancelButtonIndex={4} + destructiveButtonIndex={4} onPress={handleActionPress} /> diff --git a/src/screens/ChatScreen/index.js b/src/screens/ChatScreen/index.js index 175a9252..d53f8e9d 100644 --- a/src/screens/ChatScreen/index.js +++ b/src/screens/ChatScreen/index.js @@ -1,4 +1,4 @@ -import React, { useState, useMemo, Fragment, useEffect } from 'react'; +import React, { useState, useMemo, Fragment } from 'react'; import { connect, useDispatch } from 'react-redux'; import { createStructuredSelector } from 'reselect'; import { TouchableOpacity, Text, Clipboard, Alert, View, Linking } from 'react-native'; @@ -23,16 +23,6 @@ import { testnet } from "../../lib/oCustom"; import WarningIcon from '../../assets/images/warning.svg'; -const messageTypes = [ - "WALLET_ADDRESS", - "REQUEST_PAYMENT", - "SIGN_MESSAGE_REQUEST", - "SIGNED_MESSAGE", - "URL", - "COMMAND", - "SUGGEST_COMMAND" -]; - const ChatScreen = ({ myWalletAddress, correspondentWalletAddress, messages, navigation, backRoute, addressWif }) => { @@ -58,6 +48,15 @@ const ChatScreen = ({ isConnected })); }); + setText(""); + } + }; + + const onRequestSignMessage = () => { + if (!text) { + Alert.alert('', 'Text field is empty'); + } else { + onSend([{ text: `[Data request](sign-message-request:${text})` }]); } }; @@ -284,6 +283,7 @@ const ChatScreen = ({ clearChatHistory={onClearChatHistory} removeCorrespondent={onRemoveCorespondent} onSend={onSend} + onRequestSignMessage={onRequestSignMessage} insertAddress={insertAddress} correspondentWalletAddress={correspondentWalletAddress} correspondentAddress={correspondent.address} diff --git a/src/screens/PairInput/index.js b/src/screens/PairInput/index.js new file mode 100644 index 00000000..682d9e90 --- /dev/null +++ b/src/screens/PairInput/index.js @@ -0,0 +1,91 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +import { useDispatch } from "react-redux"; + +import { acceptInvitation } from './../../actions/correspondents'; + +import { View, Platform, KeyboardAvoidingView, TextInput, Clipboard, TouchableOpacity, Alert } from 'react-native'; +import SafeAreaView from 'react-native-safe-area-view'; + +import Header from '../../components/Header'; +import Button from './../../components/Button'; +import CopyIcon from './../../assets/images/icon-copy.svg'; + +import { REGEX_PAIRING } from "../../lib/messaging"; + +import styles from './styles'; + +const PairInputScreen = ({ navigation, backRoute }) => { + const dispatch = useDispatch(); + const [address, setAddress] = useState(""); + + const onChangeAddress = (value) => { + setAddress(value); + }; + + const handleAddContact = () => { + if (REGEX_PAIRING.test(address)) { + dispatch(acceptInvitation({ data: address })); + } else { + Alert.alert("Warning", "Wrong pairing code"); + } + }; + + const pasteAddress = async () => { + let copiedAddress = await Clipboard.getString(); + setAddress(copiedAddress); + }; + + return ( + + +
+ + + {!address && ( + + + + + + )} + +