Skip to content

Commit

Permalink
fix: Wallet types (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge authored Nov 16, 2020
1 parent e267e86 commit 2fc1a86
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/widgets/Nav/UserBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from "react";
import styled from "styled-components";
import Button from "../../components/Button";
import useWalletModal from "../WalletModal";
import { Login } from "../WalletModal/types";

interface Props {
account?: string;
closeNav: () => void;
login: () => void;
login: Login;
logout: () => void;
}

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/Nav/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Login } from "../WalletModal/types";

export type NavTheme = {
background: string;
hover: string;
Expand All @@ -10,7 +12,7 @@ export interface LangType {

export interface NavProps {
account?: string;
login: () => void;
login: Login;
logout: () => void;
isDark: boolean;
toggleTheme: (isDark: boolean) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/WalletModal/AccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from "../../components/Link";
import Flex from "../../components/Flex";
import { OpenNewIcon } from "../../components/Svg";
import { Modal } from "../Modal";
import { localStorageKey } from "./config";

interface Props {
account?: string;
Expand Down Expand Up @@ -37,6 +38,7 @@ const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null
variant="secondary"
onClick={() => {
logout();
window.localStorage.removeItem(localStorageKey);
onDismiss();
}}
>
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/WalletModal/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { HelpIcon } from "../../components/Svg";
import { Modal } from "../Modal";
import WalletCard from "./WalletCard";
import config from "./config";
import { Login } from "./types";

interface Props {
login: () => void;
login: Login;
onDismiss?: () => void;
}

Expand Down
15 changes: 5 additions & 10 deletions src/widgets/WalletModal/WalletCard.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React, { FC } from "react";
import React from "react";
import Button from "../../components/Button";
import Text from "../../components/Text";
import SvgProps from "../../components/Svg/types";

interface Config {
title: string;
icon: FC<SvgProps>;
connectorId: string;
}
import { localStorageKey } from "./config";
import { Login, Config } from "./types";

interface Props {
walletConfig: Config;
login: (id: string) => void;
login: Login;
onDismiss: () => void;
mb: string;
}
Expand All @@ -24,7 +19,7 @@ const WalletCard: React.FC<Props> = ({ login, walletConfig, onDismiss, mb }) =>
variant="tertiary"
onClick={() => {
login(walletConfig.connectorId);
window.localStorage.setItem("accountStatus", "1");
window.localStorage.setItem(localStorageKey, "1");
onDismiss();
}}
style={{ justifyContent: "space-between" }}
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/WalletModal/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import MathWallet from "./icons/MathWallet";
import TokenPocket from "./icons/TokenPocket";
import TrustWallet from "./icons/TrustWallet";
import WalletConnect from "./icons/WalletConnect";
import { Config } from "./types";

export default [
const connectors: Config[] = [
{
title: "Metamask",
icon: Metamask,
Expand All @@ -31,3 +32,6 @@ export default [
connectorId: "walletconnect",
},
];

export default connectors;
export const localStorageKey = "accountStatus";
3 changes: 2 additions & 1 deletion src/widgets/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from "react";
import { useModal } from "../Modal";
import ConnectModal from "./ConnectModal";
import AccountModal from "./AccountModal";
import { Login } from "./types";

interface ReturnType {
onPresentConnectModal: () => void;
onPresentAccountModal: () => void;
}

const useWalletModal = (login: () => void, logout: () => void, account?: string): ReturnType => {
const useWalletModal = (login: Login, logout: () => void, account?: string): ReturnType => {
const [onPresentConnectModal] = useModal(<ConnectModal login={login} />);
const [onPresentAccountModal] = useModal(<AccountModal account={account} logout={logout} />);
return { onPresentConnectModal, onPresentAccountModal };
Expand Down
21 changes: 21 additions & 0 deletions src/widgets/WalletModal/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FC } from "react";
import SvgProps from "../../components/Svg/types";

export type ConnectorId =
| "authereum"
| "fortmatic"
| "frame"
| "injected"
| "portis"
| "squarelink"
| "torus"
| "walletconnect"
| "walletlink";

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

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

0 comments on commit 2fc1a86

Please sign in to comment.