Skip to content

Commit

Permalink
Add a switch component to enable and disable manager PIN in settings.…
Browse files Browse the repository at this point in the history
… Update
  • Loading branch information
chloehjung15 committed Dec 1, 2023
1 parent f4a88bb commit 9937a9f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 45 deletions.
85 changes: 45 additions & 40 deletions screens/settings/ConnectToHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ConnectToHub = props => {
};
const [scanMode, setScanMode] = useState(false);

const [showPinSetScreen, setShowPinSetScreen] = useState(false);
// const [showPinSetScreen, setShowPinSetScreen] = useState(false);

const textStyle = {
color: isDarkMode ? '#fff' : '#000',
Expand All @@ -49,9 +49,14 @@ const ConnectToHub = props => {
console.log('Toast.show');
} else {
setScanMode(false);
setShowPinSetScreen(true);

setHubData(e.data.split('@'));
const data = e.data.split('@');
setLndhubUser(data[0]);
setLndhub(data[1]);
Toast.show({
type: 'success',
text1: 'LND Connect',
text2: 'LND Hub Save Success.',
});
}
};

Expand Down Expand Up @@ -184,23 +189,6 @@ const ConnectToHub = props => {
{lndhub && lndhub != 'blank' && lndhub}
</Text>
</View>
<Button
title="Clear Hub Connection"
onPress={async () => {
try {
setLndhubUser(null);
setLndhub(null);
setShopWallet(null);
await AsyncStorage.setItem('manager-pin', '');
} catch (err) {
Toast.show({
type: 'error',
text1: 'PIN reset error',
text2: err.message,
});
}
}}
/>
<View
style={{
flexDirection: 'row',
Expand Down Expand Up @@ -238,28 +226,45 @@ const ConnectToHub = props => {
onPress={() => onScanSuccess({data: hub})}
/>
</View>
<Button
title="Clear Hub Connection"
onPress={async () => {
try {
setLndhubUser(null);
setLndhub(null);
setShopWallet(null);
await AsyncStorage.setItem('manager-pin', '');
} catch (err) {
Toast.show({
type: 'error',
text1: 'PIN reset error',
text2: err.message,
});
}
}}
/>
</View>
</ScrollView>
)}
<PinSetScreen
showBaseModal={showPinSetScreen}
onClose={() => setShowPinSetScreen(false)}
title="Set Admin Access PIN"
successMessage="LND Hub Save Success."
successCallback={() => {
setLndhubUser(hubData[0]);
setLndhub(hubData[1]);
Toast.show({
type: 'success',
text1: 'LND Connect',
text2: 'LND Hub Save Success.',
});
setHubData([]);
}}
failCallback={() => {
setHubData([]);
}}
/>
// <PinSetScreen
// showBaseModal={showPinSetScreen}
// onClose={() => setShowPinSetScreen(false)}
// title="Set Admin Access PIN"
// successMessage="LND Hub Save Success."
// successCallback={() => {
// setLndhubUser(hubData[0]);
// setLndhub(hubData[1]);
// Toast.show({
// type: 'success',
// text1: 'LND Connect',
// text2: 'LND Hub Save Success.',
// });
// setHubData([]);
// }}
// failCallback={() => {
// setHubData([]);
// }}
// />
</>
);
};
Expand Down
36 changes: 31 additions & 5 deletions screens/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Alert,
NativeModules,
} from 'react-native';
import {ListItem, Switch} from 'react-native-elements';
import {SimpleListItem} from '../../SimpleComponents';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {
Expand Down Expand Up @@ -44,12 +45,14 @@ const Settings = () => {
const [showPinSetScreen, setShowPinSetScreen] = useState(false);
const [showPinScreen, setShowPinScreen] = useState(false);
const [pinCode, setPinCode] = useState('');
const [pinEnabled, setPinEnabled] = useState(false);

const checkPin = async () => {
try {
setInitLoading(true);
const managerPin = await AsyncStorage.getItem('manager-pin');
if (managerPin) {
setPinEnabled(true);
setShowPinScreen(true);
} else {
setInitLoading(false);
Expand Down Expand Up @@ -101,11 +104,33 @@ const Settings = () => {
onPress={() => navigate('Printer Settings')}
chevron
/>
<SimpleListItem
title="Reset PIN"
onPress={() => setShowPinSetScreen(true)}
chevron
/>
<ListItem
containerStyle={{backgroundColor: 'transparent'}}
bottomDivider={true}>
<ListItem.Content>
<ListItem.Title>Enable Manager Access PIN</ListItem.Title>
</ListItem.Content>
<Switch
value={pinEnabled}
onValueChange={async value => {
if (value) {
//enable PIN
setShowPinSetScreen(true);
} else {
//disable PIN
await AsyncStorage.setItem('manager-pin', '');
setPinEnabled(value);
}
}}
/>
</ListItem>
{pinEnabled && (
<SimpleListItem
title="Reset PIN"
onPress={() => setShowPinSetScreen(true)}
chevron
/>
)}
</View>

<View style={{flex: 1}}>
Expand Down Expand Up @@ -151,6 +176,7 @@ const Settings = () => {
<PinSetScreen
showBaseModal={showPinSetScreen}
onClose={() => setShowPinSetScreen(false)}
successCallback={() => setPinEnabled(true)}
/>
<PinCodeModal
showModal={showPinScreen}
Expand Down

0 comments on commit 9937a9f

Please sign in to comment.