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

Release/utxo protection fixes #6046

Merged
merged 9 commits into from
Dec 26, 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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.15.1",
"webpack-hot-middleware": "2.26.1",
"webpack-shell-plugin": "0.5.0"
"webpack-shell-plugin": "0.5.0",
"type-fest": "4.30.2"
},
"resolutions": {
"cross-spawn": "7.0.5",
Expand Down
16 changes: 9 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions src/app/components/account/account-addresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import { HStack } from 'leather-styles/jsx';
import { BulletSeparator, Caption } from '@leather.io/ui';
import { truncateMiddle } from '@leather.io/utils';

import { BitcoinNativeSegwitAccountLoader } from '../loaders/bitcoin-account-loader';
import { StacksAccountLoader } from '../loaders/stacks-account-loader';
import { useBitcoinNativeSegwitAccountLoader } from '../loaders/bitcoin-account-loader';
import { useStacksAccountLoader } from '../loaders/stacks-account-loader';

interface AccountAddressesProps {
index: number;
}
export function AcccountAddresses({ index }: AccountAddressesProps) {
const account = useStacksAccountLoader({ index });
const signer = useBitcoinNativeSegwitAccountLoader({ index });
return (
<HStack alignItems="center" gap="space.02" whiteSpace="nowrap">
<BulletSeparator>
<StacksAccountLoader index={index}>
{account => <Caption>{truncateMiddle(account.address, 4)}</Caption>}
</StacksAccountLoader>
<BitcoinNativeSegwitAccountLoader index={index}>
{signer => <Caption>{truncateMiddle(signer.address, 4)}</Caption>}
</BitcoinNativeSegwitAccountLoader>
{account ? <Caption>{truncateMiddle(account.address, 4)}</Caption> : null}
{signer ? <Caption>{truncateMiddle(signer.address, 4)}</Caption> : null}
</BulletSeparator>
</HStack>
);
Expand Down
23 changes: 16 additions & 7 deletions src/app/components/loaders/bitcoin-account-loader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { P2Ret } from '@scure/btc-signer/payment';
import type { DistributedOmit } from 'type-fest';

import { useConfigBitcoinEnabled } from '@app/query/common/remote-config/remote-config.query';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
Expand All @@ -20,11 +21,9 @@ interface BtcAccountLoaderIndexProps extends BitcoinAccountLoaderBaseProps {

type BtcAccountLoaderProps = BtcAccountLoaderCurrentProps | BtcAccountLoaderIndexProps;

export function BitcoinNativeSegwitAccountLoader({
children,
fallback,
...props
}: BtcAccountLoaderProps) {
export function useBitcoinNativeSegwitAccountLoader(
props: DistributedOmit<BtcAccountLoaderProps, 'children' | 'fallback'>
) {
const isBitcoinEnabled = useConfigBitcoinEnabled();

const currentAccountIndex = useCurrentAccountIndex();
Expand All @@ -33,8 +32,18 @@ export function BitcoinNativeSegwitAccountLoader({

const signer = useNativeSegwitSigner(properIndex);

if (!signer || !isBitcoinEnabled) return fallback;
return children(signer(0));
if (!signer || !isBitcoinEnabled) return null;
return signer(0);
}

export function BitcoinNativeSegwitAccountLoader({
children,
fallback,
...props
}: BtcAccountLoaderProps) {
const signer = useBitcoinNativeSegwitAccountLoader(props);
if (!signer) return fallback;
return children(signer);
}

export function BitcoinTaprootAccountLoader({ children, ...props }: BtcAccountLoaderProps) {
Expand Down
8 changes: 6 additions & 2 deletions src/app/components/loaders/stacks-account-loader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ReactNode } from 'react';

import type { DistributedOmit } from 'type-fest';

import { useCurrentAccountIndex } from '@app/store/accounts/account';
import {
useCurrentStacksAccount,
Expand Down Expand Up @@ -34,12 +36,14 @@ interface StacksAccountIndexLoaderProps extends StacksAccountBaseLoaderProps {

type StacksAccountLoaderProps = StacksAccountCurrentLoaderProps | StacksAccountIndexLoaderProps;

export function StacksAccountLoader({ children, ...props }: StacksAccountLoaderProps) {
export function useStacksAccountLoader(
props: DistributedOmit<StacksAccountLoaderProps, 'children'>
) {
const stacksAccounts = useStacksAccounts();
const currentAccountIndex = useCurrentAccountIndex();
const properIndex = 'current' in props ? currentAccountIndex : props.index;

const account = stacksAccounts[properIndex];
if (!account) return null;
return children(account);
return account;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function ConnectLedgerButton({ chain }: ConnectLedgerButtonProps) {
};

return (
<Button variant="outline" onClick={onClick}>
<Button variant="outline" size="sm" onClick={onClick}>
<HStack>
<LedgerIcon />
<styled.span textStyle="label.02">Connect&nbsp;{capitalize(chain)}</styled.span>
Expand Down
28 changes: 21 additions & 7 deletions src/app/features/collectibles/components/bitcoin/inscription.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';

import { Box } from 'leather-styles/jsx';
import { Box, styled } from 'leather-styles/jsx';

import { type Inscription } from '@leather.io/models';
import {
Expand Down Expand Up @@ -128,30 +128,44 @@ export function Inscription({ inscription }: InscriptionProps) {
position="absolute"
right="space.03"
top="space.03"
zIndex="90"
zIndex="900"
>
<DropdownMenu.Root>
<DropdownMenu.Trigger>
<IconButton
_focus={{ outline: 'focus' }}
_hover={{ bg: 'ink.component-background-hover' }}
bg="ink.background-primary"
border="1px solid"
borderColor="ink.text-primary"
borderRadius="2px"
transform="rotate(90deg)"
color="ink.action-primary-default"
icon={<EllipsisVIcon variant="small" />}
icon={<EllipsisVIcon />}
/>
</DropdownMenu.Trigger>
<DropdownMenu.Content side="bottom" style={{ marginRight: '96px' }}>
<DropdownMenu.Content
align="end"
side="bottom"
sideOffset={4}
style={{ padding: '8px' }}
>
<DropdownMenu.Item onClick={() => openInscriptionUrl(inscription.number)}>
<Flag img={<ExternalLinkIcon variant="small" />}>Open original</Flag>
<Flag img={<ExternalLinkIcon />}>
<styled.span textStyle="label.02">Open original</styled.span>
</Flag>
</DropdownMenu.Item>
{hasInscriptionBeenDiscarded(inscription) ? (
<DropdownMenu.Item onClick={() => recoverInscription(inscription)}>
<Flag img={<LockIcon variant="small" />}>Protect</Flag>
<Flag img={<LockIcon />}>
<styled.span textStyle="label.02">Protect</styled.span>
</Flag>
</DropdownMenu.Item>
) : (
<DropdownMenu.Item onClick={() => discardInscription(inscription)}>
<Flag img={<UnlockIcon variant="small" />}>Unprotect</Flag>
<Flag img={<UnlockIcon />}>
<styled.span textStyle="label.02">Unprotect</styled.span>
</Flag>
</DropdownMenu.Item>
)}
</DropdownMenu.Content>
Expand Down
11 changes: 7 additions & 4 deletions src/app/ui/components/account/account.card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import {
shimmerStyles,
} from '@leather.io/ui';

import { useViewportMinWidth } from '@app/common/hooks/use-media-query';
import { useScaleText } from '@app/common/hooks/use-scale-text';
import { AccountNameLayout } from '@app/components/account/account-name';
import { PrivateTextLayout } from '@app/components/privacy/private-text.layout';

import { BasicTooltip } from '../tooltip/basic-tooltip';

const availableBalanceTooltipLabel =
'Total balance minus outbound transfers, protected collectibles and uneconomical UTXOs.';

interface AccountCardProps {
name: string;
availableBalance: string;
Expand All @@ -45,6 +49,8 @@ export function AccountCard({
isBalancePrivate,
}: AccountCardProps) {
const scaleTextRef = useScaleText();
const isAtLeastMd = useViewportMinWidth('md');
const tooltipSide = isAtLeastMd ? 'right' : 'bottom';

return (
<Flex
Expand Down Expand Up @@ -106,10 +112,7 @@ export function AccountCard({
<styled.h2 textStyle="label.02" color="ink.text-subdued" mt="space.01">
Available balance:
<styled.span ml="space.01">
<BasicTooltip
side="right"
label="Some funds may be unavailable to protect your collectible assets. Disable protection to access your remaining balance."
>
<BasicTooltip side={tooltipSide} label={availableBalanceTooltipLabel}>
<Flag
reverse
spacing="space.01"
Expand Down
Loading