Skip to content

Commit 79a6270

Browse files
committed
feat: enable gas source switch only for unshielding and shielded
transfers
1 parent 23551bc commit 79a6270

File tree

8 files changed

+64
-50
lines changed

8 files changed

+64
-50
lines changed

apps/extension/src/Approvals/ConfirmSignLedgerTx.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
188188
setStepTwoDescription("Preparing transaction...");
189189

190190
try {
191-
// TODO: we have to check if the signer is disposable or not
192-
193191
const accountDetails = await requester.sendMessage(
194192
Ports.Background,
195193
new QueryAccountDetailsMsg(signer)
@@ -235,6 +233,11 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
235233
.type
236234
)
237235
);
236+
const disposableSigner = txDetails.reduce((acc, curr) => {
237+
console.log("www", curr.wrapperFeePayer, accountDetails.address);
238+
return acc || curr.wrapperFeePayer !== accountDetails.address;
239+
}, false);
240+
238241
// For now we work under the assumption that we can't batch transfers from masp with other tx types
239242
const fromMasp =
240243
transferTypes.includes("Shielded") ||
@@ -257,7 +260,9 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
257260
});
258261
// Adds new signature to the collection
259262
await handleMaspSignTx(ledger, tx, zip32Path, maspSignatures);
260-
} else {
263+
}
264+
265+
if (!disposableSigner) {
261266
const bip44Path = makeBip44Path(chains.namada.bip44.coinType, path);
262267
// Adds new signature to the collection
263268
await handleSignTx(ledger, tx, bip44Path, signatures);
@@ -273,10 +278,18 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
273278
Ports.Background,
274279
new ReplaceMaspSignaturesMsg(msgId, maspSignatures)
275280
);
276-
await requester.sendMessage(
277-
Ports.Background,
278-
new SubmitApprovedSignTxMsg(msgId, signer)
279-
);
281+
282+
if (disposableSigner) {
283+
await requester.sendMessage(
284+
Ports.Background,
285+
new SubmitApprovedSignTxMsg(msgId, signer)
286+
);
287+
} else {
288+
await requester.sendMessage(
289+
Ports.Background,
290+
new SubmitApprovedSignLedgerTxMsg(msgId, signatures)
291+
);
292+
}
280293
} else {
281294
await requester.sendMessage(
282295
Ports.Background,

apps/namadillo/src/App/Common/GasFeeModal.tsx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Modal,
66
Stack,
77
StyledSelectBox,
8+
Text,
89
ToggleButton,
910
} from "@namada/components";
1011
import { transparentBalanceAtom } from "atoms/accounts";
@@ -97,7 +98,6 @@ const useBuildGasOption = ({
9798
export const GasFeeModal = ({
9899
feeProps,
99100
onClose,
100-
isShielded = false,
101101
}: {
102102
feeProps: TransactionFeeProps;
103103
onClose: () => void;
@@ -108,6 +108,7 @@ export const GasFeeModal = ({
108108
gasEstimate,
109109
gasPriceTable,
110110
gasSource,
111+
gasSourceSwitch,
111112
onChangeGasLimit,
112113
onChangeGasToken,
113114
onChangeGasSource,
@@ -122,7 +123,7 @@ export const GasFeeModal = ({
122123
const findUserBalanceByTokenAddress = (tokenAddres: string): BigNumber => {
123124
// TODO: we need to refactor userShieldedBalances to return Balance[] type instead
124125
const balances =
125-
isShielded ?
126+
gasSource === "shielded" ?
126127
shieldedAmount.data?.map((balance) => ({
127128
minDenomAmount: balance.minDenomAmount,
128129
tokenAddress: balance.address,
@@ -211,27 +212,38 @@ export const GasFeeModal = ({
211212
<span className="text-xs text-neutral-500 text-right">Balance</span>
212213
<span className="text-xs text-neutral-500 text-right">Fee</span>
213214
</div>
215+
{gasSourceSwitch && gasSource !== "shielded" && (
216+
<Text className="text-red-600 text-sm">
217+
Warning! Using fees from your transparent account will reveal data.
218+
<br />
219+
To keep your data protected we recommend moving assets to the
220+
<br />
221+
shield pool to pay fees.
222+
</Text>
223+
)}
214224
<Stack
215225
direction="horizontal"
216226
className="justify-between align-middle mt-4 mb-1"
217227
>
218228
<div className="text-sm">Fee Token</div>
219-
<ToggleButton
220-
label={
221-
gasSource === "shielded" ? "Shielded Balance" : (
222-
"Transparent Balance"
223-
)
224-
}
225-
color="white"
226-
activeColor="yellow"
227-
checked={gasSource === "shielded"}
228-
onChange={() =>
229-
onChangeGasSource(
230-
gasSource === "shielded" ? "transparent" : "shielded"
231-
)
232-
}
233-
containerProps={{ className: "gap-3 text-xs" }}
234-
/>
229+
{gasSourceSwitch && (
230+
<ToggleButton
231+
label={
232+
gasSource === "shielded" ? "Shielded Balance" : (
233+
"Transparent Balance"
234+
)
235+
}
236+
color="white"
237+
activeColor="yellow"
238+
checked={gasSource === "shielded"}
239+
onChange={() =>
240+
onChangeGasSource(
241+
gasSource === "shielded" ? "transparent" : "shielded"
242+
)
243+
}
244+
containerProps={{ className: "gap-3 text-xs" }}
245+
/>
246+
)}
235247
</Stack>
236248
<StyledSelectBox
237249
id="fee-token-select"

apps/namadillo/src/App/Common/TransactionFeeButton.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { TransactionFee } from "./TransactionFee";
1111
export const TransactionFeeButton = ({
1212
feeProps,
1313
className,
14-
isShieldedTransfer = false,
1514
}: {
1615
feeProps: TransactionFeeProps;
1716
className?: string;
18-
isShieldedTransfer?: boolean;
1917
}): JSX.Element => {
2018
const [modalOpen, setModalOpen] = useState(false);
2119
const chainAssetsMap = useAtomValue(chainAssetsMapAtom);
@@ -54,11 +52,7 @@ export const TransactionFeeButton = ({
5452
</div>
5553
</div>
5654
{modalOpen && (
57-
<GasFeeModal
58-
feeProps={feeProps}
59-
onClose={() => setModalOpen(false)}
60-
isShielded={isShieldedTransfer}
61-
/>
55+
<GasFeeModal feeProps={feeProps} onClose={() => setModalOpen(false)} />
6256
)}
6357
</>
6458
);

apps/namadillo/src/App/Masp/MaspUnshield.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ export const MaspUnshield: React.FC = () => {
162162
isShieldedAddress: false,
163163
}}
164164
feeProps={feeProps}
165-
isShieldedTx={true}
166165
isSubmitting={isPerformingTransfer || isSuccess}
167166
errorMessage={generalErrorMessage}
168167
onSubmitTransfer={onSubmitTransfer}

apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export const NamadaTransfer: React.FC = () => {
202202
feeProps={feeProps}
203203
currentStatus={currentStatus}
204204
currentStatusExplanation={currentStatusExplanation}
205-
isShieldedTx={isSourceShielded}
206205
isSubmitting={
207206
isPerformingTransfer || isTransferSuccessful || Boolean(completedAt)
208207
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { TokenAmountCard } from "./TokenAmountCard";
1515

1616
type TransferDestinationProps = {
1717
isShieldedAddress?: boolean;
18-
isShieldedTx?: boolean;
1918
onChangeShielded?: (isShielded: boolean) => void;
2019
chain?: Chain;
2120
wallet?: WalletProvider;
@@ -43,7 +42,6 @@ export const TransferDestination = ({
4342
wallet,
4443
walletAddress,
4544
isShieldedAddress,
46-
isShieldedTx = false,
4745
onChangeShielded,
4846
gasDisplayAmount,
4947
gasAsset,
@@ -173,12 +171,7 @@ export const TransferDestination = ({
173171
{!isSubmitting && (
174172
<footer className="flex items-center mt-10">
175173
{changeFeeEnabled ?
176-
feeProps && (
177-
<TransactionFeeButton
178-
feeProps={feeProps}
179-
isShieldedTransfer={isShieldedTx}
180-
/>
181-
)
174+
feeProps && <TransactionFeeButton feeProps={feeProps} />
182175
: gasDisplayAmount &&
183176
gasAsset && (
184177
<TransactionFee

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export type TransferModuleProps = {
9595
currentStatus?: string;
9696
currentStatusExplanation?: string;
9797
completedAt?: Date;
98-
isShieldedTx?: boolean;
9998
buttonTextErrors?: Partial<Record<ValidationResult, string>>;
10099
onComplete?: () => void;
101100
} & (
@@ -135,7 +134,6 @@ export const TransferModule = ({
135134
completedAt,
136135
onComplete,
137136
buttonTextErrors = {},
138-
isShieldedTx = false,
139137
}: TransferModuleProps): JSX.Element => {
140138
const navigate = useNavigate();
141139
const location = useLocation();
@@ -470,7 +468,6 @@ export const TransferModule = ({
470468
destination.isShieldedAddress
471469
)}
472470
isShieldedAddress={destination.isShieldedAddress}
473-
isShieldedTx={isShieldedTx}
474471
onChangeShielded={destination.onChangeShielded}
475472
address={destination.customAddress}
476473
onToggleCustomAddress={

apps/namadillo/src/hooks/useTransactionFee.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type TransactionFeeProps = {
2121
gasEstimate: GasEstimate | undefined;
2222
gasPriceTable: GasPriceTable | undefined;
2323
gasSource: "shielded" | "transparent";
24+
gasSourceSwitch: boolean;
2425
onChangeGasLimit: (value: BigNumber) => void;
2526
onChangeGasToken: (value: string) => void;
2627
onChangeGasSource: (value: "shielded" | "transparent") => void;
@@ -35,9 +36,10 @@ export const useTransactionFee = (
3536
const userTransparentBalances = useAtomValue(transparentBalanceAtom);
3637
const userShieldedBalances = useAtomValue(shieldedBalanceAtom);
3738
const [gasSource, setGasSource] = useState<"shielded" | "transparent">(
38-
"shielded"
39+
isShielded ? "shielded" : "transparent"
3940
);
4041
const isPublicKeyRevealed = useAtomValue(isPublicKeyRevealedAtom);
42+
const isShieldedSource = gasSource === "shielded";
4143

4244
const { data: nativeToken, isLoading: isLoadingNativeToken } = useAtomValue(
4345
nativeTokenAddressAtom
@@ -80,17 +82,17 @@ export const useTransactionFee = (
8082
const availableGasTokenAddress = useMemo(() => {
8183
if (!gasPriceTable) return nativeToken;
8284

83-
if (isShielded && !userShieldedBalances.data) {
85+
if (isShieldedSource && !userShieldedBalances.data) {
8486
return nativeToken;
8587
}
8688

87-
if (!isShielded && !userTransparentBalances.data) {
89+
if (!isShieldedSource && !userTransparentBalances.data) {
8890
return nativeToken;
8991
}
9092

9193
// Separate shielded amount from transparent
9294
const balances =
93-
(isShielded ?
95+
(isShieldedSource ?
9496
// TODO: we need to refactor userShieldedBalances to return Balance[] type instead
9597
userShieldedBalances.data?.map((balance) => ({
9698
minDenomAmount: balance.minDenomAmount,
@@ -128,7 +130,7 @@ export const useTransactionFee = (
128130
userShieldedBalances.data,
129131
gasPriceTable,
130132
gasDollarMap,
131-
isShielded,
133+
isShieldedSource,
132134
]);
133135

134136
const averageGasLimit = gasEstimate && BigNumber(gasEstimate.avg);
@@ -149,12 +151,17 @@ export const useTransactionFee = (
149151
isLoadingGasEstimate ||
150152
isLoadingGasPriceTable;
151153

154+
const gasSourceSwitch =
155+
txKinds.includes("ShieldedTransfer") ||
156+
txKinds.includes("UnshieldingTransfer");
157+
152158
return {
153159
gasConfig,
154160
isLoading,
155161
gasEstimate,
156162
gasPriceTable,
157163
gasSource,
164+
gasSourceSwitch,
158165
onChangeGasLimit: setGasLimitValue,
159166
onChangeGasToken: setGasTokenValue,
160167
onChangeGasSource: setGasSource,

0 commit comments

Comments
 (0)