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

Feat/add ignore inscriptions UI #6028

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Conversation

kyranjamie
Copy link
Collaborator

@kyranjamie kyranjamie commented Dec 18, 2024

Try out Leather build 67589f4Extension build, Test report, Storybook, Chromatic

This PR adds more granular control for UTXOs. Now we track discarded UTXOs in setting slice, by txid:vout:offset.

A user might discard an one inscription on a UTXO, but not the second one, on the same UTXO. A UTXO is only spendable if all inscriptions on it are discarded.

In the UI, there's a dropdown from which users can "unprotect" inscriptions. This helps users spend funds with trash BRC-20 inscriptions on them.

This feature only works for native segwit inscriptions. Protecting/unprotecting taproot inscriptions does nothing. The UI is functional but not perfect, e.g. how hover events work on the inscription cards.

Next year, I want to jump straight on a refactor of this work. Much code here should live elsewhere, and all UTXOs should be treated equal, regardless of payment type.

@kyranjamie kyranjamie force-pushed the feat/add-ignore-inscriptions-ui branch 4 times, most recently from 57bb153 to 175048f Compare December 20, 2024 16:39
if (!featureBuilt) return null;
return (
<Box position="absolute" top="space.01" right="space.01">
<BasicTooltip label="This inscription has loads of BTC on it, remove protections? Click">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly specify the amount instead of "loads"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is disabled for now, but yeah would be better to specify

<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."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit more specificity on where: "... You can ensure those fund are available by disabling protection in the collectible menu."

@camerow

This comment was marked as resolved.

@kyranjamie kyranjamie force-pushed the feat/add-ignore-inscriptions-ui branch 8 times, most recently from db4f120 to 2164df7 Compare December 23, 2024 11:50
Copy link
Contributor

@edgarkhanzadian edgarkhanzadian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My biggest concern is the empty strings that we pass around. Other than that, looks awesome! 🚀

availableBalance,
availableUsdBalance: i18nFormatCurrency(
availableBalance,
availableBalance.amount.isGreaterThanOrEqualTo(100_000) ? 0 : 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move 100_000 to a constant

}

export function HighSatValueUtxoWarning({ inscription }: HighSatValueUtxoProps) {
if (Number(inscription.value) < 5_000) return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 5_000 constant too. Should this be a part of a wallet config?


import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';

const featureBuilt = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good place for launch darkly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could delete this as we're not using it, but hoping to add some kind of warning when revisiting this

Comment on lines +54 to +77
const content = useMemo(() => {
const sharedProps = { onClickSend: () => openSendInscriptionModal() };
switch (inscription.mimeType) {
case 'audio':
return (
<CollectibleAudio
icon={<OrdinalAvatarIcon size="lg" />}
key={inscription.title}
subtitle="Ordinal inscription"
title={`# ${inscription.number}`}
{...sharedProps}
/>
);
case 'html':
case 'svg':
case 'video':
case 'gltf':
return (
<CollectibleIframe
icon={<OrdinalAvatarIcon size="lg" />}
key={inscription.title}
src={inscription.src}
subtitle="Ordinal inscription"
title={`# ${inscription.number}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest making this a separate component that receives inscription instead of creating a component in useMemo


// Utxos but don't filter the inscribed ones
const { data: nativeSegwitUtxos } = useNativeSegwitUtxosByAddress({
address: address ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using undefined or null instead of empty string here. Typescript can help us with null/undefined while it can't do so with empty strings

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree and only did this as I'm trying to get it done quickly before Christmas.

The way I see it, resorting to empty strings here (as done in many other places), is symptomatic of poor patterns around how we pass and handle state.

I've been thinking about this with this work. One solution would be to use feature container components to handle null cases, and set state in contexts state such that it can be consumed without the need to inline null fallbacks in every case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a type signature hole useNativeSegwitUtxosByAddress, but I think we should address using placeholder values in the codebase (lots of those) in future by tightening up the contracts.

const { totalUsdBalance, availableUsdBalance, isPending, isLoadingAdditionalData } =
useAvailableBalance({
btcAddress,
stxAddress: account?.address || '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here regarding the empty string

src/app/query/bitcoin/address/utxos-by-address.hooks.ts Outdated Show resolved Hide resolved
@kyranjamie kyranjamie force-pushed the feat/add-ignore-inscriptions-ui branch from 2164df7 to d5a30dd Compare December 23, 2024 12:20
src/app/common/hooks/use-hover-with-children.ts Outdated Show resolved Hide resolved
</CollectibleOther>
);
default:
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if mimeType exhaustiveness is important here, I added an assertUnreachable to utils package do make sure it errors for uncovered cases.


// Utxos but don't filter the inscribed ones
const { data: nativeSegwitUtxos } = useNativeSegwitUtxosByAddress({
address: address ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a type signature hole useNativeSegwitUtxosByAddress, but I think we should address using placeholder values in the codebase (lots of those) in future by tightening up the contracts.

@kyranjamie kyranjamie force-pushed the feat/add-ignore-inscriptions-ui branch 2 times, most recently from 9cf5924 to 9f6a04a Compare December 23, 2024 12:27
@kyranjamie kyranjamie force-pushed the feat/add-ignore-inscriptions-ui branch from 9f6a04a to 67589f4 Compare December 23, 2024 12:28
@kyranjamie
Copy link
Collaborator Author

Thanks for your reviews all, unaddressed feedback I will work on when refactoring this in the new year

@kyranjamie kyranjamie merged commit fbb2fed into dev Dec 23, 2024
32 checks passed
@kyranjamie kyranjamie deleted the feat/add-ignore-inscriptions-ui branch December 23, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants