Moves Glidera link to sidebar
This commit is contained in:
parent
66820f7661
commit
67e2cb1d6c
13 changed files with 263 additions and 62 deletions
|
|
@ -1,14 +1,81 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('buyGlideraController',
|
||||
function($scope, $timeout, profileService, addressService, glideraService, gettext, gettextCatalog, bwsError) {
|
||||
function($scope, $timeout, $modal, profileService, addressService, glideraService, gettext, gettextCatalog, bwsError, lodash, isChromeApp) {
|
||||
|
||||
this.addr = {};
|
||||
var self = this;
|
||||
this.show2faCodeInput = null;
|
||||
this.error = null;
|
||||
this.success = null;
|
||||
this.loading = null;
|
||||
|
||||
// DISABLE ANIMATION ON CHROMEAPP
|
||||
if (isChromeApp) {
|
||||
var animatedSlideUp = 'full';
|
||||
} else {
|
||||
var animatedSlideUp = 'full animated slideInUp';
|
||||
}
|
||||
|
||||
this.otherWallets = function(testnet) {
|
||||
var network = testnet ? 'testnet' : 'livenet';
|
||||
return lodash.filter(profileService.getWallets(network), function(w) {
|
||||
return w.network == network;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openWalletsModal = function(wallets) {
|
||||
self.error = null;
|
||||
self.selectedWalletId = null;
|
||||
self.selectedWalletName = null;
|
||||
self.selectedWalletAddr = null;
|
||||
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||
$scope.wallets = wallets;
|
||||
$scope.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
$scope.selectWallet = function(walletId, walletName) {
|
||||
if (!profileService.getClient(walletId).isComplete()) {
|
||||
self.error = bwsError.msg({'code': 'WALLET_NOT_COMPLETE'}, gettextCatalog.getString('Could not choose the wallet'));
|
||||
$modalInstance.dismiss('cancel');
|
||||
return;
|
||||
}
|
||||
addressService.getAddress(walletId, false, function(err, walletAddr) {
|
||||
if (err) {
|
||||
self.error = bwsError.cb(err, gettext('Could not create address'));
|
||||
$modalInstance.dismiss('cancel');
|
||||
return;
|
||||
}
|
||||
$modalInstance.close({
|
||||
'walletId': walletId,
|
||||
'walletName': walletName,
|
||||
'walletAddr': walletAddr
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'views/modals/wallets.html',
|
||||
windowClass: animatedSlideUp,
|
||||
controller: ModalInstanceCtrl,
|
||||
});
|
||||
|
||||
modalInstance.result.finally(function() {
|
||||
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
||||
m.addClass('slideOutDown');
|
||||
});
|
||||
|
||||
modalInstance.result.then(function(obj) {
|
||||
$timeout(function() {
|
||||
self.selectedWalletId = obj.walletId;
|
||||
self.selectedWalletName = obj.walletName;
|
||||
self.selectedWalletAddr = obj.walletAddr;
|
||||
$scope.$apply();
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
this.getBuyPrice = function(token, price) {
|
||||
var self = this;
|
||||
this.error = null;
|
||||
|
|
@ -46,38 +113,28 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
};
|
||||
|
||||
this.sendRequest = function(token, permissions, twoFaCode) {
|
||||
var fc = profileService.focusedClient;
|
||||
if (!fc) return;
|
||||
var self = this;
|
||||
self.error = null;
|
||||
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
|
||||
if (!addr) {
|
||||
self.error = bwsError.msg(err);
|
||||
$scope.$apply();
|
||||
}
|
||||
else {
|
||||
self.loading = gettext('Buying bitcoin...');
|
||||
var data = {
|
||||
destinationAddress: addr,
|
||||
qty: self.buyPrice.qty,
|
||||
priceUuid: self.buyPrice.priceUuid,
|
||||
useCurrentPrice: false,
|
||||
ip: null
|
||||
};
|
||||
$timeout(function() {
|
||||
glideraService.buy(token, twoFaCode, data, function(err, data) {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
}
|
||||
else {
|
||||
self.success = data;
|
||||
$scope.$emit('Local/GlideraTx');
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
self.loading = gettext('Buying bitcoin...');
|
||||
var data = {
|
||||
destinationAddress: self.selectedWalletAddr,
|
||||
qty: self.buyPrice.qty,
|
||||
priceUuid: self.buyPrice.priceUuid,
|
||||
useCurrentPrice: false,
|
||||
ip: null
|
||||
};
|
||||
$timeout(function() {
|
||||
glideraService.buy(token, twoFaCode, data, function(err, data) {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
}
|
||||
else {
|
||||
self.success = data;
|
||||
$scope.$emit('Local/GlideraTx');
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ angular.module('copayApp.controllers').controller('glideraController',
|
|||
}
|
||||
else if (data && data.access_token) {
|
||||
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
|
||||
$scope.$emit('Local/GlideraTokenUpdated', data.access_token);
|
||||
$scope.$emit('Local/GlideraUpdated', data.access_token);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 100);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ angular.module('copayApp.controllers').controller('glideraUriController',
|
|||
}
|
||||
else if (data && data.access_token) {
|
||||
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
|
||||
$scope.$emit('Local/GlideraTokenUpdated', data.access_token);
|
||||
$scope.$emit('Local/GlideraUpdated', data.access_token);
|
||||
$timeout(function() {
|
||||
go.path('glidera');
|
||||
$scope.$apply();
|
||||
|
|
|
|||
|
|
@ -113,13 +113,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.pendingTxProposalsCountForUs = null;
|
||||
self.setSpendUnconfirmed();
|
||||
|
||||
self.glideraToken = null;
|
||||
self.glideraError = null;
|
||||
self.glideraPermissions = null;
|
||||
self.glideraEmail = null;
|
||||
self.glideraPersonalInfo = null;
|
||||
self.glideraTxs = null;
|
||||
|
||||
$timeout(function() {
|
||||
self.hasProfile = true;
|
||||
self.noFocusedWallet = false;
|
||||
|
|
@ -312,7 +305,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.setBalance(walletStatus.balance);
|
||||
self.otherWallets = lodash.filter(profileService.getWallets(self.network), function(w) {
|
||||
return w.id != self.walletId;
|
||||
});;
|
||||
});
|
||||
|
||||
// Notify external addons or plugins
|
||||
$rootScope.$emit('Local/BalanceUpdated', walletStatus.balance);
|
||||
|
|
@ -393,7 +386,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.setOngoingProcess('updatingPendingTxps', true);
|
||||
$log.debug('Updating PendingTxps');
|
||||
fc.getTxProposals({}, function(err, txps) {
|
||||
console.log('[index.js:395]',txps); //TODO
|
||||
self.setOngoingProcess('updatingPendingTxps', false);
|
||||
if (err) {
|
||||
self.handleError(err);
|
||||
|
|
@ -838,16 +830,27 @@ console.log('[index.js:395]',txps); //TODO
|
|||
};
|
||||
|
||||
self.initGlidera = function(accessToken) {
|
||||
if (self.isShared) return;
|
||||
self.glideraEnabled = configService.getSync().glidera.enabled;
|
||||
self.glideraTestnet = configService.getSync().glidera.testnet;
|
||||
var network = self.glideraTestnet ? 'testnet' : 'livenet';
|
||||
|
||||
self.glideraToken = null;
|
||||
self.glideraError = null;
|
||||
self.glideraPermissions = null;
|
||||
self.glideraEmail = null;
|
||||
self.glideraPersonalInfo = null;
|
||||
self.glideraTxs = null;
|
||||
self.glideraStatus = null;
|
||||
|
||||
glideraService.setCredentials(self.network);
|
||||
if (!self.glideraEnabled || self.isShared) return;
|
||||
|
||||
glideraService.setCredentials(network);
|
||||
|
||||
var getToken = function(cb) {
|
||||
if (accessToken) {
|
||||
cb(null, accessToken);
|
||||
} else {
|
||||
storageService.getGlideraToken(self.network, cb);
|
||||
storageService.getGlideraToken(network, cb);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -959,7 +962,7 @@ console.log('[index.js:395]',txps); //TODO
|
|||
});
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/GlideraTokenUpdated', function(event, accessToken) {
|
||||
$rootScope.$on('Local/GlideraUpdated', function(event, accessToken) {
|
||||
self.initGlidera(accessToken);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ angular.module('copayApp.controllers').controller('preferencesController',
|
|||
isoCode: config.wallet.settings.alternativeIsoCode
|
||||
};
|
||||
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||
$scope.glideraEnabled = config.glidera.enabled;
|
||||
$scope.glideraTestnet = config.glidera.testnet;
|
||||
var fc = profileService.focusedClient;
|
||||
if (fc)
|
||||
$scope.encrypt = fc.hasPrivKeyEncrypted();
|
||||
|
|
@ -61,8 +63,36 @@ angular.module('copayApp.controllers').controller('preferencesController',
|
|||
}
|
||||
});
|
||||
|
||||
var unwatchGlideraEnabled = $scope.$watch('glideraEnabled', function(newVal, oldVal) {
|
||||
if (newVal == oldVal) return;
|
||||
var opts = {
|
||||
glidera: {
|
||||
enabled: newVal
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
$rootScope.$emit('Local/GlideraUpdated');
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
});
|
||||
|
||||
var unwatchGlideraTestnet = $scope.$watch('glideraTestnet', function(newVal, oldVal) {
|
||||
if (newVal == oldVal) return;
|
||||
var opts = {
|
||||
glidera: {
|
||||
testnet: newVal
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
$rootScope.$emit('Local/GlideraUpdated');
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
unwatch();
|
||||
unwatchSpendUnconfirmed();
|
||||
unwatchGlideraEnabled();
|
||||
unwatchGlideraTestnet();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||
function($scope, $timeout, $log, gettext, gettextCatalog, configService, profileService, addressService, feeService, glideraService, bwsError) {
|
||||
function($scope, $timeout, $log, $modal, gettext, gettextCatalog, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, isChromeApp) {
|
||||
|
||||
var self = this;
|
||||
var config = configService.getSync();
|
||||
this.data = {};
|
||||
this.show2faCodeInput = null;
|
||||
|
|
@ -11,6 +12,65 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
this.loading = null;
|
||||
this.currentSpendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||
this.currentFeeLevel = config.wallet.settings.feeLevel || 'normal';
|
||||
var fc;
|
||||
|
||||
// DISABLE ANIMATION ON CHROMEAPP
|
||||
if (isChromeApp) {
|
||||
var animatedSlideUp = 'full';
|
||||
} else {
|
||||
var animatedSlideUp = 'full animated slideInUp';
|
||||
}
|
||||
|
||||
this.otherWallets = function(testnet) {
|
||||
var network = testnet ? 'testnet' : 'livenet';
|
||||
return lodash.filter(profileService.getWallets(network), function(w) {
|
||||
return w.network == network && w.m == 1;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openWalletsModal = function(wallets) {
|
||||
self.error = null;
|
||||
self.selectedWalletId = null;
|
||||
self.selectedWalletName = null;
|
||||
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||
$scope.wallets = wallets;
|
||||
$scope.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
$scope.selectWallet = function(walletId, walletName) {
|
||||
if (!profileService.getClient(walletId).isComplete()) {
|
||||
self.error = bwsError.msg({'code': 'WALLET_NOT_COMPLETE'}, gettextCatalog.getString('Could not choose the wallet'));
|
||||
$modalInstance.dismiss('cancel');
|
||||
return;
|
||||
}
|
||||
$modalInstance.close({
|
||||
'walletId': walletId,
|
||||
'walletName': walletName,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'views/modals/wallets.html',
|
||||
windowClass: animatedSlideUp,
|
||||
controller: ModalInstanceCtrl,
|
||||
});
|
||||
|
||||
modalInstance.result.finally(function() {
|
||||
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
||||
m.addClass('slideOutDown');
|
||||
});
|
||||
|
||||
modalInstance.result.then(function(obj) {
|
||||
$timeout(function() {
|
||||
self.selectedWalletId = obj.walletId;
|
||||
self.selectedWalletName = obj.walletName;
|
||||
fc = profileService.getClient(obj.walletId);
|
||||
$scope.$apply();
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
this.getSellPrice = function(token, price) {
|
||||
var self = this;
|
||||
|
|
@ -50,7 +110,6 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
|
||||
this.createTx = function(token, permissions, twoFaCode) {
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
self.error = null;
|
||||
|
||||
this.loading = gettext('Selling Bitcoin...');
|
||||
|
|
@ -58,7 +117,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
|
||||
if (!refundAddress) {
|
||||
self.loading = null;
|
||||
self.error = bwsError.msg(err);
|
||||
self.error = bwsError.msg(err, gettext('Could not create address'));
|
||||
return;
|
||||
}
|
||||
glideraService.getSellAddress(token, function(error, sellAddress) {
|
||||
|
|
@ -139,7 +198,6 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
|
||||
var _signTx = function(txp, cb) {
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
fc.signTxProposal(txp, function(err, signedTx) {
|
||||
profileService.lockFC();
|
||||
if (err) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
}
|
||||
},
|
||||
|
||||
// External services
|
||||
glidera: {
|
||||
enabled: true,
|
||||
testnet: false
|
||||
},
|
||||
|
||||
rates: {
|
||||
url: 'https://insight.bitpay.com:443/api/rates',
|
||||
},
|
||||
|
|
@ -63,6 +69,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
if (!configCache.wallet.settings.unitCode) {
|
||||
configCache.wallet.settings.unitCode = defaultConfig.wallet.settings.unitCode;
|
||||
}
|
||||
if (!configCache.glidera) {
|
||||
configCache.glidera = defaultConfig.glidera;
|
||||
}
|
||||
|
||||
} else {
|
||||
configCache = lodash.clone(defaultConfig);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue