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 #926 from blockchain/one-modal
Browse files Browse the repository at this point in the history
Only allow one trade summary modal at a time
  • Loading branch information
plondon committed Jan 30, 2017
2 parents b05bfd7 + a1b028f commit d082e8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions assets/js/controllers/sfox/sfoxCheckout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function SfoxCheckoutController ($scope, $timeout, $stateParams, $q, Wallet, MyW
$scope.siftScienceEnabled = true;
$scope.tradeId = trade.id;
$scope.selectTab('ORDER_HISTORY');
let modalInstance = modals.openTradeSummary(trade, 'initiated');
sfox.watchTrade(trade, () => modalInstance.dismiss());
modals.openTradeSummary(trade, 'initiated');
sfox.watchTrade(trade);
})
.catch(() => {
Alerts.displayError('Error connecting to our exchange partner');
Expand Down
12 changes: 10 additions & 2 deletions assets/js/services/modals.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function modals ($state, $uibModal, $ocLazyLoad) {
};
};

service.dismissPrevious = (modalOpener) => {
let modalInstance = null;
return (...args) => {
if (modalInstance) modalInstance.dismiss('overridden');
modalInstance = modalOpener(...args);
};
};

service.openBankHelper = () => open({
templateUrl: 'partials/bank-check-modal.jade',
windowClass: 'bc-modal medium'
Expand Down Expand Up @@ -66,7 +74,7 @@ function modals ($state, $uibModal, $ocLazyLoad) {
if (goingToBuySellState) $state.go('wallet.common.buy-sell');
});

service.openTradeSummary = (trade, state) => open({
service.openTradeSummary = service.dismissPrevious((trade, state) => open({
templateUrl: 'partials/trade-modal.jade',
windowClass: 'bc-modal trade-summary',
controller ($scope, trade, formatTrade, accounts) {
Expand All @@ -81,7 +89,7 @@ function modals ($state, $uibModal, $ocLazyLoad) {
: $q.resolve([]);
}
}
});
}));

return service;
}
5 changes: 2 additions & 3 deletions assets/js/services/sfox.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ function sfox ($q, Alerts, modals) {
.forEach(service.watchTrade);
}

function watchTrade (trade, completedCallback) {
function watchTrade (trade) {
watching[trade.receiveAddress] = true;
$q.resolve(trade.watchAddress())
.then(() => trade.refresh())
.then(() => { modals.openTradeSummary(trade, 'success'); })
.then(completedCallback);
.then(() => { modals.openTradeSummary(trade, 'success'); });
}
}
10 changes: 0 additions & 10 deletions tests/controllers/sfox/sfox_checkout_ctrl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ describe "SfoxCheckoutController", ->
beforeEach ->
scope = getControllerScope([{status:'active'}])

it "should watch the trade for completion and close the first modal", ->
dismissSpy = jasmine.createSpy("dismiss")
spyOn(modals, "openTradeSummary").and.returnValue(dismiss: dismissSpy)
spyOn(sfox, "watchTrade").and.callFake((trade, cb) -> cb())
scope.buyHandler(mockQuote())
scope.$digest()
trade = jasmine.objectContaining({ id: "TRADE" })
expect(sfox.watchTrade).toHaveBeenCalledWith(trade, jasmine.any(Function))
expect(dismissSpy).toHaveBeenCalled()

it "should open the trade summary modal", ->
spyOn(modals, "openTradeSummary").and.callThrough()
scope.buyHandler(mockQuote())
Expand Down

0 comments on commit d082e8e

Please sign in to comment.