fix(wallet): support no-signature wallet connect
This commit is contained in:
@@ -15,6 +15,18 @@ import { clearWalletToken, readWalletToken, writeWalletToken } from "./token";
|
||||
|
||||
type WalletStatus = "loading" | "loggedOut" | "loggedIn";
|
||||
|
||||
const localWalletTokenPrefix = "local-wallet:";
|
||||
|
||||
export function localWalletToken(wallet: string): string {
|
||||
return `${localWalletTokenPrefix}${wallet}`;
|
||||
}
|
||||
|
||||
function walletFromLocalToken(token: string): string | null {
|
||||
return token.startsWith(localWalletTokenPrefix)
|
||||
? token.slice(localWalletTokenPrefix.length)
|
||||
: null;
|
||||
}
|
||||
|
||||
type WalletContextValue = {
|
||||
address: string | null;
|
||||
token: string | null;
|
||||
@@ -52,6 +64,13 @@ export function WalletProvider({ children }: { children: ReactNode }) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localWallet = walletFromLocalToken(token);
|
||||
if (localWallet) {
|
||||
setAddress(localWallet);
|
||||
setStatus("loggedIn");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("loading");
|
||||
fetchWalletMe(token)
|
||||
.then((me) => {
|
||||
|
||||
Reference in New Issue
Block a user