diff options
author | Kevin Serrano <kevin.serrano@consensys.net> | 2017-09-12 07:22:20 +0800 |
---|---|---|
committer | Kevin Serrano <kevin.serrano@consensys.net> | 2017-09-12 07:22:20 +0800 |
commit | fa1ec5dcd16ba09d31720a42d4015dedde91148c (patch) | |
tree | 121d25121bbb01630e519f1e0c8601f8bc32531d /ui/app/util.js | |
parent | 3a7d4a5d4e94d9a4c2556b161c5bad7dc00837a4 (diff) | |
download | tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar.gz tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar.bz2 tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar.lz tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar.xz tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.tar.zst tangerine-wallet-browser-fa1ec5dcd16ba09d31720a42d4015dedde91148c.zip |
Move function as util function.
Diffstat (limited to 'ui/app/util.js')
-rw-r--r-- | ui/app/util.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index ac3f42c6b..1368ebf11 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -36,6 +36,7 @@ module.exports = { valueTable: valueTable, bnTable: bnTable, isHex: isHex, + exportAsFile: exportAsFile, } function valuesFor (obj) { @@ -215,3 +216,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) + } +} |