new animation when receiving a payment
This commit is contained in:
parent
9fff29b209
commit
19b16a491f
5 changed files with 219 additions and 1 deletions
|
|
@ -5,10 +5,14 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
var listeners = [];
|
||||
$scope.bchAddressType = { type: 'cashaddr' };
|
||||
var bchAddresses = {};
|
||||
$scope.payment_recieved = false;
|
||||
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
$scope.isNW = platformInfo.isNW;
|
||||
|
||||
var currentAddressSocket = {};
|
||||
var paymentSubscriptionObj = { op:"addr_sub" }
|
||||
|
||||
$scope.requestSpecificAmount = function() {
|
||||
$state.go('tabs.paymentRequest.amount', {
|
||||
id: $scope.wallet.credentials.walletId,
|
||||
|
|
@ -28,11 +32,39 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
popupService.showAlert(err);
|
||||
}
|
||||
|
||||
//close existing socket
|
||||
if (currentAddressSocket.close === 'function') {
|
||||
currentAddressSocket.close();
|
||||
}
|
||||
|
||||
if ($scope.wallet.coin == 'bch') {
|
||||
bchAddresses = bitcoinCashJsService.translateAddresses(addr);
|
||||
$scope.addr = bchAddresses[$scope.bchAddressType.type];
|
||||
|
||||
// listen to bch address
|
||||
currentAddressSocket = new WebSocket("wss://ws.blockchain.info/bch/inv");
|
||||
paymentSubscriptionObj.addr = bchAddresses['legacy'];
|
||||
|
||||
} else {
|
||||
$scope.addr = addr;
|
||||
|
||||
// listen to btc address
|
||||
currentAddressSocket = new WebSocket("wss://ws.blockchain.info/inv");
|
||||
paymentSubscriptionObj.addr = $scope.addr
|
||||
}
|
||||
|
||||
// create subscription
|
||||
var msg = JSON.stringify(paymentSubscriptionObj);
|
||||
currentAddressSocket.onopen = function (event) {
|
||||
console.log("message sent: " + msg);
|
||||
currentAddressSocket.send(msg);
|
||||
}
|
||||
|
||||
|
||||
// listen for response
|
||||
currentAddressSocket.onmessage = function (event) {
|
||||
console.log("message received:" + event.data);
|
||||
receivedPayment(event.data);
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
|
|
@ -41,6 +73,56 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
});
|
||||
};
|
||||
|
||||
var receivedPayment = function(data) {
|
||||
data = JSON.parse(data);
|
||||
//example payment data
|
||||
/*{
|
||||
"op": "utx",
|
||||
"x": {
|
||||
"lock_time": 0,
|
||||
"ver": 1,
|
||||
"size": 192,
|
||||
"inputs": [
|
||||
{
|
||||
"sequence": 4294967295,
|
||||
"prev_out": {
|
||||
"spent": true,
|
||||
"tx_index": 99005468,
|
||||
"type": 0,
|
||||
"addr": "1BwGf3z7n2fHk6NoVJNkV32qwyAYsMhkWf",
|
||||
"value": 65574000,
|
||||
"n": 0,
|
||||
"script": "76a91477f4c9ee75e449a74c21a4decfb50519cbc245b388ac"
|
||||
},
|
||||
"script": "483045022100e4ff962c292705f051c2c2fc519fa775a4d8955bce1a3e29884b2785277999ed02200b537ebd22a9f25fbbbcc9113c69c1389400703ef2017d80959ef0f1d685756c012102618e08e0c8fd4c5fe539184a30fe35a2f5fccf7ad62054cad29360d871f8187d"
|
||||
}
|
||||
],
|
||||
"time": 1440086763,
|
||||
"tx_index": 99006637,
|
||||
"vin_sz": 1,
|
||||
"hash": "0857b9de1884eec314ecf67c040a2657b8e083e1f95e31d0b5ba3d328841fc7f",
|
||||
"vout_sz": 1,
|
||||
"relayed_by": "127.0.0.1",
|
||||
"out": [
|
||||
{
|
||||
"spent": false,
|
||||
"tx_index": 99006637,
|
||||
"type": 0,
|
||||
"addr": "1A828tTnkVFJfSvLCqF42ohZ51ksS3jJgX",
|
||||
"value": 65564000,
|
||||
"n": 0,
|
||||
"script": "76a914640cfdf7b79d94d1c980133e3587bd6053f091f388ac"
|
||||
}
|
||||
]
|
||||
}
|
||||
}*/
|
||||
|
||||
if (data.op == "utx") {
|
||||
$scope.payment_recieved = true
|
||||
$scope.$apply();
|
||||
}
|
||||
}
|
||||
|
||||
$scope.displayAddress = function(type) {
|
||||
$scope.bchAddressType.type = type;
|
||||
$scope.addr = bchAddresses[$scope.bchAddressType.type];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue