diff --git a/apps/namadillo/src/App/Masp/MaspShield.tsx b/apps/namadillo/src/App/Masp/MaspShield.tsx index 0f4a55795..cf8b956ec 100644 --- a/apps/namadillo/src/App/Masp/MaspShield.tsx +++ b/apps/namadillo/src/App/Masp/MaspShield.tsx @@ -4,13 +4,14 @@ import { Timeline } from "App/Common/Timeline"; import { params } from "App/routes"; import { OnSubmitTransferParams, + TransactionFee, TransferModule, } from "App/Transfer/TransferModule"; import { allDefaultAccountsAtom } from "atoms/accounts"; import { namadaTransparentAssetsAtom } from "atoms/balance/atoms"; import { chainParametersAtom } from "atoms/chain/atoms"; +import { defaultGasConfigFamily } from "atoms/fees/atoms"; import { shieldTxAtom } from "atoms/shield/atoms"; -import BigNumber from "bignumber.js"; import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import { useTransactionActions } from "hooks/useTransactionActions"; @@ -63,10 +64,15 @@ export const MaspShield: React.FC = () => { const selectedAsset = selectedAssetAddress ? availableAssets?.[selectedAssetAddress] : undefined; - const transactionFee = - selectedAsset ? - // TODO: remove hardcoding - { ...selectedAsset, amount: BigNumber(0.03) } + const { data: gasConfig } = useAtomValue(defaultGasConfigFamily(["Shield"])); + + const transactionFee: TransactionFee | undefined = + selectedAsset && gasConfig ? + { + originalAddress: selectedAsset.originalAddress, + asset: selectedAsset.asset, + amount: gasConfig.gasPrice.multipliedBy(gasConfig.gasLimit), + } : undefined; const assetImage = selectedAsset ? getAssetImageUrl(selectedAsset.asset) : ""; @@ -115,8 +121,8 @@ export const MaspShield: React.FC = () => { throw new Error("No asset is selected"); } - if (typeof transactionFee === "undefined") { - throw new Error("No transaction fee is set"); + if (typeof gasConfig === "undefined") { + throw new Error("No gas config"); } setTransaction({ @@ -131,6 +137,7 @@ export const MaspShield: React.FC = () => { destinationAddress, tokenAddress: selectedAsset.originalAddress, amount, + gasConfig, }); // TODO review and improve this data to be more precise and full of details diff --git a/apps/namadillo/src/App/Masp/MaspUnshield.tsx b/apps/namadillo/src/App/Masp/MaspUnshield.tsx index 47cb7dba8..9564fe144 100644 --- a/apps/namadillo/src/App/Masp/MaspUnshield.tsx +++ b/apps/namadillo/src/App/Masp/MaspUnshield.tsx @@ -4,13 +4,14 @@ import { Timeline } from "App/Common/Timeline"; import { params } from "App/routes"; import { OnSubmitTransferParams, + TransactionFee, TransferModule, } from "App/Transfer/TransferModule"; import { allDefaultAccountsAtom } from "atoms/accounts"; import { namadaShieldedAssetsAtom } from "atoms/balance/atoms"; import { chainParametersAtom } from "atoms/chain/atoms"; +import { defaultGasConfigFamily } from "atoms/fees/atoms"; import { unshieldTxAtom } from "atoms/shield/atoms"; -import BigNumber from "bignumber.js"; import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import { useTransactionActions } from "hooks/useTransactionActions"; @@ -63,10 +64,17 @@ export const MaspUnshield: React.FC = () => { const selectedAsset = selectedAssetAddress ? availableAssets?.[selectedAssetAddress] : undefined; - const transactionFee = - selectedAsset ? - // TODO: remove hardcoding - { ...selectedAsset, amount: BigNumber(0.03) } + const { data: gasConfig } = useAtomValue( + defaultGasConfigFamily(["Unshield"]) + ); + + const transactionFee: TransactionFee | undefined = + selectedAsset && gasConfig ? + { + originalAddress: selectedAsset.originalAddress, + asset: selectedAsset.asset, + amount: gasConfig.gasPrice.multipliedBy(gasConfig.gasLimit), + } : undefined; const assetImage = selectedAsset ? getAssetImageUrl(selectedAsset.asset) : ""; @@ -115,8 +123,8 @@ export const MaspUnshield: React.FC = () => { throw new Error("No asset is selected"); } - if (typeof transactionFee === "undefined") { - throw new Error("No transaction fee is set"); + if (typeof gasConfig === "undefined") { + throw new Error("No gas config"); } setTransaction({ @@ -131,6 +139,7 @@ export const MaspUnshield: React.FC = () => { destinationAddress, tokenAddress: selectedAsset.originalAddress, amount, + gasConfig, }); // TODO review and improve this data to be more precise and full of details diff --git a/apps/namadillo/src/atoms/fees/functions.ts b/apps/namadillo/src/atoms/fees/functions.ts index 1ad097044..3894f90d4 100644 --- a/apps/namadillo/src/atoms/fees/functions.ts +++ b/apps/namadillo/src/atoms/fees/functions.ts @@ -20,6 +20,10 @@ export const txKindToIndexer = (txKind: TxKind): GasLimitTableIndexer => { return GasLimitTableIndexer.RevealPk; case "IbcTransfer": return GasLimitTableIndexer.IbcMsgTransfer; + case "Shield": + return GasLimitTableIndexer.ShieldingTransfer; + case "Unshield": + return GasLimitTableIndexer.UnshieldingTransfer; case "Unknown": return GasLimitTableIndexer.Unknown; default: diff --git a/apps/namadillo/src/atoms/shield/services.ts b/apps/namadillo/src/atoms/shield/services.ts index 01bab6788..fa0d64772 100644 --- a/apps/namadillo/src/atoms/shield/services.ts +++ b/apps/namadillo/src/atoms/shield/services.ts @@ -6,7 +6,7 @@ import { import BigNumber from "bignumber.js"; import * as Comlink from "comlink"; import { EncodedTxData, signTx } from "lib/query"; -import { Address, ChainSettings } from "types"; +import { Address, ChainSettings, GasConfig } from "types"; import { Shield } from "workers/ShieldMessages"; import { registerTransferHandlers as shieldRegisterTransferHandlers, @@ -25,6 +25,7 @@ export type ShieldTransferParams = { destinationAddress: Address; tokenAddress: Address; amount: BigNumber; + gasConfig: GasConfig; }; export type UnshieldTransferParams = { @@ -32,6 +33,7 @@ export type UnshieldTransferParams = { destinationAddress: Address; tokenAddress: Address; amount: BigNumber; + gasConfig: GasConfig; }; export const submitShieldTx = async ( @@ -49,6 +51,7 @@ export const submitShieldTx = async ( destinationAddress: target, tokenAddress: token, amount, + gasConfig, } = params; shieldRegisterTransferHandlers(); @@ -65,11 +68,7 @@ export const submitShieldTx = async ( type: "shield", payload: { account, - // TODO - gasConfig: { - gasLimit: BigNumber(250000), - gasPrice: BigNumber(0.000001), - }, + gasConfig, shieldingProps: [shieldingMsgValue], chain, indexerUrl, @@ -108,6 +107,7 @@ export const submitUnshieldTx = async ( destinationAddress: target, tokenAddress: token, amount, + gasConfig, } = params; unshieldRegisterTransferHandlers(); @@ -124,11 +124,7 @@ export const submitUnshieldTx = async ( type: "unshield", payload: { account, - // TODO - gasConfig: { - gasLimit: BigNumber(250000), - gasPrice: BigNumber(0.000001), - }, + gasConfig, unshieldingProps: [unshieldingMsgValue], chain, indexerUrl,