Clean code. Fix coinbase tx modal
This commit is contained in:
parent
a776c19e60
commit
9ac1e565ac
5 changed files with 77 additions and 62 deletions
|
|
@ -8,31 +8,34 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
||||||
var init = function() {
|
var init = function() {
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
$scope.currency = getCurrency(config.alternativeIsoCode);
|
$scope.currency = getCurrency(config.alternativeIsoCode);
|
||||||
ongoingProcess.set('connectingCoinbase', true);
|
coinbaseService.getStoredToken(function(at) {
|
||||||
coinbaseService.init(function(err, data) {
|
$scope.accessToken = at;
|
||||||
ongoingProcess.set('connectingCoinbase', false);
|
|
||||||
if (err || lodash.isEmpty(data)) {
|
// Update Access Token if necessary
|
||||||
if (err) {
|
coinbaseService.init(function(err, data) {
|
||||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
if (err || lodash.isEmpty(data)) {
|
||||||
|
if (err) {
|
||||||
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show rates
|
// Show rates
|
||||||
coinbaseService.buyPrice(data.accessToken, $scope.currency, function(err, b) {
|
coinbaseService.buyPrice(data.accessToken, $scope.currency, function(err, b) {
|
||||||
$scope.buyPrice = b.data || null;
|
$scope.buyPrice = b.data || null;
|
||||||
});
|
});
|
||||||
coinbaseService.sellPrice(data.accessToken, $scope.currency, function(err, s) {
|
coinbaseService.sellPrice(data.accessToken, $scope.currency, function(err, s) {
|
||||||
$scope.sellPrice = s.data || null;
|
$scope.sellPrice = s.data || null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Updating accessToken and accountId
|
// Updating accessToken and accountId
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.accessToken = data.accessToken;
|
$scope.accessToken = data.accessToken;
|
||||||
$scope.accountId = data.accountId;
|
$scope.accountId = data.accountId;
|
||||||
$scope.updateTransactions();
|
$scope.updateTransactions();
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -104,8 +107,8 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
animation: 'slide-in-up'
|
animation: 'slide-in-up'
|
||||||
}).then(function(modal) {
|
}).then(function(modal) {
|
||||||
$scope.coinbaseTxDetailsModal = modal;
|
$scope.modal = modal;
|
||||||
$scope.coinbaseTxDetailsModal.show();
|
$scope.modal.show();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,28 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('coinbaseTxDetailsController', function($scope, $rootScope, coinbaseService) {
|
angular.module('copayApp.controllers').controller('coinbaseTxDetailsController', function($scope, coinbaseService, popupService) {
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
coinbaseService.savePendingTransaction($scope.tx, {
|
coinbaseService.setCredentials();
|
||||||
remove: true
|
$scope.updateRequired = false;
|
||||||
}, function(err) {
|
var message = 'Are you sure you want to remove this transaction?';
|
||||||
$rootScope.$emit('Local/CoinbaseTx');
|
popupService.showConfirm(null, message, null, null, function(ok) {
|
||||||
$scope.close();
|
if (!ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
coinbaseService.savePendingTransaction($scope.tx, {
|
||||||
|
remove: true
|
||||||
|
}, function(err) {
|
||||||
|
$scope.updateRequired = true;
|
||||||
|
$scope.close();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.close = function() {
|
$scope.close = function() {
|
||||||
$scope.coinbaseTxDetailsModal.hide();
|
$scope.modal.hide().then(function() {
|
||||||
|
if ($scope.updateRequired) $scope.updateTransactions();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,13 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
return credentials.NETWORK;
|
return credentials.NETWORK;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.getStoredToken = function(cb) {
|
||||||
|
storageService.getCoinbaseToken(credentials.NETWORK, function(err, accessToken) {
|
||||||
|
if (err || !accessToken) return cb();
|
||||||
|
return cb(accessToken);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
root.getOauthCodeUrl = function() {
|
root.getOauthCodeUrl = function() {
|
||||||
return credentials.HOST
|
return credentials.HOST
|
||||||
+ '/oauth/authorize?response_type=code&client_id='
|
+ '/oauth/authorize?response_type=code&client_id='
|
||||||
|
|
@ -478,16 +485,17 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getPendingTransactions = function(coinbasePendingTransactions) {
|
root.getPendingTransactions = function(coinbasePendingTransactions) {
|
||||||
root.init(function(err, data) {
|
storageService.getCoinbaseTxs(credentials.NETWORK, function(err, txs) {
|
||||||
if (err || lodash.isEmpty(data)) {
|
txs = txs ? JSON.parse(txs) : {};
|
||||||
if (err) $log.error(err);
|
coinbasePendingTransactions.data = lodash.isEmpty(txs) ? null : txs;
|
||||||
return;
|
|
||||||
}
|
root.init(function(err, data) {
|
||||||
var accessToken = data.accessToken;
|
if (err || lodash.isEmpty(data)) {
|
||||||
var accountId = data.accountId;
|
if (err) $log.error(err);
|
||||||
storageService.getCoinbaseTxs(credentials.NETWORK, function(err, txs) {
|
return;
|
||||||
txs = txs ? JSON.parse(txs) : {};
|
}
|
||||||
coinbasePendingTransactions.data = lodash.isEmpty(txs) ? null : txs;
|
var accessToken = data.accessToken;
|
||||||
|
var accountId = data.accountId;
|
||||||
|
|
||||||
lodash.forEach(coinbasePendingTransactions.data, function(dataFromStorage, txId) {
|
lodash.forEach(coinbasePendingTransactions.data, function(dataFromStorage, txId) {
|
||||||
if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') ||
|
if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') ||
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-if="!accountId && !error" ng-init="showOauthForm = false">
|
<div ng-if="!accessToken && !error" ng-init="showOauthForm = false">
|
||||||
<div class="text-center m20v">
|
<div class="text-center m20v">
|
||||||
<img src="img/coinbase-logo.png" width="200">
|
<img src="img/coinbase-logo.png" width="200">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -53,20 +53,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-if="accountId && !error">
|
<div ng-if="accessToken && !error">
|
||||||
|
|
||||||
<div class="m20t text-center" ng-show="accountId" ng-click="updateTransactions()">
|
<div class="m20t text-center" ng-click="updateTransactions()">
|
||||||
<img src="img/coinbase-logo.png" width="200">
|
<img src="img/coinbase-logo.png" width="200">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="m10t size-12 text-center text-gray" ng-if="buyPrice && sellPrice">
|
<div class="m10t size-12 text-center text-gray">
|
||||||
{{buyPrice.amount}} {{buyPrice.currency}}
|
<span ng-show="!buyPrice || !sellPrice"> ... | ... </span>
|
||||||
|
|
<span ng-show="buyPrice && sellPrice">
|
||||||
{{sellPrice.amount}} {{sellPrice.currency}}
|
{{buyPrice.amount}} {{buyPrice.currency}}
|
||||||
|
|
|
||||||
|
{{sellPrice.amount}} {{sellPrice.currency}}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list card"
|
<div class="list card">
|
||||||
ng-show="accountId">
|
|
||||||
<a class="item item-icon-right"
|
<a class="item item-icon-right"
|
||||||
href ui-sref="tabs.buyandsell.coinbase.amount({nextStep: 'tabs.buyandsell.coinbase.buy', currency: currency})">
|
href ui-sref="tabs.buyandsell.coinbase.amount({nextStep: 'tabs.buyandsell.coinbase.buy', currency: currency})">
|
||||||
<img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="35" class="item-img-buy">
|
<img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="35" class="item-img-buy">
|
||||||
|
|
|
||||||
|
|
@ -79,18 +79,10 @@
|
||||||
<span ng-show="tx.to && tx.type == 'send'">Receive bitcoin in</span>
|
<span ng-show="tx.to && tx.type == 'send'">Receive bitcoin in</span>
|
||||||
<span class="item-note">{{tx.description}}</span>
|
<span class="item-note">{{tx.description}}</span>
|
||||||
</li>
|
</li>
|
||||||
|
<div ng-show="tx.status == 'error'" class="item item-divider"></div>
|
||||||
|
<div ng-show="tx.status == 'error'" class="item assertive" ng-click="remove()">
|
||||||
|
Remove transaction
|
||||||
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="list" ng-show="tx.status == 'error'">
|
|
||||||
<div class="item item-divider">
|
|
||||||
This action will remove the transaction.
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<a ng-click="remove()">
|
|
||||||
Remove
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-modal-view>
|
</ion-modal-view>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue