Skip to content

Commit

Permalink
Make fee configurable (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Jan 11, 2024
1 parent c32f7e2 commit 03ccf5d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ considered compromised.** If you want to test services on mainnet with this
tool, make sure to create a new account and fund it with the minimum assets
required.

Note, that dy default base fee is 100 stroops. That may not be enough for mainnet application, and base fee can be changed via `REACT_APP_BASE_FEE` environment variable

## Getting A Test Account Up and Running

You can use the demo wallet to interact with the following anchor services:
Expand Down
3 changes: 1 addition & 2 deletions packages/demo-wallet-client/src/ducks/claimAsset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { BASE_FEE } from "stellar-sdk";
import { RootState } from "config/store";
import { accountSelector } from "ducks/account";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
Expand Down Expand Up @@ -65,7 +64,7 @@ export const claimAssetAction = createAsyncThunk<
assetCode,
networkPassphrase: networkConfig.network,
networkUrl: networkConfig.url,
fee: BASE_FEE,
fee: networkConfig.baseFee,
});

return { result, trustedAssetAdded };
Expand Down
3 changes: 2 additions & 1 deletion packages/demo-wallet-shared/helpers/getNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Networks } from "stellar-sdk";
import {Networks, BASE_FEE} from "stellar-sdk";

export const getNetworkConfig = () => {
return {
network: window._env_.HORIZON_PASSPHRASE || Networks.TESTNET,
url: window._env_.HORIZON_URL || "https://horizon-testnet.stellar.org",
baseFee: process?.env?.REACT_APP_BASE_FEE || BASE_FEE,
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Account,
Asset,
BASE_FEE,
Keypair,
Operation,
Horizon,
Expand All @@ -10,6 +9,7 @@ import {
import { log } from "../../helpers/log";
import { createMemoFromType } from "../createMemoFromType";
import { TransactionStatus } from "../../types/types";
import {getNetworkConfig} from "../../helpers/getNetworkConfig";

export const pollWithdrawUntilComplete = async ({
secretKey,
Expand Down Expand Up @@ -93,7 +93,7 @@ export const pollWithdrawUntilComplete = async ({

const account = new Account(keypair.publicKey(), sequence);
const txn = new TransactionBuilder(account, {
fee: BASE_FEE,
fee: getNetworkConfig().baseFee,
networkPassphrase,
})
.addOperation(
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-wallet-shared/methods/sep31Send/sendPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getCatchError } from "@stellar/frontend-helpers";
import {
Account,
Asset,
BASE_FEE,
Keypair,
Memo,
Operation,
Expand All @@ -11,6 +10,7 @@ import {
} from "stellar-sdk";
import { log } from "../../helpers/log";
import { MemoTypeString } from "../../types/types";
import {getNetworkConfig} from "../../helpers/getNetworkConfig";

interface SendPaymentProps {
secretKey: string;
Expand Down Expand Up @@ -100,7 +100,7 @@ export const sendPayment = async ({
}

const tx = new TransactionBuilder(new Account(publicKey, sequence), {
fee: (Number(BASE_FEE) * 5).toString(),
fee: (Number(getNetworkConfig().baseFee) * 5).toString(),
networkPassphrase,
})
.addOperation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Account,
Asset,
BASE_FEE,
Keypair,
Operation,
Horizon,
Expand All @@ -10,6 +9,7 @@ import {
import { log } from "../../helpers/log";
import { createMemoFromType } from "../createMemoFromType";
import { AnyObject, TransactionStatus } from "../../types/types";
import {getNetworkConfig} from "../../helpers/getNetworkConfig";

export const pollWithdrawUntilComplete = async ({
amount,
Expand Down Expand Up @@ -95,7 +95,7 @@ export const pollWithdrawUntilComplete = async ({

const account = new Account(keypair.publicKey(), sequence);
const txn = new TransactionBuilder(account, {
fee: BASE_FEE,
fee: getNetworkConfig().baseFee,
networkPassphrase,
})
.addOperation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BASE_FEE,
Keypair,
Horizon,
Account,
Expand Down Expand Up @@ -115,7 +114,7 @@ export const buildPaymentTransaction = async ({
}

transaction = new TransactionBuilder(source, {
fee: BASE_FEE,
fee: getNetworkConfig().baseFee,
networkPassphrase: getNetworkConfig().network,
timebounds: await server.fetchTimebounds(100),
}).addOperation(operation);
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-wallet-shared/methods/trustAsset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
TransactionBuilder,
BASE_FEE,
Operation,
Asset,
Keypair,
Expand All @@ -9,6 +8,7 @@ import {
import { getErrorMessage } from "../helpers/getErrorMessage";
import { log } from "../helpers/log";
import { TrustAssetParam } from "../types/types";
import {getNetworkConfig} from "../helpers/getNetworkConfig";

export const trustAsset = async ({
secretKey,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const trustAsset = async ({

log.instruction({ title: "Building add trustline transaction" });
const transaction = new TransactionBuilder(account, {
fee: BASE_FEE,
fee: getNetworkConfig().baseFee,
networkPassphrase,
})
.addOperation(
Expand Down

0 comments on commit 03ccf5d

Please sign in to comment.