Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: paradym wallet merge #262

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions apps/easypid/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
EXPO_PUBLIC_WALLET_SERVICE_PROVIDER_URL=
EXPO_PUBLIC_APP_TYPE=PARADYM_WALLET # or FUNKE_WALLET
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]
janrtvld marked this conversation as resolved.
Show resolved Hide resolved

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()
19 changes: 19 additions & 0 deletions apps/easypid/src/config/features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { AppType } from './appType'

export const APP_CONFIGS = {
FUNKE_WALLET: {
EID_CARD: true,
AI_ANALYSIS: true,
},
PARADYM_WALLET: {
EID_CARD: false,
AI_ANALYSIS: false,
},
} satisfies Record<AppType, Record<FeatureKey, boolean>>

export const FEATURES = {
EID_CARD: 'eid_card',
AI_ANALYSIS: 'ai_analysis',
}
janrtvld marked this conversation as resolved.
Show resolved Hide resolved

export type FeatureKey = keyof typeof FEATURES
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 @@ -35,7 +37,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: 7 additions & 0 deletions apps/easypid/src/hooks/useFeatureFlag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CURRENT_APP_TYPE } from '../config/appType'
import { APP_CONFIGS } from '../config/features'
import type { FeatureKey } from '../config/features'

export const useFeatureFlag = (featureKey: FeatureKey) => {
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