Harden wallet challenge proxy

This commit is contained in:
2569718930@qq.com
2026-06-01 22:15:38 +08:00
parent 8fc9f3ae1a
commit fc0a8b8ff5
4 changed files with 127 additions and 21 deletions
+9 -5
View File
@@ -16,7 +16,11 @@ import {
WALLET_TRANSACTION_REQUEST_TIMEOUT_MS,
} from "./constants";
import { shortAddress } from "./formatters";
import { normalizePaymentError, requestWalletWithTimeout } from "./payment-utils";
import {
normalizePaymentError,
readPaymentApiErrorMessage,
requestWalletWithTimeout,
} from "./payment-utils";
import {
eip6963Providers,
getEvmProvider,
@@ -300,8 +304,8 @@ export function useWalletBind(params: UseWalletBindParams) {
method: "POST", headers: authHeaders, body: JSON.stringify({ address }),
});
if (!challengeRes.ok) {
const raw = (await challengeRes.text()).slice(0, 300);
throw new Error(copy.challengeFailed.replace("{raw}", raw));
const message = await readPaymentApiErrorMessage(challengeRes);
throw new Error(copy.challengeFailed.replace("{raw}", message));
}
const challengeJson = (await challengeRes.json()) as { nonce?: string; message?: string };
@@ -314,8 +318,8 @@ export function useWalletBind(params: UseWalletBindParams) {
method: "POST", headers: authHeaders, body: JSON.stringify({ address, nonce, signature }),
});
if (!verifyRes.ok) {
const raw = (await verifyRes.text()).slice(0, 300);
throw new Error(copy.verifyFailedRaw.replace("{raw}", raw));
const message = await readPaymentApiErrorMessage(verifyRes);
throw new Error(copy.verifyFailedRaw.replace("{raw}", message));
}
setPaymentInfo(`${walletLabel} 绑定成功: ${shortAddress(address)}${binanceBindHint || "现在可点击“立即订阅并激活服务”。"}`);