Skip to content

Commit

Permalink
Merge pull request #1309 from kaloudis/node-fast-switching
Browse files Browse the repository at this point in the history
WalletHeader: SettingsButton: go to Nodes on long-press for fast switching
  • Loading branch information
kaloudis authored Feb 12, 2023
2 parents 1d9cd70 + fec34fa commit cd4ef38
Showing 1 changed file with 24 additions and 39 deletions.
63 changes: 24 additions & 39 deletions components/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ import { Row } from '../components/layout/Row';

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

const protectedNavigation = async (
navigation: any,
route: string,
disactivatePOS?: boolean
) => {
const { posStatus, settings, setPosStatus } = stores.settingsStore;
const loginRequired = settings && (settings.passphrase || settings.pin);
const posEnabled = posStatus === 'active';

if (posEnabled && loginRequired) {
navigation.navigate('Lockscreen', {
attemptAdminLogin: true
});
} else {
if (disactivatePOS) await setPosStatus('inactive');
navigation.navigate(route);
}
};

const OpenChannelButton = ({ navigation }: { navigation: any }) => (
<Button
title=""
Expand All @@ -44,28 +63,9 @@ const OpenChannelButton = ({ navigation }: { navigation: any }) => (
/>
);

const TempleButton = ({
setPosStatus,
navigation
}: {
setPosStatus: (status: string) => void;
navigation: any;
}) => (
const TempleButton = ({ navigation }: { navigation: any }) => (
<TouchableOpacity
onPress={async () => {
const { posStatus, settings } = stores.settingsStore;
const loginRequired =
settings && (settings.passphrase || settings.pin);
const posEnabled = posStatus === 'active';
if (posEnabled && loginRequired) {
navigation.navigate('Lockscreen', {
attemptAdminLogin: true
});
} else {
await setPosStatus('inactive');
navigation.navigate('Wallet');
}
}}
onPress={() => protectedNavigation(navigation, 'Wallet', true)}
>
<Temple
fill={themeColor('text')}
Expand Down Expand Up @@ -180,20 +180,8 @@ export default class WalletHeader extends React.Component<

const SettingsButton = () => (
<TouchableOpacity
onPress={() => {
const { posStatus, settings } = stores.settingsStore;
const loginRequired =
settings && (settings.passphrase || settings.pin);
const posEnabled = posStatus === 'active';

if (posEnabled && loginRequired) {
navigation.navigate('Lockscreen', {
attemptAdminLogin: true
});
} else {
navigation.navigate('Settings');
}
}}
onPress={() => protectedNavigation(navigation, 'Settings')}
onLongPress={() => protectedNavigation(navigation, 'Nodes')}
>
{multipleNodes ? (
<NodeIdenticon
Expand Down Expand Up @@ -252,10 +240,7 @@ export default class WalletHeader extends React.Component<
}
rightComponent={
posStatus === 'active' ? (
<TempleButton
navigation={navigation}
setPosStatus={setPosStatus}
/>
<TempleButton navigation={navigation} />
) : channels ? (
<OpenChannelButton navigation={navigation} />
) : (
Expand Down

0 comments on commit cd4ef38

Please sign in to comment.