Skip to content

Commit

Permalink
feat: close modal on esc, closes #192
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jul 28, 2020
1 parent c80547d commit 550a1a5
Show file tree
Hide file tree
Showing 6 changed files with 698 additions and 33 deletions.
10 changes: 5 additions & 5 deletions app/modals/receive-stx/receive-stx-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, { FC } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useDispatch } from 'react-redux';
import { useHotkeys } from 'react-hotkeys-hook';
import Qr from 'qrcode.react';
import { Text, Modal, Button, Flex, Box, useClipboard } from '@blockstack/ui';

import { TxModalHeader, TxModalFooter } from '../transaction/transaction-modal-layout';
import { homeActions, selectReceiveModalOpen } from '../../store/home/home.reducer';
import { homeActions } from '../../store/home/home.reducer';

interface ReceiveStxModalProps {
address: string;
}

export const ReceiveStxModal: FC<ReceiveStxModalProps> = ({ address }) => {
const dispatch = useDispatch();
const modalOpen = useSelector(selectReceiveModalOpen);
useHotkeys('esc', () => void dispatch(homeActions.closeReceiveModal()));
const { hasCopied, onCopy } = useClipboard(address);
const closeModal = () => dispatch(homeActions.closeReceiveModal());
if (!modalOpen) return null;
return (
<Modal
minWidth="488px"
isOpen={modalOpen}
isOpen
headerComponent={<TxModalHeader onSelectClose={closeModal}>Receive STX</TxModalHeader>}
footerComponent={
<TxModalFooter>
Expand Down
1 change: 0 additions & 1 deletion app/modals/transaction/transaction-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const TxModalForm: FC<TxModalFormProps> = ({ balance, form }) => {
<Input
id="stxAddress"
name="recipient"
autoFocus
mt="base-tight"
placeholder="STX address"
onChange={form.handleChange}
Expand Down
4 changes: 3 additions & 1 deletion app/modals/transaction/transaction-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BN from 'bn.js';
import { BigNumber } from 'bignumber.js';
import { Modal, Text, Button } from '@blockstack/ui';
import { StacksTransaction } from '@blockstack/stacks-transactions';
import { useHotkeys } from 'react-hotkeys-hook';

import { RootState } from '../../store';
import { validateStacksAddress } from '../../utils/get-stx-transfer-direction';
Expand Down Expand Up @@ -42,6 +43,7 @@ type ModalComponents = () => {

export const TransactionModal: FC<TxModalProps> = ({ balance, address }) => {
const dispatch = useDispatch();
useHotkeys('esc', () => void dispatch(homeActions.closeTxModal()));
const [step, setStep] = useState(TxModalStep.DescribeTx);
const [fee, setFee] = useState(new BN(0));
const [amount, setAmount] = useState(new BigNumber(0));
Expand Down Expand Up @@ -172,7 +174,7 @@ export const TransactionModal: FC<TxModalProps> = ({ balance, address }) => {
const { header, body, footer } = txFormStepMap[step]();

return (
<Modal isOpen={txModalOpen} headerComponent={header} footerComponent={footer} {...modalStyle}>
<Modal isOpen headerComponent={header} footerComponent={footer} {...modalStyle}>
{body}
</Modal>
);
Expand Down
26 changes: 17 additions & 9 deletions app/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { getAddressDetails } from '../../store/address/address.actions';
import { selectAddressBalance } from '../../store/address/address.reducer';
import { selectTransactions } from '../../store/transaction/transaction.reducer';
import { selectPendingTransactions } from '../../store/pending-transaction/pending-transaction.reducer';
import { homeActions } from '../../store/home/home.reducer';
import {
homeActions,
selectTxModalOpen,
selectReceiveModalOpen,
} from '../../store/home/home.reducer';
import {
TransactionList,
StackingPromoCard,
Expand All @@ -32,12 +36,16 @@ import { HomeLayout } from './home-layout';

export const Home: FC = () => {
const dispatch = useDispatch();
const { address, balance, txs, pendingTxs } = useSelector((state: RootState) => ({
address: selectAddress(state),
txs: selectTransactions(state),
balance: selectAddressBalance(state),
pendingTxs: selectPendingTransactions(state),
}));
const { address, balance, txs, pendingTxs, txModalOpen, receiveModalOpen } = useSelector(
(state: RootState) => ({
address: selectAddress(state),
txs: selectTransactions(state),
balance: selectAddressBalance(state),
pendingTxs: selectPendingTransactions(state),
txModalOpen: selectTxModalOpen(state),
receiveModalOpen: selectReceiveModalOpen(state),
})
);

const checkIfPendingTxIsComplete = async (address: string) => {
const [error, txResponse] = await safeAwait(Api.getTxDetails(address));
Expand Down Expand Up @@ -96,8 +104,8 @@ export const Home: FC = () => {

return (
<>
<ReceiveStxModal address={address} />
<TransactionModal balance={balance || '0'} address={address} />
{receiveModalOpen && <ReceiveStxModal address={address} />}
{txModalOpen && <TransactionModal balance={balance || '0'} address={address} />}
<HomeLayout
transactionList={transactionList}
balanceCard={balanceCard}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
"react": "16.13.1",
"react-dom": "16.13.1",
"react-hot-loader": "4.12.21",
"react-hotkeys-hook": "2.2.1",
"react-redux": "7.2.0",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
Expand Down
Loading

0 comments on commit 550a1a5

Please sign in to comment.