Skip to content

Commit

Permalink
feat: use gas config
Browse files Browse the repository at this point in the history
  • Loading branch information
euharrison committed Nov 15, 2024
1 parent e811bcb commit ec57930
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
21 changes: 14 additions & 7 deletions apps/namadillo/src/App/Masp/MaspShield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) : "";
Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand Down
23 changes: 16 additions & 7 deletions apps/namadillo/src/App/Masp/MaspUnshield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) : "";
Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions apps/namadillo/src/atoms/fees/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 7 additions & 11 deletions apps/namadillo/src/atoms/shield/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,13 +25,15 @@ export type ShieldTransferParams = {
destinationAddress: Address;
tokenAddress: Address;
amount: BigNumber;
gasConfig: GasConfig;
};

export type UnshieldTransferParams = {
sourceAddress: Address;
destinationAddress: Address;
tokenAddress: Address;
amount: BigNumber;
gasConfig: GasConfig;
};

export const submitShieldTx = async (
Expand All @@ -49,6 +51,7 @@ export const submitShieldTx = async (
destinationAddress: target,
tokenAddress: token,
amount,
gasConfig,
} = params;

shieldRegisterTransferHandlers();
Expand All @@ -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,
Expand Down Expand Up @@ -108,6 +107,7 @@ export const submitUnshieldTx = async (
destinationAddress: target,
tokenAddress: token,
amount,
gasConfig,
} = params;

unshieldRegisterTransferHandlers();
Expand All @@ -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,
Expand Down

0 comments on commit ec57930

Please sign in to comment.