From b72729f06535f12af974035b141a30320e75575c Mon Sep 17 00:00:00 2001
From: Sebastian
Date: Fri, 10 Mar 2023 13:13:51 -0300
Subject: admin is allow to make wire transfers
---
packages/demobank-ui/src/pages/AdminPage.tsx | 62 +++++++++++++++++++++-
.../src/pages/PaytoWireTransferForm.tsx | 5 +-
2 files changed, 64 insertions(+), 3 deletions(-)
(limited to 'packages/demobank-ui')
diff --git a/packages/demobank-ui/src/pages/AdminPage.tsx b/packages/demobank-ui/src/pages/AdminPage.tsx
index 58b048b83..3dd34d251 100644
--- a/packages/demobank-ui/src/pages/AdminPage.tsx
+++ b/packages/demobank-ui/src/pages/AdminPage.tsx
@@ -28,7 +28,12 @@ import {
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { Cashouts } from "../components/Cashouts/index.js";
-import { ErrorMessage, usePageContext } from "../context/pageState.js";
+import { useBackendContext } from "../context/backend.js";
+import {
+ ErrorMessage,
+ PageStateType,
+ usePageContext,
+} from "../context/pageState.js";
import { useAccountDetails } from "../hooks/access.js";
import {
useBusinessAccountDetails,
@@ -45,6 +50,8 @@ import {
} from "../utils.js";
import { ErrorBannerFloat } from "./BankFrame.js";
import { ShowCashoutDetails } from "./BusinessAccount.js";
+import { PaymentOptions } from "./PaymentOptions.js";
+import { PaytoWireTransferForm } from "./PaytoWireTransferForm.js";
import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
const charset =
@@ -89,6 +96,9 @@ export function AdminPage({ onLoadNotOk }: Props): VNode {
info,
}));
}
+ function saveError(error: PageStateType["error"]): void {
+ pageStateSetter((prev) => ({ ...prev, error }));
+ }
const result = useBusinessAccounts({ account });
const { i18n } = useTranslationContext();
@@ -204,6 +214,55 @@ export function AdminPage({ onLoadNotOk }: Props): VNode {
/>
);
}
+
+ function AdminAccount(): VNode {
+ const r = useBackendContext();
+ const account = r.state.status === "loggedIn" ? r.state.username : "admin";
+ const result = useAccountDetails(account);
+
+ if (!result.ok) {
+ return onLoadNotOk(result);
+ }
+ const { data } = result;
+ const balance = Amounts.parse(data.balance.amount);
+ const balanceIsDebit = data.balance.credit_debit_indicator == "debit";
+ if (!balance) return ;
+ return (
+
+
+
+
{i18n.str`Bank account balance`}
+ {!balance ? (
+
+ Waiting server response...
+
+ ) : (
+
+ {balanceIsDebit ? - : null}
+ {`${Amounts.stringifyValue(
+ balance,
+ )}`}
+
+ {`${balance.currency}`}
+
+ )}
+
+
+ {
+ pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ info: i18n.str`Wire transfer created!`,
+ }));
+ }}
+ onError={saveError}
+ />
+
+ );
+ }
+
return (
@@ -230,6 +289,7 @@ export function AdminPage({ onLoadNotOk }: Props): VNode {
+