Changes Pdf417Barcode component from using hardcoded payment data to accepting paymentParams as a prop, making it reusable. Updates useEffect dependency array to regenerate barcode when payment params change. Also updates hub-3a-payment-encoder to v1.1.0 for PaymentParams type support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect, FC } from 'react';
|
|
import { generateBarcode } from '../lib/pdf/pdf417';
|
|
import { renderBarcode } from '../lib/pdf/renderBarcode';
|
|
import { EncodePayment, PaymentParams } from 'hub-3a-payment-encoder';
|
|
|
|
export const Pdf417Barcode:FC<{paymentParams:PaymentParams}> = ({paymentParams}) => {
|
|
const [bitmapData, setBitmapData] = useState<string | undefined>(undefined);
|
|
|
|
useEffect(() => {
|
|
const hub3a_text = EncodePayment(paymentParams);
|
|
|
|
const barcodeMatrix = generateBarcode(hub3a_text);
|
|
const bitmap = renderBarcode(barcodeMatrix, 2, 2);
|
|
setBitmapData(bitmap);
|
|
}, [paymentParams]);
|
|
|
|
// Don't render until bitmap is generated (prevents hydration mismatch)
|
|
if (!bitmapData) {
|
|
return (
|
|
<div style={{ width: "350px", height: "92px" }} className="flex items-center justify-center">
|
|
<span className="loading loading-spinner loading-lg"></span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<img src={bitmapData} style={{ width: "350px", height: "92px" }} />
|
|
</div>
|
|
);
|
|
} |