57 lines
1.8 KiB
QML
57 lines
1.8 KiB
QML
pragma Singleton
|
|
|
|
import QtQuick 2.13
|
|
import "../shared/xss.js" as XSS
|
|
|
|
QtObject {
|
|
function isHex(value) {
|
|
return /^(-0x|0x)?[0-9a-f]*$/i.test(value)
|
|
}
|
|
|
|
function startsWith0x(value) {
|
|
return value.startsWith('0x')
|
|
}
|
|
|
|
function isChatKey(value) {
|
|
return startsWith0x(value) && isHex(value) && value.length === 132
|
|
}
|
|
|
|
function isValidETHNamePrefix(value) {
|
|
return !(value.trim() === "" || value.endsWith(".") || value.indexOf("..") > -1)
|
|
}
|
|
|
|
function isAddress(value) {
|
|
return startsWith0x(value) && isHex(value) && value.length === 42
|
|
}
|
|
|
|
function isPrivateKey(value) {
|
|
return isHex(value) && ((startsWith0x(value) && value.length === 66) ||
|
|
(!startsWith0x(value) && value.length === 64))
|
|
}
|
|
|
|
function isMnemonic(value) {
|
|
// Do we support other length than 12?
|
|
return value.split(/\s|,/).length === 12
|
|
}
|
|
|
|
function compactAddress(addr, numberOfChars) {
|
|
if(addr.length <= 5 + (numberOfChars * 2)){ // 5 represents these chars 0x...
|
|
return addr;
|
|
}
|
|
return addr.substring(0, 2 + numberOfChars) + "..." + addr.substring(addr.length - numberOfChars);
|
|
}
|
|
|
|
function linkifyAndXSS(inputText) {
|
|
//URLs starting with http://, https://, or ftp://
|
|
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
|
|
var replacedText = inputText.replace(replacePattern1, "<a href='$1'>$1</a>");
|
|
|
|
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
|
|
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
|
|
replacedText = replacedText.replace(replacePattern2, "$1<a href='http://$2'>$2</a>");
|
|
|
|
replacedText = XSS.filterXSS(replacedText)
|
|
return replacedText;
|
|
}
|
|
}
|