Skip to content

Commit

Permalink
Merge pull request #2376 from shubhamkmr04/shubham/contactstore-on-se…
Browse files Browse the repository at this point in the history
…nd-view

Send: Using ContactStore to fetch contacts
  • Loading branch information
kaloudis authored Aug 30, 2024
2 parents 493eab0 + 5708ce8 commit 6ec8818
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions views/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
NativeEventSubscription
} from 'react-native';
import { Chip, Icon } from 'react-native-elements';
import EncryptedStorage from 'react-native-encrypted-storage';
import Clipboard from '@react-native-clipboard/clipboard';
import { inject, observer } from 'mobx-react';
import NfcManager, {
Expand All @@ -34,6 +33,7 @@ import NodeInfoStore from '../stores/NodeInfoStore';
import SettingsStore from '../stores/SettingsStore';
import TransactionsStore from '../stores/TransactionsStore';
import UTXOsStore from '../stores/UTXOsStore';
import ContactStore from '../stores/ContactStore';

import Amount from '../components/Amount';
import AmountInput from '../components/AmountInput';
Expand Down Expand Up @@ -75,6 +75,7 @@ interface SendProps {
TransactionsStore: TransactionsStore;
SettingsStore: SettingsStore;
UTXOsStore: UTXOsStore;
ContactStore: ContactStore;
route: Route<
'Send',
{
Expand Down Expand Up @@ -110,7 +111,6 @@ interface SendState {
clipboard: string;
loading: boolean;
contactName: string;
contacts: Contact[];
clearOnBackPress: boolean;
account: string;
additionalOutputs: Array<AdditionalOutput>;
Expand All @@ -123,7 +123,8 @@ interface SendState {
'TransactionsStore',
'BalanceStore',
'SettingsStore',
'UTXOsStore'
'UTXOsStore',
'ContactStore'
)
@observer
export default class Send extends React.Component<SendProps, SendState> {
Expand Down Expand Up @@ -168,7 +169,6 @@ export default class Send extends React.Component<SendProps, SendState> {
clipboard: '',
loading: false,
contactName,
contacts: [],
clearOnBackPress,
account: 'default',
additionalOutputs: []
Expand Down Expand Up @@ -221,8 +221,6 @@ export default class Send extends React.Component<SendProps, SendState> {
this.validateAddress(this.state.destination);
}

this.loadContacts();

this.backPressSubscription = BackHandler.addEventListener(
'hardwareBackPress',
this.backPressed.bind(this)
Expand All @@ -233,25 +231,6 @@ export default class Send extends React.Component<SendProps, SendState> {
this.backPressSubscription?.remove();
}

loadContacts = async () => {
this.props.navigation.addListener('focus', async () => {
try {
const contactsString = await EncryptedStorage.getItem(
'zeus-contacts'
);
if (contactsString) {
const contacts: Contact[] = JSON.parse(contactsString);
this.setState({ contacts, loading: false });
} else {
this.setState({ loading: false });
}
} catch (error) {
console.error('Error loading contacts:', error);
this.setState({ loading: false });
}
});
};

subscribePayment = (streamingCall: string) => {
const { handlePayment, handlePaymentError } =
this.props.TransactionsStore;
Expand Down Expand Up @@ -667,8 +646,13 @@ export default class Send extends React.Component<SendProps, SendState> {
};

render() {
const { SettingsStore, BalanceStore, UTXOsStore, navigation } =
this.props;
const {
SettingsStore,
BalanceStore,
UTXOsStore,
ContactStore,
navigation
} = this.props;
const {
isValid,
transactionType,
Expand All @@ -686,7 +670,6 @@ export default class Send extends React.Component<SendProps, SendState> {
clipboard,
loading,
contactName,
contacts,
additionalOutputs
} = this.state;
const {
Expand All @@ -695,6 +678,7 @@ export default class Send extends React.Component<SendProps, SendState> {
lightningBalance
} = BalanceStore;
const { implementation } = SettingsStore;
const { contacts } = ContactStore;

const paymentOptions = [localeString('views.Send.lnPayment')];

Expand Down

0 comments on commit 6ec8818

Please sign in to comment.