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: add config attribute to enable/disable contacts section in Settings screen, default as enabled #1374

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const defaultConfig: Config = {
supportedLanguages: [Locales.en, Locales.fr, Locales.ptBr],
showPreface: false,
disableOnboardingSkip: false,
disableContactsInSettings: false,
whereToUseWalletUrl: 'https://example.com',
showScanHelp: true,
showScanButton: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/legacy/core/App/screens/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Settings: React.FC<SettingsProps> = ({ navigation }) => {
const [store, dispatch] = useStore()
const developerOptionCount = useRef(0)
const { SettingsTheme, TextTheme, ColorPallet, Assets } = useTheme()
const [{ settings, enableTours, enablePushNotifications }, historyEnabled] = useServices([
const [{ settings, enableTours, enablePushNotifications, disableContactsInSettings }, historyEnabled] = useServices([
TOKENS.CONFIG,
TOKENS.HISTORY_ENABLED,
])
Expand Down Expand Up @@ -167,6 +167,11 @@ const Settings: React.FC<SettingsProps> = ({ navigation }) => {
},
...(settings || []),
]

// Remove the Contact section from Setting per TOKENS.CONFIG
if (disableContactsInSettings) {
settingsSections.shift();
}

// add optional push notifications menu to settings
if (enablePushNotifications) {
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/core/App/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Config {
contactHideList?: string[]
contactDetailsOptions?: ContactDetailsOptionsParams
credentialHideList?: string[]
disableContactsInSettings?: boolean
}

export interface HistoryEventsLoggerConfig {
Expand Down
36 changes: 36 additions & 0 deletions packages/legacy/core/__tests__/screens/Settings.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useNavigation } from '@react-navigation/native'
import { render } from '@testing-library/react-native'
import React from 'react'
import { container } from 'tsyringe'

import { StoreContext } from '../../App'
import Settings from '../../App/screens/Settings'
import { testIdWithKey } from '../../App/utils/testable'
import { testDefaultState } from '../contexts/store'
import { BasicAppContext } from '../helpers/app'
import { CustomBasicAppContext } from '../helpers/app'
import { TOKENS } from '../../App/container-api'
import { MainContainer } from '../../App/container-impl'

describe('Settings Screen', () => {
beforeEach(() => {
Expand Down Expand Up @@ -127,4 +131,36 @@ describe('Settings Screen', () => {
const proofButton = tree.getByTestId(testIdWithKey('ProofRequests'))
expect(proofButton).not.toBeNull()
})

test('If disableContactsInSettings is true, the Contacts section is not shown', async () => {
const customState = {
...testDefaultState,
preferences: {
...testDefaultState.preferences,
developerModeEnabled: true,
walletName: 'My Wallet',
},
}

const context = new MainContainer(container.createChildContainer()).init()
const config = context.resolve(TOKENS.CONFIG)
context.container.registerInstance(TOKENS.CONFIG, { ...config, disableContactsInSettings: true})

const tree = render(
<StoreContext.Provider
value={[
customState,
() => {
return
},
]}
>
<CustomBasicAppContext container={context}>
<Settings navigation={useNavigation()} route={{} as any} />
</CustomBasicAppContext>
</StoreContext.Provider>
)
const contactsSection = tree.queryByTestId(testIdWithKey('Contacts'))
expect(contactsSection).toBeNull()
})
})