Skip to content

Commit

Permalink
lint, simplify AddressViewComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Aug 26, 2024
1 parent 612e2db commit 5ca52ce
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions packages/ui/src/AddressViewComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styled from 'styled-components';
import { Text } from '../Text';
import { CopyToClipboardButton } from '../CopyToClipboardButton';
import { Shrink0 } from '../utils/Shrink0';
import { getAddressIndex } from '@penumbra-zone/getters/address-view';

const Root = styled.div`
display: flex;
Expand All @@ -24,18 +25,10 @@ export const AddressViewComponent = ({ addressView, copyable = true }: AddressVi
return null;
}

const accountIndex =
addressView.addressView.case === 'decoded'
? addressView.addressView.value.index?.account
: undefined;
const isOneTimeAddress =
addressView.addressView.case === 'decoded'
? !addressView.addressView.value.index?.randomizer.every(v => v === 0) // Randomized (and thus, a one-time address) if the randomizer is not all zeros.
: undefined;
const addressIndex = getAddressIndex.optional()(addressView);

const addressIndexLabel = isOneTimeAddress ? 'IBC Deposit Address for Account #' : 'Account #';

copyable = isOneTimeAddress ? false : copyable;
// a randomized index has nonzero randomizer bytes
const isRandomized = addressIndex?.randomizer.some(v => v);

const encodedAddress = bech32mAddress(addressView.addressView.value.address);

Expand All @@ -45,18 +38,18 @@ export const AddressViewComponent = ({ addressView, copyable = true }: AddressVi
<AddressIcon address={addressView.addressView.value.address} size={24} />
</Shrink0>

{accountIndex === undefined ? (
<Text technical truncate>
{encodedAddress}
{addressIndex ? (
<Text strong truncate>
{isRandomized && 'IBC Deposit Address for '}
{`Account #${addressIndex.account}`}
</Text>
) : (
<Text strong truncate>
{addressIndexLabel}
{accountIndex}
<Text technical truncate>
{encodedAddress}
</Text>
)}

{copyable && (
{copyable && !isRandomized && (
<Shrink0>
<CopyToClipboardButton text={encodedAddress} />
</Shrink0>
Expand Down

0 comments on commit 5ca52ce

Please sign in to comment.