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: show the html on stamping tool & change the oninput to onchang… #668

Merged
merged 1 commit into from
Jan 21, 2025
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
4 changes: 3 additions & 1 deletion components/shared/fee/FeeCalculatorBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ export function FeeCalculatorBase({
min="1"
max="264"
step="1"
onInput={(e) =>
onChange={(e) =>
handleChangeFee(parseInt((e.target as HTMLInputElement).value, 10))}
// onInput={(e) =>
// handleChangeFee(parseInt((e.target as HTMLInputElement).value, 10))}
className="w-full h-1 mobileLg:h-1.5 rounded-lg appearance-none cursor-pointer bg-stamp-grey [&::-webkit-slider-thumb]:w-[18px] [&::-webkit-slider-thumb]:h-[18px] [&::-webkit-slider-thumb]:mobileLg:w-[22px] [&::-webkit-slider-thumb]:mobileLg:h-[22px] [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:bg-stamp-purple-dark [&::-webkit-slider-thumb]:hover:bg-stamp-purple [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:cursor-pointer [&::-moz-range-thumb]:w-[18px] [&::-moz-range-thumb]:h-[18px] [&::-moz-range-thumb]:mobileLg:w-[22px] [&::-moz-range-thumb]:mobileLg:h-[22px] [&::-moz-range-thumb]:appearance-none [&::-moz-range-thumb]:bg-stamp-purple-dark [&::-moz-range-thumb]:hover:bg-stamp-purple-dark [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:cursor-pointer"
/>
<div
Expand Down
63 changes: 30 additions & 33 deletions islands/stamping/stamp/OlgaContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Config } from "$globals";
import { logger } from "$lib/utils/logger.ts";
import StampImageFullScreen from "$islands/stamp/details/StampImageFullScreen.tsx";
import { NOT_AVAILABLE_IMAGE } from "$lib/utils/constants.ts";
import { handleImageError } from "$lib/utils/imageUtils.ts";

const log = (message: string, data?: unknown) => {
logger.debug("stamps", {
Expand Down Expand Up @@ -299,34 +300,6 @@ export function OlgaContent() {
// Add new state and refs for tooltips
const [tooltipPosition, setTooltipPosition] = useState({ x: 0, y: 0 });
const [isUploadTooltipVisible, setIsUploadTooltipVisible] = useState(false);
const uploadTooltipTimeoutRef = useRef<number | null>(null);

// Add tooltip handlers
const handleMouseMove = (e: MouseEvent) => {
setTooltipPosition({
x: e.clientX,
y: e.clientY,
});
};

const handleUploadMouseEnter = () => {
setIsUploadTooltipVisible(true);

if (uploadTooltipTimeoutRef.current) {
globalThis.clearTimeout(uploadTooltipTimeoutRef.current);
}

uploadTooltipTimeoutRef.current = globalThis.setTimeout(() => {
setIsUploadTooltipVisible(false);
}, 1500);
};

const handleUploadMouseLeave = () => {
if (uploadTooltipTimeoutRef.current) {
globalThis.clearTimeout(uploadTooltipTimeoutRef.current);
}
setIsUploadTooltipVisible(false);
};

useEffect(() => {
if (fees && !loading) {
Expand Down Expand Up @@ -882,7 +855,10 @@ export function OlgaContent() {
message: "Unexpected minting error",
error,
});
setApiError("An unexpected error occurred");
setApiError(
error.message || error.response.data.error ||
"An unexpected error occurred",
);
setSubmissionMessage(null);
}
};
Expand Down Expand Up @@ -1015,10 +991,6 @@ export function OlgaContent() {
<div
id="image-preview"
class={`relative rounded items-center mx-auto text-center cursor-pointer ${PREVIEW_SIZE_CLASSES} content-center bg-stamp-purple-dark group hover:bg-[#8800CC] transition duration-300`}
onMouseMove={handleMouseMove}
onMouseEnter={handleUploadMouseEnter}
onMouseLeave={handleUploadMouseLeave}
onMouseDown={() => setIsUploadTooltipVisible(false)}
onClick={() => setIsUploadTooltipVisible(false)}
>
<input
Expand All @@ -1044,6 +1016,31 @@ export function OlgaContent() {
message: "Image preview failed to load",
error: e,
});
handleImageError(e);
}}
/>
)
: file.name.match(/\.(html)$/i)
? (
<iframe
width="100%"
height="100%"
scrolling="no"
loading="lazy"
sandbox="allow-scripts allow-same-origin"
src={URL.createObjectURL(file)}
class={`${PREVIEW_SIZE_CLASSES} object-contain rounded bg-black [image-rendering:pixelated]`}
onError={(e) => {
console.error("iframe error (detailed):", {
error: e,
target: e.target,
src: (e.target as HTMLIFrameElement).src,
contentWindow:
(e.target as HTMLIFrameElement).contentWindow
? "present"
: "missing",
});
handleImageError(e);
}}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/formatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function formatDate(
): string {
// Check for invalid date
if (!date || isNaN(date.getTime())) {
return "Invalid Date";
return "INVALID";
}

const locale = navigator.language || "en-US";
Expand Down
5 changes: 3 additions & 2 deletions routes/api/v2/olga/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ export const handler: Handlers<TX | TXError> = {
} as NormalizedMintResponse, { forceNoCache: true });
} catch (error: unknown) {
console.error("Minting error:", error);

const errorMessage = error instanceof Error
? error.message
: "An unexpected error occurred during minting";
: error as string || "An unexpected error occurred during minting";

// Client errors (400)
if (
errorMessage.includes("insufficient funds") ||
errorMessage.toLowerCase().includes("insufficient funds") ||
errorMessage.includes("UTXO selection failed") ||
errorMessage.includes("Invalid satsPerKB parameter")
) {
Expand Down
3 changes: 2 additions & 1 deletion server/services/stamp/stampMintService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ export class StampMintService {
if (response.error.message?.includes('invalid base58')) {
throw new Error(`Invalid wallet address format: ${sourceWallet}. Only P2PKH (1), P2WPKH (bc1q), and P2SH (3) addresses are supported.`);
}
throw new Error(`API Error: ${response.error.message || 'Unknown error'}`);

throw new Error(`API Error: ${response.error || 'Unknown error'}`);
}

// Check for nested result and rawtransaction
Expand Down
8 changes: 6 additions & 2 deletions server/services/xcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export async function fetchXcpV2WithCache<T>(
return await dbManager.handleCache(
cacheKey,
async () => {
let errorMessage = null;
for (const node of xcp_v2_nodes) {
const url = `${node.url}${endpoint}?${queryParams.toString()}`;

await logger.debug("api", {
message: "Attempting XCP node fetch",
node: node.name,
Expand Down Expand Up @@ -114,6 +114,7 @@ export async function fetchXcpV2WithCache<T>(
errorBody,
url
});
errorMessage = errorBody
continue; // Try the next node
}

Expand All @@ -132,6 +133,7 @@ export async function fetchXcpV2WithCache<T>(
url,
stack: error.stack
});
errorMessage = error.message
// Continue to the next node
}
}
Expand All @@ -140,13 +142,15 @@ export async function fetchXcpV2WithCache<T>(
await logger.warn("api", {
message: "All XCP nodes failed, returning minimal data structure",
endpoint,
queryParams: queryParams.toString()
queryParams: queryParams.toString(),
error: errorMessage
});

return {
result: [],
next_cursor: null,
result_count: 0,
error: errorMessage
} as T;
},
cacheTimeout,
Expand Down
Loading