feat: Support metamask mobile login (#2844)

This commit is contained in:
HGZ-20
2024-03-30 00:08:52 +08:00
committed by GitHub
parent 505054b0eb
commit bfa2ab63ad
8 changed files with 1721 additions and 49 deletions

View File

@ -43,6 +43,8 @@ import DouyinLoginButton from "./DouyinLoginButton";
import LoginButton from "./LoginButton";
import * as AuthBackend from "./AuthBackend";
import {WechatOfficialAccountModal} from "./Util";
import {MetaMaskProvider} from "@metamask/sdk-react";
import MetaMaskLoginButton from "./MetaMaskLoginButton";
function getSigninButton(provider) {
const text = i18next.t("login:Sign in with {type}").replace("{type}", provider.displayName !== "" ? provider.displayName : provider.type);
@ -160,11 +162,36 @@ export function renderProviderLogo(provider, application, width, margin, size, l
</a>
);
} else if (provider.category === "Web3") {
return (
<a key={provider.displayName} onClick={() => goToWeb3Url(application, provider, "signup")}>
<img width={width} height={width} src={getProviderLogoURL(provider)} alt={provider.displayName} className="provider-img" style={{margin: margin}} />
</a>
);
if (provider.type === "MetaMask") {
return (
<MetaMaskProvider
debug={false}
sdkOptions={{
communicationServerUrl: process.env.REACT_APP_COMM_SERVER_URL,
checkInstallationImmediately: false, // This will automatically connect to MetaMask on page load
dappMetadata: {
name: "Casdoor",
url: window.location.protocol + "//" + window.location.host,
},
}}
>
<MetaMaskLoginButton
application={application}
web3Provider={provider}
method={"signup"}
width={width}
margin={margin}
/>
</MetaMaskProvider>
);
} else {
return (
<a key={provider.displayName} onClick={() => goToWeb3Url(application, provider, "signup")}>
<img width={width} height={width} src={getProviderLogoURL(provider)} alt={provider.displayName}
className="provider-img" style={{margin: margin}} />
</a>
);
}
}
} else if (provider.type === "Custom") {
// style definition