removed cached added contacts
This commit is contained in:
@@ -27,12 +27,9 @@ export default function AddContactPage({navigation}) {
|
||||
const navigate = useNavigation();
|
||||
const {contactsPrivateKey, deepLinkContent, setDeepLinkContent} =
|
||||
useGlobalContextProvider();
|
||||
let debounceTimeout;
|
||||
const {globalContactsList, decodedAddedContacts, globalContactsInformation} =
|
||||
useGlobalContacts();
|
||||
const {decodedAddedContacts, globalContactsInformation} = useGlobalContacts();
|
||||
const [searchInput, setSearchInput] = useState('');
|
||||
const [users, setUsers] = useState([]);
|
||||
const [placeHolderUsers, setPlaceHolderUsers] = useState([]);
|
||||
const tabsNavigate = navigation.navigate;
|
||||
const {textInputBackground, textInputColor} = GetThemeColors();
|
||||
|
||||
@@ -44,31 +41,28 @@ export default function AddContactPage({navigation}) {
|
||||
return true;
|
||||
}, [navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
setPlaceHolderUsers(
|
||||
globalContactsList.map((savedContact, id) => {
|
||||
return (
|
||||
<ContactListItem
|
||||
key={savedContact.uniqueName}
|
||||
navigation={navigation}
|
||||
id={id}
|
||||
savedContact={savedContact}
|
||||
contactsPrivateKey={contactsPrivateKey}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
);
|
||||
}, [globalContactsList, contactsPrivateKey, navigation]);
|
||||
// useEffect(() => {
|
||||
// setPlaceHolderUsers(
|
||||
// globalContactsList.map((savedContact, id) => {
|
||||
// return (
|
||||
// <ContactListItem
|
||||
// key={savedContact.uniqueName}
|
||||
// navigation={navigation}
|
||||
// id={id}
|
||||
// savedContact={savedContact}
|
||||
// contactsPrivateKey={contactsPrivateKey}
|
||||
// />
|
||||
// );
|
||||
// }),
|
||||
// );
|
||||
// }, [globalContactsList, contactsPrivateKey, navigation]);
|
||||
|
||||
// Use useMemo to ensure debounce function is not recreated on every render
|
||||
// Debounced version of the search function
|
||||
const debouncedSearch = useDebounce(async term => {
|
||||
console.log(term);
|
||||
const results = await searchUsers(term);
|
||||
|
||||
console.log(results, 'TEST');
|
||||
const newUsers = results.map((savedContact, id) => {
|
||||
console.log(savedContact, 'TEST');
|
||||
if (!savedContact) {
|
||||
return false;
|
||||
}
|
||||
@@ -184,10 +178,10 @@ export default function AddContactPage({navigation}) {
|
||||
}, [deepLinkContent, decodedAddedContacts, navigate, setDeepLinkContent]);
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : null}
|
||||
style={{flex: 1}}>
|
||||
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
||||
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : null}
|
||||
style={{flex: 1}}>
|
||||
<GlobalThemeView useStandardWidth={true} styles={{paddingBottom: 0}}>
|
||||
<View style={styles.topBar}>
|
||||
<ThemeText styles={styles.headerText} content={'New Contacts'} />
|
||||
@@ -235,82 +229,29 @@ export default function AddContactPage({navigation}) {
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
{/* {isLoadingContacts ? (
|
||||
{searchInput.length === 0 ? (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}>
|
||||
<ActivityIndicator
|
||||
size="large"
|
||||
color={textColor}
|
||||
/>
|
||||
<Text
|
||||
style={[
|
||||
styles.gettingContacts,
|
||||
{
|
||||
color: textColor,
|
||||
},
|
||||
]}>
|
||||
Getting all contacts
|
||||
</Text>
|
||||
<View>
|
||||
<ThemeText content={'Begin searching to find contact'} />
|
||||
</View>
|
||||
</View>
|
||||
) : ( */}
|
||||
<FlatList
|
||||
showsVerticalScrollIndicator={false}
|
||||
data={users.length === 0 ? placeHolderUsers : users}
|
||||
renderItem={({item}) => item}
|
||||
/>
|
||||
{/* <View style={{flex: 1}}>
|
||||
<ScrollView>{potentialContacts}</ScrollView>
|
||||
</View> */}
|
||||
{/* )} */}
|
||||
</View>
|
||||
|
||||
{/* <View style={styles.scanProfileContainer}>
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
Keyboard.dismiss();
|
||||
setTimeout(() => {
|
||||
navigate.navigate('CameraModal', {
|
||||
updateBitcoinAdressFunc: parseContact,
|
||||
fromPage: 'addContact',
|
||||
});
|
||||
}, 200);
|
||||
}}
|
||||
style={[
|
||||
styles.scanProfileButton,
|
||||
{
|
||||
backgroundColor: COLORS.darkModeText,
|
||||
},
|
||||
]}>
|
||||
<Image
|
||||
style={styles.scanProfileImage}
|
||||
source={ICONS.scanQrCodeDark}
|
||||
) : (
|
||||
<FlatList
|
||||
showsVerticalScrollIndicator={false}
|
||||
data={users}
|
||||
renderItem={({item}) => item}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
<Text
|
||||
style={[
|
||||
styles.scanProfileText,
|
||||
{
|
||||
color: textColor,
|
||||
},
|
||||
]}>
|
||||
Scan Profile
|
||||
</Text>
|
||||
</View> */}
|
||||
)}
|
||||
</View>
|
||||
</GlobalThemeView>
|
||||
</TouchableWithoutFeedback>
|
||||
</KeyboardAvoidingView>
|
||||
</KeyboardAvoidingView>
|
||||
</TouchableWithoutFeedback>
|
||||
);
|
||||
// function debounce(func, wait) {
|
||||
// return function (...args) {
|
||||
// const context = this;
|
||||
// clearTimeout(debounceTimeout);
|
||||
// debounceTimeout = setTimeout(() => func.apply(context, args), wait);
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
function ContactListItem(props) {
|
||||
@@ -351,207 +292,47 @@ function ContactListItem(props) {
|
||||
backgroundColor: backgroundOffset,
|
||||
},
|
||||
]}>
|
||||
<Text
|
||||
style={[
|
||||
styles.contactListName,
|
||||
{
|
||||
color: textColor,
|
||||
includeFontPadding: false,
|
||||
},
|
||||
]}>
|
||||
{newContact.uniqueName[0]}
|
||||
</Text>
|
||||
<ThemeText
|
||||
styles={{includeFontPadding: false}}
|
||||
content={newContact.uniqueName[0].toUpperCase()}
|
||||
/>
|
||||
</View>
|
||||
<View>
|
||||
<Text
|
||||
style={[
|
||||
styles.contactListName,
|
||||
{
|
||||
color: textColor,
|
||||
},
|
||||
]}>
|
||||
{newContact.uniqueName}
|
||||
</Text>
|
||||
<Text
|
||||
style={[
|
||||
styles.contactListName,
|
||||
{
|
||||
color: textColor,
|
||||
fontSize: SIZES.small,
|
||||
},
|
||||
]}>
|
||||
{newContact.name || 'No name set'}
|
||||
</Text>
|
||||
<ThemeText
|
||||
styles={{includeFontPadding: false}}
|
||||
content={newContact.uniqueName}
|
||||
/>
|
||||
<ThemeText
|
||||
styles={{includeFontPadding: false, fontSize: SIZES.small}}
|
||||
content={newContact.name || 'No name set'}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
||||
async function getContactsFromDatabase() {
|
||||
let users = await queryContacts('blitzWalletUsers');
|
||||
|
||||
return users.map(doc => {
|
||||
const {
|
||||
contacts: {myProfile},
|
||||
} = doc.data();
|
||||
|
||||
const returnObject = {
|
||||
name: myProfile.name,
|
||||
uuid: myProfile.uuid,
|
||||
uniqueName: myProfile.uniqueName,
|
||||
receiveAddress: myProfile.receiveAddress,
|
||||
};
|
||||
return returnObject;
|
||||
});
|
||||
}
|
||||
|
||||
// function addContact(
|
||||
// newContact,
|
||||
// masterInfoObject,
|
||||
// toggleMasterInfoObject,
|
||||
// navigate,
|
||||
// navigation,
|
||||
// contactsPrivateKey,
|
||||
// isFromExpandedPage,
|
||||
// ) {
|
||||
// try {
|
||||
// const publicKey = getPublicKey(contactsPrivateKey);
|
||||
// let savedContacts =
|
||||
// typeof globalContactsInformation.addedContacts === 'string'
|
||||
// ? [
|
||||
// ...JSON.parse(
|
||||
// decryptMessage(
|
||||
// contactsPrivateKey,
|
||||
// publicKey,
|
||||
// globalContactsInformation.addedContacts,
|
||||
// ),
|
||||
// ),
|
||||
// ]
|
||||
// : [];
|
||||
|
||||
// if (globalContactsInformation.myProfile.uuid === newContact.uuid) {
|
||||
// navigate.navigate('ErrorScreen', {
|
||||
// errorMessage: 'Cannot add yourself',
|
||||
// });
|
||||
// return;
|
||||
// } else if (
|
||||
// savedContacts.filter(
|
||||
// savedContact =>
|
||||
// savedContact.uuid === newContact.uuid ||
|
||||
// newContact.uuid === globalContactsInformation.myProfile.uuid,
|
||||
// ).length > 0
|
||||
// ) {
|
||||
// navigate.navigate('ErrorScreen', {
|
||||
// errorMessage: 'Contact already added',
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// savedContacts.push(newContact);
|
||||
|
||||
// toggleMasterInfoObject({
|
||||
// contacts: {
|
||||
// myProfile: {
|
||||
// ...globalContactsInformation.myProfile,
|
||||
// },
|
||||
// addedContacts: encriptMessage(
|
||||
// contactsPrivateKey,
|
||||
// publicKey,
|
||||
// JSON.stringify(savedContacts),
|
||||
// ),
|
||||
// // unaddedContacts:
|
||||
// // typeof globalContactsInformation.unaddedContacts === 'string'
|
||||
// // ? globalContactsInformation.unaddedContacts
|
||||
// // : [],
|
||||
// },
|
||||
// });
|
||||
// console.log(isFromExpandedPage, 'TESTING');
|
||||
|
||||
// // if (isFromExpandedPage) {
|
||||
// // navigate.goBack();
|
||||
// // }
|
||||
|
||||
// // setTimeout(() => {
|
||||
// // navigate.navigate('ErrorScreen', {
|
||||
// // errorMessage: 'Contact saved',
|
||||
// // navigationFunction: {
|
||||
// // navigator: navigation.jumpTo,
|
||||
// // destination: 'Contacts Page',
|
||||
// // },
|
||||
// // });
|
||||
// // }, 800);
|
||||
// } catch (err) {
|
||||
// console.log(err);
|
||||
|
||||
// navigate.navigate('ErrorScreen', {errorMessage: 'Error adding contact'});
|
||||
// }
|
||||
// }
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
globalContainer: {
|
||||
flex: 1,
|
||||
},
|
||||
topBar: {
|
||||
width: '100%',
|
||||
flexDirection: 'row',
|
||||
// justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
marginBottom: 5,
|
||||
|
||||
...CENTER,
|
||||
marginBottom: 15,
|
||||
},
|
||||
headerText: {fontSize: SIZES.large},
|
||||
drawerIcon: {
|
||||
width: 20,
|
||||
height: 20,
|
||||
},
|
||||
inputContainer: {
|
||||
width: '100%',
|
||||
...CENTER,
|
||||
marginTop: 10,
|
||||
},
|
||||
|
||||
gettingContacts: {
|
||||
fontSize: SIZES.medium,
|
||||
fontFamily: FONT.Title_Regular,
|
||||
marginTop: 10,
|
||||
},
|
||||
|
||||
textInput: {
|
||||
width: '100%',
|
||||
padding: 10,
|
||||
...CENTER,
|
||||
fontSize: SIZES.medium,
|
||||
fontFamily: FONT.Title_Regular,
|
||||
borderRadius: 8,
|
||||
},
|
||||
|
||||
scanProfileContainer: {
|
||||
width: '100%',
|
||||
alignItems: 'center',
|
||||
marginTop: 'auto',
|
||||
marginBottom: 10,
|
||||
},
|
||||
scanProfileButton: {
|
||||
// borderRadius: 8,
|
||||
// overflow: 'hidden',
|
||||
marginBottom: 5,
|
||||
marginLeft: 'auto',
|
||||
},
|
||||
scanProfileImage: {
|
||||
width: 20,
|
||||
height: 20,
|
||||
// margin: 12,
|
||||
},
|
||||
scanProfileText: {fontFamily: FONT.Title_Regular, fontSize: SIZES.small},
|
||||
|
||||
contactListContainer: {
|
||||
width: '100%',
|
||||
...CENTER,
|
||||
paddingVertical: 10,
|
||||
|
||||
borderRadius: 10,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
},
|
||||
|
||||
@@ -75,7 +75,6 @@ export default function ConnectingToNodeLoadingScreen({
|
||||
const {webViewRef, setWebViewArgs} = useWebView();
|
||||
const {
|
||||
decodedAddedContacts,
|
||||
updateGlobalContactsList,
|
||||
toggleGlobalContactsInformation,
|
||||
globalContactsInformation,
|
||||
} = useGlobalContacts();
|
||||
@@ -159,7 +158,6 @@ export default function ConnectingToNodeLoadingScreen({
|
||||
claimUnclaimedBoltzSwaps();
|
||||
initWallet();
|
||||
createLiquidReceiveAddress();
|
||||
// cacheContactsList();
|
||||
}, [masterInfoObject, globalContactsInformation]);
|
||||
|
||||
return (
|
||||
@@ -197,14 +195,7 @@ export default function ConnectingToNodeLoadingScreen({
|
||||
// const liquidSession = await startGDKSession();
|
||||
const lightningSession = await connectToNode(onBreezEvent);
|
||||
const didSetLiquid = await setLiquidNodeInformationForSession();
|
||||
// const savedContactsList = JSON.parse(
|
||||
// await getLocalStorageItem('savedContactsList'),
|
||||
// );
|
||||
|
||||
// console.log('isInitalLoad', isInitialLoad);
|
||||
// if (isInitialLoad || !savedContactsList) {
|
||||
// updateGlobalContactsList('loadingScreen');
|
||||
// }
|
||||
|
||||
if (lightningSession?.isConnected) {
|
||||
const didSetLightning = await setNodeInformationForSession();
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import {useListenForMessages} from '../app/hooks/listenForMessages';
|
||||
import {getLocalStorageItem, setLocalStorageItem} from '../app/functions';
|
||||
import {isMoreThan21Days} from '../app/functions/rotateAddressDateChecker';
|
||||
import {removeLocalStorageItem} from '../app/functions/localStorage';
|
||||
|
||||
// Create a context for the WebView ref
|
||||
const GlobalContacts = createContext(null);
|
||||
@@ -26,7 +27,7 @@ export const GlobalContactsList = ({children}) => {
|
||||
);
|
||||
|
||||
const addedContacts = globalContactsInformation.addedContacts;
|
||||
const [globalContactsList, setGlobalContactsList] = useState([]);
|
||||
// const [globalContactsList, setGlobalContactsList] = useState([]);
|
||||
|
||||
const publicKey = useMemo(
|
||||
() => contactsPrivateKey && getPublicKey(contactsPrivateKey),
|
||||
@@ -43,33 +44,33 @@ export const GlobalContactsList = ({children}) => {
|
||||
});
|
||||
};
|
||||
|
||||
async function updateGlobalContactsList(fromPage) {
|
||||
let users = await queryContacts('blitzWalletUsers');
|
||||
// async function updateGlobalContactsList(fromPage) {
|
||||
// let users = await queryContacts('blitzWalletUsers');
|
||||
|
||||
if (users?.length === 0) return;
|
||||
users = users
|
||||
.map(doc => {
|
||||
try {
|
||||
const {
|
||||
contacts: {myProfile},
|
||||
} = doc;
|
||||
const returnObject = {
|
||||
name: myProfile.name,
|
||||
uuid: myProfile.uuid,
|
||||
uniqueName: myProfile.uniqueName,
|
||||
receiveAddress: myProfile.receiveAddress,
|
||||
};
|
||||
return returnObject;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.filter(contact => contact);
|
||||
// if (users?.length === 0) return;
|
||||
// users = users
|
||||
// .map(doc => {
|
||||
// try {
|
||||
// const {
|
||||
// contacts: {myProfile},
|
||||
// } = doc;
|
||||
// const returnObject = {
|
||||
// name: myProfile.name,
|
||||
// uuid: myProfile.uuid,
|
||||
// uniqueName: myProfile.uniqueName,
|
||||
// receiveAddress: myProfile.receiveAddress,
|
||||
// };
|
||||
// return returnObject;
|
||||
// } catch (err) {
|
||||
// return false;
|
||||
// }
|
||||
// })
|
||||
// .filter(contact => contact);
|
||||
|
||||
if (fromPage === 'loadingScreen') {
|
||||
setGlobalContactsList(users);
|
||||
} else return users;
|
||||
}
|
||||
// if (fromPage === 'loadingScreen') {
|
||||
// setGlobalContactsList(users);
|
||||
// } else return users;
|
||||
// }
|
||||
|
||||
const decodedAddedContacts = useMemo(() => {
|
||||
if (!publicKey || !addedContacts) return [];
|
||||
@@ -83,38 +84,43 @@ export const GlobalContactsList = ({children}) => {
|
||||
}, [addedContacts]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!didGetToHomepage) return;
|
||||
(async () => {
|
||||
const savedContactsList = JSON.parse(
|
||||
await getLocalStorageItem('savedContactsList'),
|
||||
);
|
||||
//here to remvoe cahcd contacts from legacy apps
|
||||
removeLocalStorageItem('savedContactsList');
|
||||
}, []);
|
||||
|
||||
if (
|
||||
!savedContactsList ||
|
||||
isMoreThan21Days(savedContactsList?.lastUpdated) ||
|
||||
savedContactsList?.cachedContacts.length === 0
|
||||
) {
|
||||
console.log('DID RUN DB SEARCH');
|
||||
const contactsList = await updateGlobalContactsList();
|
||||
// useEffect(() => {
|
||||
// if (!didGetToHomepage) return;
|
||||
// (async () => {
|
||||
// const savedContactsList = JSON.parse(
|
||||
// await getLocalStorageItem('savedContactsList'),
|
||||
// );
|
||||
|
||||
setLocalStorageItem(
|
||||
'savedContactsList',
|
||||
JSON.stringify({
|
||||
cachedContacts: contactsList,
|
||||
lastUpdated: new Date(),
|
||||
}),
|
||||
);
|
||||
setGlobalContactsList(contactsList);
|
||||
} else {
|
||||
console.log(savedContactsList);
|
||||
setGlobalContactsList(savedContactsList.cachedContacts);
|
||||
}
|
||||
})();
|
||||
// setTimeout(() => {
|
||||
// updateGlobalContactsList();
|
||||
// }, 1000 * 60 * 5);
|
||||
// updateGlobalContactsList();
|
||||
}, [didGetToHomepage]);
|
||||
// if (
|
||||
// !savedContactsList ||
|
||||
// isMoreThan21Days(savedContactsList?.lastUpdated) ||
|
||||
// savedContactsList?.cachedContacts.length === 0
|
||||
// ) {
|
||||
// console.log('DID RUN DB SEARCH');
|
||||
// const contactsList = await updateGlobalContactsList();
|
||||
|
||||
// setLocalStorageItem(
|
||||
// 'savedContactsList',
|
||||
// JSON.stringify({
|
||||
// cachedContacts: contactsList,
|
||||
// lastUpdated: new Date(),
|
||||
// }),
|
||||
// );
|
||||
// setGlobalContactsList(contactsList);
|
||||
// } else {
|
||||
// console.log(savedContactsList);
|
||||
// setGlobalContactsList(savedContactsList.cachedContacts);
|
||||
// }
|
||||
// })();
|
||||
// // setTimeout(() => {
|
||||
// // updateGlobalContactsList();
|
||||
// // }, 1000 * 60 * 5);
|
||||
// // updateGlobalContactsList();
|
||||
// }, [didGetToHomepage]);
|
||||
|
||||
useListenForMessages({
|
||||
didGetToHomepage,
|
||||
@@ -128,9 +134,9 @@ export const GlobalContactsList = ({children}) => {
|
||||
return (
|
||||
<GlobalContacts.Provider
|
||||
value={{
|
||||
globalContactsList,
|
||||
// globalContactsList,
|
||||
decodedAddedContacts,
|
||||
updateGlobalContactsList,
|
||||
// updateGlobalContactsList,
|
||||
globalContactsInformation,
|
||||
toggleGlobalContactsInformation,
|
||||
}}>
|
||||
|
||||
Reference in New Issue
Block a user