Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1494 from blockchain/sfox-expected-trades
Browse files Browse the repository at this point in the history
Sfox expected trades
  • Loading branch information
plondon committed Apr 24, 2018
2 parents b708f22 + 7aae2cc commit 661f3cf
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/partials/sfox/checkout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ bc-tabs(tab="tabs.selectedTab" tab-options="tabs.options" on-select="tabs.select
trade-account="checkout.state.account"
handle-quote="sellQuoteHandler(amount, baseCurr, quoteCurr)"
on-success="selling().verificationRequired ? checkout.openSfoxSignup() : buildPayment(quote)")
.flex-column.width-50.pl-30.prn.pv-10-mobile.no-margin-mobile.hidden-xs(ng-if="checkout.onStep('create') && !checkout.hasDismissedSellIntro()")
.flex-column.width-50.pl-30.prn.pv-10-mobile.no-margin-mobile.hidden-xs(ng-if="checkout.onStep('create') && !checkout.hasDismissedSellIntro() && !pendingSellTrades().length")
.flex-between
span.f-24.blue.f-14-mobile
i.icon-buy-sell.h3.mrm
span(translate="SFOX.sell.INTRODUCING_HEADER")
span
i.pointer.ti-close.f-14.mid-grey(ng-click="checkout.dismissSellIntro()")
p.f-12.mt-10(translate="SFOX.sell.INTRODUCING_BODY")
.width-50.pl-30.prn.pv-10-mobile.no-margin-mobile(ng-if="pendingSellTrades().length")
span You have {{ pendingSellTrades().length }} pending sell {{ pendingSellTrades().length === 1 ? 'transaction' : 'transactions' }} for a total of {{ pendingSellTradesTotal() }} USD. You can see more details in your
|  
a(ng-click="tabs.select('ORDER_HISTORY')") Order History.
.flex-row.pbvl(ng-if="checkout.onStep('confirm')")
exchange-confirm.width-55.border-desktop(
type="checkout.type"
Expand Down
2 changes: 1 addition & 1 deletion app/partials/sfox/details.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ div(ng-controller="SfoxTradeDetailsController")
span.f-16.em-500.pl-30.no-padding-mobile(translate="{{namespace + type + state + '.HEADER'}}" class="{{classHelper(trade)}}")
.ph-30.pt-20.ph-10-mobile.pv-20-mobile
.f-13.mb-10
span(translate="{{namespace + type + state + '.BODY'}}" translate-values="{tradeId: tradeId}")
span(translate="{{namespace + type + state + '.BODY'}}" translate-values="{tradeId: tradeId, expectedDelivery: tradeDetails.expectedDelivery.val}")
div(ng-if="tradeAccount")
.flex-end.flex-row.mb-5.mt-5
span.mid-grey.f-12 1 BTC = {{ rate }}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/exchange/confirm.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ form.bc-form.pv-20(
div
span(translate="{{namespace + type + field.key}}") {{field.key}}
helper-button(ng-show="field.key === '.TX_FEE'" content="{{namespace + type + '.TRANSACTION_FEE_HELPER'}}")
helper-button(ng-show="field.key === '.TRADING_FEE'" content="{{namespace + '.TRADING_FEE_HELPER'}}")
helper-button(ng-show="field.key === '.TRADING_FEE'" content="{{namespace + '.TRADING_FEE_HELPER'}}")
span {{ field.val }}
.flex-row.flex-align-start
.pts
Expand Down
10 changes: 8 additions & 2 deletions assets/js/controllers/sfox/sfoxBuyCheckout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function SfoxBuyCheckoutController ($scope, $timeout, $stateParams, $q, Wallet,

$scope.prepareBuy = (quote) => {
$scope.checkout.quote = quote;
return $q.resolve(sfox.buyTradeDetails($scope.checkout.quote))
let minutesInADay = 1440;
let profile = exchange.profile;
let expectedDelivery = profile.processingTimes && profile.processingTimes.usd.buy / minutesInADay + ' Days';
return $q.resolve(sfox.buyTradeDetails($scope.checkout.quote, null, null, expectedDelivery))
.then(details => {
$scope.checkout.tradeDetails = details;
$scope.checkout.type = 'buy';
Expand All @@ -34,7 +37,10 @@ function SfoxBuyCheckoutController ($scope, $timeout, $stateParams, $q, Wallet,
};

$scope.checkout.buyHandler = (quote) => sfox.buy($scope.checkout.state.account, quote)
.then(trade => $scope.checkout.trade = trade)
.then(trade => {
$scope.checkout.trade = trade
$scope.checkout.expectedDelivery = trade.expectedDelivery
})
.then(sfox.fetchTrades)
.then(() => exchange.fetchProfile())
.then(enableSiftScience)
Expand Down
2 changes: 2 additions & 0 deletions assets/js/controllers/sfox/sfoxCheckout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function SfoxCheckoutController ($scope, $timeout, $stateParams, $q, Wallet, MyW

$scope.showBuy = () => MyWallet.wallet.accountInfo.invited.sfoxBuy;
$scope.pendingBuyTrades = () => $scope.pendingTrades().filter((t) => t.isBuy);
$scope.pendingSellTrades = () => $scope.pendingTrades().filter((t) => !t.isBuy);
$scope.pendingBuyTradesTotal = () => $scope.pendingBuyTrades().map((t) => t.receiveAmount).reduce((acc, amt) => acc + amt);
$scope.pendingSellTradesTotal = () => $scope.pendingSellTrades().map((t) => t.receiveAmount).reduce((acc, amt) => acc + amt).toFixed(2);

this.handleCancel = (skipConfirm, type, step) => {
if (skipConfirm) $scope.checkout.goTo('create');
Expand Down
6 changes: 5 additions & 1 deletion assets/js/controllers/sfox/sfoxSellCheckout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ function SfoxSellCheckoutController ($scope, $timeout, $stateParams, $q, Wallet,
$scope.payment.amount(amt);
$scope.payment.updateFeePerKb(Exchange.sellFee || 2);
$scope.payment.from(Wallet.my.wallet.hdwallet.defaultAccountIndex);
let minutesInADay = 1440;
let profile = exchange.profile;
let expectedDelivery = profile.processingTimes && profile.processingTimes.usd.sell / minutesInADay + ' Days';

$scope.payment.sideEffect((payment) => {
$scope.checkout.quote = quote;
$scope.checkout.type = 'sell';
$scope.checkout.goTo('confirm');
$scope.checkout.tradeDetails = sfox.sellTradeDetails($scope.checkout.quote, payment);
$scope.checkout.tradeDetails = sfox.sellTradeDetails($scope.checkout.quote, payment, null, null, expectedDelivery);
Wallet.api.incrementPartnerTrade('sfox', 'sell', $scope.checkout.quote.baseCurrency, $scope.checkout.quote.quoteCurrency);
});

Expand All @@ -58,6 +61,7 @@ function SfoxSellCheckoutController ($scope, $timeout, $stateParams, $q, Wallet,

let submitTx = (trade) => {
$scope.checkout.trade = trade;
$scope.checkout.expectedDelivery = trade.expectedDelivery;
$scope.payment.to(trade.receiveAddress);
return Wallet.askForSecondPasswordIfNeeded().then((pw) => {
return $scope.payment.build().sign(pw).publish().payment;
Expand Down
11 changes: 9 additions & 2 deletions assets/js/controllers/sfox/sfoxTradeDetails.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ function SfoxTradeDetailsController ($scope, MyWallet, Exchange, currency, sfox,
$scope.state = '.' + trade.state;
$scope.type = trade.isBuy ? '.buy' : '.sell';

let expectedDelivery;
if ($scope.checkout && $scope.checkout.expectedDelivery) {
expectedDelivery = new Date($scope.checkout.expectedDelivery).toDateString()
} else {
expectedDelivery = new Date(trade.expectedDelivery).toDateString()
}

if ($scope.type === '.buy') {
$q.resolve(sfox.buyTradeDetails(null, trade, tx))
$q.resolve(sfox.buyTradeDetails(null, trade, tx, expectedDelivery))
.then(details => $scope.tradeDetails = details);
} else {
$scope.tradeDetails = sfox.sellTradeDetails(null, null, trade, tx);
$scope.tradeDetails = sfox.sellTradeDetails(null, null, trade, tx, expectedDelivery);
}

$scope.rate = $scope.type === '.buy'
Expand Down
22 changes: 19 additions & 3 deletions assets/js/services/sfox.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function sfox ($q, MyWallet, MyWalletHelpers, Alerts, modals, Env, Exchange, cur
return localStorageService.get('hasSeenSfoxBuyIntro');
}

function sellTradeDetails (quote, payment, trade, tx) {
function sellTradeDetails (quote, payment, trade, tx, expectedDelivery) {
let { formatCurrencyForView, convertFromSatoshi } = currency;
let fiat = currency.currencies.find((curr) => curr.code === 'USD');
let btc = currency.bitCurrencies.find((curr) => curr.code === 'BTC');
Expand All @@ -209,7 +209,7 @@ function sfox ($q, MyWallet, MyWalletHelpers, Alerts, modals, Env, Exchange, cur
: (trade.receiveAmount).toFixed(2);
let amountKey = quote || payment ? '.AMT' : '.AMT_SOLD';

return {
let details = {
txAmt: {
key: amountKey,
val: isNaN(amount) ? amount : formatCurrencyForView(convertFromSatoshi(amount, btc), btc, true)
Expand All @@ -232,9 +232,18 @@ function sfox ($q, MyWallet, MyWalletHelpers, Alerts, modals, Env, Exchange, cur
tip: () => console.log('Clicked tooltip')
}
};

if (expectedDelivery) {
details.expectedDelivery = {
key: '.EXPECTED_DELIVERY',
val: expectedDelivery
};
}

return details;
}

function buyTradeDetails (quote, trade, tx) {
function buyTradeDetails (quote, trade, tx, expectedDelivery) {
let buyTxFee;
return Env.then(env => {
buyTxFee = env.partners.sfox.buyTransactionFeeInSatoshi;
Expand Down Expand Up @@ -287,6 +296,13 @@ function sfox ($q, MyWallet, MyWalletHelpers, Alerts, modals, Env, Exchange, cur
};
}

if (expectedDelivery) {
details.expectedDelivery = {
key: '.EXPECTED_DELIVERY',
val: expectedDelivery
};
}

return details;
});
}
Expand Down
6 changes: 4 additions & 2 deletions locales/en-human.json
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@
"DISPLAY": "Pending Sell",
"ACTION": "@:EXCHANGE.ACTIONS.VIEW_DETAILS",
"HEADER": "Sell Order in Progress",
"BODY": "Your sell trade has been initiated. Your funds will be deposited into your bank account within 3-5 business days. <b>Your order ID is: SFX-{{::tradeId}}</b>"
"BODY": "Your sell trade has been initiated. Your funds will be deposited into your bank account by {{::expectedDelivery}}. <b>Your order ID is: SFX-{{::tradeId}}</b>"
},
"failed": {
"DISPLAY": "Failed Sell",
Expand All @@ -1927,6 +1927,7 @@
"TX_FEE": "Transaction Fee",
"TOTAL": "Total Outgoing Bitcoin",
"INTRODUCING_HEADER": "Sell Bitcoin",
"EXPECTED_DELIVERY": "Estimated Delivery of Funds",
"INTRODUCING_BODY": "Selling bitcoin is simple, seamless, and secure. Thanks to our partnership with SFOX, you can sell bitcoin directly from your Blockchain wallet.<br><br>Tips for getting started:<br>The minimum amount you can sell is $10. Your daily maximum can be found under the local currency field.<br><br>Currently, your Blockchain wallet supports linking only one bank account. If you would like to change your synced account, please email <a href=\"mailto:support@sfox.com?subject=Questions%20about%20my%20account%20-%20Blockchain\">support@sfox.com</a>. Please note: selling with a credit card is not supported at this time.",
"TRADING_FEE": "Trading Fee",
"TO_BE_RECEIVED": "USD To Be Received",
Expand All @@ -1943,7 +1944,7 @@
"DISPLAY": "Pending Buy",
"HEADER": "Buy Order in Progress",
"ACTION": "@:EXCHANGE.ACTIONS.VIEW_DETAILS",
"BODY": "Your buy trade has been initiated. You will receive your bitcoin in 3-7 business days. <b>Your order ID is: SFX-{{::tradeId}}</b>"
"BODY": "Your buy trade has been initiated. You will receive your bitcoin on {{::expectedDelivery}}. <b>Your order ID is: SFX-{{::tradeId}}</b>"
},
"rejected": {
"DISPLAY": "Rejected Buy",
Expand All @@ -1964,6 +1965,7 @@
"TRADING_FEE": "@:SFOX.sell.TRADING_FEE",
"TX_FEE": "@:SFOX.sell.TX_FEE",
"NOW_SUPPORTING": "This Just In!",
"EXPECTED_DELIVERY": "@:SFOX.sell.EXPECTED_DELIVERY",
"ANNOUNCEMENT": "Buy has arrived. You can now swiftly buy bitcoin directly from within your Blockchain wallet!",
"GET_STARTED": "Begin Buying",
"COMING_SOON": "We are working hard to bring <strong>buy bitcoin</strong> functionality to your wallet very soon.",
Expand Down

0 comments on commit 661f3cf

Please sign in to comment.