import React, { memo, useCallback, useEffect, useState } from "react";
import { Box, Divider, Input, Text, VStack } from "native-base";
import { CentreBox } from "../layout/CentreBox";
import { Image } from "../images";
import ConverterCircle from "../../assets/svg/converter-circle.svg";
import cUsdLogo from "../../assets/images/cusd.png";
import gdLogo from "../../assets/images/gdLogo.png";
interface CurrencyBoxProps {
title: string;
placeholder: string | undefined;
logoSrc: any;
currencyUnit: string;
onBlur: (e: any) => void;
onChangeText: (e: string) => void;
}
const CurrencyBox = ({ title, placeholder, logoSrc, currencyUnit, onBlur, onChangeText }: CurrencyBoxProps) => (
{title}
{currencyUnit}
{currencyUnit}
);
const Converter = memo(({ gdPrice }: { gdPrice?: number }) => {
const [gdAmount, setGdAmount] = useState("100");
const [usdAmount, setUsdAmount] = useState("100");
const calcAmount = useCallback(
(inputType: "gd" | "usd", amount: string) => {
const numAmount = Number(amount);
if (gdPrice) {
const koeff = inputType === "gd" ? gdPrice : 1 / gdPrice;
const setter = inputType === "usd" ? setGdAmount : setUsdAmount;
setter((numAmount * koeff).toFixed(2));
}
},
[gdPrice, usdAmount, gdAmount]
);
useEffect(() => {
if (gdPrice) {
calcAmount("gd", gdAmount || "100");
}
}, []);
const calcGd = (usdAmount: string) => {
setUsdAmount(usdAmount);
calcAmount("usd", usdAmount);
};
const calcUsd = (gdAmount: string) => {
setGdAmount(gdAmount);
calcAmount("gd", gdAmount);
};
// clearing input where it will show placeholder as value just typed in
const clearInput = (e: any) => {
e.target.value = "";
};
return (
);
});
export default Converter;