Refactoring: var -> let, const
This commit is contained in:
parent
cf7adc0b0a
commit
7a0a069681
|
@ -4,12 +4,12 @@
|
|||
// // The reload client has a compatibility with livereload.
|
||||
// // WARNING: only supports reload command.
|
||||
|
||||
// var LIVERELOAD_HOST = 'localhost:';
|
||||
// var LIVERELOAD_PORT = 35729;
|
||||
// var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
|
||||
// const LIVERELOAD_HOST = 'localhost:';
|
||||
// const LIVERELOAD_PORT = 35729;
|
||||
// const connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
|
||||
|
||||
// connection.onopen = function(event) {
|
||||
// var hello = {
|
||||
// const hello = {
|
||||
// command: 'hello',
|
||||
// protocols: ['http://livereload.com/protocols/official-7']
|
||||
// };
|
||||
|
@ -23,7 +23,7 @@
|
|||
|
||||
// connection.onmessage = function (e) {
|
||||
// if (e.data) {
|
||||
// var data = JSON.parse(e.data);
|
||||
// const data = JSON.parse(e.data);
|
||||
// if (data && data.command === 'reload') {
|
||||
// extension.runtime.reload();
|
||||
// }
|
||||
|
@ -32,9 +32,9 @@
|
|||
|
||||
window.LiveReloadOptions = { host: 'localhost' };
|
||||
|
||||
(function e (t, n, r) { function s (o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require === 'function' && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); var f = new Error("Cannot find module '" + o + "'"); throw f.code = 'MODULE_NOT_FOUND', f } var l = n[o] = {exports: {}}; t[o][0].call(l.exports, function (e) { var n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } var i = typeof require === 'function' && require; for (var o = 0; o < r.length; o++)s(r[o]); return s })({1: [function (require, module, exports) {
|
||||
(function e (t, n, r) { function s (o, u) { if (!n[o]) { if (!t[o]) { let a = typeof require === 'function' && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); let f = new Error("Cannot find module '" + o + "'"); throw f.code = 'MODULE_NOT_FOUND', f } let l = n[o] = {exports: {}}; t[o][0].call(l.exports, function (e) { let n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } let i = typeof require === 'function' && require; for (let o = 0; o < r.length; o++)s(r[o]); return s })({1: [function (require, module, exports) {
|
||||
(function () {
|
||||
var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref
|
||||
let Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref
|
||||
|
||||
_ref = require('./protocol'), Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7
|
||||
|
||||
|
@ -166,7 +166,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Connector.prototype._onopen = function (e) {
|
||||
var hello
|
||||
let hello
|
||||
this.handlers.socketConnected()
|
||||
this._disconnectionReason = 'handshake-failed'
|
||||
hello = {
|
||||
|
@ -204,7 +204,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {'./protocol': 6}], 2: [function (require, module, exports) {
|
||||
(function () {
|
||||
var CustomEvents
|
||||
let CustomEvents
|
||||
|
||||
CustomEvents = {
|
||||
bind: function (element, eventName, handler) {
|
||||
|
@ -222,7 +222,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
},
|
||||
fire: function (element, eventName) {
|
||||
var event
|
||||
let event
|
||||
if (element.addEventListener) {
|
||||
event = document.createEvent('HTMLEvents')
|
||||
event.initEvent(eventName, true, true)
|
||||
|
@ -243,7 +243,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {}], 3: [function (require, module, exports) {
|
||||
(function () {
|
||||
var LessPlugin
|
||||
let LessPlugin
|
||||
|
||||
module.exports = LessPlugin = (function () {
|
||||
LessPlugin.identifier = 'less'
|
||||
|
@ -268,9 +268,9 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
LessPlugin.prototype.reloadLess = function (path) {
|
||||
var link, links, _i, _len
|
||||
let link, links, _i, _len
|
||||
links = (function () {
|
||||
var _i, _len, _ref, _results
|
||||
let _i, _len, _ref, _results
|
||||
_ref = document.getElementsByTagName('link')
|
||||
_results = []
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
|
@ -304,7 +304,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {}], 4: [function (require, module, exports) {
|
||||
(function () {
|
||||
var Connector, LiveReload, Options, Reloader, Timer,
|
||||
let Connector, LiveReload, Options, Reloader, Timer,
|
||||
__hasProp = {}.hasOwnProperty
|
||||
|
||||
Connector = require('./connector').Connector
|
||||
|
@ -317,7 +317,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
|
||||
exports.LiveReload = LiveReload = (function () {
|
||||
function LiveReload (window) {
|
||||
var k, v, _ref
|
||||
let k, v, _ref
|
||||
this.window = window
|
||||
this.listeners = {}
|
||||
this.plugins = []
|
||||
|
@ -358,7 +358,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
})(this),
|
||||
connected: (function (_this) {
|
||||
return function (protocol) {
|
||||
var _base
|
||||
let _base
|
||||
if (typeof (_base = _this.listeners).connect === 'function') {
|
||||
_base.connect()
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
})(this),
|
||||
disconnected: (function (_this) {
|
||||
return function (reason, nextDelay) {
|
||||
var _base
|
||||
let _base
|
||||
if (typeof (_base = _this.listeners).disconnect === 'function') {
|
||||
_base.disconnect()
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
LiveReload.prototype.performReload = function (message) {
|
||||
var _ref, _ref1
|
||||
let _ref, _ref1
|
||||
this.log('LiveReload received reload request: ' + (JSON.stringify(message, null, 2)))
|
||||
return this.reloader.reload(message.path, {
|
||||
liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
|
||||
|
@ -442,7 +442,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
LiveReload.prototype.shutDown = function () {
|
||||
var _base
|
||||
let _base
|
||||
if (!this.initialized) {
|
||||
return
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
LiveReload.prototype.addPlugin = function (pluginClass) {
|
||||
var plugin
|
||||
let plugin
|
||||
if (!this.initialized) {
|
||||
return
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
LiveReload.prototype.analyze = function () {
|
||||
var plugin, pluginData, pluginsData, _i, _len, _ref
|
||||
let plugin, pluginData, pluginsData, _i, _len, _ref
|
||||
if (!this.initialized) {
|
||||
return
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {'./connector': 1, './options': 5, './reloader': 7, './timer': 9}], 5: [function (require, module, exports) {
|
||||
(function () {
|
||||
var Options
|
||||
let Options
|
||||
|
||||
exports.Options = Options = (function () {
|
||||
function Options () {
|
||||
|
@ -536,7 +536,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
})()
|
||||
|
||||
Options.extract = function (document) {
|
||||
var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1
|
||||
let element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1
|
||||
_ref = document.getElementsByTagName('script')
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
element = _ref[_i]
|
||||
|
@ -566,8 +566,8 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {}], 6: [function (require, module, exports) {
|
||||
(function () {
|
||||
var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError,
|
||||
__indexOf = [].indexOf || function (item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i } return -1 }
|
||||
let PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError,
|
||||
__indexOf = [].indexOf || function (item) { for (let i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i } return -1 }
|
||||
|
||||
exports.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6'
|
||||
|
||||
|
@ -592,7 +592,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Parser.prototype.process = function (data) {
|
||||
var command, e, message, options, _ref
|
||||
let command, e, message, options, _ref
|
||||
try {
|
||||
if (this.protocol == null) {
|
||||
if (data.match(/^!!ver:([\d.]+)$/)) {
|
||||
|
@ -638,7 +638,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Parser.prototype._parseMessage = function (data, validCommands) {
|
||||
var e, message, _ref
|
||||
let e, message, _ref
|
||||
try {
|
||||
message = JSON.parse(data)
|
||||
} catch (_error) {
|
||||
|
@ -659,10 +659,10 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {}], 7: [function (require, module, exports) {
|
||||
(function () {
|
||||
var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl
|
||||
let IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl
|
||||
|
||||
splitUrl = function (url) {
|
||||
var hash, index, params
|
||||
let hash, index, params
|
||||
if ((index = url.indexOf('#')) >= 0) {
|
||||
hash = url.slice(index)
|
||||
url = url.slice(0, index)
|
||||
|
@ -683,7 +683,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
pathFromUrl = function (url) {
|
||||
var path
|
||||
let path
|
||||
url = splitUrl(url).url
|
||||
if (url.indexOf('file://') === 0) {
|
||||
path = url.replace(/^file:\/\/(localhost)?/, '')
|
||||
|
@ -694,7 +694,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
pickBestMatch = function (path, objects, pathFunc) {
|
||||
var bestMatch, object, score, _i, _len
|
||||
let bestMatch, object, score, _i, _len
|
||||
bestMatch = {
|
||||
score: 0,
|
||||
}
|
||||
|
@ -716,7 +716,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
numberOfMatchingSegments = function (path1, path2) {
|
||||
var comps1, comps2, eqCount, len
|
||||
let comps1, comps2, eqCount, len
|
||||
path1 = path1.replace(/^\/+/, '').toLowerCase()
|
||||
path2 = path2.replace(/^\/+/, '').toLowerCase()
|
||||
if (path1 === path2) {
|
||||
|
@ -765,7 +765,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reload = function (path, options) {
|
||||
var plugin, _base, _i, _len, _ref
|
||||
let plugin, _base, _i, _len, _ref
|
||||
this.options = options
|
||||
if ((_base = this.options).stylesheetReloadTimeout == null) {
|
||||
_base.stylesheetReloadTimeout = 15000
|
||||
|
@ -798,7 +798,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reloadImages = function (path) {
|
||||
var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results
|
||||
let expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results
|
||||
expando = this.generateUniqueString()
|
||||
_ref = this.document.images
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
|
@ -829,7 +829,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reloadStylesheetImages = function (styleSheet, path, expando) {
|
||||
var e, rule, rules, styleNames, _i, _j, _len, _len1
|
||||
let e, rule, rules, styleNames, _i, _j, _len, _len1
|
||||
try {
|
||||
rules = styleSheet != null ? styleSheet.cssRules : void 0
|
||||
} catch (_error) {
|
||||
|
@ -857,7 +857,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reloadStyleImages = function (style, styleNames, path, expando) {
|
||||
var newValue, styleName, value, _i, _len
|
||||
let newValue, styleName, value, _i, _len
|
||||
for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
|
||||
styleName = styleNames[_i]
|
||||
value = style[styleName]
|
||||
|
@ -879,9 +879,9 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reloadStylesheet = function (path) {
|
||||
var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1
|
||||
let imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1
|
||||
links = (function () {
|
||||
var _i, _len, _ref, _results
|
||||
let _i, _len, _ref, _results
|
||||
_ref = this.document.getElementsByTagName('link')
|
||||
_results = []
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
|
@ -936,7 +936,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.collectImportedStylesheets = function (link, styleSheet, result) {
|
||||
var e, index, rule, rules, _i, _len
|
||||
let e, index, rule, rules, _i, _len
|
||||
try {
|
||||
rules = styleSheet != null ? styleSheet.cssRules : void 0
|
||||
} catch (_error) {
|
||||
|
@ -965,7 +965,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.waitUntilCssLoads = function (clone, func) {
|
||||
var callbackExecuted, executeCallback, poll
|
||||
let callbackExecuted, executeCallback, poll
|
||||
callbackExecuted = false
|
||||
executeCallback = (function (_this) {
|
||||
return function () {
|
||||
|
@ -1003,7 +1003,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reattachStylesheetLink = function (link) {
|
||||
var clone, parent
|
||||
let clone, parent
|
||||
if (link.__LiveReload_pendingRemoval) {
|
||||
return
|
||||
}
|
||||
|
@ -1025,14 +1025,14 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
return this.waitUntilCssLoads(clone, (function (_this) {
|
||||
return function () {
|
||||
var additionalWaitingTime
|
||||
let additionalWaitingTime
|
||||
if (/AppleWebKit/.test(navigator.userAgent)) {
|
||||
additionalWaitingTime = 5
|
||||
} else {
|
||||
additionalWaitingTime = 200
|
||||
}
|
||||
return _this.Timer.start(additionalWaitingTime, function () {
|
||||
var _ref
|
||||
let _ref
|
||||
if (!link.parentNode) {
|
||||
return
|
||||
}
|
||||
|
@ -1045,7 +1045,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.reattachImportedRule = function (_arg) {
|
||||
var href, index, link, media, newRule, parent, rule, tempLink
|
||||
let href, index, link, media, newRule, parent, rule, tempLink
|
||||
rule = _arg.rule, index = _arg.index, link = _arg.link
|
||||
parent = rule.parentStyleSheet
|
||||
href = this.generateCacheBustUrl(rule.href)
|
||||
|
@ -1087,7 +1087,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}
|
||||
|
||||
Reloader.prototype.generateCacheBustUrl = function (url, expando) {
|
||||
var hash, oldParams, originalUrl, params, _ref
|
||||
let hash, oldParams, originalUrl, params, _ref
|
||||
if (expando == null) {
|
||||
expando = this.generateUniqueString()
|
||||
}
|
||||
|
@ -1117,7 +1117,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {}], 8: [function (require, module, exports) {
|
||||
(function () {
|
||||
var CustomEvents, LiveReload, k
|
||||
let CustomEvents, LiveReload, k
|
||||
|
||||
CustomEvents = require('./customevents')
|
||||
|
||||
|
@ -1149,7 +1149,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
|||
}).call(this)
|
||||
}, {'./customevents': 2, './less': 3, './livereload': 4}], 9: [function (require, module, exports) {
|
||||
(function () {
|
||||
var Timer
|
||||
let Timer
|
||||
|
||||
exports.Timer = Timer = (function () {
|
||||
function Timer (func) {
|
||||
|
|
|
@ -30,10 +30,10 @@ if (shouldInjectWeb3()) {
|
|||
function setupInjection () {
|
||||
try {
|
||||
// inject in-page script
|
||||
var scriptTag = document.createElement('script')
|
||||
const scriptTag = document.createElement('script')
|
||||
scriptTag.textContent = inpageBundle
|
||||
scriptTag.onload = function () { this.parentNode.removeChild(this) }
|
||||
var container = document.head || document.documentElement
|
||||
const container = document.head || document.documentElement
|
||||
// append as first child
|
||||
container.insertBefore(scriptTag, container.children[0])
|
||||
} catch (e) {
|
||||
|
@ -163,7 +163,7 @@ function suffixCheck () {
|
|||
* @returns {boolean} {@code true} if the documentElement is an html node or if none exists
|
||||
*/
|
||||
function documentElementCheck () {
|
||||
var documentElement = document.documentElement.nodeName
|
||||
const documentElement = document.documentElement.nodeName
|
||||
if (documentElement) {
|
||||
return documentElement.toLowerCase() === 'html'
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ function documentElementCheck () {
|
|||
* @returns {boolean} {@code true} if the current domain is blacklisted
|
||||
*/
|
||||
function blacklistedDomainCheck () {
|
||||
var blacklistedDomains = [
|
||||
const blacklistedDomains = [
|
||||
'uscourts.gov',
|
||||
'dropbox.com',
|
||||
'webbyawards.com',
|
||||
|
@ -187,8 +187,8 @@ function blacklistedDomainCheck () {
|
|||
'ani.gamer.com.tw',
|
||||
'blueskybooking.com',
|
||||
]
|
||||
var currentUrl = window.location.href
|
||||
var currentRegex
|
||||
const currentUrl = window.location.href
|
||||
let currentRegex
|
||||
for (let i = 0; i < blacklistedDomains.length; i++) {
|
||||
const blacklistedDomain = blacklistedDomains[i].replace('.', '\\.')
|
||||
currentRegex = new RegExp(`(?:https?:\\/\\/)(?:(?!${blacklistedDomain}).)*$`)
|
||||
|
|
|
@ -14,17 +14,17 @@ class EdgeEncryptor {
|
|||
* @returns {Promise<string>} Promise resolving to an object with ciphertext
|
||||
*/
|
||||
encrypt (password, dataObject) {
|
||||
var salt = this._generateSalt()
|
||||
const salt = this._generateSalt()
|
||||
return this._keyFromPassword(password, salt)
|
||||
.then(function (key) {
|
||||
var data = JSON.stringify(dataObject)
|
||||
var dataBuffer = Unibabel.utf8ToBuffer(data)
|
||||
var vector = global.crypto.getRandomValues(new Uint8Array(16))
|
||||
var resultbuffer = asmcrypto.AES_GCM.encrypt(dataBuffer, key, vector)
|
||||
const data = JSON.stringify(dataObject)
|
||||
const dataBuffer = Unibabel.utf8ToBuffer(data)
|
||||
const vector = global.crypto.getRandomValues(new Uint8Array(16))
|
||||
const resultbuffer = asmcrypto.AES_GCM.encrypt(dataBuffer, key, vector)
|
||||
|
||||
var buffer = new Uint8Array(resultbuffer)
|
||||
var vectorStr = Unibabel.bufferToBase64(vector)
|
||||
var vaultStr = Unibabel.bufferToBase64(buffer)
|
||||
const buffer = new Uint8Array(resultbuffer)
|
||||
const vectorStr = Unibabel.bufferToBase64(vector)
|
||||
const vaultStr = Unibabel.bufferToBase64(buffer)
|
||||
return JSON.stringify({
|
||||
data: vaultStr,
|
||||
iv: vectorStr,
|
||||
|
@ -48,7 +48,7 @@ class EdgeEncryptor {
|
|||
const encryptedData = Unibabel.base64ToBuffer(payload.data)
|
||||
const vector = Unibabel.base64ToBuffer(payload.iv)
|
||||
return new Promise((resolve, reject) => {
|
||||
var result
|
||||
let result
|
||||
try {
|
||||
result = asmcrypto.AES_GCM.decrypt(encryptedData, key, vector)
|
||||
} catch (err) {
|
||||
|
@ -72,10 +72,10 @@ class EdgeEncryptor {
|
|||
*/
|
||||
_keyFromPassword (password, salt) {
|
||||
|
||||
var passBuffer = Unibabel.utf8ToBuffer(password)
|
||||
var saltBuffer = Unibabel.base64ToBuffer(salt)
|
||||
const passBuffer = Unibabel.utf8ToBuffer(password)
|
||||
const saltBuffer = Unibabel.base64ToBuffer(salt)
|
||||
return new Promise((resolve) => {
|
||||
var key = asmcrypto.PBKDF2_HMAC_SHA256.bytes(passBuffer, saltBuffer, 10000)
|
||||
const key = asmcrypto.PBKDF2_HMAC_SHA256.bytes(passBuffer, saltBuffer, 10000)
|
||||
resolve(key)
|
||||
})
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ class EdgeEncryptor {
|
|||
* @returns {string} Randomized base64 encoded data
|
||||
*/
|
||||
_generateSalt (byteCount = 32) {
|
||||
var view = new Uint8Array(byteCount)
|
||||
const view = new Uint8Array(byteCount)
|
||||
global.crypto.getRandomValues(view)
|
||||
var b64encoded = btoa(String.fromCharCode.apply(null, view))
|
||||
const b64encoded = btoa(String.fromCharCode.apply(null, view))
|
||||
return b64encoded
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ function initializePopup ({ container, connectionStream }, cb) {
|
|||
function connectToAccountManager (connectionStream, cb) {
|
||||
// setup communication with background
|
||||
// setup multiplexing
|
||||
var mx = setupMultiplex(connectionStream)
|
||||
const mx = setupMultiplex(connectionStream)
|
||||
// connect features
|
||||
setupControllerConnection(mx.createStream('controller'), cb)
|
||||
setupWeb3Connection(mx.createStream('provider'))
|
||||
|
@ -44,7 +44,7 @@ function connectToAccountManager (connectionStream, cb) {
|
|||
* @param {PortDuplexStream} connectionStream PortStream instance establishing a background connection
|
||||
*/
|
||||
function setupWeb3Connection (connectionStream) {
|
||||
var providerStream = new StreamProvider()
|
||||
const providerStream = new StreamProvider()
|
||||
providerStream.pipe(connectionStream).pipe(providerStream)
|
||||
connectionStream.on('error', console.error.bind(console))
|
||||
providerStream.on('error', console.error.bind(console))
|
||||
|
@ -62,8 +62,8 @@ function setupWeb3Connection (connectionStream) {
|
|||
function setupControllerConnection (connectionStream, cb) {
|
||||
// this is a really sneaky way of adding EventEmitter api
|
||||
// to a bi-directional dnode instance
|
||||
var eventEmitter = new EventEmitter()
|
||||
var accountManagerDnode = Dnode({
|
||||
const eventEmitter = new EventEmitter()
|
||||
const accountManagerDnode = Dnode({
|
||||
sendUpdate: function (state) {
|
||||
eventEmitter.emit('update', state)
|
||||
},
|
||||
|
|
|
@ -42,7 +42,7 @@ const {
|
|||
// customDPaths,
|
||||
} = require('../../app/scripts/controllers/network/enums')
|
||||
|
||||
var valueTable = {
|
||||
const valueTable = {
|
||||
wei: '1000000000000000000',
|
||||
kwei: '1000000000000000',
|
||||
mwei: '1000000000000',
|
||||
|
@ -55,8 +55,8 @@ var valueTable = {
|
|||
gether: '0.000000001',
|
||||
tether: '0.000000000001',
|
||||
}
|
||||
var bnTable = {}
|
||||
for (var currency in valueTable) {
|
||||
const bnTable = {}
|
||||
for (const currency in valueTable) {
|
||||
bnTable[currency] = new ethUtil.BN(valueTable[currency], 10)
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ function accountSummary (acc, firstSegLength = 6, lastSegLength = 4) {
|
|||
}
|
||||
|
||||
function isValidAddress (address, network) {
|
||||
var prefixed = ethUtil.addHexPrefix(address)
|
||||
const prefixed = ethUtil.addHexPrefix(address)
|
||||
if (ifRSK(network)) {
|
||||
if (address === '0x0000000000000000000000000000000000000000') return false
|
||||
return (ethUtil.isValidAddress(prefixed))
|
||||
|
@ -139,33 +139,33 @@ function isValidENSAddress (address) {
|
|||
}
|
||||
|
||||
function isInvalidChecksumAddress (address, network) {
|
||||
var prefixed = ethUtil.addHexPrefix(address)
|
||||
const prefixed = ethUtil.addHexPrefix(address)
|
||||
if (address === '0x0000000000000000000000000000000000000000') return false
|
||||
return !isAllOneCase(prefixed) && !isValidChecksumAddress(network, prefixed)
|
||||
}
|
||||
|
||||
function isAllOneCase (address) {
|
||||
if (!address) return true
|
||||
var lower = address.toLowerCase()
|
||||
var upper = address.toUpperCase()
|
||||
const lower = address.toLowerCase()
|
||||
const upper = address.toUpperCase()
|
||||
return address === lower || address === upper
|
||||
}
|
||||
|
||||
// Takes wei Hex, returns wei BN, even if input is null
|
||||
function numericBalance (balance) {
|
||||
if (!balance) return new ethUtil.BN(0, 16)
|
||||
var stripped = ethUtil.stripHexPrefix(balance)
|
||||
const stripped = ethUtil.stripHexPrefix(balance)
|
||||
return new ethUtil.BN(stripped, 16)
|
||||
}
|
||||
|
||||
// Takes hex, returns [beforeDecimal, afterDecimal]
|
||||
function parseBalance (balance) {
|
||||
var beforeDecimal, afterDecimal
|
||||
let afterDecimal
|
||||
const wei = numericBalance(balance)
|
||||
var weiString = wei.toString()
|
||||
const weiString = wei.toString()
|
||||
const trailingZeros = /0+$/
|
||||
|
||||
beforeDecimal = weiString.length > 18 ? weiString.slice(0, weiString.length - 18) : '0'
|
||||
const beforeDecimal = weiString.length > 18 ? weiString.slice(0, weiString.length - 18) : '0'
|
||||
afterDecimal = ('000000000000000000' + wei).slice(-18).replace(trailingZeros, '')
|
||||
if (afterDecimal === '') { afterDecimal = '0' }
|
||||
return [beforeDecimal, afterDecimal]
|
||||
|
@ -176,14 +176,14 @@ function parseBalance (balance) {
|
|||
function formatBalance (balance, decimalsToKeep, needsParse = true, network, isToken, tokenSymbol) {
|
||||
const coinName = ethNetProps.props.getNetworkCoinName(network)
|
||||
const assetName = isToken ? tokenSymbol : coinName
|
||||
var parsed = needsParse ? parseBalance(balance) : balance.split('.')
|
||||
var beforeDecimal = parsed[0]
|
||||
var afterDecimal = parsed[1]
|
||||
var formatted = '0'
|
||||
const parsed = needsParse ? parseBalance(balance) : balance.split('.')
|
||||
const beforeDecimal = parsed[0]
|
||||
let afterDecimal = parsed[1]
|
||||
let formatted = '0'
|
||||
if (decimalsToKeep === undefined) {
|
||||
if (beforeDecimal === '0') {
|
||||
if (afterDecimal !== '0') {
|
||||
var sigFigs = afterDecimal.match(/^0*(.{2})/) // default: grabs 2 most significant digits
|
||||
const sigFigs = afterDecimal.match(/^0*(.{2})/) // default: grabs 2 most significant digits
|
||||
if (sigFigs) { afterDecimal = sigFigs[0] }
|
||||
formatted = '0.' + afterDecimal + ` ${assetName}`
|
||||
}
|
||||
|
@ -199,11 +199,11 @@ function formatBalance (balance, decimalsToKeep, needsParse = true, network, isT
|
|||
|
||||
|
||||
function generateBalanceObject (formattedBalance, decimalsToKeep = 1) {
|
||||
var balance = formattedBalance.split(' ')[0]
|
||||
var label = formattedBalance.split(' ')[1]
|
||||
var beforeDecimal = balance.split('.')[0]
|
||||
var afterDecimal = balance.split('.')[1]
|
||||
var shortBalance = shortenBalance(balance, decimalsToKeep)
|
||||
let balance = formattedBalance.split(' ')[0]
|
||||
const label = formattedBalance.split(' ')[1]
|
||||
const beforeDecimal = balance.split('.')[0]
|
||||
const afterDecimal = balance.split('.')[1]
|
||||
const shortBalance = shortenBalance(balance, decimalsToKeep)
|
||||
|
||||
if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') {
|
||||
// eslint-disable-next-line eqeqeq
|
||||
|
@ -220,8 +220,8 @@ function generateBalanceObject (formattedBalance, decimalsToKeep = 1) {
|
|||
}
|
||||
|
||||
function shortenBalance (balance, decimalsToKeep = 1) {
|
||||
var truncatedValue
|
||||
var convertedBalance = parseFloat(balance)
|
||||
let truncatedValue
|
||||
const convertedBalance = parseFloat(balance)
|
||||
if (convertedBalance > 1000000) {
|
||||
truncatedValue = (balance / 1000000).toFixed(decimalsToKeep)
|
||||
return `${truncatedValue}m`
|
||||
|
@ -233,7 +233,7 @@ function shortenBalance (balance, decimalsToKeep = 1) {
|
|||
} else if (convertedBalance < 0.001) {
|
||||
return '<0.001'
|
||||
} else if (convertedBalance < 1) {
|
||||
var stringBalance = convertedBalance.toString()
|
||||
const stringBalance = convertedBalance.toString()
|
||||
if (stringBalance.split('.')[1].length > 3) {
|
||||
return convertedBalance.toFixed(3)
|
||||
} else {
|
||||
|
@ -245,7 +245,7 @@ function shortenBalance (balance, decimalsToKeep = 1) {
|
|||
}
|
||||
|
||||
function dataSize (data) {
|
||||
var size = data ? ethUtil.stripHexPrefix(data).length : 0
|
||||
const size = data ? ethUtil.stripHexPrefix(data).length : 0
|
||||
return size + ' bytes'
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ function normalizeEthStringToWei (str) {
|
|||
const parts = str.split('.')
|
||||
let eth = new ethUtil.BN(parts[0], 10).mul(bnTable.wei)
|
||||
if (parts[1]) {
|
||||
var decimal = parts[1]
|
||||
let decimal = parts[1]
|
||||
while (decimal.length < 18) {
|
||||
decimal += '0'
|
||||
}
|
||||
|
@ -275,24 +275,24 @@ function normalizeEthStringToWei (str) {
|
|||
return eth
|
||||
}
|
||||
|
||||
var multiple = new ethUtil.BN('10000', 10)
|
||||
const multiple = new ethUtil.BN('10000', 10)
|
||||
function normalizeNumberToWei (n, currency) {
|
||||
var enlarged = n * 10000
|
||||
var amount = new ethUtil.BN(String(enlarged), 10)
|
||||
const enlarged = n * 10000
|
||||
const amount = new ethUtil.BN(String(enlarged), 10)
|
||||
return normalizeToWei(amount, currency).div(multiple)
|
||||
}
|
||||
|
||||
function readableDate (ms) {
|
||||
var date = new Date(ms)
|
||||
var month = date.getMonth()
|
||||
var day = date.getDate()
|
||||
var year = date.getFullYear()
|
||||
var hours = date.getHours()
|
||||
var minutes = '0' + date.getMinutes()
|
||||
var seconds = '0' + date.getSeconds()
|
||||
const date = new Date(ms)
|
||||
const month = date.getMonth()
|
||||
const day = date.getDate()
|
||||
const year = date.getFullYear()
|
||||
const hours = date.getHours()
|
||||
const minutes = '0' + date.getMinutes()
|
||||
const seconds = '0' + date.getSeconds()
|
||||
|
||||
var dateStr = `${month}/${day}/${year}`
|
||||
var time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`
|
||||
const dateStr = `${month}/${day}/${year}`
|
||||
const time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`
|
||||
return `${dateStr} ${time}`
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ const EventEmitter = require('events').EventEmitter
|
|||
|
||||
// account management
|
||||
|
||||
var identities = {
|
||||
const identities = {
|
||||
'0x1113462427bcc9133bb46e88bcbe39cd7ef0e111': {
|
||||
name: 'Walrus',
|
||||
img: 'QmW6hcwYzXrNkuHrpvo58YeZvbZxUddv69ATSHY3BHpPdd',
|
||||
|
@ -29,7 +29,7 @@ var identities = {
|
|||
},
|
||||
}
|
||||
|
||||
var unapprovedTxs = {}
|
||||
const unapprovedTxs = {}
|
||||
addUnconfTx({
|
||||
from: '0x222462427bcc9133bb46e88bcbe39cd7ef0e7222',
|
||||
to: '0x1113462427bcc9133bb46e88bcbe39cd7ef0e111',
|
||||
|
@ -43,8 +43,8 @@ addUnconfTx({
|
|||
})
|
||||
|
||||
function addUnconfTx (txParams) {
|
||||
var time = (new Date()).getTime()
|
||||
var id = createRandomId()
|
||||
const time = (new Date()).getTime()
|
||||
const id = createRandomId()
|
||||
unapprovedTxs[id] = {
|
||||
id: id,
|
||||
txParams: txParams,
|
||||
|
@ -52,8 +52,8 @@ function addUnconfTx (txParams) {
|
|||
}
|
||||
}
|
||||
|
||||
var isUnlocked = false
|
||||
var selectedAccount = null
|
||||
let isUnlocked = false
|
||||
let selectedAccount = null
|
||||
|
||||
function getState () {
|
||||
return {
|
||||
|
@ -64,7 +64,7 @@ function getState () {
|
|||
}
|
||||
}
|
||||
|
||||
var accountManager = new EventEmitter()
|
||||
const accountManager = new EventEmitter()
|
||||
|
||||
accountManager.getState = function (cb) {
|
||||
cb(null, getState())
|
||||
|
@ -101,9 +101,9 @@ accountManager._didUpdate = function () {
|
|||
|
||||
// start app
|
||||
|
||||
var container = document.getElementById('app-content')
|
||||
const container = document.getElementById('app-content')
|
||||
|
||||
var css = MetaMaskUiCss()
|
||||
const css = MetaMaskUiCss()
|
||||
injectCss(css)
|
||||
|
||||
MetaMaskUi({
|
||||
|
@ -115,9 +115,9 @@ MetaMaskUi({
|
|||
|
||||
function createRandomId () {
|
||||
// 13 time digits
|
||||
var datePart = new Date().getTime() * Math.pow(10, 3)
|
||||
const datePart = new Date().getTime() * Math.pow(10, 3)
|
||||
// 3 random digits
|
||||
var extraPart = Math.floor(Math.random() * Math.pow(10, 3))
|
||||
const extraPart = Math.floor(Math.random() * Math.pow(10, 3))
|
||||
// 16 digits
|
||||
return datePart + extraPart
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ server.listen(8545, () => {
|
|||
})
|
||||
|
||||
// logging util
|
||||
var log = require('loglevel')
|
||||
const log = require('loglevel')
|
||||
log.setDefaultLevel(5)
|
||||
global.log = log
|
||||
|
||||
|
@ -57,7 +57,7 @@ function enableFailureOnUnhandledPromiseRejection () {
|
|||
throw evt.detail.reason
|
||||
})
|
||||
} else {
|
||||
var oldOHR = window.onunhandledrejection
|
||||
const oldOHR = window.onunhandledrejection
|
||||
window.onunhandledrejection = function (evt) {
|
||||
if (typeof oldOHR === 'function') oldOHR.apply(this, arguments)
|
||||
throw evt.detail.reason
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var mockHex = '0xabcdef0123456789'
|
||||
var mockKey = Buffer.alloc(32)
|
||||
const mockHex = '0xabcdef0123456789'
|
||||
const mockKey = Buffer.alloc(32)
|
||||
let cacheVal
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var fakeWallet = {
|
||||
const fakeWallet = {
|
||||
privKey: '0x123456788890abcdef',
|
||||
address: '0xfedcba0987654321',
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ module.exports = class MockSimpleKeychain {
|
|||
}
|
||||
|
||||
addAccounts (n = 1) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
for (let i = 0; i < n; i++) {
|
||||
this.wallets.push(fakeWallet)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ const { POA,
|
|||
const { hasUnconfirmedTransactions } = require('./helpers/confirm-transaction/util')
|
||||
const WebcamUtils = require('../lib/webcam-utils')
|
||||
|
||||
var actions = {
|
||||
const actions = {
|
||||
_setBackgroundConnection: _setBackgroundConnection,
|
||||
|
||||
GO_HOME: 'GO_HOME',
|
||||
|
@ -374,7 +374,7 @@ var actions = {
|
|||
|
||||
module.exports = actions
|
||||
|
||||
var background = null
|
||||
let background = null
|
||||
function _setBackgroundConnection (backgroundConnection) {
|
||||
background = backgroundConnection
|
||||
}
|
||||
|
@ -2237,7 +2237,7 @@ function requestExportAccount () {
|
|||
}
|
||||
|
||||
function exportAccount (password, address, dPath) {
|
||||
var self = this
|
||||
const self = this
|
||||
|
||||
return function (dispatch) {
|
||||
dispatch(self.showLoadingIndication())
|
||||
|
@ -2383,7 +2383,7 @@ function pairUpdate (coin) {
|
|||
}
|
||||
|
||||
function shapeShiftSubview (network) {
|
||||
var pair = 'btc_eth'
|
||||
const pair = 'btc_eth'
|
||||
return (dispatch) => {
|
||||
dispatch(actions.showSubLoadingIndication())
|
||||
shapeShiftRequest('marketinfo', {pair}, (mktResponse) => {
|
||||
|
@ -2408,7 +2408,7 @@ function coinShiftRquest (data, marketData) {
|
|||
shapeShiftRequest('shift', { method: 'POST', data}, (response) => {
|
||||
dispatch(actions.hideLoadingIndication())
|
||||
if (response.error) return dispatch(actions.displayWarning(response.error))
|
||||
var message = `
|
||||
const message = `
|
||||
Deposit your ${response.depositType} to the address below:`
|
||||
log.debug(`background.createShapeShiftTx`)
|
||||
background.createShapeShiftTx(response.deposit, response.depositType)
|
||||
|
@ -2444,7 +2444,7 @@ function reshowQrCode (data, coin) {
|
|||
shapeShiftRequest('marketinfo', {pair: `${coin.toLowerCase()}_eth`}, (mktResponse) => {
|
||||
if (mktResponse.error) return dispatch(actions.displayWarning(mktResponse.error))
|
||||
|
||||
var message = [
|
||||
const message = [
|
||||
`Deposit your ${coin} to the address below:`,
|
||||
`Deposit Limit: ${mktResponse.limit}`,
|
||||
`Deposit Minimum:${mktResponse.minimum}`,
|
||||
|
@ -2461,11 +2461,11 @@ function reshowQrCode (data, coin) {
|
|||
}
|
||||
|
||||
function shapeShiftRequest (query, options, cb) {
|
||||
var queryResponse, method
|
||||
let queryResponse, method
|
||||
!options ? options = {} : null
|
||||
options.method ? method = options.method : method = 'GET'
|
||||
|
||||
var requestListner = function (request) {
|
||||
const requestListner = function (request) {
|
||||
try {
|
||||
queryResponse = JSON.parse(this.responseText)
|
||||
cb ? cb(queryResponse) : null
|
||||
|
@ -2476,12 +2476,12 @@ function shapeShiftRequest (query, options, cb) {
|
|||
}
|
||||
}
|
||||
|
||||
var shapShiftReq = new XMLHttpRequest()
|
||||
const shapShiftReq = new XMLHttpRequest()
|
||||
shapShiftReq.addEventListener('load', requestListner)
|
||||
shapShiftReq.open(method, `https://shapeshift.io/${query}/${options.pair ? options.pair : ''}`, true)
|
||||
|
||||
if (options.method === 'POST') {
|
||||
var jsonObj = JSON.stringify(options.data)
|
||||
const jsonObj = JSON.stringify(options.data)
|
||||
shapShiftReq.setRequestHeader('Content-Type', 'application/json')
|
||||
return shapShiftReq.send(jsonObj)
|
||||
} else {
|
||||
|
|
|
@ -25,9 +25,9 @@ function mapStateToProps (state) {
|
|||
}
|
||||
|
||||
IdenticonComponent.prototype.render = function () {
|
||||
var props = this.props
|
||||
const props = this.props
|
||||
const { className = '', address, image } = props
|
||||
var diameter = props.diameter || this.defaultDiameter
|
||||
const diameter = props.diameter || this.defaultDiameter
|
||||
const style = {
|
||||
height: diameter,
|
||||
width: diameter,
|
||||
|
@ -66,14 +66,14 @@ IdenticonComponent.prototype.render = function () {
|
|||
}
|
||||
|
||||
IdenticonComponent.prototype.componentDidMount = function () {
|
||||
var props = this.props
|
||||
const props = this.props
|
||||
const { address, useBlockie } = props
|
||||
|
||||
if (!address) return
|
||||
|
||||
if (!isNode) {
|
||||
// eslint-disable-next-line react/no-find-dom-node
|
||||
var container = findDOMNode(this)
|
||||
const container = findDOMNode(this)
|
||||
|
||||
const diameter = props.diameter || this.defaultDiameter
|
||||
|
||||
|
@ -86,17 +86,17 @@ IdenticonComponent.prototype.componentDidMount = function () {
|
|||
}
|
||||
|
||||
IdenticonComponent.prototype.componentDidUpdate = function () {
|
||||
var props = this.props
|
||||
const props = this.props
|
||||
const { address, useBlockie } = props
|
||||
|
||||
if (!address) return
|
||||
|
||||
if (!isNode) {
|
||||
// eslint-disable-next-line react/no-find-dom-node
|
||||
var container = findDOMNode(this)
|
||||
const container = findDOMNode(this)
|
||||
|
||||
var children = container.children
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
const children = container.children
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
container.removeChild(children[i])
|
||||
}
|
||||
|
||||
|
|
|
@ -22,21 +22,21 @@ function reduceApp (state, action) {
|
|||
name = 'confTx'
|
||||
}
|
||||
|
||||
var defaultView = {
|
||||
const defaultView = {
|
||||
name,
|
||||
detailView: null,
|
||||
context: selectedAddress,
|
||||
}
|
||||
|
||||
// confirm seed words
|
||||
var seedWords = state.metamask.seedWords
|
||||
var seedConfView = {
|
||||
const seedWords = state.metamask.seedWords
|
||||
const seedConfView = {
|
||||
name: 'createVaultComplete',
|
||||
seedWords,
|
||||
}
|
||||
|
||||
// default state
|
||||
var appState = extend({
|
||||
const appState = extend({
|
||||
shouldClose: false,
|
||||
menuOpen: false,
|
||||
modal: {
|
||||
|
|
|
@ -12,7 +12,7 @@ function formatDate (date) {
|
|||
return vreme.format(new Date(date), '3/16/2014 at 14:30')
|
||||
}
|
||||
|
||||
var valueTable = {
|
||||
const valueTable = {
|
||||
wei: '1000000000000000000',
|
||||
kwei: '1000000000000000',
|
||||
mwei: '1000000000000',
|
||||
|
@ -25,8 +25,8 @@ var valueTable = {
|
|||
gether: '0.000000001',
|
||||
tether: '0.000000000001',
|
||||
}
|
||||
var bnTable = {}
|
||||
for (var currency in valueTable) {
|
||||
const bnTable = {}
|
||||
for (const currency in valueTable) {
|
||||
bnTable[currency] = new ethUtil.BN(valueTable[currency], 10)
|
||||
}
|
||||
|
||||
|
@ -79,12 +79,12 @@ function addressSummary (address, firstSegLength = 10, lastSegLength = 4, includ
|
|||
|
||||
function miniAddressSummary (address) {
|
||||
if (!address) return ''
|
||||
var checked = checksumAddress(address)
|
||||
const checked = checksumAddress(address)
|
||||
return checked ? checked.slice(0, 4) + '...' + checked.slice(-4) : '...'
|
||||
}
|
||||
|
||||
function isValidAddress (address) {
|
||||
var prefixed = ethUtil.addHexPrefix(address)
|
||||
const prefixed = ethUtil.addHexPrefix(address)
|
||||
if (address === '0x0000000000000000000000000000000000000000') return false
|
||||
return (isAllOneCase(prefixed) && ethUtil.isValidAddress(prefixed)) || ethUtil.isValidChecksumAddress(prefixed)
|
||||
}
|
||||
|
@ -94,33 +94,33 @@ function isValidENSAddress (address) {
|
|||
}
|
||||
|
||||
function isInvalidChecksumAddress (address) {
|
||||
var prefixed = ethUtil.addHexPrefix(address)
|
||||
const 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()
|
||||
var upper = address.toUpperCase()
|
||||
const lower = address.toLowerCase()
|
||||
const upper = address.toUpperCase()
|
||||
return address === lower || address === upper
|
||||
}
|
||||
|
||||
// Takes wei Hex, returns wei BN, even if input is null
|
||||
function numericBalance (balance) {
|
||||
if (!balance) return new ethUtil.BN(0, 16)
|
||||
var stripped = ethUtil.stripHexPrefix(balance)
|
||||
const stripped = ethUtil.stripHexPrefix(balance)
|
||||
return new ethUtil.BN(stripped, 16)
|
||||
}
|
||||
|
||||
// Takes hex, returns [beforeDecimal, afterDecimal]
|
||||
function parseBalance (balance) {
|
||||
var beforeDecimal, afterDecimal
|
||||
let afterDecimal
|
||||
const wei = numericBalance(balance)
|
||||
var weiString = wei.toString()
|
||||
const weiString = wei.toString()
|
||||
const trailingZeros = /0+$/
|
||||
|
||||
beforeDecimal = weiString.length > 18 ? weiString.slice(0, weiString.length - 18) : '0'
|
||||
const beforeDecimal = weiString.length > 18 ? weiString.slice(0, weiString.length - 18) : '0'
|
||||
afterDecimal = ('000000000000000000' + wei).slice(-18).replace(trailingZeros, '')
|
||||
if (afterDecimal === '') { afterDecimal = '0' }
|
||||
return [beforeDecimal, afterDecimal]
|
||||
|
@ -129,14 +129,14 @@ function parseBalance (balance) {
|
|||
// Takes wei hex, returns an object with three properties.
|
||||
// Its "formatted" property is what we generally use to render values.
|
||||
function formatBalance (balance, decimalsToKeep, needsParse = true) {
|
||||
var parsed = needsParse ? parseBalance(balance) : balance.split('.')
|
||||
var beforeDecimal = parsed[0]
|
||||
var afterDecimal = parsed[1]
|
||||
var formatted = 'None'
|
||||
const parsed = needsParse ? parseBalance(balance) : balance.split('.')
|
||||
const beforeDecimal = parsed[0]
|
||||
let afterDecimal = parsed[1]
|
||||
let formatted = 'None'
|
||||
if (decimalsToKeep === undefined) {
|
||||
if (beforeDecimal === '0') {
|
||||
if (afterDecimal !== '0') {
|
||||
var sigFigs = afterDecimal.match(/^0*(.{2})/) // default: grabs 2 most significant digits
|
||||
const sigFigs = afterDecimal.match(/^0*(.{2})/) // default: grabs 2 most significant digits
|
||||
if (sigFigs) { afterDecimal = sigFigs[0] }
|
||||
formatted = '0.' + afterDecimal + ' ETH'
|
||||
}
|
||||
|
@ -152,11 +152,11 @@ function formatBalance (balance, decimalsToKeep, needsParse = true) {
|
|||
|
||||
|
||||
function generateBalanceObject (formattedBalance, decimalsToKeep = 1) {
|
||||
var balance = formattedBalance.split(' ')[0]
|
||||
var label = formattedBalance.split(' ')[1]
|
||||
var beforeDecimal = balance.split('.')[0]
|
||||
var afterDecimal = balance.split('.')[1]
|
||||
var shortBalance = shortenBalance(balance, decimalsToKeep)
|
||||
let balance = formattedBalance.split(' ')[0]
|
||||
const label = formattedBalance.split(' ')[1]
|
||||
const beforeDecimal = balance.split('.')[0]
|
||||
const afterDecimal = balance.split('.')[1]
|
||||
const shortBalance = shortenBalance(balance, decimalsToKeep)
|
||||
|
||||
if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') {
|
||||
// eslint-disable-next-line eqeqeq
|
||||
|
@ -173,8 +173,8 @@ function generateBalanceObject (formattedBalance, decimalsToKeep = 1) {
|
|||
}
|
||||
|
||||
function shortenBalance (balance, decimalsToKeep = 1) {
|
||||
var truncatedValue
|
||||
var convertedBalance = parseFloat(balance)
|
||||
let truncatedValue
|
||||
const convertedBalance = parseFloat(balance)
|
||||
if (convertedBalance > 1000000) {
|
||||
truncatedValue = (balance / 1000000).toFixed(decimalsToKeep)
|
||||
return `${truncatedValue}m`
|
||||
|
@ -186,7 +186,7 @@ function shortenBalance (balance, decimalsToKeep = 1) {
|
|||
} else if (convertedBalance < 0.001) {
|
||||
return '<0.001'
|
||||
} else if (convertedBalance < 1) {
|
||||
var stringBalance = convertedBalance.toString()
|
||||
const stringBalance = convertedBalance.toString()
|
||||
if (stringBalance.split('.')[1].length > 3) {
|
||||
return convertedBalance.toFixed(3)
|
||||
} else {
|
||||
|
@ -198,7 +198,7 @@ function shortenBalance (balance, decimalsToKeep = 1) {
|
|||
}
|
||||
|
||||
function dataSize (data) {
|
||||
var size = data ? ethUtil.stripHexPrefix(data).length : 0
|
||||
const size = data ? ethUtil.stripHexPrefix(data).length : 0
|
||||
return size + ' bytes'
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ function normalizeEthStringToWei (str) {
|
|||
const parts = str.split('.')
|
||||
let eth = new ethUtil.BN(parts[0], 10).mul(bnTable.wei)
|
||||
if (parts[1]) {
|
||||
var decimal = parts[1]
|
||||
let decimal = parts[1]
|
||||
while (decimal.length < 18) {
|
||||
decimal += '0'
|
||||
}
|
||||
|
@ -228,24 +228,24 @@ function normalizeEthStringToWei (str) {
|
|||
return eth
|
||||
}
|
||||
|
||||
var multiple = new ethUtil.BN('10000', 10)
|
||||
const multiple = new ethUtil.BN('10000', 10)
|
||||
function normalizeNumberToWei (n, currency) {
|
||||
var enlarged = n * 10000
|
||||
var amount = new ethUtil.BN(String(enlarged), 10)
|
||||
const enlarged = n * 10000
|
||||
const amount = new ethUtil.BN(String(enlarged), 10)
|
||||
return normalizeToWei(amount, currency).div(multiple)
|
||||
}
|
||||
|
||||
function readableDate (ms) {
|
||||
var date = new Date(ms)
|
||||
var month = date.getMonth()
|
||||
var day = date.getDate()
|
||||
var year = date.getFullYear()
|
||||
var hours = date.getHours()
|
||||
var minutes = '0' + date.getMinutes()
|
||||
var seconds = '0' + date.getSeconds()
|
||||
const date = new Date(ms)
|
||||
const month = date.getMonth()
|
||||
const day = date.getDate()
|
||||
const year = date.getFullYear()
|
||||
const hours = date.getHours()
|
||||
const minutes = '0' + date.getMinutes()
|
||||
const seconds = '0' + date.getSeconds()
|
||||
|
||||
var dateStr = `${month}/${day}/${year}`
|
||||
var time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`
|
||||
const dateStr = `${month}/${day}/${year}`
|
||||
const time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`
|
||||
return `${dateStr} ${time}`
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
// helper functions for that ctx
|
||||
function write(buffer, offs) {
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
for (var j = 0; j < arguments[i].length; j++) {
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
for (let j = 0; j < arguments[i].length; j++) {
|
||||
buffer[offs++] = arguments[i].charAt(j);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@
|
|||
return String.fromCharCode(w & 255, (w >> 8) & 255);
|
||||
}
|
||||
|
||||
var PNG = function(width,height,depth) {
|
||||
const PNG = function(width,height,depth) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
@ -66,10 +66,10 @@
|
|||
this.palette = new Object();
|
||||
this.pindex = 0;
|
||||
|
||||
var _crc32 = new Array();
|
||||
const _crc32 = new Array();
|
||||
|
||||
// initialize buffer with zero bytes
|
||||
for (var i = 0; i < this.buffer_size; i++) {
|
||||
for (let i = 0; i < this.buffer_size; i++) {
|
||||
this.buffer[i] = "\x00";
|
||||
}
|
||||
|
||||
|
@ -81,14 +81,14 @@
|
|||
write(this.buffer, this.iend_offs, byte4(this.iend_size - 12), 'IEND');
|
||||
|
||||
// initialize deflate header
|
||||
var header = ((8 + (7 << 4)) << 8) | (3 << 6);
|
||||
const header = ((8 + (7 << 4)) << 8) | (3 << 6);
|
||||
header+= 31 - (header % 31);
|
||||
|
||||
write(this.buffer, this.idat_offs + 8, byte2(header));
|
||||
|
||||
// initialize deflate block headers
|
||||
for (var i = 0; (i << 16) - 1 < this.pix_size; i++) {
|
||||
var size, bits;
|
||||
for (let i = 0; (i << 16) - 1 < this.pix_size; i++) {
|
||||
const size, bits;
|
||||
if (i + 0xffff < this.pix_size) {
|
||||
size = 0xffff;
|
||||
bits = "\x00";
|
||||
|
@ -100,9 +100,9 @@
|
|||
}
|
||||
|
||||
/* Create crc32 lookup table */
|
||||
for (var i = 0; i < 256; i++) {
|
||||
var c = i;
|
||||
for (var j = 0; j < 8; j++) {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const c = i;
|
||||
for (let j = 0; j < 8; j++) {
|
||||
if (c & 1) {
|
||||
c = -306674912 ^ ((c >> 1) & 0x7fffffff);
|
||||
} else {
|
||||
|
@ -114,8 +114,8 @@
|
|||
|
||||
// compute the index into a png for a given pixel
|
||||
this.index = function(x,y) {
|
||||
var i = y * (this.width + 1) + x + 1;
|
||||
var j = this.idat_offs + 8 + 2 + 5 * Math.floor((i / 0xffff) + 1) + i;
|
||||
const i = y * (this.width + 1) + x + 1;
|
||||
const j = this.idat_offs + 8 + 2 + 5 * Math.floor((i / 0xffff) + 1) + i;
|
||||
return j;
|
||||
};
|
||||
|
||||
|
@ -123,12 +123,12 @@
|
|||
this.color = function(red, green, blue, alpha) {
|
||||
|
||||
alpha = alpha >= 0 ? alpha : 255;
|
||||
var color = (((((alpha << 8) | red) << 8) | green) << 8) | blue;
|
||||
const color = (((((alpha << 8) | red) << 8) | green) << 8) | blue;
|
||||
|
||||
if (typeof this.palette[color] == "undefined") {
|
||||
if (this.pindex == this.depth) return "\x00";
|
||||
|
||||
var ndx = this.plte_offs + 8 + 3 * this.pindex;
|
||||
const ndx = this.plte_offs + 8 + 3 * this.pindex;
|
||||
|
||||
this.buffer[ndx + 0] = String.fromCharCode(red);
|
||||
this.buffer[ndx + 1] = String.fromCharCode(green);
|
||||
|
@ -143,13 +143,13 @@
|
|||
// output a PNG string, Base64 encoded
|
||||
this.getBase64 = function() {
|
||||
|
||||
var s = this.getDump();
|
||||
const s = this.getDump();
|
||||
|
||||
var ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var c1, c2, c3, e1, e2, e3, e4;
|
||||
var l = s.length;
|
||||
var i = 0;
|
||||
var r = "";
|
||||
const ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
const c1, c2, c3, e1, e2, e3, e4;
|
||||
const l = s.length;
|
||||
const i = 0;
|
||||
const r = "";
|
||||
|
||||
do {
|
||||
c1 = s.charCodeAt(i);
|
||||
|
@ -168,14 +168,14 @@
|
|||
this.getDump = function() {
|
||||
|
||||
// compute adler32 of output pixels + row filter bytes
|
||||
var BASE = 65521; /* largest prime smaller than 65536 */
|
||||
var NMAX = 5552; /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
var s1 = 1;
|
||||
var s2 = 0;
|
||||
var n = NMAX;
|
||||
const BASE = 65521; /* largest prime smaller than 65536 */
|
||||
const NMAX = 5552; /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
const s1 = 1;
|
||||
const s2 = 0;
|
||||
const n = NMAX;
|
||||
|
||||
for (var y = 0; y < this.height; y++) {
|
||||
for (var x = -1; x < this.width; x++) {
|
||||
for (let y = 0; y < this.height; y++) {
|
||||
for (let x = -1; x < this.width; x++) {
|
||||
s1+= this.buffer[this.index(x, y)].charCodeAt(0);
|
||||
s2+= s1;
|
||||
if ((n-= 1) == 0) {
|
||||
|
@ -191,8 +191,8 @@
|
|||
|
||||
// compute crc32 of the PNG chunks
|
||||
function crc32(png, offs, size) {
|
||||
var crc = -1;
|
||||
for (var i = 4; i < size-4; i += 1) {
|
||||
const crc = -1;
|
||||
for (let i = 4; i < size-4; i += 1) {
|
||||
crc = _crc32[(crc ^ png[offs+i].charCodeAt(0)) & 0xff] ^ ((crc >> 8) & 0x00ffffff);
|
||||
}
|
||||
write(png, offs+size-4, byte4(crc ^ -1));
|
||||
|
@ -209,8 +209,8 @@
|
|||
};
|
||||
|
||||
this.fillRect = function (x, y, w, h, color) {
|
||||
for(var i = 0; i < w; i++) {
|
||||
for (var j = 0; j < h; j++) {
|
||||
for(let i = 0; i < w; i++) {
|
||||
for (let j = 0; j < h; j++) {
|
||||
this.buffer[this.index(x+i, y+j)] = color;
|
||||
}
|
||||
}
|
||||
|
@ -240,13 +240,13 @@
|
|||
}
|
||||
|
||||
function hsl2rgb(h, s, l){
|
||||
var r, g, b;
|
||||
let r, g, b;
|
||||
|
||||
if(s == 0){
|
||||
r = g = b = l; // achromatic
|
||||
}else{
|
||||
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||
var p = 2 * l - q;
|
||||
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||
const p = 2 * l - q;
|
||||
r = hue2rgb(p, q, h + 1/3);
|
||||
g = hue2rgb(p, q, h);
|
||||
b = hue2rgb(p, q, h - 1/3);
|
||||
|
@ -256,20 +256,20 @@
|
|||
}
|
||||
|
||||
// The random number is a js implementation of the Xorshift PRNG
|
||||
var randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
|
||||
const randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
|
||||
|
||||
function seedrand(seed) {
|
||||
for (var i = 0; i < randseed.length; i++) {
|
||||
for (let i = 0; i < randseed.length; i++) {
|
||||
randseed[i] = 0;
|
||||
}
|
||||
for (var i = 0; i < seed.length; i++) {
|
||||
for (let i = 0; i < seed.length; i++) {
|
||||
randseed[i % 4] = (randseed[i % 4] << 5) - randseed[i % 4] + seed.charCodeAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
function rand() {
|
||||
// based on Java's String.hashCode(), expanded to 4 32bit values
|
||||
var t = randseed[0] ^ (randseed[0] << 11);
|
||||
const t = randseed[0] ^ (randseed[0] << 11);
|
||||
|
||||
randseed[0] = randseed[1];
|
||||
randseed[1] = randseed[2];
|
||||
|
@ -281,35 +281,35 @@
|
|||
|
||||
function createColor() {
|
||||
//saturation is the whole color spectrum
|
||||
var h = Math.floor(rand() * 360);
|
||||
const h = Math.floor(rand() * 360);
|
||||
//saturation goes from 40 to 100, it avoids greyish colors
|
||||
var s = rand() * 60 + 40;
|
||||
const s = rand() * 60 + 40;
|
||||
//lightness can be anything from 0 to 100, but probabilities are a bell curve around 50%
|
||||
var l = (rand() + rand() + rand() + rand()) * 25;
|
||||
const l = (rand() + rand() + rand() + rand()) * 25;
|
||||
|
||||
return [h / 360,s / 100,l / 100];
|
||||
}
|
||||
|
||||
function createImageData(size) {
|
||||
var width = size; // Only support square icons for now
|
||||
var height = size;
|
||||
const width = size; // Only support square icons for now
|
||||
const height = size;
|
||||
|
||||
var dataWidth = Math.ceil(width / 2);
|
||||
var mirrorWidth = width - dataWidth;
|
||||
const dataWidth = Math.ceil(width / 2);
|
||||
const mirrorWidth = width - dataWidth;
|
||||
|
||||
var data = [];
|
||||
for (var y = 0; y < height; y++) {
|
||||
var row = [];
|
||||
for (var x = 0; x < dataWidth; x++) {
|
||||
const data = [];
|
||||
for (let y = 0; y < height; y++) {
|
||||
const row = [];
|
||||
for (let x = 0; x < dataWidth; x++) {
|
||||
// this makes foreground and background color to have a 43% (1/2.3) probability
|
||||
// spot color has 13% chance
|
||||
row[x] = Math.floor(rand() * 2.3);
|
||||
}
|
||||
var r = row.slice(0, mirrorWidth);
|
||||
const r = row.slice(0, mirrorWidth);
|
||||
r.reverse();
|
||||
row = row.concat(r);
|
||||
|
||||
for (var i = 0; i < row.length; i++) {
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
data.push(row[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var iconFactory
|
||||
let iconFactory
|
||||
const isValidAddress = require('ethereumjs-util').isValidAddress
|
||||
const { checksumAddress } = require('../app/util')
|
||||
const contractMap = require('eth-contract-metadata')
|
||||
|
@ -28,18 +28,18 @@ IconFactory.prototype.iconForAddress = function (address, diameter) {
|
|||
|
||||
// returns svg dom element
|
||||
IconFactory.prototype.generateIdenticonSvg = function (address, diameter) {
|
||||
var cacheId = `${address}:${diameter}`
|
||||
const cacheId = `${address}:${diameter}`
|
||||
// check cache, lazily generate and populate cache
|
||||
var identicon = this.cache[cacheId] || (this.cache[cacheId] = this.generateNewIdenticon(address, diameter))
|
||||
const identicon = this.cache[cacheId] || (this.cache[cacheId] = this.generateNewIdenticon(address, diameter))
|
||||
// create a clean copy so you can modify it
|
||||
var cleanCopy = identicon.cloneNode(true)
|
||||
const cleanCopy = identicon.cloneNode(true)
|
||||
return cleanCopy
|
||||
}
|
||||
|
||||
// creates a new identicon
|
||||
IconFactory.prototype.generateNewIdenticon = function (address, diameter) {
|
||||
var numericRepresentation = jsNumberForAddress(address)
|
||||
var identicon = this.jazzicon.generateIdenticon(diameter, numericRepresentation)
|
||||
const numericRepresentation = jsNumberForAddress(address)
|
||||
const identicon = this.jazzicon.generateIdenticon(diameter, numericRepresentation)
|
||||
return identicon
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ function imageElFor (address) {
|
|||
}
|
||||
|
||||
function jsNumberForAddress (address) {
|
||||
var addr = address.slice(2, 10)
|
||||
var seed = parseInt(addr, 16)
|
||||
const addr = address.slice(2, 10)
|
||||
const seed = parseInt(addr, 16)
|
||||
return seed
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue