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

Commit

Permalink
Merge pull request #1839 from SteveMieskoski/mercury
Browse files Browse the repository at this point in the history
change Kyber swap to use expectedRate
  • Loading branch information
gamalielhere authored May 9, 2018
2 parents 44bcc37 + 2bd2ef3 commit 3b6e7d6
Show file tree
Hide file tree
Showing 10 changed files with 2,972 additions and 2,775 deletions.
6 changes: 3 additions & 3 deletions app/includes/swap-kyber-modal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@
</tr>
<tr>
<td class="small text-right">Swapping:</td>
<td class="small text-left mono">{{swapOrder.fromVal}} {{swapOrder.fromCoin}}</td>
<td class="small text-left mono">{{swapOrder.fromVal}} {{swapOrder.fromCoin}}</td>
</tr>
<tr>
<td class="small text-right">For:</td>
<td class="small text-left mono">{{swapOrder.toVal}} {{swapOrder.toCoin}}</td>
<td class="small text-left mono"><!--{{swapOrder.toVal}}--> {{swapOrder.fromVal * swapOrder.swapRate}} {{swapOrder.toCoin}}</td>
</tr>
<tr>
<td class="small text-right">Network:</td>
Expand Down Expand Up @@ -339,7 +339,7 @@
</tr>
<tr>
<td class="small text-right">For:</td>
<td class="small text-left mono">{{swapOrder.toVal}} {{swapOrder.toCoin}}</td>
<td class="small text-left mono"><!--{{swapOrder.toVal}}--> {{swapOrder.fromVal * swapOrder.swapRate}} {{swapOrder.toCoin}}</td>
</tr>
<tr>
<td class="small text-right">Network:</td>
Expand Down
9 changes: 5 additions & 4 deletions app/includes/swap-kyber.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<p translate="SWAP_send_amt"> Amount to send </p>
</div>
<div class="col-sm-4 order-info">
<h4> {{swapOrder.toVal | number: receiveDecimals}} {{swapOrder.toCoin}} </h4>

<h4> <!--{{swapOrder.toVal | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{swapOrder.toCoin}} </h4>
<p translate="SWAP_rec_amt"> Amount to receive </p>
</div>
<div class="col-sm-4 order-info">
Expand Down Expand Up @@ -87,7 +88,7 @@
<!-- Order Info -->
<section class="row order-info-wrap">
<div class="col-sm-6 order-info">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-6 order-info">
Expand Down Expand Up @@ -250,7 +251,7 @@
<!-- Order Info -->
<section class="row order-info-wrap">
<div class="col-sm-6 order-info">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-6 order-info">
Expand Down Expand Up @@ -310,7 +311,7 @@
<p>Amount sent</p>
</div>
<div class="col-sm-12">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-12">
Expand Down
4 changes: 2 additions & 2 deletions app/includes/swap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@@if (site === 'cx' ) { @@include( '../includes/swap-kyber.tpl', { "site": "cx" } ) }
</div>

<section class="bity-contact text-center" ng-if="!isKyberSwap">
<section class="bity-contact text-center" ng-if="!isKyberRateSwap">
<p><a class="btn-warning btn-sm"
href="mailto:mew@bity.com,support@myetherwallet.com?Subject={{orderResult.reference}}%20Issue%20regarding%20my%20Swap%20via%20MEW%20&Body=%0APlease%20include%20the%20below%20if%20this%20issue%20is%20regarding%20your%20order.%20%0A%0AREF%20ID%23%3A%20{{orderResult.reference}}%0A%0AAmount%20to%20send%3A%20{{orderResult.input.amount}}%20{{orderResult.input.currency}}%0A%0AAmount%20to%20receive%3A%20{{orderResult.output.amount}}%20{{orderResult.output.currency}}%0A%0APayment%20Address%3A%20{{orderResult.payment_address}}%0A%0ARate%3A%20{{swapOrder.swapRate}}%20{{swapOrder.swapPair}}%0A%0A"
target="_blank" rel="noopener noreferrer"> Issue with your Swap? Contact support</a></p>
Expand All @@ -38,7 +38,7 @@
</textarea>
</section>

<section class="bity-contact text-center" ng-if="isKyberSwap">
<section class="bity-contact text-center" ng-if="isKyberRateSwap">
<p><a class="btn-warning btn-sm"
href="mailto:support@myetherwallet.com,support@kyber.network?Subject={{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash}}%20Issue%20regarding%20my%20Kyber%20Swap%20via%20MEW%20&Body=%0APlease%20include%20the%20below%20if%20this%20issue%20is%20regarding%20your%20order.%20%0A%0AREF%20ID%23%3A%20{{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash + '%20%20ApproveTxHash%3A%20' + kyberTransaction.tokenApproveTxHash}}%0A%0AAmount%20to%20send%3A%20{{orderResult.input.amount}}%20{{orderResult.input.currency}}%0A%0AAmount%20to%20receive%3A%20{{orderResult.output.amount}}%20{{orderResult.output.currency}}%0A%0ARate%3A%20{{swapOrder.swapRate}}%20{{swapOrder.swapPair}}%0A%0A"
target="_blank" rel="noopener noreferrer"> Issue with your Swap? Contact support</a></p>
Expand Down
6 changes: 4 additions & 2 deletions app/scripts/controllers/swapCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ var swapCtrl = function($scope, $sce, walletService) {
// todo: provide message and option to return if the rate value for the specified qty is 0.
// todo: or just provide the message and don't 'route' to the next page (I like this better)
$scope.swapOrder.finalRate = finalRate;
// $scope.swapOrder.swapRate = finalRate;
console.log("final rate", $scope.swapOrder.finalRate); //todo remove dev item
if (isFrom) {
$scope.receiveDecimals = $scope.kyber.tokenDetails[$scope.swapOrder.toCoin].decimals < bity.decimals ? $scope.kyber.tokenDetails[$scope.swapOrder.toCoin].decimals : bity.decimals;
let _toVal = finalRate * $scope.swapOrder.fromVal;
Expand Down Expand Up @@ -853,7 +855,7 @@ var swapCtrl = function($scope, $sce, walletService) {
$scope.openKyberEthOrder = function() {
try {
$scope.addressString = $scope.walletKyber.getAddressString();
$scope.tx = $scope.buildTransactionObject($scope.kyber.getTradeData($scope.swapOrder, $scope.swapOrder.swapRate), $scope.kyber.getKyberNetworkAddress(), $scope.swapOrder.fromVal);
$scope.tx = $scope.buildTransactionObject($scope.kyber.getTradeData($scope.swapOrder, $scope.swapOrder.finalRate), $scope.kyber.getKyberNetworkAddress(), $scope.swapOrder.fromVal);
var txData = uiFuncs.getTxData($scope);
txData.nonce = txData.gasPrice = null;

Expand Down Expand Up @@ -904,7 +906,7 @@ var swapCtrl = function($scope, $sce, walletService) {
// Build the Swap transaction to send to the Kyber Network Contract to execute the swap
$scope.openKyberTokenOrder = function(nonce, gasPrice) {
try {
$scope.tx = $scope.buildTransactionObject($scope.kyber.getTradeData($scope.swapOrder, $scope.swapOrder.swapRate), $scope.kyber.getKyberNetworkAddress());
$scope.tx = $scope.buildTransactionObject($scope.kyber.getTradeData($scope.swapOrder, $scope.swapOrder.finalRate), $scope.kyber.getKyberNetworkAddress());
var txData = uiFuncs.getTxData($scope);
if (nonce) {
let newNonce = parseInt(ethFuncs.hexToDecimal(nonce));
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/kyber.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ kyberFuncs.prototype.setKyberRate = function (_from, _to) {
var _this = this;
return new Promise((resolve, reject) => {
_this.getExpectedRate(_from, _to, 1, (_results) => {
let _returnedRate = _this.convertToTokenBase(_results.data.slippageRate, "ETH");
let _returnedRate = _this.convertToTokenBase(_results.data.expectedRate, "ETH");
_this.kyberRates[kyber.toPairKey(_from, _to)] = _returnedRate;
_this.priceLoaded = true;
resolve(_returnedRate);
Expand All @@ -195,7 +195,7 @@ kyberFuncs.prototype.refreshRates = function() {
let toToken = pairContents[1];
_this.getExpectedRate(fromToken, toToken, 1, (_results) => {
//
_this.kyberRates[_key] = _this.convertToTokenBase(_results.data.slippageRate, "ETH");
_this.kyberRates[_key] = _this.convertToTokenBase(_results.data.expectedRate, "ETH");
})
});
_this.priceLoaded = true;
Expand Down
23 changes: 10 additions & 13 deletions chrome-extension/cx-wallet.html
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,8 @@ <h4> {{swapOrder.fromVal}} {{swapOrder.fromCoin}} </h4>
<p translate="SWAP_send_amt"> Amount to send </p>
</div>
<div class="col-sm-4 order-info">
<h4> {{swapOrder.toVal | number: receiveDecimals}} {{swapOrder.toCoin}} </h4>

<h4> <!--{{swapOrder.toVal | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{swapOrder.toCoin}} </h4>
<p translate="SWAP_rec_amt"> Amount to receive </p>
</div>
<div class="col-sm-4 order-info">
Expand Down Expand Up @@ -2906,7 +2907,7 @@ <h5 class="col-xs-6" translate="SWAP_information">Your Information</h5>
<!-- Order Info -->
<section class="row order-info-wrap">
<div class="col-sm-6 order-info">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-6 order-info">
Expand Down Expand Up @@ -3127,11 +3128,11 @@ <h4 class="text-primary">
</tr>
<tr>
<td class="small text-right">Swapping:</td>
<td class="small text-left mono">{{swapOrder.fromVal}} {{swapOrder.fromCoin}}</td>
<td class="small text-left mono">{{swapOrder.fromVal}} {{swapOrder.fromCoin}}</td>
</tr>
<tr>
<td class="small text-right">For:</td>
<td class="small text-left mono">{{swapOrder.toVal}} {{swapOrder.toCoin}}</td>
<td class="small text-left mono"><!--{{swapOrder.toVal}}--> {{swapOrder.fromVal * swapOrder.swapRate}} {{swapOrder.toCoin}}</td>
</tr>
<tr>
<td class="small text-right">Network:</td>
Expand Down Expand Up @@ -3378,7 +3379,7 @@ <h5>Advanced</h5>
</tr>
<tr>
<td class="small text-right">For:</td>
<td class="small text-left mono">{{swapOrder.toVal}} {{swapOrder.toCoin}}</td>
<td class="small text-left mono"><!--{{swapOrder.toVal}}--> {{swapOrder.fromVal * swapOrder.swapRate}} {{swapOrder.toCoin}}</td>
</tr>
<tr>
<td class="small text-right">Network:</td>
Expand Down Expand Up @@ -3491,7 +3492,7 @@ <h5 class="col-xs-6" translate="SWAP_information">Your Information</h5>
<!-- Order Info -->
<section class="row order-info-wrap">
<div class="col-sm-6 order-info">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-6 order-info">
Expand Down Expand Up @@ -3551,7 +3552,7 @@ <h4>{{kyberOrderResult.input.amount}} {{kyberOrderResult.input.currency}}</h4>
<p>Amount sent</p>
</div>
<div class="col-sm-12">
<h4>{{kyberOrderResult.output.amount | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<h4><!--{{kyberOrderResult.output.amount | number: receiveDecimals}}--> {{swapOrder.fromVal * swapOrder.swapRate | number: receiveDecimals}} {{kyberOrderResult.output.currency}}</h4>
<p translate="SWAP_rec_amt">Amount to receive</p>
</div>
<div class="col-sm-12">
Expand Down Expand Up @@ -3666,13 +3667,13 @@ <h5>{{kyberTransaction.ethTxHash}}</h5>

<section class="bity-contact text-center" ng-if="isKyberSwap">
<p><a class="btn-warning btn-sm"
href="mailto:support@myetherwallet.com?Subject={{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash}}%20Issue%20regarding%20my%20Kyber%20Swap%20via%20MEW%20&Body=%0APlease%20include%20the%20below%20if%20this%20issue%20is%20regarding%20your%20order.%20%0A%0AREF%20ID%23%3A%20{{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash + '%20%20ApproveTxHash%3A%20' + kyberTransaction.tokenApproveTxHash}}%0A%0AAmount%20to%20send%3A%20{{orderResult.input.amount}}%20{{orderResult.input.currency}}%0A%0AAmount%20to%20receive%3A%20{{orderResult.output.amount}}%20{{orderResult.output.currency}}%0A%0ARate%3A%20{{swapOrder.swapRate}}%20{{swapOrder.swapPair}}%0A%0A"
href="mailto:support@myetherwallet.com,support@kyber.network?Subject={{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash}}%20Issue%20regarding%20my%20Kyber%20Swap%20via%20MEW%20&Body=%0APlease%20include%20the%20below%20if%20this%20issue%20is%20regarding%20your%20order.%20%0A%0AREF%20ID%23%3A%20{{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash + '%20%20ApproveTxHash%3A%20' + kyberTransaction.tokenApproveTxHash}}%0A%0AAmount%20to%20send%3A%20{{orderResult.input.amount}}%20{{orderResult.input.currency}}%0A%0AAmount%20to%20receive%3A%20{{orderResult.output.amount}}%20{{orderResult.output.currency}}%0A%0ARate%3A%20{{swapOrder.swapRate}}%20{{swapOrder.swapPair}}%0A%0A"
target="_blank" rel="noopener noreferrer"> Issue with your Swap? Contact support</a></p>
<p ng-click="swapIssue = !swapIssue">
<small>Click here if link doesn't work</small>
</p>
<textarea class="form-control input-sm" rows="9" ng-show="swapIssue" style="max-width: 35rem;margin: auto;">
To: support@myetherwallet.com
To: support@myetherwallet.com, support@kyber.network
Subject: Issue regarding my Kyber Swap via MEW - {{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash}}
Message:
TxHash(s): {{kyberTransaction.ethTxHash ? kyberTransaction.ethTxHash : kyberTransaction.tokenTxHash + " ApproveTxHash: " + kyberTransaction.tokenApproveTxHash}}
Expand All @@ -3687,10 +3688,6 @@ <h5>{{kyberTransaction.ethTxHash}}</h5>
<!-- / Swap Page -->






<main class="tab-pane active"
ng-if="globalService.currentTab==globalService.tabs.offlineTransaction.id"
ng-controller='offlineTxCtrl'
Expand Down
Loading

0 comments on commit 3b6e7d6

Please sign in to comment.