Skip to content

Commit

Permalink
Add switch for light QR codes on dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed May 5, 2023
1 parent 811cb41 commit 298ce13
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/basic/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const SettingsPage = (): JSX.Element => {
elevation={12}
sx={{
padding: '0.6em',
width: '18em',
width: '21em',
maxHeight: `${maxHeight}em`,
overflow: 'auto',
overflowX: 'clip',
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/Dialogs/EnableTelegram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useTheme } from '@mui/material/styles';
import QRCode from 'react-qr-code';
Expand All @@ -13,6 +13,7 @@ import {
Grid,
} from '@mui/material';
import { NewTabIcon } from '../Icons';
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';

interface Props {
open: boolean;
Expand All @@ -22,6 +23,7 @@ interface Props {
}

const EnableTelegramDialog = ({ open, onClose, tgBotName, tgToken }: Props): JSX.Element => {
const { settings } = useContext<UseAppStoreType>(AppContext);
const { t } = useTranslation();
const theme = useTheme();

Expand Down Expand Up @@ -49,7 +51,7 @@ const EnableTelegramDialog = ({ open, onClose, tgBotName, tgToken }: Props): JSX
sx={{
width: 290,
display: 'flex',
backgroundColor: theme.palette.background.paper,
backgroundColor: settings.lightQRs ? '#fff' : theme.palette.background.paper,
alignItems: 'center',
justifyContent: 'center',
padding: '0.5em',
Expand All @@ -63,7 +65,7 @@ const EnableTelegramDialog = ({ open, onClose, tgBotName, tgToken }: Props): JSX
>
<QRCode
bgColor={'rgba(255, 255, 255, 0)'}
fgColor={theme.palette.text.primary}
fgColor={settings.lightQRs ? '#000000' : theme.palette.text.primary}
value={'tg://resolve?domain=' + tgBotName + '&start=' + tgToken}
size={275}
onClick={handleOpenTG}
Expand Down
56 changes: 56 additions & 0 deletions frontend/src/components/SettingsForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Link,
AccountBalance,
AttachMoney,
QrCode,
} from '@mui/icons-material';
import { systemClient } from '../../services/System';
import SwapCalls from '@mui/icons-material/SwapCalls';
Expand Down Expand Up @@ -112,6 +113,61 @@ const SettingsForm = ({ dense = false, showNetwork = false }: SettingsFormProps)
/>
}
/>
{settings.mode === 'dark' ? (
<>
<ListItemIcon>
<QrCode />
</ListItemIcon>
<FormControlLabel
sx={{ position: 'relative', right: '1.5em', width: '3em' }}
labelPlacement='end'
label={settings.lightQRs ? t('Light') : t('Dark')}
control={
<Switch
checked={!settings.lightQRs}
checkedIcon={
<Paper
elevation={3}
sx={{
width: '1.2em',
height: '1.2em',
borderRadius: '0.4em',
backgroundColor: 'white',
position: 'relative',
top: `${7 - 0.5 * theme.typography.fontSize}px`,
}}
>
<DarkMode sx={{ width: '0.8em', height: '0.8em', color: '#666' }} />
</Paper>
}
icon={
<Paper
elevation={3}
sx={{
width: '1.2em',
height: '1.2em',
borderRadius: '0.4em',
backgroundColor: 'white',
padding: '0.07em',
position: 'relative',
top: `${7 - 0.5 * theme.typography.fontSize}px`,
}}
>
<LightMode sx={{ width: '0.67em', height: '0.67em', color: '#666' }} />
</Paper>
}
onChange={(e) => {
const lightQRs = !e.target.checked;
setSettings({ ...settings, lightQRs });
systemClient.setItem('settings_lightQRs', lightQRs);
}}
/>
}
/>
</>
) : (
<></>
)}
</ListItem>

<ListItem>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/TradeBox/Prompts/LockInvoice.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Box, Grid, Typography, TextField, Tooltip, useTheme } from '@mui/material';
import { ContentCopy } from '@mui/icons-material';
Expand All @@ -7,13 +7,15 @@ import { Order } from '../../../models';
import { systemClient } from '../../../services/System';
import currencies from '../../../../static/assets/currencies.json';
import WalletsButton from '../WalletsButton';
import { AppContext, UseAppStoreType } from '../../../contexts/AppContext';

interface LockInvoicePromptProps {
order: Order;
concept: 'bond' | 'escrow';
}

export const LockInvoicePrompt = ({ order, concept }: LockInvoicePromptProps): JSX.Element => {
const { settings } = useContext<UseAppStoreType>(AppContext);
const { t } = useTranslation();
const theme = useTheme();
const currencyCode: string = currencies[`${order.currency}`];
Expand Down Expand Up @@ -81,7 +83,7 @@ export const LockInvoicePrompt = ({ order, concept }: LockInvoicePromptProps): J
<Box
sx={{
display: 'flex',
backgroundColor: theme.palette.background.paper,
backgroundColor: settings.lightQRs ? '#fff' : theme.palette.background.paper,
alignItems: 'center',
justifyContent: 'center',
padding: '0.5em',
Expand All @@ -95,7 +97,7 @@ export const LockInvoicePrompt = ({ order, concept }: LockInvoicePromptProps): J
>
<QRCode
bgColor={'rgba(255, 255, 255, 0)'}
fgColor={theme.palette.text.primary}
fgColor={settings.lightQRs ? '#000000' : theme.palette.text.primary}
value={invoice ?? 'Undefined: BOLT11 invoice not received'}
size={theme.typography.fontSize * 21.8}
onClick={handleClickQR}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/AppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const useAppStore = () => {

useEffect(() => {
setTheme(makeTheme(settings));
}, [settings.fontSize, settings.mode]);
}, [settings.fontSize, settings.mode, settings.lightQRs]);

useEffect(() => {
i18n.changeLanguage(settings.language);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/models/Settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BaseSettings {
? 'dark'
: 'light';

this.lightQRs = systemClient.getItem('settings_lightQRs') === 'true';

const languageCookie = systemClient.getItem('settings_language');
this.language =
languageCookie !== ''
Expand All @@ -45,6 +47,7 @@ class BaseSettings {
public frontend: 'basic' | 'pro' = 'basic';
public mode: 'light' | 'dark' = 'light';
public fontSize: number = 14;
public lightQRs: boolean = false;
public language?: Language;
public freezeViewports: boolean = false;
public network: 'mainnet' | 'testnet' = 'mainnet';
Expand Down
2 changes: 1 addition & 1 deletion mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const App = () => {
};

EncryptedStorage.removeItem('sessionid');
// EncryptedStorage.removeItem('csrftoken');
loadCookie('robot_token');
loadCookie('settings_fontsize_basic');
loadCookie('settings_language');
loadCookie('settings_mode');
loadCookie('settings_lightQRs');
loadCookie('settings_network');
loadCookie('garage').then(() => injectMessageResolve(responseId));
};
Expand Down

0 comments on commit 298ce13

Please sign in to comment.