fix: refresh metal valuation after automatic quotes complete

This commit is contained in:
陈煜 committed 2026-10-03 22:57:19 +08:00
1 parent 0491f515fe
commit efc2c7c734
5 files changed
+21 -6

No files matched your search

+12 -2
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { api, money, type Position, currencies } from './api';
import { t as tr } from './i18n';
import { useToast } from './Toast';
@@ -11,6 +11,8 @@ export function MetalPanel({
position?: Position;
refresh: () => Promise<void>;
}) {
const refreshRef = useRef(refresh);
refreshRef.current = refresh;
const [data, setData] = useState<Data>(),
[busy, setBusy] = useState(false),
[error, setError] = useState(''),
@@ -39,7 +41,15 @@ export function MetalPanel({
const timer = setInterval(() => {
void api<Data>('/metals')
.then((v) => {
if (active) setData(v);
if (active) {
setData(v);
if (v.status.state !== 'updating') {
clearInterval(timer);
void refreshRef.current().catch((e) => {
if (active) setError(e.message);
});
}
}
})
.catch((e) => {
if (active) {