diff --git a/stores/SettingsStore.ts b/stores/SettingsStore.ts index a178bfc24..c8197977e 100644 --- a/stores/SettingsStore.ts +++ b/stores/SettingsStore.ts @@ -10,7 +10,7 @@ import { doTorRequest, RequestMethod } from '../utils/TorUtils'; // lndhub import LoginRequest from './../models/LoginRequest'; -interface Node { +export interface Node { host?: string; port?: string; url?: string; @@ -20,11 +20,11 @@ interface Node { certVerification?: boolean; enableTor?: boolean; nickname?: string; + photo?: string; // LNC pairingPhrase?: string; mailboxServer?: string; customMailboxServer?: string; - photo?: string; } interface PrivacySettings { diff --git a/utils/PhotoUtils.ts b/utils/PhotoUtils.ts index 17c6391d1..f1f93a91f 100644 --- a/utils/PhotoUtils.ts +++ b/utils/PhotoUtils.ts @@ -21,7 +21,7 @@ const BTCpay = require('..//assets/images/BTCpay.jpg'); const CLN = require('..//assets/images/CLN.jpg'); const LND = require('..//assets/images/LND.jpg'); -const getPhoto = (photo: string | null): string => { +const getPhoto = (photo: string | undefined): string => { if (typeof photo === 'string' && photo.includes('rnfs://')) { const fileName = photo.replace('rnfs://', ''); return `file://${RNFS.DocumentDirectoryPath}/${fileName}`; diff --git a/views/Accounts/ImportingAccount.tsx b/views/Accounts/ImportingAccount.tsx index e8fb656d3..c1af34f1f 100644 --- a/views/Accounts/ImportingAccount.tsx +++ b/views/Accounts/ImportingAccount.tsx @@ -161,7 +161,7 @@ export default class ImportingAccount extends React.Component< master_key_fingerprint, address_type, dry_run: false - }).then(() => navigation.navigate('Wallet')) + }).then(() => navigation.popTo('Wallet')) } /> diff --git a/views/Channels/Channel.tsx b/views/Channels/Channel.tsx index 9630a3193..37865c21d 100644 --- a/views/Channels/Channel.tsx +++ b/views/Channels/Channel.tsx @@ -110,7 +110,7 @@ export default class ChannelView extends React.Component< if (implementation === 'lightning-node-connect') { this.subscribeChannelClose(streamingCall); } else { - if (!ChannelsStore.closeChannelErr) navigation.navigate('Wallet'); + if (!ChannelsStore.closeChannelErr) navigation.popTo('Wallet'); } }; @@ -145,7 +145,7 @@ export default class ChannelView extends React.Component< ) { handleChannelClose(); this.listener = null; - this.props.navigation.navigate('Wallet'); + this.props.navigation.popTo('Wallet'); } else { handleChannelCloseError(new Error(result)); this.listener = null; diff --git a/views/ContactDetails.tsx b/views/ContactDetails.tsx index 7823b2c22..8b6d17730 100644 --- a/views/ContactDetails.tsx +++ b/views/ContactDetails.tsx @@ -176,7 +176,7 @@ export default class ContactDetails extends React.Component< ); console.log('Contact imported successfully!'); - this.props.navigation.navigate('Contacts', { loading: true }); + this.props.navigation.popTo('Contacts'); }; toggleFavorite = () => { diff --git a/views/NostrContacts.tsx b/views/NostrContacts.tsx index bdc712c7b..961393068 100644 --- a/views/NostrContacts.tsx +++ b/views/NostrContacts.tsx @@ -610,9 +610,7 @@ export default class NostrContacts extends React.Component< )} onPress={async () => { await this.importContacts(); - navigation.navigate('Contacts', { - loading: true - }); + navigation.popTo('Contacts'); }} containerStyle={{ paddingBottom: 12, @@ -632,7 +630,7 @@ export default class NostrContacts extends React.Component< }`} onPress={async () => { await this.importContacts(); - navigation.navigate('Contacts', { loading: true }); + navigation.popTo('Contacts'); }} containerStyle={{ paddingBottom: 12, paddingTop: 8 }} secondary diff --git a/views/PSBT.tsx b/views/PSBT.tsx index c1e8cb7f0..c75e4310f 100644 --- a/views/PSBT.tsx +++ b/views/PSBT.tsx @@ -224,9 +224,8 @@ export default class PSBT extends React.Component {
{ - navigation.navigate('Wallet'); - }} + onBack={() => navigation.popTo('Wallet')} + navigateBackOnBackPress={false} centerComponent={{ text: 'PSBT', style: { color: themeColor('text') } diff --git a/views/Receive.tsx b/views/Receive.tsx index e83806a0f..f8094175b 100644 --- a/views/Receive.tsx +++ b/views/Receive.tsx @@ -1468,7 +1468,7 @@ export default class Receive extends React.Component< name: 'list', size: 25 }} - onPress={() => navigation.navigate('Wallet')} + onPress={() => navigation.popTo('Wallet')} containerStyle={{ width: '100%' }} /> diff --git a/views/SendingLightning.tsx b/views/SendingLightning.tsx index 54adc97f3..2a234078a 100644 --- a/views/SendingLightning.tsx +++ b/views/SendingLightning.tsx @@ -79,7 +79,7 @@ export default class SendingLightning extends React.Component< (this.successfullySent(TransactionsStore) || this.inTransit(TransactionsStore)) ) { - navigation.navigate('Wallet'); + navigation.popTo('Wallet'); return true; } return false; @@ -447,7 +447,7 @@ export default class SendingLightning extends React.Component< color: themeColor('background') }} onPress={() => - navigation.navigate('Wallet', { + navigation.popTo('Wallet', { refresh: true }) } diff --git a/views/SendingOnChain.tsx b/views/SendingOnChain.tsx index 203e5ae96..8ce9ef906 100644 --- a/views/SendingOnChain.tsx +++ b/views/SendingOnChain.tsx @@ -261,9 +261,7 @@ export default class SendingOnChain extends React.Component< color: themeColor('background') }} containerStyle={{ width: '100%' }} - onPress={() => - navigation.navigate('Wallet') - } + onPress={() => navigation.popTo('Wallet')} buttonStyle={{ height: 40 }} /> )} diff --git a/views/Settings/AddContact.tsx b/views/Settings/AddContact.tsx index 448919edb..3acae4404 100644 --- a/views/Settings/AddContact.tsx +++ b/views/Settings/AddContact.tsx @@ -171,7 +171,7 @@ export default class AddContact extends React.Component< ); console.log('Contact updated successfully!'); - navigation.navigate('Contacts', { loading: true }); + navigation.popTo('Contacts'); } else { // Creating a new contact const contactId = uuidv4(); @@ -200,7 +200,7 @@ export default class AddContact extends React.Component< ); console.log('Contact saved successfully!'); - navigation.navigate('Contacts', { loading: true }); + navigation.popTo('Contacts'); // Reset the input fields after saving the contact this.setState({ @@ -243,7 +243,7 @@ export default class AddContact extends React.Component< ); console.log('Contact deleted successfully!'); - navigation.navigate('Contacts', { loading: true }); + navigation.popTo('Contacts'); } catch (error) { console.log('Error deleting contact:', error); } diff --git a/views/Settings/Contacts.tsx b/views/Settings/Contacts.tsx index a86bfd4be..83148ecc9 100644 --- a/views/Settings/Contacts.tsx +++ b/views/Settings/Contacts.tsx @@ -27,7 +27,7 @@ import NostrichIcon from '../../assets/images/SVG/Nostrich.svg'; interface ContactsSettingsProps { navigation: StackNavigationProp; - route: Route<'Contacts', { SendScreen: boolean; loading: boolean }>; + route: Route<'Contacts', { SendScreen: boolean }>; } interface ContactsSettingsState { @@ -58,16 +58,6 @@ export default class Contacts extends React.Component< this.props.navigation.addListener('focus', () => this.loadContacts()); } - UNSAFE_componentWillReceiveProps( - nextProps: Readonly - ): void { - const loading = nextProps.route.params?.loading; - - if (loading) { - this.setState({ loading }); - } - } - loadContacts = async () => { try { this.setState({ loading: true }); @@ -86,7 +76,7 @@ export default class Contacts extends React.Component< } }; - displayAddress = (item) => { + displayAddress = (item: Contact) => { const contact = new Contact(item); const { hasLnAddress, @@ -400,7 +390,7 @@ export default class Contacts extends React.Component< index.toString()} + keyExtractor={(_, index) => index.toString()} scrollEnabled={false} /> {!loading && contacts.length > 1 && ( diff --git a/views/Settings/EmbeddedNode/DisasterRecoveryAdvanced.tsx b/views/Settings/EmbeddedNode/DisasterRecoveryAdvanced.tsx index e1af4bd90..4e7e84544 100644 --- a/views/Settings/EmbeddedNode/DisasterRecoveryAdvanced.tsx +++ b/views/Settings/EmbeddedNode/DisasterRecoveryAdvanced.tsx @@ -113,7 +113,7 @@ export default class DisasterRecoveryAdvanced extends React.Component< await triggerRecovery( selected.backup ); - navigation.navigate('Wallet'); + navigation.popTo('Wallet'); } }} /> diff --git a/views/Settings/EmbeddedNode/RestoreChannelBackups.tsx b/views/Settings/EmbeddedNode/RestoreChannelBackups.tsx index 388d91204..fb0b82ab2 100644 --- a/views/Settings/EmbeddedNode/RestoreChannelBackups.tsx +++ b/views/Settings/EmbeddedNode/RestoreChannelBackups.tsx @@ -95,7 +95,7 @@ export default class RestoreChannelBackups extends React.Component< await restoreChannelBackups( channelBackupsBase64 ); - navigation.navigate('Wallet'); + navigation.popTo('Wallet'); } catch (e) { console.log('e', e); this.setState({ diff --git a/views/Settings/LightningAddress/NostrRelays.tsx b/views/Settings/LightningAddress/NostrRelays.tsx index 762af6561..bd731830f 100644 --- a/views/Settings/LightningAddress/NostrRelays.tsx +++ b/views/Settings/LightningAddress/NostrRelays.tsx @@ -94,10 +94,9 @@ export default class NostrRelays extends React.Component< { - navigation.navigate( - 'LightningAddress', - { relays } - ); + navigation.popTo('LightningAddress', { + relays + }); }} color={themeColor('text')} underlayColor="transparent" diff --git a/views/Settings/NodeConfiguration.tsx b/views/Settings/NodeConfiguration.tsx index 4ff61be36..4dda2a0b9 100644 --- a/views/Settings/NodeConfiguration.tsx +++ b/views/Settings/NodeConfiguration.tsx @@ -43,7 +43,8 @@ import SettingsStore, { INTERFACE_KEYS, LNC_MAILBOX_KEYS, EMBEDDED_NODE_NETWORK_KEYS, - Settings + Settings, + Node } from '../../stores/SettingsStore'; import Scan from '../../assets/images/SVG/Scan.svg'; @@ -58,21 +59,22 @@ interface NodeConfigurationProps { route: Route< 'NodeConfiguration', { - node: any; + node: Node; index: any; - active: any; - tor: any; - saved: any; - newEntry: any; - newPhoto: any; + active: boolean; + tor: boolean; + saved: boolean; + newEntry: boolean; + photo: string; } >; } interface NodeConfigurationState { + node: Node | null; nickname: string; // host: string; // lnd, c-lightning-REST - port: string | number; // lnd, c-lightning-REST + port: string; // lnd, c-lightning-REST macaroonHex: string; // lnd, c-lightning-REST url: string; // spark, eclair accessKey: string; // spark @@ -91,7 +93,7 @@ interface NodeConfigurationState { showCertModal: boolean; enableTor: boolean; interfaceKeys: Array; - photo: string | null; + photo?: string; // lnc pairingPhrase: string; mailboxServer: string; @@ -122,7 +124,8 @@ export default class NodeConfiguration extends React.Component< NodeConfigurationProps, NodeConfigurationState > { - state = { + state: NodeConfigurationState = { + node: null, nickname: '', host: '', port: '', @@ -143,7 +146,7 @@ export default class NodeConfiguration extends React.Component< username: '', password: '', accessKey: '', - photo: null, + photo: undefined, // lnc pairingPhrase: '', mailboxServer: 'mailbox.terminal.lightning.today:443', @@ -163,6 +166,8 @@ export default class NodeConfiguration extends React.Component< errorCreatingWallet: false }; + scrollViewRef = React.createRef(); + async UNSAFE_componentWillMount() { const { SettingsStore } = this.props; const { settings } = SettingsStore; @@ -284,11 +289,16 @@ export default class NodeConfiguration extends React.Component< this.initFromProps(nextProps); } - async initFromProps(props: any) { + async initFromProps(props: NodeConfigurationProps) { const { route } = props; - const { node, index, active, tor, saved, newEntry, newPhoto } = - route.params ?? {}; + const node = route.params.node ?? this.state.node; + const index = route.params.index ?? this.state.index; + const active = route.params.active ?? this.state.active; + const tor = route.params.tor ?? this.state.enableTor; + const saved = route.params.saved ?? this.state.saved; + const newEntry = route.params.newEntry ?? this.state.newEntry; + const newPhoto = route.params.photo ?? this.state.photo; if (node) { const { @@ -315,9 +325,10 @@ export default class NodeConfiguration extends React.Component< walletPassword, adminMacaroon, embeddedLndNetwork - } = node; + } = node as any; this.setState({ + node, nickname, host, port, @@ -335,7 +346,7 @@ export default class NodeConfiguration extends React.Component< saved, newEntry, enableTor: tor || enableTor, - photo: newPhoto ? newPhoto : photo || '', + photo: newPhoto || photo || '', // LNC pairingPhrase, mailboxServer, @@ -415,14 +426,14 @@ export default class NodeConfiguration extends React.Component< photo }; - let nodes: any; - let originalNode: any; + let nodes: Node[]; + let originalNode: Node; if (settings.nodes) { nodes = settings.nodes; if (index != null) { originalNode = nodes[index]; } - nodes[index !== null ? index : settings.nodes.length] = node; + nodes[index != null ? index : settings.nodes.length] = node; } else { nodes = [node]; } @@ -460,7 +471,7 @@ export default class NodeConfiguration extends React.Component< BackendUtils.disconnect(); } setConnectingStatus(true); - navigation.navigate('Wallet', { refresh: true }); + navigation.popTo('Wallet', { refresh: true }); } else { navigation.goBack(); } @@ -515,7 +526,7 @@ export default class NodeConfiguration extends React.Component< node, newEntry: true, saved: false, - index: Number(nodes.length) + index: nodes!.length }); }; @@ -539,7 +550,7 @@ export default class NodeConfiguration extends React.Component< if (newNodes.length === 0) { navigation.navigate('IntroSplash'); } else { - navigation.navigate('Nodes', { refresh: true }); + navigation.popTo('Nodes', { refresh: true }); } }); }; @@ -576,7 +587,7 @@ export default class NodeConfiguration extends React.Component< active: true }); - navigation.navigate('Wallet', { refresh: true }); + navigation.popTo('Wallet', { refresh: true }); }; createNewWallet = async (network: string = 'Mainnet') => { @@ -615,9 +626,9 @@ export default class NodeConfiguration extends React.Component< }; render() { - const { route, navigation, SettingsStore } = this.props; - const node = route.params?.node; + const { navigation, SettingsStore } = this.props; const { + node, nickname, host, port, @@ -741,7 +752,7 @@ export default class NodeConfiguration extends React.Component< style: { ...styles.text, color: themeColor('text') } }} rightComponent={ - implementation === 'eclair' ? null : ( + implementation === 'eclair' ? undefined : ( implementation === 'spark' @@ -890,7 +901,6 @@ export default class NodeConfiguration extends React.Component< showLndHubModal: false }) } - primary /> @@ -952,7 +962,6 @@ export default class NodeConfiguration extends React.Component< showCertModal: false }) } - primary /> @@ -962,7 +971,7 @@ export default class NodeConfiguration extends React.Component< @@ -989,14 +998,27 @@ export default class NodeConfiguration extends React.Component< 'SetNodePicture', { implementation } ) - : () => + : () => { + if (node) { + this.setState({ + node: { + ...node, + photo: undefined + } + }); + } this.setState( - { photo: null, saved: false }, - () => + { + photo: undefined, + saved: false + }, + () => { node ? (node.photo = '') - : null - ) + : null; + } + ); + } } > { this.setState({ loading: true }); - await this.props.SettingsStore.getSettings().then((settings: any) => { + await this.props.SettingsStore.getSettings().then((settings) => { this.setState({ loading: false, nodes: settings?.nodes || [], @@ -242,7 +242,7 @@ export default class Nodes extends React.Component { NodeInfoStore.reset(); ChannelsStore.reset(); setConnectingStatus(true); - navigation.navigate('Wallet', { + navigation.popTo('Wallet', { refresh: true }); }); diff --git a/views/Settings/Seed.tsx b/views/Settings/Seed.tsx index 4880dd970..71d0c747d 100644 --- a/views/Settings/Seed.tsx +++ b/views/Settings/Seed.tsx @@ -322,7 +322,7 @@ export default class Seed extends React.PureComponent { 'backup-complete', JSON.stringify(true) ); - navigation.navigate('Wallet'); + navigation.popTo('Wallet'); }} title={localeString( 'views.Settings.Seed.backupComplete' diff --git a/views/Settings/SeedRecovery.tsx b/views/Settings/SeedRecovery.tsx index 13570c500..32afd0a4d 100644 --- a/views/Settings/SeedRecovery.tsx +++ b/views/Settings/SeedRecovery.tsx @@ -243,9 +243,9 @@ export default class SeedRecovery extends React.PureComponent< if (nodes.length === 1) { setConnectingStatus(true); - navigation.navigate('Wallet', { refresh: true }); + navigation.popTo('Wallet', { refresh: true }); } else { - navigation.navigate('Nodes', { refresh: true }); + navigation.popTo('Nodes', { refresh: true }); } }); }; diff --git a/views/Settings/SelectCurrency.tsx b/views/Settings/SelectCurrency.tsx index d0227c589..9e9b4f938 100644 --- a/views/Settings/SelectCurrency.tsx +++ b/views/Settings/SelectCurrency.tsx @@ -137,18 +137,15 @@ export default class SelectCurrency extends React.Component< }} onPress={async () => { if (currencyConverter) { - navigation.navigate( - 'CurrencyConverter', - { - selectedCurrency: item.value - } - ); + navigation.popTo('CurrencyConverter', { + selectedCurrency: item.value + }); } else { await updateSettings({ fiat: item.value }).then(() => { getSettings(); - navigation.navigate('Currency', { + navigation.popTo('Currency', { refresh: true }); }); diff --git a/views/Settings/SetDuressPassword.tsx b/views/Settings/SetDuressPassword.tsx index 9d143e12c..a73770379 100644 --- a/views/Settings/SetDuressPassword.tsx +++ b/views/Settings/SetDuressPassword.tsx @@ -98,7 +98,7 @@ export default class SetDuressPassphrase extends React.Component< await updateSettings({ duressPassphrase }).then(() => { getSettings(); - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); @@ -109,7 +109,7 @@ export default class SetDuressPassphrase extends React.Component< const { updateSettings } = SettingsStore; await updateSettings({ duressPassphrase: '' }).then(() => { - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); diff --git a/views/Settings/SetDuressPin.tsx b/views/Settings/SetDuressPin.tsx index e21a2486e..095bdb0c4 100644 --- a/views/Settings/SetDuressPin.tsx +++ b/views/Settings/SetDuressPin.tsx @@ -96,7 +96,7 @@ export default class SetDuressPin extends React.Component< await updateSettings({ duressPin }).then(() => { getSettings(); - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); diff --git a/views/Settings/SetNodePicture.tsx b/views/Settings/SetNodePicture.tsx index cf5bb56f1..0523697dd 100644 --- a/views/Settings/SetNodePicture.tsx +++ b/views/Settings/SetNodePicture.tsx @@ -149,7 +149,7 @@ export default class SetNodePicture extends React.Component< onChoosePicturePress = async () => { const { navigation } = this.props; - navigation.navigate('NodeConfiguration', { + navigation.popTo('NodeConfiguration', { photo: this.state.photo, saved: false }); diff --git a/views/Settings/SetPassword.tsx b/views/Settings/SetPassword.tsx index bae3a8859..cd9a3e5ec 100644 --- a/views/Settings/SetPassword.tsx +++ b/views/Settings/SetPassword.tsx @@ -96,7 +96,7 @@ export default class SetPassphrase extends React.Component< await updateSettings({ passphrase }).then(() => { setLoginStatus(true); getSettings(); - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); @@ -112,7 +112,7 @@ export default class SetPassphrase extends React.Component< duressPassphrase: '', passphrase: '' }).then(() => { - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); diff --git a/views/Settings/SetPin.tsx b/views/Settings/SetPin.tsx index 304431618..6aa69fdb1 100644 --- a/views/Settings/SetPin.tsx +++ b/views/Settings/SetPin.tsx @@ -95,7 +95,7 @@ export default class SetPin extends React.Component { await updateSettings({ pin }).then(() => { setLoginStatus(true); getSettings(); - navigation.navigate('Settings', { + navigation.popTo('Settings', { refresh: true }); }); diff --git a/views/TxHex.tsx b/views/TxHex.tsx index ae42c6b53..fb81161d2 100644 --- a/views/TxHex.tsx +++ b/views/TxHex.tsx @@ -231,9 +231,8 @@ export default class TxHex extends React.Component {
{ - navigation.navigate('Wallet'); - }} + onBack={() => navigation.popTo('Wallet')} + navigateBackOnBackPress={false} centerComponent={{ text: 'Transaction Hex', style: { color: themeColor('text') }