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
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { useBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance

import { useSip10ManagedTokensBalance } from './use-sip10-balance';

interface UseTotalBalanceArgs {
const highBalance = createMoney(100_000, 'USD');

interface UseBalanceArgs {
btcAddress: string;
stxAddress: string;
}
export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs) {
export function useBalances({ btcAddress, stxAddress }: UseBalanceArgs) {
// get market data
const btcMarketData = useCryptoCurrencyMarketDataMeanAverage('BTC');
const stxMarketData = useCryptoCurrencyMarketDataMeanAverage('STX');
Expand Down Expand Up @@ -46,41 +48,59 @@ export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs)
return useMemo(() => {
// calculate total balance
const stxUsdAmount = baseCurrencyAmountInQuote(stxBalance, stxMarketData);
const btcUsdAmount = baseCurrencyAmountInQuote(btcBalance.availableBalance, btcMarketData);

const availableBtcUsdAmount = baseCurrencyAmountInQuote(
btcBalance.availableBalance,
btcMarketData
);

const totalBtcUsdAmount = baseCurrencyAmountInQuote(btcBalance.totalBalance, btcMarketData);

const totalBalance = {
...stxUsdAmount,
amount: stxUsdAmount.amount.plus(btcUsdAmount.amount).plus(sip10BalanceUsd.amount),
amount: stxUsdAmount.amount.plus(totalBtcUsdAmount.amount).plus(sip10BalanceUsd.amount),
};

const availableBalance = {
...stxUsdAmount,
amount: stxUsdAmount.amount.plus(availableBtcUsdAmount.amount).plus(sip10BalanceUsd.amount),
};

return {
isFetching: isFetchingStxBalance || isFetchingBtcBalance,
isLoading: isLoadingStxBalance || isLoadingBtcBalance,
isPending:
(isPendingStxBalance && Boolean(stxAddress)) ||
(isPendingBtcBalance && Boolean(btcAddress)),
totalBalance,
availableBalance,
availableUsdBalance: i18nFormatCurrency(
availableBalance,
availableBalance.amount.isGreaterThanOrEqualTo(highBalance.amount) ? 0 : 2
),
totalUsdBalance: i18nFormatCurrency(
totalBalance,
totalBalance.amount.isGreaterThanOrEqualTo(100_000) ? 0 : 2
totalBalance.amount.isGreaterThanOrEqualTo(highBalance.amount) ? 0 : 2
),
isLoadingAdditionalData:
isLoadingAdditionalDataStxBalance || isLoadingAdditionalDataBtcBalance,
};
}, [
stxBalance,
stxMarketData,
btcBalance.availableBalance,
btcBalance.totalBalance,
btcMarketData,
isFetchingBtcBalance,
sip10BalanceUsd.amount,
isFetchingStxBalance,
isLoadingBtcBalance,
isFetchingBtcBalance,
isLoadingStxBalance,
isPendingBtcBalance,
isLoadingBtcBalance,
isPendingStxBalance,
stxBalance,
stxMarketData,
isLoadingAdditionalDataBtcBalance,
isLoadingAdditionalDataStxBalance,
stxAddress,
isPendingBtcBalance,
btcAddress,
sip10BalanceUsd,
isLoadingAdditionalDataStxBalance,
isLoadingAdditionalDataBtcBalance,
]);
}
32 changes: 32 additions & 0 deletions src/app/common/hooks/use-hover-with-children.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useCallback, useState } from 'react';

interface HoverBind {
onMouseEnter(event: React.MouseEvent<HTMLElement, MouseEvent>): void;
onMouseLeave(event: React.MouseEvent<HTMLElement, MouseEvent>): void;
}

export function useHoverWithChildren(): [boolean, HoverBind] {
const [isHovered, setIsHovered] = useState(false);

const handleMouseEnter = useCallback(() => {
setIsHovered(true);
}, []);

const handleMouseLeave = useCallback((event: React.MouseEvent<HTMLElement, MouseEvent>) => {
const relatedTarget = event.relatedTarget as HTMLElement;

// If the related target is a child of the current element, don't trigger mouseleave
if (event.currentTarget.contains(relatedTarget)) {
return;
}

setIsHovered(false);
}, []);

const bind: HoverBind = {
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
};

return [isHovered, bind];
}
4 changes: 2 additions & 2 deletions src/app/components/account-total-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { styled } from 'leather-styles/jsx';

import { SkeletonLoader, shimmerStyles } from '@leather.io/ui';

import { useTotalBalance } from '@app/common/hooks/balance/use-total-balance';
import { useBalances } from '@app/common/hooks/balance/use-balances';
import { PrivateText } from '@app/components/privacy/private-text';

interface AccountTotalBalanceProps {
Expand All @@ -13,7 +13,7 @@ interface AccountTotalBalanceProps {
}

export const AccountTotalBalance = memo(({ btcAddress, stxAddress }: AccountTotalBalanceProps) => {
const { totalUsdBalance, isFetching, isLoading, isLoadingAdditionalData } = useTotalBalance({
const { totalUsdBalance, isFetching, isLoading, isLoadingAdditionalData } = useBalances({
btcAddress,
stxAddress,
});
Expand Down
6 changes: 6 additions & 0 deletions src/app/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const debug = {
chrome.storage.local.clear();
chrome.storage.session.clear();
},
bypassInscriptionChecks() {
store.dispatch(settingsSlice.actions.dangerouslyChosenToBypassAllInscriptionChecks());
},
resetInscriptionState() {
store.dispatch(settingsSlice.actions.resetInscriptionState());
},
};

export function setDebugOnGlobal() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Box, Circle } from 'leather-styles/jsx';

import type { Inscription } from '@leather.io/models';

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


interface HighSatValueUtxoProps {
inscription: Inscription;
}

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?

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

<Circle bg="red" size="sm" />
</BasicTooltip>
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CollectibleText } from '../_collectible-types/collectible-text';
interface InscriptionTextProps {
contentSrc: string;
inscriptionNumber: number;
onClickCallToAction(): void;
onClickCallToAction?(): void;
onClickSend(): void;
}
export function InscriptionText({
Expand Down
Loading
Loading