From eb590dac914034fc68004a56d7e3942f2a1c00fb Mon Sep 17 00:00:00 2001 From: shubham Date: Wed, 24 Jul 2024 14:33:29 +0530 Subject: [PATCH 1/5] Link remote pubkey from Channel view to the stored contacts --- views/Channels/Channel.tsx | 59 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index 0a3f93431..4f998656b 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -41,6 +41,7 @@ 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; @@ -56,6 +57,7 @@ interface ChannelState { forceCloseChannel: boolean; deliveryAddress: string; channel: Channel; + contacts: any; } @inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore') @@ -75,7 +77,8 @@ export default class ChannelView extends React.Component< satPerByte: '', forceCloseChannel: false, deliveryAddress: '', - channel + channel, + contacts: [] }; if (BackendUtils.isLNDBased() && channel.channelId != null) { @@ -83,6 +86,57 @@ export default class ChannelView extends React.Component< } } + componentDidMount() { + this.loadContacts(); + } + + loadContacts = async () => { + 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 ( + { + this.props.navigation.navigate('ContactDetails', { + contactId: contact.contactId || contact.id, + isNostrContact: false + }); + }} + > + + {contact.name} + + + ); + } + return null; + }; + closeChannel = async ( channelPoint?: string, channelId?: string, @@ -295,6 +349,7 @@ export default class ChannelView extends React.Component< )} + {remotePubkey && this.renderContactLink(remotePubkey)} Date: Fri, 26 Jul 2024 17:37:34 +0530 Subject: [PATCH 2/5] Highlight matching contact --- locales/en.json | 1 + views/Channels/Channel.tsx | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/locales/en.json b/locales/en.json index 937532424..0fa9936a1 100644 --- a/locales/en.json +++ b/locales/en.json @@ -432,6 +432,7 @@ "views.Channel.Total.offline": "Total offline", "views.Channel.zeroConf": "Zero conf", "views.Channel.commitmentType": "Commitment Type", + "views.Channel.matchingContactFound": "Matching Contact Found", "views.UTXOs.CoinControl.noUTXOs": "No UTXOs available", "views.EditFee.mainText": "Edit network fee", "views.EditFee.fastestFee": "Fastest fee", diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index 4f998656b..efbfe7694 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -116,6 +116,10 @@ export default class ChannelView extends React.Component< if (contact) { return ( { this.props.navigation.navigate('ContactDetails', { contactId: contact.contactId || contact.id, @@ -123,14 +127,22 @@ export default class ChannelView extends React.Component< }); }} > - - {contact.name} + + {`${localeString( + 'views.Channel.matchingContactFound' + )} - `} + + + {contact.name} + + ); } @@ -831,5 +843,14 @@ const styles = StyleSheet.create({ button: { paddingTop: 15, paddingBottom: 15 + }, + container: { + marginTop: 8, + paddingHorizontal: 32, + paddingVertical: 16, + borderRadius: 6, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center' } }); From 7aeefc41fde9b64814af378c621a3996ba3892e5 Mon Sep 17 00:00:00 2001 From: shubham Date: Mon, 29 Jul 2024 14:42:07 +0530 Subject: [PATCH 3/5] Update layout to display contact info --- views/Channels/Channel.tsx | 43 +++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index efbfe7694..7645e0b1d 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -5,7 +5,8 @@ import { ScrollView, StyleSheet, TouchableOpacity, - View + View, + Image } from 'react-native'; import { Divider, Icon, ListItem } from 'react-native-elements'; @@ -34,6 +35,7 @@ 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'; @@ -127,22 +129,23 @@ export default class ChannelView extends React.Component< }); }} > - - {`${localeString( - 'views.Channel.matchingContactFound' - )} - `} - - + {contact.photo && ( + + )} + {contact.name} - + ); } @@ -361,6 +364,16 @@ export default class ChannelView extends React.Component< )} + + {`${localeString( + 'views.Channel.matchingContactFound' + )}`} + {remotePubkey && this.renderContactLink(remotePubkey)} Date: Wed, 28 Aug 2024 09:42:08 +0800 Subject: [PATCH 4/5] Removing the 'matching contact found' label --- locales/en.json | 1 - views/Channels/Channel.tsx | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/locales/en.json b/locales/en.json index 0fa9936a1..937532424 100644 --- a/locales/en.json +++ b/locales/en.json @@ -432,7 +432,6 @@ "views.Channel.Total.offline": "Total offline", "views.Channel.zeroConf": "Zero conf", "views.Channel.commitmentType": "Commitment Type", - "views.Channel.matchingContactFound": "Matching Contact Found", "views.UTXOs.CoinControl.noUTXOs": "No UTXOs available", "views.EditFee.mainText": "Edit network fee", "views.EditFee.fastestFee": "Fastest fee", diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index 7645e0b1d..db568106e 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -364,16 +364,6 @@ export default class ChannelView extends React.Component< )} - - {`${localeString( - 'views.Channel.matchingContactFound' - )}`} - {remotePubkey && this.renderContactLink(remotePubkey)} Date: Thu, 29 Aug 2024 23:24:05 +0800 Subject: [PATCH 5/5] Refactor to use ContactStore for getting contacts --- views/Channels/Channel.tsx | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index db568106e..104d01717 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -40,16 +40,17 @@ import { getPhoto } from '../../utils/PhotoUtils'; import ChannelsStore from '../../stores/ChannelsStore'; import SettingsStore from '../../stores/SettingsStore'; import NodeInfoStore from '../../stores/NodeInfoStore'; +import ContactStore from '../../stores/ContactStore'; 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; ChannelsStore: ChannelsStore; SettingsStore: SettingsStore; NodeInfoStore: NodeInfoStore; + ContactStore: ContactStore; route: Route<'Channel', { channel: Channel }>; } @@ -59,10 +60,9 @@ interface ChannelState { forceCloseChannel: boolean; deliveryAddress: string; channel: Channel; - contacts: any; } -@inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore') +@inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore', 'ContactStore') @observer export default class ChannelView extends React.Component< ChannelProps, @@ -79,8 +79,7 @@ export default class ChannelView extends React.Component< satPerByte: '', forceCloseChannel: false, deliveryAddress: '', - channel, - contacts: [] + channel }; if (BackendUtils.isLNDBased() && channel.channelId != null) { @@ -88,28 +87,9 @@ export default class ChannelView extends React.Component< } } - componentDidMount() { - this.loadContacts(); - } - - loadContacts = async () => { - 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; + const { ContactStore } = this.props; + const { contacts } = ContactStore; return contacts.find((contact) => contact.pubkey.includes(pubkey)); };