diff options
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 |