Moves Glidera link to sidebar

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-11 13:11:41 -03:00
parent 66820f7661
commit 67e2cb1d6c
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
13 changed files with 263 additions and 62 deletions

View File

@ -47,8 +47,24 @@
</div>
<div ng-show="!buy.show2faCodeInput && !buy.success">
<form name="buyPriceForm"
ng-submit="buy.get2faCode(index.glideraToken)" novalidate>
<div ng-if="index.glideraToken"
ng-init="otherWallets = buy.otherWallets(index.glideraTestnet)"
ng-click="openWalletsModal(otherWallets)">
<label translate>Wallet</label>
<div class="input">
<input type="text" id="address" name="address" ng-disabled="buy.selectedWalletId"
ng-attr-placeholder="{{'Choose your destination wallet'|translate}}"
ng-model="buy.selectedWalletName" required>
<a class="postfix size-12 m0 text-gray">
<i class="icon-wallet size-18"></i>
</a>
</div>
</div>
<label><span translate>Amount in</span> {{showAlternative ? 'USD' : 'BTC'}}</label>
<div class="input">
<input ng-show="!showAlternative" type="number" id="qty"
@ -82,7 +98,8 @@
<input class="button black expand round"
ng-style="{'background-color':index.backgroundColor}"
type="submit" value="{{'Continue'|translate}}"
ng-disabled="index.glideraLimits.transactDisabledPendingFirstTransaction || !buy.buyPrice.qty || buy.loading">
ng-disabled="index.glideraLimits.transactDisabledPendingFirstTransaction || !buy.buyPrice.qty ||
!buy.selectedWalletAddr || buy.loading">
</div>
</form>
</div>

View File

@ -61,7 +61,7 @@
<p translate>You can buy and sell Bitcoin with a US bank account directly in Copay.</p>
<div class="m10b text-gray size-12" translate>Connect your Glidera account to get started</div>
<div class="box-notification size-12 text-warning" ng-show="index.network == 'testnet'">
<div class="box-notification size-12 text-warning" ng-show="index.glideraTestnet">
<i class="fi-info"></i>
Testnet wallets only work with Glidera Sandbox Accounts
</div>
@ -113,7 +113,7 @@
|| (!index.glideraStatus.userBankAccountIsSetup && index.glideraStatus.bankAccountState != 'VERIFIED'))">
<span translate>Your Glidera account is not ready to transact. Please, verify it at</span>
<a href
ng-init="glideraUrl = index.network == 'testnet' ? 'https://sandbox.glidera.io/login' :
ng-init="glideraUrl = index.glideraTestnet ? 'https://sandbox.glidera.io/login' :
'https://glidera.io/login'"
ng-click="$root.openExternalLink(glideraUrl)">Glidera.io</a>
</div>

View File

@ -25,5 +25,15 @@
<div translate>Create, join or import</div>
</a>
</li>
<li ng-show="index.glideraEnabled">
<a ng-click="$root.go('glidera')" class="oh">
<i class="icon-arrow-right3 size-18 right m10t"></i>
<i class="icon-bank size-24 db left m20r m5t"></i>
<div class="tu text-bold">
<span class="size-12" translate>Buy &amp; Sell Bitcoin</span>
</div>
<div translate>Glidera</div>
</a>
</li>
</ul>
</nav>

View File

@ -95,6 +95,14 @@
{{preferences.bwsurl}}
</span>
</li>
<li class="line-b p20" ng-show="!index.noFocusedWallet">
<span translate>Enable Glidera Service</span>
<switch id="glidera-enabled" name="glideraEnabled" ng-model="glideraEnabled" class="green right"></switch>
</li>
<li class="line-b p20" ng-show="!index.noFocusedWallet && glideraEnabled">
<span translate>Glidera Sandbox</span>
<switch id="glidera-testnet" name="glideraTestnet" ng-model="glideraTestnet" class="green right"></switch>
</li>
<li class="line-b p20" ng-click="$root.go('about')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>About Copay</span>

View File

@ -49,6 +49,21 @@
<div ng-show="!sell.show2faCodeInput && !sell.success">
<form name="sellPriceForm"
ng-submit="sell.get2faCode(index.glideraToken)" novalidate>
<div ng-if="index.glideraToken"
ng-init="otherWallets = sell.otherWallets(index.glideraTestnet)"
ng-click="openWalletsModal(otherWallets)">
<label translate>Wallet</label>
<div class="input">
<input type="text" id="address" name="address" ng-disabled="sell.selectedWalletId"
ng-attr-placeholder="{{'Choose your destination wallet'|translate}}"
ng-model="sell.selectedWalletName" required>
<a class="postfix size-12 m0 text-gray">
<i class="icon-wallet size-18"></i>
</a>
</div>
</div>
<label><span translate>Amount in</span> {{showAlternative ? 'USD' : 'BTC'}}</label>
<div class="input">
<input ng-show="!showAlternative" type="number" id="qty"
@ -83,7 +98,8 @@
<input class="button black expand round"
ng-style="{'background-color':index.backgroundColor}"
type="submit" value="{{'Continue'|translate}}"
ng-disabled="index.glideraLimits.transactDisabledPendingFirstTransaction || !sell.sellPrice.qty || sell.loading">
ng-disabled="index.glideraLimits.transactDisabledPendingFirstTransaction || !sell.sellPrice.qty ||
!sell.selectedWalletId || sell.loading">
</div>
</form>
</div>

View File

@ -112,13 +112,6 @@
ng-style="{'background-color':index.backgroundColor}">{{ (index.alias || index.walletName) | limitTo: 1}}
</div>
<div class="right">
<a ng-show="!index.isShared" class="button outline round light-gray tiny preferences-icon m10r"
ng-click="$root.go('glidera')">
<i class="icon-bank size-18 vm"></i>
<span class="show-for-medium-up">Glidera</span>
</a>
<a ng-click="$root.go('preferences')" class="button outline round light-gray tiny preferences-icon m0">
<i class="fi-widget size-18 vm"></i>
<span class="show-for-medium-up" translate>Preferences</span>

View File

@ -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);
};
});

View File

@ -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);

View File

@ -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();

View File

@ -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);
});

View File

@ -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();
});
});

View File

@ -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) {

View File

@ -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);