refactor config/list/scan
This commit is contained in:
parent
7dadf7e321
commit
fbda525e6d
8 changed files with 213 additions and 26 deletions
|
|
@ -14,9 +14,6 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
|||
$scope.hideNextSteps = {
|
||||
value: config.hideNextSteps.enabled
|
||||
};
|
||||
$scope.cashSupport = {
|
||||
value: config.cashSupport.enabled
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -31,19 +28,6 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.cashSupportChange = function() {
|
||||
var opts = {
|
||||
cashSupport: {
|
||||
enabled: $scope.cashSupport.value
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.nextStepsChange = function() {
|
||||
var opts = {
|
||||
hideNextSteps: {
|
||||
|
|
|
|||
97
src/js/controllers/cash.js
Normal file
97
src/js/controllers/cash.js
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('otherBalanceController',
|
||||
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, bwcError ) {
|
||||
var wallet;
|
||||
var listeners = [];
|
||||
var notifications = [];
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
$scope.isAndroid = platformInfo.isAndroid;
|
||||
$scope.isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
$scope.isNW = platformInfo.isNW;
|
||||
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
updateAllWallets();
|
||||
});
|
||||
|
||||
var updateAllWallets = function() {
|
||||
var wallets = profileService.getWallets({coin:'btc', onlyComplete:true, network: 'livenet' });
|
||||
|
||||
|
||||
// TODO ?
|
||||
if (lodash.isEmpty(wallets)) return;
|
||||
console.log('[otherBalance.js.24:wallets:]',wallets); //TODO
|
||||
|
||||
|
||||
var walletsBCH = profileService.getWallets({coin:'bch', network: 'livenet' });
|
||||
var xPubKeyIndex = lodash.indexBy(walletsBCH,"credentials.xPubKey");
|
||||
console.log('[otherBalance.js.28:xPubKeyIndex:]',xPubKeyIndex); //TODO
|
||||
|
||||
wallets= lodash.filter(wallets,function(w) { return xPubKeyIndex[w.credentials.xPubKey]; });
|
||||
console.log('[otherBalance.js.31:wallets:]',wallets); //TODO
|
||||
|
||||
|
||||
// TODO Filterout already duplicated walelts
|
||||
// TODO filterout balance=0 wallets
|
||||
//
|
||||
//
|
||||
|
||||
$scope.wallets = wallets;
|
||||
|
||||
var i = wallets.length;
|
||||
var j = 0;
|
||||
lodash.each(wallets, function(wallet) {
|
||||
walletService.getBalance(wallet, {coin:'bch'}, function(err, status) {
|
||||
if (err) {
|
||||
|
||||
wallet.error = (err === 'WALLET_NOT_REGISTERED') ? gettextCatalog.getString('Wallet not registered') : bwcError.msg(err);
|
||||
|
||||
$log.error(err);
|
||||
return;
|
||||
}
|
||||
//
|
||||
|
||||
console.log('[otherBalance.js.28:status:]',status); //TODO
|
||||
wallet.error = null;
|
||||
wallet.status = status;
|
||||
if (++j == i) {
|
||||
//
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.duplicate = function(wallet) {
|
||||
$log.debug('Duplicating wallet for BCH:' + wallet.id + ':' + wallet.name);
|
||||
|
||||
var opts = {};
|
||||
opts.name = wallet.name + '[BCH]';
|
||||
opts.m = wallet.m;
|
||||
opts.n = wallet.n;
|
||||
opts.myName = wallet.credentials.copayerName;
|
||||
opts.networkName = wallet.network;
|
||||
opts.coin = 'bch';
|
||||
|
||||
// TODO: finger print / decrypt
|
||||
$log.warn('TODO finger print / decrypt');
|
||||
|
||||
|
||||
opts.walletPrivKey = wallet.credentials.walletPrivKey;
|
||||
|
||||
walletService.getStatus(wallet, {}, function(err, status){
|
||||
if (err) {
|
||||
// TODO
|
||||
$log.err('TODO Err');
|
||||
return;
|
||||
}
|
||||
opts.singleAddress = status.wallet.singleAddress;
|
||||
|
||||
// create and store a wallet
|
||||
profileService.createWallet(opts, function(err) {
|
||||
$state.go('tabs.home');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
31
src/js/controllers/preferencesCash.js
Normal file
31
src/js/controllers/preferencesCash.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesCashController', function($scope, $log, $timeout, appConfigService, lodash, configService, platformInfo, pushNotificationsService, emailService) {
|
||||
var updateConfig = function() {
|
||||
var config = configService.getSync();
|
||||
$scope.appName = appConfigService.nameCase;
|
||||
|
||||
$scope.cashSupport = {
|
||||
value: config.wallet.cashSupport.enabled
|
||||
};
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cashSupportChange = function() {
|
||||
var opts = {
|
||||
wallet: {
|
||||
cashSupport: $scope.cashSupport.value
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
updateConfig();
|
||||
});
|
||||
});
|
||||
|
|
@ -25,6 +25,11 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
}, 10);
|
||||
});
|
||||
|
||||
$scope.cashSupport = {
|
||||
value: config.cashSupport.enabled
|
||||
};
|
||||
|
||||
|
||||
// TODO move this to a generic service
|
||||
bitpayCardService.getCards(function(err, cards) {
|
||||
if (err) $log.error(err);
|
||||
|
|
@ -62,6 +67,8 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
updateConfig();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -464,6 +464,16 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.cash', {
|
||||
url: '/cash',
|
||||
views: {
|
||||
'tab-home@tabs': {
|
||||
controller: 'cashController',
|
||||
templateUrl: 'views/tab-cash.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,16 +8,6 @@
|
|||
<ion-content>
|
||||
<div class="settings-list list">
|
||||
|
||||
<ion-toggle class="has-comment" ng-model="cashSupport.value" toggle-class="toggle-balanced" ng-change="cashSupportChange()">
|
||||
<span class="toggle-label" translate>Support Bitcoin Cash</span>
|
||||
</ion-toggle>
|
||||
<div class="comment">
|
||||
<span translate>Enable Bitcoin Cash wallet creation and operation within the App.</span>
|
||||
<a ng-click="openBitcoinCashWeb()" translate>Learn more</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<ion-toggle class="has-comment" ng-model="spendUnconfirmed.value" toggle-class="toggle-balanced" ng-change="spendUnconfirmedChange()">
|
||||
<span class="toggle-label" translate>Use Unconfirmed Funds</span>
|
||||
</ion-toggle>
|
||||
|
|
|
|||
41
www/views/cashScan.html
Normal file
41
www/views/cashScan.html
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<ion-view id="other-balance" hide-tabs>
|
||||
<ion-nav-bar class="bar-royal">
|
||||
<ion-nav-title>
|
||||
<span translate>Bitcoin Cash (BCH) Balances</span>
|
||||
</ion-nav-title>
|
||||
<ion-nav-back-button>
|
||||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
|
||||
<ion-content>
|
||||
|
||||
<div class="list card">
|
||||
<div class="item item-icon-right item-heading">
|
||||
<span translate>BTC Wallets</span>
|
||||
</div>
|
||||
<div>
|
||||
<div ng-repeat="wallet in wallets track by $index"
|
||||
class="item item-sub item-icon-left item-big-icon-left item-icon-right wallet"
|
||||
>
|
||||
<i class="icon big-icon-svg">
|
||||
<img ng-src="img/{{wallet.network == 'testnet' ? 'icon-wallet-testnet' : (wallet.coin == 'btc' ? 'icon-btc' : 'icon-bch')}}.svg" ng-class="{'wallet-background-color-default': !wallet.color}" ng-style="{'background-color': wallet.color}" class="bg wallet"/>
|
||||
</i>
|
||||
<span>
|
||||
{{wallet.name || wallet.id}}
|
||||
</span>
|
||||
<p>
|
||||
<span > {{wallet.status.totalBalanceStr ? wallet.status.totalBalanceStr : ( wallet.cachedBalance ? wallet.cachedBalance + (wallet.cachedBalanceUpdatedOn ? ' · ' + ( wallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo) : '') : '' ) }} </span>
|
||||
|
||||
<span class="tab-home__wallet__multisig-number" ng-if="wallet.n > 1">
|
||||
{{wallet.m}}-of-{{wallet.n}}
|
||||
</span>
|
||||
|
||||
</p>
|
||||
<button ng-click="duplicate(wallet)">
|
||||
Duplicate for BCH
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ion-content>
|
||||
27
www/views/preferencesCash.html
Normal file
27
www/views/preferencesCash.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<ion-view id="tab-notifications" class="settings" show-tabs>
|
||||
<ion-nav-bar class="bar-royal">
|
||||
<ion-nav-title>{{'Bitcoin Cash Support' | translate}}</ion-nav-title>
|
||||
<ion-nav-back-button>
|
||||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
|
||||
<ion-content>
|
||||
<div class="list">
|
||||
<ion-toggle class="has-comment" ng-model="cashSupport.value" toggle-class="toggle-balanced" ng-change="cashSupportChange()">
|
||||
<span class="toggle-label" translate>Support Bitcoin Cash</span>
|
||||
</ion-toggle>
|
||||
|
||||
<div ng-show="!cashSupport.value">
|
||||
<span translate>Enable Bitcoin Cash wallet creation and operation within the App.</span>
|
||||
<a ng-click="openBitcoinCashWeb()">Learn more</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-if="cashSupport.value">
|
||||
<span class="setting-value" translate>
|
||||
<button ng-show="cashSupport.value" ui-sref="tabs.cash" translate>Check your current wallets for Bitcoin Cash</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
Loading…
Add table
Add a link
Reference in a new issue