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
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

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

we're no longer using this locale now

"views.UTXOs.CoinControl.noUTXOs": "No UTXOs available",
"views.EditFee.mainText": "Edit network fee",
"views.EditFee.fastestFee": "Fastest fee",
Expand Down
101 changes: 98 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,17 @@ export default class ChannelView extends React.Component<
</Text>
</TouchableOpacity>
)}
<Text
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like the display component here but i don't think we need the label. Let's remove Matching Contact Found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

style={{
fontSize: 16,
marginBottom: 8
}}
>
{`${localeString(
'views.Channel.matchingContactFound'
)}`}
</Text>
{remotePubkey && this.renderContactLink(remotePubkey)}
</View>
<BalanceSlider
localBalance={lurkerMode ? 50 : localBalance}
Expand Down Expand Up @@ -770,11 +850,26 @@ const styles = StyleSheet.create({
paddingBottom: 10
},
pubkey: {
paddingBottom: 30,
paddingBottom: 24,
textAlign: 'center'
},
button: {
paddingTop: 15,
paddingBottom: 15
},
container: {
marginTop: 8,
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 6,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
image: {
width: 50,
height: 50,
borderRadius: 25,
marginRight: 14
}
});
Loading