From 56ebe6fa25da9773beb990c47c075f2880cedf0c Mon Sep 17 00:00:00 2001 From: Govard Barkhatov Date: Tue, 29 Oct 2024 07:16:54 +0200 Subject: [PATCH] feature: Resolve filter ordinals (#258) * feature: Ordinals filtering modal (#251) * ordinals filtering modal * certify * update wording * title and may contain * resolve filter ordinals (main to dev) * filter ordinals is a part of btc wallet provider * rm should filter ordinals from useUTXOs * TODO ordinals wording * initial move * rm unused comment * rename var --- src/app/components/Connect/ConnectSmall.tsx | 14 +++ src/app/components/Connect/ConnectedSmall.tsx | 16 ++++ .../components/Modals/FilterOrdinalsModal.tsx | 91 +++++++++++++++++++ src/app/context/wallet/BTCWalletProvider.tsx | 2 +- .../wallet/WalletConnectionProvider.tsx | 1 + src/app/hooks/api/useUTXOs.ts | 9 +- src/app/page.tsx | 2 + src/app/state/index.tsx | 49 ++++++++-- 8 files changed, 172 insertions(+), 12 deletions(-) create mode 100644 src/app/components/Modals/FilterOrdinalsModal.tsx diff --git a/src/app/components/Connect/ConnectSmall.tsx b/src/app/components/Connect/ConnectSmall.tsx index e9d0146c..ea7f46d6 100644 --- a/src/app/components/Connect/ConnectSmall.tsx +++ b/src/app/components/Connect/ConnectSmall.tsx @@ -7,6 +7,7 @@ import { Tooltip } from "react-tooltip"; import { useOnClickOutside } from "usehooks-ts"; import { useHealthCheck } from "@/app/hooks/useHealthCheck"; +import { useAppState } from "@/app/state"; import { getNetworkConfig } from "@/config/network.config"; import { satoshiToBtc } from "@/utils/btcConversions"; import { maxDecimals } from "@/utils/maxDecimals"; @@ -30,6 +31,8 @@ export const ConnectSmall: React.FC = ({ btcWalletBalanceSat, onDisconnect, }) => { + const { ordinalsExcluded, includeOrdinals, excludeOrdinals } = useAppState(); + const [showMenu, setShowMenu] = useState(false); const handleClickOutside = () => { setShowMenu(false); @@ -110,6 +113,17 @@ export const ConnectSmall: React.FC = ({
+
+ +
+ +
+
+

+ Your wallet may contain Bitcoin Ordinals, which are unique digital + assets. If you proceed without filtering, these Ordinals could be + included in future actions involving your balance. +

+

Please select:

+
+
+
+ +
+
+ +
+
+

+ * You can change this setting later if needed +

+ +
+ + ); +}; diff --git a/src/app/context/wallet/BTCWalletProvider.tsx b/src/app/context/wallet/BTCWalletProvider.tsx index 99d24069..7e0d67d9 100644 --- a/src/app/context/wallet/BTCWalletProvider.tsx +++ b/src/app/context/wallet/BTCWalletProvider.tsx @@ -79,7 +79,7 @@ export const BTCWalletProvider = ({ children }: PropsWithChildren) => { const [address, setAddress] = useState(""); const { showError } = useError(); - const { open, disconnect, isConnected, providers } = useWalletConnection(); + const { open, isConnected, providers } = useWalletConnection(); const btcDisconnect = useCallback(() => { setBTCWalletProvider(undefined); diff --git a/src/app/context/wallet/WalletConnectionProvider.tsx b/src/app/context/wallet/WalletConnectionProvider.tsx index cfe7a644..d96c94b0 100644 --- a/src/app/context/wallet/WalletConnectionProvider.tsx +++ b/src/app/context/wallet/WalletConnectionProvider.tsx @@ -32,6 +32,7 @@ export const WalletConnectionProvider = ({ children }: PropsWithChildren) => { { if (!getUtxos || !address) { @@ -14,6 +16,11 @@ export function useUTXOs({ enabled = true }: { enabled?: boolean } = {}) { } const mempoolUTXOs = await getUtxos(address); + // Return UTXOs without filtering if not required + if (!ordinalsExcluded) { + return mempoolUTXOs; + } + const filteredUTXOs = await filterOrdinals( mempoolUTXOs, address, @@ -24,7 +31,7 @@ export function useUTXOs({ enabled = true }: { enabled?: boolean } = {}) { }; const data = useAPIQuery({ - queryKey: [UTXO_KEY, address], + queryKey: [UTXO_KEY, address, ordinalsExcluded], queryFn: fetchAvailableUTXOs, enabled: Boolean(getUtxos) && Boolean(address) && enabled, refetchInterval: 5 * ONE_MINUTE, diff --git a/src/app/page.tsx b/src/app/page.tsx index effd1ad3..4e79bd57 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -7,6 +7,7 @@ import { DelegationTabs } from "./components/Delegations/DelegationTabs"; import { FAQ } from "./components/FAQ/FAQ"; import { Footer } from "./components/Footer/Footer"; import { Header } from "./components/Header/Header"; +import { FilterOrdinalsModal } from "./components/Modals/FilterOrdinalsModal"; import { NetworkBadge } from "./components/NetworkBadge/NetworkBadge"; import { PersonalBalance } from "./components/PersonalBalance/PersonalBalance"; import { Staking } from "./components/Staking/Staking"; @@ -31,6 +32,7 @@ const Home = () => {