diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-05-20 03:06:45 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-05-20 03:06:45 +0800 |
commit | c8deb355f7d1e4d1e10868a7d960fa460a7c51db (patch) | |
tree | 7f00234f62abda988035dc4ac83f7981ad446452 /ui/app/util.js | |
parent | 685a1881b86c19fe52a7cd82ed4e2b34617429ff (diff) | |
download | tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar.gz tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar.bz2 tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar.lz tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar.xz tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.tar.zst tangerine-wallet-browser-c8deb355f7d1e4d1e10868a7d960fa460a7c51db.zip |
Add address capitalization checksumming
Diffstat (limited to 'ui/app/util.js')
-rw-r--r-- | ui/app/util.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index 0f3f191aa..d8a0313ea 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -21,6 +21,8 @@ for (var currency in valueTable) { module.exports = { valuesFor: valuesFor, addressSummary: addressSummary, + isAllOneCase: isAllOneCase, + isValidAddress: isValidAddress, numericBalance: numericBalance, parseBalance: parseBalance, formatBalance: formatBalance, @@ -42,7 +44,19 @@ function valuesFor(obj) { } function addressSummary(address) { - return address ? address.slice(0,2+8)+'...'+address.slice(-4) : '...' + var checked = ethUtil.toChecksumAddress(address) + return checked ? checked.slice(0,2+8)+'...'+checked.slice(-4) : '...' +} + +function isValidAddress(address) { + var prefixed = ethUtil.addHexPrefix(address) + return isAllOneCase(prefixed) && ethUtil.isValidAddress(prefixed) || ethUtil.isValidChecksumAddress(prefixed) +} + +function isAllOneCase(address) { + var lower = address.toLowerCase() + var upper = address.toUpperCase() + return address === lower || address === upper } // Takes wei Hex, returns wei BN, even if input is null |