Skip to content

Commit

Permalink
chore: discard inscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Dec 18, 2024
1 parent b2b1558 commit ba31b0f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/app/features/collectibles/components/bitcoin/inscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ORD_IO_URL } from '@shared/constants';
import { RouteUrls } from '@shared/route-urls';

import { openInNewTab } from '@app/common/utils/open-in-new-tab';
import { useDiscardedInscriptions } from '@app/store/settings/settings.selectors';

import { CollectibleAudio } from '../_collectible-types/collectible-audio';
import { CollectibleIframe } from '../_collectible-types/collectible-iframe';
Expand All @@ -29,6 +30,7 @@ function openInscriptionUrl(num: number) {
export function Inscription({ inscription }: InscriptionProps) {
const navigate = useNavigate();
const location = useLocation();
const { hasBeenDiscarded, discardInscription, recoverInscription } = useDiscardedInscriptions();

const openSendInscriptionModal = useCallback(() => {
navigate(RouteUrls.SendOrdinalInscription, {
Expand Down Expand Up @@ -112,6 +114,19 @@ export function Inscription({ inscription }: InscriptionProps) {
<Box position="relative">
{content}
<HighSatValueUtxoWarning inscription={inscription} />
IsDiscarded: {String(hasBeenDiscarded(inscription.id))}
<br />
value: {inscription.value}
<br />
<button
onClick={() => {
hasBeenDiscarded(inscription.id)
? recoverInscription(inscription.id)
: discardInscription(inscription.id);
}}
>
toggle safe to spend
</button>
</Box>
);
}
38 changes: 36 additions & 2 deletions src/app/store/settings/settings.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useSelector } from 'react-redux';
import { useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { createSelector } from '@reduxjs/toolkit';

import { RootState } from '@app/store';

import { settingsSlice } from './settings.slice';

const selectSettings = (state: RootState) => state.settings;

const selectUserSelectedTheme = createSelector(selectSettings, state => state.userSelectedTheme);
Expand All @@ -27,6 +30,37 @@ export function useIsPrivateMode() {
return useSelector(selectIsPrivateMode);
}

const selectHasUserBypassedInscriptionChecks = createSelector(
selectSettings,
state => state.bypassInscriptionChecks ?? false
);

export function useHasUserBypassedInscriptionChecks() {
return useSelector(selectSettings, state => state.bypassInscriptionChecks ?? false);
return useSelector(selectHasUserBypassedInscriptionChecks);
}

const selectDiscardedInscriptions = createSelector(
selectSettings,
state => state.discardedInscriptions
);

export function useDiscardedInscriptions() {
const discardedInscriptions = useSelector(selectDiscardedInscriptions);
const dispatch = useDispatch();

return useMemo(
() => ({
discardedInscriptions,
hasBeenDiscarded(inscriptionId: string) {
return discardedInscriptions.includes(inscriptionId);
},
discardInscription(inscriptionId: string) {
dispatch(settingsSlice.actions.discardInscription(inscriptionId));
},
recoverInscription(inscriptionId: string) {
dispatch(settingsSlice.actions.recoverInscription(inscriptionId));
},
}),
[discardedInscriptions, dispatch]
);
}
11 changes: 11 additions & 0 deletions src/app/store/settings/settings.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ interface InitialState {
dismissedMessages: string[];
isPrivateMode?: boolean;
bypassInscriptionChecks?: boolean;
discardedInscriptions: string[];
}

const initialState: InitialState = {
userSelectedTheme: 'system',
dismissedMessages: [],
discardedInscriptions: [],
};

export const settingsSlice = createSlice({
Expand All @@ -34,5 +36,14 @@ export const settingsSlice = createSlice({
dangerouslyChosenToBypassAllInscriptionChecks(state) {
state.bypassInscriptionChecks = true;
},
discardInscription(state, action: PayloadAction<string>) {
if (!Array.isArray(state.discardedInscriptions)) state.discardedInscriptions = [];
state.discardedInscriptions.push(action.payload);
},
recoverInscription(state, action: PayloadAction<string>) {
state.discardedInscriptions = state.discardedInscriptions.filter(
inscriptionId => inscriptionId !== action.payload
);
},
},
});

0 comments on commit ba31b0f

Please sign in to comment.