fix(lint): avoid effect self-references in async loaders
This commit is contained in:
@@ -67,7 +67,7 @@ export default function NotificationsPage() {
|
||||
const [loadingError, setLoadingError] = useState<string | null>(null)
|
||||
const [markingAll, setMarkingAll] = useState(false)
|
||||
|
||||
const loadNotifications = useCallback(async () => {
|
||||
const loadNotifications = useCallback(async function loadNotifications() {
|
||||
setLoading(true)
|
||||
setLoadingError(null)
|
||||
|
||||
@@ -100,7 +100,7 @@ export default function NotificationsPage() {
|
||||
}
|
||||
}, [loadNotifications])
|
||||
|
||||
const markAllAsRead = useCallback(async () => {
|
||||
const markAllAsRead = useCallback(async function markAllAsRead() {
|
||||
if (markAllPendingRef.current) return
|
||||
|
||||
markAllPendingRef.current = true
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user