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

Custom pictures for node config #2010

Merged
merged 11 commits into from
Mar 26, 2024
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import PaymentsSettings from './views/Settings/PaymentsSettings';
import InvoicesSettings from './views/Settings/InvoicesSettings';
import LSP from './views/Settings/LSP';
import ChannelsSettings from './views/Settings/ChannelsSettings';
import SetNodePicture from './views/Settings/SetNodePicture';

// Lightning address
import LightningAddress from './views/Settings/LightningAddress';
Expand Down Expand Up @@ -441,6 +442,9 @@ const AppScenes = {
},
RestoreChannelBackups: {
screen: RestoreChannelBackups
},
SetNodePicture: {
screen: SetNodePicture
}
};

Expand Down
Binary file added assets/images/Alby.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/BTCpay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/CLN.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/LND.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-1a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-1b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-2a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-2b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-3a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-3b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-4a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-4b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-5a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-5b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-6a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-6b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-7a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/zeus-illustration-7b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 23 additions & 7 deletions components/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'react-native';
import { inject, observer } from 'mobx-react';
import Clipboard from '@react-native-clipboard/clipboard';
import RNFS from 'react-native-fs';

import ChannelsStore from '../stores/ChannelsStore';
import LightningAddressStore from '../stores/LightningAddressStore';
Expand Down Expand Up @@ -46,8 +47,6 @@ import stores from '../stores/Stores';
import { Body } from './text/Body';
import { Row } from '../components/layout/Row';

const Contact = require('../assets/images/Mascot.png');

const TorIcon = require('../assets/images/tor.png');

const Mailbox = () => (
Expand Down Expand Up @@ -206,6 +205,14 @@ export default class WalletHeader extends React.Component<
}
}

getPhoto(photo: string | null): string {
if (typeof photo === 'string' && photo.includes('rnfs://')) {
const fileName = photo.replace('rnfs://', '');
return `file://${RNFS.DocumentDirectoryPath}/${fileName}`;
}
return photo || '';
}

render() {
const { clipboard } = this.state;
const {
Expand All @@ -227,8 +234,6 @@ export default class WalletHeader extends React.Component<
const laLoading = LightningAddressStore?.loading;
const { isSyncing } = SyncStore!;
const { getOrders } = PosStore!;
const multipleNodes: boolean =
(settings && settings.nodes && settings.nodes.length > 1) || false;
const selectedNode: any =
(settings &&
settings.nodes?.length &&
Expand All @@ -245,14 +250,19 @@ export default class WalletHeader extends React.Component<
onLongPress={() => protectedNavigation(navigation, 'Nodes')}
accessibilityLabel={localeString('views.Settings.title')}
>
{multipleNodes ? (
{selectedNode && selectedNode.photo ? (
<Image
source={{
uri: this.getPhoto(selectedNode.photo)
}}
style={styles.photo}
/>
) : (
<NodeIdenticon
selectedNode={selectedNode}
width={35}
rounded
/>
) : (
<Image source={Contact} style={{ width: 35, height: 35 }} />
)}
</TouchableOpacity>
);
Expand Down Expand Up @@ -551,5 +561,11 @@ const styles = StyleSheet.create({
badgeTextStyle: {
fontWeight: 'normal',
textAlign: 'center'
},
photo: {
alignSelf: 'center',
width: 42,
height: 42,
borderRadius: 68
}
});
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@
"views.Settings.Contacts.noAddress": "No Address",
"views.Settings.Contacts.to": "To",
"views.Settings.Contacts.deleteAllContacts": "Delete all contacts",
"views.SetNodePicture.choosePicture": "Choose Picture",
"views.Transaction.title": "Transaction",
"views.Transaction.totalFees": "Total Fees",
"views.Transaction.transactionHash": "Transaction Hash",
Expand Down
1 change: 1 addition & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Node {
pairingPhrase?: string;
mailboxServer?: string;
customMailboxServer?: string;
photo?: string;
}

interface PrivacySettings {
Expand Down
145 changes: 120 additions & 25 deletions views/Settings/NodeConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
StyleSheet,
Text,
View,
Image,
ScrollView,
TouchableOpacity
} from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';
import { inject, observer } from 'mobx-react';
import EncryptedStorage from 'react-native-encrypted-storage';
import cloneDeep from 'lodash/cloneDeep';
import RNFS from 'react-native-fs';

import { hash, STORAGE_KEY } from '../../backends/LNC/credentialStore';

Expand Down Expand Up @@ -43,6 +45,7 @@ import SettingsStore, {
} from '../../stores/SettingsStore';

import Scan from '../../assets/images/SVG/Scan.svg';
import AddIcon from '../../assets/images/SVG/Add.svg';

import { createLndWallet } from '../../utils/LndMobileUtils';

Expand Down Expand Up @@ -73,6 +76,7 @@ interface NodeConfigurationState {
showCertModal: boolean;
enableTor: boolean;
interfaceKeys: Array<any>;
photo: string | null;
// lnc
pairingPhrase: string;
mailboxServer: string;
Expand Down Expand Up @@ -124,6 +128,7 @@ export default class NodeConfiguration extends React.Component<
username: '',
password: '',
accessKey: '',
photo: null,
// lnc
pairingPhrase: '',
mailboxServer: 'mailbox.terminal.lightning.today:443',
Expand Down Expand Up @@ -273,6 +278,7 @@ export default class NodeConfiguration extends React.Component<
const tor = navigation.getParam('enableTor', false);
const saved = navigation.getParam('saved', null);
const newEntry = navigation.getParam('newEntry', null);
const photo = navigation.getParam('photo', null);

if (node) {
const {
Expand Down Expand Up @@ -318,6 +324,7 @@ export default class NodeConfiguration extends React.Component<
saved,
newEntry,
enableTor: tor || enableTor,
photo,
// LNC
pairingPhrase,
mailboxServer,
Expand All @@ -332,7 +339,8 @@ export default class NodeConfiguration extends React.Component<
this.setState({
index,
active,
newEntry
newEntry,
photo
});
}
}
Expand Down Expand Up @@ -360,7 +368,8 @@ export default class NodeConfiguration extends React.Component<
seedPhrase,
walletPassword,
adminMacaroon,
embeddedLndNetwork
embeddedLndNetwork,
photo
} = this.state;
const { setConnectingStatus, updateSettings, settings } = SettingsStore;

Expand Down Expand Up @@ -391,7 +400,8 @@ export default class NodeConfiguration extends React.Component<
seedPhrase,
walletPassword,
adminMacaroon,
embeddedLndNetwork
embeddedLndNetwork,
photo
};

let nodes: any;
Expand Down Expand Up @@ -444,7 +454,8 @@ export default class NodeConfiguration extends React.Component<
certVerification,
pairingPhrase,
mailboxServer,
customMailboxServer
customMailboxServer,
photo
} = this.state;
const { nodes } = settings;

Expand All @@ -464,7 +475,8 @@ export default class NodeConfiguration extends React.Component<
enableTor,
pairingPhrase,
mailboxServer,
customMailboxServer
customMailboxServer,
photo
};

navigation.navigate('NodeConfiguration', {
Expand Down Expand Up @@ -570,8 +582,17 @@ export default class NodeConfiguration extends React.Component<
}
};

getPhoto(photo: string | null): string {
if (typeof photo === 'string' && photo.includes('rnfs://')) {
const fileName = photo.replace('rnfs://', '');
return `file://${RNFS.DocumentDirectoryPath}/${fileName}`;
}
return photo || '';
}

render() {
const { navigation, SettingsStore } = this.props;
const node = navigation.getParam('node', null);
const {
nickname,
host,
Expand All @@ -589,6 +610,7 @@ export default class NodeConfiguration extends React.Component<
implementation,
certVerification,
enableTor,
photo,
interfaceKeys,
existingAccount,
suggestImport,
Expand Down Expand Up @@ -675,6 +697,15 @@ export default class NodeConfiguration extends React.Component<
);
};

const AddPhotos = () => (
<AddIcon
fill={themeColor('background')}
width="14"
height="14"
style={{ alignSelf: 'center' }}
/>
);

return (
<Screen>
<Header
Expand Down Expand Up @@ -925,29 +956,77 @@ export default class NodeConfiguration extends React.Component<
message={createAccountSuccess}
/>
)}
<View style={styles.container}>
<TouchableOpacity
onPress={
(node === null || !node.photo) &&
photo === null
? () =>
navigation.navigate(
'SetNodePicture',
{ implementation }
)
: () =>
this.setState(
shubhamkmr04 marked this conversation as resolved.
Show resolved Hide resolved
{ photo: null, saved: false },
() =>
node
? (node.photo = '')
: null
)
}
>
<View
style={{
...styles.imageBackground,
backgroundColor:
themeColor('secondaryText')
}}
>
{node?.photo || photo ? (
<Image
source={{
uri: this.getPhoto(
node?.photo || photo
)
}}
style={styles.imageBackground}
/>
) : (
<AddPhotos />
)}
</View>
</TouchableOpacity>

<View>
<Text
<View
style={{
...styles.text,
color: themeColor('secondaryText')
flex: 1,
marginLeft: 14,
marginTop: -16
}}
>
{localeString(
'views.Settings.AddEditNode.nickname'
)}
</Text>
<TextInput
placeholder={'My lightning node'}
value={nickname}
onChangeText={(text: string) =>
this.setState({
nickname: text,
saved: false
})
}
locked={loading}
/>
<Text
style={{
...styles.text,
color: themeColor('text')
}}
>
{localeString(
'views.Settings.AddEditNode.nickname'
)}
</Text>
<TextInput
placeholder={'My lightning node'}
value={nickname}
onChangeText={(text: string) =>
this.setState({
nickname: text,
saved: false
})
}
locked={loading}
/>
</View>
</View>

{!adminMacaroon && <NodeInterface />}
Expand Down Expand Up @@ -1552,7 +1631,7 @@ export default class NodeConfiguration extends React.Component<
!(
implementation === 'embedded-lnd' && !adminMacaroon
) && (
<View style={{ ...styles.button, marginTop: 20 }}>
<View style={{ ...styles.button }}>
<Button
title={
saved
Expand Down Expand Up @@ -1763,5 +1842,21 @@ const styles = StyleSheet.create({
nodeInterface: {
paddingTop: 10,
paddingBottom: 10
},
container: {
flexDirection: 'row',
alignItems: 'center'
},
imageBackground: {
width: 50,
height: 50,
borderRadius: 24,
justifyContent: 'center'
},
photo: {
alignSelf: 'center',
width: 128,
height: 128,
borderRadius: 68
}
});
Loading
Loading