Skip to content

Commit

Permalink
Merge pull request #754 from faizkhan00/add-cancel
Browse files Browse the repository at this point in the history
Add cancel
  • Loading branch information
achamely committed Jul 15, 2014
2 parents 72eea06 + 072ca42 commit 0a97251
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 41 deletions.
7 changes: 7 additions & 0 deletions www/js/WalletController.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ function WalletTradePendingController($scope, $http, $q, userService, hashExplor
);
return addresses;
}

$scope.isCancel=true;
$scope.confirmCancel = function(tx) {
$scope.selectedAddress = tx.from_address;
$scope.selectedCoin_extra = (+tx.currencyId) == 1 ? 'MSC' : 'TMSC';
$scope.cancelTrig=!$scope.cancelTrig;
}
}


25 changes: 21 additions & 4 deletions www/js/WalletSellAssetsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall

// [ Template Initialization ]

if ($scope.isCancel == true) {
$scope.activeCurrencyPair=['BTC','BTC']; // set defaults for Cancel
}

$scope.currencySaleList = $scope.currencyList.filter(function(currency){
if (currency.symbol == $scope.activeCurrencyPair[1] )
$scope.$parent.$parent.selectedCoin = currency;
Expand Down Expand Up @@ -142,6 +146,7 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
var dustValue = 5430;
var minerMinimum = 10000;
var nonZeroValue = 1;
var cancelFees = (5757*3);
var divisible = $scope.selectedCoin.divisible;

var convertToSatoshi = [
Expand All @@ -168,7 +173,7 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
var balance = divisible ? +convertedValues[4] : +$scope.balanceData[0];
var btcbalance = +convertedValues[5];

var coin = $scope.selectedCoin.symbol;
var coin = $scope.isCancel != true ? $scope.selectedCoin.symbol : $scope.selectedCoin_extra;
var salePricePerCoin = $scope.salePricePerCoin;
var address = $scope.selectedAddress;
var saleBlocks = +$scope.saleBlocks;
Expand All @@ -179,10 +184,10 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
if ($scope.saleForm.$valid == false) {
error += 'make sure all fields are completely filled, ';
}
if (coin == 'BTC') {
if ( $scope.isCancel != true && coin == 'BTC') {
error += 'make sure your sale is for MSC or TMSC, ';
}
if( ((coin == 'MSC') || (coin == 'TMSC')) ) {
if( $scope.isCancel != true && ((coin == 'MSC') || (coin == 'TMSC')) ) {
if (saleAmount < nonZeroValue)
error += 'make sure your send amount is non-zero, ';
if (buyersFee < minerMinimum)
Expand All @@ -197,12 +202,14 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
if (saleBlocks < 1)
error += 'make sure your block timeframe is at least 1, ';
}
if ($scope.isCancel == true && (((cancelFees + minerFees) <= btcbalance) == false) )
error += 'make sure you have enough Bitcoin to cover your transaction fees, ';
if (error.length < 8) {
$scope.$parent.showErrors = false;

// open modal
var modalInstance = $modal.open({
templateUrl: '/partials/wallet_sale_modal.html',
templateUrl: $scope.isCancel == true ? '/partials/wallet_cancel_modal.html' : '/partials/wallet_sale_modal.html',
controller: function($scope, $rootScope, userService, data, prepareSaleTransaction, getUnsignedSaleTransaction, convertSatoshiToDisplayedValue, getDisplayedAbbreviation) {
$scope.sendSuccess = false, $scope.sendError = false, $scope.waiting = false, $scope.privKeyPass = {};
$scope.convertSatoshiToDisplayedValue=convertSatoshiToDisplayedValue,
Expand All @@ -212,6 +219,7 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
$scope.selectedCoin=data.selectedCoin,
$scope.salePricePerCoin= data.price;


$scope.ok = function() {
$scope.clicked = true;
$scope.waiting = true;
Expand Down Expand Up @@ -251,6 +259,15 @@ function WalletSellAssetsController($modal, $scope, $http, $q, userService, wall
}
}
});

modalInstance.result.then(function() {
if ($scope.isCancel)
$scope.$parent.$parent.$parent.cancelTrig = null;
}, function() {
if ($scope.isCancel)
$scope.$parent.$parent.$parent.cancelTrig = null;
});

} else {
error += 'and try again.';
$scope.error = error;
Expand Down
25 changes: 25 additions & 0 deletions www/partials/wallet_cancel_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="modal-body">
<h3 class="text-center"> Confirm Sale Cancellation </h3>
<p><br>
You're about to cancel this sale. If this is correct, please press Cancel Sale below.
If you encounter an error or change your mind feel free to click away from the dialog and try again.
</p>
<div class="pull-right">
<button ng-disabled="clicked" class="btn btn-primary" ng-click="ok()">Yes, cancel this sale</button>
<img class="" src="/assets/img/34-1.gif" ng-show="waiting">
</div>
<br>
</div>
<div class="modal-footer">
<div class="row">
<div ng-show="sendSuccess" class="text-center">
<h4 class="pull-right col-xs-12" style="color:green"> Sale cancelled successfully,
check your transaction <a target="_blank" href="{{url}}">here.</a></h4> <br> <h5><small>It can take up to 20 minutes to update the wallet, please do not make another cancellation during this time.</small></h5>
</div>
<div ng-show="sendError" class="text-center">
<h4 class="col-xs-12" style="color:red;"> Sale not cancelled:
{{error}} </h4>
</div>
</div>
</div>

66 changes: 29 additions & 37 deletions www/partials/wallet_pending.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,41 @@ <h3 ng-hide="orderbook.length == 0"> Active Sell Offers</h3>
<td>{{transaction.formatted_price_per_coin }}</td>
<td >{{transaction.formatted_amount}}</td>
<td >{{transaction.bitcoin_required}}</td>
<td ><button class="btn btn-primary btn-sm" ng-click="purchaseCoin(transaction)" type="submit" disabled>Cancel Offer</button></td>
<td ><button class="btn btn-primary btn-sm" ng-click="confirmCancel(transaction)" type="submit">Cancel Offer</button></td>
</tr>

</table>
<!--<div ng-controller="WalletTradeHistoryController" ng-init="getData(selectedAddress)">
<h4> Wallet Offers History:
<select ng-model="currPair" ng-options="pairObject as pairObject for pairObject in pairs"
ng-change="getData(selectedAddress)">
<option value="">-- choose currency pair --</option>
</select>
for
<select ng-model="selectedAddress" ng-options="addrObject.address as addrObject.address for addrObject in addresses"
ng-change="getData(selectedAddress)">
<option value="">-- choose address --</option>
</select>
</h4>
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Transaction hash</th>
<th>Type</th>
<th>Status</th>
<th>Amount</th>
<th>Transaction time</th>
</tr>
</thead>
<tbody>
</tbody>

<tr ng-repeat="transaction in orderbook">
{{transaction}}
<td> <a href="">{{transaction.tx_hash}}</a></td>
<td>{{transaction.tx_type_str}}</td>
<td>{{transaction.status}}</td>
<td>{{transaction.formatted_amount}}</td>
<td>{{transaction.tx_time | date:'dd MMM yyyy HH:mma Z'}}</td>
</tr>
</table>
</div> -->
</div>

<div class="row" ng-hide="true"> <!-- debug mode is unhide -->
<div ng-controller="WalletAssetsFormController">
<div ng-controller="TransactionGenerationController">
<div ng-controller="WalletSellAssetsController">
<form name="saleForm" ng-submit="validateSaleForm()">
<div ng-show="showErrors" class="alert alert-danger"> <strong> {{error}} </strong> </div>
<input class="form-control" ng-model="selectedCoin_extra" >
<select class="form-control" ng-model="selectedAddress"
ng-options="address for address in addressList"
ng-change="setBalance()" ng-init="setBalance()"
>
<option value=""> -- Choose Address -- </option>
</select>
<input name="amount" type="number" ng-model="saleAmount" class="form-control" ng-init="saleAmount=0.0" required >
<input name="ppc" type="number" ng-model="salePricePerCoin" class="form-control" ng-init="salePricePerCoin=0.0" required >
<input name="blocks" type="number" ng-model="saleBlocks" class="form-control" ng-init="saleBlocks=10" required >
<input name="buyerfee" type="number" ng-model="buyersFee" class="form-control" ng-init="buyersFee=0" required >
<input name="fees" type="number" ng-model="minerFees" class="form-control" ng-init="minerFees=0.0001" min="0.0001" required >
<span class="input-group-addon" >
Available Bitcoin: {{ balanceData[1]}} {{selectedCoin.symbol}}
</span>
<div ng-if="cancelTrig" ng-init="validateSaleForm()"></div>
</form>
</div>
</div>
</div>
</div>

<div class="row" ng-hide="pendingThinking">
<h4 ng-hide="pendingThinking">
<a ng-click="pendingThinking = true"> <strong> < Go back </strong> </a>
Expand Down

0 comments on commit 0a97251

Please sign in to comment.