Skip to content

Commit

Permalink
refactor: proof templates to DI (#2039)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason C. Leach <[email protected]>
  • Loading branch information
jleach authored Jul 3, 2024
1 parent d5c07fc commit bdf92cb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 51 deletions.
4 changes: 3 additions & 1 deletion app/.bundle/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
BUNDLE_FORCE_RUBY_PLATFORM: "1"
BUNDLE_FROZEN: "true"
41 changes: 24 additions & 17 deletions app/container-imp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@ import Developer from './src/screens/Developer'
import Preface from './src/screens/Preface'
import Terms, { TermsVersion } from './src/screens/Terms'
import { BCLocalStorageKeys, BCState, DismissPersonCredentialOffer, IASEnvironment, initialState } from './src/store'
import { useProofRequestTemplates } from '@hyperledger/aries-bifold-verifier'
import { BaseLogger } from '@credo-ts/core'

export class AppContainer implements Container {
private container: DependencyContainer
public constructor(bifoldContainer: Container) {
this.container = bifoldContainer.getContainer().createChildContainer()
private _container: DependencyContainer
private log?: BaseLogger

public constructor(bifoldContainer: Container, log?: BaseLogger) {
this._container = bifoldContainer.container.createChildContainer()
this.log = log
}

public get container(): DependencyContainer {
return this._container
}

public init(): Container {
// eslint-disable-next-line no-console
console.log(`Initializing BC Wallet App container`)
this.log?.info(`Initializing BC Wallet 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.SCREEN_PREFACE, Preface)
this.container.registerInstance(TOKENS.CRED_HELP_ACTION_OVERRIDES, [
this._container.registerInstance(TOKENS.SCREEN_PREFACE, Preface)
this._container.registerInstance(TOKENS.CRED_HELP_ACTION_OVERRIDES, [
{
credDefIds: [
'RGjWbW1eycP7FrMf4QJvX8:3:CL:13:Person',
Expand All @@ -65,15 +75,16 @@ export class AppContainer implements Container {
},
},
])
this.container.registerInstance(TOKENS.SCREEN_TERMS, { screen: Terms, version: TermsVersion })
this.container.registerInstance(TOKENS.SCREEN_DEVELOPER, Developer)
this._container.registerInstance(TOKENS.SCREEN_TERMS, { screen: Terms, version: TermsVersion })
this._container.registerInstance(TOKENS.SCREEN_DEVELOPER, Developer)

const resolver = new RemoteOCABundleResolver(Config.OCA_URL ?? '', {
brandingOverlayType: BrandingOverlayType.Branding10,
})
this._container.registerInstance(TOKENS.UTIL_OCA_RESOLVER, resolver)

this.container.registerInstance(TOKENS.UTIL_OCA_RESOLVER, resolver)
this.container.registerInstance(TOKENS.LOAD_STATE, async (dispatch: React.Dispatch<ReducerAction<unknown>>) => {
this._container.registerInstance(TOKENS.UTIL_PROOF_TEMPLATE, useProofRequestTemplates)
this._container.registerInstance(TOKENS.LOAD_STATE, async (dispatch: React.Dispatch<ReducerAction<unknown>>) => {
const loadState = async <Type>(key: LocalStorageKeys | BCLocalStorageKeys, updateVal: (val: Type) => void) => {
const data = await AsyncStorage.getItem(key)
if (data) {
Expand Down Expand Up @@ -134,16 +145,12 @@ export class AppContainer implements Container {
}
const logger = new RemoteLogger(logOptions)
logger.startEventListeners()
this.container.registerInstance(TOKENS.UTIL_LOGGER, logger)
this._container.registerInstance(TOKENS.UTIL_LOGGER, logger)

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
return this._container.resolve(token) as TokenMapping[K]
}
}
4 changes: 2 additions & 2 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ PODS:
- React-jsinspector (0.72.5)
- React-logger (0.72.5):
- glog
- "react-native-attestation (1.0.0-alpha.259+2cda573d)":
- "react-native-attestation (1.0.0-alpha.261+0fba0883)":
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-config (1.5.0):
Expand Down Expand Up @@ -931,7 +931,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: ff70a72027dea5cc7d71cfcc6fad7f599f63987a
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-attestation: 7f043cf4a959e259492dcca3d9a6cc6b83517d53
react-native-attestation: e26b2c99b3b3a5ae38c3828378c78dca4f07cac7
react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-get-random-values: a6ea6a8a65dc93e96e24a11105b1a9c8cfe1d72a
Expand Down
12 changes: 6 additions & 6 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
"@formatjs/intl-relativetimeformat": "9.3.1",
"@hyperledger/anoncreds-react-native": "0.2.2",
"@hyperledger/aries-askar-react-native": "0.2.1",
"@hyperledger/aries-bifold-core": "1.0.0-alpha.259",
"@hyperledger/aries-bifold-remote-logs": "1.0.0-alpha.259",
"@hyperledger/aries-bifold-verifier": "1.0.0-alpha.259",
"@hyperledger/aries-oca": "1.0.0-alpha.259",
"@hyperledger/aries-react-native-attestation": "1.0.0-alpha.259",
"@hyperledger/aries-bifold-core": "1.0.0-alpha.261",
"@hyperledger/aries-bifold-remote-logs": "1.0.0-alpha.261",
"@hyperledger/aries-bifold-verifier": "1.0.0-alpha.261",
"@hyperledger/aries-oca": "1.0.0-alpha.261",
"@hyperledger/aries-react-native-attestation": "1.0.0-alpha.261",
"@hyperledger/indy-vdr-react-native": "0.2.2",
"@react-native-async-storage/async-storage": "1.15.11",
"@react-native-community/masked-view": "0.1.11",
Expand Down Expand Up @@ -171,4 +171,4 @@
"react-test-renderer": "18.2.0",
"typescript": "5.2.2"
}
}
}
50 changes: 25 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4321,9 +4321,9 @@ __metadata:
languageName: node
linkType: hard

"@hyperledger/aries-bifold-core@npm:1.0.0-alpha.259":
version: 1.0.0-alpha.259
resolution: "@hyperledger/aries-bifold-core@npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-core@npm:1.0.0-alpha.261":
version: 1.0.0-alpha.261
resolution: "@hyperledger/aries-bifold-core@npm:1.0.0-alpha.261"
peerDependencies:
"@credo-ts/anoncreds": 0.5.3
"@credo-ts/askar": 0.5.3
Expand Down Expand Up @@ -4397,57 +4397,57 @@ __metadata:
uuid: ^9.0.0
bin:
bifold: bin/bifold
checksum: 6b687f480577f5826dce84f43116c226db7210c2d649363b0412b552354952b41e039d4fb5be87e7b8babf46b7393f1ef2d8a3007313733402980ab3d769a2ee
checksum: 02cb5ec8e28769aac9c64ded6576a0dfe7c8017e1bc2517a160ac2bf96831ba079d7bf49b42c37b7081992dc6841971b25b92589f297bb15069c88c5a2685ef9
languageName: node
linkType: hard

"@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.259":
version: 1.0.0-alpha.259
resolution: "@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.261":
version: 1.0.0-alpha.261
resolution: "@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.261"
peerDependencies:
"@credo-ts/core": 0.5.3
axios: ^1.4.0
buffer: ^6.0.3
react: ^18.2.0
react-native: ^0.72.5
react-native-logs: ^5.1.0
checksum: 66efc06ecae1875ebdaac99aa2c278d72d1801835cb42a9f844455d81108772ed3806109eaf0b65ebb4a6f15d16a1a88d8f00a8a265d14f2a0d843926383837c
checksum: 6f03210915aa111ef5a94b23800566771d2184780c983bf5f09bdc6bbea70c35ff229b5194d28f0cbd5905311572ab2bced5adfd934167fb14a5c6367c25714e
languageName: node
linkType: hard

"@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.259":
version: 1.0.0-alpha.259
resolution: "@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.261":
version: 1.0.0-alpha.261
resolution: "@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.261"
peerDependencies:
"@credo-ts/anoncreds": 0.5.3
"@credo-ts/core": 0.5.3
"@credo-ts/react-hooks": ^0.6.0
"@hyperledger/anoncreds-shared": 0.2.2
react: ^18.2.0
checksum: 00209e4584fe7c83b205eac312c8b2f2c5a2edd612b2b560992fba78e946d3070eb395c553266d41b1ebf130c0b3c2c093648eb418f70b0db5efc9833081adb7
checksum: 1245e7f80fce3128295002f95dd67320ad4f9648a7ffba93e194e730ff4d388d3db783cd4ea3ce711e7e92aa6159a18c4e94d02c4a40bf0db2c60b6bc98c126b
languageName: node
linkType: hard

"@hyperledger/aries-oca@npm:1.0.0-alpha.259":
version: 1.0.0-alpha.259
resolution: "@hyperledger/aries-oca@npm:1.0.0-alpha.259"
"@hyperledger/aries-oca@npm:1.0.0-alpha.261":
version: 1.0.0-alpha.261
resolution: "@hyperledger/aries-oca@npm:1.0.0-alpha.261"
dependencies:
"@credo-ts/anoncreds": "npm:0.5.3"
"@credo-ts/core": "npm:0.5.3"
axios: "npm:^1.4.0"
lodash.startcase: "npm:^4.4.0"
react-native-fs: "npm:^2.16.6"
checksum: eff4273b40dbddedda71d0b839e99d7553046d99e9d4e5bfdad2b7286b46464ad2026a6a0ea36a3fe9f10cdcd77175d0297c2993d65fba64c35fece760c79644
checksum: 4d1eed767fb99482fff12569cb8b21988353015583392fa0bda4cf9f577bb8ebaa818182c9b39d91e3a40c88d2dfa22e8ff2e1989366e9b00369575638694ec3
languageName: node
linkType: hard

"@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.259":
version: 1.0.0-alpha.259
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.259"
"@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.261":
version: 1.0.0-alpha.261
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.261"
peerDependencies:
react: "*"
react-native: "*"
checksum: 9129611d0aef2d88fe136cd3b50db4f4c55799ab4f2cad7180e2a187bf24e6e75d019f4c7bf58839a6a7a45a065ac0dfe93a29372ca75ae29624f55c17bcea1d
checksum: d167fca02e77b4db73ffd3535a99fcde83703d904619ece10016abff906271bdd2a047d6cde20394442f472c291ce7a13aaa7bb3a4da4470de03e0f959cf1d59
languageName: node
linkType: hard

Expand Down Expand Up @@ -8962,11 +8962,11 @@ __metadata:
"@formatjs/intl-relativetimeformat": "npm:9.3.1"
"@hyperledger/anoncreds-react-native": "npm:0.2.2"
"@hyperledger/aries-askar-react-native": "npm:0.2.1"
"@hyperledger/aries-bifold-core": "npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-remote-logs": "npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-verifier": "npm:1.0.0-alpha.259"
"@hyperledger/aries-oca": "npm:1.0.0-alpha.259"
"@hyperledger/aries-react-native-attestation": "npm:1.0.0-alpha.259"
"@hyperledger/aries-bifold-core": "npm:1.0.0-alpha.261"
"@hyperledger/aries-bifold-remote-logs": "npm:1.0.0-alpha.261"
"@hyperledger/aries-bifold-verifier": "npm:1.0.0-alpha.261"
"@hyperledger/aries-oca": "npm:1.0.0-alpha.261"
"@hyperledger/aries-react-native-attestation": "npm:1.0.0-alpha.261"
"@hyperledger/indy-vdr-react-native": "npm:0.2.2"
"@react-native-async-storage/async-storage": "npm:1.15.11"
"@react-native-community/masked-view": "npm:0.1.11"
Expand Down

0 comments on commit bdf92cb

Please sign in to comment.