fix: simplify wallet choices and use bnb chain

This commit is contained in:
TerryM
2026-06-02 02:58:01 +08:00
parent b9fe7ff168
commit 0edcc80513
7 changed files with 197 additions and 248 deletions

View File

@@ -10,7 +10,7 @@ import {
import { useToast } from "../components/Toast";
import { useI18n } from "../i18n";
import { fetchWalletMe } from "./api";
import { signInWithInjectedWallet } from "./injected";
import { signInWithInjectedWallet, type WalletKind } from "./injected";
import { clearWalletToken, readWalletToken, writeWalletToken } from "./token";
type WalletStatus = "loading" | "loggedOut" | "loggedIn";
@@ -22,7 +22,7 @@ type WalletContextValue = {
loginModalOpen: boolean;
openLoginModal: () => void;
closeLoginModal: () => void;
signInInjected: () => Promise<void>;
signInInjected: (kind?: WalletKind) => Promise<void>;
completeLogin: (token: string, wallet: string) => void;
logout: () => void;
};
@@ -80,18 +80,21 @@ export function WalletProvider({ children }: { children: ReactNode }) {
setLoginModalOpen(false);
}, []);
const signInInjected = useCallback(async () => {
try {
const res = await signInWithInjectedWallet();
completeLogin(res.token, res.wallet);
showToast(t("walletLoginSuccess"));
} catch (error) {
const message =
error instanceof Error ? error.message : t("walletLoginFailed");
showToast(message || t("walletLoginFailed"), "error");
throw error;
}
}, [completeLogin, showToast, t]);
const signInInjected = useCallback(
async (kind?: WalletKind) => {
try {
const res = await signInWithInjectedWallet(kind);
completeLogin(res.token, res.wallet);
showToast(t("walletLoginSuccess"));
} catch (error) {
const message =
error instanceof Error ? error.message : t("walletLoginFailed");
showToast(message || t("walletLoginFailed"), "error");
throw error;
}
},
[completeLogin, showToast, t],
);
const logout = useCallback(() => {
clearWalletToken();