aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/hooks
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-11-20 12:38:16 -0300
committerSebastian <sebasjm@gmail.com>2023-11-20 12:38:16 -0300
commit6138846050563e0dca95b0b6d792776925e4c35f (patch)
treeb33cd36acf4b38d3a016506d4f7fa681c83beb63 /packages/aml-backoffice-ui/src/hooks
parent7ed3e78f790837479fc2bb2eb6ddc40c78ce59b5 (diff)
new forms api
Diffstat (limited to 'packages/aml-backoffice-ui/src/hooks')
-rw-r--r--packages/aml-backoffice-ui/src/hooks/useCases.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/aml-backoffice-ui/src/hooks/useCases.ts b/packages/aml-backoffice-ui/src/hooks/useCases.ts
index c4edd9207..81ca2755a 100644
--- a/packages/aml-backoffice-ui/src/hooks/useCases.ts
+++ b/packages/aml-backoffice-ui/src/hooks/useCases.ts
@@ -12,7 +12,6 @@ import { useOfficer } from "./useOfficer.js";
const useSWR = _useSWR as unknown as SWRHook;
const PAGE_SIZE = 10;
-const MAX_RESULT_SIZE = PAGE_SIZE * 2 - 1;
/**
* FIXME: mutate result when balance change (transaction )
* @param account
@@ -24,11 +23,11 @@ export function useCases(state: AmlExchangeBackend.AmlState) {
const session = officer.state === "ready" ? officer.account : undefined;
const { api } = useExchangeApiContext();
- const [offset, setOffet] = useState<string>();
+ const [offset, setOffset] = useState<string>();
async function fetcher([officer, state, offset]: [OfficerAccount, AmlExchangeBackend.AmlState, string | undefined]) {
return await api.getDecisionsByState(officer, state, {
- order: "asc", offset, limit: MAX_RESULT_SIZE
+ order: "asc", offset, limit: PAGE_SIZE + 1
})
}
@@ -51,7 +50,7 @@ export function useCases(state: AmlExchangeBackend.AmlState) {
// if the query returns less that we ask, then we have reach the end or beginning
const isLastPage =
- data && data.type === "ok" && data.body.records.length < PAGE_SIZE;
+ data && data.type === "ok" && data.body.records.length <= PAGE_SIZE;
const isFirstPage = !offset;
const pagination = {
@@ -60,12 +59,10 @@ export function useCases(state: AmlExchangeBackend.AmlState) {
loadMore: () => {
if (isLastPage || data?.type !== "ok") return;
const list = data.body.records
- if (list.length < MAX_RESULT_SIZE) {
- // setOffset(list[list.length-1].account_name);
- }
+ setOffset(String(list[list.length - 1].rowid));
},
- loadMorePrev: () => {
- null;
+ reset: () => {
+ setOffset(undefined)
},
};
@@ -79,11 +76,13 @@ export function useCases(state: AmlExchangeBackend.AmlState) {
} as OperationFail<never>
}
}
+
if (data) {
if (data.type === "fail") {
return { data }
}
- return { data, pagination }
+ const records = isLastPage ? data.body.records : removeLastElement(data.body.records)
+ return { data: { type: "ok" as const, body: { records } }, pagination }
}
if (error) {
return error;
@@ -137,3 +136,9 @@ const example1: TalerExchangeApi.AmlRecords = {
};
+function removeLastElement<T>(list: Array<T>): Array<T> {
+ if (list.length === 0) {
+ return list;
+ }
+ return list.slice(0, -1)
+} \ No newline at end of file