mirror of https://github.com/BTCPrivate/copay.git
Sell flow completed
This commit is contained in:
parent
ada933d49c
commit
ffa268a827
|
@ -17,7 +17,7 @@
|
|||
"ng-lodash": "~0.2.0",
|
||||
"angular-moment": "0.10.1",
|
||||
"moment": "2.10.3",
|
||||
"angular-bitcore-wallet-client": "0.1.2",
|
||||
"angular-bitcore-wallet-client": "0.1.4",
|
||||
"angular-ui-router": "~0.2.13",
|
||||
"qrcode-decoder-js": "*",
|
||||
"fastclick": "*",
|
||||
|
|
|
@ -1,63 +1,70 @@
|
|||
<div
|
||||
class="topbar-container"
|
||||
ng-include="'views/includes/topbar.html'"
|
||||
ng-init="titleSection='Sell'; goBackToState = 'glidera'">
|
||||
ng-init="titleSection='Sell Bitcoin'; goBackToState = 'glidera'">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="content glidera"
|
||||
<div class="content glidera p20v"
|
||||
ng-controller="sellGlideraController as sell">
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<div class="columns">
|
||||
|
||||
<h1>Sell Bitcoin</h1>
|
||||
<div ng-show="!sell.show2faCodeInput && !sell.success">
|
||||
<form name="sellPriceForm"
|
||||
ng-submit="sell.get2faCode(index.glideraToken)" novalidate>
|
||||
<label>Amount in {{showAlternative ? 'USD' : 'BTC'}}</label>
|
||||
<div class="input">
|
||||
<input ng-show="!showAlternative" type="number" id="qty"
|
||||
name="qty" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-minlength="0.00000001" ng-maxlength="10000000000"
|
||||
ng-model="qty" autocomplete="off" ng-change="sell.getSellPrice(index.glideraToken, {'qty': qty})">
|
||||
|
||||
<form name="form" ng-submit="sell.getSellPrice(index.glideraToken, {'qty': qty, 'fiat': fiat})" novalidate>
|
||||
<label>Amount BTC</label>
|
||||
<input type="number" ng-model="qty">
|
||||
<label>Amount USD</label>
|
||||
<input type="number" ng-model="fiat">
|
||||
<input class="button" type="submit" value="Get Sell Price">
|
||||
</form>
|
||||
<input ng-show="showAlternative" type="number" id="fiat"
|
||||
name="fiat" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="fiat" autocomplete="off" ng-change="sell.getSellPrice(index.glideraToken, {'fiat': fiat})">
|
||||
|
||||
<h2>Sell Price</h2>
|
||||
<ul>
|
||||
<li>qty: {{sell.sellPrice.qty}}
|
||||
<li>price: {{sell.sellPrice.price}}
|
||||
<li>subtotal: {{sell.sellPrice.subtotal}}
|
||||
<li>fees: {{sell.sellPrice.fees}}
|
||||
<li>total: {{sell.sellPrice.total}}
|
||||
<li>currency: {{sell.sellPrice.currency}}
|
||||
<li>expires: {{sell.sellPrice.expires}}
|
||||
<li>priceUuid: {{sell.sellPrice.priceUuid}}
|
||||
</ul>
|
||||
|
||||
<h2>Create Tx</h2>
|
||||
|
||||
<div class="m10b">
|
||||
refundAddress: {{sell.addr[index.walletId]}}<br>
|
||||
sellAddress: {{sell.sellAddress}}
|
||||
<a ng-show="!showAlternative" class="postfix"
|
||||
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>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
<button
|
||||
ng-click="raw = sell.createTx()">
|
||||
Create
|
||||
</button>
|
||||
|
||||
|
||||
<div class="m10b" ng-show="sell.raw">{{sell.raw}}</div>
|
||||
|
||||
<h2>Send 2FA Code</h2>
|
||||
<button ng-click="sell.get2faCode(index.glideraToken)">Send 2FA Code</button>
|
||||
|
||||
<h2>Send TX to Glider</h2>
|
||||
<form name="form2" ng-submit="sell.sendTx(index.glideraToken, twoFaCode)" novalidate>
|
||||
<label>2FA Code
|
||||
<input type="number" ng-model="twoFaCode">
|
||||
</label>
|
||||
<input class="button" type="submit" value="Sell">
|
||||
</form>
|
||||
<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>
|
||||
<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>
|
||||
<form name="sellForm"
|
||||
ng-submit="sell.createTx(index.glideraToken, twoFaCode)" novalidate>
|
||||
<label>Enter 2FA Code</label>
|
||||
<input type="number" ng-model="twoFaCode" required>
|
||||
<input class="button dark-gray outline round"
|
||||
type="submit" value="Sell Bitcoin">
|
||||
</form>
|
||||
</div>
|
||||
<div class="text-center" ng-show="sell.success">
|
||||
<h1>Sale complete</h1>
|
||||
<p class="text-gray">
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,24 +8,6 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
this.error = null;
|
||||
this.success = null;
|
||||
|
||||
this.setDestinationAddress = function() {
|
||||
var self = this;
|
||||
this.addrError = null;
|
||||
var fc = profileService.focusedClient;
|
||||
if (!fc) return;
|
||||
|
||||
$timeout(function() {
|
||||
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
|
||||
if (err) {
|
||||
return;
|
||||
} else {
|
||||
if (addr) self.addr[fc.credentials.walletId] = addr;
|
||||
}
|
||||
$scope.$digest();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.getBuyPrice = function(token, price) {
|
||||
var self = this;
|
||||
if (!price || (price && !price.qty && !price.fiat)) {
|
||||
|
@ -60,9 +42,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
|
|||
useCurrentPrice: false,
|
||||
ip: null
|
||||
};
|
||||
console.log('[sellGlidera.js:128]',token, twoFaCode, addr, data); //TODO
|
||||
glideraService.buy(token, twoFaCode, data, function(error, data) {
|
||||
console.log('[sellGlidera.js:116]', error, data); //TODO
|
||||
self.loading = false;
|
||||
if (error) {
|
||||
self.error = error;
|
||||
|
|
|
@ -851,7 +851,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.initGlidera = function() {
|
||||
if (self.isShared) return;
|
||||
storageService.getGlideraToken(self.network, function(err, val) {
|
||||
if (err) return;
|
||||
if (err || !val) return;
|
||||
else {
|
||||
self.glideraToken = val;
|
||||
glideraService.getTransactions(val, function(error, txs) {
|
||||
|
|
|
@ -4,89 +4,86 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
function($scope, $timeout, $log, gettext, configService, profileService, addressService, feeService, glideraService) {
|
||||
|
||||
var config = configService.getSync();
|
||||
this.addr = {};
|
||||
this.data = {};
|
||||
this.sellAddress = null;
|
||||
this.show2faCodeInput = null;
|
||||
this.success = null;
|
||||
this.currentSpendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||
this.currentFeeLevel = config.wallet.settings.feeLevel || 'normal';
|
||||
|
||||
this.setRefundAddress = function() {
|
||||
var self = this;
|
||||
this.addrError = null;
|
||||
var fc = profileService.focusedClient;
|
||||
if (!fc) return;
|
||||
|
||||
$timeout(function() {
|
||||
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
|
||||
if (err) {
|
||||
self.addrError = err;
|
||||
} else {
|
||||
if (addr) self.addr[fc.credentials.walletId] = addr;
|
||||
}
|
||||
$scope.$digest();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.setSellAddress = function(token) {
|
||||
var self = this;
|
||||
glideraService.getSellAddress(token, function(error, addr) {
|
||||
self.sellAddress = addr.sellAddress;
|
||||
});
|
||||
};
|
||||
|
||||
this.getSellPrice = function(token, price) {
|
||||
var self = this;
|
||||
this.sellAmount = price.qty;
|
||||
if (!price || (price && !price.qty && !price.fiat)) {
|
||||
this.sellPrice = null;
|
||||
return;
|
||||
}
|
||||
glideraService.sellPrice(token, price, function(error, sellPrice) {
|
||||
self.sellPrice = sellPrice;
|
||||
self.setSellAddress(token);
|
||||
self.setRefundAddress();
|
||||
});
|
||||
};
|
||||
|
||||
this.createTx = function() {
|
||||
this.get2faCode = function(token) {
|
||||
var self = this;
|
||||
$timeout(function() {
|
||||
glideraService.get2faCode(token, function(error, sent) {
|
||||
self.show2faCodeInput = sent;
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
this.createTx = function(token, twoFaCode) {
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
|
||||
$timeout(function() {
|
||||
var address = self.sellAddress;
|
||||
var amount = parseInt((self.sellAmount * 100000000).toFixed(0));
|
||||
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
|
||||
if (!refundAddress) return;
|
||||
glideraService.getSellAddress(token, function(error, sellAddress) {
|
||||
if (!sellAddress) return;
|
||||
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
|
||||
|
||||
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
||||
if (err) $log.debug(err);
|
||||
fc.sendTxProposal({
|
||||
toAddress: address,
|
||||
amount: amount,
|
||||
message: 'Glidera',
|
||||
payProUrl: null,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
console.log('[sellGlidera.js:62]',txp); //TODO
|
||||
if (err) {
|
||||
profileService.lockFC();
|
||||
$log.error(err);
|
||||
return;
|
||||
}
|
||||
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
||||
if (err) $log.debug(err);
|
||||
fc.sendTxProposal({
|
||||
toAddress: sellAddress,
|
||||
amount: amount,
|
||||
message: 'Glidera',
|
||||
payProUrl: null,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
if (err) {
|
||||
profileService.lockFC();
|
||||
$log.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fc.canSign()) {
|
||||
$log.info('No signing proposal: No private key');
|
||||
return;
|
||||
}
|
||||
if (!fc.canSign()) {
|
||||
$log.info('No signing proposal: No private key');
|
||||
return;
|
||||
}
|
||||
|
||||
self.signTx(txp, function(err, raw) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
return raw;
|
||||
}
|
||||
_signTx(txp, function(err, 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);
|
||||
}
|
||||
else {
|
||||
var data = {
|
||||
refundAddress: refundAddress,
|
||||
signedTransaction: rawTx,
|
||||
priceUuid: self.sellPrice.priceUuid,
|
||||
useCurrentPrice: false,
|
||||
ip: null
|
||||
};
|
||||
glideraService.sell(token, twoFaCode, data, function(error, data) {
|
||||
self.success = data
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -95,11 +92,10 @@ console.log('[sellGlidera.js:62]',txp); //TODO
|
|||
|
||||
};
|
||||
|
||||
this.signTx = function(txp, cb) {
|
||||
var _signTx = function(txp, cb) {
|
||||
var self = this;
|
||||
var fc = profileService.focusedClient;
|
||||
fc.signTxProposal(txp, function(err, signedTx) {
|
||||
console.log('[sellGlidera.js:96]',signedTx); //TODO
|
||||
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'));
|
||||
|
@ -107,42 +103,13 @@ console.log('[sellGlidera.js:62]',txp); //TODO
|
|||
}
|
||||
|
||||
if (signedTx.status == 'accepted') {
|
||||
var t = profileService.getUtils().buildTx(signedTx);
|
||||
var raw = t.uncheckedSerialize();
|
||||
console.log('[sellGlidera.js:104]',raw); //TODO
|
||||
return cb(null, raw);
|
||||
return cb(null, signedTx.raw);
|
||||
|
||||
} else {
|
||||
return cb(true);
|
||||
console.log('NO ACCEPTED TX');
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.get2faCode = function(token, cb) {
|
||||
var self = this;
|
||||
glideraService.get2faCode(token, function(error, sent) {
|
||||
self.show2faCodeInput = sent;
|
||||
});
|
||||
};
|
||||
|
||||
this.sendTx = function(token, twoFaCode, raw) {
|
||||
var fc = profileService.focusedClient;
|
||||
var self = this;
|
||||
var data = {
|
||||
refundAddress: self.addr[fc.credentials.walletId],
|
||||
signedTransaction: raw,
|
||||
priceUuid: self.sellPrice.priceUuid,
|
||||
useCurrentPrice: false,
|
||||
ip: null
|
||||
};
|
||||
console.log('[sellGlidera.js:128]',token, twoFaCode, data); //TODO
|
||||
glideraService.sell(token, twoFaCode, data, function(error, data) {
|
||||
console.log('[sellGlidera.js:116]',data); //TODO
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -135,7 +135,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
if (!token) return cb('Invalid Token');
|
||||
$http(_get('/user/create_sell_address', token)).then(function(data) {
|
||||
$log.info('Glidera Create Sell Address: SUCCESS');
|
||||
return cb(null, data.data);
|
||||
return cb(null, data.data.sellAddress);
|
||||
}, function(data) {
|
||||
$log.error('Glidera Create Sell Address: ERROR ' + data.statusText);
|
||||
return cb(data.statusText);
|
||||
|
@ -189,11 +189,9 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
useCurrentPrice: data.useCurrentPrice,
|
||||
ip: data.ip
|
||||
};
|
||||
console.log('[glideraService.js:161]',data); //TODO
|
||||
$http(_post('/sell', token, twoFaCode, data)).then(function(data) {
|
||||
console.log('[glideraService.js:168]',data); //TODO
|
||||
$log.info('Glidera Sell: SUCCESS');
|
||||
return cb(null, data);
|
||||
return cb(null, data.data);
|
||||
}, function(data) {
|
||||
$log.error('Glidera Sell: ERROR ' + data.statusText);
|
||||
return cb(data.statusText);
|
||||
|
|
Loading…
Reference in New Issue