refactor: remove demo timers and client-side timeout simulation
Remove lib/config/demo-timers.ts and all usages across stores and pages. Order timeout scheduling, dispute auto-progression, and hardcoded countdown displays are removed — timeouts are now handled server-side by the backend.
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
import type { Actor } from "@/lib/actor"
|
||||
import {
|
||||
ORDER_ACCEPT_TIMEOUT_MS,
|
||||
ORDER_CLOSE_TIMEOUT_MS,
|
||||
ORDER_REVIEW_TIMEOUT_MS,
|
||||
} from "@/lib/config/demo-timers"
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import { evaluateOrderTransition, type OrderAction } from "@/lib/domain/order-machine"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
@@ -48,16 +43,8 @@ interface OrderState {
|
||||
resolveDispute: (orderId: string) => OrderMutationResult
|
||||
}
|
||||
|
||||
const orderTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
const pendingCreations = new Set<string>()
|
||||
|
||||
function clearOrderTimeout(orderId: string) {
|
||||
const timer = orderTimeouts.get(orderId)
|
||||
if (!timer) return
|
||||
clearTimeout(timer)
|
||||
orderTimeouts.delete(orderId)
|
||||
}
|
||||
|
||||
function isParticipant(order: Order, userId: string) {
|
||||
return order.consumerId === userId || order.playerId === userId
|
||||
}
|
||||
@@ -149,42 +136,6 @@ function syncChatSession(order: Order, previousStatus: OrderStatus) {
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleOrderTimeout(orderId: string, status: OrderStatus) {
|
||||
clearOrderTimeout(orderId)
|
||||
|
||||
if (status !== "pending_accept" && status !== "pending_close" && status !== "pending_review") {
|
||||
return
|
||||
}
|
||||
|
||||
const timeoutMap: Record<"pending_accept" | "pending_close" | "pending_review", number> = {
|
||||
pending_accept: ORDER_ACCEPT_TIMEOUT_MS,
|
||||
pending_close: ORDER_CLOSE_TIMEOUT_MS,
|
||||
pending_review: ORDER_REVIEW_TIMEOUT_MS,
|
||||
}
|
||||
const timeoutMs = timeoutMap[status]
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
const state = useOrderStore.getState()
|
||||
const order = state.orders.find((item) => item.id === orderId)
|
||||
if (!order || order.status !== status) {
|
||||
orderTimeouts.delete(orderId)
|
||||
return
|
||||
}
|
||||
|
||||
if (status === "pending_accept") {
|
||||
state.autoTimeoutPendingAccept(orderId)
|
||||
} else if (status === "pending_close") {
|
||||
state.autoTimeoutPendingClose(orderId)
|
||||
} else if (status === "pending_review") {
|
||||
state.autoTimeoutPendingReview(orderId)
|
||||
}
|
||||
|
||||
orderTimeouts.delete(orderId)
|
||||
}, timeoutMs)
|
||||
|
||||
orderTimeouts.set(orderId, timer)
|
||||
}
|
||||
|
||||
function notifyOrderStatus(order: Order) {
|
||||
if (!useAuthStore.getState().notificationPrefs.order) {
|
||||
return
|
||||
@@ -346,7 +297,6 @@ export const useOrderStore = create<OrderState>((set, get) => {
|
||||
orders: [order, ...state.orders],
|
||||
}))
|
||||
|
||||
scheduleOrderTimeout(order.id, order.status)
|
||||
return { decision: allow(), order }
|
||||
},
|
||||
createPaidOrder: (input, actor) => {
|
||||
@@ -437,17 +387,3 @@ export const useOrderStore = create<OrderState>((set, get) => {
|
||||
resolveDispute: (orderId) => applyTransition(orderId, "RESOLVE_DISPUTE"),
|
||||
}
|
||||
})
|
||||
|
||||
useOrderStore.subscribe((state, prevState) => {
|
||||
state.orders.forEach((order) => {
|
||||
const prevOrder = prevState.orders.find((item) => item.id === order.id)
|
||||
if (!prevOrder || prevOrder.status !== order.status) {
|
||||
scheduleOrderTimeout(order.id, order.status)
|
||||
}
|
||||
})
|
||||
prevState.orders.forEach((order) => {
|
||||
if (!state.orders.some((item) => item.id === order.id)) {
|
||||
clearOrderTimeout(order.id)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user