Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onInput(event: React.SyntheticEvent) {
event.preventDefault();
let phoneNumber = event.currentTarget.value as string;
try {
const phoneUtil = PhoneNumberUtil.getInstance();
phoneNumber = phoneUtil.format(
phoneUtil.parse(phoneNumber),
PhoneNumberFormat.INTERNATIONAL);
} catch (e) {
// Ignore errors as we validate on submit
}
this.setState({
phoneNumber: phoneNumber,
});
if (this.state.error) {
this.validate(phoneNumber);
}
}
export const getFormattedPhoneNumber = (cell, country = "US") => {
const phoneUtil = PhoneNumberUtil.getInstance();
// we return an empty string vs null when the phone number is inValid
// because when the cell is null, batch inserts into campaign contacts fail
// then when contacts have cell.length < 12 (+1), it's deleted before assignments are created
try {
const inputNumber = phoneUtil.parse(cell, country);
const isValid = phoneUtil.isValidNumber(inputNumber);
if (isValid) {
return phoneUtil.format(inputNumber, PhoneNumberFormat.E164);
}
return "";
} catch (e) {
log.error(e);
return "";
}
};
import {
PhoneNumber,
PhoneNumberFormat,
PhoneNumberType,
PhoneNumberUtil,
} from 'google-libphonenumber'
import * as Web3Utils from 'web3-utils'
export interface ParsedPhoneNumber {
e164Number: string
displayNumber: string
countryCode?: number
regionCode?: string
}
const phoneUtil = PhoneNumberUtil.getInstance()
const MIN_PHONE_LENGTH = 4
export function getCountryEmoji(
e164PhoneNumber: string,
countryCodePossible?: number,
regionCodePossible?: string
) {
// The country code and region code can both be passed in, or it can be inferred from the e164PhoneNumber
let countryCode: any
let regionCode: any
countryCode = countryCodePossible
regionCode = regionCodePossible
if (!countryCode || !regionCode) {
countryCode = getCountryCode(e164PhoneNumber)
regionCode = getRegionCode(e164PhoneNumber)
}
import { PhoneNumberUtil } from 'google-libphonenumber'
import Nexmo from 'nexmo'
import { fetchEnv } from './env'
const phoneUtil = PhoneNumberUtil.getInstance()
let nexmoClient: any
let nexmoNumbers: Array<{
code: string
phoneNumber: string
}> = []
export async function initializeSmsProviders() {
nexmoClient = new Nexmo({
apiKey: fetchEnv('NEXMO_KEY'),
apiSecret: fetchEnv('NEXMO_SECRET'),
})
const availableNumbers = await getAvailableNumbers()
nexmoNumbers = availableNumbers.map((number: any) => ({
} from './config'
import {
deleteMessage,
getActiveVerifiers,
getMessagesForPhoneNumber,
incrementVerifierAttemptCount,
isMessageSent,
saveMessage,
setVerifierProperties,
} from './database'
import { MobileVerifier } from './types'
const SMS_LENGTH_LIMIT = 160
const NUM_VERIFIERS_TO_WAKE = 3
const MAX_VERIFIER_ATTEMPT_COUNT = 20
const phoneUtil = PhoneNumberUtil.getInstance()
export async function sendSmsCode(address: string, phoneNumber: string, message: string) {
console.info('Attempting to send sms verification code.')
message = getFormattedMessage(message)
if (alwaysUseTwilio) {
console.info('Config set to always use Twilio')
await sendViaTextProvider(phoneNumber, message)
return 'Twilio'
}
const verifiers = await getRandomActiveVerifiers(NUM_VERIFIERS_TO_WAKE, phoneNumber)
if (verifiers === null || verifiers.length === 0) {
console.info('No suitable verifiers found. Using Twilio')
await sendViaTextProvider(phoneNumber, message)
export const getDisplayPhoneNumber = (e164Number, country = "US") => {
const phoneUtil = PhoneNumberUtil.getInstance();
const parsed = phoneUtil.parse(e164Number, country);
return phoneUtil.format(parsed, PhoneNumberFormat.NATIONAL);
};
const validator = (control: AbstractControl): { [key: string]: any } => {
if (Util.isNotPresent(control)) {
return undefined;
}
if (!PhoneValidators.checkRegionCode(local)) {
return { 'noValidRegionCode': true };
}
let phoneParser: PhoneNumberUtil = PhoneNumberUtil.getInstance();
let error = { 'noPhoneNumber': true };
try {
let phoneNumber: libPhoneNumber.PhoneNumber = phoneParser.parse(control.value, local);
if (phoneParser.isValidNumber(phoneNumber)) {
error = undefined;
}
} catch (err) {
error = { 'noPhoneNumber': true };
}
return error;
};
return validator;
validate(number: string): boolean {
let valid = false;
let error: string | undefined = undefined;
try {
const phoneUtil = PhoneNumberUtil.getInstance();
const phoneNumber = phoneUtil.parse(number);
valid = phoneUtil.isValidNumber(phoneNumber);
} catch (e) {
valid = false;
}
if (!valid) {
error = "Invalid phone number";
}
this.setState({
error: error,
});
return valid;
}
constructor () {
super()
this.phoneUtil = PhoneNumberUtil.getInstance()
this.countries = countries.callingCountries.all.filter((country) => country.status === 'assigned')
this.mouseDownOnMenu = false
this._pageClick = this.pageClick.bind(this)
this.missingFlags = { AQ: 'WW', BQ: 'NL', EH: 'WW-AFR', MF: 'FR', SH: 'GB' }
this.boxShadowStyle = '0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12), 0 5px 5px -3px rgba(0, 0, 0, 0.4)'
this.bgColorTransitionStyle = 'background-color .25s, color .25s'
this.inputID = '__react-intl-tel-input'
this.state = {
open: false,
selectedCountry: {},
intlPhoneNumber: '',
phoneNumber: '',
searchTerm: '',
valid: false,
filteredCountries: [],
preferredCountries: [],