-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing gas estimate on IBC transfers (#1607)
* fix: fixing gas estimate * fix: fixing gas asset on Namada transactions
- Loading branch information
1 parent
7fb9b0a
commit be1e7d7
Showing
11 changed files
with
126 additions
and
60 deletions.
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
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
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 |
---|---|---|
@@ -1,8 +1,37 @@ | ||
import { Asset } from "@chain-registry/types"; | ||
import { isTransparentAddress } from "App/Transfer/common"; | ||
import BigNumber from "bignumber.js"; | ||
import { GasConfig } from "types"; | ||
import { findAssetByDenom } from "integrations/utils"; | ||
import { Address, GasConfig, GasConfigToDisplay } from "types"; | ||
import { isNamadaAsset, toDisplayAmount } from "utils"; | ||
import { unknownAsset } from "./assets"; | ||
|
||
export const getDisplayGasFee = (gasConfig: GasConfig): BigNumber => { | ||
return BigNumber(gasConfig.gasPrice) | ||
.multipliedBy(gasConfig.gasLimit) | ||
.decimalPlaces(6); | ||
export const calculateGasFee = (gasConfig: GasConfig): BigNumber => { | ||
return BigNumber(gasConfig.gasPrice).multipliedBy(gasConfig.gasLimit); | ||
}; | ||
|
||
export const getDisplayGasFee = ( | ||
gasConfig: GasConfig, | ||
chainAssetsMap?: Record<Address, Asset> | ||
): GasConfigToDisplay => { | ||
const { gasToken } = gasConfig; | ||
let asset: Asset; | ||
|
||
if (isTransparentAddress(gasToken) && chainAssetsMap) { | ||
// The gasConfig token might be the address of the token on Namada chain | ||
asset = chainAssetsMap[gasToken] ?? unknownAsset(gasToken); | ||
} else { | ||
// However, if the gasConfig contains a token used by Keplr, it could be the asset | ||
// denomination unit, like "uosmo" | ||
asset = findAssetByDenom(gasToken) ?? unknownAsset(gasToken); | ||
} | ||
|
||
const totalDisplayAmount = calculateGasFee(gasConfig); | ||
return { | ||
totalDisplayAmount: | ||
isNamadaAsset(asset) ? totalDisplayAmount : ( | ||
toDisplayAmount(asset, totalDisplayAmount).decimalPlaces(6) | ||
), | ||
asset, | ||
}; | ||
}; |