Skip to content

Commit

Permalink
Added vendor to the AML block (#2590)
Browse files Browse the repository at this point in the history
* feat(*): added vendor to the aml block

* refactor(backoffice-v2): removed toTitleCase instance
  • Loading branch information
Omri-Levy committed Jul 31, 2024
1 parent 9a28dc1 commit fb89dce
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 14 deletions.
4 changes: 3 additions & 1 deletion apps/backoffice-v2/src/domains/workflows/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const BaseWorkflowByIdSchema = z.object({
workflowDefinition: WorkflowDefinitionByIdSchema,
createdAt: z.string().datetime(),
context: z.object({
aml: AmlSchema.optional(),
aml: AmlSchema.extend({
vendor: z.string().optional(),
}).optional(),
documents: z.array(z.any()).default([]),
entity: z.record(z.any(), z.any()),
parentMachine: ObjectWithIdSchema.extend({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toTitleCase } from 'string-ts';
import { titleCase } from 'string-ts';
import { ChevronDown } from 'lucide-react';
import React, { ComponentProps, useMemo } from 'react';
import { createColumnHelper } from '@tanstack/react-table';
Expand All @@ -12,7 +12,13 @@ import { Button } from '@/common/components/atoms/Button/Button';
import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed';
import { TextWithNAFallback } from '@/common/components/atoms/TextWithNAFallback/TextWithNAFallback';

export const useAmlBlock = (data: Array<TWorkflowById['context']['aml']>) => {
export const useAmlBlock = ({
data,
vendor,
}: {
data: Array<TWorkflowById['context']['aml']>;
vendor: string;
}) => {
const amlBlock = useMemo(() => {
if (!data?.length) {
return [];
Expand All @@ -37,6 +43,11 @@ export const useAmlBlock = (data: Array<TWorkflowById['context']['aml']>) => {
},
},
columns: [
{
id: 'screenedBy',
header: 'Screened by',
cell: () => <TextWithNAFallback>{titleCase(vendor ?? '')}</TextWithNAFallback>,
},
{
accessorKey: 'totalMatches',
header: 'Total Matches',
Expand Down Expand Up @@ -139,7 +150,7 @@ export const useAmlBlock = (data: Array<TWorkflowById['context']['aml']>) => {
cell: info => {
const matchTypes = info.getValue();

return <TextWithNAFallback>{toTitleCase(matchTypes)}</TextWithNAFallback>;
return <TextWithNAFallback>{titleCase(matchTypes)}</TextWithNAFallback>;
},
}),
columnHelper.accessor('pep', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StateTag, TStateTags, isObject } from '@ballerine/common';
import { isObject, StateTag, TStateTags } from '@ballerine/common';
import { ComponentProps, useCallback, useMemo } from 'react';

import { Separator } from '@/common/components/atoms/Separator/Separator';
Expand Down Expand Up @@ -109,9 +109,36 @@ export const useKycBlock = ({
childWorkflow?.context?.pluginsOutput?.kyc_session[key]?.result?.vendorResult?.aml ??
childWorkflow?.context?.pluginsOutput?.kyc_session[key]?.result?.aml,
);
}, [kycSessionKeys]);
}, [childWorkflow?.context?.pluginsOutput?.kyc_session, kycSessionKeys]);
const vendor = useMemo(() => {
if (!kycSessionKeys?.length) {
return;
}

const amlVendor = kycSessionKeys
.map(
key =>
childWorkflow?.context?.pluginsOutput?.kyc_session[key]?.result?.vendorResult?.aml
?.vendor ??
childWorkflow?.context?.pluginsOutput?.kyc_session[key]?.result?.aml?.vendor,
)
.filter(Boolean);

if (!amlVendor.length) {
const kycVendor = kycSessionKeys
.map(key => childWorkflow?.context?.pluginsOutput?.kyc_session[key]?.vendor)
.filter(Boolean);

const amlBlock = useAmlBlock(amlData);
return kycVendor.join(', ');
}

return amlVendor.join(', ');
}, [childWorkflow?.context?.pluginsOutput?.kyc_session, kycSessionKeys]);

const amlBlock = useAmlBlock({
data: amlData,
vendor: vendor ?? '',
});

const documentExtractedData = kycSessionKeys?.length
? kycSessionKeys?.map((key, index, collection) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ export const useDefaultBlocksLogic = () => {

const amlData = useMemo(() => [workflow?.context?.aml], [workflow?.context?.aml]);

const amlBlock = useAmlBlock(amlData);
const amlBlock = useAmlBlock({
data: amlData,
vendor: workflow?.context?.aml?.vendor ?? '',
});

const amlWithContainerBlock = useMemo(() => {
if (!amlBlock?.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const useOngoingBlocksLogic = () => {

const amlData = useMemo(() => [workflow?.context?.aml], [workflow?.context?.aml]);

const amlBlock = useAmlBlock(amlData);
const amlBlock = useAmlBlock({
data: amlData,
vendor: workflow?.context?.aml?.vendor ?? '',
});

const amlWithContainerBlock = useMemo(() => {
if (!amlBlock?.length) {
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ export class HookCallbackHandlerService {
}

if (processName === 'aml-unified-api') {
const aml = data.data as {
id: string;
endUserId: string;
hits: Array<Record<string, unknown>>;
const aml = {
...(data.data as {
id: string;
endUserId: string;
hits: Array<Record<string, unknown>>;
}),
vendor: data.vendor,
};

const attributePath = resultDestinationPath.split('.');
Expand Down

0 comments on commit fb89dce

Please sign in to comment.