fix(会员报价): 桌面端报价请求增加序号守卫
- useAccountWallet.ts:requestMembershipQuote 记录请求令牌,只有最新请求可以写入报价、错误与 loading Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -64,6 +64,7 @@ export function useAccountWallet(currentUserId: string) {
|
||||
null,
|
||||
);
|
||||
const rechargeLifecycleRef = useRef(0);
|
||||
const membershipQuoteRequestRef = useRef<symbol | null>(null);
|
||||
const walletLedgerLifecycleRef = useRef(0);
|
||||
const redeemLifecycleRef = useRef(0);
|
||||
const [walletUiOwnerUserId, setWalletUiOwnerUserId] = useState(currentUserId);
|
||||
@@ -395,32 +396,29 @@ export function useAccountWallet(currentUserId: string) {
|
||||
async function requestMembershipQuote(plan: ProfileMembershipPlan) {
|
||||
const rechargeLifecycle = rechargeLifecycleRef.current;
|
||||
const snapshotOwnerUserId = currentUserId;
|
||||
const requestToken = Symbol('profile-membership-quote');
|
||||
membershipQuoteRequestRef.current = requestToken;
|
||||
const isLatestQuoteRequest = () =>
|
||||
rechargeLifecycleRef.current === rechargeLifecycle &&
|
||||
currentUserIdRef.current === snapshotOwnerUserId &&
|
||||
membershipQuoteRequestRef.current === requestToken;
|
||||
setMembershipQuote(null);
|
||||
setMembershipQuoteError(null);
|
||||
setMembershipQuoteLoading(true);
|
||||
try {
|
||||
const quote = await getClientProfileMembershipUpgradeQuote(plan);
|
||||
if (
|
||||
rechargeLifecycleRef.current !== rechargeLifecycle ||
|
||||
currentUserIdRef.current !== snapshotOwnerUserId
|
||||
) {
|
||||
if (!isLatestQuoteRequest()) {
|
||||
return;
|
||||
}
|
||||
setMembershipQuote(quote);
|
||||
} catch (error) {
|
||||
if (
|
||||
rechargeLifecycleRef.current === rechargeLifecycle &&
|
||||
currentUserIdRef.current === snapshotOwnerUserId
|
||||
) {
|
||||
if (isLatestQuoteRequest()) {
|
||||
setMembershipQuoteError(
|
||||
error instanceof Error ? error.message : '读取升级报价失败',
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (
|
||||
rechargeLifecycleRef.current === rechargeLifecycle &&
|
||||
currentUserIdRef.current === snapshotOwnerUserId
|
||||
) {
|
||||
if (isLatestQuoteRequest()) {
|
||||
setMembershipQuoteLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user