diff --git a/src/app/calculator/page.tsx b/src/app/calculator/page.tsx index 5be0b44..130769f 100644 --- a/src/app/calculator/page.tsx +++ b/src/app/calculator/page.tsx @@ -2,6 +2,7 @@ import { useData } from '@/app/context/datacontext'; import { useState } from 'react'; +import InfoIcon from '@/icons/info' export default function Calculator() { const { @@ -21,32 +22,45 @@ export default function Calculator() { initialBamkPrice = Number(magicEdenBamkData.floorUnitPrice.formatted); } - const [myNusd, setMyNusd] = useState('2000'); - const [totalNusd, setTotalNusd] = useState(initialTotalNusd); - const [bamkPrice, setBamkPrice] = useState(initialBamkPrice); + const [walletNusd, setMyNusd] = useState(2000); + const [poolNusd, setPoolNusd] = useState(0); + const [liquidityPoolPercent, setLiquidityPoolPercent] = useState(0); + const [totalNusd, setTotalNusd] = useState(initialTotalNusd); + const [bamkPrice, setBamkPrice] = useState(initialBamkPrice); const handleMyNusdChange = (e: React.ChangeEvent) => { - const value = e.target.value; - // Sanitize leading zeros - const sanitizedValue = value.replace(/^0+(?=\d)/, ''); - setMyNusd(sanitizedValue); + const value = e.target.value.replace(/^0+/, ''); + setMyNusd(value === '' ? 0 : Number(value)); + }; + + const handlePoolNusdChange = (e: React.ChangeEvent) => { + const value = e.target.value.replace(/^0+/, ''); + setPoolNusd(value === '' ? 0 : Number(value)); + }; + + const handleLPPercentChange = (e: React.ChangeEvent) => { + let value = e.target.value.replace(/^0+/, ''); + let numericValue = value === '' ? 0 : Number(value); + if (numericValue > 100) { + numericValue = 100; + } + setLiquidityPoolPercent(numericValue); }; const handleTotalNusdChange = (e: React.ChangeEvent) => { - const value = e.target.value; - // Sanitize leading zeros - const sanitizedValue = value.replace(/^0+(?=\d)/, ''); - setTotalNusd(Number(sanitizedValue)); + const value = e.target.value.replace(/^0+/, ''); + setTotalNusd(value === '' ? 0 : Number(value)); }; const handleBamkPriceChange = (e: React.ChangeEvent) => { - const value = e.target.value; - // Sanitize leading zeros - const sanitizedValue = value.replace(/^0+(?=\d)/, ''); - setBamkPrice(Number(sanitizedValue)); + const value = e.target.value.replace(/^0+/, ''); + setBamkPrice(value === '' ? 0 : Number(value)); }; - const bamkPerDay = ((Number(myNusd) || 0) / totalNusd) * (31250 * 144); + const bamkLiquidityBonus = 5000 * 144; + const liquidityPoolBonus = (Number(liquidityPoolPercent) / 100) * bamkLiquidityBonus; + + const bamkPerDay = ((Number(walletNusd) + Number(poolNusd) || 0) / Number(totalNusd)) * (31250 * 144) + liquidityPoolBonus; if ( !magicEdenBamkData || @@ -70,33 +84,80 @@ export default function Calculator() {
- +
- + + +
+
+ +
+
+ +
-

{bamkPerDay.toLocaleString(undefined, { maximumFractionDigits: 2 })} BAMK = {((bamkPerDay * bamkPrice)/100000000).toLocaleString(undefined, { maximumFractionDigits: 8 })} BTC = ${(btcPriceData.bitcoin.usd * (Math.floor(bamkPerDay * bamkPrice)) / 100000000).toLocaleString(undefined, { maximumFractionDigits: 2 })}

+

{bamkPerDay.toLocaleString(undefined, { maximumFractionDigits: 2 })} BAMK = {((bamkPerDay * Number(bamkPrice))/100000000).toLocaleString(undefined, { maximumFractionDigits: 8 })} BTC = ${(btcPriceData.bitcoin.usd * (Math.floor(bamkPerDay * Number(bamkPrice))) / 100000000).toLocaleString(undefined, { maximumFractionDigits: 2 })}

diff --git a/src/app/globals.css b/src/app/globals.css index 6bfedd6..45f00dd 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -63,3 +63,39 @@ @apply bg-background text-foreground; } } + +.tooltip { + position: relative; + display: inline-block; + cursor: pointer; + margin-left: 5px; +} + +.tooltip .tooltiptext { + visibility: hidden; + width: 200px; + background-color: #292524; + border: black; + border-style: groove; + color: #fff; + text-align: center; + border-radius: 6px; + padding: 5px; + position: absolute; + z-index: 1; + top: 20%; + left: 0%; + margin-left: 0; + opacity: 0; + transition: opacity 0.3s; +} + +.tooltip:hover .tooltiptext, +.tooltip:focus .tooltiptext { + visibility: visible; + opacity: 1; +} + +.info-icon { + vertical-align: middle; +} diff --git a/src/icons/info.tsx b/src/icons/info.tsx new file mode 100644 index 0000000..ca954a8 --- /dev/null +++ b/src/icons/info.tsx @@ -0,0 +1,27 @@ +import React, { FC, ReactElement, MouseEvent } from 'react'; + +const InfoIcon: FC<{ + className?: string; + width?: number; + height?: number; + onClick?: (evt: MouseEvent) => void; +}> = (props): ReactElement => { + return ( + + + + ); +}; + +export default InfoIcon; \ No newline at end of file