Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-hash committed Dec 15, 2024
1 parent e20cb41 commit 31d0d0d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
17 changes: 16 additions & 1 deletion app/src/components/BurnSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import React from 'react';
import Image from 'next/image';
import styles from "../styles/BurnSummary.module.css";

const humanizeNumber = (num: number): string => {
if (num >= 1000000000) {
return (num / 1000000000).toFixed(2) + 'B';
}
if (num >= 1000000) {
return (num / 1000000).toFixed(2) + 'M';
}
if (num >= 1000) {
return (num / 1000).toFixed(2) + 'K';
}
return num.toFixed(2);
};

interface BurnSummaryProps {
amount: string;
tokenSymbol?: string;
Expand All @@ -12,6 +25,8 @@ interface BurnSummaryProps {
export const BurnSummary: React.FC<BurnSummaryProps> = ({ amount, tokenSymbol, txId, logoURI }) => {
if (!txId) return null;

const humanizedAmount = humanizeNumber(Number(amount));

return (
<div className={styles.summaryContainer}>
<h3>Burn Summary</h3>
Expand All @@ -25,7 +40,7 @@ export const BurnSummary: React.FC<BurnSummaryProps> = ({ amount, tokenSymbol, t
className={styles.tokenLogo}
/>
)}
{' '} You burned {Number(amount).toFixed(2)} {tokenSymbol}</p>
{' '} You burned {humanizedAmount} {tokenSymbol}</p>
</div>
<a
href={`https://explorer.alephium.org/transactions/${txId}`}
Expand Down
47 changes: 31 additions & 16 deletions app/src/components/FurnacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const FurnacePage: FC = () => {
const [computedBalance, setComputedBalance] = useState<string>('0');
const [isCustomToken, setIsCustomToken] = useState(false);
const [txId, setTxId] = useState<string | undefined>(undefined);
const [showSummary, setShowSummary] = useState(false);
const nodeRef = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -96,6 +97,17 @@ export const FurnacePage: FC = () => {
}
}, [balance, selectedToken]);

useEffect(() => {
setShowSummary(false);
setTxId(undefined);
}, [amount, selectedToken]);

useEffect(() => {
if (txId) {
setShowSummary(true);
}
}, [txId]);

const handleConvert = async () => {
if (!amount) {
alert("Please enter an amount");
Expand All @@ -109,21 +121,24 @@ export const FurnacePage: FC = () => {
}

if (signer) {
const floatToDecimals = convertToInt(amount)
console.log(floatToDecimals)
const tx = await burn(
signer,
floatToDecimals[0],
floatToDecimals[1],
selectedToken?.id ?? '',
selectedToken?.decimals ?? 0,
withNft,
account?.group
);
setTxId(tx.txId)
updateBalanceForTx(tx.txId, 1)
try {
const floatToDecimals = convertToInt(amount)
console.log(floatToDecimals)
const tx = await burn(
signer,
floatToDecimals[0],
floatToDecimals[1],
selectedToken?.id ?? '',
selectedToken?.decimals ?? 0,
withNft,
account?.group
);
setTxId(tx.txId)
updateBalanceForTx(tx.txId, 1)
} catch (error) {
console.error("Error during burn:", error);
}
}
console.log("Convert button clicked with amount:", amount);
};

return (
Expand All @@ -137,7 +152,7 @@ export const FurnacePage: FC = () => {
<div className={styles.imageContainer}>
<SwitchTransition>
<CSSTransition
key={txId ? 'summary' : 'image'}
key={showSummary ? 'summary' : 'image'}
timeout={300}
classNames={{
enter: styles.fadeEnter,
Expand All @@ -148,7 +163,7 @@ export const FurnacePage: FC = () => {
nodeRef={nodeRef}
>
<div ref={nodeRef}>
{txId ? (
{showSummary ? (
<BurnSummary
amount={amount}
tokenSymbol={selectedToken?.symbol}
Expand Down

0 comments on commit 31d0d0d

Please sign in to comment.