Suggest login with ethereum if wallet is present

This commit is contained in:
silverpill 2022-09-24 23:47:42 +00:00
parent 360d00ddb2
commit 74173b4884
2 changed files with 13 additions and 3 deletions

View file

@ -28,7 +28,11 @@ export async function getWallet(
provider?: Web3Provider, provider?: Web3Provider,
): Promise<Signer | null> { ): Promise<Signer | null> {
if (!provider) { if (!provider) {
provider = getWeb3Provider() try {
provider = getWeb3Provider()
} catch (error) {
return null
}
} }
try { try {
await provider.send("eth_requestAccounts", []) await provider.send("eth_requestAccounts", [])

View file

@ -103,14 +103,18 @@ import {
import Loader from "@/components/Loader.vue" import Loader from "@/components/Loader.vue"
import { useInstanceInfo } from "@/store/instance" import { useInstanceInfo } from "@/store/instance"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
import { createEip4361_SignedMessage, getWallet } from "@/utils/ethereum" import {
createEip4361_SignedMessage,
getWallet,
hasEthereumWallet,
} from "@/utils/ethereum"
const router = useRouter() const router = useRouter()
const { setCurrentUser, setAuthToken } = useCurrentUser() const { setCurrentUser, setAuthToken } = useCurrentUser()
const { instance } = $(useInstanceInfo()) const { instance } = $(useInstanceInfo())
const isRegistered = $ref(true) const isRegistered = $ref(true)
const loginType = $ref<"password" | "eip4361">("password") const loginType = $ref<"password" | "eip4361">(hasEthereumWallet() ? "eip4361" : "password")
const username = $ref("") const username = $ref("")
const password = $ref<string | null>(null) const password = $ref<string | null>(null)
const inviteCode = $ref<string | null>(null) const inviteCode = $ref<string | null>(null)
@ -156,6 +160,7 @@ async function register() {
} else { } else {
const signer = await getWallet() const signer = await getWallet()
if (!signer) { if (!signer) {
loginErrorMessage = "wallet not found"
return return
} }
const { message, signature } = await createEip4361_SignedMessage( const { message, signature } = await createEip4361_SignedMessage(
@ -200,6 +205,7 @@ async function login() {
} else { } else {
const signer = await getWallet() const signer = await getWallet()
if (!signer) { if (!signer) {
loginErrorMessage = "wallet not found"
return return
} }
const { message, signature } = await createEip4361_SignedMessage( const { message, signature } = await createEip4361_SignedMessage(