Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Common/Ticker.js
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | try { | ||||
); | ); | ||||
} | } | ||||
} catch (err) { | } catch (err) { | ||||
return err; | return err; | ||||
} | } | ||||
return legacyAddress; | return legacyAddress; | ||||
} | } | ||||
export function toLegacyArray(addressArray) { | |||||
let cleanArray = []; // array of bch converted addresses to be returned | |||||
try { | |||||
if ( | |||||
addressArray === null || | |||||
addressArray === undefined || | |||||
!addressArray.length || | |||||
addressArray === '' | |||||
) { | |||||
throw new Error('Invalid addressArray input'); | |||||
} | |||||
const arrayLength = addressArray.length; | |||||
for (let i = 0; i < arrayLength; i++) { | |||||
let testedAddress; | |||||
let legacyAddress; | |||||
let addressValueArr = addressArray[i].split(','); | |||||
let address = addressValueArr[0]; | |||||
let value = addressValueArr[1]; | |||||
if (isValidCashPrefix(address)) { | |||||
// Prefix-less addresses may be valid, but the cashaddr.decode function used below | |||||
// will throw an error without a prefix. Hence, must ensure prefix to use that function. | |||||
const hasPrefix = address.includes(':'); | |||||
if (!hasPrefix) { | |||||
testedAddress = currency.legacyPrefix + ':' + address; | |||||
} else { | |||||
testedAddress = address; | |||||
} | |||||
// Note: an `ecash:` checksum address with no prefix will not be validated by | |||||
// parseAddress in Send.js | |||||
// Only handle the case of prefixless address that is valid `bitcoincash:` address | |||||
const { type, hash } = cashaddr.decode(testedAddress); | |||||
legacyAddress = cashaddr.encode( | |||||
currency.legacyPrefix, | |||||
type, | |||||
hash, | |||||
); | |||||
let convertedArrayData = legacyAddress + ',' + value + '\n'; | |||||
cleanArray.push(convertedArrayData); | |||||
} else { | |||||
console.log(`Error: ${address} is not a cash address`); | |||||
throw new Error( | |||||
'Address prefix is not a valid cash address with a prefix from the Ticker.prefixes array', | |||||
); | |||||
} | |||||
} | |||||
} catch (err) { | |||||
return err; | |||||
} | |||||
return cleanArray; | |||||
} | |||||
export function parseAddress(BCH, addressString, isToken = false) { | export function parseAddress(BCH, addressString, isToken = false) { | ||||
// Build return obj | // Build return obj | ||||
const addressInfo = { | const addressInfo = { | ||||
address: '', | address: '', | ||||
isValid: false, | isValid: false, | ||||
queryString: null, | queryString: null, | ||||
amount: null, | amount: null, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |