Skip to content

Commit

Permalink
Add sighash none warning (#152)
Browse files Browse the repository at this point in the history
* Add sighash none warning

* Fix spacing

---------

Co-authored-by: Den <36603049+dhriaznov@users.noreply.github.com>
  • Loading branch information
victorkirov and dhriaznov committed Mar 25, 2024
1 parent 5759028 commit 59ae427
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/app/components/confirmBtcTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ReviewTransactionText = styled(StyledP)`
margin-bottom: ${(props) => props.theme.space.l};
`;

const BroadcastCallout = styled(Callout)`
const SpacedCallout = styled(Callout)`
margin-bottom: ${(props) => props.theme.space.m};
`;

Expand Down Expand Up @@ -69,6 +69,7 @@ type Props = {
) => Promise<number | undefined>;
onFeeRateSet?: (feeRate: number) => void;
feeRate?: number;
hasSigHashNone?: boolean;
};

function ConfirmBtcTransaction({
Expand All @@ -93,6 +94,7 @@ function ConfirmBtcTransaction({
getFeeForFeeRate,
onFeeRateSet,
feeRate,
hasSigHashNone = false,
}: Props) {
const [isModalVisible, setIsModalVisible] = useState(false);
const [currentStepIndex, setCurrentStepIndex] = useState(0);
Expand Down Expand Up @@ -171,7 +173,14 @@ function ConfirmBtcTransaction({
<ReviewTransactionText typography="headline_s">
{t('REVIEW_TRANSACTION')}
</ReviewTransactionText>
{!isBroadcast && <BroadcastCallout bodyText={t('PSBT_NO_BROADCAST_DISCLAIMER')} />}
{hasSigHashNone && (
<SpacedCallout
variant="danger"
titleText={t('PSBT_SIG_HASH_NONE_DISCLAIMER_TITLE')}
bodyText={t('PSBT_SIG_HASH_NONE_DISCLAIMER')}
/>
)}
{!isBroadcast && <SpacedCallout bodyText={t('PSBT_NO_BROADCAST_DISCLAIMER')} />}
<TransactionSummary
token={token}
amountToSend={amountToSend}
Expand Down
12 changes: 9 additions & 3 deletions src/app/screens/signPsbtRequest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ConfirmBitcoinTransaction from '@components/confirmBtcTransaction';
import useSignPsbtTx from '@hooks/useSignPsbtTx';
import useTransactionContext from '@hooks/useTransactionContext';
import useWalletSelector from '@hooks/useWalletSelector';
import { btcTransaction, Transport } from '@secretkeylabs/xverse-core';
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -17,6 +16,7 @@ function SignPsbtRequest() {
const [inputs, setInputs] = useState<btcTransaction.EnhancedInput[]>([]);
const [outputs, setOutputs] = useState<btcTransaction.EnhancedOutput[]>([]);
const [feeOutput, setFeeOutput] = useState<btcTransaction.TransactionFeeOutput | undefined>();
const [hasSigHashNone, setHasSigHashNone] = useState(false);

const { payload, confirmSignPsbt, cancelSignPsbt } = useSignPsbtTx();
const txnContext = useTransactionContext();
Expand All @@ -30,17 +30,22 @@ function SignPsbtRequest() {

useSignPsbtValidationGate({ payload, parsedPsbt });

const { btcAddress, ordinalsAddress } = useWalletSelector();
useEffect(() => {
if (!parsedPsbt) return;

parsedPsbt
.getSummary()
.then((summary) => {
const { feeOutput: psbtFeeOutput, inputs: psbtInputs, outputs: psbtOutputs } = summary;
const {
feeOutput: psbtFeeOutput,
inputs: psbtInputs,
outputs: psbtOutputs,
hasSigHashNone: psbtHasSigHashNone,
} = summary;
setFeeOutput(psbtFeeOutput);
setInputs(psbtInputs);
setOutputs(psbtOutputs);
setHasSigHashNone(psbtHasSigHashNone);
setIsLoading(false);
})
.catch((error) => {
Expand Down Expand Up @@ -112,6 +117,7 @@ function SignPsbtRequest() {
isLoading={isLoading}
isSubmitting={isSigning}
isBroadcast={payload.broadcast}
hasSigHashNone={hasSigHashNone}
confirmText={t('CONFIRM')}
cancelText={t('CANCEL')}
onCancel={onCancel}
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@
"ADDRESS_MISMATCH": "There’s a mismatch between your signing address and the address you’re logged with.",
"PSBT_NO_BROADCAST_DISCLAIMER": "This transaction will not be broadcasted from your wallet. It may be broadcasted later by a third party.",
"PSBTS_NO_BROADCAST_DISCLAIMER": "These transactions will not be broadcasted from your wallet. They may be broadcasted later by a third party.",
"PSBT_SIG_HASH_NONE_DISCLAIMER_TITLE": "Transaction uses SIGHASH_NONE",
"PSBT_SIG_HASH_NONE_DISCLAIMER": "Signing this transaction gives the requester full authority over your funds; they may alter fund destinations. Use with understanding of potential fund loss.",
"PSBT_CANT_PARSE_ERROR_TITLE": "Transaction Error",
"PSBT_CANT_PARSE_ERROR_DESCRIPTION": "The requested transaction is invalid and cannot be processed. Please contact the developer of the requesting app for support.",
"PSBT_INDEX_CANT_PARSE_ERROR_DESCRIPTION": "The requested transaction at {{index}} index is invalid and cannot be processed. Please contact the developer of the requesting app for support.",
Expand Down

0 comments on commit 59ae427

Please sign in to comment.