From c15dcd3a8baf2b087278241ca3f9c64495c183ba Mon Sep 17 00:00:00 2001 From: ZouidiSamih Date: Mon, 20 Jan 2025 18:26:27 -0500 Subject: [PATCH 1/5] feat: add visibility toggle for scan error info button (#1399) Signed-off-by: ZouidiSamih --- .../core/App/components/misc/QRScanner.tsx | 22 ++++++++++--------- packages/legacy/core/App/types/config.ts | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/legacy/core/App/components/misc/QRScanner.tsx b/packages/legacy/core/App/components/misc/QRScanner.tsx index 819b57c90..4140980a9 100644 --- a/packages/legacy/core/App/components/misc/QRScanner.tsx +++ b/packages/legacy/core/App/components/misc/QRScanner.tsx @@ -25,7 +25,7 @@ interface Props { const QRScanner: React.FC = ({ handleCodeScan, error, enableCameraOnError }) => { const navigation = useNavigation>() - const [{ showScanHelp, showScanButton }] = useServices([TOKENS.CONFIG]) + const [{ showScanHelp, showScanButton, showScanErrorButton = true }] = useServices([TOKENS.CONFIG]) const [torchActive, setTorchActive] = useState(false) const [showInfoBox, setShowInfoBox] = useState(false) const [showErrorDetailsModal, setShowErrorDetailsModal] = useState(false) @@ -109,15 +109,17 @@ const QRScanner: React.FC = ({ handleCodeScan, error, enableCameraOnError {error.message} - setShowErrorDetailsModal(true)} - accessibilityLabel={t('Scan.ShowDetails')} - accessibilityRole={'button'} - testID={testIdWithKey('ShowDetails')} - hitSlop={hitSlop} - > - - + {showScanErrorButton && ( + setShowErrorDetailsModal(true)} + accessibilityLabel={t('Scan.ShowDetails')} + accessibilityRole={'button'} + testID={testIdWithKey('ShowDetails')} + hitSlop={hitSlop} + > + + + )} ) : ( <> diff --git a/packages/legacy/core/App/types/config.ts b/packages/legacy/core/App/types/config.ts index b3c2224cd..cb566344e 100644 --- a/packages/legacy/core/App/types/config.ts +++ b/packages/legacy/core/App/types/config.ts @@ -31,6 +31,7 @@ export interface Config { whereToUseWalletUrl?: string showScanHelp?: boolean showScanButton?: boolean + showScanErrorButton?: boolean globalScreenOptions?: StackNavigationOptions showDetailsInfo?: boolean contactHideList?: string[] From 23a23323061ff39a181565089cd3a9990112bf7e Mon Sep 17 00:00:00 2001 From: ClaudeArs <107423901+ClaudeArs@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:42:38 -0500 Subject: [PATCH 2/5] feat: Inject title and condition link of Scan Help page (#1403) Signed-off-by: ClaudeArs --- packages/legacy/core/App/localization/en/index.ts | 1 + packages/legacy/core/App/localization/fr/index.ts | 1 + packages/legacy/core/App/navigators/ConnectStack.tsx | 1 + packages/legacy/core/App/screens/ScanHelp.tsx | 6 +++--- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/legacy/core/App/localization/en/index.ts b/packages/legacy/core/App/localization/en/index.ts index 99ff8cecd..7a4ed0e34 100644 --- a/packages/legacy/core/App/localization/en/index.ts +++ b/packages/legacy/core/App/localization/en/index.ts @@ -758,6 +758,7 @@ const translation = { "EnterPIN": "Enter PIN", "Home": "Notifications", "Scan": "Scan", + "ScanHelp": "Scan Help", "Credentials": "Credentials", "CredentialDetails": "Credential Details", "Notifications": "Notifications", diff --git a/packages/legacy/core/App/localization/fr/index.ts b/packages/legacy/core/App/localization/fr/index.ts index e092e7658..d1e8f3ea5 100644 --- a/packages/legacy/core/App/localization/fr/index.ts +++ b/packages/legacy/core/App/localization/fr/index.ts @@ -741,6 +741,7 @@ const translation = { "EnterPIN": "Saisir le NIP", "Home": "Notifications", "Scan": "Numériser", + "ScanHelp": "Aide à la numérisation", "Credentials": "Justificatifs", "CredentialDetails": "Détails des attestations", "Notifications": "Notifications", diff --git a/packages/legacy/core/App/navigators/ConnectStack.tsx b/packages/legacy/core/App/navigators/ConnectStack.tsx index 44b725277..f5fd40342 100644 --- a/packages/legacy/core/App/navigators/ConnectStack.tsx +++ b/packages/legacy/core/App/navigators/ConnectStack.tsx @@ -47,6 +47,7 @@ const ConnectStack: React.FC = () => { name={Screens.ScanHelp} component={ScanHelp} options={{ + title: t('Screens.ScanHelp'), ...ScreenOptionsDictionary[Screens.ScanHelp] }} /> diff --git a/packages/legacy/core/App/screens/ScanHelp.tsx b/packages/legacy/core/App/screens/ScanHelp.tsx index 179e52379..76092dfe4 100644 --- a/packages/legacy/core/App/screens/ScanHelp.tsx +++ b/packages/legacy/core/App/screens/ScanHelp.tsx @@ -33,12 +33,12 @@ const ScanHelp: React.FC = () => { {t('Scan.WhatToScan')} {t('Scan.ScanOnySpecial')} {t('Scan.ScanOnlySpecial2')} - whereToUseWalletUrl && Linking.openURL(whereToUseWalletUrl)} + onPress={() => Linking.openURL(whereToUseWalletUrl)} testID={testIdWithKey('WhereToUseLink')} - /> + /> )} {t('Scan.ScanOnlySpecial3')} From 3a6b2eafe3b4eb200ccf7f86caa80f2ac71ffba5 Mon Sep 17 00:00:00 2001 From: jcdrouin21 Date: Wed, 22 Jan 2025 12:17:04 -0500 Subject: [PATCH 3/5] chore: Enhance exports in core modules and a small import fix (#1404) Signed-off-by: Jean-Christophe Drouin --- packages/legacy/core/App/index.ts | 4 +++- packages/legacy/core/App/modules/history/index.ts | 4 ++-- packages/legacy/core/App/types/proof-items.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/legacy/core/App/index.ts b/packages/legacy/core/App/index.ts index e4827ab83..40c3af6dd 100644 --- a/packages/legacy/core/App/index.ts +++ b/packages/legacy/core/App/index.ts @@ -83,7 +83,9 @@ export { BifoldError } from './types/error' export { EventTypes } from './constants' export { migrateToAskar } from './utils/migration' export { createLinkSecretIfRequired, getAgentModules } from './utils/agent' -export { removeExistingInvitationIfRequired, connectFromScanOrDeepLink } from './utils/helpers' +export { removeExistingInvitationIfRequired, connectFromScanOrDeepLink, formatTime, useCredentialConnectionLabel, getConnectionName } from './utils/helpers' +export { isValidAnonCredsCredential, getCredentialIdentifiers } from './utils/credential' +export { buildFieldsFromAnonCredsCredential } from './utils/oca' export type { AnimatedComponents } from './animated-components' export type { diff --git a/packages/legacy/core/App/modules/history/index.ts b/packages/legacy/core/App/modules/history/index.ts index dcc8b2cdf..9ab0b1653 100644 --- a/packages/legacy/core/App/modules/history/index.ts +++ b/packages/legacy/core/App/modules/history/index.ts @@ -1,2 +1,2 @@ -import { IHistoryManager } from './types' -export type { IHistoryManager } +import { IHistoryManager, HistoryRecord} from './types' +export type { IHistoryManager, HistoryRecord } diff --git a/packages/legacy/core/App/types/proof-items.ts b/packages/legacy/core/App/types/proof-items.ts index fc4db0531..cfc9d6623 100644 --- a/packages/legacy/core/App/types/proof-items.ts +++ b/packages/legacy/core/App/types/proof-items.ts @@ -1,7 +1,7 @@ import { AnonCredsCredentialsForProofRequest } from '@credo-ts/anoncreds' import { CredentialExchangeRecord } from '@credo-ts/core' import { Attribute, Predicate } from '@hyperledger/aries-oca/build/legacy' -import { DescriptorMetadata } from 'utils/anonCredsProofRequestMapper' +import { DescriptorMetadata } from '../utils/anonCredsProofRequestMapper' export type CredentialDataForProof = { groupedProof: (ProofCredentialPredicates & ProofCredentialAttributes)[], From 52149fd57bac4e253f86cb55a93e5e546cabbc24 Mon Sep 17 00:00:00 2001 From: jian4on <96585781+jian4on@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:18:30 -0500 Subject: [PATCH 4/5] feat: Change network status check feature in NetInfo, disable/enable mediator check and provide new method to check isInternetReachable (#1390) Signed-off-by: Jian Wang Co-authored-by: Al Rosenthal --- .../core/App/components/network/NetInfo.tsx | 77 +++++++++++++------ packages/legacy/core/App/container-impl.ts | 2 + packages/legacy/core/App/contexts/network.tsx | 16 ++-- packages/legacy/core/App/types/config.ts | 2 + .../legacy/core/__tests__/contexts/network.ts | 4 +- .../core/__tests__/screens/Chat.test.tsx | 6 +- 6 files changed, 75 insertions(+), 32 deletions(-) diff --git a/packages/legacy/core/App/components/network/NetInfo.tsx b/packages/legacy/core/App/components/network/NetInfo.tsx index eb18b94d7..0babf5342 100644 --- a/packages/legacy/core/App/components/network/NetInfo.tsx +++ b/packages/legacy/core/App/components/network/NetInfo.tsx @@ -4,36 +4,18 @@ import { useTranslation } from 'react-i18next' import Toast from 'react-native-toast-message' import { useNetwork } from '../../contexts/network' import { ToastType } from '../../components/toast/BaseToast' +import { TOKENS, useServices } from '../../container-api' const NetInfo: React.FC = () => { - const { silentAssertConnectedNetwork, assertNetworkReachable } = useNetwork() + const { silentAssertConnectedNetwork, assertInternetReachable, assertMediatorReachable } = useNetwork() + const [{ disableMediatorCheck }] = useServices([TOKENS.CONFIG]) const { t } = useTranslation() const [hasShown, setHasShown] = useState(false) const isConnected = silentAssertConnectedNetwork() - useEffect(() => { - // Network is connected - if (isConnected) { - // Assert that internet is available - assertNetworkReachable().then((status) => { - // Connected to a network, reset toast - setHasShown(false) - if (status) { - return - } - - // User is connected to a network but has no internet, display toast - Toast.show({ - type: ToastType.Error, - autoHide: true, - text1: t('NetInfo.NoInternetConnectionTitle'), - }) - }) - return - } - // Only show the toast if the user hasn't seen it already - if (!hasShown) { + useEffect(() => { + const _showNetworkWarning = () => { setHasShown(true) Toast.show({ type: ToastType.Error, @@ -41,7 +23,54 @@ const NetInfo: React.FC = () => { text1: t('NetInfo.NoInternetConnectionTitle'), }) } - }, [isConnected, assertNetworkReachable, t, hasShown]) + // Network is available, do further testing according to CFG.disableMediatorCheck + if (!disableMediatorCheck) { + // Network is available + if (isConnected) { + // Check mediator socket, also assert internet reachable + assertMediatorReachable().then((status) => { + if (status) { + Toast.hide() + return + } else { + // Network is available but cannot access nediator, display toast + _showNetworkWarning() + } + }) + return + } else if (!hasShown) { + _showNetworkWarning() + } + return + } else { + // Check internetReachable by connecting test beacon urls + assertInternetReachable().then((status) => { + if (status) { + Toast.hide() + return + } else if (null === status) { + // keep silent when the internet status not yet assert + return + /* + Toast.show({ + type: ToastType.Info, + autoHide: false, + text1: "Checking internet reachable", + }) + */ + } else if (!hasShown) { + _showNetworkWarning() + } + }) + } + }, [ + isConnected, + disableMediatorCheck, + assertInternetReachable, + assertMediatorReachable, + t, + hasShown + ]) return null } diff --git a/packages/legacy/core/App/container-impl.ts b/packages/legacy/core/App/container-impl.ts index 2f4a52be8..a42b44f78 100644 --- a/packages/legacy/core/App/container-impl.ts +++ b/packages/legacy/core/App/container-impl.ts @@ -61,6 +61,8 @@ export const defaultConfig: Config = { showPreface: false, disableOnboardingSkip: false, disableContactsInSettings: false, + disableMediatorCheck: false, + internetReachabilityUrls: ['https://clients3.google.com/generate_204'], whereToUseWalletUrl: 'https://example.com', showScanHelp: true, showScanButton: true, diff --git a/packages/legacy/core/App/contexts/network.tsx b/packages/legacy/core/App/contexts/network.tsx index adc162792..12fd36a60 100644 --- a/packages/legacy/core/App/contexts/network.tsx +++ b/packages/legacy/core/App/contexts/network.tsx @@ -5,12 +5,14 @@ import { createContext, useContext, useState } from 'react' import NetInfoModal from '../components/modals/NetInfoModal' import { hostnameFromURL, canConnectToHost } from '../utils/network' import { Config } from 'react-native-config' + export interface NetworkContext { silentAssertConnectedNetwork: () => boolean assertNetworkConnected: () => boolean displayNetInfoModal: () => void hideNetInfoModal: () => void - assertNetworkReachable: () => Promise + assertInternetReachable: () => Promise + assertMediatorReachable: () => Promise } export const NetworkContext = createContext(null as unknown as NetworkContext) @@ -28,7 +30,7 @@ export const NetworkProvider: React.FC = ({ children }) } const silentAssertConnectedNetwork = () => { - return netInfo.isConnected || netInfo.type !== NetInfoStateType.none + return netInfo.isConnected || [NetInfoStateType.wifi, NetInfoStateType.cellular].includes(netInfo.type) } const assertNetworkConnected = () => { @@ -36,11 +38,14 @@ export const NetworkProvider: React.FC = ({ children }) if (!isConnected) { displayNetInfoModal() } - return isConnected } - const assertNetworkReachable = async (): Promise => { + const assertInternetReachable = async (): Promise => { + return netInfo.isInternetReachable as boolean + } + + const assertMediatorReachable = async (): Promise => { const hostname = hostnameFromURL(Config.MEDIATOR_URL!) if (hostname === null || hostname.length === 0) { @@ -60,7 +65,8 @@ export const NetworkProvider: React.FC = ({ children }) assertNetworkConnected, displayNetInfoModal, hideNetInfoModal, - assertNetworkReachable, + assertInternetReachable, + assertMediatorReachable }} > {children} diff --git a/packages/legacy/core/App/types/config.ts b/packages/legacy/core/App/types/config.ts index cb566344e..cdd3cfca7 100644 --- a/packages/legacy/core/App/types/config.ts +++ b/packages/legacy/core/App/types/config.ts @@ -38,6 +38,8 @@ export interface Config { contactDetailsOptions?: ContactDetailsOptionsParams credentialHideList?: string[] disableContactsInSettings?: boolean + disableMediatorCheck?: boolean + internetReachabilityUrls: string[] } export interface HistoryEventsLoggerConfig { diff --git a/packages/legacy/core/__tests__/contexts/network.ts b/packages/legacy/core/__tests__/contexts/network.ts index 32b645002..d56502723 100644 --- a/packages/legacy/core/__tests__/contexts/network.ts +++ b/packages/legacy/core/__tests__/contexts/network.ts @@ -3,7 +3,9 @@ const networkContext = { silentAssertConnectedNetwork: jest.fn(), displayNetInfoModal: jest.fn(), hideNetInfoModal: jest.fn(), - assertNetworkReachable: jest.fn(), + // assertNetworkReachable: jest.fn(), + assertInternetReachable: jest.fn(), + assertMediatorReachable: jest.fn(), } export default networkContext diff --git a/packages/legacy/core/__tests__/screens/Chat.test.tsx b/packages/legacy/core/__tests__/screens/Chat.test.tsx index 8be6de38c..4670b9683 100644 --- a/packages/legacy/core/__tests__/screens/Chat.test.tsx +++ b/packages/legacy/core/__tests__/screens/Chat.test.tsx @@ -83,7 +83,8 @@ describe('Chat Screen', () => { jest.spyOn(network, 'useNetwork').mockImplementation(() => ({ silentAssertConnectedNetwork: () => true, assertNetworkConnected: () => true, - assertNetworkReachable: jest.fn(), + assertInternetReachable: jest.fn(), + assertMediatorReachable: jest.fn(), displayNetInfoModal: jest.fn(), hideNetInfoModal: jest.fn(), })) @@ -108,7 +109,8 @@ describe('Chat screen with messages', () => { jest.spyOn(network, 'useNetwork').mockImplementation(() => ({ silentAssertConnectedNetwork: () => true, assertNetworkConnected: () => true, - assertNetworkReachable: jest.fn(), + assertInternetReachable: jest.fn(), + assertMediatorReachable: jest.fn(), displayNetInfoModal: jest.fn(), hideNetInfoModal: jest.fn(), })) From 410b3694f7b44d744299f37999ccfbcaf75055f9 Mon Sep 17 00:00:00 2001 From: Al Rosenthal Date: Wed, 22 Jan 2025 11:48:46 -0800 Subject: [PATCH 5/5] fix: fixed inline function warning (#1407) Signed-off-by: al-rosenthal --- packages/legacy/core/App/navigators/SettingStack.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/legacy/core/App/navigators/SettingStack.tsx b/packages/legacy/core/App/navigators/SettingStack.tsx index 653e98be4..ab2a2e9a3 100644 --- a/packages/legacy/core/App/navigators/SettingStack.tsx +++ b/packages/legacy/core/App/navigators/SettingStack.tsx @@ -102,13 +102,14 @@ const SettingStack: React.FC = () => { /> } options={{ title: t('Screens.ChangePIN'), headerBackTestID: testIdWithKey('Back'), ...ScreenOptionsDictionary[Screens.CreatePIN], }} - /> + > + {(props: any) => } +