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

feature: Ordinals filtering modal #251

Merged
merged 4 commits into from
Oct 24, 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
15 changes: 15 additions & 0 deletions src/app/components/Connect/ConnectSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ interface ConnectSmallProps {
address: string;
btcWalletBalanceSat?: number;
onDisconnect: () => void;
shouldFilterOrdinals: boolean;
setShouldFilterOrdinals: (value: boolean) => void;
}

export const ConnectSmall: React.FC<ConnectSmallProps> = ({
onConnect,
address,
btcWalletBalanceSat,
onDisconnect,
shouldFilterOrdinals,
setShouldFilterOrdinals,
}) => {
const [showMenu, setShowMenu] = useState(false);
const handleClickOutside = () => {
Expand Down Expand Up @@ -106,6 +110,17 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({
<div className="flex flex-col">
<Hash value={address} address noFade fullWidth />
</div>
<div className="form-control">
<label className="label cursor-pointer">
<span className="label-text">Ordinals included</span>
<input
type="checkbox"
className="toggle toggle-primary"
checked={!shouldFilterOrdinals}
onChange={() => setShouldFilterOrdinals(!shouldFilterOrdinals)}
/>
</label>
</div>
<button
className="btn btn-outline btn-sm"
onClick={() => {
Expand Down
17 changes: 17 additions & 0 deletions src/app/components/Connect/ConnectedSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ interface ConnectedSmallProps {
address: string;
onDisconnect: () => void;
btcWalletBalanceSat?: number;
shouldFilterOrdinals: boolean;
setShouldFilterOrdinals: (value: boolean) => void;
}

export const ConnectedSmall: React.FC<ConnectedSmallProps> = ({
address,
btcWalletBalanceSat,
onDisconnect,
shouldFilterOrdinals,
setShouldFilterOrdinals,
}) => {
const [showMenu, setShowMenu] = useState(false);
const handleClickOutside = () => {
Expand Down Expand Up @@ -72,6 +76,19 @@ export const ConnectedSmall: React.FC<ConnectedSmallProps> = ({
<div className="flex flex-col">
<Hash value={address} address noFade fullWidth />
</div>
<div className="form-control">
<label className="label cursor-pointer">
<span className="label-text">Ordinals included</span>
<input
type="checkbox"
className="toggle toggle-primary"
checked={!shouldFilterOrdinals}
onChange={() =>
setShouldFilterOrdinals(!shouldFilterOrdinals)
}
/>
</label>
</div>
<button
className="btn btn-outline btn-sm"
onClick={() => {
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ interface HeaderProps {
address: string;
btcWalletBalanceSat?: number;
onDisconnect: () => void;
shouldFilterOrdinals: boolean;
setShouldFilterOrdinals: (value: boolean) => void;
}

export const Header: React.FC<HeaderProps> = ({
onConnect,
address,
btcWalletBalanceSat,
onDisconnect,
shouldFilterOrdinals,
setShouldFilterOrdinals,
}) => {
return (
<nav>
Expand All @@ -36,6 +40,8 @@ export const Header: React.FC<HeaderProps> = ({
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
shouldFilterOrdinals={shouldFilterOrdinals}
setShouldFilterOrdinals={setShouldFilterOrdinals}
/>
<ThemeToggle />
</div>
Expand All @@ -46,6 +52,8 @@ export const Header: React.FC<HeaderProps> = ({
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
shouldFilterOrdinals={shouldFilterOrdinals}
setShouldFilterOrdinals={setShouldFilterOrdinals}
/>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/Modals/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ export const ConnectModal: React.FC<ConnectModalProps> = ({
checked={noInscription}
/>
<span className="label-text text-xs leading-snug md:text-sm">
I certify that there are no Bitcoin inscriptions tokens in my
wallet.
I certify that staking bitcoin with ordinals, bitcoin NFTs,
Ruins, or any other bitcoin inscriptions can cause their
complete and permanent loss.
</span>
</label>
</div>
Expand Down
88 changes: 88 additions & 0 deletions src/app/components/Modals/FilterOrdinalsModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { IoMdClose } from "react-icons/io";

import { GeneralModal } from "./GeneralModal";

interface FilterOrdinalsModalProps {
open: boolean;
onClose: (value: boolean) => void;
shouldFilterOrdinals: boolean;
setShouldFilterOrdinals: (value: boolean) => void;
}

export const FilterOrdinalsModal: React.FC<FilterOrdinalsModalProps> = ({
open,
onClose,
shouldFilterOrdinals,
setShouldFilterOrdinals,
}) => {
return (
<GeneralModal open={open} onClose={onClose}>
<div className="mb-4 flex items-center justify-between">
<h3 className="font-bold">
Ordinals, Bitcoin NFTs, Runes, Bitcoin inscriptions
</h3>
<button
className="btn btn-circle btn-ghost btn-sm"
onClick={() => onClose(false)}
>
<IoMdClose size={24} />
</button>
</div>
<div className="flex flex-col gap-4 md:max-w-[34rem]">
<div className="flex flex-col gap-4 leading-snug text-sm">
<p>
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.
</p>
<p>Please select:</p>
</div>
<div className="flex flex-col gap-4 rounded-xl bg-base-100 p-3 md:p-4">
<div className="form-control">
<label className="label cursor-pointer justify-start gap-2">
<input
type="radio"
name="ordinals-radio"
className="radio checked:bg-primary"
checked={!shouldFilterOrdinals}
onChange={() => setShouldFilterOrdinals(false)}
/>
<span className="label-text">
I want to <strong>include</strong> ordinals, bitcoin NFTs,
Ruins, and any other bitcoin inscriptions in my stakable bitcoin
balance. I understand that doing so can cause their complete and
permanent loss and agree that I am solely liable and responsible
for their loss. I have been warned.
</span>
</label>
</div>
<div className="form-control">
<label className="label cursor-pointer justify-start gap-2">
<input
type="radio"
name="ordinals-radio"
className="radio checked:bg-primary"
checked={shouldFilterOrdinals}
onChange={() => setShouldFilterOrdinals(true)}
/>
<span className="label-text">
I would like to <strong>exclude</strong> ordinals, bitcoin NFTs,
Ruins, and any other bitcoin inscriptions in my stakable bitcoin
balance
</span>
</label>
</div>
</div>
<p className="text-xs opacity-50">
* You can change this setting later if needed
</p>
<button
className="btn-primary btn flex-1"
onClick={() => onClose(false)}
>
Confirm
</button>
</div>
</GeneralModal>
);
};
25 changes: 24 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Footer } from "./components/Footer/Footer";
import { Header } from "./components/Header/Header";
import { ConnectModal } from "./components/Modals/ConnectModal";
import { ErrorModal } from "./components/Modals/ErrorModal";
import { FilterOrdinalsModal } from "./components/Modals/FilterOrdinalsModal";
import { NetworkBadge } from "./components/NetworkBadge/NetworkBadge";
import { Staking } from "./components/Staking/Staking";
import { Stats } from "./components/Stats/Stats";
Expand Down Expand Up @@ -118,18 +119,31 @@ const Home: React.FC<HomeProps> = () => {
},
});

// Whether or not to filter out ordinals from the UTXOs
const [shouldFilterOrdinals, setShouldFilterOrdinals] = useState(true);

const [filterOrdinalsModalOpen, setFilterOrdinalsModalOpen] = useState(false);

const handleShouldFilterOrdinals = (value: boolean) => {
setShouldFilterOrdinals(value);
};

// Fetch all UTXOs
const {
data: availableUTXOs,
error: availableUTXOsError,
isError: hasAvailableUTXOsError,
refetch: refetchAvailableUTXOs,
} = useQuery({
queryKey: [UTXO_KEY, address],
queryKey: [UTXO_KEY, address, shouldFilterOrdinals],
queryFn: async () => {
if (btcWallet?.getUtxos && address) {
// all confirmed UTXOs from the wallet
const mempoolUTXOs = await btcWallet.getUtxos(address);

// return the UTXOs if we don't need to filter out the ordinals
if (!shouldFilterOrdinals) return mempoolUTXOs;

// filter out the ordinals
const filteredUTXOs = await filterOrdinals(
mempoolUTXOs,
Expand Down Expand Up @@ -230,6 +244,7 @@ const Home: React.FC<HomeProps> = () => {
setBTCWalletNetwork(toNetwork(await walletProvider.getNetwork()));
setAddress(address);
setPublicKeyNoCoord(publicKeyNoCoord.toString("hex"));
setFilterOrdinalsModalOpen(true);
} catch (error: Error | any) {
if (
error instanceof WalletError &&
Expand Down Expand Up @@ -324,6 +339,8 @@ const Home: React.FC<HomeProps> = () => {
onDisconnect={handleDisconnectBTC}
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
shouldFilterOrdinals={shouldFilterOrdinals}
setShouldFilterOrdinals={handleShouldFilterOrdinals}
/>
<div className="container mx-auto flex justify-center p-6">
<div className="container flex flex-col gap-6">
Expand Down Expand Up @@ -388,6 +405,12 @@ const Home: React.FC<HomeProps> = () => {
onConnect={handleConnectBTC}
connectDisabled={!!address}
/>
<FilterOrdinalsModal
open={filterOrdinalsModalOpen}
onClose={setFilterOrdinalsModalOpen}
shouldFilterOrdinals={shouldFilterOrdinals}
setShouldFilterOrdinals={handleShouldFilterOrdinals}
/>
<ErrorModal
open={isErrorOpen}
errorMessage={error.message}
Expand Down