Skip to content

Commit

Permalink
Refactor to use ContactStore for getting contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Aug 29, 2024
1 parent 37ba0ba commit e82d2c0
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>;
ChannelsStore: ChannelsStore;
SettingsStore: SettingsStore;
NodeInfoStore: NodeInfoStore;
ContactStore: ContactStore;
route: Route<'Channel', { channel: Channel }>;
}

Expand All @@ -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,
Expand All @@ -79,37 +79,17 @@ export default class ChannelView extends React.Component<
satPerByte: '',
forceCloseChannel: false,
deliveryAddress: '',
channel,
contacts: []
channel
};

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

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));
};

Expand Down

0 comments on commit e82d2c0

Please sign in to comment.