Skip to content

Commit

Permalink
feat: flag
Browse files Browse the repository at this point in the history
  • Loading branch information
janrtvld committed Jan 13, 2025
1 parent 7cb3c4d commit 0ea5783
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 21 deletions.
7 changes: 2 additions & 5 deletions apps/easypid/src/app/authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { TypedArrayEncoder, WalletInvalidKeyError } from '@credo-ts/core'
import { initializeAppAgent, useSecureUnlock } from '@easypid/agent'
import { useBiometricsType } from '@easypid/hooks/useBiometricsType'
import { secureWalletKey } from '@package/secure-store/secureUnlock'
import { FlexPage, Heading, HeroIcons, YStack, useToastController } from '@package/ui'
import { FlexPage, Heading, HeroIcons, IconContainer, YStack, useToastController } from '@package/ui'
import * as SplashScreen from 'expo-splash-screen'
import { PinDotsInput, type PinDotsInputRef } from 'packages/app/src'
import { useEffect, useRef, useState } from 'react'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { Circle } from 'tamagui'
import { useResetWalletDevMenu } from '../utils/resetWallet'

/**
Expand Down Expand Up @@ -108,9 +107,7 @@ export default function Authenticate() {
<FlexPage flex-1 safeArea="y" alignItems="center">
<YStack fg={1} gap="$6" mb={shouldStickToBottom ? -16 : undefined}>
<YStack flex-1 alignItems="center" justifyContent="flex-end" gap="$4">
<Circle size="$4" backgroundColor="$grey-100">
<HeroIcons.LockClosed strokeWidth={2} color="$grey-700" />
</Circle>
<IconContainer h="$4" w="$4" ai="center" jc="center" icon={<HeroIcons.LockClosedFilled />} />
<Heading variant="h2" fontWeight="$semiBold">
Enter your app PIN code
</Heading>
Expand Down
36 changes: 36 additions & 0 deletions apps/easypid/src/config/appType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { APP_CONFIGS } from './features'

export const appTypes = ['FUNKE_WALLET', 'PARADYM_WALLET'] as const
export type AppType = (typeof appTypes)[number]

const getAppType = (): AppType => {
let appType = process.env.EXPO_PUBLIC_APP_TYPE as AppType

if (!appType) {
console.warn('⚠️ EXPO_PUBLIC_APP_TYPE not set, falling back to PARADYM_WALLET')
appType = 'PARADYM_WALLET'
}

if (!appTypes.includes(appType)) {
console.warn(`⚠️ EXPO_PUBLIC_APP_TYPE is not a valid app type: ${appType}. Falling back to PARADYM_WALLET.`)
appType = 'PARADYM_WALLET'
}

const features = APP_CONFIGS[appType]
const sortedFeatures = Object.entries(features).sort(([, a], [, b]) => (b ? 1 : 0) - (a ? 1 : 0))

console.log(`
🔧 App Configuration
━━━━━━━━━━━━━━━━━━━━
📱 App Type: ${appType}
⚙️ Features:${sortedFeatures
.map(
([key, value]) => `
- ${key}: ${value ? '✅' : '❌'}`
)
.join('')}`)

return appType as AppType
}

export const CURRENT_APP_TYPE = getAppType()
21 changes: 11 additions & 10 deletions apps/easypid/src/config/features.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export const FEATURES = {
EID_CARD_FEATURE: 'eid_card_feature',
AI_ANALYSIS_FEATURE: 'ai_analysis_feature',
}
import type { AppType } from './appType'

export const APP_CONFIGS = {
FUNKE_WALLET: {
[FEATURES.EID_CARD_FEATURE]: true,
[FEATURES.AI_ANALYSIS_FEATURE]: true,
EID_CARD: true,
AI_ANALYSIS: true,
},
PARADYM_WALLET: {
[FEATURES.EID_CARD_FEATURE]: false,
[FEATURES.AI_ANALYSIS_FEATURE]: false,
EID_CARD: false,
AI_ANALYSIS: false,
},
} satisfies Record<AppType, Record<FeatureKey, boolean>>

export const FEATURES = {
EID_CARD: 'eid_card',
AI_ANALYSIS: 'ai_analysis',
}

export type AppType = keyof typeof APP_CONFIGS
export type FeatureKey = keyof (typeof APP_CONFIGS)[AppType]
export type FeatureKey = keyof typeof FEATURES
2 changes: 1 addition & 1 deletion apps/easypid/src/features/menu/FunkeMenuScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const MenuItem = ({ item, idx, onPress }: { item: (typeof menuItems)[number]; id
<Stack
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onPress={withHaptics(() => Linking.openURL('mailto:[email protected]?subject=Feedback on the Funke EUDI Wallet'))}
onPress={withHaptics(() => Linking.openURL('mailto:[email protected]?subject=Feedback on the Wallet'))}
asChild
>
{content}
Expand Down
4 changes: 3 additions & 1 deletion apps/easypid/src/features/menu/FunkeSettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import React from 'react'
import { TextBackButton } from 'packages/app/src'
import { LocalAiContainer } from './components/LocalAiContainer'

import { useFeatureFlag } from '@easypid/hooks/useFeatureFlag'
import { useScrollViewPosition } from '@package/app/src/hooks'
import { useDevelopmentMode } from '../../hooks/useDevelopmentMode'

export function FunkeSettingsScreen() {
const { handleScroll, isScrolledByOffset, scrollEventThrottle } = useScrollViewPosition()
const [isDevelopmentModeEnabled, setIsDevelopmentModeEnabled] = useDevelopmentMode()
const isOverAskingAiEnabled = useFeatureFlag('AI_ANALYSIS')

return (
<FlexPage gap="$0" paddingHorizontal="$0">
Expand All @@ -28,7 +30,7 @@ export function FunkeSettingsScreen() {
value={isDevelopmentModeEnabled ?? false}
onChange={setIsDevelopmentModeEnabled}
/>
<LocalAiContainer />
{isOverAskingAiEnabled && <LocalAiContainer />}
</YStack>
<YStack btw="$0.5" borderColor="$grey-200" pt="$4" mx="$-4" px="$4" bg="$background">
<TextBackButton />
Expand Down
7 changes: 3 additions & 4 deletions apps/easypid/src/hooks/useFeatureFlag.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CURRENT_APP_TYPE } from '../config/appType'
import { APP_CONFIGS } from '../config/features'
import type { AppType, FeatureKey } from '../config/features'

const APP_TYPE = (process.env.EXPO_PUBLIC_APP_TYPE || 'PARADYM_WALLET') as AppType
import type { FeatureKey } from '../config/features'

export const useFeatureFlag = (featureKey: FeatureKey) => {
return APP_CONFIGS[APP_TYPE]?.[featureKey] ?? false
return APP_CONFIGS[CURRENT_APP_TYPE]?.[featureKey] ?? false
}
7 changes: 7 additions & 0 deletions apps/easypid/src/hooks/useOverAskingAi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'
import { useLLM } from '@easypid/llm'
import type { OverAskingInput, OverAskingResponse } from '@easypid/use-cases/OverAskingApi'
import { EXCLUDED_ATTRIBUTES_FOR_ANALYSIS, checkForOverAskingApi } from '@easypid/use-cases/OverAskingApi'
import { useFeatureFlag } from './useFeatureFlag'

const fallbackResponse: OverAskingResponse = {
validRequest: 'could_not_determine',
Expand All @@ -14,6 +15,7 @@ export function useOverAskingAi() {
const [overAskingResponse, setOverAskingResponse] = useState<OverAskingResponse>()

const { generate, response, error, isModelReady, isModelGenerating, interrupt } = useLLM()
const isOverAskingAiEnabled = useFeatureFlag('AI_ANALYSIS')

useEffect(() => {
if (error) {
Expand All @@ -35,6 +37,11 @@ export function useOverAskingAi() {
}, [response, isModelGenerating, error])

const checkForOverAsking = async (input: OverAskingInput) => {
if (!isOverAskingAiEnabled) {
console.debug('Over-asking AI feature flag is not enabled, skipping')
return
}

setIsProcessingOverAsking(true)
if (isModelReady) {
console.debug('Local LLM ready, using local LLM')
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/content/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
HandRaisedIcon as HandRaisedFilledIcon,
IdentificationIcon as IdentificationFilledIcon,
InformationCircleIcon as InformationCircleFilledIcon,
LockClosedIcon as LockClosedFilledIcon,
QueueListIcon as QueueListFilledIcon,
ShieldCheckIcon as ShieldCheckFilledIcon,
TrashIcon as TrashFilledIcon,
Expand Down Expand Up @@ -180,6 +181,7 @@ export const HeroIcons = {
Cloud: wrapHeroIcon(CloudIcon),
CpuChipFilled: wrapHeroIcon(CpuChipFilledIcon),
CommandLineFilled: wrapHeroIcon(CommandLineIcon),
LockClosedFilled: wrapHeroIcon(LockClosedFilledIcon),
} as const

export const CustomIcons = {
Expand Down

0 comments on commit 0ea5783

Please sign in to comment.