Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/AELF_24371059: Transaction Fee is incorrect in transaction summary #11

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}