diff --git a/flow-typed/CoinSwap.js b/flow-typed/CoinSwap.js index c8311d83f..06bca44d0 100644 --- a/flow-typed/CoinSwap.js +++ b/flow-typed/CoinSwap.js @@ -1,10 +1,27 @@ +declare type CoinSwapInfo = { + coin: string, + sendAddress: string, + sendAmount: number, + lbcAmount: number, +} + declare type CoinSwapState = { - btcAddresses: Array + coinSwaps: Array }; declare type CoinSwapAction = { type: string, data: { - btcAddress: string, + coin: string, + sendAddress: string, + sendAmount: number, + lbcAmount: number, + }, +}; + +declare type CoinSwapRemoveAction = { + type: string, + data: { + sendAddress: string, }, }; diff --git a/ui/component/walletSwap/index.js b/ui/component/walletSwap/index.js index 111db9e54..02c16935f 100644 --- a/ui/component/walletSwap/index.js +++ b/ui/component/walletSwap/index.js @@ -2,20 +2,20 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router'; import WalletSwap from './view'; import { doOpenModal } from 'redux/actions/app'; -import { doAddBtcAddress } from 'redux/actions/coinSwap'; +import { doAddCoinSwap } from 'redux/actions/coinSwap'; import { doToast } from 'redux/actions/notifications'; -import { selectBtcAddresses } from 'redux/selectors/coinSwap'; +import { selectCoinSwaps } from 'redux/selectors/coinSwap'; import { selectReceiveAddress, doGetNewAddress, doCheckAddressIsMine } from 'lbry-redux'; const select = (state, props) => ({ receiveAddress: selectReceiveAddress(state), - btcAddresses: selectBtcAddresses(state), + coinSwaps: selectCoinSwaps(state), }); const perform = (dispatch) => ({ openModal: (modal, props) => dispatch(doOpenModal(modal, props)), doToast: (options) => dispatch(doToast(options)), - doAddBtcAddress: (address) => dispatch(doAddBtcAddress(address)), + addCoinSwap: (coinSwap) => dispatch(doAddCoinSwap(coinSwap)), getNewAddress: () => dispatch(doGetNewAddress()), checkAddressIsMine: (address) => dispatch(doCheckAddressIsMine(address)), }); diff --git a/ui/component/walletSwap/view.jsx b/ui/component/walletSwap/view.jsx index ed55ac603..4f5bae81e 100644 --- a/ui/component/walletSwap/view.jsx +++ b/ui/component/walletSwap/view.jsx @@ -47,24 +47,16 @@ const NAG_RATE_CALL_FAILED = 'Unable to obtain exchange rate. Try again later.'; type Props = { receiveAddress: string, - btcAddresses: Array, + coinSwaps: Array, doToast: ({ message: string }) => void, - doAddBtcAddress: (string) => void, + addCoinSwap: (CoinSwapInfo) => void, getNewAddress: () => void, checkAddressIsMine: (string) => void, openModal: (string, {}) => void, }; function WalletSwap(props: Props) { - const { - receiveAddress, - doToast, - btcAddresses, - doAddBtcAddress, - getNewAddress, - checkAddressIsMine, - openModal, - } = props; + const { receiveAddress, doToast, coinSwaps, addCoinSwap, getNewAddress, checkAddressIsMine, openModal } = props; const [btc, setBtc] = usePersistedState('swap-btc-amount', 0.001); const [btcError, setBtcError] = React.useState(); @@ -92,9 +84,9 @@ function WalletSwap(props: Props) { setBtcAddress(null); } - function removeBtcAddress(btcAddress) { + function removeCoinSwap(sendAddress) { openModal(MODALS.CONFIRM_REMOVE_BTC_SWAP_ADDRESS, { - btcAddress: btcAddress, + sendAddress: sendAddress, }); } @@ -236,7 +228,12 @@ function WalletSwap(props: Props) { }) .then((result) => { setBtcAddress(result); - doAddBtcAddress(result); + addCoinSwap({ + coin: 'btc', + sendAddress: result, + sendAmount: btc, + lbcAmount: lbc, + }); }) .catch((err) => { setNag({ msg: err === INTERNAL_APIS_DOWN ? NAG_SWAP_CALL_FAILED : err.message, type: 'error' }); @@ -259,8 +256,8 @@ function WalletSwap(props: Props) { setNag(null); setIsRefreshingStatus(true); - btcAddresses.forEach((x) => { - queryStatus(x, null, null); + coinSwaps.forEach((x) => { + queryStatus(x.sendAddress, null, null); }); } @@ -357,9 +354,7 @@ function WalletSwap(props: Props) { disabled={isSwapping || isNaN(btc) || btc === 0 || lbc === 0 || btcError} label={isSwapping ? __('Processing...') : __('Start Swap')} /> - {btcAddresses.length !== 0 && ( -