Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve QR code legibility #168

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-hotels-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/auth-kit": minor
---

feat: improve QR code legibility
1 change: 1 addition & 0 deletions packages/auth-kit/src/components/FarcasterLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function FarcasterLogo({
xmlns="http://www.w3.org/2000/svg"
width={width}
height={height}
viewBox="0 0 22 20"
fill="none"
>
<title>Farcaster logo</title>
Expand Down
23 changes: 12 additions & 11 deletions packages/auth-kit/src/components/QRCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function QRCode({
const padding = "20";
const size = sizeProp - parseInt(padding, 10) * 2;

const dots = useMemo(() => {
const dots: ReactElement[] = [];
const squares = useMemo(() => {
const squares: ReactElement[] = [];
const matrix = generateMatrix(uri, ecl);
const cellSize = size / matrix.length;
const qrList = [
Expand All @@ -54,7 +54,7 @@ export function QRCode({
const x1 = (matrix.length - 7) * cellSize * x;
const y1 = (matrix.length - 7) * cellSize * y;
for (let i = 0; i < 3; i++) {
dots.push(
squares.push(
<rect
fill={i % 2 !== 0 ? "white" : "black"}
height={cellSize * (7 - i * 2)}
Expand Down Expand Up @@ -91,13 +91,14 @@ export function QRCode({
j < matrixMiddleEnd
)
) {
dots.push(
<circle
cx={i * cellSize + cellSize / 2}
cy={j * cellSize + cellSize / 2}
squares.push(
<rect
fill="black"
key={`circle-${i}-${j}`}
r={cellSize / 3} // calculate size of single dots
height={cellSize - 0.5}
key={`square-${i}-${j}`}
width={cellSize - 0.5}
x={i * cellSize}
y={j * cellSize}
/>
);
}
Expand All @@ -106,7 +107,7 @@ export function QRCode({
});
});

return dots;
return squares;
}, [ecl, logoSize, logoMargin, size, uri]);

const logoPosition = size / 2 - logoSize / 2;
Expand Down Expand Up @@ -135,7 +136,7 @@ export function QRCode({
</clipPath>
</defs>
<rect fill="transparent" height={size} width={size} />
{dots}
{squares}
</svg>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function QRCodeDialog({
height={18}
fill="none"
>
<title>Sign in With Farcaster</title>
<path
fill="rgba(0,0,0,0.5)"
fillRule="evenodd"
Expand Down Expand Up @@ -61,7 +62,7 @@ export function QRCodeDialog({
marginBottom: 12,
}}
>
<QRCode uri={url} size={264} logoSize={22} logoMargin={12} />
<QRCode uri={url} size={300} logoSize={28} logoMargin={16} />
</div>
<div style={{ display: "flex", justifyContent: "center" }}>
<Button
Expand All @@ -81,6 +82,7 @@ export function QRCodeDialog({
height={18}
fill="none"
>
<title>Sign in With Farcaster QR Code</title>
<path
fill="#7C65C1"
fillRule="evenodd"
Expand Down
Loading