added migration script to bottom sheet switcher and fixed check logic

This commit is contained in:
Nouman Tahir 2021-06-29 15:02:06 +05:00
parent b6b80e7a7b
commit 97109ddc24
2 changed files with 13 additions and 3 deletions

View File

@ -7,11 +7,14 @@ import { updateCurrentAccount } from '../../../redux/actions/accountAction';
import { isRenderRequired } from '../../../redux/actions/applicationActions'; import { isRenderRequired } from '../../../redux/actions/applicationActions';
import { getUserDataWithUsername } from '../../../realm/realm'; import { getUserDataWithUsername } from '../../../realm/realm';
import { switchAccount } from '../../../providers/hive/auth'; import { migrateToMasterKeyWithAccessToken, switchAccount } from '../../../providers/hive/auth';
import AccountsBottomSheet from '../view/accountsBottomSheetView'; import AccountsBottomSheet from '../view/accountsBottomSheetView';
import { toggleAccountsBottomSheet } from '../../../redux/actions/uiAction'; import { toggleAccountsBottomSheet } from '../../../redux/actions/uiAction';
//Constants
import AUTH_TYPE from '../../../constants/authType';
const AccountsBottomSheetContainer = ({ navigation }) => { const AccountsBottomSheetContainer = ({ navigation }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const accountsBottomSheetViewRef = useRef(); const accountsBottomSheetViewRef = useRef();
@ -21,6 +24,8 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
); );
const currentAccount = useSelector((state) => state.account.currentAccount); const currentAccount = useSelector((state) => state.account.currentAccount);
const accounts = useSelector((state) => state.account.otherAccounts); const accounts = useSelector((state) => state.account.otherAccounts);
const pinHash = useSelector((state)=>state.application.pin);
useEffect(() => { useEffect(() => {
if (isVisibleAccountsBottomSheet) { if (isVisibleAccountsBottomSheet) {
@ -61,12 +66,17 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
} }
//fetch upto data account data nd update current account; //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); const realmData = await getUserDataWithUsername(accountData.username);
_currentAccount.username = _currentAccount.name; _currentAccount.username = _currentAccount.name;
_currentAccount.local = realmData[0]; _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)); dispatch(updateCurrentAccount(_currentAccount));
}; };

View File

@ -812,7 +812,7 @@ class ApplicationContainer extends Component {
[_currentAccount.local] = realmData; [_currentAccount.local] = realmData;
//migreate account to use access token for master key auth type //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); _currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, pinCode);
} }