Skip to content

Commit

Permalink
feat(ledger): ui to ignore inscriptions
Browse files Browse the repository at this point in the history
chore: discard inscriptions

chore: global checks switch

wip

chore: track satpoint as well as vout

chore: track spendable utxos, add them back to queries

chore: add total balance set up

chore: add tooltip to total balance

feat: add recover/unrecover ui

fix: flip the balances

fix: filter inscriptions ext side

fix: hover with parent check for fab

feat: add subdued colour to icon

fix: skip ids of spendable insciptions
  • Loading branch information
kyranjamie committed Dec 23, 2024
1 parent bf225fc commit 9768e0f
Show file tree
Hide file tree
Showing 21 changed files with 478 additions and 143 deletions.
42 changes: 30 additions & 12 deletions src/app/common/hooks/balance/use-total-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { useBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance

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

interface UseTotalBalanceArgs {
interface UseAvailableBalanceArgs {
btcAddress: string;
stxAddress: string;
}
export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs) {
export function useAvailableBalance({ btcAddress, stxAddress }: UseAvailableBalanceArgs) {
// get market data
const btcMarketData = useCryptoCurrencyMarketDataMeanAverage('BTC');
const stxMarketData = useCryptoCurrencyMarketDataMeanAverage('STX');
Expand Down Expand Up @@ -46,19 +46,36 @@ 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(100_000) ? 0 : 2
),
totalUsdBalance: i18nFormatCurrency(
totalBalance,
totalBalance.amount.isGreaterThanOrEqualTo(100_000) ? 0 : 2
Expand All @@ -67,20 +84,21 @@ export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs)
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 const useHoverWithChildren = (): [boolean, HoverBind] => {
const [isHovered, setIsHovered] = useState<boolean>(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 { useAvailableBalance } from '@app/common/hooks/balance/use-total-balance';
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 } = useAvailableBalance({
btcAddress,
stxAddress,
});
Expand Down
3 changes: 3 additions & 0 deletions src/app/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const debug = {
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;

interface HighSatValueUtxoProps {
inscription: Inscription;
}

export function HighSatValueUtxoWarning({ inscription }: HighSatValueUtxoProps) {
if (Number(inscription.value) < 5_000) return null;
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">
<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

0 comments on commit 9768e0f

Please sign in to comment.