Skip to content

Commit

Permalink
feat(Blockstack): a bit of refactoring and handle registration after …
Browse files Browse the repository at this point in the history
…tier 2 completion
  • Loading branch information
Philip London committed Oct 29, 2019
1 parent 9b913d5 commit b0b2909
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 65 deletions.
Expand Up @@ -4890,7 +4890,7 @@
"id": "modals.sunriverlinkerror.continue"
}
],
"path": "src/modals/Exchange/SunRiverLinkError/index.json"
"path": "src/modals/Exchange/AirdropError/index.json"
},
{
"descriptors": [
Expand Down
Expand Up @@ -31,6 +31,7 @@ class SiftScience extends Component {
return null
}
}
this.props.onDone()
window.addEventListener('message', receiveMessage, false)
}

Expand Down
Expand Up @@ -4,7 +4,7 @@ import { TIERS } from '../../modules/profile/model'

export const KYC_MODAL = '@KYC.IdentityVerification'
export const USER_EXISTS_MODAL = '@KYC.UserExists'
export const SUNRIVER_LINK_ERROR_MODAL = '@KYC.SunRiverLinkError'
export const AIRDROP_ERROR_MODAL = '@KYC.AirdropError'

export const STEPS = {
coinify: 'coinify',
Expand Down
Expand Up @@ -19,7 +19,7 @@ import {
UPDATE_FAILURE,
KYC_MODAL,
FLOW_TYPES,
SUNRIVER_LINK_ERROR_MODAL
AIRDROP_ERROR_MODAL
} from './model'
import { computeSteps } from './services'
import { getStateNameFromAbbreviation } from 'services/LocalesService'
Expand Down Expand Up @@ -61,11 +61,7 @@ export default ({ api, coreSagas }) => {
newUser
)
} catch (error) {
// Todo: use generic confirm modal
// Should NOT be specific to sunriver
yield put(
actions.modals.showModal(SUNRIVER_LINK_ERROR_MODAL, { error })
)
yield put(actions.modals.showModal(AIRDROP_ERROR_MODAL, { error }))
yield put(actions.modules.profile.setCampaign({}))
throw new Error(invalidLinkError)
}
Expand Down Expand Up @@ -103,6 +99,12 @@ export default ({ api, coreSagas }) => {
// Buffer for tagging user
yield delay(3000)
yield put(actions.modules.profile.fetchUser())
const tags = (yield select(selectors.modules.profile.getTags)).getOrElse({
[campaign]: false
})
const isCampaignTagged = prop(campaign, tags)
// Something went wrong with tagging the campaign
if (!isCampaignTagged) return
yield take(actionTypes.modules.profile.FETCH_USER_DATA_SUCCESS)
yield put(actions.form.stopSubmit(ID_VERIFICATION_SUBMITTED_FORM))
yield put(actions.modals.closeAllModals())
Expand Down
Expand Up @@ -9,12 +9,8 @@ import { Remote } from 'blockchain-wallet-v4/src'
import { actions, model, selectors } from 'data'
import * as A from './actions'
import * as S from './selectors'
import { EMAIL_STEPS, SUNRIVER_LINK_ERROR_MODAL } from './model'
import sagas, {
logLocation,
noCampaignDataError,
invalidLinkError
} from './sagas'
import { EMAIL_STEPS } from './model'
import sagas, { logLocation, noCampaignDataError } from './sagas'

const api = {
fetchKycConfig: jest.fn(),
Expand Down Expand Up @@ -227,29 +223,4 @@ describe('registerUserCampaign', () => {
.next()
.isDone()
})
it('should show error modal and log error if registering fails', () => {
const saga = testSaga(registerUserCampaign, { newUser })
const error = new Error()
saga
.next()
.select(selectors.modules.profile.getCampaign)
.next(campaign)
.call(getCampaignData, campaign)
.next(campaignData)
.call(api.registerUserCampaign, campaign.name, campaignData, newUser)
.throw(error)
.put(actions.modals.showModal(SUNRIVER_LINK_ERROR_MODAL, { error }))
.next()
.put(actions.modules.profile.setCampaign({}))
.next()
.put(
actions.logs.logErrorMessage(
logLocation,
'registerUserCampaign',
invalidLinkError
)
)
.next()
.isDone()
})
})
Expand Up @@ -8,6 +8,7 @@ export const logLocation = 'components/onboarding/sagas'

export default () => {
const airdropClaimSubmitClicked = function * ({ payload }) {
// TODO: REFACTOR TO USE claimCampaignClicked
const { campaign } = payload
try {
yield put(actions.form.startSubmit('airdropClaim'))
Expand Down
20 changes: 12 additions & 8 deletions packages/blockchain-wallet-v4-frontend/src/data/goals/sagas.js
Expand Up @@ -436,17 +436,21 @@ export default ({ api }) => {
selectors.modules.profile.getBlockstackTag
)).getOrElse(false)
if (!blockstackTag && current === TIERS[2]) {
const password = null
yield put(actions.core.data.stx.generateAddress(password))
const { payload } = yield take(actions.core.data.stx.setAddress)
const { address } = payload
yield call(api.registerUserCampaign, 'BLOCKSTACK', {
'x-campaign-address': address
})
const campaign = (yield select(
selectors.core.walletOptions.getStxCampaign
)).getOrElse('BLOCKSTACK')
yield put(actions.modules.profile.setCampaign({ name: campaign }))
yield put(
actions.components.identityVerification.registerUserCampaign()
)
}
} catch (e) {
yield put(
actions.logs.logErrorMessage(logLocation, 'runPaymentProtocolGoal', e)
actions.logs.logErrorMessage(
logLocation,
'runRegisterForBlockstackAirdropGoal',
e
)
)
}
}
Expand Down
Expand Up @@ -49,6 +49,16 @@ export default ({ api, coreSagas, networks }) => {
'x-campaign-email': campaign.email
}
}
if (campaign.name === 'BLOCKSTACK') {
// 2nd pw check
const password = null
yield put(actions.core.data.stx.generateAddress(password))
const { payload } = yield take(actions.core.data.stx.setAddress)
const { address } = payload
return {
'x-campaign-address': address
}
}

return null
}
Expand Down
Expand Up @@ -36,6 +36,10 @@ export const getUserKYCState = compose(
lift(prop('kycState')),
getUserData
)
export const getTags = compose(
lift(path(['tags'])),
getUserData
)
export const getSunRiverTag = compose(
lift(path(['tags', 'SUNRIVER'])),
getUserData
Expand Down
Expand Up @@ -29,7 +29,7 @@ const Header = styled(ModalHeader)`
`

const {
SUNRIVER_LINK_ERROR_MODAL,
AIRDROP_ERROR_MODAL,
ERROR_TYPES
} = model.components.identityVerification

Expand Down Expand Up @@ -66,7 +66,7 @@ const getErrorMessage = ({ code }) => {
}
}

export const SunRiverLinkError = ({ position, total, error, closeAll }) => {
export const AirdropError = ({ position, total, error, closeAll }) => {
return (
<Modal size='medium' position={position} total={total}>
<Header onClose={closeAll}>
Expand All @@ -92,4 +92,4 @@ export const SunRiverLinkError = ({ position, total, error, closeAll }) => {
)
}

export default modalEnhancer(SUNRIVER_LINK_ERROR_MODAL)(SunRiverLinkError)
export default modalEnhancer(AIRDROP_ERROR_MODAL)(AirdropError)
Expand Up @@ -272,7 +272,7 @@ class Submitted extends React.PureComponent {
}

Submitted.defaultProps = {
campaign: 'sunriver'
campaign: 'BLOCKSTACK'
}

const mapStateToProps = state => ({
Expand Down
Expand Up @@ -4,7 +4,7 @@ import ExchangeResults from './ExchangeResults'
import KycDocResubmit from './KycDocResubmit'
import IdentityVerification from './IdentityVerification'
import ShapeshiftTradeDetails from './ShapeshiftTradeDetails'
import SunRiverLinkError from './SunRiverLinkError'
import AirdropError from './AirdropError'
import SwapUpgrade from './SwapUpgrade'
import UserExists from './UserExists'

Expand All @@ -15,7 +15,7 @@ export {
KycDocResubmit,
IdentityVerification,
ShapeshiftTradeDetails,
SunRiverLinkError,
AirdropError,
SwapUpgrade,
UserExists
}
@@ -1,12 +1,11 @@
import React from 'react'
import styled from 'styled-components'
import { prop } from 'ramda'
import { compose, bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { FormattedMessage } from 'react-intl'
import CopyToClipBoard from 'react-copy-to-clipboard'

import { actions, model } from 'data'
import { actions } from 'data'
import modalEnhancer from 'providers/ModalEnhancer'

import {
Expand All @@ -20,8 +19,6 @@ import {
TooltipHost
} from 'blockchain-info-components'

const { CAMPAIGNS } = model.components.identityVerification

const AirdropSuccessModalHeader = styled(ModalHeader)`
position: absolute;
border: 0;
Expand Down Expand Up @@ -80,7 +77,7 @@ class AirdropSuccess extends React.PureComponent {

render () {
const { isLinkCopied } = this.state
const { campaign, close, position, total } = this.props
const { close, position, total } = this.props
const link = 'https://www.blockchain.com/getcrypto'
const tweetLink =
'https://twitter.com/intent/tweet?text=' +
Expand All @@ -100,7 +97,6 @@ class AirdropSuccess extends React.PureComponent {
<FormattedMessage
id='modals.airdropsuccess.airdropprogram'
defaultMessage='Enrolled in Airdrop Program!'
values={{ coinCode: prop('coinCode', CAMPAIGNS[campaign]) }}
/>
</Text>
<Copy weight={400}>
Expand Down Expand Up @@ -160,10 +156,6 @@ class AirdropSuccess extends React.PureComponent {
}
}

AirdropSuccess.defaultProps = {
campaign: 'sunriver'
}

const mapDispatchToProps = dispatch => ({
actions: bindActionCreators(actions.components.onboarding, dispatch)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain-wallet-v4-frontend/src/modals/index.js
Expand Up @@ -34,7 +34,7 @@ import {
KycDocResubmit,
IdentityVerification,
ShapeshiftTradeDetails,
SunRiverLinkError,
AirdropError,
SwapUpgrade,
UserExists
} from './Exchange'
Expand Down Expand Up @@ -138,7 +138,7 @@ const Modals = () => (
<SfoxExchangeData />
<SfoxTradeDetails />
<SfoxEnterMicroDeposits />
<SunRiverLinkError />
<AirdropError />
<Support />
<SwapGetStarted />
<SwapUpgrade />
Expand Down

0 comments on commit b0b2909

Please sign in to comment.