Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
chore: Save the connector id in localstorage (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge committed Mar 2, 2021
1 parent ba47f13 commit 5aee14d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/widgets/WalletModal/AccountModal.tsx
Expand Up @@ -5,7 +5,7 @@ import LinkExternal from "../../components/Link/LinkExternal";
import Flex from "../../components/Box/Flex";
import { Modal } from "../Modal";
import CopyToClipboard from "./CopyToClipboard";
import { localStorageKey } from "./config";
import { connectorLocalStorageKey } from "./config";

interface Props {
account: string;
Expand Down Expand Up @@ -34,9 +34,8 @@ const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null
variant="secondary"
onClick={() => {
logout();
window.localStorage.removeItem(localStorageKey);
window.localStorage.removeItem(connectorLocalStorageKey);
onDismiss();
window.location.reload();
}}
>
Logout
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/WalletModal/WalletCard.tsx
@@ -1,7 +1,7 @@
import React from "react";
import Button from "../../components/Button/Button";
import Text from "../../components/Text/Text";
import { localStorageKey } from "./config";
import { connectorLocalStorageKey } from "./config";
import { Login, Config } from "./types";

interface Props {
Expand All @@ -19,7 +19,7 @@ const WalletCard: React.FC<Props> = ({ login, walletConfig, onDismiss, mb }) =>
variant="tertiary"
onClick={() => {
login(walletConfig.connectorId);
window.localStorage.setItem(localStorageKey, "1");
window.localStorage.setItem(connectorLocalStorageKey, walletConfig.connectorId);
onDismiss();
}}
style={{ justifyContent: "space-between" }}
Expand Down
16 changes: 8 additions & 8 deletions src/widgets/WalletModal/config.tsx
Expand Up @@ -4,40 +4,40 @@ import TokenPocket from "./icons/TokenPocket";
import TrustWallet from "./icons/TrustWallet";
import WalletConnect from "./icons/WalletConnect";
import BinanceChain from "./icons/BinanceChain";
import { Config } from "./types";
import { Config, ConnectorNames } from "./types";

const connectors: Config[] = [
{
title: "Metamask",
icon: Metamask,
connectorId: "injected",
connectorId: ConnectorNames.Injected,
},
{
title: "TrustWallet",
icon: TrustWallet,
connectorId: "injected",
connectorId: ConnectorNames.Injected,
},
{
title: "MathWallet",
icon: MathWallet,
connectorId: "injected",
connectorId: ConnectorNames.Injected,
},
{
title: "TokenPocket",
icon: TokenPocket,
connectorId: "injected",
connectorId: ConnectorNames.Injected,
},
{
title: "WalletConnect",
icon: WalletConnect,
connectorId: "walletconnect",
connectorId: ConnectorNames.WalletConnect,
},
{
title: "Binance Chain Wallet",
icon: BinanceChain,
connectorId: "bsc",
connectorId: ConnectorNames.BSC,
},
];

export default connectors;
export const localStorageKey = "accountStatus";
export const connectorLocalStorageKey = "connectorId";
4 changes: 3 additions & 1 deletion src/widgets/WalletModal/index.tsx
@@ -1,2 +1,4 @@
export { default as useWalletModal } from "./useWalletModal";
export type { ConnectorId, Login } from "./types";
export { connectorLocalStorageKey } from "./config";
export { ConnectorNames } from "./types";
export type { Login } from "./types";
20 changes: 7 additions & 13 deletions src/widgets/WalletModal/types.ts
@@ -1,22 +1,16 @@
import { FC } from "react";
import { SvgProps } from "../../components/Svg/types";

export type ConnectorId =
| "authereum"
| "fortmatic"
| "frame"
| "injected"
| "portis"
| "squarelink"
| "torus"
| "walletconnect"
| "walletlink"
| "bsc";
export enum ConnectorNames {
Injected = "injected",
WalletConnect = "walletconnect",
BSC = "bsc",
}

export type Login = (connectorId: ConnectorId) => void;
export type Login = (connectorId: ConnectorNames) => void;

export interface Config {
title: string;
icon: FC<SvgProps>;
connectorId: ConnectorId;
connectorId: ConnectorNames;
}

0 comments on commit 5aee14d

Please sign in to comment.