Skip to content

Commit

Permalink
prax: add non-native-fee-warning (#242)
Browse files Browse the repository at this point in the history
* add privacy warning to approval dialogue

* move warning to top

* feedback: remove useEffect in favor of helper function

* simplify
  • Loading branch information
TalDerei authored Nov 25, 2024
1 parent 0841002 commit a79ce04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion apps/extension/src/routes/popup/approval/transaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { Jsonified } from '@penumbra-zone/types/jsonified';
import { TransactionViewTab } from './types';
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { viewClient } from '../../../../clients';
import { TransactionView } from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';

const getMetadata: MetadataFetchFn = async ({ assetId }) => {
const feeAssetId = assetId ? assetId : new ChainRegistryClient().bundled.globals().stakingAssetId;
Expand All @@ -19,6 +20,16 @@ const getMetadata: MetadataFetchFn = async ({ assetId }) => {
return denomMetadata;
};

const hasAltGasFee = (txv?: TransactionView): boolean => {
const { stakingAssetId } = new ChainRegistryClient().bundled.globals();
let feeAssetId = txv?.bodyView?.transactionParameters?.fee?.assetId;
if (feeAssetId === undefined) {
feeAssetId = stakingAssetId;
}

return feeAssetId.equals(stakingAssetId);
};

export const TransactionApproval = () => {
const { authorizeRequest: authReqString, setChoice, sendResponse } = useStore(txApprovalSelector);

Expand Down Expand Up @@ -53,6 +64,14 @@ export const TransactionApproval = () => {
</h1>
</div>
<div className='grow overflow-auto p-4'>
{selectedTransactionViewName === TransactionViewTab.SENDER &&
!hasAltGasFee(selectedTransactionView) && (
<div className='mb-4 rounded border border-yellow-500 p-2 text-sm text-yellow-500'>
<span className='block text-center font-bold'>⚠ Privacy Warning:</span>
Transaction uses a non-native fee token. To reduce gas costs and protect your privacy,
maintain an UM balance for fees.
</div>
)}
<ViewTabs
defaultValue={selectedTransactionViewName}
onValueChange={setSelectedTransactionViewName}
Expand All @@ -61,7 +80,7 @@ export const TransactionApproval = () => {
<TransactionViewComponent txv={selectedTransactionView} metadataFetcher={getMetadata} />

{selectedTransactionViewName === TransactionViewTab.SENDER && (
<div className='mt-4'>
<div className='mt-2'>
<JsonViewer jsonObj={authorizeRequest.toJson() as Jsonified<AuthorizeRequest>} />
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/ui/json-viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const customTheme: NamedColorspace = {

export const JsonViewer = ({ jsonObj }: { jsonObj: JsonObject | JsonValue[] }) => {
return (
<div className='mt-5 rounded bg-black p-5'>
<div className='mt-0 rounded bg-black p-5'>
<TextaJsonViewer
value={jsonObj}
style={{ fontFamily: 'Iosevka Term' }}
Expand Down

0 comments on commit a79ce04

Please sign in to comment.