diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/brokerage/types.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/brokerage/types.ts index f806eb73fa8..c620e436999 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/brokerage/types.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/brokerage/types.ts @@ -150,6 +150,7 @@ export type BankDetails = { bankAccountType: string bankName: string routingNumber: string + sortCode?: string } interface BankTransferAccountAttrs { diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/Authorize.success.tsx similarity index 69% rename from packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/template.success.tsx rename to packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/Authorize.success.tsx index ec007b41efa..732494bf3a1 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/template.success.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/Authorize.success.tsx @@ -1,105 +1,45 @@ -import React, { useState } from 'react' +import React from 'react' import { FormattedMessage } from 'react-intl' -import { defaultTo, filter, path } from 'ramda' -import styled from 'styled-components' +import { useDispatch } from 'react-redux' import { fiatToString } from '@core/exchange/utils' import { FiatType } from '@core/types' -import { Button, Icon, Image, Text } from 'blockchain-info-components' +import { Button, Image, Text } from 'blockchain-info-components' import { FlyoutWrapper, Row, Title, Value } from 'components/Flyout' +import { buySell } from 'data/components/actions' import { getFiatFromPair } from 'data/components/buySell/model' -import { BankTransferAccountType } from 'data/types' +import { BankTransferAccountType, BuyQuoteStateType } from 'data/types' -import { Props as _P, SuccessStateType } from '.' +import { DropdownItem } from './DropDownItem' +import { BackContainer, Bottom, InfoText, InfoTitle, Wrapper } from './styles' -const Wrapper = styled.div` - display: flex; - flex-direction: column; - height: 100%; -` -const BackContainer = styled(Text)` - display: flex; - align-items: center; - width: 100%; - font-weight: 600; - font-size: 20px; -` -const DropdownTitleRow = styled.div<{ isPaymentInformation?: boolean }>` - display: flex; - justify-content: space-between; - align-items: center; - cursor: pointer; - padding: ${(props) => (props.isPaymentInformation ? '0 40px' : 'auto')}; - /* chevorn icon rotation */ - > span:last-child { - size: 10px; - transition: transform 0.2s; - color: ${(props) => props.theme.grey600}; - &.active { - transform: rotate(180deg); - } - } -` -const InfoTitle = styled(Title)` - font-weight: 600; - line-height: 1.5; - color: ${(props) => props.theme.grey900}; -` +type Props = { + bankAccounts: BankTransferAccountType[] + handleClose: () => void + quote: BuyQuoteStateType +} -const InfoDropdown = styled.div` - max-height: 0; - margin-top: 0; - overflow: hidden; - transition: max-height, margin-top 0.3s; - &.isToggled { - max-height: 100%; - margin-top: 12px; - } -` -const InfoText = styled(Title)` - font-size: 14px; - font-weight: 500; - color: ${(props) => props.theme.grey600}; - line-height: 1.5; -` -const Bottom = styled(FlyoutWrapper)` - display: flex; - flex-direction: column; - justify-content: flex-end; - height: 100%; -` -const DropdownRow = styled(Row)<{ isPaymentInformation?: boolean }>` - padding: ${(props) => (props.isPaymentInformation ? '16px 0' : 'auto')}; -` +const Success = ({ bankAccounts, handleClose, quote }: Props) => { + const dispatch = useDispatch() -const DropdownItem = ({ bodyText, isPaymentInformation, titleText }) => { - const [isToggled, handleToggle] = useState(false) - return ( - - handleToggle(!isToggled)} - > - {titleText} - - - - {bodyText} - - - ) -} + const counterAmount = quote.amount + const counterCurrency = getFiatFromPair(quote.pairObject.pair) + const bankAccount = bankAccounts.find( + (bank) => bank.state === 'ACTIVE' && bank.id === quote.paymentMethodId + )! -const Success = (props: Props) => { - const { bankAccounts, buySellActions, quote } = props - const counterAmount = props.quote.amount - const counterCurrency = getFiatFromPair(props.quote.pair) - const [bankAccount] = filter( - (b: BankTransferAccountType) => b.state === 'ACTIVE' && b.id === quote.paymentMethodId, - defaultTo([])(bankAccounts) - ) - const entity = path(['attributes', 'entity'], bankAccount) - const entityName = entity === 'Safeconnect(UK)' ? 'SafeConnect' : 'SafeConnect (UAB)' + const { attributes, details } = bankAccount ?? {} + + const entityName = attributes?.entity === 'Safeconnect(UK)' ? 'SafeConnect' : 'SafeConnect (UAB)' + + const onApprove = () => { + dispatch( + buySell.confirmOrder({ + paymentMethodId: bankAccount.id, + quoteState: quote + }) + ) + } return ( @@ -147,7 +87,7 @@ const Success = (props: Props) => { defaultMessage='Payer Name' /> - {path(['details', 'accountName'], bankAccount)} + {details?.accountName} @@ -156,7 +96,7 @@ const Success = (props: Props) => { defaultMessage='Sort Code' /> - {path(['details', 'sortCode'], bankAccount)} + {details?.sortCode} @@ -165,7 +105,7 @@ const Success = (props: Props) => { defaultMessage='Account Number' /> - {path(['details', 'accountNumber'], bankAccount)} + {details?.accountNumber} @@ -183,7 +123,7 @@ const Success = (props: Props) => { defaultMessage='Bank Name' /> - {path(['details', 'bankName'], bankAccount)} + {details?.bankName} } @@ -299,17 +239,13 @@ const Success = (props: Props) => { @@ -321,7 +257,7 @@ const Success = (props: Props) => { height='48px' color='red400' style={{ marginTop: '16px' }} - onClick={() => props.handleClose()} + onClick={handleClose} > @@ -330,6 +266,4 @@ const Success = (props: Props) => { ) } -export type Props = Omit<_P, 'data'> & SuccessStateType - export default Success diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/DropDownItem.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/DropDownItem.tsx new file mode 100644 index 00000000000..c1e1541b01c --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/DropDownItem.tsx @@ -0,0 +1,23 @@ +import React, { useState } from 'react' + +import { Icon } from 'blockchain-info-components' + +import { DropdownRow, DropdownTitleRow, InfoDropdown, InfoText, InfoTitle } from './styles' + +export const DropdownItem = ({ bodyText, isPaymentInformation, titleText }) => { + const [isToggled, handleToggle] = useState(false) + return ( + + handleToggle(!isToggled)} + > + {titleText} + + + + {bodyText} + + + ) +} diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/index.tsx index 6870d33d8a1..26181eb69bf 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/index.tsx @@ -1,44 +1,20 @@ import React from 'react' -import { connect, ConnectedProps } from 'react-redux' -import { bindActionCreators, Dispatch } from 'redux' +import { useSelector } from 'react-redux' -import { ExtractSuccess } from '@core/types' import DataError from 'components/DataError' -import { actions, selectors } from 'data' -import { RootState } from 'data/rootReducer' -import { BankTransferAccountType } from 'data/types' +import { getBankTransferAccounts } from 'data/components/brokerage/selectors' +import { getBuyQuote } from 'data/components/buySell/selectors' +import { useRemote } from 'hooks' -import { getData } from './selectors' -import Success from './template.success' +import Success from './Authorize.success' -const Authorize = ({ data, ...props }: Props) => { - return data.cata({ - Failure: (e) => , - Loading: () => <>, - NotAsked: () => <>, - Success: (val) => - }) -} - -const mapStateToProps = (state: RootState) => ({ - bankAccounts: selectors.components.brokerage - .getBankTransferAccounts(state) - .getOrElse([] as Array), - data: getData(state) -}) - -const mapDispatchToProps = (dispatch: Dispatch) => ({ - buySellActions: bindActionCreators(actions.components.buySell, dispatch) -}) +const Authorize = ({ handleClose }: { handleClose: () => void }) => { + const { data, error, isLoading, isNotAsked } = useRemote(getBuyQuote) + const bankAccounts = useSelector(getBankTransferAccounts).getOrElse([]) -const connector = connect(mapStateToProps, mapDispatchToProps) - -type OwnProps = { - handleClose: () => void + if (error) return + if (isLoading || isNotAsked || !data) return null + return } -export type SuccessStateType = ExtractSuccess> - -export type Props = OwnProps & ConnectedProps - -export default connector(Authorize) +export default Authorize diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/selectors.ts deleted file mode 100644 index 134743f1861..00000000000 --- a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/selectors.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { lift } from 'ramda' - -import { ExtractSuccess } from '@core/types' -import { selectors } from 'data' -import { RootState } from 'data/rootReducer' - -export const getData = (state: RootState) => { - const quoteR = selectors.components.buySell.getBuyQuote(state) - - return lift((quote: ExtractSuccess) => ({ - quote - }))(quoteR) -} diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/styles.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/styles.tsx new file mode 100644 index 00000000000..bec40236e00 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/Authorize/styles.tsx @@ -0,0 +1,64 @@ +import styled from 'styled-components' + +import { Text } from 'blockchain-info-components' +import { FlyoutWrapper, Row, Title } from 'components/Flyout' + +export const Wrapper = styled.div` + display: flex; + flex-direction: column; + height: 100%; +` +export const BackContainer = styled(Text)` + display: flex; + align-items: center; + width: 100%; + font-weight: 600; + font-size: 20px; +` +export const DropdownTitleRow = styled.div<{ isPaymentInformation?: boolean }>` + display: flex; + justify-content: space-between; + align-items: center; + cursor: pointer; + padding: ${(props) => (props.isPaymentInformation ? '0 40px' : 'auto')}; + /* chevorn icon rotation */ + > span:last-child { + size: 10px; + transition: transform 0.2s; + color: ${(props) => props.theme.grey600}; + &.active { + transform: rotate(180deg); + } + } +` +export const InfoTitle = styled(Title)` + font-weight: 600; + line-height: 1.5; + color: ${(props) => props.theme.grey900}; +` + +export const InfoDropdown = styled.div` + max-height: 0; + margin-top: 0; + overflow: hidden; + transition: max-height, margin-top 0.3s; + &.isToggled { + max-height: 100%; + margin-top: 12px; + } +` +export const InfoText = styled(Title)` + font-size: 14px; + font-weight: 500; + color: ${(props) => props.theme.grey600}; + line-height: 1.5; +` +export const Bottom = styled(FlyoutWrapper)` + display: flex; + flex-direction: column; + justify-content: flex-end; + height: 100%; +` +export const DropdownRow = styled(Row)<{ isPaymentInformation?: boolean }>` + padding: ${(props) => (props.isPaymentInformation ? '16px 0' : 'auto')}; +` diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/index.tsx index 6a71bdc81e4..b9830113eb5 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/BuySell/index.tsx @@ -234,7 +234,7 @@ class BuySell extends PureComponent { )} {this.props.step === 'AUTHORIZE_PAYMENT' && ( - + )} {this.props.step === 'CHECKOUT_CONFIRM' && (