Skip to content

Commit

Permalink
Show cenotaph warning (#219)
Browse files Browse the repository at this point in the history
* Show cenotaph warning

* Move cenotaph warning to transactionSummary
  • Loading branch information
victorkirov committed Apr 23, 2024
1 parent 1250117 commit 74fe75e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/app/components/confirmBtcTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Props = {
outputs: btcTransaction.EnhancedOutput[];
feeOutput?: btcTransaction.TransactionFeeOutput;
runeSummary?: RuneSummary;
showCenotaphCallout: boolean;
isLoading: boolean;
isSubmitting: boolean;
isBroadcast?: boolean;
Expand Down Expand Up @@ -76,6 +77,7 @@ function ConfirmBtcTransaction({
outputs,
feeOutput,
runeSummary,
showCenotaphCallout,
isLoading,
isSubmitting,
isBroadcast,
Expand Down Expand Up @@ -205,6 +207,7 @@ function ConfirmBtcTransaction({
outputs={outputs}
feeOutput={feeOutput}
isPartialTransaction={isPartialTransaction}
showCenotaphCallout={showCenotaphCallout}
getFeeForFeeRate={getFeeForFeeRate}
onFeeRateSet={onFeeRateSet}
feeRate={feeRate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const WarningCallout = styled(Callout)`

type Props = {
isPartialTransaction: boolean;
showCenotaphCallout: boolean;
inputs: btcTransaction.EnhancedInput[];
outputs: btcTransaction.EnhancedOutput[];
feeOutput?: btcTransaction.TransactionFeeOutput;
Expand All @@ -49,6 +50,7 @@ type Props = {

function TransactionSummary({
isPartialTransaction,
showCenotaphCallout,
inputs,
outputs,
feeOutput,
Expand Down Expand Up @@ -127,6 +129,9 @@ function TransactionSummary({
{isUnConfirmedInput && (
<WarningCallout bodyText={t('UNCONFIRMED_UTXO_WARNING')} variant="warning" />
)}
{showCenotaphCallout && (
<WarningCallout variant="danger" bodyText={t('RUNES_CENOTAPH_WARNING')} />
)}
{runeSummary?.mint && !runeSummary?.mint?.runeIsOpen && (
<WarningCallout bodyText={t('RUNE_TERM_ENDED')} variant="danger" />
)}
Expand Down
2 changes: 1 addition & 1 deletion src/app/screens/confirmBtcTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function ConfirmBtcTransaction() {
description={t('BTC_TRANSFER_DANGER_ALERT_DESC')}
buttonText={t('BACK')}
onClose={onClosePress}
secondButtonText={t('CONITNUE')}
secondButtonText={t('CONTINUE')}
onButtonClick={onClosePress}
onSecondButtonClick={onContinueButtonClick}
isWarningAlert
Expand Down
2 changes: 1 addition & 1 deletion src/app/screens/confirmInscriptionRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function ConfirmInscriptionRequest() {
description={t('CONFIRM_TRANSACTION.BTC_TRANSFER_DANGER_ALERT_DESC')}
buttonText={t('CONFIRM_TRANSACTION.BACK')}
onClose={onClosePress}
secondButtonText={t('CONITNUE')}
secondButtonText={t('CONTINUE')}
onButtonClick={onClosePress}
onSecondButtonClick={onContinueButtonClick}
isWarningAlert
Expand Down
1 change: 1 addition & 0 deletions src/app/screens/restoreFunds/recoverRunes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function RecoverRunes() {
inputs={summary?.inputs ?? []}
outputs={summary?.outputs ?? []}
feeOutput={summary?.feeOutput}
showCenotaphCallout={!!summary?.runeOp?.Cenotaph?.flaws}
runeSummary={runeSummary}
isLoading={isLoading}
isSubmitting={isBroadcasting}
Expand Down
1 change: 1 addition & 0 deletions src/app/screens/sendBtc/stepDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function StepDisplay({
inputs={summary.inputs}
outputs={summary.outputs}
feeOutput={summary.feeOutput}
showCenotaphCallout={!!summary?.runeOp?.Cenotaph?.flaws}
isLoading={false}
confirmText={t('COMMON.CONFIRM')}
cancelText={t('COMMON.CANCEL')}
Expand Down
1 change: 1 addition & 0 deletions src/app/screens/sendRune/stepDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function StepDisplay({
inputs={summary.inputs}
outputs={summary.outputs}
feeOutput={summary.feeOutput}
showCenotaphCallout={!!summary?.runeOp?.Cenotaph?.flaws}
runeSummary={runeSummary}
isLoading={false}
confirmText={t('COMMON.CONFIRM')}
Expand Down
11 changes: 5 additions & 6 deletions src/app/screens/signBatchPsbtRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,8 @@ interface TxResponse {
psbtBase64: string;
}

type PsbtSummary = {
inputs: btcTransaction.EnhancedInput[];
outputs: btcTransaction.EnhancedOutput[];
feeOutput?: btcTransaction.TransactionFeeOutput | undefined;
hasSigHashNone: boolean;
};
// TODO: export this from core
type PsbtSummary = Awaited<ReturnType<btcTransaction.EnhancedPsbt['getSummary']>>;

function SignBatchPsbtRequest() {
const { btcAddress, ordinalsAddress, selectedAccount, network } = useWalletSelector();
Expand Down Expand Up @@ -434,6 +430,9 @@ function SignBatchPsbtRequest() {
feeOutput={parsedPsbts[currentPsbtIndex].summary.feeOutput}
runeSummary={parsedPsbts[currentPsbtIndex].runeSummary}
isPartialTransaction={!parsedPsbts[currentPsbtIndex].summary.feeOutput}
showCenotaphCallout={
!!parsedPsbts[currentPsbtIndex].summary.runeOp?.Cenotaph?.flaws
}
/>
)}
</CustomizedModalContainer>
Expand Down
33 changes: 12 additions & 21 deletions src/app/screens/signPsbtRequest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { makeRPCError, sendRpcResponse } from '@common/utils/rpc/helpers';
import ConfirmBitcoinTransaction from '@components/confirmBtcTransaction';
import RequestError from '@components/requests/requestError';
import useBtcClient from '@hooks/useBtcClient';
import useHasFeature from '@hooks/useHasFeature';
import useTransactionContext from '@hooks/useTransactionContext';
import useWalletSelector from '@hooks/useWalletSelector';
Expand All @@ -18,6 +17,9 @@ import { RpcErrorCode } from 'sats-connect';
import useSignPsbt from './useSignPsbt';
import useSignPsbtValidationGate from './useSignPsbtValidationGate';

// TODO: export this from core
type PSBTSummary = Awaited<ReturnType<btcTransaction.EnhancedPsbt['getSummary']>>;

function SignPsbtRequest() {
const navigate = useNavigate();

Expand All @@ -26,10 +28,7 @@ function SignPsbtRequest() {

const [isLoading, setIsLoading] = useState(true);
const [isSigning, setIsSigning] = useState(false);
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 [summary, setSummary] = useState<PSBTSummary | undefined>();
const [runeSummary, setRuneSummary] = useState<RuneSummary | undefined>(undefined);
const hasRunesSupport = useHasFeature('RUNES_SUPPORT');

Expand All @@ -49,19 +48,10 @@ function SignPsbtRequest() {

parsedPsbt
.getSummary()
.then(async (summary) => {
const {
feeOutput: psbtFeeOutput,
inputs: psbtInputs,
outputs: psbtOutputs,
hasSigHashNone: psbtHasSigHashNone,
} = summary;
setFeeOutput(psbtFeeOutput);
setInputs(psbtInputs);
setOutputs(psbtOutputs);
setHasSigHashNone(psbtHasSigHashNone);
.then(async (txSummary) => {
setSummary(txSummary);
if (hasRunesSupport) {
setRuneSummary(await parseSummaryForRunes(txnContext, summary, network.type));
setRuneSummary(await parseSummaryForRunes(txnContext, txSummary, network.type));
}
setIsLoading(false);
})
Expand Down Expand Up @@ -138,14 +128,15 @@ function SignPsbtRequest() {
/>
) : (
<ConfirmBitcoinTransaction
inputs={inputs}
outputs={outputs}
feeOutput={feeOutput}
inputs={summary?.inputs ?? []}
outputs={summary?.outputs ?? []}
feeOutput={summary?.feeOutput}
showCenotaphCallout={!!summary?.runeOp?.Cenotaph?.flaws}
runeSummary={runeSummary}
isLoading={isLoading}
isSubmitting={isSigning}
isBroadcast={payload.broadcast}
hasSigHashNone={hasSigHashNone}
hasSigHashNone={summary?.hasSigHashNone}
confirmText={t('CONFIRM')}
cancelText={t('CANCEL')}
onCancel={onCancel}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@
"ORDINAL_DETECTED_ACTION": "Move to my ordinals address",
"BTC_TRANSFER_DANGER_ALERT_TITLE": "Danger",
"BTC_TRANSFER_DANGER_ALERT_DESC": "You are about to make a Bitcoin transfer which contains an ordinal inscription. Once transferred out of the wallet, you will not be able to recover them.",
"CONITNUE": "Continue",
"CONTINUE": "Continue",
"BACK": "Back",
"HIGH_FEE_WARNING_TEXT": "The estimated transaction fee for this transaction is very high.",
"UNCONFIRMED_BALANCE_WARNING": "You are spending unconfirmed outputs in this transaction. This may lower the effective fee rate causing delays in transaction confirmation",
"RUNES_CENOTAPH_WARNING": "This transaction will burn all input Runes. Make sure you trust the requesting app.",
"LEDGER": {
"CONNECT": {
"TITLE": "Connect your hardware wallet",
Expand Down

0 comments on commit 74fe75e

Please sign in to comment.