Skip to content

Commit

Permalink
Merge pull request #11 from yongenaelf/fix/AELF_24371059
Browse files Browse the repository at this point in the history
fix/AELF_24371059: Transaction Fee is incorrect in transaction summary
  • Loading branch information
Faizal-aelf authored Nov 30, 2023
2 parents c8bf2e8 + 24a2497 commit fa79146
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions components/transactions/components/TransferVerification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { transfer } from "@/utils/transaction";
import { useAElf } from "@/hooks/useAElf";
import { chainState, addressState } from "@/state";
import { rpcUrlState } from "@/state/selector";
import { isEmptyObject } from "@/utils";
import { fetchMainAddress, getFormattedAddress } from "../utils";
import styles from '../style.module.css';

Expand Down Expand Up @@ -36,7 +37,7 @@ const TransferVerification = ({
const rpcUrl = useRecoilValue(rpcUrlState);
const [isInsufficient, setInsufficient] = useState<boolean>(false);
const [error, setError] = useState<string>('');
const [fees, setFees] = useState<number>(0);
const [fees, setFees] = useState<string>('-');
const chain = useRecoilValue(chainState);
const aelfInstance = useAElf();
const amount = new BigNumber(data.amount.replaceAll(",", ""));
Expand All @@ -46,7 +47,6 @@ const TransferVerification = ({
try {
if (!tokenContract) throw new Error("no contract");
const { tokenContractAddress } = tokenContract;

const rawTx = await transfer(
address,
fetchMainAddress(to),
Expand All @@ -69,8 +69,12 @@ const TransferVerification = ({
);
const {Success, TransactionFee } = await feeResponse.json();
if (Success) {
const calculatedFees = Number(new BigNumber(TransactionFee.ELF).dividedBy(10 ** 8).toNumber());
setFees(calculatedFees);
if (isEmptyObject(TransactionFee)) {
setFees('-');
} else {
const calculatedFees = Number(new BigNumber(TransactionFee.ELF).dividedBy(10 ** 8).toNumber());
setFees(`${calculatedFees} ELF`);
}
setInsufficient(false);
setError('');
} else {
Expand Down Expand Up @@ -105,7 +109,7 @@ const TransferVerification = ({
<FormField label="To">{getFormattedAddress(data.to, chain)}</FormField>
<FormField label="Amount">{amount.toNumber().toFixed(amount.dp()).replace(/\B(?=(\d{3})+(?!\d))/g, ",")} ELF</FormField>
<FormField label="Memo">{data.memo}</FormField>
{!isInsufficient && <FormField label="Transaction Fee">{fees} ELF</FormField>}
{!isInsufficient && <FormField label="Transaction Fee">{fees}</FormField>}
</Modal>
);
};
Expand Down
4 changes: 4 additions & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export const formatNumber = (value: string) => {
} else {
return integerPart;
}
}

export const isEmptyObject = (obj: object) => {
return Object.keys(obj).length === 0;
}

0 comments on commit fa79146

Please sign in to comment.