Skip to content

Commit

Permalink
center align qrcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
vorujack committed Mar 12, 2024
1 parent 7f5029c commit f842610
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ npm run electron:make

For Apple Silicon chips (M series) you must use the `arm64` build. Using the intel-based build will result in camera malfunction.

In case of ***damaged file*** error, use this command:
In case of **_damaged file_** error, use this command:

```
sudo xattr -r -s com.apple.quarantine /Application/minotaur.app
Expand Down
4 changes: 2 additions & 2 deletions src/components/display-qrcode/DisplayQRCode.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { Alert, Box, Button, MobileStepper, Slider } from '@mui/material';
import { QRCodeSVG } from 'qrcode.react';
import QRCodeSVG from './QrCodeSVG';
import { MAX_CHUNK_SIZE, QRCODE_MINIMUM_CHUNK_SIZE } from '@/utils/const';
import {
ContentCopyOutlined,
Expand Down Expand Up @@ -53,7 +53,7 @@ const DisplayQRCode = (props: DisplayQRCodePropsType) => {
border: '1px solid #ddd',
}}
>
<QRCodeSVG value={value} size={512} />
<QRCodeSVG value={value} />
</Box>
{pageCount > 1 ? (
<MobileStepper
Expand Down
29 changes: 29 additions & 0 deletions src/components/display-qrcode/QrCodeSVG.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { QRCodeSVG as PackageQrCode } from 'qrcode.react';
import { useEffect, useRef, useState } from 'react';

interface QrCodeSVGPropsType {
value: string;
}
const QrCodeSVG = (props: QrCodeSVGPropsType) => {
const [size, setSize] = useState(512);
const [clientSize, setClientSize] = useState(0);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (ref && ref.current) {
const rect = ref.current.getBoundingClientRect();
const newSize = Math.min(rect.width, rect.height);
if (newSize !== clientSize) {
setClientSize(newSize);
const pow = Math.min(Math.floor(Math.log(newSize) / Math.log(2)), 9);
setSize(Math.pow(2, pow));
}
}
}, [size, ref, clientSize]);
return (
<div ref={ref}>
<PackageQrCode size={size} value={props.value} />
</div>
);
};

export default QrCodeSVG;
4 changes: 2 additions & 2 deletions src/pages/settings/WalletExtendedPublicKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@mui/material';
import CopyToClipboardIcon from '@/components/copy-to-clipboard/CopyToClipboardIcon';
import AppFrame from '@/layouts/AppFrame';
import { QRCodeSVG } from 'qrcode.react';
import QRCodeSVG from '@/components/display-qrcode/QrCodeSVG';
import base58 from 'bs58';
import { StateWallet } from '@/store/reducer/wallet';
import BackButtonRouter from '@/components/back-button/BackButtonRouter';
Expand Down Expand Up @@ -61,7 +61,7 @@ const WalletExtendedPublicKey = (props: WalletExtendedPublicKeyPropsType) => {
sx={{ bgcolor: 'white', textAlign: 'center', mt: 1, mb: 2 }}
>
<Typography sx={{ p: 8, fontStyle: 'italic', color: 'textSecondary' }}>
<QRCodeSVG value={xPubEncoded} size={256} />
<QRCodeSVG value={xPubEncoded} />
</Typography>
</Card>
<Card>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/wallet-page/address/AddressViewCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Box, Card, Divider, IconButton, Typography } from '@mui/material';
import { Close, EditOutlined } from '@mui/icons-material';
import { QRCodeSVG } from 'qrcode.react';
import QRCodeSVG from '@/components/display-qrcode/QrCodeSVG';
import CopyToClipboardIcon from '@/components/copy-to-clipboard/CopyToClipboardIcon';
import Heading from '@/components/heading/Heading';
import ListController from '@/components/list-controller/ListController';
Expand Down Expand Up @@ -54,8 +54,8 @@ const AddressViewCard = (props: AddressViewCardPropsType) => {
<Divider sx={{ my: 2 }} />
</React.Fragment>
) : null}
<Box sx={{ p: 8, textAlign: 'center', fontStyle: 'italic' }}>
<QRCodeSVG value={props.address.address} size={256} />
<Box sx={{ pt: 8, pb: 8, textAlign: 'center', fontStyle: 'italic' }}>
<QRCodeSVG value={props.address.address} />
</Box>
<Box>
<Card sx={{ display: 'flex', bgcolor: 'info.light', p: 2 }}>
Expand Down

0 comments on commit f842610

Please sign in to comment.