+ return html`
${renderMessage(this.label)} ${renderInput(this.type)}
${renderError(this.displayError, this.error)}
`;
diff --git a/src/components/wallet-header/WalletHeaderElement.ts b/src/components/wallet-header/WalletHeaderElement.ts
new file mode 100644
index 0000000..ef99abf
--- /dev/null
+++ b/src/components/wallet-header/WalletHeaderElement.ts
@@ -0,0 +1,70 @@
+import { attr, controller, target } from "@github/catalyst";
+import { html, TemplateResult } from "@github/jtml";
+import { BaseComponentElement } from "common/";
+import { CircleLoaderElement } from "components/circle-loader/CircleLoaderElement";
+import { findMethod } from "core/utils";
+
+@controller
+class WalletHeaderElement extends BaseComponentElement {
+ @attr currentBalance: number;
+ @attr lastMonth: number;
+ @attr nextMonth: number;
+ @attr currency: string;
+ @attr custom: string;
+
+ fetchFunc: Function = () => {};
+ constructor() {
+ super();
+ }
+
+ elementConnected = (): void => {
+ this.executeFetch();
+ this.update();
+ };
+
+ attributeChangedCallback(): void {
+ this.update();
+ }
+
+ executeFetch = async (options?): Promise
=> {
+ const actionString = this.custom;
+ const submitFunc = findMethod(actionString, this.appMain);
+
+ try {
+ this.loader?.start?.();
+ await submitFunc(options);
+ this.loader?.stop?.();
+ } catch (err) {
+ this.loader?.stop?.();
+ console.error(err);
+ }
+ };
+
+ render = (): TemplateResult => {
+ const { currentBalance, currency, lastMonth, nextMonth } = this;
+
+ const renderItem = (header, balance, currency) => html`
+
${header}
+
${balance}${currency}
+
`;
+
+ const renderHeader = () => {
+ if (this.loader && this.loader.loading) {
+ return html``;
+ }
+ return html`${renderItem(
+ "Last Month",
+ lastMonth,
+ currency
+ )}${renderItem(
+ "Current Balance",
+ currentBalance,
+ currency
+ )}${renderItem("Next Month", nextMonth, currency)}`;
+ };
+
+ return html`${renderHeader()}
`;
+ };
+}
+
+export type { WalletHeaderElement };
diff --git a/src/layouts/index.ts b/src/layouts/index.ts
index 65489b5..fbbca00 100644
--- a/src/layouts/index.ts
+++ b/src/layouts/index.ts
@@ -1 +1,2 @@
export * from "./menu-layout/MenuLayoutElement";
+export * from "./initial-layout/InitialLayoutElement";
diff --git a/src/layouts/initial-layout/InitialLayoutElement.ts b/src/layouts/initial-layout/InitialLayoutElement.ts
new file mode 100644
index 0000000..f3b7275
--- /dev/null
+++ b/src/layouts/initial-layout/InitialLayoutElement.ts
@@ -0,0 +1,31 @@
+import { controller, target } from "@github/catalyst";
+import { closest } from "core/utils";
+import { html, TemplateResult } from "@github/jtml";
+import { BaseLayoutElement } from "common/layouts";
+import { AppMainElement } from "components/";
+
+@controller
+class InitialLayoutElement extends BaseLayoutElement {
+ @closest appMain: AppMainElement;
+ @target appPage: HTMLDivElement;
+
+ constructor() {
+ super();
+ }
+
+ elementConnected = (): void => {
+ this.update();
+ };
+
+ elementDisconnected = (appMain: AppMainElement): void => {};
+
+ render = (): TemplateResult => {
+ return html`
+
+ `;
+ };
+}
+
+export type { InitialLayoutElement };
diff --git a/src/pages/home-page/HomePageElement.ts b/src/pages/home-page/HomePageElement.ts
index 6102743..a31080e 100644
--- a/src/pages/home-page/HomePageElement.ts
+++ b/src/pages/home-page/HomePageElement.ts
@@ -1,12 +1,13 @@
-import { controller } from "@github/catalyst";
+import { controller, target } from "@github/catalyst";
import { html, TemplateResult, until } from "@github/jtml";
-import { PingService } from "services/";
-import { AppMainElement } from "components/";
+import { WalletService } from "services/";
+import { AppMainElement, WalletHeaderElement } from "components/";
import { BasePageElement } from "common/";
@controller
class HomePageElement extends BasePageElement {
- private pingService: PingService;
+ @target walletHeader: WalletHeaderElement;
+ private walletService: WalletService;
constructor() {
super({
title: "Home",
@@ -14,25 +15,31 @@ class HomePageElement extends BasePageElement {
}
elementConnected = (): void => {
- this.pingService = new PingService(this.appMain?.appService);
+ this.walletService = new WalletService(this.appMain?.appService);
this.update();
this.appMain.addEventListener("tokenchange", this.update);
+ this.getBalance();
};
elementDisconnected = (appMain: AppMainElement): void => {
appMain?.removeEventListener("tokenchange", this.update);
};
- getPong = async (): Promise => {
+ getBalance = async (): Promise => {
try {
- const response = await this.pingService.getAll();
+ const response = await this.walletService.getBalance();
+ this.setBalance(response);
} catch (err) {
throw err;
}
};
- pongEl = (): TemplateResult => {
- return html`${until(this.getPong())}
`;
+ setBalance = (header) => {
+ if (!this.walletHeader) return;
+ this.walletHeader.currency = header.currency;
+ this.walletHeader.currentBalance = header.currentBalance || "0";
+ this.walletHeader.lastMonth = header.lastMonth || "0";
+ this.walletHeader.nextMonth = header.nextMonth || "0";
};
openModal = (): void => {
@@ -47,6 +54,14 @@ class HomePageElement extends BasePageElement {
render = (): TemplateResult => {
return html`
+
`;
};
}
diff --git a/src/pages/index.ts b/src/pages/index.ts
index a1ba7d7..a51280e 100644
--- a/src/pages/index.ts
+++ b/src/pages/index.ts
@@ -7,3 +7,4 @@ export * from "./history-page/HistoryPageElement";
export * from "./wallet-list/WalletListElement";
export * from "./wallet-create/WalletCreateElement";
export * from "./transaction-create/TransactionCreateElement";
+export * from "./wallet-page/WalletPageElement";
diff --git a/src/pages/transaction-create/TransactionCreateElement.ts b/src/pages/transaction-create/TransactionCreateElement.ts
index 8c2280c..4ab10a7 100644
--- a/src/pages/transaction-create/TransactionCreateElement.ts
+++ b/src/pages/transaction-create/TransactionCreateElement.ts
@@ -51,15 +51,22 @@ class TransactionCreateElement extends BasePageElement {
} catch (err) {}
};
- onSubmit = async (): Promise => {
+ onSubmit = async (values): Promise => {
try {
if (!this.validate()) {
return;
}
- const { name: description, wallet: walletId } = this.values;
+
+ const {
+ description: description,
+ wallet: walletId,
+ amount,
+ } = values;
+
const response = await this.transactionService.post({
description,
walletId,
+ amount,
});
if (response?.id) {
@@ -90,10 +97,17 @@ class TransactionCreateElement extends BasePageElement {
data-custom="transaction-create#onSubmit"
data-has-cancel="true"
>
+
diff --git a/src/pages/wallet-page/WalletPageElement.ts b/src/pages/wallet-page/WalletPageElement.ts
new file mode 100644
index 0000000..8326f82
--- /dev/null
+++ b/src/pages/wallet-page/WalletPageElement.ts
@@ -0,0 +1,105 @@
+import { controller, target } from "@github/catalyst";
+import { html, TemplateResult } from "@github/jtml";
+import { TransactionsService, WalletService } from "services/";
+import {
+ AppMainElement,
+ AppPaginationElement,
+ WalletHeaderElement,
+} from "components/";
+import { BasePageElement } from "common/";
+
+@controller
+class WalletPageElement extends BasePageElement {
+ private transactionsService: TransactionsService;
+ private walletService: WalletService;
+ @target pagination: AppPaginationElement;
+ @target walletHeader: WalletHeaderElement;
+ walletId: string;
+ constructor() {
+ super({
+ title: "Wallet",
+ });
+ }
+
+ elementConnected = (): void => {
+ this.walletService = new WalletService(this.appMain?.appService);
+ this.transactionsService = new TransactionsService(
+ this.appMain?.appService
+ );
+ if (this?.routerService?.routerState?.data) {
+ const { walletId } = this?.routerService?.routerState?.data;
+ if (walletId) {
+ this.walletId = walletId;
+ }
+ }
+ this.update();
+ this.pagination?.setFetchFunc?.(this.getTransactions, true)!;
+ this.appMain.addEventListener("tokenchange", this.update);
+ };
+
+ elementDisconnected = (appMain: AppMainElement): void => {
+ appMain?.removeEventListener("tokenchange", this.update);
+ };
+
+ getTransactions = async (options): Promise => {
+ try {
+ if (this?.routerService?.routerState?.data) {
+ const { walletId } = this?.routerService?.routerState?.data;
+ if (walletId) {
+ options["walletId"] = walletId;
+ }
+ }
+ const response = await this.transactionsService.getAll(options);
+ return response;
+ } catch (err) {
+ throw err;
+ }
+ };
+
+ getBalance = async (): Promise => {
+ try {
+ const response = await this.walletService.getBalance({
+ walletId: this.walletId,
+ });
+ this.setBalance(response);
+ } catch (err) {
+ throw err;
+ }
+ };
+
+ setBalance = (header) => {
+ if (!this.walletHeader) return;
+ this.walletHeader.currency = header.currency;
+ this.walletHeader.currentBalance = header.currentBalance || "0";
+ this.walletHeader.lastMonth = header.lastMonth || "0";
+ this.walletHeader.nextMonth = header.nextMonth || "0";
+ };
+
+ render = (): TemplateResult => {
+ const renderHeader = () => html``;
+
+ const renderWallet = () => {
+ if (this.routerService?.routerState?.data?.walletId) {
+ return html`${this.routerService?.routerState?.data?.walletId}`;
+ }
+ return html``;
+ };
+ return html`
+ ${renderHeader()} ${renderWallet()}
+
+
`;
+ };
+}
+
+export type { WalletPageElement };
diff --git a/src/services/WalletService.ts b/src/services/WalletService.ts
index f183918..7092e50 100644
--- a/src/services/WalletService.ts
+++ b/src/services/WalletService.ts
@@ -4,6 +4,14 @@ class WalletService extends BaseService {
constructor(appService: AppService) {
super("/wallet", appService);
}
+
+ getBalance = (params?: Object, headers?: HeadersInit) => {
+ return this.appService.get(
+ this.endpoint + "/wallet-header",
+ params,
+ headers
+ );
+ };
}
export default WalletService;
diff --git a/src/styles/app-form/app-form.scss b/src/styles/app-form/app-form.scss
new file mode 100644
index 0000000..be2f664
--- /dev/null
+++ b/src/styles/app-form/app-form.scss
@@ -0,0 +1,20 @@
+app-form {
+ form[data-target="app-form.formElement"] {
+ width: 56%;
+ margin: 0 auto;
+
+ input-field,
+ app-dropdown > .input-main {
+ width: 100%;
+ display: block;
+ input,
+ select {
+ width: 100%;
+ padding: 2px 0;
+ margin: 6px 0;
+ display: block;
+ font-size: 16px;
+ }
+ }
+ }
+}
diff --git a/src/styles/app-form/index.scss b/src/styles/app-form/index.scss
new file mode 100644
index 0000000..a8c756b
--- /dev/null
+++ b/src/styles/app-form/index.scss
@@ -0,0 +1 @@
+@import "./app-form.scss";
diff --git a/src/styles/layout/index.scss b/src/styles/layout/index.scss
new file mode 100644
index 0000000..131ae0d
--- /dev/null
+++ b/src/styles/layout/index.scss
@@ -0,0 +1 @@
+@import "./menu-layout.scss";
diff --git a/src/styles/layout/menu-layout.scss b/src/styles/layout/menu-layout.scss
new file mode 100644
index 0000000..97690ce
--- /dev/null
+++ b/src/styles/layout/menu-layout.scss
@@ -0,0 +1,3 @@
+[data-target="input-field.main"] {
+ width: 100%;
+}
diff --git a/src/styles/main.scss b/src/styles/main.scss
index 69df669..b9761cc 100644
--- a/src/styles/main.scss
+++ b/src/styles/main.scss
@@ -6,3 +6,5 @@
@import "./app-loader/index.scss";
@import "./circle-loader/index.scss";
@import "./page/index.scss";
+@import "./app-form/index.scss";
+@import "./layout/index.scss";