Skip to content

Commit

Permalink
Add confirmation modal to scanned email
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Jan 11, 2025
1 parent 4d22f74 commit 5f9ed0e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 21 additions & 1 deletion src/actions/DeepLinkingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react'
import { sprintf } from 'sprintf-js'

import { ButtonsModal } from '../components/modals/ButtonsModal'
import { ConfirmContinueModal } from '../components/modals/ConfirmContinueModal'
import { FundAccountModal } from '../components/modals/FundAccountModal'
import { pickWallet } from '../components/modals/WalletListModal'
import { Airship, showError, showToast, showToastSpinner } from '../components/services/AirshipInstance'
Expand All @@ -16,7 +17,7 @@ import { Dispatch, RootState, ThunkAction } from '../types/reduxTypes'
import { NavigationBase } from '../types/routerTypes'
import { EdgeAsset } from '../types/types'
import { logEvent } from '../util/tracking'
import { base58ToUuid } from '../util/utils'
import { base58ToUuid, isEmail } from '../util/utils'
import { activatePromotion } from './AccountReferralActions'
import { checkAndShowLightBackupModal } from './BackupModalActions'
import { logoutRequest } from './LoginActions'
Expand Down Expand Up @@ -250,8 +251,27 @@ async function handleLink(navigation: NavigationBase, dispatch: Dispatch, state:
}
}
}

const promise = parseWallets()
await showToastSpinner(lstrings.scan_parsing_link, promise)
console.debug(assets)

// Check if this is an email for Tron USDT and show warning for potential
// PIX send
if (isEmail(link.uri) && assets.find(asset => asset.pluginId === 'tron' && asset.tokenId === 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') != null) {
const approved = await Airship.show<boolean>(bridge => (
<ConfirmContinueModal
bridge={bridge}
title={lstrings.warning_sending_pix_to_email_title}
body={lstrings.warning_sending_pix_to_email_body}
warning
isSkippable
/>
))
if (!approved) {
return
}
}

// Check if the uri matches one of the wallet types that we could create. In such a case, link.uri
// would be of the format 'dogecoin:QUE1U9n3kMYR...'
Expand Down
7 changes: 2 additions & 5 deletions src/components/tiles/AddressTile2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { NavigationBase } from '../../types/routerTypes'
import { getTokenId, getTokenIdForced } from '../../util/CurrencyInfoHelpers'
import { parseDeepLink } from '../../util/DeepLinkParser'
import { checkPubAddress } from '../../util/FioAddressUtils'
import { isEmail } from '../../util/utils'
import { EdgeAnim } from '../common/EdgeAnim'
import { EdgeTouchableOpacity } from '../common/EdgeTouchableOpacity'
import { AddressModal } from '../modals/AddressModal'
Expand Down Expand Up @@ -107,13 +108,9 @@ export const AddressTile2 = React.forwardRef((props: Props, ref: React.Forwarded
}
}

// Taken from pixkey.ts in edge-currency-accountbased
const re =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

// Check if this is an email for Tron USDT and show warning for potential
// PIX send
if (re.test(String(address).toLowerCase()) && coreWallet.currencyInfo.pluginId === 'tron' && tokenId === 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') {
if (isEmail(address) && coreWallet.currencyInfo.pluginId === 'tron' && tokenId === 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') {
const approved = await Airship.show<boolean>(bridge => (
<ConfirmContinueModal
bridge={bridge}
Expand Down
6 changes: 6 additions & 0 deletions src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const DEFAULT_TRUNCATE_PRECISION = 6

export const normalizeForSearch = (str: string, delimiter: string = '') => str.replace(/\s/g, delimiter).toLowerCase()

// Taken from pixkey.ts in edge-currency-accountbased
export const isEmail = (text: string) =>
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(
text.toLowerCase()
)

// Replaces extra chars with '...' either in the middle or end of the input string
export const truncateString = (input: string | number, maxLength: number, isMidTrunc: boolean = false) => {
const inputStr = typeof input !== 'string' ? String(input) : input
Expand Down

0 comments on commit 5f9ed0e

Please sign in to comment.