Skip to content

Commit 90a73d7

Browse files
authored
✨ Context Wallet in Application (#4900)
1 parent c9b54f3 commit 90a73d7

File tree

15 files changed

+215
-192
lines changed

15 files changed

+215
-192
lines changed

services/static-webserver/client/source/class/osparc/Preferences.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ qx.Class.define("osparc.Preferences", {
117117
requestChangePreferredWalletId: function(walletId) {
118118
this.self().patchPreference("preferredWalletId", walletId)
119119
.then(() => {
120-
this.setPreferredWalletId(walletId);
121-
const wallets = osparc.store.Store.getInstance().getWallets();
120+
const store = osparc.store.Store.getInstance();
121+
const wallets = store.getWallets();
122+
const walletFound = wallets.find(wallet => wallet.getWalletId() === walletId);
123+
if (walletFound) {
124+
store.setPreferredWallet(walletFound);
125+
}
122126
wallets.forEach(wallet => wallet.setPreferredWallet(wallet.getWalletId() === walletId));
127+
this.setPreferredWalletId(walletId);
123128
})
124129
.catch(err => {
125130
console.error(err);

services/static-webserver/client/source/class/osparc/data/Roles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ qx.Class.define("osparc.data.Roles", {
5858
}
5959
},
6060

61+
// study, templates, services
6162
RESOURCE: {
6263
1: {
6364
id: "read",

services/static-webserver/client/source/class/osparc/desktop/MainPage.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ qx.Class.define("osparc.desktop.MainPage", {
6969
const creditsWindow = osparc.desktop.credits.UserCenterWindow.openWindow();
7070
creditsWindow.openOverview();
7171
}
72-
const preferenceSettings = osparc.Preferences.getInstance();
73-
const preferenceWalletId = preferenceSettings.getPreferredWalletId();
74-
const wallets = store.getWallets();
75-
if (wallets.length === 1 && (preferenceWalletId === null || osparc.desktop.credits.Utils.getWallet(preferenceWalletId) === null)) {
76-
// If there is only one wallet available, make it default
77-
preferenceSettings.requestChangePreferredWalletId(wallets[0].getWalletId());
78-
}
7972

8073
const mainStack = this.__createMainStack();
8174
this._add(mainStack, {

services/static-webserver/client/source/class/osparc/desktop/credits/Activity.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ qx.Class.define("osparc.desktop.credits.Activity", {
2323

2424
this._setLayout(new qx.ui.layout.VBox(15));
2525

26-
const wallet = osparc.desktop.credits.Utils.getContextWallet();
27-
this.setContextWallet(wallet);
26+
const store = osparc.store.Store.getInstance();
27+
store.bind("contextWallet", this, "contextWallet");
2828
},
2929

3030
properties: {
@@ -69,7 +69,7 @@ qx.Class.define("osparc.desktop.credits.Activity", {
6969
});
7070
this._add(control);
7171
break;
72-
case "page-buttons":
72+
case "page-buttons-layout":
7373
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({
7474
allowGrowX: true,
7575
alignX: "center",
@@ -83,7 +83,7 @@ qx.Class.define("osparc.desktop.credits.Activity", {
8383
allowGrowX: false
8484
});
8585
control.addListener("execute", () => this.__fetchData(this.__getPrevRequest()));
86-
const pageButtons = this.getChildControl("page-buttons");
86+
const pageButtons = this.getChildControl("page-buttons-layout");
8787
pageButtons.add(control);
8888
break;
8989
}
@@ -93,7 +93,7 @@ qx.Class.define("osparc.desktop.credits.Activity", {
9393
textAlign: "center",
9494
alignY: "middle"
9595
});
96-
const pageButtons = this.getChildControl("page-buttons");
96+
const pageButtons = this.getChildControl("page-buttons-layout");
9797
pageButtons.add(control);
9898
break;
9999
}
@@ -103,7 +103,7 @@ qx.Class.define("osparc.desktop.credits.Activity", {
103103
allowGrowX: false
104104
});
105105
control.addListener("execute", () => this.__fetchData(this.__getNextUsageRequest()));
106-
const pageButtons = this.getChildControl("page-buttons");
106+
const pageButtons = this.getChildControl("page-buttons-layout");
107107
pageButtons.add(control);
108108
break;
109109
}

services/static-webserver/client/source/class/osparc/desktop/credits/BuyCredits.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ qx.Class.define("osparc.desktop.credits.BuyCredits", {
2323

2424
this._setLayout(new qx.ui.layout.VBox(15));
2525

26-
const wallet = osparc.desktop.credits.Utils.getContextWallet();
27-
this.setContextWallet(wallet);
26+
const store = osparc.store.Store.getInstance();
27+
store.bind("contextWallet", this, "contextWallet");
2828
},
2929

3030
properties: {
@@ -100,22 +100,15 @@ qx.Class.define("osparc.desktop.credits.BuyCredits", {
100100
},
101101

102102
__buildLayout: function() {
103-
this.getChildControl("credits-intro");
104-
this.getChildControl("credits-left-view");
103+
this._removeAll();
104+
this._createChildControlImpl("credits-intro");
105+
this._createChildControlImpl("credits-left-view");
105106
const wallet = this.getContextWallet();
106107
if (wallet.getMyAccessRights()["write"]) {
107-
this.__populateLayout();
108-
} else {
109-
this._add(osparc.desktop.credits.Utils.getNoWriteAccessLabel());
110-
}
111-
},
112-
113-
__populateLayout: function() {
114-
const wallet = this.getContextWallet();
115-
if (wallet) {
116-
const paymentMode = this.getChildControl("payment-mode");
117-
const autoRecharge = this.getChildControl("auto-recharge");
118-
const oneTime = this.getChildControl("one-time-payment");
108+
this._createChildControlImpl("wallet-billing-settings");
109+
const paymentMode = this._createChildControlImpl("payment-mode");
110+
const autoRecharge = this._createChildControlImpl("auto-recharge");
111+
const oneTime = this._createChildControlImpl("one-time-payment");
119112
autoRecharge.show();
120113
oneTime.exclude();
121114
paymentMode.addListener("changeSelection", e => {
@@ -128,6 +121,8 @@ qx.Class.define("osparc.desktop.credits.BuyCredits", {
128121
oneTime.exclude();
129122
}
130123
});
124+
} else {
125+
this._add(osparc.desktop.credits.Utils.getNoWriteAccessOperationsLabel());
131126
}
132127
},
133128

services/static-webserver/client/source/class/osparc/desktop/credits/Summary.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ qx.Class.define("osparc.desktop.credits.Summary", {
2323

2424
this._setLayout(new qx.ui.layout.VBox(10));
2525

26-
const wallet = osparc.desktop.credits.Utils.getContextWallet();
27-
this.setContextWallet(wallet);
26+
const store = osparc.store.Store.getInstance();
27+
store.bind("contextWallet", this, "contextWallet");
2828
},
2929

3030
properties: {
@@ -75,9 +75,13 @@ qx.Class.define("osparc.desktop.credits.Summary", {
7575
},
7676

7777
__buildLayout: function() {
78-
this.getChildControl("wallets-card");
79-
this.getChildControl("settings-card");
80-
this.getChildControl("activity-card");
78+
this._removeAll();
79+
this._createChildControlImpl("wallets-card");
80+
const wallet = this.getContextWallet();
81+
if (wallet && wallet.getMyAccessRights()["write"]) {
82+
this._createChildControlImpl("settings-card");
83+
}
84+
this._createChildControlImpl("activity-card");
8185
},
8286

8387
__createOverviewCard: function(cardLabel, content, buttonLabel, signalName, signalData) {
@@ -246,7 +250,7 @@ qx.Class.define("osparc.desktop.credits.Summary", {
246250

247251
return layout;
248252
}
249-
return osparc.desktop.credits.Utils.getNoWriteAccessLabel();
253+
return null;
250254
},
251255

252256
__createActivityView: function() {

services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ qx.Class.define("osparc.desktop.credits.Transactions", {
2323

2424
this._setLayout(new qx.ui.layout.VBox(15));
2525

26-
const wallet = osparc.desktop.credits.Utils.getContextWallet();
27-
this.setContextWallet(wallet);
26+
const store = osparc.store.Store.getInstance();
27+
store.bind("contextWallet", this, "contextWallet");
2828
},
2929

3030
properties: {
@@ -49,9 +49,10 @@ qx.Class.define("osparc.desktop.credits.Transactions", {
4949
},
5050

5151
__buildLayout: function() {
52+
this._removeAll();
5253
const wallet = this.getContextWallet();
53-
if (wallet.getMyAccessRights()["write"]) {
54-
const transactionsTable = this.getChildControl("transactions-table");
54+
if (wallet && wallet.getMyAccessRights()["write"]) {
55+
const transactionsTable = this._createChildControlImpl("transactions-table");
5556
osparc.data.Resources.fetch("payments", "get")
5657
.then(transactions => {
5758
if ("data" in transactions) {
@@ -60,7 +61,7 @@ qx.Class.define("osparc.desktop.credits.Transactions", {
6061
})
6162
.catch(err => console.error(err));
6263
} else {
63-
this._add(osparc.desktop.credits.Utils.getNoWriteAccessLabel());
64+
this._add(osparc.desktop.credits.Utils.getNoWriteAccessInformationLabel());
6465
}
6566
},
6667

services/static-webserver/client/source/class/osparc/desktop/credits/Usage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ qx.Class.define("osparc.desktop.credits.Usage", {
2323

2424
this._setLayout(new qx.ui.layout.VBox(15));
2525

26-
const wallet = osparc.desktop.credits.Utils.getContextWallet();
27-
this.setContextWallet(wallet);
26+
const store = osparc.store.Store.getInstance();
27+
store.bind("contextWallet", this, "contextWallet");
2828
},
2929

3030
properties: {

services/static-webserver/client/source/class/osparc/desktop/credits/UserCenterWindow.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ qx.Class.define("osparc.desktop.credits.UserCenterWindow", {
1919
extend: osparc.ui.window.SingletonWindow,
2020

2121
construct: function() {
22-
this.base(arguments, "credits", this.tr("User Center"));
22+
const caption = this.tr("User Center");
23+
this.base(arguments, "credits", caption);
2324

2425
const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
2526
const viewWidth = walletsEnabled ? 1000 : 800;
2627
const viewHeight = walletsEnabled ? 700 : 600;
2728

29+
if (walletsEnabled) {
30+
const store = osparc.store.Store.getInstance();
31+
// Concatenate context wallet's name
32+
store.bind("contextWallet", this, "caption", {
33+
converter: contextWallet => caption + (contextWallet ? (" - " + contextWallet.getName()) : "")
34+
});
35+
}
36+
2837
this.set({
2938
layout: new qx.ui.layout.Grow(),
3039
modal: true,

services/static-webserver/client/source/class/osparc/desktop/credits/Utils.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@ qx.Class.define("osparc.desktop.credits.Utils", {
2424
return Boolean(statics && statics["isPaymentEnabled"]);
2525
},
2626

27-
getContextWallet: function() {
28-
const activeWallet = osparc.store.Store.getInstance().getActiveWallet();
29-
if (activeWallet) {
30-
return activeWallet;
31-
}
32-
const preferredWallet = osparc.desktop.credits.Utils.getPreferredWallet();
33-
if (preferredWallet) {
34-
return preferredWallet;
35-
}
36-
// It should never reach here
37-
return null;
27+
getNoWriteAccessInformationLabel: function() {
28+
return new qx.ui.basic.Label().set({
29+
value: qx.locale.Manager.tr("You can't access this information"),
30+
font: "text-14",
31+
allowGrowX: true
32+
});
3833
},
3934

40-
getNoWriteAccessLabel: function() {
35+
getNoWriteAccessOperationsLabel: function() {
4136
return new qx.ui.basic.Label().set({
42-
value: qx.locale.Manager.tr("You can't access this information"),
37+
value: qx.locale.Manager.tr("You can't access this operations"),
4338
font: "text-14",
4439
allowGrowX: true
4540
});
@@ -135,16 +130,6 @@ qx.Class.define("osparc.desktop.credits.Utils", {
135130
return [];
136131
},
137132

138-
getPreferredWallet: function() {
139-
const store = osparc.store.Store.getInstance();
140-
const wallets = store.getWallets();
141-
const favouriteWallet = wallets.find(wallet => wallet.isPreferredWallet());
142-
if (favouriteWallet) {
143-
return favouriteWallet;
144-
}
145-
return null;
146-
},
147-
148133
getPaymentMethods: function(walletId) {
149134
return new Promise(resolve => {
150135
const promises = [];

0 commit comments

Comments
 (0)