Skip to content

Commit a7b8fb0

Browse files
authored
fix: show drep key in sign data popup (#1925)
1 parent 64e6814 commit a7b8fb0

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

apps/browser-extension-wallet/src/features/dapp/components/ConfirmData.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { useAnalyticsContext } from '@providers';
2121
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
2222
import { signingCoordinator } from '@lib/wallet-api-ui';
2323
import { senderToDappInfo } from '@src/utils/senderToDappInfo';
24-
import { useOnUnload } from './confirm-transaction/hooks';
24+
import { useGetOwnPubDRepKeyHash, useOnUnload } from './confirm-transaction/hooks';
2525
import { parseError } from '@src/utils/parse-error';
2626

2727
const INDENT_SPACING = 2;
@@ -39,6 +39,10 @@ const hasJsonStructure = (str: string): boolean => {
3939
}
4040
};
4141

42+
const isPaymentAddress = (
43+
signWith: Wallet.Cardano.PaymentAddress | Wallet.Cardano.RewardAccount
44+
): signWith is Wallet.Cardano.PaymentAddress => signWith.startsWith('addr');
45+
4246
export const DappConfirmData = (): React.ReactElement => {
4347
const {
4448
utils: { setNextView },
@@ -53,6 +57,8 @@ export const DappConfirmData = (): React.ReactElement => {
5357
const [dappInfo, setDappInfo] = useState<Wallet.DappInfo>();
5458
const analytics = useAnalyticsContext();
5559

60+
const { ownPubDRepKeyHash, loading: isLoadingOwnPubDRepKeyHash } = useGetOwnPubDRepKeyHash();
61+
5662
const [formattedData, setFormattedData] = useState<{
5763
address: string;
5864
dataToSign: string;
@@ -99,15 +105,31 @@ export const DappConfirmData = (): React.ReactElement => {
99105
useEffect(() => {
100106
if (!req) return;
101107
const dataFromHex = fromHex(req.signContext.payload);
102-
const txDataAddress = req.signContext.signWith;
108+
109+
let txDataAddress = req.signContext.signWith;
110+
111+
if (ownPubDRepKeyHash && isPaymentAddress(txDataAddress)) {
112+
const drepAddr = Wallet.Cardano.Address.fromString(txDataAddress);
113+
114+
if (
115+
drepAddr?.getType() === Wallet.Cardano.AddressType.EnterpriseKey &&
116+
drepAddr?.getProps().paymentPart?.hash === ownPubDRepKeyHash
117+
) {
118+
txDataAddress = Wallet.Cardano.DRepID.cip129FromCredential({
119+
hash: drepAddr?.getProps().paymentPart?.hash,
120+
type: Wallet.Cardano.CredentialType.KeyHash
121+
});
122+
}
123+
}
124+
103125
const jsonStructureOrHexString = {
104126
address: txDataAddress,
105127
dataToSign: hasJsonStructure(dataFromHex)
106128
? JSON.stringify(JSON.parse(dataFromHex), undefined, INDENT_SPACING)
107129
: dataFromHex
108130
};
109131
setFormattedData(jsonStructureOrHexString);
110-
}, [req]);
132+
}, [req, ownPubDRepKeyHash]);
111133

112134
const signWithHardwareWallet = useCallback(async () => {
113135
setIsConfirmingTx(true);
@@ -138,7 +160,7 @@ export const DappConfirmData = (): React.ReactElement => {
138160
<Layout pageClassname={styles.spaceBetween} title={t(sectionTitle[DAPP_VIEWS.CONFIRM_DATA])}>
139161
<div className={styles.container}>
140162
<DappInfo {...dappInfo} className={styles.dappInfo} />
141-
{formattedData ? (
163+
{formattedData && !isLoadingOwnPubDRepKeyHash ? (
142164
<>
143165
<div className={styles.contentSection}>
144166
<p className={styles.heading} data-testid="dapp-transaction-recipient-address-title">

0 commit comments

Comments
 (0)