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

chore: fix max quantity function & fix setFromState issue & fix image… #479

Merged
merged 1 commit into from
Dec 11, 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
1 change: 1 addition & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface StampRow {
floorPriceUSD?: number | null;
marketCapUSD?: number | null;
recentSalePrice?: number | "priceless";
unbound_quantity: number;
}

export interface DisplayCountBreakpoints {
Expand Down
57 changes: 31 additions & 26 deletions islands/Wallet/details/WalletTransferModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SelectField } from "$islands/stamping/SelectField.tsx";
import { ModalLayout } from "$components/shared/modal/ModalLayout.tsx";
import { useTransactionForm } from "$client/hooks/useTransactionForm.ts";
import type { StampRow } from "$globals";
import { getStampImageSrc, handleImageError } from "$lib/utils/imageUtils.ts";

interface Props {
fee: number;
Expand Down Expand Up @@ -33,10 +34,12 @@ function WalletTransferModal({
const { wallet } = walletContext;
const [maxQuantity, setMaxQuantity] = useState(1);
const [quantity, setQuantity] = useState(1);
const [imgSrc, setImgSrc] = useState("");
const [selectedStamp, setSelectedStamp] = useState<StampRow | null>(null);

const {
formState,
setFormState,
handleChangeFee: internalHandleChangeFee,
handleSubmit,
isSubmitting,
Expand Down Expand Up @@ -80,7 +83,7 @@ function WalletTransferModal({
if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.error || "Failed to create transfer transaction."
errorData.error || "Failed to create transfer transaction.",
);
}

Expand All @@ -93,12 +96,12 @@ function WalletTransferModal({
wallet,
responseData.result.psbt,
[], // Empty array for inputs to sign
true // Enable RBF
true, // Enable RBF
);

if (signResult.signed && signResult.txid) {
setSuccessMessage(
`Transfer initiated successfully. TXID: ${signResult.txid}`
`Transfer initiated successfully. TXID: ${signResult.txid}`,
);
setTimeout(toggleModal, 5000);
} else if (signResult.cancelled) {
Expand All @@ -110,7 +113,7 @@ function WalletTransferModal({
};

const handleQuantityChange = (
e: React.ChangeEvent<HTMLInputElement>
e: React.ChangeEvent<HTMLInputElement>,
): void => {
const value = parseInt(e.target.value, 10);
if (!isNaN(value)) {
Expand All @@ -124,15 +127,15 @@ function WalletTransferModal({
}
};
const getMaxQuantity = () => {
const max = Math.max(
...stamps.data.map((stamp) => stamp.unbounded_quantity)
);
setMaxQuantity(max);
if (selectedStamp) {
setMaxQuantity(selectedStamp?.unbound_quantity);
}
};

useEffect(() => {
getMaxQuantity();
}, [stamps]);
setImgSrc(getStampImageSrc(selectedStamp as StampRow));
}, [selectedStamp]);

const inputField =
"h-12 px-3 rounded-md bg-stamp-grey text-stamp-grey-darkest placeholder:text-stamp-grey-darkest placeholder:uppercase placeholder:font-light text-sm mobileLg:text-base font-medium w-full outline-none focus:bg-stamp-grey-light";
Expand All @@ -141,20 +144,23 @@ function WalletTransferModal({
<ModalLayout onClose={handleCloseModal} title="TRANSFER">
<div className="flex w-full gap-3 mobileMd:gap-6">
<div className="min-w-[108px] h-[108px] mobileMd:min-w-[120px] mobileMd:h-[120px] bg-[#660099] rounded-md flex items-center justify-center">
{selectedStamp ? (
<img
// src={`/api/v2/stamp/${selectedStamp.stamp}/content`}
src={selectedStamp.stamp_url}
alt={`Stamp #${selectedStamp.stamp}`}
className="w-full h-full object-contain"
/>
) : (
<img
src="/img/stamping/image-upload.svg"
class="w-12 h-12"
alt=""
/>
)}
{selectedStamp
? (
<img
src={imgSrc}
onError={handleImageError}
loading="lazy"
alt={`Stamp #${selectedStamp.stamp}`}
className="w-full h-full object-contain pixelart"
/>
)
: (
<img
src="/img/stamping/image-upload.svg"
class="w-12 h-12"
alt=""
/>
)}
</div>

<div className="flex flex-col gap-3 mobileMd:gap-6 flex-1">
Expand All @@ -163,7 +169,7 @@ function WalletTransferModal({
value={selectedStamp?.stamp?.toString() || ""}
onChange={(e) => {
const selectedItem = stamps.data.find(
(item) => item.tx_hash === e.currentTarget.value
(item) => item.tx_hash === e.currentTarget.value,
);

if (selectedItem) {
Expand Down Expand Up @@ -200,8 +206,7 @@ function WalletTransferModal({
setFormState({
...formState,
recipientAddress: (e.target as HTMLInputElement).value,
})
}
})}
placeholder="Recipient address"
className={inputField}
/>
Expand Down
2 changes: 1 addition & 1 deletion routes/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function App({ Component, state }: PageProps<unknown>) {
<div class="flex flex-col min-h-screen">
<Header />
<main
class="flex flex-col flex-grow px-3 mobileMd:px-6 desktop:px-12 py-12 mobileLg:py-24 desktop:py-36 max-w-desktop mx-auto w-full content-lazy"
class="flex flex-col flex-grow px-3 mobileMd:px-6 desktop:px-12 py-12 mobileLg:py-24 desktop:py-36 max-w-desktop mx-auto w-full"
f-client-nav
>
<Partial name="body">
Expand Down