Skip to content

Commit

Permalink
feat: mobile on desktop (#150)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Joseph Chalabi <[email protected]>
Co-authored-by: Felix C. Morency <[email protected]>
  • Loading branch information
chalabi2 and fmorency authored Jan 6, 2025
1 parent 118300c commit 62356e7
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 151 deletions.
Binary file modified bun.lockb
Binary file not shown.
348 changes: 305 additions & 43 deletions components/react/modal.tsx

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions components/react/qrCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import Image from 'next/image';
import QRCodeUtil from 'qrcode';
import React, { FunctionComponent, ReactElement, useMemo } from 'react';

const generateMatrix = (
value: string,
errorCorrectionLevel: QRCodeUtil.QRCodeErrorCorrectionLevel
) => {
const arr = Array.prototype.slice.call(
QRCodeUtil.create(value, { errorCorrectionLevel }).modules.data,
0
);
const sqrt = Math.sqrt(arr.length);
return arr.reduce(
(rows, key, index) =>
(index % sqrt === 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) && rows,
[]
);
};

export const QRCode: FunctionComponent<{
errorCorrectionLevel?: QRCodeUtil.QRCodeErrorCorrectionLevel;
logoUrl?: string;
logoSize?: number;
size?: number;
value: string;
}> = ({ errorCorrectionLevel = 'M', logoSize = 50, logoUrl, size = 280, value }) => {
const dots = useMemo(() => {
const dots: ReactElement[] = [];
const matrix = generateMatrix(value, errorCorrectionLevel);
const cellSize = size / matrix.length;
let qrList = [
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: 0, y: 1 },
];

qrList.forEach(({ x, y }) => {
const x1 = (matrix.length - 7) * cellSize * x;
const y1 = (matrix.length - 7) * cellSize * y;
for (let i = 0; i < 3; i++) {
dots.push(
<rect
fill={i % 2 !== 0 ? 'white' : 'black'}
height={cellSize * (7 - i * 2)}
key={`${i}-${x}-${y}`}
rx={(i - 2) * -5 + (i === 0 ? 2 : 0)} // calculated border radius for corner squares
ry={(i - 2) * -5 + (i === 0 ? 2 : 0)} // calculated border radius for corner squares
width={cellSize * (7 - i * 2)}
x={x1 + cellSize * i}
y={y1 + cellSize * i}
/>
);
}
});

const clearArenaSize = Math.floor(logoSize / cellSize);
const matrixMiddleStart = matrix.length / 2 - clearArenaSize / 2;
const matrixMiddleEnd = matrix.length / 2 + clearArenaSize / 2 - 1;

matrix.forEach((row: QRCodeUtil.QRCode[], i: number) => {
row.forEach((_: any, j: number) => {
if (matrix[i][j]) {
if (
!(
(i < 7 && j < 7) ||
(i > matrix.length - 8 && j < 7) ||
(i < 7 && j > matrix.length - 8)
)
) {
if (
!(
i > matrixMiddleStart &&
i < matrixMiddleEnd &&
j > matrixMiddleStart &&
j < matrixMiddleEnd
)
) {
dots.push(
<circle
cx={i * cellSize + cellSize / 2}
cy={j * cellSize + cellSize / 2}
fill="black"
key={`circle-${i}-${j}`}
r={cellSize / 3} // calculate size of single dots
/>
);
}
}
}
});
});

return dots;
}, [errorCorrectionLevel, logoSize, size, value]);

const logoPosition = size / 2 - logoSize / 2;

return (
<div className="relative flex items-center justify-center rounded-xl bg-white p-4">
<div className="relative" style={{ height: size, width: size }}>
{logoUrl && (
<div
className="absolute flex rounded-lg justify-center"
style={{
top: logoPosition,
width: size,
}}
>
<Image height={logoSize} src={logoUrl} width={logoSize} alt="Wallet logo" />
</div>
)}
<svg height={size} width={size}>
<rect fill="transparent" height={size} width={size} />
{dots}
</svg>
</div>
</div>
);
};
8 changes: 3 additions & 5 deletions components/react/views/Connecting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Dialog } from '@headlessui/react';
import { XMarkIcon } from '@heroicons/react/24/outline';
import { ChevronLeftIcon } from '@heroicons/react/20/solid';
import { getRealLogo } from '@/utils';
import { useTheme } from '@/contexts';

export const Connecting = ({
onClose,
Expand All @@ -21,7 +20,8 @@ export const Connecting = ({
title: string;
subtitle: string;
}) => {
const { theme } = useTheme();
const isDarkMode = document.documentElement.classList.contains('dark');

return (
<div className="mt-3 text-center sm:mt-1.5">
<div className="flex justify-between items-center mb-2">
Expand All @@ -46,9 +46,7 @@ export const Connecting = ({
<div className="flex flex-col w-full h-full mt-4 sm:px-8 sm:py-6">
<img
src={
name === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo, theme === 'dark')
name === 'Cosmos MetaMask Extension' ? '/metamask.svg' : getRealLogo(logo, isDarkMode)
}
alt={name}
className="flex-shrink-0 w-20 h-20 mx-auto aspect-1"
Expand Down
11 changes: 6 additions & 5 deletions components/react/views/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { XMarkIcon, ArrowPathIcon } from '@heroicons/react/24/outline';
import { ChevronLeftIcon } from '@heroicons/react/20/solid';
import Image from 'next/image';
import { getRealLogo } from '@/utils';
import { useTheme } from '@/contexts';

export const Error = ({
currentWalletName,
onClose,
Expand All @@ -19,7 +19,8 @@ export const Error = ({
onReconnect: () => void;
logo: string;
}) => {
const { theme } = useTheme();
const isDarkMode = document.documentElement.classList.contains('dark');

return (
<div className="mt-3 text-center sm:mt-1.5">
<div className="flex flex-row items-center justify-between">
Expand Down Expand Up @@ -48,9 +49,9 @@ export const Error = ({
<div className="p-3 border rounded-full border-red-600 mx-auto aspect-1 flex-shrink-0">
<Image
src={
currentWalletName === 'cosmos-extension-metamask'
currentWalletName === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo, theme === 'dark')
: getRealLogo(logo, isDarkMode)
}
alt="Wallet type logo"
className="flex-shrink-0 w-16 h-16 aspect-1"
Expand All @@ -66,7 +67,7 @@ export const Error = ({
className="rounded-lg w-[180px] btn btn-error inline-flex justify-center items-center py-2.5 font-medium mt-4 bg-mint mx-auto text-black dark:text-white"
onClick={onReconnect}
>
<ArrowPathIcon className="flex-shrink-0 w-5 h-5 mr-2 text-black dark:text-white" />
<ArrowPathIcon className="flex-shrink-0 w-5 h-5 mr-2 " />
Reconnect
</button>
</div>
Expand Down
8 changes: 3 additions & 5 deletions components/react/views/NotExist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Dialog } from '@headlessui/react';
import { XMarkIcon, ArrowDownTrayIcon } from '@heroicons/react/24/outline';
import { ChevronLeftIcon } from '@heroicons/react/20/solid';
import { getRealLogo } from '@/utils';
import { useTheme } from '@/contexts';

export const NotExist = ({
onClose,
Expand All @@ -18,7 +17,8 @@ export const NotExist = ({
logo: string;
name: string;
}) => {
const { theme } = useTheme();
const isDarkMode = document.documentElement.classList.contains('dark');

return (
<div className="mt-3 text-center sm:mt-1.5">
<div className="flex justify-between items-center mb-2">
Expand All @@ -43,9 +43,7 @@ export const NotExist = ({
<div className="flex flex-col w-full h-full py-6 mt-4 sm:px-8">
<img
src={
name === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo, theme === 'dark')
name === 'Cosmos MetaMask Extension' ? '/metamask.svg' : getRealLogo(logo, isDarkMode)
}
alt={name}
className="flex-shrink-0 w-16 h-16 mx-auto aspect-1"
Expand Down
54 changes: 0 additions & 54 deletions components/react/views/QRCode.tsx

This file was deleted.

Loading

0 comments on commit 62356e7

Please sign in to comment.