Skip to content

Commit

Permalink
fix address parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay.natorin committed Dec 2, 2020
1 parent a3ae00c commit acf8480
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/lib/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import crypto from 'react-native-crypto';
import { getChash160, isValidAddress } from 'obyte/lib/utils';
import { getSignedMessageInfoFromJsonBase64 } from './oCustom';

export const REG_WALLET_ADDRESS = /^([A-Z0-9]{32})$/g;
export const REG_WALLET_ADDRESS = /(.*?\s|^)([2-7A-Z]{32})([\s.,;!:].*?|$)/g;
export const REG_REQUEST_PAYMENT = /\[.*?\]\(((?:byteball-tn|byteball|obyte-tn|obyte):([0-9A-Z]{32})(?:\?([\w=&;+%]+))?)\)/g;
export const REGEX_SIGN_MESSAGE_REQUEST = /\[(.+?)\]\(sign-message-request(-network-aware)?:(.+?)\)/g;
export const REGEX_SIGNED_MESSAGE = /\[(.+?)\]\(signed-message:([\w\/+=]+?)\)/g;
Expand Down Expand Up @@ -61,21 +61,18 @@ export const parseTextMessage = originalText => {
type = 'PROSAIC_CONTRACT';
return toDelayedReplacement({ type, text: '[UNSUPPORTED ACTION]' });
})
.replace(REG_WALLET_ADDRESS, (str, address) => {
.replace(REG_WALLET_ADDRESS, (str, description, address) => {
type = 'WALLET_ADDRESS';
params = { address };
return toDelayedReplacement({ type, address });
return toDelayedReplacement({ type, description, address });
})
.replace(REG_REQUEST_PAYMENT, (str, payload, address, amount) => {
type = 'REQUEST_PAYMENT';
params = { amount, address };
return toDelayedReplacement({ type, address, amount });
})
.replace(
REGEX_SIGN_MESSAGE_REQUEST,
(str, description, networkAware, messageToSign) => {
type = 'SIGN_MESSAGE_REQUEST';
params = { messageToSign };
return toDelayedReplacement({ type, messageToSign });
},
)
Expand Down
7 changes: 4 additions & 3 deletions src/screens/ChatScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ const ChatScreen = ({
)
}
case "WALLET_ADDRESS": {
const { address } = data;
const { address, description } = data;
return user._id !== 1
? (
<TouchableOpacity onPress={() => navigation.navigate('MakePayment', { walletAddress: data.address })}>
{description ? <Text style={style}>{description}</Text> : null}
<Text style={replacedStyle}>{address}</Text>
</TouchableOpacity>
)
: <Text style={style}>{address}</Text>
: <Text style={style}>{description ? `${description}${address}` : address}</Text>
}
case "REQUEST_PAYMENT": {
const { amount, address } = data;
Expand Down Expand Up @@ -135,7 +136,7 @@ const ChatScreen = ({
: <Text style={style}>{`Request to sign message: \"${messageToSign}\"`}</Text>
}
case "SIGNED_MESSAGE": {
return <Text style={style}>{`Signed message: ${data.text}`}</Text>
return <Text style={{ ...style, ...styles.actionMessage }}>{`Signed message: ${data.text}`}</Text>
}
case "URL": {
const { url } = data;
Expand Down

0 comments on commit acf8480

Please sign in to comment.