Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
SetOrderCoin Logic Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMieskoski committed Apr 23, 2018
1 parent 076d44e commit 336e436
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 398 deletions.
179 changes: 45 additions & 134 deletions app/scripts/controllers/swapCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,151 +118,60 @@ var swapCtrl = function ($scope, $sce, walletService) {
// todo: devise a Cleaner method

$scope.setOrderCoin = function (isFrom, coin) {
let doAssignment = true;
$scope.kyberSwapRateDisplay();
let bityOptions = ["ETH", "BTC", "REP"];
let kyberOptions = $scope.availableTokens;
let isBity = (_coin) => {
return bityOptions.indexOf(_coin) > -1;
}
if (isFrom) {

// BTC selected as fromCoin
if (coin === "BTC") {
$scope.availableToOptions = [...bityOptions];
if ($scope.swapOrder.fromCoin == "ETH") {
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];
}

// ETH selected as fromCoin
} else if (coin === "ETH") {
if ($scope.swapOrder.toCoin == "ETH" && ($scope.swapOrder.fromCoin != "REP" && $scope.swapOrder.toCoin != "REP")) {
$scope.swapOrder.toCoin = $scope.swapOrder.fromCoin.slice();
$scope.swapOrder.fromCoin = "ETH";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
if ($scope.availableTokens.indexOf($scope.swapOrder.toCoin) >= 0) {
$scope.availableFromOptions = ["ETH"];
} else if ($scope.swapOrder.toCoin == "BTC") {
$scope.availableFromOptions = ["BTC", "ETH"];
}

doAssignment = false;
$scope.availableToOptions = []
if (isBity(coin)) {
bityOptions.forEach((_item) => {
if (_item != coin) $scope.availableToOptions.push(_item)
})
if (coin == "ETH") {
kyberOptions.forEach((_item) => {
$scope.availableToOptions.push(_item)
})
}

$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];

// A Token selected as fromCoin
} else if ($scope.availableTokens.indexOf(coin) >= 0) {
$scope.availableToOptions = ["ETH"];
if ($scope.swapOrder.toCoin != "ETH") {
$scope.swapOrder.toCoin = "ETH";
}
if ($scope.swapOrder.fromCoin == coin) {
$scope.swapOrder.toCoin = $scope.swapOrder.fromCoin.slice();
$scope.swapOrder.fromCoin = "ETH";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
$scope.availableFromOptions = ["ETH"];
$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];
doAssignment = false;
} else {
if ($scope.swapOrder.fromCoin == "ETH") {
$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];
}

}
}
if (doAssignment) $scope.swapOrder.fromCoin = coin;

if ($scope.swapOrder.fromCoin == "ETH") {
$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];
} else {
$scope.availableToOptions = ["ETH"]
}

} else { // Set coin and options when a to coin is selected

// BTC selected as toCoin
if (coin === "BTC") {
if ($scope.swapOrder.fromCoin == "BTC" && $scope.swapOrder.toCoin == "ETH") {
$scope.swapOrder.fromCoin = "ETH";
$scope.swapOrder.toCoin = "BTC";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];
$scope.availableFromOptions = ["BTC", "ETH"];
doAssignment = false;
} else if ($scope.swapOrder.fromCoin == "ETH" && $scope.swapOrder.toCoin == "BTC") {
$scope.swapOrder.fromCoin = "BTC";
$scope.swapOrder.toCoin = "ETH";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];
$scope.availableToOptions = [...bityOptions];
doAssignment = false;
}

if ($scope.availableTokens.indexOf($scope.swapOrder.fromCoin) >= 0) {
$scope.swapOrder.fromCoin = "ETH";
$scope.availableToOptions = [...bityOptions, ...$scope.availableTokens];
}
$scope.availableFromOptions = ["BTC", "ETH"];
console.log("toCoin -> BTC", coin); //todo remove dev item
// ETH selected as toCoin
} else if (coin === "ETH") {
if ($scope.swapOrder.fromCoin == "ETH" && ($scope.swapOrder.fromCoin != "REP" && $scope.swapOrder.toCoin != "REP")) {
$scope.swapOrder.fromCoin = $scope.swapOrder.toCoin.slice();
$scope.swapOrder.toCoin = "ETH";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
// $scope.availableToOptions = ["ETH"];

if ($scope.availableTokens.indexOf($scope.swapOrder.fromCoin) >= 0) {
$scope.availableToOptions = ["ETH"];
} else if ($scope.swapOrder.fromCoin == "BTC") {
$scope.availableToOptions = [...bityOptions];
}

doAssignment = false;
}
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];

// REP selected as toCoin
} else if (coin === "REP") {
$scope.availableFromOptions = ["BTC", "ETH"];

// A Token selected as toCoin
} else if ($scope.availableTokens.indexOf(coin) >= 0) {
$scope.availableFromOptions = ["ETH"];
if ($scope.swapOrder.fromCoin !== "ETH") {
$scope.swapOrder.fromCoin = "ETH";
$scope.swapOrder.fromCoin = coin;
} else {
$scope.availableFromOptions = []
if (isBity(coin)) {
if (coin == "ETH") {
bityOptions.forEach((_item) => {
if (_item != coin && _item != "REP") $scope.availableFromOptions.push(_item)
})
kyberOptions.forEach((_item) => {
$scope.availableFromOptions.push(_item)
})
} else {
bityOptions.forEach((_item) => {
if (_item != coin && _item != "REP") $scope.availableFromOptions.push(_item)
})
}

if ($scope.swapOrder.toCoin == coin) {
$scope.swapOrder.fromCoin = $scope.swapOrder.toCoin.slice();
$scope.swapOrder.toCoin = "ETH";
// to prevent mis-interpretation reset the values when swapping to and from
$scope.swapOrder.fromVal = 0;
$scope.swapOrder.toVal = 0;
$scope.availableToOptions = ["ETH"];
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];
doAssignment = false;
} else {
if($scope.swapOrder.fromCoin == "ETH"){
console.log(coin); //todo remove dev item
bityOptions.forEach((_item) => {
if (_item != coin) $scope.availableToOptions.push(_item)
})
kyberOptions.forEach((_item) => {
$scope.availableToOptions.push(_item)
})
} else {
if ($scope.swapOrder.toCoin == "ETH") {
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];
}
$scope.availableToOptions = ["ETH"]
}

}

if (doAssignment) $scope.swapOrder.toCoin = coin;

if ($scope.swapOrder.toCoin == "ETH") {
$scope.availableFromOptions = [...bityOptions, ...$scope.availableTokens];
}
$scope.swapOrder.toCoin = coin;
}

if (bityOptions.indexOf($scope.swapOrder.toCoin) > -1 && bityOptions.indexOf($scope.swapOrder.fromCoin) > -1) {

if (isBity($scope.swapOrder.toCoin) && isBity($scope.swapOrder.fromCoin)) {
if ($scope.swapOrder.fromCoin == $scope.swapOrder.toCoin)
for (var i in bityOptions)
if (bityOptions[i] != $scope.swapOrder.fromCoin) {
Expand All @@ -273,6 +182,8 @@ var swapCtrl = function ($scope, $sce, walletService) {
} else {
$scope.setKyberOrderCoin(isFrom);
}


};

$scope.setBityOrderCoin = function (isFrom) {
Expand Down
3 changes: 2 additions & 1 deletion chrome-extension/cx-wallet.html
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,8 @@ <h5>Transaction Hash(es):</h5>
<span>
Track your swap transaction:
</span>
<h6 ng-if="!kyberTransaction.tokenTxHash">Waiting for token authorization <span ng-repeat="tick in indicatorhacked track by $index">. </span></h6>
<span ng-if="!kyberTransaction.tokenTxHash" class="text-info">Waiting for token authorization <span ng-repeat="tick in indicatorhacked track by $index">. </span></span>
<span ng-if="!kyberTransaction.tokenTxHash" class="text-danger"> Do Not Navigate Away or Close Your Browser</span>
<a class="strong" ng-href="{{kyberTransaction.tokenTxLink}}" target="_blank" rel="noopener">
<h5>{{kyberTransaction.tokenTxHash}}</h5>
</a>
Expand Down
Loading

0 comments on commit 336e436

Please sign in to comment.