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

How we can send paper wallet's email content into HTML rendered Data #836

Open
mxicoderspl opened this issue Aug 14, 2023 · 0 comments
Open

Comments

@mxicoderspl
Copy link

A challenge I encountered while working on custom cryptocurrency extensions. I have successfully developed a paper wallet solution for these extensions. However, I faced an issue when attempting to include description or message data within the HTML-rendered content for the paper wallet.

The problem I encountered was that, when sending this content via email, the actual HTML source code was being displayed instead of the desired rendered content. I am aiming to find a solution that enables me to send the HTML-rendered data as the content or message within the email body.

My goal is to ensure that the recipients of these emails are able to see the beautifully rendered HTML content rather than the raw source code. If you have any insights or suggestions on how to achieve this, I would greatly appreciate your guidance.

This is the source code of Our Paper Wallet Generator:-

public class VoucherWalletGenerator implements IPaperWalletGenerator {

    private static final Logger log = LoggerFactory.getLogger("batm.master.VoucherWalletGenerator");
    private IExtensionContext ctx;
    private ITransactionDetails transactionDetails;
    private Locale locale;

    private static final int imagesize = 400;
    private static final String MESSAGE = "This is a test content for paper wallet";



    public VoucherWalletGenerator() {
    }

    public VoucherWalletGenerator(ITransactionDetails transactionDetails, Locale locale){
        log.info("3 transaction details in method:"+transactionDetails.getCryptoCurrency());
        this.transactionDetails=transactionDetails;
        this.locale=locale;
    }

    @Override
    public IPaperWallet generateWallet(String cryptoCurrency, String passphrase, String language, boolean shouldBeVanity) {
        return generateWallet();
    }

    private VoucherPaperWallet generateWallet()  {
        log.info("4 transaction details in method:"+transactionDetails.getCryptoCurrency());
        String charactersallowed = "";

        String newtkn = "XYXYXYXYXY";
        
        VoucherPaperWallet paperwallet = new VoucherPaperWallet();
        byte[] image = generateQR(newtkn, imagesize);

        paperwallet.setCryptoCurrency(CryptoCurrency.VE.getCode());
        paperwallet.setMessage(EmailProviderForVoucher.getBuyVoucherHtmlBody(transactionDetails,locale));
        paperwallet.setFileExtension("png");
        paperwallet.setAddress("");
        paperwallet.setContentType("image/png");
        paperwallet.setContent(image);

        return paperwallet;
    }

    public byte[] generateQR(String address, int size)  {
        Hashtable hintMap = new Hashtable();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        try {
            QRCodeWriter qrCodeWriter = new QRCodeWriter();
            BitMatrix byteMatrix = qrCodeWriter.encode(address,
                BarcodeFormat.QR_CODE, size, size, hintMap);
            int matrixWidth = byteMatrix.getWidth();
            BufferedImage image = new BufferedImage(matrixWidth, matrixWidth,
                BufferedImage.TYPE_INT_RGB);
            image.createGraphics();

            Graphics2D graphics = (Graphics2D) image.getGraphics();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, matrixWidth, matrixWidth);
            // Paint and save the image using the ByteMatrix
            graphics.setColor(Color.BLACK);

            for (int i = 0; i < matrixWidth; i++) {
                for (int j = 0; j < matrixWidth; j++) {
                    if (byteMatrix.get(i, j)) {
                        graphics.fillRect(i, j, 1, 1);
                    }
                }
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageOutputStream stream = new MemoryCacheImageOutputStream(baos);
            ImageIO.write(image, "png", stream);
            stream.close();
            return baos.toByteArray();
        }	catch (WriterException | IOException e) {
            log.error("Error", e);
        }
        return null;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant