diff options
Diffstat (limited to 'ui/app/util.js')
-rw-r--r-- | ui/app/util.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index ac3f42c6b..3f8b4dcc3 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -36,6 +36,8 @@ module.exports = { valueTable: valueTable, bnTable: bnTable, isHex: isHex, + exportAsFile: exportAsFile, + isInvalidChecksumAddress, } function valuesFor (obj) { @@ -65,6 +67,12 @@ function isValidAddress (address) { return (isAllOneCase(prefixed) && ethUtil.isValidAddress(prefixed)) || ethUtil.isValidChecksumAddress(prefixed) } +function isInvalidChecksumAddress (address) { + var prefixed = ethUtil.addHexPrefix(address) + if (address === '0x0000000000000000000000000000000000000000') return false + return !isAllOneCase(prefixed) && !ethUtil.isValidChecksumAddress(prefixed) && ethUtil.isValidAddress(prefixed) +} + function isAllOneCase (address) { if (!address) return true var lower = address.toLowerCase() @@ -215,3 +223,18 @@ function readableDate (ms) { function isHex (str) { return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/)) } + +function exportAsFile (filename, data) { + // source: https://stackoverflow.com/a/33542499 by Ludovic Feltz + const blob = new Blob([data], {type: 'text/csv'}) + if (window.navigator.msSaveOrOpenBlob) { + window.navigator.msSaveBlob(blob, filename) + } else { + const elem = window.document.createElement('a') + elem.href = window.URL.createObjectURL(blob) + elem.download = filename + document.body.appendChild(elem) + elem.click() + document.body.removeChild(elem) + } +} |