Skip to content

Commit

Permalink
Merge pull request #242 from xch-dev/add-to-offer
Browse files Browse the repository at this point in the history
Add to offer for NFTs in both single and bulk
  • Loading branch information
Rigidity authored Jan 6, 2025
2 parents 7c6b1ec + 926c965 commit 624b35b
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 138 deletions.
47 changes: 45 additions & 2 deletions src/components/MultiSelectActions.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { commands, TransactionResponse } from '@/bindings';
import { useErrors } from '@/hooks/useErrors';
import { toMojos } from '@/lib/utils';
import { useWalletState } from '@/state';
import { useOfferState, useWalletState } from '@/state';
import { t } from '@lingui/core/macro';
import { Trans } from '@lingui/react/macro';
import { ChevronDown, Flame, SendIcon, UserRoundPlus } from 'lucide-react';
import {
ChevronDown,
Flame,
HandCoins,
SendIcon,
UserRoundPlus,
} from 'lucide-react';
import { useState } from 'react';
import { AssignNftDialog } from './AssignNftDialog';
import ConfirmationDialog from './ConfirmationDialog';
Expand All @@ -16,6 +22,7 @@ import {
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from './ui/dropdown-menu';

Expand All @@ -29,7 +36,10 @@ export function MultiSelectActions({
onConfirm,
}: MultiSelectActionsProps) {
const walletState = useWalletState();
const offerState = useOfferState();

const { addError } = useErrors();

const selectedCount = selected.length;

const [transferOpen, setTransferOpen] = useState(false);
Expand Down Expand Up @@ -126,6 +136,39 @@ export function MultiSelectActions({
<Trans>Burn</Trans>
</span>
</DropdownMenuItem>

<DropdownMenuSeparator />

<DropdownMenuItem
className='cursor-pointer'
onClick={(e) => {
e.stopPropagation();

const newNfts = [...offerState.offered.nfts];

for (const item of selected) {
if (newNfts.includes(item)) {
continue;
}

newNfts.push(item);
}

useOfferState.setState({
offered: {
...offerState.offered,
nfts: newNfts,
},
});

onConfirm();
}}
>
<HandCoins className='mr-2 h-4 w-4' />
<span>
<Trans>Add to Offer</Trans>
</span>
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
Expand Down
33 changes: 32 additions & 1 deletion src/components/NftCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useErrors } from '@/hooks/useErrors';
import { amount } from '@/lib/formTypes';
import { nftUri } from '@/lib/nftUri';
import { toMojos } from '@/lib/utils';
import { useWalletState } from '@/state';
import { useOfferState, useWalletState } from '@/state';
import { zodResolver } from '@hookform/resolvers/zod';
import { t } from '@lingui/core/macro';
import { Trans } from '@lingui/react/macro';
Expand All @@ -20,6 +20,7 @@ import {
EyeIcon,
EyeOff,
Flame,
HandCoins,
LinkIcon,
MoreVertical,
SendIcon,
Expand Down Expand Up @@ -85,6 +86,7 @@ export function NftCardList({ children }: PropsWithChildren) {

export function NftCard({ nft, updateNfts, selectionState }: NftProps) {
const walletState = useWalletState();
const offerState = useOfferState();
const navigate = useNavigate();

const { addError } = useErrors();
Expand Down Expand Up @@ -287,6 +289,35 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {

<DropdownMenuSeparator />

<DropdownMenuItem
className='cursor-pointer'
onClick={(e) => {
e.stopPropagation();

const newNfts = [...offerState.offered.nfts];

newNfts.push(nft.launcher_id);

useOfferState.setState({
offered: {
...offerState.offered,
nfts: newNfts,
},
});
}}
disabled={
!nft.created_height ||
offerState.offered.nfts.findIndex(
(nftId) => nftId === nft.launcher_id,
) !== -1
}
>
<HandCoins className='mr-2 h-4 w-4' />
<span>
<Trans>Add to Offer</Trans>
</span>
</DropdownMenuItem>

<DropdownMenuItem
className='cursor-pointer'
onClick={(e) => {
Expand Down
Loading

0 comments on commit 624b35b

Please sign in to comment.