wait for finance fee pool propagation

This commit is contained in:
2026-08-12 14:56:50 +08:00
parent 285e17f0ba
commit 6d50bde31e
2 changed files with 15 additions and 6 deletions
@@ -79,10 +79,18 @@ async function normalizeFixture(context) {
|| !Array.isArray(root.orders) || !Array.isArray(root.feeSources)) return null
const customerId = id(root.customerId)
const orders = new Map(root.orders.map((order) => [id(order.orderId ?? order.id), order]))
const poolResponse = await context.request('GET',
`${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
const poolData = poolResponse?.body?.data
const pool = rows(poolData).concat(rows(poolData?.items)).filter((item) => String(item?.sourceType ?? '') !== 'MANUAL_COST')
const expectedSourceIds = new Set(root.feeSources.map(sourceId).filter(Boolean))
let pool = []
for (let attempt = 0; attempt < 20; attempt += 1) {
const poolResponse = await context.request('GET',
`${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
const poolData = poolResponse?.body?.data
pool = rows(poolData).concat(rows(poolData?.items))
.filter((item) => String(item?.sourceType ?? '') !== 'MANUAL_COST')
const visible = new Set(pool.map((item) => id(item?.sourceId)))
if ([...expectedSourceIds].every((source) => visible.has(source))) break
await new Promise((resolve) => setTimeout(resolve, 500))
}
const poolBySource = new Map(pool.map((item) => [id(item?.sourceId), item]))
const attemptedSources = root.feeSources.map((raw) => {
const order = orders.get(id(raw.orderId))