turn off user defined SP address is input it empty
This commit is contained in:
@@ -6,7 +6,8 @@ import { CustomTitleBar } from './CustomTitleBar';
|
||||
|
||||
export const AppWindowFrame: FCWithChildren = ({ children }) => {
|
||||
const location = useLocation();
|
||||
const { userDefinedGateway, setUserDefinedGateway } = useClientContext();
|
||||
const { userDefinedGateway, setUserDefinedGateway, userDefinedSPAddress, setUserDefinedSPAddress } =
|
||||
useClientContext();
|
||||
|
||||
// defined functions to be used when moving away from pages
|
||||
const onBack = () => {
|
||||
@@ -19,6 +20,14 @@ export const AppWindowFrame: FCWithChildren = ({ children }) => {
|
||||
setUserDefinedGateway((current) => ({ ...current, isActive: false }));
|
||||
}
|
||||
};
|
||||
case '/menu/settings/service-provider':
|
||||
return () => {
|
||||
// when the user moves away from the settings page and the gateway is not valid
|
||||
// set isActive to false
|
||||
if (!userDefinedSPAddress?.address) {
|
||||
setUserDefinedSPAddress((current) => ({ ...current, isActive: false }));
|
||||
}
|
||||
};
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => {
|
||||
|
||||
useEffect(() => {
|
||||
setItemInStorage({ key: FORAGE_SP_KEY, value: userDefinedSPAddress });
|
||||
}, [userDefinedGateway]);
|
||||
}, [userDefinedSPAddress]);
|
||||
|
||||
const initialiseApp = async () => {
|
||||
const services = await invoke('get_services');
|
||||
|
||||
@@ -33,6 +33,10 @@ export const ServiceProviderSettings = () => {
|
||||
return 'The service provider specified is not in our known list.';
|
||||
};
|
||||
|
||||
const validateInput = (value: string) => {
|
||||
setUserDefinedSPAddress((current) => ({ ...current, address: !value.length ? undefined : value }));
|
||||
};
|
||||
|
||||
return (
|
||||
<Box height="100%">
|
||||
<Stack justifyContent="space-between" height="100%">
|
||||
@@ -63,11 +67,10 @@ export const ServiceProviderSettings = () => {
|
||||
<Autocomplete
|
||||
clearOnEscape
|
||||
disabled={connectionStatus === 'connected'}
|
||||
value={userDefinedSPAddress.address}
|
||||
sx={{ mt: 1 }}
|
||||
options={serviceProviders.map((sp) => sp.address)}
|
||||
getOptionLabel={(address) => `${address.substring(0, 18)}...`}
|
||||
freeSolo
|
||||
value={userDefinedSPAddress.address || ''}
|
||||
onChange={(e, value) => handleSelectFromList(value)}
|
||||
size="small"
|
||||
renderInput={(params) => (
|
||||
@@ -75,7 +78,7 @@ export const ServiceProviderSettings = () => {
|
||||
autoFocus
|
||||
{...params}
|
||||
placeholder="Service provider"
|
||||
onChange={(e) => setUserDefinedSPAddress((current) => ({ ...current, address: e.target.value }))}
|
||||
onChange={(e) => validateInput(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
ListboxProps={{ style: { background: 'unset', fontSize: '14px' } }}
|
||||
|
||||
Reference in New Issue
Block a user