From 97109ddc24194fe84e2f0896205ec544d720e3d8 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 29 Jun 2021 15:02:06 +0500 Subject: [PATCH] added migration script to bottom sheet switcher and fixed check logic --- .../container/accountsBottomSheetContainer.js | 14 ++++++++++++-- .../application/container/applicationContainer.js | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/accountsBottomSheet/container/accountsBottomSheetContainer.js b/src/components/accountsBottomSheet/container/accountsBottomSheetContainer.js index 35c7c9b2d..0bcbf33b2 100644 --- a/src/components/accountsBottomSheet/container/accountsBottomSheetContainer.js +++ b/src/components/accountsBottomSheet/container/accountsBottomSheetContainer.js @@ -7,11 +7,14 @@ import { updateCurrentAccount } from '../../../redux/actions/accountAction'; import { isRenderRequired } from '../../../redux/actions/applicationActions'; import { getUserDataWithUsername } from '../../../realm/realm'; -import { switchAccount } from '../../../providers/hive/auth'; +import { migrateToMasterKeyWithAccessToken, switchAccount } from '../../../providers/hive/auth'; import AccountsBottomSheet from '../view/accountsBottomSheetView'; import { toggleAccountsBottomSheet } from '../../../redux/actions/uiAction'; +//Constants +import AUTH_TYPE from '../../../constants/authType'; + const AccountsBottomSheetContainer = ({ navigation }) => { const dispatch = useDispatch(); const accountsBottomSheetViewRef = useRef(); @@ -21,6 +24,8 @@ const AccountsBottomSheetContainer = ({ navigation }) => { ); const currentAccount = useSelector((state) => state.account.currentAccount); const accounts = useSelector((state) => state.account.otherAccounts); + const pinHash = useSelector((state)=>state.application.pin); + useEffect(() => { if (isVisibleAccountsBottomSheet) { @@ -61,12 +66,17 @@ const AccountsBottomSheetContainer = ({ navigation }) => { } //fetch upto data account data nd update current account; - const _currentAccount = await switchAccount(accountData.username); + let _currentAccount = await switchAccount(accountData.username); const realmData = await getUserDataWithUsername(accountData.username); _currentAccount.username = _currentAccount.name; _currentAccount.local = realmData[0]; + //migreate account to use access token for master key auth type + if (realmData[0].authType === AUTH_TYPE.MASTER_KEY && realmData[0].accessToken === "") { + _currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, pinHash); + } + dispatch(updateCurrentAccount(_currentAccount)); }; diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 7a9f80c45..9efe43ac0 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -812,7 +812,7 @@ class ApplicationContainer extends Component { [_currentAccount.local] = realmData; //migreate account to use access token for master key auth type - if (realmData[0].authType === AUTH_TYPE.MASTER_KEY && realmData[0].accessToken) { + if (realmData[0].authType === AUTH_TYPE.MASTER_KEY && realmData[0].accessToken === "") { _currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, pinCode); }