-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan <[email protected]>
- Loading branch information
Showing
9 changed files
with
205 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 75 additions & 18 deletions
93
apps/easypid/src/features/share/components/RequestPurposeSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,87 @@ | ||
import { Circle, Heading, HeroIcons, Image, MessageBox, Stack, YStack } from '@package/ui' | ||
import type { VerificationAnalysisResult } from '@easypid/use-cases/ValidateVerification' | ||
import { | ||
AnimatedStack, | ||
Circle, | ||
Heading, | ||
HeroIcons, | ||
Image, | ||
InfoSheet, | ||
MessageBox, | ||
Stack, | ||
XStack, | ||
YStack, | ||
useScaleAnimation, | ||
} from '@package/ui' | ||
import type { DisplayImage } from 'packages/agent/src' | ||
import { useState } from 'react' | ||
import { ZoomIn } from 'react-native-reanimated' | ||
import { VerificationAnalysisIcon } from './VerificationAnalysisIcon' | ||
|
||
interface RequestPurposeSectionProps { | ||
purpose: string | ||
logo?: DisplayImage | ||
verificationAnalysis?: VerificationAnalysisResult | ||
} | ||
|
||
export function RequestPurposeSection({ purpose, logo }: RequestPurposeSectionProps) { | ||
export function RequestPurposeSection({ purpose, logo, verificationAnalysis }: RequestPurposeSectionProps) { | ||
const [isAnalysisModalOpen, setIsAnalysisModalOpen] = useState(false) | ||
|
||
const { handlePressIn, handlePressOut, pressStyle } = useScaleAnimation() | ||
|
||
const toggleAnalysisModal = () => setIsAnalysisModalOpen(!isAnalysisModalOpen) | ||
|
||
return ( | ||
<YStack gap="$2"> | ||
<Heading variant="sub2">PURPOSE</Heading> | ||
<MessageBox | ||
variant="light" | ||
message={purpose} | ||
icon={ | ||
<Circle size="$4" overflow="hidden"> | ||
{logo?.url ? ( | ||
<Image circle src={logo.url} alt={logo.altText} width="100%" height="100%" resizeMode="contain" /> | ||
) : ( | ||
<Stack bg="$grey-200" width="100%" height="100%" ai="center" jc="center"> | ||
<HeroIcons.BuildingOffice color="$grey-800" size={24} /> | ||
</Stack> | ||
<> | ||
<YStack gap="$2"> | ||
{verificationAnalysis?.result?.validRequest === 'no' && ( | ||
<AnimatedStack | ||
style={pressStyle} | ||
onPressIn={handlePressIn} | ||
onPressOut={handlePressOut} | ||
onPress={toggleAnalysisModal} | ||
mb="$4" | ||
> | ||
<MessageBox | ||
icon={<HeroIcons.InformationCircleFilled />} | ||
variant="error" | ||
message="The purpose given does not match the data requested." | ||
/> | ||
</AnimatedStack> | ||
)} | ||
<XStack gap="$2" jc="space-between" ai="center"> | ||
<Heading variant="sub2">PURPOSE</Heading> | ||
<Stack h="$2" w="$2" ai="center" jc="center"> | ||
{verificationAnalysis && ( | ||
<AnimatedStack key={verificationAnalysis.result?.validRequest} entering={ZoomIn}> | ||
<VerificationAnalysisIcon verificationAnalysis={verificationAnalysis} /> | ||
</AnimatedStack> | ||
)} | ||
</Circle> | ||
} | ||
</Stack> | ||
</XStack> | ||
<MessageBox | ||
variant="light" | ||
message={purpose} | ||
icon={ | ||
<Circle size="$4" overflow="hidden"> | ||
{logo?.url ? ( | ||
<Image circle src={logo.url} alt={logo.altText} width="100%" height="100%" resizeMode="contain" /> | ||
) : ( | ||
<Stack bg="$grey-200" width="100%" height="100%" ai="center" jc="center"> | ||
<HeroIcons.BuildingOffice color="$grey-800" size={24} /> | ||
</Stack> | ||
)} | ||
</Circle> | ||
} | ||
/> | ||
</YStack> | ||
<InfoSheet | ||
variant="danger" | ||
isOpen={isAnalysisModalOpen} | ||
setIsOpen={setIsAnalysisModalOpen} | ||
title="Overasking detected" | ||
description="This organization seems to be asking for different or more data than their purpose suggests. Read the request carefully. You can deny the request if you do not agree with the data asked." | ||
onClose={toggleAnalysisModal} | ||
/> | ||
</YStack> | ||
</> | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/easypid/src/features/share/components/VerificationAnalysisIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { VerificationAnalysisResult } from '@easypid/use-cases/ValidateVerification' | ||
import { HeroIcons, Spinner } from 'packages/ui/src' | ||
|
||
interface VerificationAnalysisIconProps { | ||
verificationAnalysis: VerificationAnalysisResult | ||
} | ||
|
||
export function VerificationAnalysisIcon({ verificationAnalysis }: VerificationAnalysisIconProps) { | ||
if (!verificationAnalysis.result || verificationAnalysis.isLoading) return <Spinner scale={0.8} /> | ||
|
||
if (verificationAnalysis.result.validRequest === 'could_not_determine') { | ||
// AI doesn't know or an error was thrown | ||
return null | ||
} | ||
|
||
if (verificationAnalysis.result.validRequest === 'yes') { | ||
return <HeroIcons.CheckCircleFilled size={26} color="$positive-500" /> | ||
} | ||
|
||
return <HeroIcons.ExclamationTriangleFilled size={26} color="$danger-500" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const PLAYGROUND_URL = 'https://funke.animo.id' | ||
|
||
export type VerificationAnalysisInput = { | ||
verifier: { | ||
name: string | ||
domain: string | ||
} | ||
name: string | ||
purpose: string | ||
cards: Array<{ | ||
name: string | ||
subtitle: string | ||
requestedAttributes: Array<string> | ||
}> | ||
} | ||
|
||
export type VerificationAnalysisResponse = { | ||
validRequest: 'yes' | 'no' | 'could_not_determine' | ||
reason: string | ||
} | ||
|
||
export type VerificationAnalysisResult = { | ||
isLoading: boolean | ||
result: VerificationAnalysisResponse | undefined | ||
} | ||
|
||
export const analyzeVerification = async ({ | ||
verifier, | ||
name, | ||
purpose, | ||
cards, | ||
}: VerificationAnalysisInput): Promise<VerificationAnalysisResponse> => { | ||
try { | ||
const response = await fetch(`${PLAYGROUND_URL}/api/validate-verification-request`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ verifier, name, purpose, cards }), | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Request to AI returned ${response.status}`) | ||
} | ||
|
||
return await response.json() | ||
} catch (error) { | ||
console.error('AI analysis failed:', error) | ||
return { | ||
validRequest: 'could_not_determine', | ||
reason: 'An error occurred while validating the verification', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters