Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Common/Ticker.js
import mainLogo from '@assets/logo_primary.png'; | import mainLogo from '@assets/logo_primary.png'; | ||||
import tokenLogo from '@assets/logo_secondary.png'; | import tokenLogo from '@assets/logo_secondary.png'; | ||||
import cashaddr from 'cashaddrjs'; | import cashaddr from 'ecashaddrjs'; | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
export const currency = { | export const currency = { | ||||
name: 'eCash', | name: 'eCash', | ||||
ticker: 'XEC', | ticker: 'XEC', | ||||
logo: mainLogo, | logo: mainLogo, | ||||
legacyPrefix: 'bitcoincash', | legacyPrefix: 'bitcoincash', | ||||
prefixes: ['bitcoincash', 'ecash'], | prefixes: ['ecash'], | ||||
coingeckoId: 'bitcoin-cash-abc-2', | coingeckoId: 'bitcoin-cash-abc-2', | ||||
defaultFee: 2.01, | defaultFee: 2.01, | ||||
dustSats: 550, | dustSats: 550, | ||||
etokenSats: 546, | etokenSats: 546, | ||||
cashDecimals: 2, | cashDecimals: 2, | ||||
blockExplorerUrl: 'https://explorer.bitcoinabc.org', | blockExplorerUrl: 'https://explorer.bitcoinabc.org', | ||||
tokenExplorerUrl: 'https://explorer.be.cash', | tokenExplorerUrl: 'https://explorer.be.cash', | ||||
blockExplorerUrlTestnet: 'https://texplorer.bitcoinabc.org', | blockExplorerUrlTestnet: 'https://texplorer.bitcoinabc.org', | ||||
tokenName: 'eToken', | tokenName: 'eToken', | ||||
tokenTicker: 'eToken', | tokenTicker: 'eToken', | ||||
tokenLogo: tokenLogo, | tokenLogo: tokenLogo, | ||||
tokenPrefixes: ['simpleledger', 'etoken'], | tokenPrefixes: ['etoken'], | ||||
tokenIconsUrl: '', //https://tokens.bitcoin.com/32 for BCH SLP | tokenIconsUrl: '', //https://tokens.bitcoin.com/32 for BCH SLP | ||||
useBlockchainWs: false, | useBlockchainWs: false, | ||||
txHistoryCount: 5, | txHistoryCount: 5, | ||||
hydrateUtxoBatchSize: 20, | hydrateUtxoBatchSize: 20, | ||||
defaultSettings: { fiatCurrency: 'usd' }, | defaultSettings: { fiatCurrency: 'usd' }, | ||||
settingsValidation: { | settingsValidation: { | ||||
fiatCurrency: [ | fiatCurrency: [ | ||||
'usd', | 'usd', | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | try { | ||||
); | ); | ||||
} | } | ||||
} catch (err) { | } catch (err) { | ||||
return err; | return err; | ||||
} | } | ||||
return legacyAddress; | return legacyAddress; | ||||
} | } | ||||
export function parseAddress(BCH, addressString) { | 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, | ||||
}; | }; | ||||
// Parse address string for parameters | // Parse address string for parameters | ||||
const paramCheck = addressString.split('?'); | const paramCheck = addressString.split('?'); | ||||
let cleanAddress = paramCheck[0]; | let cleanAddress = paramCheck[0]; | ||||
addressInfo.address = cleanAddress; | addressInfo.address = cleanAddress; | ||||
// Validate address | // Validate address | ||||
let isValidAddress; | let isValidAddress; | ||||
try { | try { | ||||
isValidAddress = BCH.Address.isCashAddress(cleanAddress); | isValidAddress = BCH.Address.isCashAddress(cleanAddress); | ||||
// Only accept addresses with ecash: prefix | |||||
const { prefix } = cashaddr.decode(cleanAddress); | |||||
// If the address does not have a valid prefix or token prefix | |||||
if ( | |||||
(!isToken && !currency.prefixes.includes(prefix)) || | |||||
(isToken && !currency.tokenPrefixes.includes(prefix)) | |||||
) { | |||||
// then it is not a valid destination address for XEC sends | |||||
isValidAddress = false; | |||||
} | |||||
} catch (err) { | } catch (err) { | ||||
isValidAddress = false; | isValidAddress = false; | ||||
} | } | ||||
addressInfo.isValid = isValidAddress; | addressInfo.isValid = isValidAddress; | ||||
// Check for parameters | // Check for parameters | ||||
// only the amount param is currently supported | // only the amount param is currently supported | ||||
Show All 23 Lines |