aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/token-util.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-10-28 01:39:40 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-10-28 08:29:12 +0800
commitc8c918d44e26e9541beead982ef0ed79a56d6e6f (patch)
tree9763d9c455910fd9b93b987d020617f4b8f13399 /ui/app/token-util.js
parent5d8b53bcf491bfe6dd59f4986f02da70b91df5cd (diff)
downloadtangerine-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.js36
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,
+}