From a0399a709cbefb9d0b730bc2e35f7c0a00371c3d Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 9 Mar 2026 13:29:54 -0300 Subject: [PATCH 1/2] feat: show network fee for send tx, create token and create nano dialogs --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/components/NetworkFee.tsx | 25 +++++++++++++ packages/snap/src/components/index.ts | 1 + packages/snap/src/dialogs/createNano.tsx | 3 +- packages/snap/src/dialogs/createToken.tsx | 36 ++++++++++++++++--- packages/snap/src/dialogs/sendTransaction.tsx | 5 +-- 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 packages/snap/src/components/NetworkFee.tsx diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index b88d22b5..451cf6a6 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -3,7 +3,7 @@ "description": "Hathor Network Snap integration", "proposedName": "Hathor Wallet", "source": { - "shasum": "GSxSmcmiD0HXf+qm3n/2QBYBgd+lt/2sxRwJxNoNVlc=", + "shasum": "mW1+L7TrK4SBxVb1JlZ7YkCbUf3l2MIWQVELgALMspE=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/components/NetworkFee.tsx b/packages/snap/src/components/NetworkFee.tsx new file mode 100644 index 00000000..2b3cfad2 --- /dev/null +++ b/packages/snap/src/components/NetworkFee.tsx @@ -0,0 +1,25 @@ +/** + * Copyright (c) Hathor Labs and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { Bold, Box, Divider, Text } from '@metamask/snaps-sdk/jsx'; +import { constants as libConstants, numberUtils } from '@hathor/wallet-lib'; + +export const formatHtrAmount = (amount?: bigint): string => { + if (amount === undefined || amount === 0n) { + return '-'; + } + return `${numberUtils.prettyValue(amount)} ${libConstants.DEFAULT_NATIVE_TOKEN_CONFIG.symbol}`; +} + +export const NetworkFee = ({ networkFee, showDivider = false }: { networkFee?: bigint; showDivider?: boolean }) => { + return ( + + {showDivider ? : null} + Network fee: {formatHtrAmount(networkFee)} + + ); +} diff --git a/packages/snap/src/components/index.ts b/packages/snap/src/components/index.ts index 1f126a27..64f60a51 100644 --- a/packages/snap/src/components/index.ts +++ b/packages/snap/src/components/index.ts @@ -6,3 +6,4 @@ */ export { PushTxWarning } from './PushTxWarning'; +export { NetworkFee, formatHtrAmount } from './NetworkFee'; diff --git a/packages/snap/src/dialogs/createNano.tsx b/packages/snap/src/dialogs/createNano.tsx index 3aed36a1..82788302 100644 --- a/packages/snap/src/dialogs/createNano.tsx +++ b/packages/snap/src/dialogs/createNano.tsx @@ -8,7 +8,7 @@ import { REQUEST_METHODS, DIALOG_TYPES } from '../constants'; import { Bold, Box, Card, Container, Copyable, Heading, Icon, Section, Text, Tooltip } from '@metamask/snaps-sdk/jsx'; import { constants as libConstants, bigIntUtils, dateUtils, NanoContractActionType, numberUtils } from '@hathor/wallet-lib'; -import { PushTxWarning } from '../components'; +import { NetworkFee, PushTxWarning } from '../components'; const renderOptionalContractDetail = (param, title) => { if (!param) return null; @@ -187,6 +187,7 @@ export const createNanoPage = async (data, params, origin) => ( {renderArguments(data.parsedArgs)} {renderActions(params.actions, data.tokenDetails)} + diff --git a/packages/snap/src/dialogs/createToken.tsx b/packages/snap/src/dialogs/createToken.tsx index 716c722c..c322badb 100644 --- a/packages/snap/src/dialogs/createToken.tsx +++ b/packages/snap/src/dialogs/createToken.tsx @@ -8,6 +8,7 @@ import { REQUEST_METHODS, DIALOG_TYPES } from '../constants'; import { Box, Card, Container, Divider, Heading, Section, Text } from '@metamask/snaps-sdk/jsx'; import { numberUtils } from '@hathor/wallet-lib'; +import { formatHtrAmount } from '../components'; const renderConditionalCard = (title, value, parsedValue = null) => { if (value == null) { @@ -21,8 +22,29 @@ const boolToString = (bool) => { return bool ? 'true' : 'false'; } -export const createTokenPage = async (data, params, origin) => ( - await snap.request({ +/** + * Get the fee model label based on token type + */ +const getFeeModelLabel = (tokenType?: 'deposit' | 'fee'): string => { + if (tokenType === 'deposit') { + return 'Deposit Token'; + } + if (tokenType === 'fee') { + return 'Fee Token'; + } + return 'Native Token'; +} + +export const createTokenPage = async (data, params, origin) => { + const tokenType = params.token_type as 'deposit' | 'fee' | undefined; + const amount = BigInt(params.amount); + const feeModelLabel = getFeeModelLabel(tokenType); + + // Use pre-calculated values from the RPC handler (passed via data) + const networkFee = data.networkFee; + const depositAmount = data.depositAmount; + + return await snap.request({ method: REQUEST_METHODS.DIALOG, params: { type: DIALOG_TYPES.CONFIRMATION, @@ -36,7 +58,11 @@ export const createTokenPage = async (data, params, origin) => (
- + + + + + {renderConditionalCard('Address', params.address)} {renderConditionalCard('Change address', params.change_address)} {renderConditionalCard('Create mint authority', params.create_mint, boolToString(params.create_mint))} @@ -51,5 +77,5 @@ export const createTokenPage = async (data, params, origin) => ( ), }, - }) -) + }); +} diff --git a/packages/snap/src/dialogs/sendTransaction.tsx b/packages/snap/src/dialogs/sendTransaction.tsx index 948bc085..5eada513 100644 --- a/packages/snap/src/dialogs/sendTransaction.tsx +++ b/packages/snap/src/dialogs/sendTransaction.tsx @@ -8,7 +8,7 @@ import { REQUEST_METHODS, DIALOG_TYPES } from '../constants'; import { Bold, Box, Container, Divider, Heading, Icon, Section, Text, Tooltip } from '@metamask/snaps-sdk/jsx'; import { constants as libConstants, numberUtils, helpersUtils } from '@hathor/wallet-lib'; -import { PushTxWarning } from '../components'; +import { NetworkFee, PushTxWarning } from '../components'; const renderInputs = (inputs) => { if (!inputs) { @@ -122,6 +122,7 @@ export const sendTransactionPage = async (data, params, origin) => ( {renderOutputs(params.outputs, data.tokenDetails)} {renderChangeAddress(params.changeAddress)} +
@@ -129,4 +130,4 @@ export const sendTransactionPage = async (data, params, origin) => ( ), }, }) -) \ No newline at end of file +) From 652b0600229b0fbd75ecd640d88fd924acf10e91 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 9 Mar 2026 18:37:15 -0300 Subject: [PATCH 2/2] feat: use correct network fee and deposit fee. Adjust create token dialog for the new token version parameter --- packages/snap/package.json | 2 +- packages/snap/snap.manifest.json | 2 +- packages/snap/src/dialogs/createNano.tsx | 2 +- packages/snap/src/dialogs/createToken.tsx | 23 +++++++++++------------ yarn.lock | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/snap/package.json b/packages/snap/package.json index cf720da0..1ce605df 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@hathor/hathor-rpc-handler": "workspace:*", - "@hathor/wallet-lib": "2.14.0", + "@hathor/wallet-lib": "2.16.0", "@metamask/snaps-sdk": "9.2.0", "node-stdlib-browser": "1.3.1" }, diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 451cf6a6..a1088043 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -3,7 +3,7 @@ "description": "Hathor Network Snap integration", "proposedName": "Hathor Wallet", "source": { - "shasum": "mW1+L7TrK4SBxVb1JlZ7YkCbUf3l2MIWQVELgALMspE=", + "shasum": "zuKLrJeNvUp9ImMD6+3cJ8ShO6sN9CSWjwFrwwitSFc=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/dialogs/createNano.tsx b/packages/snap/src/dialogs/createNano.tsx index 82788302..86a71b10 100644 --- a/packages/snap/src/dialogs/createNano.tsx +++ b/packages/snap/src/dialogs/createNano.tsx @@ -187,7 +187,7 @@ export const createNanoPage = async (data, params, origin) => ( {renderArguments(data.parsedArgs)} {renderActions(params.actions, data.tokenDetails)} - + diff --git a/packages/snap/src/dialogs/createToken.tsx b/packages/snap/src/dialogs/createToken.tsx index c322badb..d2808b5f 100644 --- a/packages/snap/src/dialogs/createToken.tsx +++ b/packages/snap/src/dialogs/createToken.tsx @@ -23,26 +23,25 @@ const boolToString = (bool) => { } /** - * Get the fee model label based on token type + * Get the fee model label based on token version */ -const getFeeModelLabel = (tokenType?: 'deposit' | 'fee'): string => { - if (tokenType === 'deposit') { - return 'Deposit Token'; +const getFeeModelLabel = (version?: 'deposit' | 'fee'): string => { + switch (version) { + case 'fee': + return 'Fee Token'; + case 'deposit': + default: + return 'Deposit Token'; } - if (tokenType === 'fee') { - return 'Fee Token'; - } - return 'Native Token'; } export const createTokenPage = async (data, params, origin) => { - const tokenType = params.token_type as 'deposit' | 'fee' | undefined; const amount = BigInt(params.amount); - const feeModelLabel = getFeeModelLabel(tokenType); + const feeModelLabel = getFeeModelLabel(params.version); // Use pre-calculated values from the RPC handler (passed via data) - const networkFee = data.networkFee; - const depositAmount = data.depositAmount; + const networkFee = data.fee; + const depositAmount = data.deposit; return await snap.request({ method: REQUEST_METHODS.DIALOG, diff --git a/yarn.lock b/yarn.lock index 60f4e075..5dc1bb4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2507,7 +2507,7 @@ __metadata: resolution: "@hathor/snap@workspace:packages/snap" dependencies: "@hathor/hathor-rpc-handler": "workspace:*" - "@hathor/wallet-lib": "npm:2.14.0" + "@hathor/wallet-lib": "npm:2.16.0" "@jest/globals": "npm:29.7.0" "@metamask/auto-changelog": "npm:3.4.4" "@metamask/eslint-config": "npm:12.2.0"