fix(lint): avoid effect self-references in async loaders

This commit is contained in:
zetaloop
2026-04-24 09:06:55 +08:00
parent d59f7c6dc8
commit 774c62ec1c
3 changed files with 96 additions and 42 deletions
+58 -26
View File
@@ -59,36 +59,68 @@ export default function WalletPage() {
})
}, [isConsumer, transactions])
const loadWalletData = useCallback(async (options?: { showToast?: boolean }) => {
setIsLoading(true)
setLoadError(null)
try {
const res = await requestWithAuth(async () => {
const [b, items] = await Promise.all([
getWalletBalance(),
listWalletTransactions({ offset: 0, limit: 1000 }),
])
return { balance: b, transactions: items }
})
if (!res) {
setLoadError("请先登录")
return
const loadWalletData = useCallback(
async (options?: { showToast?: boolean; silent?: boolean }) => {
if (!options?.silent) {
setIsLoading(true)
setLoadError(null)
}
setBalance(res.balance)
setTransactions(res.transactions)
if (options?.showToast) notifySuccess("交易记录已刷新")
} catch (error) {
setLoadError(toApiError(error).msg)
} finally {
setIsLoading(false)
}
}, [])
try {
const res = await requestWithAuth(async () => {
const [b, items] = await Promise.all([
getWalletBalance(),
listWalletTransactions({ offset: 0, limit: 1000 }),
])
return { balance: b, transactions: items }
})
if (!res) {
setLoadError("请先登录")
return
}
setBalance(res.balance)
setTransactions(res.transactions)
if (options?.showToast) notifySuccess("交易记录已刷新")
} catch (error) {
setLoadError(toApiError(error).msg)
} finally {
setIsLoading(false)
}
},
[],
)
useEffect(() => {
void loadWalletData()
}, [loadWalletData])
let cancelled = false
void (async () => {
try {
const res = await requestWithAuth(async () => {
const [b, items] = await Promise.all([
getWalletBalance(),
listWalletTransactions({ offset: 0, limit: 100 }),
])
return { balance: b, transactions: items }
})
if (cancelled) return
if (!res) {
setLoadError("请先登录")
return
}
setBalance(res.balance)
setTransactions(res.transactions)
} catch (error) {
if (cancelled) return
setLoadError(toApiError(error).msg)
}
})()
return () => {
cancelled = true
}
}, [])
const handleTopUp = (rawAmount?: number) => {
const amount = rawAmount ?? Number(customAmount)