payment received socket now works on custom amount screen

This commit is contained in:
Kadir Sekha 2018-03-14 11:58:11 +09:00
commit 6e28268c24
2 changed files with 55 additions and 2 deletions

View file

@ -1,6 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('customAmountController', function($scope, $ionicHistory, txFormatService, platformInfo, configService, profileService, walletService, popupService, bitcoinCashJsService) {
angular.module('copayApp.controllers').controller('customAmountController', function($scope, $ionicHistory, txFormatService, platformInfo, configService, profileService, walletService, popupService, bitcoinCashJsService, $timeout) {
var currentAddressSocket = {};
var paymentSubscriptionObj = { op:"addr_sub" }
$scope.showingPaymentReceived = false;
var showErrorAndBack = function(title, msg) {
popupService.showAlert(title, msg, function() {
@ -38,8 +42,10 @@ angular.module('copayApp.controllers').controller('customAmountController', func
if ($scope.wallet.coin == 'bch') {
bchAddresses = bitcoinCashJsService.translateAddresses(addr);
$scope.address = bchAddresses[$scope.bchAddressType];
prepareWebSocket(bchAddresses['legacy']);
} else {
$scope.address = addr;
prepareWebSocket(addr);
}
$scope.displayAddress = function(type) {
@ -70,6 +76,8 @@ angular.module('copayApp.controllers').controller('customAmountController', func
$scope.amountBtc = amount; // BTC or BCH
$scope.altAmountStr = txFormatService.formatAlternativeStr($scope.wallet.coin, parsedAmount.amountSat);
}
});
});
@ -96,4 +104,39 @@ angular.module('copayApp.controllers').controller('customAmountController', func
return protocol + $scope.address + '?amount=' + $scope.amountBtc;
};
var prepareWebSocket = function(address) {
if (currentAddressSocket.close === 'function') {
currentAddressSocket.close();
}
if ($scope.wallet.coin == 'bch') {
currentAddressSocket = new WebSocket('wss://ws.blockchain.info/bch/inv');
} else {
currentAddressSocket = new WebSocket('wss://ws.blockchain.info/inv/');
}
paymentSubscriptionObj.addr = address;
var msg = JSON.stringify(paymentSubscriptionObj);
currentAddressSocket.onopen = function(event) {
currentAddressSocket.send(msg);
}
currentAddressSocket.onmessage = function(event) {
receivedPayment(event.data);
}
$timeout(function() {
$scope.$apply();
}, 10);
};
var receivedPayment = function(data) {
data = JSON.parse(data);
if (data.op == 'utx') {
$scope.showingPaymentReceived = true;
$scope.$apply();
}
}
});

View file

@ -19,7 +19,7 @@
</ion-nav-buttons>
</ion-nav-bar>
<ion-content scroll="false">
<div class="address" ng-if="address && amountBtc">
<div ng-show="!showingPaymentReceived" class="address" ng-if="address && amountBtc">
<div class="qr-code" copy-to-clipboard="copyToClipboard()">
<qrcode size="220" data="{{ protocolHandler }}:{{address + '?amount=' + amountBtc}}" color="#334"></qrcode>
</div>
@ -62,5 +62,15 @@
</div>
</div>
</div>
<div ng-show="showingPaymentReceived" ng-click="showingPaymentReceived = false">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
<circle class="path circle" fill="none" stroke="#19B234" stroke-width="6" stroke-miterlimit="10" cx="65.1" cy="65.1" r="62.1"/>
<polyline class="path check" fill="none" stroke="#19B234" stroke-width="6" stroke-linecap="round" stroke-miterlimit="10" points="100.2,40.2 51.5,88.8 29.8,67.5 "/>
</svg>
<p class="success animated fadeIn" style="text-align: center">
<br/>Payment Received!<br/>
<br/>Return To Address<br/>
</p>
</div>
</ion-content>
</ion-view>