diff options
author | Dan <danjm.com@gmail.com> | 2017-10-28 01:39:40 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-28 08:29:12 +0800 |
commit | c8c918d44e26e9541beead982ef0ed79a56d6e6f (patch) | |
tree | 9763d9c455910fd9b93b987d020617f4b8f13399 /ui/app/token-util.js | |
parent | 5d8b53bcf491bfe6dd59f4986f02da70b91df5cd (diff) | |
download | tangerine-wallet-browser-c8c918d44e26e9541beead982ef0ed79a56d6e6f.tar.gz tangerine-wallet-browser-c8c918d44e26e9541beead982ef0ed79a56d6e6f.tar.zst tangerine-wallet-browser-c8c918d44e26e9541beead982ef0ed79a56d6e6f.zip |
Add utility for getting token data; get token data in tx-list even if token has been removed.
Diffstat (limited to 'ui/app/token-util.js')
-rw-r--r-- | ui/app/token-util.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ui/app/token-util.js b/ui/app/token-util.js new file mode 100644 index 000000000..eec518556 --- /dev/null +++ b/ui/app/token-util.js @@ -0,0 +1,36 @@ +const abi = require('human-standard-token-abi') +const Eth = require('ethjs-query') +const EthContract = require('ethjs-contract') + +const tokenInfoGetter = function () { + if (typeof global.ethereumProvider === 'undefined') return + + const eth = new Eth(global.ethereumProvider) + const contract = new EthContract(eth) + const TokenContract = contract(abi) + + const tokens = {} + + return async (address) => { + if (tokens[address]) { + return tokens[address] + } + + const contract = TokenContract.at(address) + + const result = await Promise.all([ + contract.symbol(), + contract.decimals(), + ]) + + const [ symbol = [], decimals = [] ] = result + + tokens[address] = { symbol: symbol[0], decimals: decimals[0] } + + return tokens[address] + } +} + +module.exports = { + tokenInfoGetter, +} |