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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ REACT_APP_ROLLBAR_API_KEY=

# Should or should not throw errors when saving profile fails
REACT_APP_THROW_SAVE_PROFILE_ERRORS=true

REACT_APP_RECEIVE_URL=
REACT_APP_SEND_URL=
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ REACT_APP_AMPLITUDE_API_KEY=
REACT_APP_ROLLBAR_API_KEY=
REACT_APP_THROW_SAVE_PROFILE_ERRORS=true
REACT_APP_ADMIN_MNEMONIC=drip industry pizza deny pistol stem must device citizen crowd offer now
REACT_APP_RECEIVE_URL=http://localhost:3000/AppNavigation/Dashboard/Send
REACT_APP_SEND_URL=http://localhost:3000/AppNavigation/Dashboard/Home
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
6 changes: 5 additions & 1 deletion src/config/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const publicUrl = process.env.REACT_APP_PUBLIC_URL || (window && window.location && window.location.origin)

const Config = {
env: process.env.REACT_APP_ENV || 'development',
version: process.env.VERSION || 'v0',
logLevel: process.env.REACT_APP_LOG_LEVEL || 'debug',
serverUrl: process.env.REACT_APP_SERVER_URL || 'http://localhost:3003',
gunPublicUrl: process.env.REACT_APP_GUN_PUBLIC_URL || 'http://localhost:3003/gun',
web3SiteUrl: process.env.REACT_APP_WEB3_SITE_URL,
publicUrl: process.env.REACT_APP_PUBLIC_URL || (window && window.location && window.location.origin),
publicUrl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is defined above in this file

infuraKey: process.env.REACT_APP_INFURA_KEY,
network: process.env.REACT_APP_NETWORK || 'fuse',
zoomLicenseKey: process.env.REACT_APP_ZOOM_LICENSE_KEY,
Expand All @@ -20,6 +22,8 @@ const Config = {
!process.env.REACT_APP_THROW_SAVE_PROFILE_ERRORS || process.env.REACT_APP_THROW_SAVE_PROFILE_ERRORS === 'true',
withMockedFeeds: process.env.REACT_APP_WITH_MOCKED_FEEDS === 'true',
safariMobileKeyboardGuidedSize: process.env.REACT_APP_SAFARI_MOBILE_KEYBOARD_GUIDED_SIZE === 'true',
receiveUrl: process.env.REACT_APP_RECEIVE_URL || `${publicUrl}/AppNavigation/Dashboard/Send`,
sirpy marked this conversation as resolved.
Show resolved Hide resolved
sendUrl: process.env.REACT_APP_SEND_URL || `${publicUrl}/AppNavigation/Dashboard/Home`,
ethereum: {
'42': {
network_id: 42,
Expand Down
28 changes: 24 additions & 4 deletions src/lib/share/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,38 @@ type ActionType = 'receive' | 'send'
export function generateShareLink(action: ActionType = 'receive', params: {} = {}): string {
// depending on the action, routes may vary
const destination = {
receive: 'Send',
send: 'Home',
receive: Config.receiveUrl,
send: Config.sendUrl,
}[action]
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:
break
}

// creates query params from params object
const queryParams = toPairs(params)
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`)
}

return encodeURI(`${Config.publicUrl}/AppNavigation/Dashboard/${destination}?${queryParams}`)
return encodeURI(`${destination}${queryParams}`)
}