Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link Channel to the stored contacts #2299

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 87 additions & 3 deletions views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ScrollView,
StyleSheet,
TouchableOpacity,
View
View,
Image
} from 'react-native';

import { Divider, Icon, ListItem } from 'react-native-elements';
Expand Down Expand Up @@ -34,13 +35,15 @@ import BackendUtils from '../../utils/BackendUtils';
import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';
import UrlUtils from '../../utils/UrlUtils';
import { getPhoto } from '../../utils/PhotoUtils';

import ChannelsStore from '../../stores/ChannelsStore';
import SettingsStore from '../../stores/SettingsStore';
import NodeInfoStore from '../../stores/NodeInfoStore';

import Edit from '../../assets/images/SVG/Edit.svg';
import HourglassIcon from '../../assets/images/SVG/Hourglass.svg';
import EncryptedStorage from 'react-native-encrypted-storage';

interface ChannelProps {
navigation: StackNavigationProp<any, any>;
Expand All @@ -56,6 +59,7 @@ interface ChannelState {
forceCloseChannel: boolean;
deliveryAddress: string;
channel: Channel;
contacts: any;
}

@inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore')
Expand All @@ -75,14 +79,79 @@ export default class ChannelView extends React.Component<
satPerByte: '',
forceCloseChannel: false,
deliveryAddress: '',
channel
channel,
contacts: []
};

if (BackendUtils.isLNDBased() && channel.channelId != null) {
ChannelsStore.loadChannelInfo(channel.channelId);
}
}

componentDidMount() {
this.loadContacts();
}

loadContacts = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase and refactor to use the newly added ContactStore

console.log('LOADING CONTACTS...');
try {
const contactsString = await EncryptedStorage.getItem(
'zeus-contacts'
);
if (contactsString) {
const contacts = JSON.parse(contactsString);
this.setState({ contacts });
} else {
}
} catch (error) {
console.log('Error loading contacts:', error);
}
};

findContactByPubkey = (pubkey: string) => {
const { contacts } = this.state;
return contacts.find((contact) => contact.pubkey.includes(pubkey));
};

renderContactLink = (remotePubkey: string) => {
const contact = this.findContactByPubkey(remotePubkey);
if (contact) {
return (
<TouchableOpacity
style={{
...styles.container,
backgroundColor: themeColor('secondary')
}}
onPress={() => {
this.props.navigation.navigate('ContactDetails', {
contactId: contact.contactId || contact.id,
isNostrContact: false
});
}}
>
{contact.photo && (
<Image
source={{ uri: getPhoto(contact.photo) }}
style={styles.image}
/>
)}
<View>
<Text
style={{
fontSize: 18,
color: themeColor('highlight'),
fontFamily: 'PPNeueMontreal-Book'
}}
>
{contact.name}
</Text>
</View>
</TouchableOpacity>
);
}
return null;
};

closeChannel = async (
channelPoint?: string,
channelId?: string,
Expand Down Expand Up @@ -295,6 +364,7 @@ export default class ChannelView extends React.Component<
</Text>
</TouchableOpacity>
)}
{remotePubkey && this.renderContactLink(remotePubkey)}
</View>
<BalanceSlider
localBalance={lurkerMode ? 50 : localBalance}
Expand Down Expand Up @@ -770,11 +840,25 @@ const styles = StyleSheet.create({
paddingBottom: 10
},
pubkey: {
paddingBottom: 30,
paddingBottom: 24,
textAlign: 'center'
},
button: {
paddingTop: 15,
paddingBottom: 15
},
container: {
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 6,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
image: {
width: 50,
height: 50,
borderRadius: 25,
marginRight: 14
}
});
Loading