Skip to content

Commit

Permalink
feat(simple buy): add linked cards to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Apr 27, 2020
1 parent 4a53492 commit 1f17a1b
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ type MessagesType = {
'scenes.settings.general.walletid.description': 'Wallet ID is your unique identifier. It is completely individual to you, and it is what you will use to log in and access your wallet. It is NOT a bitcoin address for sending or receiving.'
'scenes.settings.general.walletid.title': 'Wallet ID'
'scenes.settings.general.walletid.warning': 'Do not share your Wallet ID with others.'
'scenes.settings.linked_cards': 'Linked Cards'
'scenes.settings.manage_addresses.archive': 'Archive'
'scenes.settings.manage_addresses.edit_name': 'Edit Name'
'scenes.settings.manage_addresses.make_default': 'Make Default'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ModalNamesType =
| '@MODAL.SEND.ETH'
| '@MODAL.SEND.PAX'
| '@MODAL.SEND.XLM'
| 'PairingCode'
| 'RECOVERY_PHRASE_MODAL'
| 'ShowEthPrivateKey'
| 'ShowXlmPrivateKey'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MethodSelect extends PureComponent<Props> {
case 'CARD':
return 'Credit or Debit Card'
case 'USER_CARD':
return value.card.label
return value && value.card ? value.card.label : 'Credit or Debit Card'
}
}

Expand All @@ -105,7 +105,8 @@ class MethodSelect extends PureComponent<Props> {
)
case 'USER_CARD':
let cardType = CARD_TYPES.find(
card => card.type === value.card.type.toLowerCase()
card =>
card.type === (value.card ? value.card.type.toLowerCase() : '')
)
return (
<img
Expand All @@ -125,7 +126,7 @@ class MethodSelect extends PureComponent<Props> {
m => m.type === 'CARD'
)
const cardMethods = availableCards.map(card => ({
text: card.card.label,
text: card.card ? card.card.label : 'Credit or Debit Card',
value: {
...card,
type: 'USER_CARD',
Expand Down Expand Up @@ -173,7 +174,7 @@ class MethodSelect extends PureComponent<Props> {
})}
</Limit>
</Display>
{props.value.type === 'USER_CARD' && (
{props.value.type === 'USER_CARD' && props.value.state === 'ACTIVE' && (
<CardLimitsDisplay isItem={isItem}>
···· {props.value.card.number}
<Limit>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { FormattedMessage } from 'react-intl'
import React from 'react'

import { Button, Icon, Link } from 'blockchain-info-components'
import { FormattedMessage } from 'react-intl'
import {
SettingComponent,
SettingContainer,
SettingDescription,
SettingHeader,
SettingSummary
} from 'components/Setting'
import React from 'react'

const About = () => {
return (
Expand All @@ -29,7 +28,7 @@ const About = () => {
</SettingSummary>
<SettingComponent>
<Link href='https://www.blockchain.com/about' target='_blank'>
<Button nature='empty'>
<Button data-e2e='aboutLink' nature='empty'>
<Icon name='open-in-new-tab' size='20px' />
</Button>
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { actions } from 'data'
import { bindActionCreators, Dispatch } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import { getData } from './selectors'
import { RemoteDataType, SBCardType } from 'core/types'
import { RootState } from 'data/rootReducer'
import React, { PureComponent } from 'react'
import Success from './template.success'

class LinkedCards extends PureComponent<Props> {
componentDidMount () {
this.props.simpleBuyActions.fetchSBCards()
}

render () {
return this.props.data.cata({
Success: val => <Success {...val} />,
Loading: () => null,
Failure: () => null,
NotAsked: () => null
})
}
}

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
data: getData(state)
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})

const connector = connect(
mapStateToProps,
mapDispatchToProps
)

export type SuccessStateType = {
cards: Array<SBCardType>
}
type LinkStatePropsType = {
data: RemoteDataType<string, SuccessStateType>
}
type Props = ConnectedProps<typeof connector>

export default connector(LinkedCards)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { lift } from 'ramda'
import { RootState } from 'data/rootReducer'
import { selectors } from 'data'

export const getData = (state: RootState) => {
const cardsR = selectors.components.simpleBuy.getSBCards(state)

return lift(cards => ({ cards }))(cardsR)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Button } from 'blockchain-info-components'
import { FormattedMessage } from 'react-intl'
import {
SettingComponent,
SettingContainer,
SettingHeader,
SettingSummary
} from 'components/Setting'
import { SuccessStateType } from '.'
import React from 'react'

const Success: React.FC<Props> = props => {
return (
<SettingContainer>
<SettingSummary>
<SettingHeader>
<FormattedMessage
id='scenes.settings.linked_cards'
defaultMessage='Linked Cards'
/>
</SettingHeader>
{props.cards.map((card, i) => {
return (
<div key={i}>{card.state === 'ACTIVE' ? card.card.number : ''}</div>
)
})}
</SettingSummary>
<SettingComponent>
<Button nature='empty' data-e2e='addCardFromSettings'>
<FormattedMessage
id='scenes.lockbox.settings.adddevice.add'
defaultMessage='Add Device'
/>
</Button>
</SettingComponent>
</SettingContainer>
)
}

type Props = SuccessStateType

export default Success
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { FormattedMessage } from 'react-intl'
import React from 'react'
import styled from 'styled-components'

import { actions } from 'data'
import { Badge, Button, Text } from 'blockchain-info-components'
import { bindActionCreators } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import { FormattedMessage } from 'react-intl'
import {
SettingComponent,
SettingContainer,
SettingDescription,
SettingHeader,
SettingSummary
} from 'components/Setting'
import React from 'react'
import styled from 'styled-components'

const BadgesContainer = styled.div`
display: block;
Expand All @@ -23,7 +22,7 @@ const BadgesContainer = styled.div`
}
`

class PairingCode extends React.PureComponent {
class PairingCode extends React.PureComponent<Props> {
onShowCode = () => {
this.props.modalActions.showModal('PairingCode')
}
Expand All @@ -42,8 +41,8 @@ class PairingCode extends React.PureComponent {
<FormattedMessage
id='scenes.settings.general.pairingcode.description'
defaultMessage="Scan the code (click on 'Show Pairing Code') with your Blockchain Wallet (iOS or Android) for a seamless connection to your wallet."
altFont
light
// altFont
// light
/>
<FormattedMessage
id='scenes.settings.general.pairingcode.description2'
Expand All @@ -62,7 +61,11 @@ class PairingCode extends React.PureComponent {
</SettingDescription>
</SettingSummary>
<SettingComponent>
<Button nature='primary' onClick={this.onShowCode}>
<Button
data-e2e='showQrCode'
nature='primary'
onClick={this.onShowCode}
>
<FormattedMessage
id='scenes.settings.general.pairingcode.settings.show'
defaultMessage='Show Pairing Code'
Expand All @@ -78,7 +81,11 @@ const mapDispatchToProps = dispatch => ({
modalActions: bindActionCreators(actions.modals, dispatch)
})

export default connect(
const connector = connect(
null,
mapDispatchToProps
)(PairingCode)
)

type Props = ConnectedProps<typeof connector>

export default connector(PairingCode)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const PrivacyPolicy = () => {
</SettingSummary>
<SettingComponent>
<Link href='https://www.blockchain.com/legal/privacy' target='_blank'>
<Button nature='empty'>
<Button data-e2e='privacyLink' nature='empty'>
<Icon name='open-in-new-tab' size='20px' />
</Button>
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TermsOfService = () => {
</SettingSummary>
<SettingComponent>
<Link href='https://www.blockchain.com/legal/terms' target='_blank'>
<Button nature='empty'>
<Button data-e2e='termsLink' nature='empty'>
<Icon name='open-in-new-tab' size='20px' />
</Button>
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { connect } from 'react-redux'
import { connect, ConnectedProps } from 'react-redux'
import { FormattedMessage } from 'react-intl'
import React from 'react'

import { selectors } from 'data'
import {
SettingComponent,
Expand All @@ -11,8 +9,9 @@ import {
SettingSummary
} from 'components/Setting'
import { Text } from 'blockchain-info-components'
import React from 'react'

const WalletId = props => {
const WalletId = (props: Props) => {
return (
<SettingContainer>
<SettingSummary>
Expand Down Expand Up @@ -46,4 +45,8 @@ const mapStateToProps = state => ({
guid: selectors.core.wallet.getGuid(state)
})

export default connect(mapStateToProps)(WalletId)
const connector = connect(mapStateToProps)

type Props = ConnectedProps<typeof connector>

export default connector(WalletId)
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { FormattedMessage } from 'react-intl'
import React from 'react'
import styled from 'styled-components'

import { Banner, Text } from 'blockchain-info-components'

import { FormattedMessage } from 'react-intl'
import About from './About'
import LinkedCards from './LinkedCards'
import PairingCode from './PairingCode'
import PrivacyPolicy from './PrivacyPolicy'
import React from 'react'
import styled from 'styled-components'
import TermsOfService from './TermsOfService'
import WalletId from './WalletId'

const Wrapper = styled.section`
padding: 30px;
width: 100%;
box-sizing: border-box;
`
const Wrapper = styled.section``

const General = () => {
return (
Expand All @@ -34,6 +29,7 @@ const General = () => {
</Banner>
<WalletId />
<PairingCode />
<LinkedCards />
<PrivacyPolicy />
<TermsOfService />
<About />
Expand Down
21 changes: 12 additions & 9 deletions packages/blockchain-wallet-v4/src/network/api/simpleBuy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ export type SBCardType = {
addedAt: Date
address: NabuAddressType
attributes: {}
card: {
expireMonth: number
expireYear: number
label: string
number: string
type: 'VISA' | 'MASTERCARD'
}
currency: 'EUR'
id: string
partner: 'EVERYPAY'
state: SBCardStateType
}
} & (
| {
card: {
expireMonth: number
expireYear: number
label: string
number: string
type: 'VISA' | 'MASTERCARD'
}
state: 'ACTIVE'
}
| { card: null; state: Exclude<SBCardStateType, 'ACTIVE'> })

export type SBCardStateType =
| 'PENDING'
Expand Down

0 comments on commit 1f17a1b

Please sign in to comment.