diff options
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages/CaseDetails.tsx')
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/CaseDetails.tsx | 131 |
1 files changed, 55 insertions, 76 deletions
diff --git a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx index d02d8b395..ce820d612 100644 --- a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx +++ b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx @@ -13,64 +13,13 @@ import { FlexibleForm } from "../forms/index.js"; import { UIFormField } from "../handlers/forms.js"; import { Pages } from "../pages.js"; import { AmlExchangeBackend } from "../types.js"; +import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; +import { useOfficer } from "../hooks/useOfficer.js"; +import { buildQuerySignature } from "../account.js"; +import { useCaseDetails } from "../hooks/useCaseDetails.js"; +import { handleNotOkResult } from "../utils/errors.js"; -const response: AmlExchangeBackend.AmlDecisionDetails = { - aml_history: [ - { - justification: "Lack of documentation", - decider_pub: "ASDASDASD", - decision_time: { - t_s: Date.now() / 1000, - }, - new_state: 2, - new_threshold: "USD:0", - }, - { - justification: "Doing a transfer of high amount", - decider_pub: "ASDASDASD", - decision_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 6, - }, - new_state: 1, - new_threshold: "USD:2000", - }, - { - justification: "Account is known to the system", - decider_pub: "ASDASDASD", - decision_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 9, - }, - new_state: 0, - new_threshold: "USD:100", - }, - ], - kyc_attributes: [ - { - collection_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 8, - }, - expiration_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 4, - }, - provider_section: "asdasd", - attributes: { - name: "Sebastian", - }, - }, - { - collection_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 5, - }, - expiration_time: { - t_s: Date.now() / 1000 - 60 * 60 * 24 * 30 * 2, - }, - provider_section: "asdasd", - attributes: { - creditCard: "12312312312", - }, - }, - ], -}; type AmlEvent = AmlFormEvent | KycCollectionEvent | KycExpirationEvent; type AmlFormEvent = { type: "aml-form"; @@ -127,7 +76,7 @@ function getEventsFromAmlHistory( }); prev.push({ type: "kyc-expiration", - title: "expired" as TranslatedString, + title: "expiration" as TranslatedString, when: AbsoluteTime.fromProtocolTimestamp(k.expiration_time), fields: !k.attributes ? [] : Object.keys(k.attributes), }); @@ -136,19 +85,30 @@ function getEventsFromAmlHistory( return ae.concat(ke).sort(selectSooner); } -export function CaseDetails({ account }: { account?: string }) { - const events = getEventsFromAmlHistory( - response.aml_history, - response.kyc_attributes, - ); - console.log("DETAILS", events, events[events.length - 1 - 2]); - const [selected, setSelected] = useState<AmlEvent>( - events[events.length - 1 - 2], - ); +export function CaseDetails({ account: paytoHash }: { account: string }) { + const [selected, setSelected] = useState<AmlEvent | undefined>(undefined); + + const officer = useOfficer(); + const { i18n } = useTranslationContext(); + if (officer.state !== "ready") { + return <HandleAccountNotReady officer={officer} />; + } + const signature = + officer.state === "ready" + ? buildQuerySignature(officer.account.signingKey) + : undefined; + const details = useCaseDetails(officer.account.accountId, paytoHash, signature) + if (!details.ok && !details.loading) { + return handleNotOkResult(i18n)(details); + } + const aml_history = details.loading ? [] : details.data.aml_history + const kyc_attributes = details.loading ? [] : details.data.kyc_attributes + const events = getEventsFromAmlHistory(aml_history,kyc_attributes); + return ( <div> <a - href={Pages.newFormEntry.url({ account })} + href={Pages.newFormEntry.url({ account: paytoHash })} class="m-4 block rounded-md w-fit border-0 px-3 py-2 text-center text-sm bg-indigo-700 text-white shadow-sm hover:bg-indigo-700" > New AML form @@ -271,13 +231,24 @@ function ShowConsolidated({ history: AmlEvent[]; until: AmlEvent; }): VNode { - console.log("UNTIL", until); const cons = getConsolidated(history, until.when); const form: FlexibleForm<Consolidated> = { versionId: "1", behavior: (form) => { - return {}; + return { + aml: { + threshold: { + hidden: !form.aml + }, + since: { + hidden: !form.aml + }, + state: { + hidden: !form.aml + } + } + }; }, design: [ { @@ -356,8 +327,8 @@ function ShowConsolidated({ interface Consolidated { aml: { - state?: AmlExchangeBackend.AmlState; - threshold?: AmountJson; + state: AmlExchangeBackend.AmlState; + threshold: AmountJson; since: AbsoluteTime; }; kyc: { @@ -375,7 +346,13 @@ function getConsolidated( ): Consolidated { const initial: Consolidated = { aml: { - since: AbsoluteTime.never(), + state: AmlExchangeBackend.AmlState.normal, + threshold: { + currency: "ARS", + value: 1000, + fraction: 0, + }, + since: AbsoluteTime.never() }, kyc: {}, }; @@ -391,9 +368,11 @@ function getConsolidated( break; } case "aml-form": { - prev.aml.threshold = cur.threshold; - prev.aml.state = cur.state; - prev.aml.since = cur.when; + prev.aml = { + since: cur.when, + state: cur.state, + threshold: cur.threshold + } break; } case "kyc-collection": { |