Skip to content

Commit

Permalink
feat(IBAN and BIC validation)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed May 25, 2018
1 parent 1cfaecd commit f1c6c80
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
},
"dependencies": {}
"dependencies": {
"ibantools": "^2.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormattedMessage } from 'react-intl'
import { Icon, Text } from 'blockchain-info-components'
import { SelectBoxCoinifyCurrency, TextBoxDebounced } from 'components/Form'
import { Field, reduxForm } from 'redux-form'
import { has, head, prop } from 'ramda'
import { head } from 'ramda'
import { getReasonExplanation } from 'services/CoinifyService'

const Wrapper = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl'
import styled from 'styled-components'
import { Button, Link, Text } from 'blockchain-info-components'

import { required } from 'services/FormHelper'
import { required, validIban, validBIC } from 'services/FormHelper'
import { flex, spacing } from 'services/StyleService'
import { StepTransition } from 'components/Utilities/Stepper'
import { Form, ColLeft, InputWrapper, PartnerHeader, PartnerSubHeader, ColRight, ColRightInner } from 'components/BuySell/Signup'
Expand Down Expand Up @@ -37,11 +37,11 @@ const AddBankDetails = (props) => {
</PartnerSubHeader>
<Text weight={300} size='12px'>
<FormattedMessage id='coinifyexchangedata.addbankdetails.iban' defaultMessage='International Bank Account (IBAN)' />
<Field name='iban' validate={[required]} component={TextBox} />
<Field name='iban' validate={[required, validIban]} component={TextBox} />
</Text>
<Text weight={300} size='12px'>
<FormattedMessage id='coinifyexchangedata.addbankdetails.swift' defaultMessage='Bank Identifier Code (SWIFT/BIC)' />
<Field name='bic' validate={[required]} component={TextBox} />
<Field name='bic' validate={[required, validBIC]} component={TextBox} />
</Text>
</InputWrapper>
</BorderBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import styled from 'styled-components'
import { path } from 'ramda'

import { Remote } from 'blockchain-wallet-v4/src'
import * as service from 'services/CoinifyService'
import Stepper, { StepView } from 'components/Utilities/Stepper'
import OrderCheckout from '../OrderCheckout'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lift, prop } from 'ramda'
import { lift } from 'ramda'
import { formValueSelector } from 'redux-form'

import { selectors } from 'data'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bip39 from 'bip39'
import { isNumeric, isEmail, isDOB, isGuid, isUsZipcode, isIpList, isAlphaNumeric, formatSSN, formatDOB, formatUSZipcode, isOverEighteen, isSSN, formatPhone } from './../ValidationHelper'
import { isValidIBAN, isValidBIC } from 'ibantools'
import { isValidNumber } from 'libphonenumber-js'
import zxcvbn from 'zxcvbn'
import { utils } from 'blockchain-wallet-v4/src'
Expand Down Expand Up @@ -36,6 +37,10 @@ const validEmailCode = value => isAlphaNumeric(value) ? undefined : 'Invalid Ema

const validBitcoinPrivateKey = value => utils.bitcoin.isValidBitcoinPrivateKey(value) ? undefined : 'Invalid Bitcoin Private Key'

const validIban = value => isValidIBAN(value) ? undefined : 'Invalid IBAN'

const validBIC = value => isValidBIC(value) ? undefined : 'Invalid BIC'

const normalizeSocialSecurity = (val, prevVal) => formatSSN(val, prevVal)

const normalizeDateOfBirth = (val, prevVal) => formatDOB(val, prevVal)
Expand Down Expand Up @@ -73,6 +78,8 @@ export {
validBitcoinCashAddress,
validBitcoinPrivateKey,
validEtherAddress,
validIban,
validBIC,
normalizeSocialSecurity,
normalizeDateOfBirth,
normalizeUSZipcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ describe('FormHelper', () => {
})
})

describe('validIban()', () => {
it('returns correct string if invalid iban passed', () => {
expect(FormHelper.validIban('this is not a valid iban')).toEqual('Invalid IBAN')
})

it('returns undefined if valid iban is given', () => {
expect(FormHelper.validIban('GB04BARC20474473160944')).toBeUndefined()
})
})

describe('validBIC()', () => {
it('returns correct string if invalid BIC passed', () => {
expect(FormHelper.validBIC('this is not a valid BIC')).toEqual('Invalid BIC')
})

it('returns undefined if valid BIC is given', () => {
expect(FormHelper.validBIC('GB04BARC20474473160944')).toBeUndefined()
})
})

describe('ageOverEighteen()', () => {
it('returns correct string if age is not over 18', () => {
expect(FormHelper.ageOverEighteen(Date.now() - 400000)).toEqual('Must be 18 or older')
Expand Down

0 comments on commit f1c6c80

Please sign in to comment.