Skip to content

Commit

Permalink
feat: address displayer
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Mar 18, 2024
1 parent faa3a79 commit 7f72f15
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { Box, BoxProps } from 'leather-styles/jsx';

import { AddressDisplayer } from './address-displayer';
import { AddressDisplayer } from '@app/ui/components/address-displayer/address-displayer';

interface FormAddressDisplayerProps extends BoxProps {
address: string;
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/app-version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const AppVersionLabel = forwardRef<HTMLSpanElement, AppVersionLabelProps>(
({ children, isLatestVersion, ...props }: AppVersionLabelProps, ref) => (
<styled.span
ref={ref}
textStyle="mono.02"
textStyle="code"
fontSize="10px"
marginRight="10px"
mb="-4px"
ml="space.02"
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/receive/components/receive-tokens.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { SharedComponentsSelectors } from '@tests/selectors/shared-component.sel
import { Box, Flex, styled } from 'leather-styles/jsx';

import { useLocationState } from '@app/common/hooks/use-location-state';
import { AddressDisplayer } from '@app/components/address-displayer/address-displayer';
import { BaseDrawer } from '@app/components/drawer/base-drawer';
import { useBackgroundLocationRedirect } from '@app/routes/hooks/use-background-location-redirect';
import { AddressDisplayer } from '@app/ui/components/address-displayer/address-displayer';
import { Button } from '@app/ui/components/button/button';

import { QrCode } from './address-qr-code';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export function BroadcastErrorLayout(props: BroadcastErrorProps) {
mx="space.05"
p="space.04"
textAlign="left"
textStyle="mono.02"
textStyle="code"
fontSize="10px"
wordBreak="break-all"
>
{errorPayload}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from 'leather-styles/jsx';
import { type HTMLStyledProps, styled } from 'leather-styles/jsx';

interface AddressDisplayerLayoutProps {
interface AddressDisplayerLayoutProps extends HTMLStyledProps<'span'> {
isEven: boolean;
children: React.ReactNode;
}
Expand All @@ -9,7 +9,7 @@ export function AddressDisplayerLayout({ isEven, ...props }: AddressDisplayerLay
<styled.span
color={isEven ? 'ink.text-primary' : 'ink.text-subdued'}
mr="space.02"
textStyle="mono.01"
textStyle="code"
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Flex } from 'leather-styles/jsx';

import { BtcAvatarIcon } from '../avatar/btc-avatar-icon';
import { StxAvatarIcon } from '../avatar/stx-avatar-icon';
import { Flag } from '../flag/flag';
import { AddressDisplayer as Component } from './address-displayer';

const meta: Meta<typeof Component> = {
component: Component,
tags: ['autodocs'],
title: 'AddressDisplayer',
parameters: {
controls: { include: ['address'] },
},
};

export default meta;
type Story = StoryObj<typeof Component>;

export const Bitcoin: Story = {
args: {
address: 'bc1pmzfrwwndsqmk5yh69yjr5lfgfg4ev8c0tsc06e',
},
};

export const Stacks: Story = {
args: {
address: 'SP3XKZE32KZ925AAAGWPG1W66YP5BM2RD73T6AJHS',
},
};

export const WithBTCIcon: Story = {
args: {
address: 'bc1pmzfrwwndsqmk5yh69yjr5lfgfg4ev8c0tsc06e',
},
render: args => (
<Flag img={<BtcAvatarIcon />}>
<Flex flexWrap="wrap" maxWidth="400px">
<Component address={args.address} />
</Flex>
</Flag>
),
};

export const WithSTXIcon: Story = {
args: {
address: 'SP3XKZE32KZ925AAAGWPG1W66YP5BM2RD73T6AJHS',
},
render: args => (
<Flag img={<StxAvatarIcon />}>
<Flex flexWrap="wrap" maxWidth="400px">
<Component address={args.address} />
</Flex>
</Flag>
),
};
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import type { HTMLStyledProps } from 'leather-styles/types';

import { isEven } from '@app/common/math/helpers';

import { AddressDisplayerLayout } from './address-displayer.layout';
import { groupByFour } from './address-displayer.utils';

function groupByFour(text: string) {
const result = [];

for (let i = 0; i < text.length; i += 4) {
result.push(text.slice(i, i + 4));
}

return result;
}

interface AddressDisplayerProps {
interface AddressDisplayerProps extends HTMLStyledProps<'span'> {
address: string;
}
export function AddressDisplayer({ address }: AddressDisplayerProps) {
export function AddressDisplayer({ address, ...props }: AddressDisplayerProps) {
return (
<>
{groupByFour(address).map((letterGroup, index) => (
<AddressDisplayerLayout key={index} isEven={isEven(index + 1)}>
<AddressDisplayerLayout key={index} isEven={isEven(index + 1)} {...props}>
{letterGroup}
</AddressDisplayerLayout>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function groupByFour(text: string) {
const result = [];
for (let i = 0; i < text.length; i += 4) {
result.push(text.slice(i, i + 4));
}
return result;
}

0 comments on commit 7f72f15

Please sign in to comment.