, totalWallets: number) {
+ this.walletData = wallets;
+ this.totalWallets = totalWallets;
+ console.log("eh");
+ this.update();
+ }
+
+ updateToken = () => {
+ if (this.isAuth) {
+ this.getWallets();
+ } else {
+ this.update();
+ }
+ };
+
+ update = () => {
+ render(this.render(), this);
+ };
+
+ get isAuth() {
+ return this.appMain.isAuth;
+ }
+
+ render = () => {
+ return html`
+
+ -
+ Home
+
+ ${this.isAuth
+ ? html` -
+ History
+
`
+ : null}
+ ${this.isAuth && this.totalWallets > 0
+ ? this.walletData.map((wallet) => {
+ return html`
+ -
+ ${wallet.name}
+
+ `;
+ })
+ : null}
+ ${this.isAuth && this.totalWallets > 2
+ ? html`
+ -
+ Other
+
+ `
+ : null}
+ ${this.isAuth
+ ? html` -
+ Logout
+
`
+ : null}
+ ${!this.isAuth
+ ? html`
+ -
+ Login
+
+ -
+ Register
+
+ `
+ : null}
+
+ `;
+ };
+}
diff --git a/src/components/app-shadow/AppShadowElement.ts b/src/components/app-shadow/AppShadowElement.ts
index f1c2fa5..68f97cf 100644
--- a/src/components/app-shadow/AppShadowElement.ts
+++ b/src/components/app-shadow/AppShadowElement.ts
@@ -11,16 +11,16 @@ class AppShadowElement extends HTMLElement {
super();
}
- @update
connectedCallback() {
this.attachShadow({ mode: "open" });
+ this.update();
}
- render() {
+ render = () => {
return html` `;
- }
+ };
- update() {
+ update = () => {
render(this.render(), this.shadowRoot!);
- }
+ };
}
diff --git a/src/components/index.ts b/src/components/index.ts
index 98486df..53a3fc4 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -4,4 +4,5 @@ export * from "./app-link/AppLinkElement";
export * from "./app-modal/AppModalElement";
export * from "./app-root/AppRootElement";
export * from "./app-slot/AppSlotElement";
+export * from "./app-menu/AppMenuElement";
export * from "./input-field/InputFieldElement";
diff --git a/src/components/input-field/InputFieldElement.ts b/src/components/input-field/InputFieldElement.ts
index c2d8cbd..7f9051a 100644
--- a/src/components/input-field/InputFieldElement.ts
+++ b/src/components/input-field/InputFieldElement.ts
@@ -24,9 +24,9 @@ class InputFieldElement extends HTMLElement {
super();
}
- @update
public connectedCallback(): void {
this.randId = `${name}${randomId()}`;
+ this.update();
}
get valid(): boolean {
@@ -37,7 +37,6 @@ class InputFieldElement extends HTMLElement {
return this.rules.includes("required");
}
- @update
validate(): boolean {
let _return = true;
const rules = this.rules?.split("|").filter((a) => a);
@@ -66,22 +65,24 @@ class InputFieldElement extends HTMLElement {
if (_return) {
this.error = null;
}
+ this.update();
return _return;
}
- update() {
- render(
- html`
- ${this.label &&
- html``}
-
- ${this.error && html`${this.error}`}
-
`,
- this
- );
- }
+ render = () => {
+ return html`
+ ${this.label &&
+ html``}
+
+ ${this.error && html`${this.error}`}
+
`;
+ };
+
+ update = () => {
+ render(this.render(), this);
+ };
}
export type { InputFieldElement };
diff --git a/src/core/services/app-service/AppService.ts b/src/core/services/app-service/AppService.ts
index 818bc81..b5e55be 100644
--- a/src/core/services/app-service/AppService.ts
+++ b/src/core/services/app-service/AppService.ts
@@ -120,8 +120,8 @@ class AppService {
response?.statusCode == 401
) {
if (response?.statusCode == 401) {
- this.appMain.authStore.token = null;
this.appMain.routerService.goTo("/token-expired");
+ this.appMain.authStore.token = null;
}
throw response;
}
diff --git a/src/core/services/base-service/BaseService.ts b/src/core/services/base-service/BaseService.ts
index 94f2890..7e04978 100644
--- a/src/core/services/base-service/BaseService.ts
+++ b/src/core/services/base-service/BaseService.ts
@@ -3,8 +3,8 @@ import { AppService, HttpClient } from "core/services";
class BaseService {
constructor(public endpoint: string, public appService: AppService) {}
- getAll = (headers?: HeadersInit) => {
- return this.appService.get(this.endpoint, null, headers);
+ getAll = (params?: Object, headers?: HeadersInit) => {
+ return this.appService.get(this.endpoint, params, headers);
};
get = (params?: Object, headers?: HeadersInit) => {
diff --git a/src/core/services/router-service/RouterService.ts b/src/core/services/router-service/RouterService.ts
index fdc0098..c85cc13 100644
--- a/src/core/services/router-service/RouterService.ts
+++ b/src/core/services/router-service/RouterService.ts
@@ -136,7 +136,6 @@ class RouterService {
}
}
- @update
goBack() {
if (!Array.isArray(this.historyStack)) this.historyStack = [];
const lenHistory = this.historyStack.length;
@@ -147,14 +146,15 @@ class RouterService {
window.history.pushState({}, "", url.toString());
this.historyStack.pop();
}
+ this.update();
}
- @update
init() {
window.addEventListener("popstate", () => {
this.historyStack.pop();
this.update();
});
+ this.update();
}
findByPath() {
diff --git a/src/layouts/menu-layout/MenuLayoutElement.ts b/src/layouts/menu-layout/MenuLayoutElement.ts
index e5df483..8a2aea7 100644
--- a/src/layouts/menu-layout/MenuLayoutElement.ts
+++ b/src/layouts/menu-layout/MenuLayoutElement.ts
@@ -24,28 +24,21 @@ class MenuLayoutElement extends BaseLayoutElement {
get isAuth() {
const _hasToken = this.appMain?.isAuth;
const _hasData = this.appMain?.authStore?.user;
- return _hasData && _hasToken;
+ return _hasToken;
}
updateAuth = () => {
this.update();
};
- render() {
+ render = () => {
return html`
- ${this.isAuth &&
- html``}
+
`;
- }
+ };
update = () => {
render(this.render(), this);
- const _appSlot = this._appSlot;
- if (_appSlot && this.appSlot) {
- this.appSlot.innerHTML = _appSlot;
- }
};
}
diff --git a/src/pages/history-page/HistoryPageElement.ts b/src/pages/history-page/HistoryPageElement.ts
new file mode 100644
index 0000000..2c7fdc1
--- /dev/null
+++ b/src/pages/history-page/HistoryPageElement.ts
@@ -0,0 +1,69 @@
+import { attr, targets, controller, target } from "@github/catalyst";
+import { closest, index, update, isTrue } from "core/utils";
+import { html, render, until } from "@github/jtml";
+import { TransactionsService } from "services/";
+import { AppMainElement } from "components/";
+
+@controller
+class HistoryPageElement extends HTMLElement {
+ private transactionsService: TransactionsService;
+ private transactions: Array = [];
+ @closest appMain: AppMainElement;
+ constructor() {
+ super();
+ }
+
+ connectedCallback() {
+ this.transactionsService = new TransactionsService(
+ this.appMain?.appService
+ );
+ if (this.appMain.isAuth) this.getTransactions();
+ this.update();
+ window.addEventListener("tokenchange", this.update);
+ }
+
+ disconnectedCallback(): void {
+ window.removeEventListener("tokenchange", this.update);
+ }
+
+ getTransactions = async () => {
+ try {
+ const response = await this.transactionsService.getAll();
+ if (response) {
+ this.setTransactions(response);
+ }
+ } catch (err) {
+ throw err;
+ }
+ };
+
+ setTransactions(transactions: Array) {
+ this.transactions = transactions;
+ this.update();
+ }
+
+ openModal = () => {
+ const _modal = this.appMain.appModal;
+ if (_modal) {
+ this.appMain.closeModal();
+ } else {
+ this.appMain.createModal("login-page");
+ }
+ };
+
+ render = () => {
+ return html`
+
+ ${this.transactions
+ ? this.transactions.map((transaction) => {
+ html` - ${transaction.description}
`;
+ })
+ : null}
+
+ `;
+ };
+
+ update = () => {
+ render(this.render(), this);
+ };
+}
diff --git a/src/pages/home-page/HomePageElement.ts b/src/pages/home-page/HomePageElement.ts
index be3cd35..1e9757c 100644
--- a/src/pages/home-page/HomePageElement.ts
+++ b/src/pages/home-page/HomePageElement.ts
@@ -44,22 +44,11 @@ class HomePageElement extends HTMLElement {
}
};
- render() {
+ render = () => {
return html`
- |
- ${this.appMain.isAuth
- ? html`
- |`
- : html``}
`;
- }
+ };
update = () => {
render(this.render(), this);
diff --git a/src/pages/index.ts b/src/pages/index.ts
index a15baa5..54953c9 100644
--- a/src/pages/index.ts
+++ b/src/pages/index.ts
@@ -3,3 +3,4 @@ export * from "./home-page/HomePageElement";
export * from "./register-page/RegisterPageElement";
export * from "./login-page/LoginPageElement";
export * from "./not-found/NotFoundElement";
+export * from "./history-page/HistoryPageElement";
diff --git a/src/pages/login-page/LoginPageElement.ts b/src/pages/login-page/LoginPageElement.ts
index a76869a..c463e00 100644
--- a/src/pages/login-page/LoginPageElement.ts
+++ b/src/pages/login-page/LoginPageElement.ts
@@ -11,13 +11,14 @@ class LoginPageElement extends HTMLElement {
@closest appMain: AppMainElement;
authService: AuthService;
routerService: RouterService;
+ errorMessage: string;
constructor() {
super();
}
- @update
connectedCallback() {
this.authService = new AuthService(this.appMain.appService);
this.routerService = this.appMain.routerService;
+ this.update();
}
get emailInput() {
@@ -65,6 +66,9 @@ class LoginPageElement extends HTMLElement {
} else if (err?.errorCode == 400104) {
this.passwordInput.error = err?.message;
this.passwordInput.update();
+ } else {
+ this.errorMessage = "Unable to log in!";
+ this.update();
}
}
};
@@ -78,7 +82,7 @@ class LoginPageElement extends HTMLElement {
return _return;
}
- render() {
+ render = () => {
return html`
`;
- }
+ };
- update() {
+ update = () => {
render(this.render(), this);
- }
+ };
}
diff --git a/src/services/TransactionsService.ts b/src/services/TransactionsService.ts
new file mode 100644
index 0000000..613c1e4
--- /dev/null
+++ b/src/services/TransactionsService.ts
@@ -0,0 +1,9 @@
+import { AppService, BaseService } from "core/services";
+
+class TransactionsService extends BaseService {
+ constructor(appService: AppService) {
+ super("/transaction", appService);
+ }
+}
+
+export default TransactionsService;
diff --git a/src/services/WalletService.ts b/src/services/WalletService.ts
new file mode 100644
index 0000000..f183918
--- /dev/null
+++ b/src/services/WalletService.ts
@@ -0,0 +1,9 @@
+import { AppService, BaseService } from "core/services";
+
+class WalletService extends BaseService {
+ constructor(appService: AppService) {
+ super("/wallet", appService);
+ }
+}
+
+export default WalletService;
diff --git a/src/services/index.ts b/src/services/index.ts
index 1c63abb..905493a 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -1,2 +1,4 @@
export { default as PingService } from "./PingService";
export { default as AuthService } from "./AuthService";
+export { default as WalletService } from "./WalletService";
+export { default as TransactionsService } from "./TransactionsService";