Skip to content

Commit 66424c0

Browse files
committed
working logo in svg
1 parent 01b476f commit 66424c0

File tree

6 files changed

+38
-52
lines changed

6 files changed

+38
-52
lines changed

src/internal/components/QrCode/QrCode.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// import { useIsSmallScreen } from ':rn/shared/hooks/useIsSmallScreen';
2-
31
import { QRCodeSVG, type QRCodeSVGProps } from './QrCodeSvg';
4-
5-
export const QR_CODE_SIZE = 237;
6-
export const QR_CODE_SMALL_SIZE = 150;
7-
export const QR_LOGO_SIZE = 50;
8-
export const QR_LOGO_RADIUS = 25;
2+
import {
3+
QR_CODE_SIZE,
4+
QR_LOGO_SIZE,
5+
QR_LOGO_RADIUS,
6+
QR_LOGO_BACKGROUND_COLOR,
7+
} from './gradientConstants';
98

109
export function QRCodeComponent({
1110
color = '#000000',
@@ -14,13 +13,13 @@ export function QRCodeComponent({
1413
isAsyncDataFetched,
1514
gradientType,
1615
}: QRCodeSVGProps) {
17-
// const isSmallScreen = useIsSmallScreen();
1816

1917
return (
2018
<QRCodeSVG
2119
size={QR_CODE_SIZE}
2220
logo={logo}
2321
logoSize={QR_LOGO_SIZE}
22+
logoBackgroundColor={QR_LOGO_BACKGROUND_COLOR}
2423
logoBorderRadius={QR_LOGO_RADIUS}
2524
value={value}
2625
color={color}

src/internal/components/QrCode/QrCodeSvg.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import { useEffect, useMemo, useState } from 'react';
2-
// import { Animated, Easing } from 'react-native';
3-
// import Svg, { Defs, G, LinearGradient, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
4-
// import { curves, durations } from '@cbhq/cds-common/motion/tokens';
5-
62
import {
73
GRADIENT_END_COORDINATES,
84
GRADIENT_START_COORDINATES,
@@ -36,10 +32,6 @@ export type QRCodeSVGProps = {
3632
gradientType?: 'radial' | 'linear';
3733
};
3834

39-
// const A = {
40-
// RadialGradient: Animated.createAnimatedComponent(RadialGradient),
41-
// };
42-
4335
export function QRCodeSVG({
4436
value,
4537
size = 100,
@@ -65,9 +57,7 @@ export function QRCodeSVG({
6557
const gradientRadiusMax = size * 0.55;
6658
const gradientRadiusMin = logoSize / 2;
6759
const gradientCenterPoint = size / 2;
68-
// const gradientAnim = useRef(
69-
// new Animated.Value(isAsyncDataFetched ? gradientRadiusMax : gradientRadiusMin),
70-
// ).current;
60+
7161
const [gradientRadius, setGradientRadius] = useState(
7262
isAsyncDataFetched ? gradientRadiusMax : gradientRadiusMin,
7363
);

src/internal/components/QrCode/gradientConstants.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// import { MiamiThemeColorPreference } from 'cb-wallet-data/stores/ThemeColors/themeColorConfigs';
2-
1+
export const QR_CODE_SIZE = 237;
2+
export const QR_LOGO_SIZE = 50;
3+
export const QR_LOGO_RADIUS = 10;
4+
export const QR_LOGO_BACKGROUND_COLOR = 'white';
35
export const GRADIENT_START_COORDINATES = { x: 0, y: 0 };
46
export const GRADIENT_END_COORDINATES = { x: 1, y: 0 };
57
export const GRADIENT_END_STYLE = { borderRadius: 32 };

src/internal/components/QrCode/useLogo.tsx

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { useMemo } from 'react';
1+
import React, { useMemo } from 'react';
2+
import { cbwSvg } from '../../svg/cbwSvg';
3+
import ReactDOMServer from 'react-dom/server';
24

35
type RenderLogoProps = {
46
size: number;
5-
logo: React.ReactNode | undefined;
7+
logo: { uri: string } | React.ReactNode | undefined;
68
logoSize: number;
79
logoBackgroundColor: string;
810
logoMargin: number;
911
logoBorderRadius: number;
1012
};
1113

14+
const defaultSvgString = ReactDOMServer.renderToString(cbwSvg);
15+
const defaultSvgDataUri = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
16+
defaultSvgString,
17+
)}`;
18+
1219
export function useLogo({
1320
size,
1421
logo,
@@ -18,25 +25,18 @@ export function useLogo({
1825
logoBorderRadius,
1926
}: RenderLogoProps) {
2027
const svgLogo = useMemo(() => {
21-
if (!logo) {
22-
return;
28+
let logoUri = defaultSvgDataUri;
29+
if (React.isValidElement(logo)) {
30+
logoUri = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
31+
ReactDOMServer.renderToString(logo),
32+
)}`;
2333
}
2434
const logoPosition = (size - logoSize - logoMargin * 2) / 2;
2535
const logoBackgroundSize = logoSize + logoMargin * 2;
26-
const logoBackgroundBorderRadius =
27-
logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius;
2836

2937
return (
3038
<g transform={`translate(${logoPosition}, ${logoPosition})`}>
3139
<defs>
32-
<clipPath id="clip-logo-background">
33-
<rect
34-
width={logoBackgroundSize}
35-
height={logoBackgroundSize}
36-
rx={logoBackgroundBorderRadius}
37-
ry={logoBackgroundBorderRadius}
38-
/>
39-
</clipPath>
4040
<clipPath id="clip-logo">
4141
<rect
4242
width={logoSize}
@@ -50,18 +50,19 @@ export function useLogo({
5050
<rect
5151
width={logoBackgroundSize}
5252
height={logoBackgroundSize}
53+
rx={logoBorderRadius}
54+
ry={logoBorderRadius}
5355
fill={logoBackgroundColor}
54-
clipPath="url(#clip-logo-background)"
5556
/>
5657
</g>
57-
<g x={logoMargin} y={logoMargin}>
58-
<g
58+
<g transform={`translate(${logoMargin}, ${logoMargin})`}>
59+
<image
5960
width={logoSize}
6061
height={logoSize}
62+
preserveAspectRatio="xMidYMid slice"
63+
href={logoUri}
6164
clipPath="url(#clip-logo)"
62-
>
63-
{logo}
64-
</g>
65+
/>
6566
</g>
6667
</g>
6768
);

src/internal/svg/cbwSvg.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { background, icon } from '../../styles/theme';
2-
3-
export const cbwSvg = (width: number, height: number) => (
1+
export const cbwSvg = (
42
<svg
5-
width={width}
6-
height={height}
3+
width={24}
4+
height={24}
75
viewBox="0 0 1024 1024"
86
xmlns="http://www.w3.org/2000/svg"
97
>
108
<title>Wallet Icon</title>
11-
<rect width="1024" height="1024" fill="#0052FF" />
9+
<rect width="100%" height="100%" fill="#0052FF" />
1210
<path
1311
fillRule="evenodd"
1412
clipRule="evenodd"

src/wallet/components/island/WalletIslandQrReceive.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { copySvg } from '../../../internal/svg/copySvg';
55
import { border, cn, color, pressable, text } from '../../../styles/theme';
66
import { useWalletContext } from '../WalletProvider';
77
import { useWalletIslandContext } from './WalletIslandProvider';
8-
import { cbwSvg } from '../../../internal/svg/cbwSvg';
98

109
export function WalletIslandQrReceive() {
1110
const { address } = useWalletContext();
@@ -46,10 +45,7 @@ export function WalletIslandQrReceive() {
4645
</button>
4746
</div>
4847

49-
<QRCodeComponent
50-
value={address ? `ethereum:${address}` : ''}
51-
logo={cbwSvg(24, 24)}
52-
/>
48+
<QRCodeComponent value={address ? `ethereum:${address}` : ''} />
5349

5450
<button
5551
type="button"

0 commit comments

Comments
 (0)