Skip to content

Commit

Permalink
Merge pull request MyEtherWallet#284 from j-chimienti/fix/token-display
Browse files Browse the repository at this point in the history
Fix/token display
  • Loading branch information
Dexaran authored Oct 4, 2018
2 parents 4d4559b + 167788a commit 083ab3d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 98 deletions.
4 changes: 2 additions & 2 deletions app/scripts/controllers/tabsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);

Expand Down
43 changes: 9 additions & 34 deletions app/scripts/controllers/walletBalanceCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var walletBalanceCtrl = function(

$scope.messageService = messageService;

$scope.tokenVisibility = "shown";

$scope.modalService = modalService;
$scope.coldStakingService = coldStakingService;

Expand All @@ -23,7 +25,7 @@ var walletBalanceCtrl = function(
DEXNSFunction: 5
};

$scope.tokensLoaded = true;
$scope.tokensLoaded = false;
$scope.localToken = {
contractAdd: "",
symbol: "",
Expand All @@ -34,7 +36,6 @@ var walletBalanceCtrl = function(
$scope.contract = {
functions: []
};
$scope.slide = 1;
$scope.customTokenSymbol = "";
$scope.customTokenInterval = null;

Expand All @@ -58,6 +59,8 @@ var walletBalanceCtrl = function(
if (coldStakingService.validNetwork()) {
coldStakingService.staker_info();
}

$scope.setAllBalance();
}
);

Expand Down Expand Up @@ -102,8 +105,6 @@ var walletBalanceCtrl = function(
$scope.customTokenField = false;
$scope.customTokenDexNSField = false;
$scope.customTokenSymbol = "";

$scope.addressDrtv.ensAddressField = "";
};

$scope.saveTokenToLocal = function() {
Expand All @@ -127,8 +128,7 @@ var walletBalanceCtrl = function(
contractAdd: "",
symbol: "",
decimals: "",
type: "custom",
network: ""
type: ajaxReq.type
};
};

Expand All @@ -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 = "";
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand All @@ -276,7 +253,6 @@ var walletBalanceCtrl = function(
data
).outputs;
var contractAddress = outputs[1].value;
var contractInfo = outputs[2].value.split("-");

if (
contractAddress ===
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions app/scripts/directives/accountBalanceTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ <h5>Reward</h5>
title="{{walletService.wallet.balance}} (Double-Click)"
class="text-left pointer"
>
<span ng-dblclick="showLongBal = !showLongBal">
<span
ng-init="showLongBalance = false;"
ng-dblclick="showLongBalance = !showLongBalance">
<span class="mono wrap"
ng-show="!showLongBal">{{walletService.wallet.balance | number}}</span>
<span class="mono wrap" ng-show="showLongBal">{{walletService.wallet.balance}}</span>
ng-show="!showLongBalance">{{walletService.wallet.balance | number}}</span>
<span class="mono wrap" ng-show="showLongBalance">{{walletService.wallet.balance}}</span>
</span>
</span>
<span
Expand Down Expand Up @@ -118,7 +120,9 @@ <h5>Reward</h5>
{{altBalance.symbol}}
</td>
<td class="account-info point text-right"
ng-init="showLongBal = false;"
ng-dblclick="showLongBal=!showLongBal"

title="{{altBalance.balance}} (Double-Click)"
colspan="{{coldStakingService.validNetwork() ? 3 : 1}}"
>
Expand Down
19 changes: 15 additions & 4 deletions app/scripts/directives/tokenBalances.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<table class="account-info table table-responsive">
<caption translate="sidebar_TokenBal">Token Balances:</caption>
<tbody>
<tr ng-repeat="token in wallet.tokenObjs track by $index"
ng-show="token.balance !== 0 && token.balance !== 'loading' || token.type !== 'default' || tokenVisibility === 'shown'">
<tr ng-repeat="token in wallet.tokenObjs track by $index + token.contractAddress"
ng-show="token.type === ajaxReq.type && tokenVisibility === 'shown'">
<td class="text-left">
<coin-icon icon="{{token.getSymbol()}}"></coin-icon>
</td>
Expand All @@ -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"
/>
<span ng-switch="showLongBal"
ng-dblclick="showLongBal = !showLongBal"
ng-init="showLongBal = false;"
>
<span ng-switch-default="false">
{{token.getBalance() | number }}
</span>
<span ng-switch-when="true">
{{token.getBalance() }}
</span>
</span>
</td>
<td ng-if="token.dexns.name && token.dexns.info">
{{token.dexns.info}}
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/globalFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
57 changes: 30 additions & 27 deletions app/scripts/myetherwallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,8 +100,7 @@ Wallet.prototype.setBalance = function(callback) {
"ether",
data.chf
);

if (callback) callback();
callback();
});
}
});
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/services/coinPrice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 083ab3d

Please sign in to comment.