Skip to content

Commit

Permalink
Merge pull request bitpay#327 from msalcala11/slideToPayComponent
Browse files Browse the repository at this point in the history
Implement Slide to Pay
  • Loading branch information
matiu authored Oct 11, 2016
2 parents 767b523 + 77557f6 commit 8607867
Show file tree
Hide file tree
Showing 30 changed files with 842 additions and 164 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ module.exports = function(grunt) {
'bower_components/angular-clipboard/angular-clipboard.js',
'bower_components/angular-md5/angular-md5.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/ngtouch/src/ngTouch.js',
'angular-pbkdf2/angular-pbkdf2.js',
'angular-bitcore-wallet-client/angular-bitcore-wallet-client.js'
],
Expand All @@ -147,6 +148,7 @@ module.exports = function(grunt) {
'src/js/init.js',
'src/js/trezor-url.js',
'bower_components/trezor-connect/login.js',
'node_modules/bezier-easing/dist/bezier-easing.min.js',
'node_modules/cordova-plugin-qrscanner/dist/cordova-plugin-qrscanner-lib.min.js'
],
dest: 'www/js/copay.js'
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"ng-csv": "~0.3.6",
"ionic-toast": "^0.4.1",
"angular-clipboard": "^1.4.2",
"angular-md5": "^0.1.10"
"angular-md5": "^0.1.10",
"ngtouch": "^1.0.1"
},
"resolutions": {
"angular": "1.5.3"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"adm-zip": "^0.4.7",
"angular": "1.4.6",
"angular-mocks": "1.4.10",
"bezier-easing": "^2.0.3",
"bhttp": "^1.2.1",
"bitcore-wallet-client": "4.2.1",
"bower": "^1.7.9",
Expand Down
1 change: 1 addition & 0 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var modules = [
'ionic',
'ionic-toast',
'angular-clipboard',
'ngTouch',
'ngLodash',
'ngCsv',
'angular-md5',
Expand Down
67 changes: 53 additions & 14 deletions src/js/controllers/confirm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig) {
var cachedTxp = {};
var isChromeApp = platformInfo.isChromeApp;

$ionicConfig.views.swipeBackEnabled(false);

$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isWallet = data.stateParams.isWallet;
$scope.isCard = data.stateParams.isCard;
Expand All @@ -30,6 +32,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
throw ('bad params');
}
$scope.isCordova = platformInfo.isCordova;
$scope.hasClick = platformInfo.hasClick;
$scope.data = {};

var config = configService.getSync().wallet;
Expand All @@ -54,7 +57,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}

var filteredWallets = [];
var index = 0, enoughFunds = false;
var index = 0;
var enoughFunds = false;

lodash.each(wallets, function(w) {
walletService.getStatus(w, {}, function(err, status) {
Expand Down Expand Up @@ -198,14 +202,15 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};

var setSendError = function(msg) {
$scope.sendStatus = '';
popupService.showAlert(gettextCatalog.getString('Error at confirm:'), msg);
};

function apply(txp) {
$scope.fee = txFormatService.formatAmountStr(txp.fee);
$scope.txp = txp;
$scope.$apply();
};
}

var createTx = function(wallet, dryRun, cb) {
var config = configService.getSync().wallet;
Expand Down Expand Up @@ -270,7 +275,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
});
};

$scope.approve = function() {
$scope.approve = function(onSendStatusChange) {
var wallet = $scope.wallet;
if (!wallet) {
return setSendError(gettextCatalog.getString('No wallet selected'));
Expand All @@ -284,9 +289,10 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (err) return setSendError(err);
});
}
ongoingProcess.set('creatingTx', true);

ongoingProcess.set('creatingTx', true, onSendStatusChange);
createTx(wallet, false, function(err, txp) {
ongoingProcess.set('creatingTx', false);
ongoingProcess.set('creatingTx', false, onSendStatusChange);
if (err) return;

var config = configService.getSync();
Expand All @@ -304,24 +310,57 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (!spendingPassEnabled && !touchIdEnabled) {
if (isCordova && bigAmount) {
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
if (!ok) return;
publishAndSign(wallet, txp);
if (!ok) {
$scope.sendStatus = '';
$timeout(function() {
$scope.$apply();
});
return;
}
publishAndSign(wallet, txp, onSendStatusChange);
});
}
else {
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
if (!ok) return;
publishAndSign(wallet, txp);
if (!ok) {
$scope.sendStatus = '';
return;
}
publishAndSign(wallet, txp, onSendStatusChange);
});
}
}
else publishAndSign(wallet, txp);
else publishAndSign(wallet, txp, onSendStatusChange);
});
};

function publishAndSign(wallet, txp) {
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
function statusChangeHandler(processName, showName, isOn) {
$log.debug('statusChangeHandler: ', processName, showName, isOn);
if ((processName === 'broadcastingTx' || ((processName === 'signingTx') && $scope.wallet.m > 1)) && !isOn) {
$scope.sendStatus = 'success';
$scope.$digest();
} else if (showName) {
$scope.sendStatus = showName;
}
}

$scope.statusChangeHandler = statusChangeHandler;

$scope.onConfirm = function() {
$scope.approve(statusChangeHandler);
};

$scope.onSuccessConfirm = function() {
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$scope.sendStatus = '';
$state.go('tabs.send');
};

function publishAndSign(wallet, txp, onSendStatusChange) {
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
}, onSendStatusChange);
}
});
40 changes: 1 addition & 39 deletions src/js/controllers/modals/txStatus.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
'use strict';

angular.module('copayApp.controllers').controller('txStatusController', function($scope, $timeout, $state, $stateParams, $ionicHistory, $log, addressbookService) {
angular.module('copayApp.controllers').controller('txStatusController', function($scope, $timeout) {

if ($scope.cb) $timeout($scope.cb, 100);

var previousView = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName;
$scope.fromSendTab = previousView.match(/tabs.send/) ? true : false;
$scope.fromBitPayCard = previousView.match(/tabs.bitpayCard/) ? true : false;
$scope.fromPayPro = $stateParams.paypro ? true : false;

$scope.cancel = function() {
$scope.txStatusModal.hide();
if ($scope.fromSendTab) {
$ionicHistory.removeBackView();
$state.go('tabs.send');
$timeout(function() {
$state.transitionTo('tabs.home');
}, 100);
} else if ($scope.fromBitPayCard) {
$ionicHistory.removeBackView();
$timeout(function() {
$state.transitionTo('tabs.bitpayCard');
}, 100);
}
};

$scope.save = function(addressbookEntry) {
$scope.txStatusModal.hide();
$ionicHistory.nextViewOptions({
disableAnimate: true,
disableBack: true
});
$ionicHistory.removeBackView();
$state.go('tabs.send.addressbook', {
fromSendTab: $scope.fromSendTab,
addressbookEntry: addressbookEntry
});
}

addressbookService.list(function(err, ab) {
if (err) $log.error(err);
if (ab[$scope.tx.toAddress]) {
$scope.entryExist = true;
$log.debug('Entry already exist');
}
})

});
36 changes: 31 additions & 5 deletions src/js/controllers/modals/txpDetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, ongoingProcess, platformInfo, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, walletService, popupService) {
angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, $log, ongoingProcess, platformInfo, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, walletService, popupService, $state, $ionicHistory) {
var self = $scope.self;
var tx = $scope.tx;
var copayers = $scope.copayers;
Expand All @@ -17,7 +17,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
$scope.canSign = $scope.wallet.canSign() || $scope.wallet.isPrivKeyExternal();
$scope.color = $scope.wallet.color;
$scope.data = {};

$scope.hasClick = platformInfo.hasClick;
initActionList();
checkPaypro();
}
Expand Down Expand Up @@ -66,17 +66,18 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}

var setSendError = function(msg) {
$scope.sendStatus = '';
var error = msg || gettextCatalog.getString('Could not send payment');
popupService.showAlert(gettextCatalog.getString('Error'), error);
}

$scope.sign = function() {
$scope.sign = function(onSendStatusChange) {
$scope.loading = true;
walletService.publishAndSign($scope.wallet, $scope.tx, function(err, txp) {
$scope.$emit('UpdateTx');
if (err) return setSendError(err);
$scope.close();
});
success();
}, onSendStatusChange);
};

function setError(err, prefix) {
Expand Down Expand Up @@ -213,6 +214,31 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
});
};

function statusChangeHandler(processName, showName, isOn) {
$log.debug('statusChangeHandler: ', processName, showName, isOn);
if (showName) {
$scope.sendStatus = showName;
}
}

function success() {
$scope.sendStatus = 'success';
$scope.$digest();
}

$scope.statusChangeHandler = statusChangeHandler;

$scope.onConfirm = function() {
$scope.sign(statusChangeHandler);
};

$scope.onSuccessConfirm = function() {
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$scope.close();
};

$scope.close = function() {
$scope.loading = null;
$scope.txpDetailsModal.hide();
Expand Down
20 changes: 20 additions & 0 deletions src/js/directives/clickToAccept.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

angular.module('copayApp.directives')
.directive('clickToAccept', function() {
return {
restrict: 'E',
templateUrl: 'views/includes/clickToAccept.html',
transclude: true,
scope: {
sendStatus: '=clickSendStatus',
},
link: function(scope, element, attrs) {
scope.$watch('sendStatus', function() {
if(scope.sendStatus !== 'success') {
scope.displaySendStatus = scope.sendStatus;
}
});
}
};
});
19 changes: 0 additions & 19 deletions src/js/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,4 @@ angular.module('copayApp.directives')
});
}
}
})
.directive('accept', function() {
return {
restrict: 'E',
templateUrl: 'views/includes/acceptSlide.html',
scope: {},
link: function(scope, element, attrs) {
scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
scope.slider = data.slider;
});

scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
if (data.slider.activeIndex == 0) {
scope.slider.slideNext();
scope.$emit('accepted');
}
});
}
}
});
Loading

0 comments on commit 8607867

Please sign in to comment.