mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 19:28:26 +00:00
Remove task queue default timeout from mint ops
This commit is contained in:
@@ -380,7 +380,12 @@ export const WalletStoreModel = types
|
||||
}
|
||||
|
||||
setGlobalRequestOptions({
|
||||
headers: {'User-Agent': `Minibits/${JS_BUNDLE_VERSION}`}
|
||||
headers: {'User-Agent': `Minibits/${JS_BUNDLE_VERSION}`},
|
||||
// Down from the cashu-ts default of 300s. Money-moving tasks have no
|
||||
// queue timeout (see createQueueAwaitable), so this bounds how long
|
||||
// the user waits for a network failure. NUT-19 cached endpoints
|
||||
// (swap/melt/mint) are still retried within the mint's ttl.
|
||||
requestTimeout: 60 * 1000,
|
||||
})
|
||||
// create cashu-ts mint instance
|
||||
const newMint = new CashuMint(mintUrl)
|
||||
|
||||
@@ -48,7 +48,6 @@ const transferQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'transferTask',
|
||||
timeoutMessage: 'transferQueue timed out',
|
||||
task: () =>
|
||||
transferTask(
|
||||
mintBalanceToTransferFrom,
|
||||
@@ -86,7 +85,6 @@ const transferOnchainQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'transferOnchainTask',
|
||||
timeoutMessage: 'transferOnchainQueue timed out',
|
||||
task: () =>
|
||||
transferOnchainTask(
|
||||
mintBalanceToTransferFrom,
|
||||
|
||||
@@ -43,7 +43,6 @@ const topupQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'topupTask',
|
||||
timeoutMessage: 'Topup task timed out',
|
||||
task: () =>
|
||||
topupTask(
|
||||
mintBalanceToTopup,
|
||||
|
||||
@@ -92,7 +92,6 @@ const receiveQueueAwaitable = (
|
||||
|
||||
return createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: useBatch ? 'receiveBatchTask' : 'receiveTask',
|
||||
timeoutMessage: 'receiveQueue timed out',
|
||||
task: async () => {
|
||||
const token = await decodeTokenWithKeysets(encodedToken, mint.mintUrl)
|
||||
return (useBatch
|
||||
@@ -112,7 +111,6 @@ const receiveOfflinePrepareQueueAwaitable = (
|
||||
return createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'receiveOfflinePrepareTask',
|
||||
prioritized: false,
|
||||
timeoutMessage: 'Offline receive prepare timed out',
|
||||
task: () =>
|
||||
receiveOfflinePrepareTask(
|
||||
mintUrl,
|
||||
@@ -130,7 +128,6 @@ const receiveOfflineCompleteQueueAwaitable = (
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'receiveOfflineCompleteTask',
|
||||
prioritized: false,
|
||||
timeoutMessage: 'Offline receive complete timed out',
|
||||
task: () => receiveOfflineCompleteTask(transactionId),
|
||||
})
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ const revertQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'revertTask',
|
||||
timeoutMessage: 'Revert task timed out',
|
||||
task: () => revertTask(transaction),
|
||||
})
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ const sendQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'sendTask',
|
||||
timeoutMessage: 'sendQueue timed out',
|
||||
task: () =>
|
||||
sendTask(
|
||||
mintBalanceToSendFrom,
|
||||
@@ -38,7 +37,6 @@ const cashuPaymentRequestQueueAwaitable = (
|
||||
): Promise<TransactionTaskResult> =>
|
||||
createQueueAwaitable<TransactionTaskResult>({
|
||||
taskFunction: 'cashuPaymentRequestTask',
|
||||
timeoutMessage: 'Cashu payment request timed out',
|
||||
task: () =>
|
||||
cashuPaymentRequestTask(
|
||||
mintBalanceToReceiveTo,
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
SYNC_STATE_WITH_ALL_MINTS_TASK,
|
||||
SYNC_STATE_WITH_MINT_TASK,
|
||||
SyncStateTaskResult,
|
||||
TASK_QUEUE_TIMEOUT,
|
||||
TransactionStateUpdate,
|
||||
WalletTaskResult,
|
||||
} from '../types'
|
||||
@@ -488,6 +489,7 @@ const syncStateWithAllMintsQueueAwaitable = (
|
||||
): Promise<SyncStateTaskResult> =>
|
||||
createQueueAwaitable<SyncStateTaskResult>({
|
||||
taskFunction: 'syncSpendableStateTask',
|
||||
timeoutMs: TASK_QUEUE_TIMEOUT,
|
||||
timeoutMessage: 'Sync all mints state timed out',
|
||||
task: () => syncStateWithAllMintsTask({proofState: options.proofState}),
|
||||
})
|
||||
@@ -508,6 +510,7 @@ const syncStateWithMintQueueAwaitable = (
|
||||
return createQueueAwaitable<SyncStateTaskResult>({
|
||||
taskFunction: SYNC_STATE_WITH_MINT_TASK,
|
||||
prioritized: false,
|
||||
timeoutMs: TASK_QUEUE_TIMEOUT,
|
||||
timeoutMessage: 'Sync mint state timed out',
|
||||
task: () => syncStateWithMintTask(options),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import EventEmitter from '../../utils/eventEmitter'
|
||||
import AppError, {Err} from '../../utils/AppError'
|
||||
import {SyncQueue} from '../syncQueueService'
|
||||
import {TASK_QUEUE_TIMEOUT, WalletTaskResult} from './types'
|
||||
import {WalletTaskResult} from './types'
|
||||
|
||||
/**
|
||||
* Shared helper that wraps a task function with the SyncQueue + EventEmitter +
|
||||
@@ -21,7 +21,15 @@ export interface QueueAwaitableOptions<T extends WalletTaskResult> {
|
||||
task: () => Promise<T>
|
||||
/** Use addPrioritizedTask when true, otherwise addTask. Defaults to true. */
|
||||
prioritized?: boolean
|
||||
/** Timeout in ms before rejecting with TIMEOUT_ERROR. Defaults to TASK_QUEUE_TIMEOUT. */
|
||||
/**
|
||||
* Timeout in ms before rejecting with TIMEOUT_ERROR. Omitted = no timeout.
|
||||
*
|
||||
* The timeout only stops the CALLER waiting — the task keeps running in the
|
||||
* queue and may still move money. Never set it on a task that spends, receives
|
||||
* or mints ecash: the screen would report "failed" for an operation that is
|
||||
* still in flight, inviting a retry or an app kill mid-operation. Such tasks
|
||||
* settle on their own, bounded by the cashu-ts request timeout.
|
||||
*/
|
||||
timeoutMs?: number
|
||||
/** Message used for the timeout error. */
|
||||
timeoutMessage?: string
|
||||
@@ -34,7 +42,7 @@ export const createQueueAwaitable = <T extends WalletTaskResult>(
|
||||
taskFunction,
|
||||
task,
|
||||
prioritized = true,
|
||||
timeoutMs = TASK_QUEUE_TIMEOUT,
|
||||
timeoutMs,
|
||||
timeoutMessage = `${taskFunction} timed out`,
|
||||
} = options
|
||||
|
||||
@@ -81,10 +89,12 @@ export const createQueueAwaitable = <T extends WalletTaskResult>(
|
||||
|
||||
queued.then(resolveOnce).catch(rejectOnce)
|
||||
|
||||
setTimeout(() => {
|
||||
if (!resolved) {
|
||||
rejectOnce(new AppError(Err.TIMEOUT_ERROR, timeoutMessage))
|
||||
}
|
||||
}, timeoutMs)
|
||||
if (timeoutMs !== undefined) {
|
||||
setTimeout(() => {
|
||||
if (!resolved) {
|
||||
rejectOnce(new AppError(Err.TIMEOUT_ERROR, timeoutMessage))
|
||||
}
|
||||
}, timeoutMs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user