Skip to content

Commit c08468b

Browse files
committed
feat: fix names and refactor
1 parent cac4861 commit c08468b

File tree

16 files changed

+62
-75
lines changed

16 files changed

+62
-75
lines changed

apps/namadillo/public/config.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#localnet_enabled = false
66
#fathom_site_id = ""
77

8-
[server_fee.*]
9-
transparent_target = "tnam1qrku7yxdt6d23nhe826ntukygzkfyczuu5mm0yll"
10-
shielded_target = "znam175uaqlukleyjjyfcccehp2pw3g696a57skewlv0fenldlw702gtjd6qkpjs09zxl6jafsz3e73h"
8+
[frontend_fee."*"]
9+
transparent_target = "tnam1qrxsru5rdu4he400xny6p779fcw7xuftsgjnmzup"
10+
shielded_target = "znam1494fmm9qd4frr7jrydnxlcyt57nhngzutxnzgh6y70mkvh23d9z0jk2aasxh4p8dn2kczlgpans"
1111
percentage = 0.1
1212

13-
[server_fee.tnam1p54697ljxkw3ptffwy8xjhua9uwjc7kk9cc6fxnw]
13+
[frontend_fee.tnam1p54697ljxkw3ptffwy8xjhua9uwjc7kk9cc6fxnw]
1414
transparent_target = "tnam1qrku7yxdt6d23nhe826ntukygzkfyczuu5mm0yll"
1515
shielded_target = "znam175uaqlukleyjjyfcccehp2pw3g696a57skewlv0fenldlw702gtjd6qkpjs09zxl6jafsz3e73h"
1616
percentage = 0.5

apps/namadillo/src/App/Ibc/IbcTransfer.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ export const IbcTransfer = ({
6969
const { trackEvent } = useFathomTracker();
7070
const { storeTransaction } = useTransactionActions();
7171

72-
const {
73-
transferToNamada,
74-
gasConfig: gasConfigQuery,
75-
frontendFeeConfig,
76-
} = useIbcTransaction({
72+
const { transferToNamada, gasConfig, frontendFee } = useIbcTransaction({
7773
registry,
7874
sourceAddress,
7975
sourceChannel,
@@ -82,16 +78,6 @@ export const IbcTransfer = ({
8278
selectedAsset: selectedAssetWithAmount?.asset,
8379
});
8480

85-
// Transfer module expects gasToken to be address of the token on the side of namada
86-
const gasConfig = useMemo(() => {
87-
if (gasConfigQuery.data && selectedAssetWithAmount?.asset.address) {
88-
return {
89-
...gasConfigQuery.data,
90-
gasToken: selectedAssetWithAmount.asset.address,
91-
};
92-
}
93-
}, [gasConfigQuery.data, selectedAssetWithAmount?.asset.address]);
94-
9581
// DERIVED VALUES
9682
const shielded = isShieldedAddress(destinationAddress ?? "");
9783
const availableDisplayAmount = mapUndefined((baseDenom) => {
@@ -175,8 +161,8 @@ export const IbcTransfer = ({
175161
isShieldedAddress: shielded,
176162
onChangeAddress: setDestinationAddress,
177163
}}
178-
gasConfig={gasConfig}
179-
frontendFeeConfig={frontendFeeConfig}
164+
gasConfig={gasConfig.data}
165+
frontendFee={frontendFee}
180166
isSubmitting={
181167
transferToNamada.isPending ||
182168
/* isSuccess means that the transaction has been broadcasted, but doesn't take

apps/namadillo/src/App/Swap/hooks/usePerformOsmosisSwapTx.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export function usePerformOsmosisSwapTx(): UsePerformOsmosisSwapResult {
181181
account: transparentAccount,
182182
params: [params],
183183
gasConfig: feeProps.gasConfig,
184+
frontendFee: feeProps.frontendFee,
184185
});
185186

186187
setStatus(SwapStatus.awaitingSignature());

apps/namadillo/src/App/Transfer/TransferModule.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const TransferModule = ({
5151
currentStatus,
5252
currentStatusExplanation,
5353
gasConfig: gasConfigProp,
54-
frontendFeeConfig: frontendFeeConfigProp,
54+
frontendFee: frontendFeeProp,
5555
onSubmitTransfer,
5656
completedAt,
5757
onComplete,
@@ -124,8 +124,7 @@ export const TransferModule = ({
124124

125125
// We have to do this to get correct config for ibc deposits
126126
const gasConfig = gasConfigProp ?? feeProps?.gasConfig;
127-
const frontendFeeConfig =
128-
frontendFeeConfigProp ?? feeProps?.frontendFeeConfig;
127+
const frontendFee = frontendFeeProp ?? feeProps?.frontendFee;
129128

130129
const displayGasFee = useMemo(() => {
131130
return gasConfig ?
@@ -143,8 +142,9 @@ export const TransferModule = ({
143142
.decimalPlaces(6);
144143
}
145144

145+
// TODO: move this code
146146
const frontendSusFee =
147-
frontendFeeConfig?.[selectedAsset.asset.address || "default"];
147+
frontendFee?.[selectedAsset.asset.address || "default"];
148148

149149
if (frontendSusFee && (isShielding || isUnshielding)) {
150150
amountMinusFees = amountMinusFees

apps/namadillo/src/App/Transfer/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Asset,
99
AssetWithAmountAndChain,
1010
ChainRegistryEntry,
11-
FrontendFeeConfig,
11+
FrontendFee,
1212
GasConfig,
1313
LedgerAccountInfo,
1414
WalletProvider,
@@ -59,7 +59,7 @@ export type TransferModuleProps = {
5959
errorMessage?: string;
6060
// Fee overrides - used for IBC deposits only
6161
gasConfig?: GasConfig;
62-
frontendFeeConfig?: FrontendFeeConfig;
62+
frontendFee?: FrontendFee;
6363
currentStatus: string;
6464
currentStatusExplanation?: string;
6565
onSubmitTransfer: (params: OnSubmitTransferParams) => Promise<void>;

apps/namadillo/src/atoms/fees/services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "@namada/indexer-client";
66
import { FrontendSusFeeProps } from "@namada/sdk-multicore";
77
import { assertNever } from "@namada/utils";
8-
import { FrontendFeeConfig } from "types";
8+
import { FrontendFee } from "types";
99
import { TxKind } from "types/txKind";
1010

1111
export const fetchGasEstimate = async (
@@ -53,12 +53,12 @@ export const fetchTokensGasPrice = async (
5353
};
5454

5555
export const frontendSusMsgFromConfig = (
56-
frontendFeeConfig: FrontendFeeConfig,
56+
frontendFee: FrontendFee,
5757
token: string,
5858
whichTarget: "shielded" | "transparent"
5959
): FrontendSusFeeProps => {
6060
const { percentage, shieldedTarget, transparentTarget } =
61-
frontendFeeConfig[token] || frontendFeeConfig["*"];
61+
frontendFee[token] || frontendFee["*"];
6262

6363
const target =
6464
whichTarget === "shielded" ? shieldedTarget

apps/namadillo/src/atoms/integrations/services.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { getIndexerApi } from "atoms/api";
1818
import { chainParametersAtom } from "atoms/chain";
1919
import { frontendSusMsgFromConfig } from "atoms/fees";
20-
import { rpcUrlAtom, serverFeeAtom } from "atoms/settings";
20+
import { frontendFeeAtom, rpcUrlAtom } from "atoms/settings";
2121
import { queryForAck, queryForIbcTimeout } from "atoms/transactions";
2222
import BigNumber from "bignumber.js";
2323
import * as Comlink from "comlink";
@@ -75,7 +75,7 @@ export const getShieldedArgs = async (
7575
const store = getDefaultStore();
7676
const rpcUrl = store.get(rpcUrlAtom);
7777
const chain = store.get(chainParametersAtom);
78-
const frontendFeeConfig = store.get(serverFeeAtom);
78+
const frontendFee = store.get(frontendFeeAtom);
7979

8080
if (!chain.isSuccess) throw "Chain not loaded";
8181

@@ -87,9 +87,10 @@ export const getShieldedArgs = async (
8787
});
8888

8989
const frontendSusFee = frontendSusMsgFromConfig(
90-
frontendFeeConfig,
90+
frontendFee,
9191
namadaToken,
92-
"transparent"
92+
// For IBC shielding, the fee is always deposited into shielded pool
93+
"shielded"
9394
);
9495

9596
const msg: GenerateIbcShieldingMemo = {

apps/namadillo/src/atoms/settings/atoms.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ export const maspIndexerUrlAtom = atom((get) => {
179179
});
180180

181181
// TODO: figure out where to have this atom
182-
export const serverFeeAtom = atom((get) => {
183-
const serverFee = get(defaultServerConfigAtom).data?.server_fee;
182+
export const frontendFeeAtom = atom((get) => {
183+
const frontendFee = get(defaultServerConfigAtom).data?.frontend_fee;
184184
// TODO: validate with schema
185185
return pipe(
186-
serverFee ?? {},
186+
frontendFee ?? {},
187187
R.map((fee) => ({
188188
transparentTarget: fee.transparent_target,
189189
shieldedTarget: fee.shielded_target,

apps/namadillo/src/atoms/transfer/atoms.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ export const createShieldingTransferAtom = atomWithMutation((get) => {
103103
gasConfig,
104104
account,
105105
memo,
106-
frontendFeeConfig,
106+
frontendFee,
107107
}: BuildTxAtomParams<ShieldingTransferProps>) =>
108108
createShieldingTransferTx(
109109
chain.data!,
110110
account,
111111
params,
112112
gasConfig,
113113
rpcUrl,
114-
memo,
115-
frontendFeeConfig
114+
frontendFee,
115+
memo
116116
),
117117
};
118118
});
@@ -130,8 +130,8 @@ export const createUnshieldingTransferAtom = atomWithMutation((get) => {
130130
gasConfig,
131131
account,
132132
signer,
133+
frontendFee,
133134
memo,
134-
frontendFeeConfig,
135135
}: BuildTxAtomParams<UnshieldingTransferProps>) => {
136136
invariant(
137137
signer,
@@ -153,8 +153,8 @@ export const createUnshieldingTransferAtom = atomWithMutation((get) => {
153153
gasConfig,
154154
rpcUrl,
155155
signer,
156-
memo,
157-
frontendFeeConfig
156+
frontendFee,
157+
memo
158158
);
159159
},
160160
};
@@ -225,7 +225,7 @@ export const createIbcTxAtom = atomWithMutation((get) => {
225225
account,
226226
signer,
227227
memo,
228-
frontendFeeConfig,
228+
frontendFee,
229229
}: BuildTxAtomParams<IbcTransferProps>) => {
230230
invariant(
231231
signer,
@@ -241,8 +241,8 @@ export const createIbcTxAtom = atomWithMutation((get) => {
241241
gasConfig,
242242
rpcUrl,
243243
signer?.publicKey,
244-
memo,
245-
frontendFeeConfig
244+
frontendFee,
245+
memo
246246
);
247247
},
248248
};

apps/namadillo/src/atoms/transfer/services.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import BigNumber from "bignumber.js";
1818
import * as Comlink from "comlink";
1919
import { NamadaKeychain } from "hooks/useNamadaKeychain";
2020
import { buildTx, EncodedTxData, isPublicKeyRevealed } from "lib/query";
21-
import { Address, ChainSettings, FrontendFeeConfig, GasConfig } from "types";
21+
import { Address, ChainSettings, FrontendFee, GasConfig } from "types";
2222
import { getSdkInstance } from "utils/sdk";
2323
import {
2424
IbcTransfer,
@@ -169,7 +169,7 @@ export const createShieldingTransferTx = async (
169169
props: ShieldingTransferProps[],
170170
gasConfig: GasConfig,
171171
rpcUrl: string,
172-
frontendFeeConfig: FrontendFeeConfig,
172+
frontendFee: FrontendFee,
173173
memo?: string
174174
): Promise<EncodedTxData<ShieldingTransferProps> | undefined> => {
175175
const source = props[0]?.data[0]?.source;
@@ -192,7 +192,7 @@ export const createShieldingTransferTx = async (
192192
buildTxFn: async (workerLink) => {
193193
const publicKeyRevealed = await isPublicKeyRevealed(account.address);
194194
const frontendSusFee = frontendSusMsgFromConfig(
195-
frontendFeeConfig,
195+
frontendFee,
196196
token,
197197
"transparent"
198198
);
@@ -228,7 +228,7 @@ export const createUnshieldingTransferTx = async (
228228
gasConfig: GasConfig,
229229
rpcUrl: string,
230230
disposableSigner: GenDisposableSignerResponse,
231-
frontendFeeConfig: FrontendFeeConfig,
231+
frontendFee: FrontendFee,
232232
memo?: string
233233
): Promise<EncodedTxData<UnshieldingTransferProps> | undefined> => {
234234
const { publicKey: signerPublicKey } = disposableSigner;
@@ -253,7 +253,7 @@ export const createUnshieldingTransferTx = async (
253253
nativeToken: chain.nativeTokenAddress,
254254
buildTxFn: async (workerLink) => {
255255
const frontendSusFee = frontendSusMsgFromConfig(
256-
frontendFeeConfig,
256+
frontendFee,
257257
token,
258258
"transparent"
259259
);
@@ -289,7 +289,7 @@ export const createIbcTx = async (
289289
gasConfig: GasConfig,
290290
rpcUrl: string,
291291
signerPublicKey: string,
292-
frontendFeeConfig: FrontendFeeConfig,
292+
frontendFee: FrontendFee,
293293
memo?: string
294294
): Promise<EncodedTxData<IbcTransferProps>> => {
295295
let bparams: BparamsMsgValue[] | undefined;
@@ -305,11 +305,11 @@ export const createIbcTx = async (
305305
nativeToken: chain.nativeTokenAddress,
306306
buildTxFn: async (workerLink) => {
307307
const firstProps = props[0];
308-
const frontendSusFee = frontendSusMsgFromConfig(
309-
frontendFeeConfig,
310-
firstProps.token,
311-
"transparent"
312-
);
308+
const isUnshielding = firstProps.gasSpendingKey === firstProps.source;
309+
const frontendSusFee =
310+
isUnshielding ?
311+
frontendSusMsgFromConfig(frontendFee, firstProps.token, "transparent")
312+
: undefined;
313313
const msgValue: IbcTransferProps = {
314314
...firstProps,
315315
gasSpendingKey: firstProps.gasSpendingKey,

0 commit comments

Comments
 (0)