mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 11:18:24 +00:00
Fix setting transaction ERROR or EXPIRED statuses
This commit is contained in:
@@ -88,6 +88,8 @@ export const sendTask = async function (
|
|||||||
} as TransactionTaskResult
|
} as TransactionTaskResult
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
// Mark the tx ERROR if one was created during prepare.
|
// Mark the tx ERROR if one was created during prepare.
|
||||||
|
// prepare() errors thrown after the draft exists carry its transactionId.
|
||||||
|
transactionIdForRecovery ??= e?.params?.transactionId
|
||||||
if (transactionIdForRecovery) {
|
if (transactionIdForRecovery) {
|
||||||
const tx = transactionsStore.findById(transactionIdForRecovery)
|
const tx = transactionsStore.findById(transactionIdForRecovery)
|
||||||
if (tx) {
|
if (tx) {
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ export const transferTask = async function (
|
|||||||
nwcEvent,
|
nwcEvent,
|
||||||
} as TransactionTaskResult
|
} as TransactionTaskResult
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
// prepare() may throw after creating the draft (e.g. expired invoice); its
|
||||||
|
// errors carry the transactionId so the draft still gets stamped ERROR/EXPIRED.
|
||||||
|
transactionIdForRecovery ??= e?.params?.transactionId
|
||||||
let txAfterError = transactionIdForRecovery
|
let txAfterError = transactionIdForRecovery
|
||||||
? transactionsStore.findById(transactionIdForRecovery)
|
? transactionsStore.findById(transactionIdForRecovery)
|
||||||
: undefined
|
: undefined
|
||||||
@@ -111,15 +114,17 @@ export const transferTask = async function (
|
|||||||
txAfterError.status !== TransactionStatus.RECOVERED &&
|
txAfterError.status !== TransactionStatus.RECOVERED &&
|
||||||
txAfterError.status !== TransactionStatus.ERROR
|
txAfterError.status !== TransactionStatus.ERROR
|
||||||
) {
|
) {
|
||||||
|
// Only prepare's expiry check puts `expiry` in the error params.
|
||||||
|
const status = e?.params?.expiry ? TransactionStatus.EXPIRED : TransactionStatus.ERROR
|
||||||
let transactionData: TransactionData[] = []
|
let transactionData: TransactionData[] = []
|
||||||
try { transactionData = JSON.parse(txAfterError.data) } catch {}
|
try { transactionData = JSON.parse(txAfterError.data) } catch {}
|
||||||
transactionData.push({
|
transactionData.push({
|
||||||
status: TransactionStatus.ERROR,
|
status,
|
||||||
error: WalletUtils.formatError(e),
|
error: WalletUtils.formatError(e),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
})
|
})
|
||||||
txAfterError.update({
|
txAfterError.update({
|
||||||
status: TransactionStatus.ERROR,
|
status,
|
||||||
data: JSON.stringify(transactionData),
|
data: JSON.stringify(transactionData),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -216,6 +221,9 @@ export const transferOnchainTask = async function (
|
|||||||
nwcEvent,
|
nwcEvent,
|
||||||
} as TransactionTaskResult
|
} as TransactionTaskResult
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
// prepare() may throw after creating the draft (e.g. expired invoice); its
|
||||||
|
// errors carry the transactionId so the draft still gets stamped ERROR/EXPIRED.
|
||||||
|
transactionIdForRecovery ??= e?.params?.transactionId
|
||||||
const txAfterError = transactionIdForRecovery
|
const txAfterError = transactionIdForRecovery
|
||||||
? transactionsStore.findById(transactionIdForRecovery)
|
? transactionsStore.findById(transactionIdForRecovery)
|
||||||
: undefined
|
: undefined
|
||||||
@@ -228,15 +236,17 @@ export const transferOnchainTask = async function (
|
|||||||
txAfterError.status !== TransactionStatus.RECOVERED &&
|
txAfterError.status !== TransactionStatus.RECOVERED &&
|
||||||
txAfterError.status !== TransactionStatus.ERROR
|
txAfterError.status !== TransactionStatus.ERROR
|
||||||
) {
|
) {
|
||||||
|
// Only prepare's expiry check puts `expiry` in the error params.
|
||||||
|
const status = e?.params?.expiry ? TransactionStatus.EXPIRED : TransactionStatus.ERROR
|
||||||
let transactionData: TransactionData[] = []
|
let transactionData: TransactionData[] = []
|
||||||
try { transactionData = JSON.parse(txAfterError.data) } catch {}
|
try { transactionData = JSON.parse(txAfterError.data) } catch {}
|
||||||
transactionData.push({
|
transactionData.push({
|
||||||
status: TransactionStatus.ERROR,
|
status,
|
||||||
error: WalletUtils.formatError(e),
|
error: WalletUtils.formatError(e),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
})
|
})
|
||||||
txAfterError.update({
|
txAfterError.update({
|
||||||
status: TransactionStatus.ERROR,
|
status,
|
||||||
data: JSON.stringify(transactionData),
|
data: JSON.stringify(transactionData),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user