Skip to content

Commit

Permalink
feat: IoC/Service Discovery (openwallet-foundation#1075)
Browse files Browse the repository at this point in the history
Signed-off-by: Clécio Varjão <[email protected]>
Signed-off-by: Mostafa Gamal <[email protected]>
Co-authored-by: Mostafa Gamal <[email protected]>
  • Loading branch information
cvarjao and MosCD3 authored Mar 6, 2024
1 parent e022b72 commit 6dc85ca
Show file tree
Hide file tree
Showing 28 changed files with 544 additions and 210 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
},
"resolutions": {
"typescript": "^5.0.4",
"tsyringe": "4.8.0",
"@typescript-eslint/parser": "^6.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@types/react": "^18.0.24",
Expand Down
25 changes: 25 additions & 0 deletions packages/legacy/app/container-imp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Container, TokenMapping } from '@hyperledger/aries-bifold-core'
import { DependencyContainer } from 'tsyringe'

export class AppContainer implements Container {
private container: DependencyContainer
public constructor(bifoldContainer: Container) {
this.container = bifoldContainer.getContainer().createChildContainer()
}
public init(): Container {
// eslint-disable-next-line no-console
console.log(`Initializing App container`)
// Here you can register any component to override components in core package
// Example: Replacing button in core with custom button
// this.container.registerInstance(TOKENS.COMP_BUTTON, Button)
return this
}

public resolve<K extends keyof TokenMapping>(token: K): TokenMapping[K] {
return this.container.resolve(token) as TokenMapping[K]
}

public getContainer(): DependencyContainer {
return this.container
}
}
11 changes: 8 additions & 3 deletions packages/legacy/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@ import '@formatjs/intl-relativetimeformat/locale-data/en' // locale-data for en
import '@formatjs/intl-datetimeformat/polyfill'
import '@formatjs/intl-datetimeformat/locale-data/en' // locale-data for en
import '@formatjs/intl-datetimeformat/add-all-tz' // Add ALL tz data
import 'reflect-metadata'

import { NavigationTheme } from '@hyperledger/aries-bifold-core'
import { NavigationTheme, App as BifoldApp, MainContainer } from '@hyperledger/aries-bifold-core'
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native'
import * as React from 'react'
import { AppRegistry, LogBox } from 'react-native'
//import { version as ReactNativeVersion } from 'react-native/Libraries/Core/ReactNativeVersion'
import { container } from 'tsyringe'

import App from './App'
//import App from './App'
import { name as appName } from './app.json'
import { AppContainer } from './container-imp'

const navigationTheme = {
...NavigationTheme,
}

LogBox.ignoreAllLogs()
// console.log(`React Native Version:${ReactNativeVersion.major}.${ReactNativeVersion.minor}.${ReactNativeVersion.patch}`)
const bifoldContainer = new MainContainer(container.createChildContainer()).init()
const App = BifoldApp(new AppContainer(bifoldContainer).init())

const Base = () => {
const navigationRef = useNavigationContainerRef()

Expand Down
34 changes: 18 additions & 16 deletions packages/legacy/app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,6 @@ PODS:
- React-jsinspector (0.72.5)
- React-logger (0.72.5):
- glog
- react-native-camera (3.44.3):
- React-Core
- react-native-camera/RCT (= 3.44.3)
- react-native-camera/RN (= 3.44.3)
- react-native-camera/RCT (3.44.3):
- React-Core
- react-native-camera/RN (3.44.3):
- React-Core
- react-native-config (1.5.0):
- react-native-config/App (= 1.5.0)
- react-native-config/App (1.5.0):
Expand All @@ -347,6 +339,8 @@ PODS:
- React-Core
- react-native-netinfo (9.3.7):
- React-Core
- react-native-orientation-locker (1.6.0):
- React-Core
- react-native-safe-area-context (3.4.1):
- React-Core
- react-native-splash-screen (3.3.0):
Expand Down Expand Up @@ -522,6 +516,10 @@ PODS:
- RNVectorIcons (10.0.0):
- React-Core
- SocketRocket (0.6.1)
- VisionCamera (3.6.16):
- React
- React-callinvoker
- React-Core
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -551,11 +549,11 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-camera (from `../node_modules/react-native-camera`)
- react-native-config (from `../node_modules/react-native-config`)
- react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-orientation-locker (from `../node_modules/react-native-orientation-locker`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-splash-screen (from `../node_modules/react-native-splash-screen`)
- react-native-tcp-socket (from `../node_modules/react-native-tcp-socket`)
Expand Down Expand Up @@ -590,6 +588,7 @@ DEPENDENCIES:
- RNScreens (from `../node_modules/react-native-screens`)
- RNSVG (from `../node_modules/react-native-svg`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- VisionCamera (from `../node_modules/react-native-vision-camera`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -650,8 +649,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-camera:
:path: "../node_modules/react-native-camera"
react-native-config:
:path: "../node_modules/react-native-config"
react-native-encrypted-storage:
Expand All @@ -660,6 +657,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-get-random-values"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-orientation-locker:
:path: "../node_modules/react-native-orientation-locker"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-splash-screen:
Expand Down Expand Up @@ -728,20 +727,22 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-svg"
RNVectorIcons:
:path: "../node_modules/react-native-vector-icons"
VisionCamera:
:path: "../node_modules/react-native-vision-camera"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
anoncreds: 8e6ab626d5250ae6301c3e96d6fc739186e083f0
aries-askar: 738c677e194913ed3c256adc953db3fe0494f8f8
boost: a7c83b31436843459a1961bfd74b96033dc77234
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CatCrypto: a477899b6be4954e75be4897e732da098cc0a5a8
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: 71803c074f6325f10b5ec891c443b6bbabef0ca7
FBReactNativeSpec: 448e08a759d29a96e15725ae532445bf4343567c
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 5337263514dd6f09803962437687240c5dc39aa4
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: f6cf92a471053245614d9d8097736f6337d5b86c
indy-vdr: 85cd66089f151256581323440e78988891f4082e
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Expand All @@ -760,11 +761,11 @@ SPEC CHECKSUMS:
React-jsiexecutor: ff70a72027dea5cc7d71cfcc6fad7f599f63987a
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-camera: b8cc03e2feec0c04403d0998e37cf519d8fd4c6f
react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-get-random-values: a6ea6a8a65dc93e96e24a11105b1a9c8cfe1d72a
react-native-netinfo: 2517ad504b3d303e90d7a431b0fcaef76d207983
react-native-orientation-locker: 4409c5b12b65f942e75449872b4f078b6f27af81
react-native-safe-area-context: 9e40fb181dac02619414ba1294d6c2a807056ab9
react-native-splash-screen: 4312f786b13a81b5169ef346d76d33bc0c6dc457
react-native-tcp-socket: e724380c910c2e704816ec817ed28f1342246ff7
Expand Down Expand Up @@ -800,8 +801,9 @@ SPEC CHECKSUMS:
RNSVG: d7d7bc8229af3842c9cfc3a723c815a52cdd1105
RNVectorIcons: 8b5bb0fa61d54cd2020af4f24a51841ce365c7e9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
VisionCamera: b236f548d6507923857dade542c7e0a148ed3492
Yoga: 86fed2e4d425ee4c6eab3813ba1791101ee153c6

PODFILE CHECKSUM: 91c24b25407631a4023c96a168470f60d473e28f

COCOAPODS: 1.11.2
COCOAPODS: 1.13.0
1 change: 1 addition & 0 deletions packages/legacy/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"react-native-vector-icons": "^10.0.0",
"react-native-vision-camera": "^3.6.16",
"react-native-webview": "^11.22.3",
"tsyringe": "^4.7.0",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
86 changes: 86 additions & 0 deletions packages/legacy/core/App/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import AgentProvider from '@aries-framework/react-hooks'
import * as React from 'react'
import { useEffect, useMemo } from 'react'
import { StatusBar } from 'react-native'
import SplashScreen from 'react-native-splash-screen'
import Toast from 'react-native-toast-message'

import { animatedComponents } from './animated-components'
import ErrorModal from './components/modals/ErrorModal'
import NetInfo from './components/network/NetInfo'
import toastConfig from './components/toast/ToastConfig'
import { credentialOfferTourSteps } from './components/tour/CredentialOfferTourSteps'
import { credentialsTourSteps } from './components/tour/CredentialsTourSteps'
import { homeTourSteps } from './components/tour/HomeTourSteps'
import { proofRequestTourSteps } from './components/tour/ProofRequestTourSteps'
import { Container, ContainerProvider } from './container-api'
import { AnimatedComponentsProvider } from './contexts/animated-components'
import { AuthProvider } from './contexts/auth'
import { CommonUtilProvider } from './contexts/commons'
import { ConfigurationProvider } from './contexts/configuration'
import { NetworkProvider } from './contexts/network'
import { StoreProvider } from './contexts/store'
import { ThemeProvider } from './contexts/theme'
import { TourProvider } from './contexts/tour/tour-provider'
import { defaultConfiguration } from './defaultConfiguration'
import { initLanguages, initStoredLanguage, translationResources } from './localization'
import RootStack from './navigators/RootStack'
import { theme } from './theme'
//import { credentialOfferTourSteps, credentialsTourSteps, proofRequestTourSteps } from './index'

initLanguages(translationResources)

function App(sytem: Container) {
return () => {
useMemo(() => {
initStoredLanguage().then()
}, [])

useEffect(() => {
// Hide the native splash / loading screen so that our
// RN version can be displayed.
SplashScreen.hide()
}, [])

return (
<ContainerProvider value={sytem}>
<StoreProvider>
<AgentProvider>
<ThemeProvider value={theme}>
<AnimatedComponentsProvider value={animatedComponents}>
<ConfigurationProvider value={defaultConfiguration}>
<CommonUtilProvider>
<AuthProvider>
<NetworkProvider>
<StatusBar
hidden={false}
barStyle="light-content"
backgroundColor={theme.ColorPallet.brand.primary}
translucent={false}
/>
<NetInfo />
<ErrorModal />
<TourProvider
homeTourSteps={homeTourSteps}
credentialsTourSteps={credentialsTourSteps}
credentialOfferTourSteps={credentialOfferTourSteps}
proofRequestTourSteps={proofRequestTourSteps}
overlayColor={'gray'}
overlayOpacity={0.7}
>
<RootStack />
</TourProvider>
<Toast topOffset={15} config={toastConfig} />
</NetworkProvider>
</AuthProvider>
</CommonUtilProvider>
</ConfigurationProvider>
</AnimatedComponentsProvider>
</ThemeProvider>
</AgentProvider>
</StoreProvider>
</ContainerProvider>
)
}
}
export default App
42 changes: 42 additions & 0 deletions packages/legacy/core/App/components/buttons/Button-api.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { TouchableOpacity } from 'react-native'

export enum ButtonType {
Critical,
Primary,
Secondary,
ModalCritical,
ModalPrimary,
ModalSecondary,
}

export interface ButtonProps extends React.PropsWithChildren {
title: string
buttonType: ButtonType
accessibilityLabel?: string
testID?: string
onPress?: () => void
disabled?: boolean
}

export enum ButtonState {
Default = 'default',
Disabled = 'disabled',
Active = 'active',
}

export enum ButtonStyleNames {
Critical_Default = 'Critical' + '_' + ButtonState.Default,
Critical_Disabled = 'Critical' + '_' + ButtonState.Disabled,
Critical_Active = 'Critical' + '_' + ButtonState.Active,
}
/*
type stylesType = { readonly [key in ButtonStyleNames]?: ViewStyle | TextStyle | ImageStyle}
const styles: stylesType = StyleSheet.create({
[ButtonStyleNames.Critical_Default]: {},
[ButtonType.Secondary]: {},
[ButtonType.ModalCritical]: {},
[ButtonType.ModalPrimary]: {},
[ButtonType.ModalSecondary]: {},
})
*/
export type Button = React.FC<ButtonProps & React.RefAttributes<TouchableOpacity>>
25 changes: 5 additions & 20 deletions packages/legacy/core/App/components/buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,9 @@ import { Text, TouchableOpacity, View } from 'react-native'

import { useTheme } from '../../contexts/theme'

export enum ButtonType {
Critical,
Primary,
Secondary,
ModalCritical,
ModalPrimary,
ModalSecondary,
}
import { Button, ButtonType, ButtonProps } from './Button-api'

export interface ButtonProps extends React.PropsWithChildren {
title: string
buttonType: ButtonType
accessibilityLabel?: string
testID?: string
onPress?: () => void
disabled?: boolean
}

const Button: React.FC<ButtonProps & React.RefAttributes<TouchableOpacity>> = forwardRef(
const ButtonImpl: Button = forwardRef(
(
{ title, buttonType, accessibilityLabel, testID, onPress, disabled = false, children },
ref: React.LegacyRef<TouchableOpacity>
Expand Down Expand Up @@ -80,5 +64,6 @@ const Button: React.FC<ButtonProps & React.RefAttributes<TouchableOpacity>> = fo
)
}
)

export default Button
export default ButtonImpl
export { ButtonType, ButtonImpl }
export type { Button, ButtonProps }
Loading

0 comments on commit 6dc85ca

Please sign in to comment.