Skip to content

Commit

Permalink
- avoid events on isLogin() : use api events and rooscope.login
Browse files Browse the repository at this point in the history
- Put Device into rootScope, to avoid call of Device.isEnable()
- ES: Market price is optional
  • Loading branch information
blavenie committed Sep 16, 2016
1 parent b2db8ec commit 52b4c7a
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 50 deletions.
2 changes: 1 addition & 1 deletion www/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ angular.module("cesium.config", [])
}
},
"version": "0.3.0",
"build": "2016-09-16T15:12:33.494Z",
"build": "2016-09-16T15:34:45.590Z",
"newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug"
})

Expand Down
19 changes: 10 additions & 9 deletions www/js/controllers/app-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
$rootScope.walletData = Wallet.data;
$rootScope.settings = csSettings.data;
$rootScope.config = csConfig;
$rootScope.device = Device;
$rootScope.login = Wallet.isLogin();

////////////////////////////////////////
// Load currencies
Expand All @@ -81,12 +83,8 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
// Device Methods
////////////////////////////////////////

$scope.isDeviceEnable = function() {
return Device.isEnable();
};

$scope.scanQrCodeAndGo = function() {
if (!Device.isEnable()) {
if (!Device.enable) {
return;
}
Device.camera.scan()
Expand Down Expand Up @@ -215,10 +213,13 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
.catch(UIUtils.onError());
};

// Is connected
$scope.isLogin = function() {
return Wallet.isLogin();
};
// add listener on wallet event
Wallet.api.data.on.login($scope, function() {
$rootScope.login = true;
}, this);
Wallet.api.data.on.logout($scope, function() {
$rootScope.login = false;
}, this);

// If connected and same pubkey
$scope.isUserPubkey = function(pubkey) {
Expand Down
2 changes: 1 addition & 1 deletion www/js/controllers/wot-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, Device, Wal
};

$scope.scanQrCode = function(){
if (!Device.isEnable()) {
if (!Device.enable) {
return;
}
Device.camera.scan()
Expand Down
12 changes: 9 additions & 3 deletions www/js/services/device-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services']
MAX_WIDTH: 400
},
readyPromise,

// workaround to quickly no is device or not (even before the ready() event)
enable = true;
// removeIf(device)
enable = false;
// endRemoveIf(device)

// Replace the '$ionicPlatform.ready()', to enable multiple calls
ready = function () {
Expand All @@ -25,9 +30,9 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services']
return readyPromise;
};

isEnable = function() {
/*isEnable = function() {
return enable;
};
};*/

getPicture = function(sourceType) {
return $q(function (resolve, reject) {
Expand Down Expand Up @@ -132,7 +137,8 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services']

return {
ready: ready,
isEnable: isEnable,
enable: enable,
/*isEnable: isEnable,*/
clipboard: {
copy: copy
},
Expand Down
4 changes: 2 additions & 2 deletions www/js/services/settings-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi
useRelative: true,
timeWarningExpireMembership: 2592000 * 2 /*=2 mois*/,
timeWarningExpire: 2592000 * 3 /*=3 mois*/,
useLocalStorage: Device.isEnable(), // on mobile device, use local storage by default
useLocalStorage: Device.enable, // on mobile device, use local storage by default
walletHistoryTimeSecond: 30 * 24 * 60 * 60 /*30 days*/,
walletHistorySliceSecond: 5 * 24 * 60 * 60 /*download using 5 days slice*/,
rememberMe: Device.isEnable(), // on mobile device, remember me by default
rememberMe: Device.enable, // on mobile device, remember me by default
showUDHistory: true,
locale: {
id: defaultLocale
Expand Down
40 changes: 26 additions & 14 deletions www/js/services/wallet-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,40 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser
},

login = function(salt, password) {
return $q(function(resolve, reject) {
CryptoUtils.connect(salt, password).then(
function(keypair) {
// Copy result to properties
data.pubkey = CryptoUtils.util.encode_base58(keypair.signPk);
data.keypair = keypair;
if (csSettings.data.useLocalStorage) {
store();
}
resolve(data);
}
);
});
return $q(function(resolve, reject) {
CryptoUtils.connect(salt, password).then(
function(keypair) {
// Copy result to properties
data.pubkey = CryptoUtils.util.encode_base58(keypair.signPk);
data.keypair = keypair;
if (csSettings.data.useLocalStorage) {
store();
}

// Send login event
api.data.raise.login(data);

resolve(data);
}
);
});
},

logout = function(username, password) {
return $q(function(resolve, reject) {

resetData(); // will reset keypair
store(); // store (if local storage enable)

// Send logout event
api.data.raise.logout();

resolve();
});
},

isLogin = function() {
return !!data.pubkey;
return !!data.pubkey;
},

// If connected and same pubkey
Expand Down Expand Up @@ -229,6 +237,8 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser
data.loaded = false;
}

api.data.raise.login(data);

// Load parameters
// This prevent timeout error, when loading a market record after a browser refresh (e.g. F5)
return loadParameters();
Expand Down Expand Up @@ -1131,6 +1141,8 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser
;

// Register extension points
api.registerEvent('data', 'login');
api.registerEvent('data', 'logout');
api.registerEvent('data', 'load');
api.registerEvent('data', 'reset');

Expand Down
4 changes: 2 additions & 2 deletions www/plugins/es/js/controllers/common-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ function ESMenuExtendController($scope, $state, screenmatch, PluginService, csSe

}

function ESPicturesEditController($scope, $ionicModal, Wallet, esMarket, UIUtils, $state, CryptoUtils, $q, $ionicPopup, Device, $timeout, ModalUtils) {
function ESPicturesEditController($scope, UIUtils, $q, Device) {
'ngInject';

$scope.selectNewPicture = function() {
if ($scope.isDeviceEnable()){
if (Device.enable){
openPicturePopup();
}
else {
Expand Down
3 changes: 1 addition & 2 deletions www/plugins/es/templates/market/edit_record.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ <h4 class="gray" ng-if="id">
ng-show="!useRelative">
<span class="input-label">{{'MARKET.EDIT.RECORD_PRICE' | translate}} ({{currency | abbreviate}})</span>
<input type="text" name="price" placeholder="{{'MARKET.EDIT.RECORD_PRICE_HELP' | translate}} ({{currency | abbreviate}})"
ng-model="formData.price"
required>
ng-model="formData.price">
<span class="gray button button-block icon ion-arrow-swap hidden-xs hidden-sm" ng-click="unitPopover.show($event)">
</span>
<span class="gray button button-block button-clear button-icon visible-xs visible-sm" ng-click="unitPopover.show($event)">
Expand Down
6 changes: 3 additions & 3 deletions www/plugins/es/templates/menu_extend.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<ng-if ng-if="enable && extensionPoint === 'menu-user'">
<!-- user profile -->
<ion-item menu-close class="item item-icon-left" active-link="active"
ng-if="isLogin()"
ng-if="$root.login"
href="#/app/user/profile/edit">
<i class="icon ion-person"></i>
<span translate>MENU.USER_PROFILE</span>
</ion-item>
<ion-item menu-close class="item item-icon-left" active-link="active"
ng-if="!isLogin()"
<ion-item menu-close class="item item-icon-left item-menu-disable" active-link="active"
ng-if="!$root.login"
ng-click="login('app.user_edit_profile')">
<i class="icon ion-person"></i>
<span translate>MENU.USER_PROFILE</span>
Expand Down
4 changes: 1 addition & 3 deletions www/plugins/es/templates/user/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ <h4 class="light">
<input type="file" id="avatarFile" accept=".png,.jpeg,.jpg" onchange="angular.element(this).scope().fileChanged(event)"
style="visibility:hidden; position:absolute;"/>

<ion-list class="animate-ripple item-text-wrap" ng-init="setForm(profileForm)"
can-swipe="isDeviceEnable()">

<ion-list class="animate-ripple item-text-wrap" ng-init="setForm(profileForm)">

<div class="item item-divider">
{{'PROFILE.GENERAL_DIVIDER' | translate}}
Expand Down
6 changes: 3 additions & 3 deletions www/templates/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ <h4 class="visible-xs" translate>HOME.MESSAGE_SHORT</h4>

<button type="button"
class="button button-block button-positive button-raised icon icon-left ion-locked ink-dark"
ng-click="login()" ng-show="!isLogin()" translate>COMMON.BTN_LOGIN</button>
ng-click="login()" ng-show="!$root.login" translate>COMMON.BTN_LOGIN</button>
<button type="button"
class="button button-block button-positive button-raised icon icon-left ion-card ink-dark"
ui-sref="app.view_wallet" ng-show="isLogin()" translate>HOME.BTN_ACCOUNT</button>
ui-sref="app.view_wallet" ng-show="$root.login" translate>HOME.BTN_ACCOUNT</button>

<div class="text-center no-padding" ng-show="!isLogin()">
<div class="text-center no-padding" ng-show="!$root.login">
{{'LOGIN.NO_ACCOUNT_QUESTION'|translate}}
<br class="visible-xs">
<b>
Expand Down
12 changes: 6 additions & 6 deletions www/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ <h1 class="title royal" translate>
<!-- USER Section -->
<div class="item item-divider"></div>

<ion-item menu-close class="item item-icon-left item-menu-disable" ng-click="login('app.view_wallet')" ng-if="!isLogin()">
<ion-item menu-close class="item item-icon-left item-menu-disable" ng-click="login('app.view_wallet')" ng-if="!$root.login">
<i class="icon ion-card"></i>
<span translate>MENU.ACCOUNT</span>
</ion-item>
<ion-item menu-close class="item item-icon-left" active-link="active" href="#/app/wallet" ng-if="isLogin()">
<ion-item menu-close class="item item-icon-left" active-link="active" href="#/app/wallet" ng-if="$root.login">
<i class="icon ion-card"></i>
<span translate>MENU.ACCOUNT</span>
</ion-item>
Expand All @@ -77,22 +77,22 @@ <h1 class="title royal" translate>
</ion-item>

<!-- actions -->
<div class="item item-divider" ng-if="isLogin()"></div>
<ion-item menu-close class="item item-button-right" ng-if="isLogin()">
<div class="item item-divider" ng-if="$root.login"></div>
<ion-item menu-close class="item item-button-right" ng-if="$root.login">
<span translate>MENU.TRANSFER</span>
<button class="button button-energized-900" ng-click="showTransferModal()">
<i class="icon ion-paper-airplane"></i>
</button>
</ion-item>
<!-- scan QR code -->
<ion-item menu-close class="item item-button-right" ng-if="isDeviceEnable()">
<ion-item menu-close class="item item-button-right" ng-if="$root.device.enable">
<span translate>Scan</span>
<button class="button button-stable" ng-click="scanQrCodeAndGo()">
<i class="icon ion-qr-scanner"></i>
</button>
</ion-item>
<!-- log out -->
<ion-item menu-close class="item item-button-right" ng-if="isLogin()">
<ion-item menu-close class="item item-button-right" ng-if="$root.login">
<span translate>COMMON.BTN_LOGOUT</span>
<button class="button button-stable" ng-click="logout()">
<i class="icon ion-log-out"></i>
Expand Down
1 change: 1 addition & 0 deletions www/templates/wot/lookup_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

<ion-list
class="animate-ripple"
can-swipe="$root.device.enable"
ng-if="!search.looking && search.results.length">

<ion-item ng-repeat="identity in search.results" class="item-border-large item-avatar item-icon-right ink" ng-click="select(identity)">
Expand Down
2 changes: 1 addition & 1 deletion www/templates/wot/modal_lookup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1 class="title" translate>WOT.MODAL.TITLE</h1>

<button class="button button-icon button-clear icon ion-qr-scanner visible-xs hidden-no-device"
ng-if="isDeviceEnable()"
ng-if="$root.device.enable"
ng-click="scanQrCode()">
</button>
</ion-header-bar>
Expand Down

0 comments on commit 52b4c7a

Please sign in to comment.