Skip to content

Commit

Permalink
Merge pull request #1668 from shubhamkmr04/shubham/Contact_Fixes
Browse files Browse the repository at this point in the history
Contacts: Fixes
  • Loading branch information
kaloudis authored Sep 20, 2023
2 parents 2de6ebc + 85d8911 commit 1f9dd1d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 94 deletions.
5 changes: 3 additions & 2 deletions views/ContactDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default class ContactDetails extends React.Component<
}}
color={themeColor('text')}
underlayColor="transparent"
size={35}
/>
);
const StarButton = () => (
Expand All @@ -171,7 +172,7 @@ export default class ContactDetails extends React.Component<
onPress={this.toggleFavorite}
color={themeColor('text')}
underlayColor="transparent"
size={28}
size={32}
/>
);
const EditContactButton = () => (
Expand All @@ -183,7 +184,7 @@ export default class ContactDetails extends React.Component<
})
}
>
<EditContact height={36} width={36} />
<EditContact height={40} width={40} />
</TouchableOpacity>
);
return (
Expand Down
84 changes: 45 additions & 39 deletions views/Settings/AddContact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ interface AddContactProps {
}

interface Contact {
lnAddress: string;
onchainAddress: string;
nip05: string;
nostrNpub: string;
pubkey: string;
lnAddress: string[];
onchainAddress: string[];
nip05: string[];
nostrNpub: string[];
pubkey: string[];
name: string;
description: string;
id: string;
Expand Down Expand Up @@ -327,18 +327,17 @@ export default class AddContact extends React.Component<
}}
color={themeColor('text')}
underlayColor="transparent"
size={35}
/>
);

const AddPhotos = () => (
<TouchableOpacity onPress={this.selectPhoto}>
<AddIcon
fill={themeColor('background')}
width="20"
height="20"
style={{ alignSelf: 'center' }}
/>
</TouchableOpacity>
<AddIcon
fill={themeColor('background')}
width="20"
height="20"
style={{ alignSelf: 'center' }}
/>
);

const StarButton = ({ isFavourite, onPress }) => (
Expand All @@ -347,6 +346,7 @@ export default class AddContact extends React.Component<
onPress={onPress}
color={themeColor('text')}
underlayColor="transparent"
size={35}
/>
);

Expand Down Expand Up @@ -383,30 +383,30 @@ export default class AddContact extends React.Component<
alignItems: 'center'
}}
>
<View
style={{
backgroundColor:
themeColor('secondaryText'),
marginTop: 40,
width: 136,
height: 136,
borderRadius: 68,
justifyContent: 'center'
}}
>
{this.state.photo ? (
<TouchableOpacity
onPress={this.selectPhoto}
>
<TouchableOpacity onPress={this.selectPhoto}>
<View
style={{
backgroundColor:
themeColor('secondaryText'),
marginTop: 40,
width: 136,
height: 136,
borderRadius: 68,
justifyContent: 'center'
}}
>
{this.state.photo ? (
<Image
source={{ uri: this.state.photo }}
source={{
uri: this.state.photo
}}
style={styles.photo}
/>
</TouchableOpacity>
) : (
<AddPhotos />
)}
</View>
) : (
<AddPhotos />
)}
</View>
</TouchableOpacity>
</View>

<View
Expand Down Expand Up @@ -1066,17 +1066,23 @@ export default class AddContact extends React.Component<
!isValidNIP05 ||
!isValidNpub ||
!isValidPubkey ||
(lnAddress.length > 1 &&
(lnAddress?.length > 1 &&
lnAddress[lnAddress.length - 1] === '') ||
(onchainAddress.length > 1 &&
(pubkey?.length > 1 &&
pubkey[pubkey.length - 1] === '') ||
(onchainAddress?.length > 1 &&
onchainAddress[
onchainAddress.length - 1
]) === '' ||
(nip05.length > 1 &&
(nip05?.length > 1 &&
nip05[nip05.length - 1] === '') ||
(nostrNpub.length > 1 &&
(nostrNpub?.length > 1 &&
nostrNpub[nostrNpub.length - 1] === '') ||
!(lnAddress[0] || onchainAddress[0])
!(
lnAddress[0] ||
onchainAddress[0] ||
pubkey[0]
)
}
/>
</View>
Expand Down
137 changes: 84 additions & 53 deletions views/Settings/Contacts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Text, View, TouchableOpacity, FlatList, Image } from 'react-native';
import { Header, Icon, SearchBar, Chip, Divider } from 'react-native-elements';
import { Header, Icon, SearchBar, Divider } from 'react-native-elements';
import AddIcon from '../../assets/images/SVG/Add.svg';
import EncryptedStorage from 'react-native-encrypted-storage';

Expand Down Expand Up @@ -74,14 +74,85 @@ export default class Contacts extends React.Component<
}
});
};
displayAddress = (item) => {
const hasLnAddress =
item.lnAddress &&
item.lnAddress.length === 1 &&
item.lnAddress[0] !== '';
const hasOnchainAddress =
item.onchainAddress &&
item.onchainAddress.length === 1 &&
item.onchainAddress[0] !== '';
const hasPubkey =
item.pubkey && item.pubkey.length === 1 && item.pubkey[0] !== '';

if (hasLnAddress + hasOnchainAddress + hasPubkey >= 2) {
return localeString('views.Settings.Contacts.multipleAddresses');
}

if (hasLnAddress) {
return item.lnAddress[0].length > 15
? `${item.lnAddress[0].slice(0, 4)}...${item.lnAddress[0].slice(
-4
)}`
: item.lnAddress[0];
}

if (hasOnchainAddress) {
return item.onchainAddress[0].length > 15
? `${item.onchainAddress[0].slice(
0,
4
)}...${item.onchainAddress[0].slice(-4)}`
: item.onchainAddress[0];
}

if (hasPubkey) {
return item.pubkey[0].length > 15
? `${item.pubkey[0].slice(0, 4)}...${item.pubkey[0].slice(-4)}`
: item.pubkey[0];
}

return localeString('views.Settings.Contacts.multipleAddresses');
};

renderContactItem = ({ item }: { item: ContactItem }) => (
<TouchableOpacity
onPress={() =>
this.props.navigation.navigate('ContactDetails', {
contactId: item.id
})
}
onPress={() => {
(item.lnAddress &&
item.lnAddress.length === 1 &&
item.lnAddress[0] !== '' &&
item.onchainAddress[0] === '' &&
item.pubkey[0] === '' &&
this.state.SendScreen &&
this.props.navigation.navigate('Send', {
destination: item.lnAddress[0],
contactName: item.name
})) ||
(item.onchainAddress &&
item.onchainAddress.length === 1 &&
item.onchainAddress[0] !== '' &&
item.lnAddress[0] === '' &&
item.pubkey[0] === '' &&
this.state.SendScreen &&
this.props.navigation.navigate('Send', {
destination: item.onchainAddress[0],
contactName: item.name
})) ||
(item.pubkey &&
item.pubkey.length === 1 &&
item.pubkey[0] !== '' &&
item.lnAddress[0] === '' &&
item.onchainAddress[0] === '' &&
this.state.SendScreen &&
this.props.navigation.navigate('Send', {
destination: item.pubkey[0],
contactName: item.name
})) ||
this.props.navigation.navigate('ContactDetails', {
contactId: item.id
});
}}
>
<View
style={{
Expand Down Expand Up @@ -112,33 +183,7 @@ export default class Contacts extends React.Component<
color: themeColor('secondaryText')
}}
>
{item.lnAddress &&
item.lnAddress.length === 1 &&
item.lnAddress[0] !== '' &&
item.onchainAddress[0] === ''
? item.lnAddress[0].length > 15
? `${item.lnAddress[0].slice(
0,
4
)}...${item.lnAddress[0].slice(-4)}`
: item.lnAddress[0]
: item.lnAddress.length > 1
? `${localeString(
'views.Settings.Contacts.multipleAddresses'
)}`
: item.onchainAddress &&
item.onchainAddress.length === 1 &&
item.onchainAddress[0] !== '' &&
item.lnAddress[0] === ''
? item.onchainAddress[0].length > 15
? `${item.onchainAddress[0].slice(
0,
4
)}...${item.onchainAddress[0].slice(-4)}`
: item.onchainAddress[0]
: `${localeString(
'views.Settings.Contacts.multipleAddresses'
)}`}
{this.displayAddress(item)}
</Text>
</View>
</View>
Expand Down Expand Up @@ -181,14 +226,15 @@ export default class Contacts extends React.Component<
}}
color={themeColor('text')}
underlayColor="transparent"
size={35}
/>
);
const Add = ({ navigation }: { navigation: any }) => (
<TouchableOpacity onPress={() => navigation.navigate('AddContact')}>
<View
style={{
width: 30,
height: 30,
width: 35,
height: 35,
borderRadius: 25,
backgroundColor: themeColor('chain'),
justifyContent: 'center',
Expand All @@ -197,24 +243,13 @@ export default class Contacts extends React.Component<
>
<AddIcon
fill={themeColor('background')}
width={12}
height={12}
width={16}
height={16}
style={{ alignSelf: 'center' }}
/>
</View>
</TouchableOpacity>
);
const PayButton = ({ navigation }: { navigation: any }) => (
<Chip
title="Pay"
titleStyle={{ color: 'black', fontSize: 16 }}
buttonStyle={{
backgroundColor: themeColor('chain'),
minWidth: 70
}}
onPress={() => navigation.navigate('AddContact')}
/>
);

const favoriteContacts = filteredContacts.filter(
(contact) => contact.isFavourite
Expand All @@ -237,11 +272,7 @@ export default class Contacts extends React.Component<
borderBottomWidth: 0
}}
rightComponent={
SendScreen ? (
<PayButton navigation={navigation} />
) : (
<Add navigation={navigation} />
)
!SendScreen && <Add navigation={navigation} />
}
/>
<View>
Expand Down

0 comments on commit 1f9dd1d

Please sign in to comment.