Buy flow completed

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-02 19:16:59 -03:00
parent 56d6abf360
commit ada933d49c
5 changed files with 107 additions and 72 deletions

View File

@ -1,52 +1,69 @@
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Buy'; goBackToState = 'glidera'">
ng-init="titleSection='Buy Bitcoin'; goBackToState = 'glidera'">
</div>
<div class="content glidera" ng-controller="buyGlideraController as buy">
<div class="content glidera p20v" ng-controller="buyGlideraController as buy">
<div class="row">
<div class="large-12 columns">
<h1>Buy Bitcoin</h1>
<form name="form" ng-submit="buy.getBuyPrice(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 Buy Price">
</form>
<h2>Buy Price</h2>
<ul>
<li>qty: {{buy.buyPrice.qty}}
<li>price: {{buy.buyPrice.price}}
<li>subtotal: {{buy.buyPrice.subtotal}}
<li>fees: {{buy.buyPrice.fees}}
<li>total: {{buy.buyPrice.total}}
<li>currency: {{buy.buyPrice.currency}}
<li>expires: {{buy.buyPrice.expires}}
<li>priceUuid: {{buy.buyPrice.priceUuid}}
</ul>
<div class="m10b">
destinationAddress: {{buy.addr[index.walletId]}}<br>
<div class="columns">
<div ng-show="!buy.show2faCodeInput && !buy.success">
<form name="buyPriceForm"
ng-submit="buy.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="buy.getBuyPrice(index.glideraToken, {'qty': qty})">
<input ng-show="showAlternative" type="number" id="fiat"
name="fiat" ng-attr-placeholder="{{'Amount'|translate}}"
ng-model="fiat" autocomplete="off" ng-change="buy.getBuyPrice(index.glideraToken, {'fiat': fiat})">
<a ng-show="!showAlternative" class="postfix"
ng-click="showAlternative = true; qty = null; buy.buyPrice = null">BTC</a>
<a ng-show="showAlternative" class="postfix"
ng-click="showAlternative = false; fiat = null; buy.buyPrice = null">USD</a>
<input class="button dark-gray outline round"
type="submit" value="Continue" ng-disabled="!buy.buyPrice.qty">
</div>
</form>
<div class="text-gray size-12 m10b" ng-show="buy.buyPrice.qty">
Buy
<span ng-show="qty">${{buy.buyPrice.subtotal}} {{buy.buyPrice.currency}} in Bitcoin</span>
<span ng-show="fiat">{{buy.buyPrice.qty}} BTC</span>
at ${{buy.buyPrice.price}} {{buy.buyPrice.currency}}
</div>
</div>
<div ng-show="buy.show2faCodeInput && !buy.success">
<p class="text-center text-gray">
The purchase price of ${{buy.buyPrice.price}} USD will be immediately withdrawn from your bank account.
</p>
<p class="text-center text-gray">
The total of {{buy.buyPrice.qty}} BTC will be purchased and deposited in your bitcoin wallet ({{index.walletName}}) in 2-4 business days.
</p>
<p class="text-center text-gray">
<form name="buyForm"
ng-submit="buy.sendRequest(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="Buy Bitcoin">
</form>
</div>
<div ng-show="buy.error && !buy.success" class="text-warning m10b">{{buy.error}}</div>
<div class="text-center" ng-show="buy.success">
<h1>Purchase complete</h1>
<p class="text-gray">
A transfer has been initiated from your bank account. Your bitcoin should arrive in your wallet in 4-6 business days.
</p>
<h2>Send 2FA Code</h2>
<button ng-click="buy.get2faCode(index.glideraToken)">Send 2FA Code</button>
<h2>Buy</h2>
<form name="form2" ng-submit="buy.send(index.glideraToken, twoFaCode)" novalidate>
<label>2FA Code
<input type="number" ng-model="twoFaCode">
</label>
<input class="button" type="submit" value="Buy">
</form>
<button class="outline dark-gray round expand"
ng-click="$root.go('glidera')">Finish</button>
</div>
</div>
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>

View File

@ -99,7 +99,7 @@
</div>
<div class="size-12 text-gray columns m5t">
<span class="text-success" ng-if="tx.status == 'COMPLETE'">Completed</span>
<span class="text-info" ng-if="tx.status == 'PENDING'">Pending</span>
<span class="text-info" ng-if="tx.status == 'PROCESSING'">Processing</span>
<span class="text-warning" ng-if="tx.status == 'ERROR'">Error</span>
</div>
</div>

View File

@ -20,9 +20,9 @@
<div class="size-42">
{{tx.subtotal}} {{tx.currency}}
</div>
<div>
<div class="size-12 text-gray">
<span class="text-success" ng-if="tx.status == 'COMPLETE'">Completed</span>
<span class="text-info" ng-if="tx.status == 'PENDING'">Pending</span>
<span class="text-info" ng-if="tx.status == 'PROCESSING'">Processing</span>
<span class="text-warning" ng-if="tx.status == 'ERROR'">Error</span>
</div>
</div>
@ -38,22 +38,22 @@
<li ng-show="tx.price" class="line-b p10 oh">
<span class="text-gray" translate>Price</span>:
<span class="right">{{tx.price}}</span>
<span class="right">${{tx.price}} {{tx.currency}}</span>
</li>
<li ng-show="tx.subtotal" class="line-b p10 oh">
<span class="text-gray" translate>Subtotal</span>:
<span class="right">{{tx.subtotal}}</span>
<span class="right">${{tx.subtotal}} {{tx.currency}}</span>
</li>
<li ng-show="tx.fees" class="line-b p10 oh">
<span class="text-gray" translate>Fees</span>:
<span class="right">{{tx.fees}}</span>
<span class="right">${{tx.fees}} {{tx.currency}}</span>
</li>
<li ng-show="tx.total" class="line-b p10 oh">
<span class="text-gray" translate>Total</span>:
<span class="right">{{tx.total}}</span>
<span class="right">${{tx.total}} {{tx.currency}}</span>
</li>
</ul>
<div class="extra-margin-bottom"></div>

View File

@ -4,6 +4,9 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
function($scope, $timeout, profileService, addressService, glideraService) {
this.addr = {};
this.show2faCodeInput = null;
this.error = null;
this.success = null;
this.setDestinationAddress = function() {
var self = this;
@ -14,7 +17,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
$timeout(function() {
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
if (err) {
self.addrError = err;
return;
} else {
if (addr) self.addr[fc.credentials.walletId] = addr;
}
@ -25,36 +28,51 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.getBuyPrice = function(token, price) {
var self = this;
this.buyAmount = price.qty;
if (!price || (price && !price.qty && !price.fiat)) {
this.buyPrice = null;
return;
}
glideraService.buyPrice(token, price, function(error, buyPrice) {
self.buyPrice = buyPrice;
self.setDestinationAddress();
});
};
this.get2faCode = function(token, cb) {
this.get2faCode = function(token) {
var self = this;
glideraService.get2faCode(token, function(error, sent) {
self.show2faCodeInput = sent;
$timeout(function() {
glideraService.get2faCode(token, function(error, sent) {
self.show2faCodeInput = sent;
});
}, 100);
};
this.sendRequest = function(token, twoFaCode) {
var fc = profileService.focusedClient;
if (!fc) return;
this.loading = true;
var self = this;
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
if (addr) {
var data = {
destinationAddress: addr,
qty: self.buyPrice.qty,
priceUuid: self.buyPrice.priceUuid,
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;
}
else {
self.success = data
}
});
}
});
};
this.send = function(token, twoFaCode) {
var fc = profileService.focusedClient;
var self = this;
var data = {
destinationAddress: self.addr[fc.credentials.walletId],
qty: self.buyPrice.qty,
priceUuid: self.buyPrice.priceUuid,
useCurrentPrice: false,
ip: null
};
console.log('[sellGlidera.js:128]',token, twoFaCode, data); //TODO
glideraService.buy(token, twoFaCode, data, function(error, data) {
console.log('[sellGlidera.js:116]',data); //TODO
});
};
});

View File

@ -224,7 +224,7 @@ console.log('[glideraService.js:168]',data); //TODO
};
$http(_post('/buy', token, twoFaCode, data)).then(function(data) {
$log.info('Glidera Buy: SUCCESS');
return cb(null, data);
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Buy: ERROR ' + data.statusText);
return cb(data.statusText);