-
Notifications
You must be signed in to change notification settings - Fork 106
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
Namadillo: Fees #904
Closed
Closed
Namadillo: Fees #904
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { IoWarningOutline } from "react-icons/io5"; | ||
|
||
export const FeeWarning = (): JSX.Element => { | ||
return ( | ||
<div className="flex text-xs items-center gap-1 text-yellow"> | ||
<i className="text-sm"> | ||
<IoWarningOutline /> | ||
</i> | ||
Remember to keep a small amount of NAM for fees | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
import { gasLimitsAtom, minimumGasPriceAtom } from "atoms/fees"; | ||
import clsx from "clsx"; | ||
import { useGasEstimate } from "hooks/useGasEstimate"; | ||
import { useAtomValue } from "jotai"; | ||
import { TxKind } from "types"; | ||
import { FeeWarning } from "./FeeWarning"; | ||
import { NamCurrency } from "./NamCurrency"; | ||
import { TextLink } from "./TextLink"; | ||
|
||
type TransactionFeesProps = { | ||
txKind: TxKind; | ||
numberOfTransactions: number; | ||
displayWarning?: boolean; | ||
className?: string; | ||
}; | ||
|
||
export const TransactionFees = ({ | ||
txKind, | ||
numberOfTransactions, | ||
displayWarning, | ||
className, | ||
}: TransactionFeesProps): JSX.Element => { | ||
const { calculateMinGasRequired } = useGasEstimate(); | ||
const minimumGas = calculateMinGasRequired(numberOfTransactions); | ||
const gasLimits = useAtomValue(gasLimitsAtom); | ||
const gasPrice = useAtomValue(minimumGasPriceAtom); | ||
|
||
if (!gasLimits.isSuccess || !gasPrice.isSuccess || numberOfTransactions === 0) | ||
return <></>; | ||
|
||
if (!minimumGas || minimumGas.eq(0)) return <></>; | ||
return ( | ||
<div className={clsx("text-white text-sm", className)}> | ||
<TextLink>Transaction fee:</TextLink>{" "} | ||
<NamCurrency | ||
className="font-medium" | ||
amount={minimumGas} | ||
forceBalanceDisplay={true} | ||
/> | ||
<div className={clsx("flex flex-col", className)}> | ||
<div className="text-white text-sm"> | ||
Transaction fee:{" "} | ||
<NamCurrency | ||
className="font-medium" | ||
forceBalanceDisplay={true} | ||
amount={gasPrice.data.multipliedBy( | ||
gasLimits.data[txKind].native.multipliedBy(numberOfTransactions) | ||
)} | ||
/> | ||
</div> | ||
{displayWarning && <FeeWarning />} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ export const fetchMinimumGasPrice = async ( | |
({ token }) => token === nativeToken | ||
); | ||
invariant(!!nativeTokenCost, "Error querying minimum gas price"); | ||
const asBigNumber = new BigNumber(nativeTokenCost.amount); | ||
// TODO: this should be removed after indexer error is fixed! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is fixed now. |
||
const asBigNumber = new BigNumber(nativeTokenCost.amount).dividedBy(100000); | ||
invariant( | ||
!asBigNumber.isNaN(), | ||
"Error converting minimum gas price to BigNumber" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this still be correct in cases where a reveal PK is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need to review it again after the batch tx PR gets in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With batch Tx in, RevealPk wasn't considered when calculating fees - it is overestimating though so will work as is (though is incorrect). We still need to determine how fees can be calculated when we have a batch with of Txs, and (currently) at most 2 Tx types in that batch (RevealPK + the type of other Txs). I'm up for taking a look, and we don't necessarily need to address that in this PR!