mirror of https://github.com/BTCPrivate/copay.git
Sell
This commit is contained in:
parent
693b0da4a2
commit
40113052f4
|
@ -1,7 +1,7 @@
|
|||
<div
|
||||
class="topbar-container"
|
||||
ng-include="'views/includes/topbar.html'"
|
||||
ng-init="titleSection='Buy Bitcoin'; goBackToState = 'glidera'">
|
||||
ng-init="titleSection='Buy'; goBackToState = 'glidera'">
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
|||
<div class="rect4"></div>
|
||||
<div class="rect5"></div>
|
||||
</div>
|
||||
<span translate>Sending request to Glidera...</span>
|
||||
<span>{{buy.loading|translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
<div ng-show="!buy.show2faCodeInput && !buy.success">
|
||||
<form name="buyPriceForm"
|
||||
ng-submit="buy.get2faCode(index.glideraToken)" novalidate>
|
||||
<label>Amount in {{showAlternative ? 'USD' : 'BTC'}}</label>
|
||||
<label><span translate>Amount in</span> {{showAlternative ? 'USD' : 'BTC'}}</label>
|
||||
<div class="input">
|
||||
<input ng-show="!showAlternative" type="number" id="qty"
|
||||
name="qty" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
|
@ -49,7 +49,7 @@
|
|||
</div>
|
||||
|
||||
<input class="button dark-gray outline round expand"
|
||||
type="submit" value="Continue" ng-disabled="!buy.buyPrice.qty || buy.loading">
|
||||
type="submit" value="{{'Continue'|translate}}" ng-disabled="!buy.buyPrice.qty || buy.loading">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -62,10 +62,10 @@
|
|||
</p>
|
||||
<form name="buyForm"
|
||||
ng-submit="buy.sendRequest(index.glideraToken, index.glideraPermissions, twoFaCode)" novalidate>
|
||||
<label>Enter 2FA Code</label>
|
||||
<label translate>Enter 2FA Code</label>
|
||||
<input type="number" ng-model="twoFaCode" required>
|
||||
<input class="button dark-gray outline round expand"
|
||||
type="submit" value="Buy Bitcoin" ng-disabled="buyForm.$invalid || buy.loading">
|
||||
type="submit" value="{{'Buy'|translate}}" ng-disabled="buyForm.$invalid || buy.loading">
|
||||
</form>
|
||||
</div>
|
||||
<div class="box-notification" ng-show="buy.error && !buy.success">
|
||||
|
@ -74,13 +74,13 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="text-center" ng-show="buy.success">
|
||||
<h1>Purchase complete</h1>
|
||||
<h1 translate>Purchase complete</h1>
|
||||
<p class="text-gray" translate>
|
||||
A transfer has been initiated from your bank account. Your bitcoin should arrive in your wallet in 4-6 business days.
|
||||
</p>
|
||||
|
||||
<button class="outline dark-gray round expand"
|
||||
ng-click="$root.go('glidera')">
|
||||
ng-click="$root.go('glidera')" translate>
|
||||
Finish
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -1,19 +1,32 @@
|
|||
<div
|
||||
class="topbar-container"
|
||||
ng-include="'views/includes/topbar.html'"
|
||||
ng-init="titleSection='Sell Bitcoin'; goBackToState = 'glidera'">
|
||||
ng-init="titleSection='Sell'; goBackToState = 'glidera'">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="content glidera p20v"
|
||||
ng-controller="sellGlideraController as sell">
|
||||
<div class="content glidera p20v" ng-controller="sellGlideraController as sell">
|
||||
|
||||
<div class="onGoingProcess" ng-show="sell.loading">
|
||||
<div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
|
||||
<div class="spinner">
|
||||
<div class="rect1"></div>
|
||||
<div class="rect2"></div>
|
||||
<div class="rect3"></div>
|
||||
<div class="rect4"></div>
|
||||
<div class="rect5"></div>
|
||||
</div>
|
||||
<span>{{sell.loading|translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns">
|
||||
|
||||
<div ng-show="!sell.show2faCodeInput && !sell.success">
|
||||
<form name="sellPriceForm"
|
||||
ng-submit="sell.get2faCode(index.glideraToken)" novalidate>
|
||||
<label>Amount in {{showAlternative ? 'USD' : 'BTC'}}</label>
|
||||
<label><span translate>Amount in</span> {{showAlternative ? 'USD' : 'BTC'}}</label>
|
||||
<div class="input">
|
||||
<input ng-show="!showAlternative" type="number" id="qty"
|
||||
name="qty" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
|
@ -28,42 +41,47 @@
|
|||
ng-click="showAlternative = true; qty = null; sell.sellPrice = null">BTC</a>
|
||||
<a ng-show="showAlternative" class="postfix"
|
||||
ng-click="showAlternative = false; fiat = null; sell.sellPrice = null">USD</a>
|
||||
<input class="button dark-gray outline round"
|
||||
type="submit" value="Continue" ng-disabled="!sell.sellPrice.qty">
|
||||
|
||||
<div class="text-center text-gray size-12 m20b" ng-show="sell.sellPrice.qty">
|
||||
Sell
|
||||
<span ng-show="qty">${{sell.sellPrice.subtotal}} {{sell.sellPrice.currency}} in Bitcoin</span>
|
||||
<span ng-show="fiat">{{sell.sellPrice.qty}} BTC</span>
|
||||
at ${{sell.sellPrice.price}} {{sell.sellPrice.currency}}
|
||||
</div>
|
||||
|
||||
<input class="button dark-gray outline round expand"
|
||||
type="submit" value="{{'Continue'|translate}}" ng-disabled="!sell.sellPrice.qty || sell.loading">
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-gray size-12 m10b" ng-show="sell.sellPrice.qty">
|
||||
Sell
|
||||
<span ng-show="qty">${{sell.sellPrice.subtotal}} {{sell.sellPrice.currency}} in Bitcoin</span>
|
||||
<span ng-show="fiat">{{sell.sellPrice.qty}} BTC</span>
|
||||
at ${{sell.sellPrice.price}} {{sell.sellPrice.currency}}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div ng-show="sell.show2faCodeInput && !sell.success">
|
||||
<p class="text-center text-gray">
|
||||
The bitcoin amount of {{sell.sellPrice.qty}} will be immediately sent from your bitcoin
|
||||
wallet ({{index.walletName}}) to Glidera.
|
||||
<p class="text-center text-gray" translate>
|
||||
The bitcoin amount of {{sell.sellPrice.qty}} will be immediately sent from your bitcoin wallet ({{index.walletName}}) to Glidera.
|
||||
</p>
|
||||
<p class="text-center text-gray">
|
||||
The total of ${{sell.sellPrice.subtotal}} {{sell.sellPrice.currency}} will be deposited
|
||||
in your bank account in 4-6 business days.
|
||||
<p class="text-center text-gray" translate>
|
||||
The total of ${{sell.sellPrice.subtotal}} {{sell.sellPrice.currency}} will be deposited in your bank account in 4-6 business days.
|
||||
</p>
|
||||
<form name="sellForm"
|
||||
ng-submit="sell.createTx(index.glideraToken, twoFaCode)" novalidate>
|
||||
<label>Enter 2FA Code</label>
|
||||
ng-submit="sell.createTx(index.glideraToken, index.glideraPermissions, twoFaCode)" novalidate>
|
||||
<label translate>Enter 2FA Code</label>
|
||||
<input type="number" ng-model="twoFaCode" required>
|
||||
<input class="button dark-gray outline round"
|
||||
type="submit" value="Sell Bitcoin">
|
||||
<input class="button dark-gray outline round expand"
|
||||
type="submit" value="{{'Sell'|translate}}" ng-disabled="sellForm.$invalid || sell.loading">
|
||||
</form>
|
||||
</div>
|
||||
<div class="box-notification" ng-show="sell.error && !sell.success">
|
||||
<span class="text-warning size-14">
|
||||
{{sell.error|translate}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-center" ng-show="sell.success">
|
||||
<h1>Sale complete</h1>
|
||||
<p class="text-gray">
|
||||
<h1 translate>Sale complete</h1>
|
||||
<p class="text-gray" translate>
|
||||
A transfer has been initiated to your bank account and should arrive in 4-6 business days.
|
||||
</p>
|
||||
|
||||
<button class="outline dark-gray round expand"
|
||||
ng-click="$root.go('glidera')">Finish</button>
|
||||
ng-click="$root.go('glidera')" translate>Finish</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -168,26 +168,18 @@
|
|||
</div>
|
||||
|
||||
<div ng-if="index.txps[0]">
|
||||
<div ng-show="index.requiresMultipleSignatures">
|
||||
<h4 class="title m0" translate>Payment Proposals</h4>
|
||||
<div class="last-transactions pr" ng-repeat="tx in index.txps"
|
||||
ng-include="index.txTemplateUrl">
|
||||
</div>
|
||||
|
||||
<div class="text-gray text-center size-12 p10t"
|
||||
ng-show="index.lockedBalanceSat && !index.updatingStatus">
|
||||
<span translate>Total Locked Balance</span>:
|
||||
<b>{{index.lockedBalanceStr}} </b>
|
||||
<span> {{index.lockedBalanceAlternative}}
|
||||
{{index.alternativeIsoCode}} </span>
|
||||
</div>
|
||||
<h4 ng-show="index.requiresMultipleSignatures" class="title m0" translate>Payment Proposals</h4>
|
||||
<h4 ng-show="!index.requiresMultipleSignatures" class="title m0" translate>Unsent transactions</h4>
|
||||
<div class="last-transactions pr" ng-repeat="tx in index.txps"
|
||||
ng-include="index.txTemplateUrl">
|
||||
</div>
|
||||
|
||||
<div ng-show="!index.requiresMultipleSignatures">
|
||||
<h4 class="title m0" translate>Unsent transactions</h4>
|
||||
<div class="last-transactions pr" ng-repeat="tx in index.txps"
|
||||
ng-include="index.txTemplateUrl">
|
||||
</div>
|
||||
<div class="text-gray text-center size-12 p10t"
|
||||
ng-show="index.lockedBalanceSat && !index.updatingStatus">
|
||||
<span translate>Total Locked Balance</span>:
|
||||
<b>{{index.lockedBalanceStr}} </b>
|
||||
<span> {{index.lockedBalanceAlternative}}
|
||||
{{index.alternativeIsoCode}} </span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="extra-margin-bottom"></div>
|
||||
|
|
|
@ -7,6 +7,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
this.show2faCodeInput = null;
|
||||
this.error = null;
|
||||
this.success = null;
|
||||
this.loading = null;
|
||||
|
||||
this.getBuyPrice = function(token, price) {
|
||||
var self = this;
|
||||
|
@ -26,14 +27,15 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
|
||||
this.get2faCode = function(token) {
|
||||
var self = this;
|
||||
this.loading = true;
|
||||
this.loading = gettext('Sending 2FA code...');
|
||||
$timeout(function() {
|
||||
glideraService.get2faCode(token, function(err, sent) {
|
||||
self.loading = false;
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = gettext('Glidera could not the 2FA code to your phone');
|
||||
self.error = gettext('Glidera could not send the 2FA code to your phone');
|
||||
}
|
||||
else {
|
||||
self.error = null;
|
||||
self.show2faCodeInput = sent;
|
||||
}
|
||||
});
|
||||
|
@ -51,7 +53,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
$scope.$apply();
|
||||
}
|
||||
else {
|
||||
self.loading = true;
|
||||
self.loading = gettext('Buying bitcoin...');
|
||||
var data = {
|
||||
destinationAddress: addr,
|
||||
qty: self.buyPrice.qty,
|
||||
|
@ -61,7 +63,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
};
|
||||
$timeout(function() {
|
||||
glideraService.buy(token, twoFaCode, data, function(err, data) {
|
||||
self.loading = false;
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = gettext('Could not buy bitcoin');
|
||||
}
|
||||
|
|
|
@ -393,6 +393,7 @@ 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);
|
||||
|
@ -950,6 +951,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.updateGlidera(accessToken, permissions);
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/GlideraError', function(event) {
|
||||
self.debouncedUpdate();
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
|
||||
self.updateAll();
|
||||
self.updateTxHistory();
|
||||
|
|
|
@ -7,38 +7,64 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
this.data = {};
|
||||
this.show2faCodeInput = null;
|
||||
this.success = null;
|
||||
this.error = null;
|
||||
this.loading = null;
|
||||
this.currentSpendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||
this.currentFeeLevel = config.wallet.settings.feeLevel || 'normal';
|
||||
|
||||
this.getSellPrice = function(token, price) {
|
||||
var self = this;
|
||||
if (!price || (price && !price.qty && !price.fiat)) {
|
||||
this.error = null;
|
||||
this.sellPrice = null;
|
||||
return;
|
||||
}
|
||||
glideraService.sellPrice(token, price, function(error, sellPrice) {
|
||||
self.sellPrice = sellPrice;
|
||||
glideraService.sellPrice(token, price, function(err, sellPrice) {
|
||||
if (err) {
|
||||
self.error = gettext('Glidera could not get pricing to sell bitcoin');
|
||||
}
|
||||
else {
|
||||
self.error = null;
|
||||
self.sellPrice = sellPrice;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.get2faCode = function(token) {
|
||||
var self = this;
|
||||
this.loading = gettext('Sending 2FA code...');
|
||||
$timeout(function() {
|
||||
glideraService.get2faCode(token, function(error, sent) {
|
||||
self.show2faCodeInput = sent;
|
||||
glideraService.get2faCode(token, function(err, sent) {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = gettext('Glidera could not send the 2FA code to your phone');
|
||||
}
|
||||
else {
|
||||
self.show2faCodeInput = sent;
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
this.createTx = function(token, twoFaCode) {
|
||||
this.createTx = function(token, permissions, twoFaCode) {
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
self.error = null;
|
||||
|
||||
this.loading = gettext('Selling Bitcoin...');
|
||||
$timeout(function() {
|
||||
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
|
||||
if (!refundAddress) return;
|
||||
if (!refundAddress) {
|
||||
self.loading = null;
|
||||
self.error = gettext('Could not get the bitcoin address');
|
||||
return;
|
||||
}
|
||||
glideraService.getSellAddress(token, function(error, sellAddress) {
|
||||
if (!sellAddress) return;
|
||||
if (!sellAddress) {
|
||||
self.loading = null;
|
||||
self.error = gettext('Could not get the destination bitcoin address');
|
||||
return;
|
||||
}
|
||||
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
|
||||
|
||||
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
||||
|
@ -47,6 +73,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
toAddress: sellAddress,
|
||||
amount: amount,
|
||||
message: 'Glidera',
|
||||
customData: {'glideraToken': token},
|
||||
payProUrl: null,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||
|
@ -54,32 +81,48 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
if (err) {
|
||||
profileService.lockFC();
|
||||
$log.error(err);
|
||||
$timeout(function() {
|
||||
self.loading = null;
|
||||
self.error = gettext('Could not create transaction');
|
||||
}, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fc.canSign()) {
|
||||
self.loading = null;
|
||||
$log.info('No signing proposal: No private key');
|
||||
return;
|
||||
}
|
||||
|
||||
_signTx(txp, function(err, rawTx) {
|
||||
_signTx(txp, function(err, txp, rawTx) {
|
||||
profileService.lockFC();
|
||||
if (err) {
|
||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
self.loading = null;
|
||||
self.error = err;
|
||||
$scope.$apply();
|
||||
}
|
||||
else {
|
||||
var data = {
|
||||
refundAddress: refundAddress,
|
||||
signedTransaction: rawTx,
|
||||
priceUuid: self.sellPrice.priceUuid,
|
||||
useCurrentPrice: false,
|
||||
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
|
||||
ip: null
|
||||
};
|
||||
glideraService.sell(token, twoFaCode, data, function(error, data) {
|
||||
self.success = data
|
||||
glideraService.sell(token, twoFaCode, data, function(err, data) {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = gettext('Could not sell bitcoin');
|
||||
fc.removeTxProposal(txp, function(err, txpb) {
|
||||
$timeout(function() {
|
||||
$scope.$emit('Local/GlideraError');
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
else {
|
||||
self.success = data;
|
||||
$scope.$emit('Local/GlideraUpdated', token, permissions);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -98,16 +141,16 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
fc.signTxProposal(txp, function(err, signedTx) {
|
||||
profileService.lockFC();
|
||||
if (err) {
|
||||
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
|
||||
err = gettext('The payment was created but could not be signed');
|
||||
return cb(err);
|
||||
}
|
||||
else {
|
||||
if (signedTx.status == 'accepted') {
|
||||
return cb(null, txp, signedTx.raw);
|
||||
|
||||
if (signedTx.status == 'accepted') {
|
||||
return cb(null, signedTx.raw);
|
||||
|
||||
} else {
|
||||
return cb(true);
|
||||
console.log('NO ACCEPTED TX');
|
||||
} else {
|
||||
return cb(gettext('The transaction could not be signed'));
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue