diff --git a/app/scripts/controllers/tabsCtrl.js b/app/scripts/controllers/tabsCtrl.js index eb8ccc0f26..afb5afefa5 100644 --- a/app/scripts/controllers/tabsCtrl.js +++ b/app/scripts/controllers/tabsCtrl.js @@ -154,9 +154,9 @@ var tabsCtrl = function( } Token.popTokens = $scope.curNode.tokenList.map(token => - Object.assign(token, { + Object.assign({}, token, { node: key, - network: $scope.curNode.type + type: $scope.curNode.type }) ); diff --git a/app/scripts/controllers/walletBalanceCtrl.js b/app/scripts/controllers/walletBalanceCtrl.js index 3be8aa96ff..265c75fc91 100644 --- a/app/scripts/controllers/walletBalanceCtrl.js +++ b/app/scripts/controllers/walletBalanceCtrl.js @@ -14,6 +14,8 @@ var walletBalanceCtrl = function( $scope.messageService = messageService; + $scope.tokenVisibility = "shown"; + $scope.modalService = modalService; $scope.coldStakingService = coldStakingService; @@ -23,7 +25,7 @@ var walletBalanceCtrl = function( DEXNSFunction: 5 }; - $scope.tokensLoaded = true; + $scope.tokensLoaded = false; $scope.localToken = { contractAdd: "", symbol: "", @@ -34,7 +36,6 @@ var walletBalanceCtrl = function( $scope.contract = { functions: [] }; - $scope.slide = 1; $scope.customTokenSymbol = ""; $scope.customTokenInterval = null; @@ -58,6 +59,8 @@ var walletBalanceCtrl = function( if (coldStakingService.validNetwork()) { coldStakingService.staker_info(); } + + $scope.setAllBalance(); } ); @@ -102,8 +105,6 @@ var walletBalanceCtrl = function( $scope.customTokenField = false; $scope.customTokenDexNSField = false; $scope.customTokenSymbol = ""; - - $scope.addressDrtv.ensAddressField = ""; }; $scope.saveTokenToLocal = function() { @@ -127,8 +128,7 @@ var walletBalanceCtrl = function( contractAdd: "", symbol: "", decimals: "", - type: "custom", - network: "" + type: ajaxReq.type }; }; @@ -137,7 +137,7 @@ var walletBalanceCtrl = function( $scope.contract.functions = []; var tAbi = $scope.erc20Abi; for (var i in tAbi) { - if (tAbi[i].type == "function") { + if (tAbi[i].type === "function") { tAbi[i].inputs.map(function(i) { i.value = ""; }); @@ -197,32 +197,11 @@ var walletBalanceCtrl = function( return curFunc; }; - $scope.$watch( - function() { - return $scope.addressDrtv.ensAddressField; - }, - function(newAddress) { - if (!$scope.Validator) return; - - $scope.localToken.symbol = ""; - - $scope.localToken.decimals = ""; - - if ($scope.Validator.isValidAddress(newAddress)) { - $scope.localToken.symbol = "loading..."; - - $scope.localToken.decimals = "loading..."; - - $scope.getTokenInfo(newAddress); - } - } - ); - $scope.$watch( function() { return globalFuncs.getCurNode(); }, - function(newNode) { + function(newNode, oldNode) { // console.log('new node', newNode); $scope.resetLocalToken(); @@ -252,8 +231,6 @@ var walletBalanceCtrl = function( ]; getNameFunction.inputs[0].value = newSymbol; - var DEXNSnetwork = "ETC"; // DexNS network is always ETC! - $scope.nodeList[ backgroundNodeService.backgroundNode ].lib.getEthCall( @@ -276,7 +253,6 @@ var walletBalanceCtrl = function( data ).outputs; var contractAddress = outputs[1].value; - var contractInfo = outputs[2].value.split("-"); if ( contractAddress === @@ -374,8 +350,7 @@ var walletBalanceCtrl = function( $scope.getTokenInfo = function(address, symbol = null) { $scope.localToken.contractAdd = address; - $scope.localToken.network = - nodes.nodeList[globalFuncs.getCurNode()].name; + $scope.localToken.type = ajaxReq.type; var request_ = { to: address, diff --git a/app/scripts/directives/accountBalanceTable.html b/app/scripts/directives/accountBalanceTable.html index 8dfc35e423..c7c59a48fd 100644 --- a/app/scripts/directives/accountBalanceTable.html +++ b/app/scripts/directives/accountBalanceTable.html @@ -41,10 +41,12 @@
|
@@ -12,8 +12,19 @@
class="token-remove"
title="Remove Token"
ng-click="removeTokenFromLocal(token.symbol)"
- ng-show="token.type!=='default'"/>
- {{token.getBalance() }}
+ ng-show="token.local === true"
+ />
+
+
+ {{token.getBalance() | number }}
+
+
+ {{token.getBalance() }}
+
+
{{token.dexns.info}} diff --git a/app/scripts/globalFuncs.js b/app/scripts/globalFuncs.js index c38e5238fb..e45be7bc08 100644 --- a/app/scripts/globalFuncs.js +++ b/app/scripts/globalFuncs.js @@ -345,8 +345,7 @@ globalFuncs.saveTokenToLocal = function(localToken, callback) { symbol: localToken.symbol, decimal: parseInt(localToken.decimals), decimals: parseInt(localToken.decimals), - type: nodes.nodeTypes.Custom, - network: nodes.nodeList[node].name, + type: localToken.type, node }); globalFuncs.localStorage.setItem( diff --git a/app/scripts/myetherwallet.js b/app/scripts/myetherwallet.js index c17a6c7cd9..0d7f82a7b4 100644 --- a/app/scripts/myetherwallet.js +++ b/app/scripts/myetherwallet.js @@ -22,44 +22,48 @@ Wallet.generate = function(icapDirect) { } }; Wallet.prototype.setTokens = function() { - const { popTokens } = Token; - let storedTokens = !!globalFuncs.localStorage.getItem("localTokens", null) + const { popTokens: _popTokens } = Token; + + const popTokens = _popTokens.map(token => + Object.assign(token, { local: false }) + ); + + const _localTokens = !!globalFuncs.localStorage.getItem("localTokens", null) ? JSON.parse(globalFuncs.localStorage.getItem("localTokens")) : []; - storedTokens = storedTokens.map(token => - Object.assign(token, { address: token.contractAddress }) + const localTokens = _localTokens.map(token => + Object.assign(token, { address: token.contractAddress, local: true }) ); - let node_ = globalFuncs.getCurNode(); - const network = nodes.nodeList[node_]; - const tokens = [] - .concat(popTokens, storedTokens) + const addr = this.getAddressString(); + this.tokenObjs = [] + .concat(popTokens, localTokens) .map( token => new Token( token.address, - this.getAddressString(), + addr, globalFuncs.stripTags(token.symbol), token.decimal, token.type, - token.network, - token.node + token.node, + token.local ) ); - this.tokenObjs = tokens.map(token => { - if (token.network === ajaxReq.type) { - token.fetchBalance(); - } else { - token.setBalance(`SWITCH TO ${token.network} NETWORK`); - } - - return token; - }); + Promise.all( + this.tokenObjs.map(token => { + if (token.type === ajaxReq.type) { + token.fetchBalance(); + } else { + token.setBalance(`SWITCH TO ${token.type} NETWORK`); + } + }) + ); }; -Wallet.prototype.setBalance = function(callback) { - this.balance = this.usdBalance = this.eurBalance = this.btcBalance = this.chfBalance = this.repBalance = this.gbpBalance = +Wallet.prototype.setBalance = function(callback = console.log) { + this.balance = this.usdBalance = this.eurBalance = this.btcBalance = this.chfBalance = this.gbpBalance = "loading"; ajaxReq.getBalance(this.getAddressString(), data => { if (data.error) this.balance = data.msg; @@ -96,8 +100,7 @@ Wallet.prototype.setBalance = function(callback) { "ether", data.chf ); - - if (callback) callback(); + callback(); }); } }); @@ -125,21 +128,21 @@ Wallet.prototype.getPrivateKeyString = function() { } }; Wallet.prototype.getPublicKey = function() { - if (typeof this.pubKey == "undefined") { + if (typeof this.pubKey === "undefined") { return ethUtil.privateToPublic(this.privKey); } else { return this.pubKey; } }; Wallet.prototype.getPublicKeyString = function() { - if (typeof this.pubKey == "undefined") { + if (typeof this.pubKey === "undefined") { return "0x" + this.getPublicKey().toString("hex"); } else { return "0x" + this.pubKey.toString("hex"); } }; Wallet.prototype.getAddress = function() { - if (typeof this.pubKey == "undefined") { + if (typeof this.pubKey === "undefined") { return ethUtil.privateToAddress(this.privKey); } else { return ethUtil.publicToAddress(this.pubKey, true); diff --git a/app/scripts/services/coinPrice.service.js b/app/scripts/services/coinPrice.service.js index c87fd92d9d..9b8b454616 100644 --- a/app/scripts/services/coinPrice.service.js +++ b/app/scripts/services/coinPrice.service.js @@ -34,9 +34,9 @@ const coinPriceService = function coinPriceService() { (result.hasOwnProperty("data") && result.data.Response === "Error") ) { - // fixme: throw err; - - return Object.assign({}, result, { error: true }); + return Promise.reject( + Object.assign({}, result, { error: true }) + ); } else { const { data } = result; diff --git a/app/scripts/tokenlib.js b/app/scripts/tokenlib.js index 4484e940a2..2928b743c3 100644 --- a/app/scripts/tokenlib.js +++ b/app/scripts/tokenlib.js @@ -18,8 +18,8 @@ var Token = function( symbol, decimal, type, - network, - node + node, + local = false ) { this.contractAddress = contractAddress; this.userAddress = userAddress; @@ -27,9 +27,10 @@ var Token = function( this.decimal = decimal; this.type = type; this.balance = "loading"; - this.network = network; // str this.node = node; // str + this.local = local; + this.dexns = { info: "", name: "" @@ -44,12 +45,6 @@ Token.popTokens = []; Token.prototype.getContractAddress = function() { return this.contractAddress; }; -Token.prototype.getUserAddress = function() { - return this.userAddress; -}; -Token.prototype.setUserAddress = function(address) { - this.userAddress = address; -}; Token.prototype.getSymbol = function() { return this.symbol; }; @@ -59,9 +54,6 @@ Token.prototype.getDecimal = function() { Token.prototype.getBalance = function() { return this.balance; }; -Token.prototype.getBalanceBN = function() { - return this.balanceBN; -}; Token.prototype.setBalance = function(balance) { this.balance = balance; @@ -75,7 +67,7 @@ Token.prototype.initDexns = function() { if (_name) { this.dexns.name = _name; - console.log(this.contractAddress, _name); + // console.log(this.contractAddress, _name); dexnsStorageContract .call("getName", { inputs: [_name] }) @@ -94,7 +86,7 @@ Token.prototype.fetchBalance = function() { [ethFuncs.getNakedAddress(this.userAddress)] ); - const node_ = nodes.nodeList[this.node]; + const node_ = this.node; // check that node has proper getEthCall method or resort to ajax Req const requestObj = @@ -104,9 +96,6 @@ Token.prototype.fetchBalance = function() { ? node_.lib : ajaxReq; - // FIXME: translate - this.setBalance("loading..."); - try { requestObj.getEthCall(request_, data => { if ( @@ -119,18 +108,12 @@ Token.prototype.fetchBalance = function() { .div(new BigNumber(10).pow(this.getDecimal())) .toString() ); - this.balanceBN = new BigNumber(data.data).toString(); - //if (callback) callback(); } else { this.setBalance(globalFuncs.errorMsgs[20]); - this.balanceBN = "0"; } }); } catch (e) { this.setBalance("0"); //globalFuncs.errorMsgs[20]; - this.balanceBN = "0"; - - // console.error('error fetching token balance: ', request_); } }; |