Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#496 One time links should be generated by our url shortener #615

Merged
Merged
23 changes: 23 additions & 0 deletions src/components/dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import userStorage from '../../lib/gundb/UserStorage'
import { FAQ, PrivacyArticle, PrivacyPolicy, RewardsTab, Support, TermsOfUse } from '../webView/webViewInstances'
import { withStyles } from '../../lib/styles'
import Mnemonics from '../signin/Mnemonics'
import { extractQueryParams, readCode } from '../../lib/share'

// import goodWallet from '../../lib/wallet/GoodWallet'
import Amount from './Amount'
Expand All @@ -47,6 +48,7 @@ import SendConfirmation from './SendConfirmation'
import SendLinkSummary from './SendLinkSummary'
import SendQRSummary from './SendQRSummary'
import { ACTION_SEND } from './utils/sendReceiveFlow'
import { routeAndPathForCode } from './utils/routeAndPathForCode'

// import FaceRecognition from './FaceRecognition/FaceRecognition'
// import FRIntro from './FaceRecognition/FRIntro'
Expand Down Expand Up @@ -85,6 +87,27 @@ const Dashboard = props => {
}
}

//Service redirects Send/Receive
useEffect(() => {
const anyParams = extractQueryParams(window.location.href)
if (anyParams.code) {
const { screenProps } = props
if (anyParams && anyParams.code) {
StanislavShevchenko marked this conversation as resolved.
Show resolved Hide resolved
const code = readCode(decodeURI(anyParams.code))
routeAndPathForCode('send', code)
.then(({ route, params }) => screenProps.push(route, params))
.catch(e => {
showErrorDialog(null, e, { onDismiss: screenProps.goToRoot })
})
}
}
if (anyParams.paymentCode) {
if (anyParams && anyParams.paymentCode) {
props.navigation.state.params = anyParams
}
}
}, [])

const nextFeed = () => {
return getNextFeed(gdstore)
}
Expand Down
17 changes: 12 additions & 5 deletions src/lib/share/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,32 @@ export function generateShareLink(action: ActionType = 'receive', params: {} = {
receive: Config.receiveUrl,
send: Config.sendUrl,
}[action]
let queryParams = '?'
let queryParams = ''

switch (Config.env) {
case 'production':
if (params.code) {
queryParams = `/${params.code}`
delete params.code
} else if (params.paymentCode) {
queryParams = `/${params.paymentCode}`
delete params.paymentCode
}
break

default:
// creates query params from params object
queryParams += toPairs(params)
.map(param => param.join('='))
.join('&')
break
}

// creates query params from params object
const additionalParams = toPairs(params)
.map(param => param.join('='))
.join('&')

if (additionalParams.length) {
queryParams += `?${additionalParams}`
}

if (!queryParams || !destination) {
throw new Error(`Link couldn't be generated`)
}
Expand Down