From 6ace1fe73b190f1c6eeae65957529797075ec3d9 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Thu, 8 Aug 2019 12:25:25 +0300 Subject: [PATCH] Fixed linking issue --- .../container/applicationContainer.js | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 8151d669e..562abd620 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -11,6 +11,7 @@ import { injectIntl } from 'react-intl'; import { NavigationActions } from 'react-navigation'; import { bindActionCreators } from 'redux'; import EStyleSheet from 'react-native-extended-stylesheet'; +import forEach from 'lodash/forEach'; // Constants import AUTH_TYPE from '../../../constants/authType'; @@ -170,23 +171,36 @@ class ApplicationContainer extends Component { let content; let profile; const { currentAccount, dispatch } = this.props; + const { isIos } = this.state; - if ( - url.indexOf('esteem') > -1 || - url.indexOf('steemit') > -1 || - url.indexOf('busy') > -1 || - url.indexOf('steempeak') > -1 - ) { - url = url.substring(url.indexOf('@'), url.length); - const routeParams = url.indexOf('/') > -1 ? url.split('/') : [url]; + const mapObj = { + esteem: '', + 'steemit.com/': '', + 'busy.org/': '', + 'steempeak.com/': '', + }; - [, permlink] = routeParams; - author = - routeParams && routeParams.length > 0 && routeParams[0].indexOf('@') > -1 - ? routeParams[0].replace('@', '') - : routeParams[0]; + let formattedUrl = url + .split('//') + .pop() + .replace(/steemit.com\/|busy.org\/|steempeak.com\//gi, matched => { + return mapObj[matched]; + }); + + // TODO: WORKAROUND + if (isIos && url.indexOf('esteem://') > -1) { + formattedUrl = `@${formattedUrl}`; } + const routeParams = formattedUrl.indexOf('/') > -1 ? formattedUrl.split('/') : [formattedUrl]; + + forEach(routeParams, (value, index) => { + if (value.indexOf('@') > -1) { + author = value.replace('@', ''); + permlink = routeParams[index + 1]; + } + }); + if (author && permlink) { await getPost(author, permlink, currentAccount.name) .then(result => {