-
Notifications
You must be signed in to change notification settings - Fork 11
Display better fee breakdown for soroban transactions #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1b5ea92
dbba845
fe46ee5
699e4b3
99e918f
5205d82
b964af5
cc32f03
c874021
773b7f7
5d672bf
acb1b73
4d6a47c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import BigNumber from "bignumber.js"; | ||
| import Icon from "components/sds/Icon"; | ||
| import { Text } from "components/sds/Typography"; | ||
| import { NATIVE_TOKEN_CODE } from "config/constants"; | ||
| import { useTransactionBuilderStore } from "ducks/transactionBuilder"; | ||
| import { useTransactionSettingsStore } from "ducks/transactionSettings"; | ||
| import { formatTokenForDisplay } from "helpers/formatAmount"; | ||
| import useAppTranslation from "hooks/useAppTranslation"; | ||
| import useColors from "hooks/useColors"; | ||
| import React from "react"; | ||
| import { ActivityIndicator, TouchableOpacity, View } from "react-native"; | ||
|
|
||
| type FeeBreakdownBottomSheetProps = { | ||
| onClose: () => void; | ||
| /** | ||
| * Whether the current transaction is Soroban-type (C-token, C-address, or | ||
| * collectible), derived from the sending context rather than the builder | ||
| * store. Controls row visibility and description text independently of | ||
| * whether simulation has completed yet. | ||
| */ | ||
| isSorobanContext: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * FeeBreakdownBottomSheet Component | ||
| * | ||
| * The mobile equivalent of the extension's FeesPane. | ||
| * For Soroban transactions: shows Inclusion Fee + Resource Fee + Total Fee rows. | ||
| * For classic transactions: shows only the Total Fee row. | ||
| * Shows ActivityIndicator while a build is in progress. | ||
| * Includes a contextual description (different text for Soroban vs classic). | ||
| */ | ||
leofelix077 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const FeeBreakdownBottomSheet: React.FC<FeeBreakdownBottomSheetProps> = ({ | ||
| onClose, | ||
| isSorobanContext, | ||
| }) => { | ||
| const { t } = useAppTranslation(); | ||
| const { themeColors } = useColors(); | ||
| const { | ||
| isSoroban, | ||
| sorobanResourceFeeXlm, | ||
| sorobanInclusionFeeXlm, | ||
| isBuilding, | ||
| } = useTransactionBuilderStore(); | ||
| const { transactionFee } = useTransactionSettingsStore(); | ||
|
|
||
| const totalFeeXlm = | ||
| isSoroban && sorobanInclusionFeeXlm && sorobanResourceFeeXlm | ||
| ? new BigNumber(sorobanInclusionFeeXlm) | ||
| .plus(sorobanResourceFeeXlm) | ||
| .toString() | ||
| : transactionFee; | ||
|
|
||
| return ( | ||
| <View className="flex-1"> | ||
| {/* Header — lilac icon + close button */} | ||
| <View className="relative flex-row items-center mb-8"> | ||
| <View className="bg-lilac-3 p-2 rounded-[8px]"> | ||
| <Icon.Route color={themeColors.lilac[9]} size={28} /> | ||
| </View> | ||
| <TouchableOpacity onPress={onClose} className="absolute right-0"> | ||
| <Icon.X | ||
| color={themeColors.foreground.secondary} | ||
| size={24} | ||
| circle | ||
| circleBackground={themeColors.background.tertiary} | ||
| /> | ||
| </TouchableOpacity> | ||
| </View> | ||
|
|
||
| {/* Title */} | ||
| <Text xl medium primary textAlign="left"> | ||
| {t("feeBreakdown.title")} | ||
| </Text> | ||
|
|
||
| {/* Fee rows card */} | ||
| <View className="mt-[16px] rounded-[12px] overflow-hidden bg-background-tertiary"> | ||
| {isSoroban && ( | ||
| <View className="flex-row justify-between items-center px-[16px] py-[12px] border-b border-gray-6"> | ||
| <Text md secondary> | ||
| {t("transactionAmountScreen.details.inclusionFee")} | ||
| </Text> | ||
| {isBuilding || !sorobanInclusionFeeXlm ? ( | ||
| <ActivityIndicator | ||
| size="small" | ||
| color={themeColors.text.secondary} | ||
| /> | ||
| ) : ( | ||
| <Text md primary> | ||
| {formatTokenForDisplay( | ||
| sorobanInclusionFeeXlm, | ||
| NATIVE_TOKEN_CODE, | ||
| )} | ||
| </Text> | ||
| )} | ||
| </View> | ||
| )} | ||
| {isSoroban && ( | ||
| <View className="flex-row justify-between items-center px-[16px] py-[12px] border-b border-gray-6"> | ||
| <Text md secondary> | ||
| {t("transactionAmountScreen.details.resourceFee")} | ||
| </Text> | ||
| {isBuilding || !sorobanResourceFeeXlm ? ( | ||
|
Comment on lines
+76
to
+103
|
||
| <ActivityIndicator | ||
| size="small" | ||
| color={themeColors.text.secondary} | ||
| /> | ||
| ) : ( | ||
| <Text md primary> | ||
| {formatTokenForDisplay( | ||
| sorobanResourceFeeXlm, | ||
| NATIVE_TOKEN_CODE, | ||
| )} | ||
| </Text> | ||
| )} | ||
| </View> | ||
| )} | ||
| {/* Total Fee — always shown, accented in lilac */} | ||
| <View className="flex-row justify-between items-center px-[16px] py-[12px]"> | ||
| <Text md medium color={themeColors.lilac[11]}> | ||
| {t("transactionAmountScreen.details.totalFee")} | ||
| </Text> | ||
| {isBuilding ? ( | ||
| <ActivityIndicator | ||
| size="small" | ||
| color={themeColors.text.secondary} | ||
| /> | ||
| ) : ( | ||
| <Text md medium color={themeColors.lilac[11]}> | ||
| {formatTokenForDisplay(totalFeeXlm, NATIVE_TOKEN_CODE)} | ||
| </Text> | ||
| )} | ||
| </View> | ||
| </View> | ||
|
|
||
| {/* Contextual description */} | ||
| <View className="mt-[24px] pr-8"> | ||
| <Text md regular secondary textAlign="left"> | ||
| {t( | ||
| isSorobanContext | ||
| ? "feeBreakdown.descriptionSoroban" | ||
| : "feeBreakdown.descriptionClassic", | ||
| )} | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default FeeBreakdownBottomSheet; | ||
Uh oh!
There was an error while loading. Please reload this page.