From 354dcc3f757e02416d143f41576f2d03f3cff0b8 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Sat, 3 Feb 2024 23:56:37 +0500 Subject: [PATCH] add support to process hiveuris from notification data --- src/components/qrModal/qrModalView.tsx | 13 +++++++++++++ src/redux/actions/uiAction.ts | 6 ++++++ src/redux/constants/constants.js | 1 + src/redux/reducers/uiReducer.ts | 8 ++++++++ src/screens/application/hook/useInitApplication.tsx | 11 ++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/components/qrModal/qrModalView.tsx b/src/components/qrModal/qrModalView.tsx index 2811de8658..eca5512373 100644 --- a/src/components/qrModal/qrModalView.tsx +++ b/src/components/qrModal/qrModalView.tsx @@ -36,11 +36,21 @@ export const QRModal = () => { const isPinCodeOpen = useAppSelector((state) => state.application.isPinCodeOpen); const isLoggedIn = useAppSelector((state) => state.application.isLoggedIn); + const [isScannerActive, setIsScannerActive] = useState(true); const [isProcessing, setIsProcessing] = useState(false); const sheetModalRef = useRef(); const scannerRef = useRef(null); + //TODO: make sure to properly clean uri processing code to process uri from deep links and notifications + const hiveUriToHandle = useAppSelector((state) => state.ui.hiveUriToHandle); + useEffect(() => { + if(hiveUriToHandle){ + _handleHiveUri(hiveUriToHandle); + } + }, [hiveUriToHandle]) + + useEffect(() => { if (isVisibleQRModal) { requestCameraPermission(); @@ -48,8 +58,11 @@ export const QRModal = () => { } else { sheetModalRef?.current?.hide(); } + }, [isVisibleQRModal]); + + const requestCameraPermission = async () => { if (Platform.OS === 'ios') { const permissionStatus = await check(PERMISSIONS.IOS.CAMERA); diff --git a/src/redux/actions/uiAction.ts b/src/redux/actions/uiAction.ts index 54a9e0e47e..17bab07dcb 100644 --- a/src/redux/actions/uiAction.ts +++ b/src/redux/actions/uiAction.ts @@ -17,6 +17,7 @@ import { LOGOUT_DONE, SHOW_WEBVIEW_MODAL, HIDE_WEBVIEW_MODAL, + HIVE_URI_TO_HANDLE, } from '../constants/constants'; import { PostEditorModalData } from '../reducers/uiReducer'; @@ -118,3 +119,8 @@ export const logout = () => ({ export const logoutDone = () => ({ type: LOGOUT_DONE, }); + +export const handleHiveUri = (hiveUri:string) => ({ + payload:hiveUri, + type: HIVE_URI_TO_HANDLE +}) diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index 99ed13f09b..0372539666 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -71,6 +71,7 @@ export const SET_DEVICE_ORIENTATION = 'SET_DEVICE_ORIENTATION'; export const SET_LOCKED_ORIENTATION = 'SET_LOCKED_ORIENTATION'; export const SHOW_REPLY_MODAL = 'SHOW_REPLY_MODAL'; export const HIDE_REPLY_MODAL = 'HIDE_REPLY_MODAL'; +export const HIVE_URI_TO_HANDLE = 'HIVE_URI_TO_HANDLE'; // POSTS export const SET_FEED_POSTS = 'SET_FEED_POSTS'; diff --git a/src/redux/reducers/uiReducer.ts b/src/redux/reducers/uiReducer.ts index 757fc62648..7ff1dfe75b 100644 --- a/src/redux/reducers/uiReducer.ts +++ b/src/redux/reducers/uiReducer.ts @@ -17,6 +17,7 @@ import { LOGOUT_DONE, SHOW_WEBVIEW_MODAL, HIDE_WEBVIEW_MODAL, + HIVE_URI_TO_HANDLE, } from '../constants/constants'; import { orientations } from '../constants/orientationsConstants'; @@ -42,6 +43,7 @@ interface UiState { replyModalVisible: boolean; replyModalData?: PostEditorModalData | null; isLogingOut: boolean; + hiveUriToHandle:string; } const initialState: UiState = { @@ -61,6 +63,7 @@ const initialState: UiState = { replyModalData: null, replyModalVisible: false, isLogingOut: false, + hiveUriToHandle: '', }; const uiReducer = (state = initialState, action): UiState => { @@ -176,6 +179,11 @@ const uiReducer = (state = initialState, action): UiState => { ...state, isLogingOut: false, }; + case HIVE_URI_TO_HANDLE: + return { + ...state, + hiveUriToHandle: action.payload + } default: return state; } diff --git a/src/screens/application/hook/useInitApplication.tsx b/src/screens/application/hook/useInitApplication.tsx index c0bb7ff10b..a2972890da 100644 --- a/src/screens/application/hook/useInitApplication.tsx +++ b/src/screens/application/hook/useInitApplication.tsx @@ -15,7 +15,7 @@ import messaging from '@react-native-firebase/messaging'; import BackgroundTimer from 'react-native-background-timer'; import FastImage from 'react-native-fast-image'; import { useAppDispatch, useAppSelector } from '../../../hooks'; -import { setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction'; +import { handleHiveUri, setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction'; import { orientations } from '../../../redux/constants/orientationsConstants'; import isAndroidTablet from '../../../utils/isAndroidTablet'; import darkTheme from '../../../themes/darkTheme'; @@ -27,6 +27,8 @@ import { markNotifications } from '../../../providers/ecency/ecency'; import { updateUnreadActivityCount } from '../../../redux/actions/accountAction'; import RootNavigation from '../../../navigation/rootNavigation'; import ROUTES from '../../../constants/routeNames'; +import { isPoundElement } from 'intl-messageformat-parser'; +import * as hiveuri from 'hive-uri'; export const useInitApplication = () => { const dispatch = useAppDispatch(); @@ -232,6 +234,12 @@ export const useInitApplication = () => { key = push.source || 'inactive'; break; + case 'hiveuri': + if(push.hiveUri){ + dispatch(handleHiveUri(push.hiveUri)) + } + break; + default: break; } @@ -259,6 +267,7 @@ export const useInitApplication = () => { }); } } + } }; };