FIX: Biometric failure would trigger false positive navigation

It wouldnt broadcadt tx though
This commit is contained in:
Marcos Rodriguez Vélez 2024-10-21 01:18:20 -04:00 committed by GitHub
parent 6d1a21c853
commit 15f1d4cff4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,15 +170,31 @@ const Confirm: React.FC = () => {
return bitcoin.address.toOutputScript(recipients[0].address, bitcoin.networks.bitcoin);
};
const send = async () => {
const handleSendTransaction = async () => {
dispatch({ type: ActionType.SET_BUTTON_DISABLED, payload: true });
dispatch({ type: ActionType.SET_LOADING, payload: true });
try {
const txids2watch = [];
// Perform biometric authentication first
if (await isBiometricUseCapableAndEnabled()) {
if (!(await unlockWithBiometrics())) {
// Stop execution if biometric unlock fails
dispatch({ type: ActionType.SET_LOADING, payload: false });
dispatch({ type: ActionType.SET_BUTTON_DISABLED, payload: false });
return;
}
}
const txidsToWatch = [];
if (!state.isPayjoinEnabled) {
await broadcast(tx);
// Only broadcast the transaction after biometrics pass
const result = await broadcastTransaction(tx);
if (!result) {
dispatch({ type: ActionType.SET_LOADING, payload: false });
dispatch({ type: ActionType.SET_BUTTON_DISABLED, payload: false });
return;
}
} else {
const payJoinWallet = new PayjoinTransaction(psbt, (txHex: string) => broadcast(txHex), wallet as HDSegwitBech32Wallet);
const payJoinWallet = new PayjoinTransaction(psbt, (txHex: string) => broadcastTransaction(txHex), wallet as HDSegwitBech32Wallet);
const paymentScript = getPaymentScript();
if (!paymentScript) {
throw new Error('Invalid payment script');
@ -191,15 +207,15 @@ const Confirm: React.FC = () => {
await payjoinClient.run();
const payjoinPsbt = payJoinWallet.getPayjoinPsbt();
if (payjoinPsbt) {
const tx2watch = payjoinPsbt.extractTransaction();
txids2watch.push(tx2watch.getId());
const txToWatch = payjoinPsbt.extractTransaction();
txidsToWatch.push(txToWatch.getId());
}
}
const txid = bitcoin.Transaction.fromHex(tx).getId();
txids2watch.push(txid);
txidsToWatch.push(txid);
// @ts-ignore: Notifications has to be TSed
Notifications.majorTomToGroundControl([], [], txids2watch);
Notifications.majorTomToGroundControl([], [], txidsToWatch);
let amount = 0;
for (const recipient of recipients) {
if (recipient.value) {
@ -227,16 +243,10 @@ const Confirm: React.FC = () => {
}
};
const broadcast = async (transaction: string) => {
const broadcastTransaction = async (transaction: string) => {
await BlueElectrum.ping();
await BlueElectrum.waitTillConnected();
if (await isBiometricUseCapableAndEnabled()) {
if (!(await unlockWithBiometrics())) {
return;
}
}
const result = await wallet.broadcastTx(transaction);
if (!result) {
throw new Error(loc.errors.broadcast);
@ -330,7 +340,7 @@ const Confirm: React.FC = () => {
{state.isLoading ? (
<ActivityIndicator />
) : (
<Button disabled={isElectrumDisabled || state.isButtonDisabled} onPress={send} title={loc.send.confirm_sendNow} />
<Button disabled={isElectrumDisabled || state.isButtonDisabled} onPress={handleSendTransaction} title={loc.send.confirm_sendNow} />
)}
</BlueCard>
</View>
@ -434,4 +444,4 @@ const styles = StyleSheet.create({
fontSize: 15,
fontWeight: 'bold',
},
});
});