From da8ba5e4e5a211cdc06f14240a7bfabb40f3868a Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Mon, 30 May 2022 21:42:31 +0500 Subject: [PATCH 1/4] validate valid ecency url on keyboard blur --- ios/Podfile.lock | 2 +- src/components/postBoost/postBoostView.js | 22 +++++++++++++++++++++- src/screens/redeem/screen/redeemScreen.js | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b87295c4f..3ee32c649 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -833,4 +833,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311 -COCOAPODS: 1.11.3 +COCOAPODS: 1.11.2 diff --git a/src/components/postBoost/postBoostView.js b/src/components/postBoost/postBoostView.js index e0196be59..dd88df7d4 100644 --- a/src/components/postBoost/postBoostView.js +++ b/src/components/postBoost/postBoostView.js @@ -21,6 +21,7 @@ import { Modal } from '../modal'; // Styles import styles from './postBoostStyles'; import { OptionsModal } from '../atoms'; +import { deepLinkParser } from '../../utils/deepLinkParser'; class BoostPostScreen extends PureComponent { /* Props @@ -112,6 +113,22 @@ class BoostPostScreen extends PureComponent { handleOnSubmit(redeemType, amount, fullPermlink, selectedUser); }; + _validateUrl = async () => { + const { permlink } = this.state; + const { user } = this.props; + const deepLinkData = await deepLinkParser(permlink, user); + console.log('deepLinkData : ', deepLinkData); + const { routeName, params, key } = deepLinkData || {}; + if (routeName && key && params && params.content) { + let postPermlink = `${params.content.author}/${params.content.permlink}`; + this.setState({ + permlink: postPermlink, + isValid: true, + }); + } else { + this.setState({ isValid: false }); + } + }; render() { const { intl } = this.props; const { selectedUser, balance, factor, permlinkSuggestions, permlink, isValid } = this.state; @@ -126,10 +143,11 @@ class BoostPostScreen extends PureComponent { isSCModalOpen, handleOnSCModalClose, getESTMPrice, + user, } = this.props; const calculatedESTM = 150 + 50 * factor; - + // console.log('this.state.permlink : ', this.state.permlink); return ( @@ -166,6 +184,8 @@ class BoostPostScreen extends PureComponent { placeholder={intl.formatMessage({ id: 'promote.permlinkPlaceholder' })} placeholderTextColor="#c1c5c7" autoCapitalize="none" + returnKeyType="done" + onBlur={() => this._validateUrl()} /> )} renderItem={({ item }) => ( diff --git a/src/screens/redeem/screen/redeemScreen.js b/src/screens/redeem/screen/redeemScreen.js index 803215fa5..e5f9c9e36 100644 --- a/src/screens/redeem/screen/redeemScreen.js +++ b/src/screens/redeem/screen/redeemScreen.js @@ -24,6 +24,7 @@ class RedeemScreen extends PureComponent { navigationParams, redeemType, getESTMPrice, + user, }) => ( {({ handleOnSubmit, SCPath, isSCModalOpen, handleOnSCModalClose, isLoading }) => ( @@ -57,6 +58,7 @@ class RedeemScreen extends PureComponent { handleOnSCModalClose={handleOnSCModalClose} SCPath={SCPath} getESTMPrice={getESTMPrice} + user={user} /> )} From 68279ba5d2352b566f883dc0dbdcb2faf95a5b4e Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Mon, 30 May 2022 21:46:22 +0500 Subject: [PATCH 2/4] added validation check in deeplink parser which was causing error if url other than ececny is entered --- src/utils/deepLinkParser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/deepLinkParser.ts b/src/utils/deepLinkParser.ts index 7eda69d98..c8051432b 100644 --- a/src/utils/deepLinkParser.ts +++ b/src/utils/deepLinkParser.ts @@ -56,7 +56,7 @@ export const deepLinkParser = async (url, currentAccount) => { } } - if (feedType === 'hot' || feedType === 'trending' || feedType === 'created') { + if (feedType && ( feedType === 'hot' || feedType === 'trending' || feedType === 'created' )) { if (!tag) { routeName = ROUTES.SCREENS.TAG_RESULT; } else if (/hive-[1-3]\d{4,6}$/.test(tag)) { @@ -73,7 +73,7 @@ export const deepLinkParser = async (url, currentAccount) => { if (!routeName) { const { mode, referredUser } = parseAuthUrl(url) || {}; - if (mode === 'SIGNUP') { + if (mode && referredUser && mode === 'SIGNUP') { routeName = ROUTES.SCREENS.REGISTER; params = { referredUser, From 09bd4b90c7513eb51deb30b9f45404dc464131ed Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Mon, 30 May 2022 22:09:10 +0500 Subject: [PATCH 3/4] used postUrlParser instead of deepLinkParser --- src/components/postBoost/postBoostView.js | 13 ++++++------- src/utils/deepLinkParser.ts | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/postBoost/postBoostView.js b/src/components/postBoost/postBoostView.js index dd88df7d4..322e096ce 100644 --- a/src/components/postBoost/postBoostView.js +++ b/src/components/postBoost/postBoostView.js @@ -22,6 +22,7 @@ import { Modal } from '../modal'; import styles from './postBoostStyles'; import { OptionsModal } from '../atoms'; import { deepLinkParser } from '../../utils/deepLinkParser'; +import postUrlParser from '../../utils/postUrlParser'; class BoostPostScreen extends PureComponent { /* Props @@ -113,14 +114,12 @@ class BoostPostScreen extends PureComponent { handleOnSubmit(redeemType, amount, fullPermlink, selectedUser); }; - _validateUrl = async () => { + _validateUrl = () => { const { permlink } = this.state; - const { user } = this.props; - const deepLinkData = await deepLinkParser(permlink, user); - console.log('deepLinkData : ', deepLinkData); - const { routeName, params, key } = deepLinkData || {}; - if (routeName && key && params && params.content) { - let postPermlink = `${params.content.author}/${params.content.permlink}`; + const postUrl = postUrlParser(permlink); + console.log('postUrl : ', postUrl); + if (postUrl && postUrl.author && postUrl.permlink) { + let postPermlink = `${postUrl.author}/${postUrl.permlink}`; this.setState({ permlink: postPermlink, isValid: true, diff --git a/src/utils/deepLinkParser.ts b/src/utils/deepLinkParser.ts index c8051432b..7eda69d98 100644 --- a/src/utils/deepLinkParser.ts +++ b/src/utils/deepLinkParser.ts @@ -56,7 +56,7 @@ export const deepLinkParser = async (url, currentAccount) => { } } - if (feedType && ( feedType === 'hot' || feedType === 'trending' || feedType === 'created' )) { + if (feedType === 'hot' || feedType === 'trending' || feedType === 'created') { if (!tag) { routeName = ROUTES.SCREENS.TAG_RESULT; } else if (/hive-[1-3]\d{4,6}$/.test(tag)) { @@ -73,7 +73,7 @@ export const deepLinkParser = async (url, currentAccount) => { if (!routeName) { const { mode, referredUser } = parseAuthUrl(url) || {}; - if (mode && referredUser && mode === 'SIGNUP') { + if (mode === 'SIGNUP') { routeName = ROUTES.SCREENS.REGISTER; params = { referredUser, From e4b36d2f33a3813eedf20f747797395ae6649ca1 Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Mon, 30 May 2022 22:20:56 +0500 Subject: [PATCH 4/4] validate only if it is not validated i-e do not validate when selected from dropdown --- src/components/postBoost/postBoostView.js | 34 +++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/components/postBoost/postBoostView.js b/src/components/postBoost/postBoostView.js index 322e096ce..605cd162b 100644 --- a/src/components/postBoost/postBoostView.js +++ b/src/components/postBoost/postBoostView.js @@ -42,6 +42,7 @@ class BoostPostScreen extends PureComponent { }; this.startActionSheet = React.createRef(); + this.urlInputRef = React.createRef(); } // Component Life Cycles @@ -115,17 +116,18 @@ class BoostPostScreen extends PureComponent { }; _validateUrl = () => { - const { permlink } = this.state; - const postUrl = postUrlParser(permlink); - console.log('postUrl : ', postUrl); - if (postUrl && postUrl.author && postUrl.permlink) { - let postPermlink = `${postUrl.author}/${postUrl.permlink}`; - this.setState({ - permlink: postPermlink, - isValid: true, - }); - } else { - this.setState({ isValid: false }); + const { permlink, isValid } = this.state; + if (!isValid) { + const postUrl = postUrlParser(permlink); + if (postUrl && postUrl.author && postUrl.permlink) { + let postPermlink = `${postUrl.author}/${postUrl.permlink}`; + this.setState({ + permlink: postPermlink, + isValid: true, + }); + } else { + this.setState({ isValid: false }); + } } }; render() { @@ -151,7 +153,7 @@ class BoostPostScreen extends PureComponent { - + this._validateUrl()} + innerRef={this.urlInputRef} /> )} renderItem={({ item }) => ( + onPress={() => { + this.urlInputRef.current?.blur(); this.setState({ permlink: item, isValid: true, permlinkSuggestions: [], - }) - } + }); + }} > {item}