Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit c1f14cf

Browse files
authored
Merge pull request #1844 from OpenBazaar/shapeshift
Shapeshift integration with Shifty Button
2 parents 6b34872 + e122112 commit c1f14cf

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed

imgs/shapeshift_logo.png

21.9 KB
Loading

js/languages/en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@
685685
"OpenAddress": "Open in Local Wallet",
686686
"CopyAddress": "Copy to Clipboard",
687687
"RefreshPayment": "Refresh Payment Status",
688+
"Refresh": "Refresh",
689+
"PayWithAltCoins": "Pay with Altcoins",
690+
"AltCoins": "Use Altcoins",
688691
"summaryMsg1": "Your payment has been sent to %{recipient}",
689692
"summaryMsg2": "The expected processing time for this order is %{time}",
690693
"summaryMsg3": "You can check the status of your order on your %{purchasesPageLink}",

js/templates/buyWizard.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ <h3 class="custCol-text padding30"><%= polyglot.t('CheckExchanges') %> </h3>
2929
</div>
3030
<a class="btn btn-txt btn-wide row10 js-buyWizardPayCopy custCol-secondary custCol-text"><i class="ion-clipboard"></i> <%= polyglot.t('buyFlow.CopyAddress') %></a>
3131
<a class="btn btn-txt btn-wide row10 js-buyWizardPayLink custCol-secondary custCol-text"><i class="ion-link"></i> <%= polyglot.t('buyFlow.OpenAddress') %></a>
32-
<a class="btn btn-txt btn-wide js-buyWizardPayCheck custCol-secondary custCol-text"><i class="ion-refresh"></i> <%= polyglot.t('buyFlow.RefreshPayment') %></a>
32+
<div class="flexRow pad">
33+
<div class="flexCol-6">
34+
<a class="btn btn-txt btn-wide js-buyWizardPayCheck custCol-secondary custCol-text"><i class="ion-refresh"></i> <%= polyglot.t('buyFlow.RefreshPayment') %></a>
35+
</div>
36+
<div class="flexCol-6">
37+
<a class="btn btn-txt btn-wide js-buyWizardShapeshiftURL custCol-secondary custCol-text ss-button">
38+
<img src="imgs/shapeshift_logo.png" height="18px" width="18px" style="position: relative; top: 4px;"> <%= polyglot.t('buyFlow.PayWithAltCoins') %>
39+
</a>
40+
</div>
41+
</div>
3342
<div class="rowTop10 txt-center note custCol-text">
3443
<%= polyglot.t('buyFlow.paymentNote') %>
3544
</div>

js/templates/transactionModal.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ <h3 class="txt-bright"><%= polyglot.t('CheckExchanges') %> </h3>
5555
href="bitcoin:<%= ob.buyer_order.order.payment.address %>?amount=<%= ob.buyer_order.order.payment.amount %>&message=<%= ob.vendor_offer.listing.item.title %>">
5656
<i class="ion-link"></i> <%= polyglot.t('buyFlow.OpenAddress') %>
5757
</a>
58-
<a class="btn btn-txt btn-wide js-transactionPayCheck"><i class="ion-refresh"></i> <%= polyglot.t('buyFlow.RefreshPayment') %></a>
58+
59+
<div class="flexRow pad">
60+
<div class="flexCol-6">
61+
<a class="btn btn-txt btn-wide js-transactionPayCheck"><i class="ion-refresh"></i> <%= polyglot.t('buyFlow.Refresh') %></a>
62+
</div>
63+
<div class="flexCol-6">
64+
<a class="btn btn-txt btn-wide js-transactionShapeshiftURL">
65+
<img src="imgs/shapeshift_logo.png" height="18px" width="18px" style="position: relative; top: 4px;"> <%= polyglot.t('buyFlow.AltCoins') %>
66+
</a>
67+
</div>
68+
</div>
5969
</div>
6070
</div>
6171
</div>

js/views/buyWizardVw.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ var __ = require('underscore'),
1212
qr = require('qr-encode'),
1313
app = require('../App').getApp(),
1414
clipboard = require('electron').clipboard,
15-
templateHelpers = require('../utils/templateHelpers');
15+
templateHelpers = require('../utils/templateHelpers'),
16+
BrowserWindow = require('electron').remote.BrowserWindow;
17+
1618

1719
module.exports = baseModal.extend({
1820

@@ -37,6 +39,7 @@ module.exports = baseModal.extend({
3739
'click .js-buyWizardPurchaseBack': 'backPurchase',
3840
'click .js-buyWizardPayCopy': 'copyPayAddress',
3941
'click .js-accordionNext': 'accNext',
42+
'click .js-buyWizardShapeshiftURL': 'openShapeshiftURL',
4043
'click .js-accordionPrev': 'accPrev',
4144
'click .js-buyWizardCountryWrapper': 'openCountrySelect',
4245
'click .js-buyWizardPayCheck': 'checkPayment',
@@ -66,6 +69,7 @@ module.exports = baseModal.extend({
6669
this.model.set('selectedModerator', "");
6770
this.model.updateAttributes();
6871
this.cachePayData = "";
72+
this.totalBTCPrice = 0;
6973
this.partialPaymentAmount = 0;
7074

7175
//create the country select list
@@ -574,18 +578,17 @@ module.exports = baseModal.extend({
574578
throw new Error('Data must be provided to the showPayAddress function');
575579
}
576580

577-
var totalBTCPrice = 0,
578-
storeName = encodeURI(this.model.get('page').profile.name),
581+
var storeName = encodeURI(this.model.get('page').profile.name),
579582
message = encodeURI(this.model.get('vendor_offer').listing.item.title.substring(0, 20) + " "+data.order_id),
580583
payHREF = "",
581584
dataURI;
582585
this.$el.find('.js-buyWizardSpinner').addClass('hide');
583586
this.orderID = data.order_id;
584-
totalBTCPrice = data.amount - this.partialPaymentAmount;
585-
this.$el.find('.js-buyWizardDetailsTotalBTC').text(templateHelpers.intlNumFormat(totalBTCPrice, 8));
587+
this.totalBTCPrice = data.amount - this.partialPaymentAmount;
588+
this.$el.find('.js-buyWizardDetailsTotalBTC').text(templateHelpers.intlNumFormat(this.totalBTCPrice, 8));
586589
this.payURL = data.payment_address;
587590

588-
payHREF = "bitcoin:"+ data.payment_address+"?amount="+totalBTCPrice;
591+
payHREF = "bitcoin:"+ data.payment_address+"?amount="+this.totalBTCPrice;
589592
if (localStorage.getItem('AdditionalPaymentData') != "false") {
590593
payHREF += "&label="+storeName+"&message="+message;
591594
}
@@ -595,9 +598,14 @@ module.exports = baseModal.extend({
595598
dataURI = qr(payHREF, {type: 10, size: 10, level: 'M'});
596599
this.$el.find('.js-buyWizardPayQRCode').attr('src', dataURI);
597600
this.$el.find('.js-buyWizardPayPrice').text();
598-
this.$el.find('.js-buyWizardPayURL').text(data.payment_address);
601+
this.$el.find('.js-buyWizardPayURL').text(this.payURL);
599602
this.$el.find('.js-buyWizardPayLink').attr('href', payHREF);
600-
this.buyDetailsView.lockForm();
603+
},
604+
605+
openShapeshiftURL: function() {
606+
var shapeshiftURL = 'https://shapeshift.io/shifty.html?destination='+this.payURL+'&amp;output=BTC&apiKey=24ad734e196c948de4608e00472ab8a4b956a298c52abc20fda74114d6cebcb632714a9c5a0f38f46cef0bc974dfd41c34488432128d65acc099b3892f92d602&amount='+this.totalBTCPrice;
607+
var shapeshiftWin = new BrowserWindow({width: 700, height: 500, frame: true});
608+
shapeshiftWin.loadURL(shapeshiftURL);
601609
},
602610

603611
hidePayAddress: function(){

js/views/transactionModalVw.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var __ = require('underscore'),
1111
qr = require('qr-encode'),
1212
app = require('../App.js').getApp(),
1313
discussionCl = require('../collections/discussionCl'),
14-
clipboard = require('electron').clipboard;
14+
clipboard = require('electron').clipboard,
15+
BrowserWindow = require('electron').remote.BrowserWindow;
1516

1617
module.exports = baseModal.extend({
1718

@@ -56,7 +57,8 @@ module.exports = baseModal.extend({
5657
//'blur textarea': 'validateInput',
5758
'click #BuyWizardQRDetailsInput': 'toggleQRDetails',
5859
'keydown #transactionDiscussionSendText': 'onKeydownDiscussion',
59-
'keyup #transactionDiscussionSendText': 'onKeyupDiscussion'
60+
'keyup #transactionDiscussionSendText': 'onKeyupDiscussion',
61+
'click .js-transactionShapeshiftURL': 'openShapeshiftURL',
6062
},
6163

6264
initialize: function (options) {
@@ -151,8 +153,8 @@ module.exports = baseModal.extend({
151153
render: function () {
152154
var self = this,
153155
orderPrice = 0,
154-
orderPaid = 0,
155-
orderDue = 0;
156+
orderPaid = 0;
157+
this.orderDue = 0;
156158

157159
//make sure data is valid
158160
if (this.model.get('invalidData')){
@@ -168,7 +170,7 @@ module.exports = baseModal.extend({
168170
__.each(this.model.get("bitcoin_txs"), function(payment){
169171
orderPaid += payment.value;
170172
});
171-
orderDue = orderPrice - orderPaid;
173+
this.orderDue = orderPrice - orderPaid;
172174

173175
loadTemplate('./js/templates/transactionModal.html', function(loadedTemplate) {
174176
self.$el.html(loadedTemplate(
@@ -184,7 +186,7 @@ module.exports = baseModal.extend({
184186
orderID: self.orderID,
185187
orderPrice: orderPrice,
186188
orderPaid: orderPaid,
187-
orderDue: orderDue
189+
orderDue: self.orderDue
188190
})
189191
));
190192

@@ -259,7 +261,8 @@ module.exports = baseModal.extend({
259261
var payHREF,
260262
dataURI;
261263
if (this.model.get('buyer_order')){
262-
payHREF = "bitcoin:" + this.model.get('buyer_order').order.payment.address + "?amount=" + this.model.get('buyer_order').order.payment.amount;
264+
this.payURL = this.model.get('buyer_order').order.payment.address;
265+
payHREF = "bitcoin:" + this.payURL + "?amount=" + this.orderDue;
263266

264267
if (localStorage.getItem('AdditionalPaymentData') != "false") {
265268
payHREF += "&message=" + this.model.get('vendor_offer').listing.item.title.substring(0, 20) + " " + this.orderID;
@@ -819,6 +822,12 @@ module.exports = baseModal.extend({
819822
targ4.text(app.intlNumFormat(adjustedTotal - updatedVal * adjustedTotal, 8));
820823
},
821824

825+
openShapeshiftURL: function() {
826+
var shapeshiftURL = 'https://shapeshift.io/shifty.html?destination='+this.payURL+'&amp;output=BTC&apiKey=24ad734e196c948de4608e00472ab8a4b956a298c52abc20fda74114d6cebcb632714a9c5a0f38f46cef0bc974dfd41c34488432128d65acc099b3892f92d602&amount='+this.orderDue;
827+
var shapeshiftWin = new BrowserWindow({width: 700, height: 500, frame: true});
828+
shapeshiftWin.loadURL(shapeshiftURL);
829+
},
830+
822831
closeOrderForm: function(){
823832
this.setState(this.lastTab);
824833
},

0 commit comments

Comments
 (0)