<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arif Can</title>
    <description>The latest articles on DEV Community by Arif Can (@chezciacbro).</description>
    <link>https://dev.to/chezciacbro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2330208%2F320d1064-8737-428d-adf6-a722a8d2e31d.png</url>
      <title>DEV Community: Arif Can</title>
      <link>https://dev.to/chezciacbro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chezciacbro"/>
    <language>en</language>
    <item>
      <title>Transferring BTC Total data to amount on page 2 (help)</title>
      <dc:creator>Arif Can</dc:creator>
      <pubDate>Sat, 02 Nov 2024 22:53:28 +0000</pubDate>
      <link>https://dev.to/chezciacbro/transferring-btc-total-data-to-amount-on-page-2-help-5ec0</link>
      <guid>https://dev.to/chezciacbro/transferring-btc-total-data-to-amount-on-page-2-help-5ec0</guid>
      <description>&lt;p&gt;I want my Total BTC data in Bitcoin-Payment.tsx to be taken and when I click the "Pay with BTC" button, I want it to be directed to the 2nd page, BtcPaymentConfirmation.tsx, and I want the total data on the 1st page to appear in the "amount:" section, along with the 8-digit random order number. Can you help me?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//btc-payment.tsx page(1.page)
"use client";
import AnimationContainer from "@/components/global/animation-container";
import React, { useState, useEffect } from "react";
import axios from "axios";
import { FaCreditCard, FaMoneyBillWave } from "react-icons/fa";
import { useRouter } from "next/compat/router";

const BtcPayment = () =&amp;gt; {
    const [selectedProduct, setSelectedProduct] = useState&amp;lt;string | null&amp;gt;(null);
    const [selectedCardSubType, setSelectedCardSubType] = useState&amp;lt;string | null&amp;gt;(null);
    const [selectedBalanceType, setSelectedBalanceType] = useState&amp;lt;string | null&amp;gt;(null);
    const [isLoading, setIsLoading] = useState(false);
    const [btcRate, setBtcRate] = useState&amp;lt;number | null&amp;gt;(null);
    const router = useRouter();

    const handlePayment = () =&amp;gt; {
        const orderNumber = Math.floor(10000000 + Math.random() * 90000000).toString();
        const total = selectedProduct
            ? (selectedProduct === "Virtual Subscription" &amp;amp;&amp;amp; selectedBalanceType
                ? {
                    "$50": 5,
                    "$100": 10,
                    "$200": 20,
                }[selectedBalanceType] || 0
                : products.find(p =&amp;gt; p.name === selectedProduct)?.usdPrice! || 0) / (btcRate || 1)
            : 0;

        if (total &amp;gt; 0) {
            if (router) {
                router.push({
                    pathname: "/BtcPaymentConfirmation",
                    query: { orderNumber, btcAmount: total.toFixed(4) },
                });
            }
        } else {
            console.error("Total amount is zero or invalid");
        }
    };

    // Updated products with random names and options
    const products = [
        { name: "Digital Product A", usdPrice: 100, icon: &amp;lt;FaCreditCard /&amp;gt; },
        { name: "Digital Product B", usdPrice: 200, icon: &amp;lt;FaCreditCard /&amp;gt; },
        { name: "Virtual Subscription", usdPrice: 50, icon: &amp;lt;FaMoneyBillWave /&amp;gt; },
    ];

    useEffect(() =&amp;gt; {
        const fetchBtcRate = async () =&amp;gt; {
            try {
                const response = await axios.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&amp;amp;vs_currencies=usd");
                setBtcRate(response.data.bitcoin.usd);
            } catch (error) {
                console.error("Error fetching BTC rate:", error);
            }
        };

        fetchBtcRate();
        const interval = setInterval(fetchBtcRate, 60000);
        return () =&amp;gt; clearInterval(interval);
    }, []);

    const handleProductSelect = (productName: string) =&amp;gt; {
        setSelectedProduct(productName === selectedProduct ? null : productName);
        setSelectedCardSubType(null);
        setSelectedBalanceType(null);
    };

    const total = selectedProduct
        ? (selectedProduct === "Virtual Subscription" &amp;amp;&amp;amp; selectedBalanceType
            ? {
                "$50": 5,
                "$100": 10,
                "$200": 20,
              }[selectedBalanceType] || 0
            : products.find(p =&amp;gt; p.name === selectedProduct)?.usdPrice! || 0) / (btcRate || 1)
        : 0;

    return (
        &amp;lt;div className="flex flex-col items-center justify-center py-20"&amp;gt;
            &amp;lt;AnimationContainer delay={0.1}&amp;gt;
                &amp;lt;h1 className="text-2xl md:text-4xl lg:text-5xl font-semibold font-heading text-center mt-6 !leading-tight"&amp;gt;
                    Select Your Product
                &amp;lt;/h1&amp;gt;
                &amp;lt;p className="text-base md:text-lg mt-6 text-center text-muted-foreground"&amp;gt;
                    Choose the product you want to purchase with BTC.
                &amp;lt;/p&amp;gt;
            &amp;lt;/AnimationContainer&amp;gt;

            &amp;lt;div className="mt-10 w-full max-w-md"&amp;gt;
                &amp;lt;div className="flex flex-col items-center mt-4 space-y-4"&amp;gt;
                    {products.map((product) =&amp;gt; (
                        &amp;lt;button
                            key={product.name}
                            className={`w-full p-2 rounded border flex items-center justify-between ${
                                selectedProduct === product.name
                                    ? "bg-primary text-primary-foreground"
                                    : "bg-white text-black"
                            }`}
                            onClick={() =&amp;gt; handleProductSelect(product.name)}
                        &amp;gt;
                            &amp;lt;span className="flex items-center space-x-2"&amp;gt;
                                {product.icon}
                                &amp;lt;span&amp;gt;{product.name}&amp;lt;/span&amp;gt;
                            &amp;lt;/span&amp;gt;
                            &amp;lt;span&amp;gt;{btcRate ? (product.usdPrice / btcRate).toFixed(4) : "Loading..."} BTC&amp;lt;/span&amp;gt;
                        &amp;lt;/button&amp;gt;
                    ))}

                    {selectedProduct &amp;amp;&amp;amp; (selectedProduct === "Digital Product A" || selectedProduct === "Digital Product B") &amp;amp;&amp;amp; (
                        &amp;lt;div className="mt-6 w-full max-w-xs border-t pt-4"&amp;gt;
                            &amp;lt;p className="text-center mb-2"&amp;gt;Choose Card Type&amp;lt;/p&amp;gt;
                            &amp;lt;div className="flex justify-center space-x-4"&amp;gt;
                                {["Visa", "MasterCard", "American Express"].map((cardType) =&amp;gt; (
                                    &amp;lt;button
                                        key={cardType}
                                        className={`px-4 py-2 rounded border ${
                                            selectedCardSubType === cardType
                                                ? "bg-primary text-primary-foreground"
                                                : "bg-white text-black"
                                        }`}
                                        onClick={() =&amp;gt; setSelectedCardSubType(cardType)}
                                    &amp;gt;
                                        {cardType}
                                    &amp;lt;/button&amp;gt;
                                ))}
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;
                    )}

                    {selectedProduct === "Virtual Subscription" &amp;amp;&amp;amp; (
                        &amp;lt;div className="mt-6 w-full max-w-xs border-t pt-4"&amp;gt;
                            &amp;lt;p className="text-center mb-2"&amp;gt;Choose Balance Type&amp;lt;/p&amp;gt;
                            &amp;lt;div className="flex justify-center space-x-4"&amp;gt;
                                {["$50", "$100", "$200"].map((balanceType) =&amp;gt; (
                                    &amp;lt;button
                                        key={balanceType}
                                        className={`px-4 py-2 rounded border ${
                                            selectedBalanceType === balanceType
                                                ? "bg-primary text-primary-foreground"
                                                : "bg-white text-black"
                                        }`}
                                        onClick={() =&amp;gt; setSelectedBalanceType(balanceType)}
                                    &amp;gt;
                                        {balanceType}
                                    &amp;lt;/button&amp;gt;
                                ))}
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;
                    )}
                &amp;lt;/div&amp;gt;

                &amp;lt;div className="mt-6 text-center"&amp;gt;
                    &amp;lt;p className="text-lg font-medium"&amp;gt;
                        Total: {total.toFixed(4)} BTC
                    &amp;lt;/p&amp;gt;
                    &amp;lt;button
                        className="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 active:scale-95 transition-all bg-primary text-primary-foreground hover:bg-primary/90 primary h-9 px-4 py-2 mt-4"
                        disabled={
                            isLoading ||
                            !selectedProduct ||
                            ((selectedProduct === "Digital Product A" || selectedProduct === "Digital Product B") &amp;amp;&amp;amp; !selectedCardSubType) ||
                            (selectedProduct === "Virtual Subscription" &amp;amp;&amp;amp; !selectedBalanceType)
                        }
                        onClick={handlePayment}
                    &amp;gt;
                        {isLoading ? (
                            &amp;lt;span className="loader mr-2"&amp;gt;&amp;lt;/span&amp;gt;
                        ) : (
                            "Pay with BTC"
                        )}
                    &amp;lt;/button&amp;gt;
                &amp;lt;/div&amp;gt;

                {selectedProduct &amp;amp;&amp;amp; (
                    &amp;lt;div className="mt-6 text-center"&amp;gt;
                        &amp;lt;p className="text-lg font-semibold"&amp;gt;Selected Product: {selectedProduct}&amp;lt;/p&amp;gt;
                        {selectedProduct === "Virtual Subscription" &amp;amp;&amp;amp; selectedBalanceType &amp;amp;&amp;amp; (
                            &amp;lt;p className="text-md"&amp;gt;Balance Type: {selectedBalanceType}&amp;lt;/p&amp;gt;
                        )}
                        {(selectedProduct === "Digital Product A" || selectedProduct === "Digital Product B") &amp;amp;&amp;amp; selectedCardSubType &amp;amp;&amp;amp; (
                            &amp;lt;p className="text-md"&amp;gt;Card Type: {selectedCardSubType}&amp;lt;/p&amp;gt;
                        )}
                    &amp;lt;/div&amp;gt;
                )}
            &amp;lt;/div&amp;gt;

            &amp;lt;style jsx&amp;gt;{`
                .loader {
                    border: 4px solid rgba(255, 255, 255, 0.3);
                    border-top: 4px solid #ffffff;
                    border-radius: 50%;
                    width: 24px;
                    height: 24px;
                    animation: spin 1s linear infinite;
                }

                @keyframes spin {
                    0% {
                        transform: rotate(0deg);
                    }
                    100% {
                        transform: rotate(360deg);
                    }
                }
            `}&amp;lt;/style&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};

export default BtcPayment;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//BtcPaymentConfirmation.tsx (2.page)
"use client"
import { BorderBeam } from "@/components/ui/border-beam";
import { useEffect, useState } from "react";
import { Copy } from 'lucide-react'; // Importing the Copy icon

const BtcPaymentConfirmation = () =&amp;gt; {
    const [timeLeft, setTimeLeft] = useState(900); // 15-minute countdown
    const [copyMessage, setCopyMessage] = useState(""); // State for copy feedback

    const walletAddress = "bc1qmpph23yp6dgqwd2dzee02djauevp9d57rqw8nu"; // Replace with actual wallet address

    // Google Charts API URL for QR code generation
    const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?size=180x180&amp;amp;data=${encodeURIComponent(walletAddress)}`;

    // Countdown timer
    useEffect(() =&amp;gt; {
        if (timeLeft &amp;gt; 0) {
            const timer = setInterval(() =&amp;gt; setTimeLeft(prev =&amp;gt; prev - 1), 1000);
            return () =&amp;gt; clearInterval(timer);
        }
    }, [timeLeft]);

    const formatTime = (seconds: number) =&amp;gt; {
        const minutes = Math.floor(seconds / 60);
        const remainingSeconds = seconds % 60;
        return `${minutes}:${remainingSeconds &amp;lt; 10 ? '0' : ''}${remainingSeconds}`;
    };

    const percentageLeft = (timeLeft / 900) * 100; // Calculate percentage left

    // Function to copy wallet address
    const copyToClipboard = () =&amp;gt; {
        navigator.clipboard.writeText(walletAddress).then(() =&amp;gt; {
            setCopyMessage("Copied!"); // Show feedback message
            setTimeout(() =&amp;gt; setCopyMessage(""), 2000); // Clear message after 2 seconds
        }).catch(err =&amp;gt; {
            console.error('Failed to copy: ', err);
        });
    };

    return (
        &amp;lt;div className="flex items-center justify-center min-h-screen"&amp;gt;
            &amp;lt;div className="shadow-md rounded-lg p-8 w-full max-w-lg text-center border border-white"&amp;gt;

                &amp;lt;h1 className="text-2xl md:text-4xl lg:text-5xl font-semibold font-heading mt-4 mb-4"&amp;gt;Payment Confirmation&amp;lt;/h1&amp;gt;
                &amp;lt;p className="text-lg font-semibold mb-2"&amp;gt;Order Number:&amp;lt;/p&amp;gt;
                &amp;lt;p className="text-lg mb-4 font-semibold font-heading"&amp;gt;Amount:&amp;lt;/p&amp;gt;

                &amp;lt;div className="relative mt-4 border-2 border-violet-500 rounded p-1 inline-block"&amp;gt; {/* Tighter frame design */}
                    &amp;lt;img src={qrCodeUrl} alt="QR Code" width={180} height={180} className="mx-auto" /&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;p className="text-center mt-2"&amp;gt;Scan to Pay&amp;lt;/p&amp;gt;

                &amp;lt;div className="mt-6"&amp;gt;
                    &amp;lt;p className="text-center text-sm font-semibold font-heading"&amp;gt;Wallet Address:&amp;lt;/p&amp;gt;
                    &amp;lt;div className="flex items-center justify-center"&amp;gt;
                        &amp;lt;p className="text-sm font-semibold font-heading mr-2"&amp;gt;{walletAddress}&amp;lt;/p&amp;gt;
                        &amp;lt;button 
                            onClick={copyToClipboard} 
                            className="p-2 text-white rounded flex items-center justify-center"
                            aria-label="Copy wallet address"
                        &amp;gt;
                            &amp;lt;Copy className="h-5 w-5" /&amp;gt;
                        &amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                    {copyMessage &amp;amp;&amp;amp; &amp;lt;p className="text-white font-semibold font-heading mt-2"&amp;gt;{copyMessage}&amp;lt;/p&amp;gt;} {/* Feedback message */}
                &amp;lt;/div&amp;gt;

                &amp;lt;div className="mt-6 text-lg font-semibold font-heading text-white"&amp;gt;
                    &amp;lt;span className="text-transparent bg-gradient-to-r from-violet-500 to-fuchsia-500 bg-clip-text inline-block"&amp;gt;
                        Complete your payment in: {formatTime(timeLeft)} 
                    &amp;lt;/span&amp;gt;
                &amp;lt;/div&amp;gt;

                {/* Countdown bar */}
                &amp;lt;div className="mt-4 h-4 bg-gray-500 rounded"&amp;gt;
                    &amp;lt;div
                        className="h-full bg-white rounded"
                        style={{ width: `${percentageLeft}%` }}
                    /&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};

export default BtcPaymentConfirmation;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>nextjs</category>
      <category>btc</category>
      <category>cryptocurrency</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
