Check dapp url before metamask login (#191)

This commit is contained in:
Szymon Szlachtowicz 2022-01-17 00:16:12 +01:00 committed by GitHub
parent 7581693fe6
commit c6c81e1ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -78,6 +78,7 @@ function DragDiv() {
config={{
communityKey: process.env.COMMUNITY_KEY ?? "",
environment: process.env.ENV ?? "",
dappUrl: "https://0.0.0.0:8080",
}}
fetchMetadata={fetchMetadata}
/>

View File

@ -3,6 +3,7 @@ import { genPrivateKeyWithEntropy } from "@waku/status-communities/dist/cjs/util
import React, { useCallback } from "react";
import styled from "styled-components";
import { useConfig } from "../../contexts/configProvider";
import {
useSetIdentity,
useSetWalletIdentity,
@ -29,9 +30,14 @@ export function WalletModal() {
const { setModal: setWalleConnectModal } = useModal(WalletConnectModalName);
const { setModal: setCoinbaseModal } = useModal(CoinbaseModalName);
const { messenger } = useMessengerContext();
const { dappUrl } = useConfig();
const handleMetamaskClick = useCallback(async () => {
const ethereum = (window as any)?.ethereum as any | undefined;
if (document.location.origin !== dappUrl) {
alert("You are not signing in from correct url!");
return;
}
if (ethereum && messenger) {
try {
if (ethereum?.isMetaMask) {
@ -47,7 +53,7 @@ export function WalletModal() {
},
message: {
action: "Status Chat Key",
onlySignOn: "https://auth.status.im/",
onlySignOn: dappUrl,
message:
"I'm aware that i am signing message that creates a private chat key for status communicator. And I have double checked everything is fine.",
},

View File

@ -3,11 +3,13 @@ import React, { createContext, useContext } from "react";
export type ConfigType = {
communityKey: string;
environment: string;
dappUrl: string;
};
const ConfigContext = createContext<ConfigType>({
communityKey: "",
environment: "production",
dappUrl: "",
});
export function useConfig() {