Skip to content

Commit

Permalink
filter ordinals modal show once main (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarkhatov authored Oct 31, 2024
1 parent 8c5ab7a commit c2ef3a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const OVERFLOW_TVL_WARNING_THRESHOLD = 0.2;
export const OVERFLOW_HEIGHT_WARNING_THRESHOLD = 3;
export const UTXO_KEY = "UTXOs";
export const FILTER_ORDINALS_MODAL_KEY = "bbn-staking-filter-ordinals-modal";
24 changes: 20 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Network, WalletProvider } from "@/utils/wallet/wallet_provider";

import { getDelegations, PaginatedDelegations } from "./api/getDelegations";
import { getGlobalParams } from "./api/getGlobalParams";
import { UTXO_KEY } from "./common/constants";
import { FILTER_ORDINALS_MODAL_KEY, UTXO_KEY } from "./common/constants";
import { signPsbtTransaction } from "./common/utils/psbt";
import { Delegations } from "./components/Delegations/Delegations";
import { FAQ } from "./components/FAQ/FAQ";
Expand Down Expand Up @@ -213,6 +213,9 @@ const Home: React.FC<HomeProps> = () => {
setConnectModalOpen(true);
};

const [hasSeenFilterOrdinalsModal, setHasSeenFilterOrdinalsModal] =
useLocalStorage<Record<string, boolean>>(FILTER_ORDINALS_MODAL_KEY, {});

const { logTermsAcceptance } = useTermsAcceptance();
const handleDisconnectBTC = useCallback(() => {
setBTCWallet(undefined);
Expand Down Expand Up @@ -245,7 +248,12 @@ const Home: React.FC<HomeProps> = () => {
setBTCWalletNetwork(toNetwork(await walletProvider.getNetwork()));
setAddress(address);
setPublicKeyNoCoord(publicKeyNoCoord.toString("hex"));
setFilterOrdinalsModalOpen(true);

// Show the modal only if it hasn't been seen before for the address
if (!hasSeenFilterOrdinalsModal[address]) {
setFilterOrdinalsModalOpen(true);
}

// Log the terms acceptance
logTermsAcceptance({
address,
Expand Down Expand Up @@ -279,7 +287,7 @@ const Home: React.FC<HomeProps> = () => {
});
}
},
[showError],
[showError, hasSeenFilterOrdinalsModal],
);

// Subscribe to account changes
Expand Down Expand Up @@ -335,6 +343,14 @@ const Home: React.FC<HomeProps> = () => {
0,
);

const handleCloseFilterOrdinalsModal = () => {
setFilterOrdinalsModalOpen(false);
setHasSeenFilterOrdinalsModal((prev) => ({
...prev,
[address]: true,
}));
};

return (
<main
className={`relative h-full min-h-svh w-full ${network === Network.MAINNET ? "main-app-mainnet" : "main-app-testnet"}`}
Expand Down Expand Up @@ -413,7 +429,7 @@ const Home: React.FC<HomeProps> = () => {
/>
<FilterOrdinalsModal
open={filterOrdinalsModalOpen}
onClose={setFilterOrdinalsModalOpen}
onClose={handleCloseFilterOrdinalsModal}
shouldFilterOrdinals={shouldFilterOrdinals}
setShouldFilterOrdinals={handleShouldFilterOrdinals}
/>
Expand Down

0 comments on commit c2ef3a4

Please sign in to comment.