aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/components/Transactions/state.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/components/Transactions/state.ts')
-rw-r--r--packages/demobank-ui/src/components/Transactions/state.ts53
1 files changed, 29 insertions, 24 deletions
diff --git a/packages/demobank-ui/src/components/Transactions/state.ts b/packages/demobank-ui/src/components/Transactions/state.ts
index 5d613c5d0..b17986e48 100644
--- a/packages/demobank-ui/src/components/Transactions/state.ts
+++ b/packages/demobank-ui/src/components/Transactions/state.ts
@@ -20,7 +20,11 @@ import { useEffect } from "preact/hooks";
import useSWR from "swr";
import { Props, State } from "./index.js";
-export function useComponentState({ accountLabel, pageNumber, balanceValue }: Props): State {
+export function useComponentState({
+ accountLabel,
+ pageNumber,
+ balanceValue,
+}: Props): State {
const { data, error, mutate } = useSWR(
`access-api/accounts/${accountLabel}/transactions?page=${pageNumber}`,
);
@@ -39,40 +43,41 @@ export function useComponentState({ accountLabel, pageNumber, balanceValue }: Pr
error: {
hasError: true,
operational: false,
- message: `Transactions page ${pageNumber} was not found.`
- }
- }
+ message: `Transactions page ${pageNumber} was not found.`,
+ },
+ };
case 401:
return {
status: "loading-error",
error: {
hasError: true,
operational: false,
- message: "Wrong credentials given."
- }
- }
+ message: "Wrong credentials given.",
+ },
+ };
default:
return {
status: "loading-error",
error: {
hasError: true,
operational: false,
- message: `Transaction page ${pageNumber} could not be retrieved.`
- } as any
- }
+ message: `Transaction page ${pageNumber} could not be retrieved.`,
+ } as any,
+ };
}
}
if (!data) {
return {
status: "loading",
- error: undefined
- }
+ error: undefined,
+ };
}
-
const transactions = data.transactions.map((item: unknown) => {
- if (!item || typeof item !== "object" ||
+ if (
+ !item ||
+ typeof item !== "object" ||
!("direction" in item) ||
!("creditorIban" in item) ||
!("debtorIban" in item) ||
@@ -86,12 +91,12 @@ export function useComponentState({ accountLabel, pageNumber, balanceValue }: Pr
}
const anyItem = item as any;
if (
- !(typeof anyItem.creditorIban === 'string') ||
- !(typeof anyItem.debtorIban === 'string') ||
- !(typeof anyItem.date === 'string') ||
- !(typeof anyItem.subject === 'string') ||
- !(typeof anyItem.currency === 'string') ||
- !(typeof anyItem.amount === 'string')
+ !(typeof anyItem.creditorIban === "string") ||
+ !(typeof anyItem.debtorIban === "string") ||
+ !(typeof anyItem.date === "string") ||
+ !(typeof anyItem.subject === "string") ||
+ !(typeof anyItem.currency === "string") ||
+ !(typeof anyItem.amount === "string")
) {
return;
}
@@ -109,11 +114,11 @@ export function useComponentState({ accountLabel, pageNumber, balanceValue }: Pr
? `${dateParse[3]}/${dateParse[2]} ${dateParse[1]}`
: undefined;
- const date = parse(dateStr ?? "", "dd/MM yyyy", new Date())
+ const date = parse(dateStr ?? "", "dd/MM yyyy", new Date());
const when: AbsoluteTime = {
- t_ms: date.getTime()
- }
+ t_ms: date.getTime(),
+ };
const amount = Amounts.parse(`${anyItem.currency}:${anyItem.amount}`);
const subject = anyItem.subject;
return {
@@ -122,7 +127,7 @@ export function useComponentState({ accountLabel, pageNumber, balanceValue }: Pr
when,
amount,
subject,
- }
+ };
});
return {