Coin-swap: require authentication
While it would be nice if we can swap anonymously through Desktop, the IAPI will tie a wallet address with an account. Final decision is to require authentication.
This commit is contained in:
parent
d63cb0dc2d
commit
7c25de1e58
2 changed files with 20 additions and 1 deletions
|
@ -5,11 +5,13 @@ import { doOpenModal } from 'redux/actions/app';
|
||||||
import { doAddCoinSwap } from 'redux/actions/coinSwap';
|
import { doAddCoinSwap } from 'redux/actions/coinSwap';
|
||||||
import { doToast } from 'redux/actions/notifications';
|
import { doToast } from 'redux/actions/notifications';
|
||||||
import { selectCoinSwaps } from 'redux/selectors/coinSwap';
|
import { selectCoinSwaps } from 'redux/selectors/coinSwap';
|
||||||
|
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||||
import { selectReceiveAddress, doGetNewAddress, doCheckAddressIsMine } from 'lbry-redux';
|
import { selectReceiveAddress, doGetNewAddress, doCheckAddressIsMine } from 'lbry-redux';
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
receiveAddress: selectReceiveAddress(state),
|
receiveAddress: selectReceiveAddress(state),
|
||||||
coinSwaps: selectCoinSwaps(state),
|
coinSwaps: selectCoinSwaps(state),
|
||||||
|
isAuthenticated: selectUserVerifiedEmail(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
|
|
|
@ -12,8 +12,10 @@ import QRCode from 'component/common/qr-code';
|
||||||
import usePersistedState from 'effects/use-persisted-state';
|
import usePersistedState from 'effects/use-persisted-state';
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
import * as MODALS from 'constants/modal_types';
|
import * as MODALS from 'constants/modal_types';
|
||||||
|
import * as PAGES from 'constants/pages';
|
||||||
import { clipboard } from 'electron';
|
import { clipboard } from 'electron';
|
||||||
import I18nMessage from 'component/i18nMessage';
|
import I18nMessage from 'component/i18nMessage';
|
||||||
|
import { Redirect, useHistory } from 'react-router';
|
||||||
|
|
||||||
const BTC_SATOSHIS = 100000000;
|
const BTC_SATOSHIS = 100000000;
|
||||||
const BTC_MAX = 21000000;
|
const BTC_MAX = 21000000;
|
||||||
|
@ -48,6 +50,7 @@ const NAG_RATE_CALL_FAILED = 'Unable to obtain exchange rate. Try again later.';
|
||||||
type Props = {
|
type Props = {
|
||||||
receiveAddress: string,
|
receiveAddress: string,
|
||||||
coinSwaps: Array<CoinSwapInfo>,
|
coinSwaps: Array<CoinSwapInfo>,
|
||||||
|
isAuthenticated: boolean,
|
||||||
doToast: ({ message: string }) => void,
|
doToast: ({ message: string }) => void,
|
||||||
addCoinSwap: (CoinSwapInfo) => void,
|
addCoinSwap: (CoinSwapInfo) => void,
|
||||||
getNewAddress: () => void,
|
getNewAddress: () => void,
|
||||||
|
@ -56,7 +59,16 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function WalletSwap(props: Props) {
|
function WalletSwap(props: Props) {
|
||||||
const { receiveAddress, doToast, coinSwaps, addCoinSwap, getNewAddress, checkAddressIsMine, openModal } = props;
|
const {
|
||||||
|
receiveAddress,
|
||||||
|
doToast,
|
||||||
|
coinSwaps,
|
||||||
|
isAuthenticated,
|
||||||
|
addCoinSwap,
|
||||||
|
getNewAddress,
|
||||||
|
checkAddressIsMine,
|
||||||
|
openModal,
|
||||||
|
} = props;
|
||||||
|
|
||||||
const [btc, setBtc] = usePersistedState('swap-btc-amount', 0.001);
|
const [btc, setBtc] = usePersistedState('swap-btc-amount', 0.001);
|
||||||
const [btcError, setBtcError] = React.useState();
|
const [btcError, setBtcError] = React.useState();
|
||||||
|
@ -69,6 +81,7 @@ function WalletSwap(props: Props) {
|
||||||
const [isSwapping, setIsSwapping] = React.useState(false);
|
const [isSwapping, setIsSwapping] = React.useState(false);
|
||||||
const [statusMap, setStatusMap] = React.useState({});
|
const [statusMap, setStatusMap] = React.useState({});
|
||||||
const [isRefreshingStatus, setIsRefreshingStatus] = React.useState(false);
|
const [isRefreshingStatus, setIsRefreshingStatus] = React.useState(false);
|
||||||
|
const { location } = useHistory();
|
||||||
|
|
||||||
const status = btcAddress ? statusMap[btcAddress] : null;
|
const status = btcAddress ? statusMap[btcAddress] : null;
|
||||||
const btcTxId = status && status.receipt_txid ? status.receipt_txid : null;
|
const btcTxId = status && status.receipt_txid ? status.receipt_txid : null;
|
||||||
|
@ -469,6 +482,10 @@ function WalletSwap(props: Props) {
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
return <Redirect to={`/$/${PAGES.AUTH_SIGNIN}?redirect=${location.pathname}`} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleStartSwap}>
|
<Form onSubmit={handleStartSwap}>
|
||||||
<Card
|
<Card
|
||||||
|
|
Loading…
Reference in a new issue