Skip to content

Commit

Permalink
🐛 fix: erc20 gas format (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustin01 authored Aug 20, 2024
1 parent 98a41e6 commit 04231dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions apps/wallet/src/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import { FC } from "react";
import { useNavigate } from "react-router-dom";
import SvgGo from '../assets/right-arrow.svg?react'

const PageHeader: FC<{ title: string, backable?: boolean }> = ({ title, backable = true }) => {
const PageHeader: FC<{
title: string,
backable?: boolean
onBeforeBack?: () => void
}> = ({ title, backable = true, onBeforeBack }) => {
const navigate = useNavigate()

if (backable) {
return (
<div className="flex-none">
<button className="btn btn-ghost btn-sm gap-2 items-center pl-0" onClick={() => navigate(-1)}>
<button className="btn btn-ghost btn-sm gap-2 items-center pl-0" onClick={() => {
onBeforeBack?.()
navigate(-1)
}}>
<SvgGo className="size-6 rotate-180" />
<span className="text-base font-bold">{title}</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/pages/send-token/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const SendTokenPage: FC = observer(() => {

return (
<div className="h-full px-6 flex flex-col gap-6 overflow-auto">
<PageHeader title="Send" />
<PageHeader title="Send" onBeforeBack={() => sendTokenStore.reset()} />
<div className="flex-1 flex flex-col gap-6">
<div>
<label className="form-control w-full">
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/utils/chain/chain-wallets/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BigNumber from "bignumber.js";
import { AssetInfo, ChainWallet } from "../types";
import { isAddress, JsonRpcProvider, Contract, HDNodeWallet, parseEther, parseUnits } from "ethers";
import { isAddress, JsonRpcProvider, Contract, HDNodeWallet, parseEther, parseUnits, formatEther } from "ethers";
import { Chain, ChainAssetType, ChainId, ChainInfo } from "../../../basicTypes";
import { erc20Abi } from "./erc20";
import { WalletAccount } from "@deland-labs/hibit-id-sdk";
Expand Down Expand Up @@ -135,7 +135,7 @@ export class EthereumChainWallet extends ChainWallet {
const estimatedGas = await token
.getFunction('transfer')
.estimateGas(toAddress, parseUnits(amount.toString(), decimals));
return new BigNumber(parseEther(new BigNumber(estimatedGas.toString()).times(price).toString()).toString())
return new BigNumber(formatEther(new BigNumber(estimatedGas.toString()).times(price).toString()))
}

throw new Error(`Ethereum: unsupported chain asset type ${assetInfo.chainAssetType.toString()}`);
Expand Down

0 comments on commit 04231dc

Please sign in to comment.