Skip to content

Commit

Permalink
feat(data-science): require modal origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed May 4, 2020
1 parent 4786784 commit 5792bf1
Show file tree
Hide file tree
Showing 36 changed files with 191 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ export const TierCard = ({
className='actionButton'
fullwidth
nature='primary'
onClick={() => identityVerificationActions.verifyIdentity(tier)}
onClick={() =>
identityVerificationActions.verifyIdentity(
tier,
false,
'SettingsProfile'
)
}
data-e2e={`continueKycTier${tier}Btn`}
>
{tierStarted ? (
Expand Down Expand Up @@ -232,7 +238,7 @@ export const TierCard = ({
jumbo
fullwidth
nature='primary'
onClick={() => simpleBuyActions.showModal('settingsProfile')}
onClick={() => simpleBuyActions.showModal('SettingsProfile')}
data-e2e='buyNowBtn'
>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ type Props = LinkStatePropsType & LinkDispatchPropsType
class ExchangePromo extends PureComponent<Props> {
onSignup = () => {
this.props.modalActions.closeAllModals()
this.props.modalActions.showModal('LinkToExchangeAccount')
this.props.modalActions.showModal('LinkToExchangeAccount', {
origin: 'SendExchangePromo'
})
this.props.analyticsActions.logEvent([
...EXCHANGE_EVENTS.PROMO,
'connect_modal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const BackupLink = styled.span`

class MnemonicRequiredForCustodySend extends React.PureComponent<Props> {
handleClick = () => {
this.props.modalActions.showModal('RECOVERY_PHRASE_MODAL')
this.props.modalActions.showModal('RECOVERY_PHRASE_MODAL', {
origin: 'Send'
})
}
render () {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import {
IdentityVerificationActionTypes,
StepsType
} from './types'
import { ModalOriginType } from 'data/modals/types'
import { TIERS } from '../../modules/profile/model'

export const verifyIdentity = (
tier = TIERS[2],
needMoreInfo = false
needMoreInfo = false,
origin: ModalOriginType
): IdentityVerificationActionTypes => ({
type: AT.VERIFY_IDENTITY,
payload: { tier, needMoreInfo }
payload: { tier, needMoreInfo, origin }
})

export const initializeVerification = (tier, needMoreInfo) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export default ({ api, coreSagas, networks }) => {

const verifyIdentity = function * ({ payload }) {
const { tier, needMoreInfo } = payload
yield put(actions.modals.showModal(KYC_MODAL, { tier, needMoreInfo }))
yield put(
actions.modals.showModal(KYC_MODAL, {
tier,
needMoreInfo,
origin: 'Unknown'
})
)
}

const defineSteps = function * (tier, needMoreInfo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as AT from './actionTypes'
import { ModalOriginType } from 'data/modals/types'
import { RemoteDataType } from 'core/types'

export type EmailSmsStepType = 'edit' | 'verify'
Expand Down Expand Up @@ -207,6 +208,7 @@ interface SetVerificationStepAction {
interface VerifyIdentityAction {
payload: {
needMoreInfo?: boolean
origin: ModalOriginType
tier: number
}
type: typeof AT.VERIFY_IDENTITY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default ({
const bitPayInvoiceEntered = function * (bip21Payload) {
yield put(
actions.modals.showModal('Confirm', {
origin: 'SendBch',
title: CC.BITPAY_CONFIRM_TITLE,
message: CC.BITPAY_CONFIRM_MSG
})
Expand All @@ -143,7 +144,9 @@ export default ({

const bitpayInvoiceExpired = function * () {
yield put(actions.modals.closeAllModals())
yield put(actions.modals.showModal('BitPayInvoiceExpired'))
yield put(
actions.modals.showModal('BitPayInvoiceExpired', { origin: 'SendBch' })
)
yield put(
actions.analytics.logEvent([
...TRANSACTION_EVENTS.BITPAY_FAILURE,
Expand Down Expand Up @@ -193,7 +196,8 @@ export default ({
actions.modals.showModal(
`@MODAL.SEND.${modalName}` as ModalNamesType,
{
coin: payload
coin: payload,
origin: 'SendBch'
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default ({
const bitPayInvoiceEntered = function * (bip21Payload) {
yield put(
actions.modals.showModal('Confirm', {
origin: 'SendBtc',
title: CC.BITPAY_CONFIRM_TITLE,
message: CC.BITPAY_CONFIRM_MSG
})
Expand All @@ -169,7 +170,9 @@ export default ({

const bitpayInvoiceExpired = function * () {
yield put(actions.modals.closeAllModals())
yield put(actions.modals.showModal('BitPayInvoiceExpired'))
yield put(
actions.modals.showModal('BitPayInvoiceExpired', { origin: 'SendBtc' })
)
yield put(
actions.analytics.logEvent([
...TRANSACTION_EVENTS.BITPAY_FAILURE,
Expand Down Expand Up @@ -218,7 +221,8 @@ export default ({
actions.modals.showModal(
`@MODAL.SEND.${modalName}` as ModalNamesType,
{
coin: payload
coin: payload,
origin: 'SendBtc'
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export default ({
actions.modals.showModal(
`@MODAL.SEND.${modalName}` as ModalNamesType,
{
coin: payload
coin: payload,
origin: 'SendEth'
}
)
)
Expand Down Expand Up @@ -572,7 +573,9 @@ export default ({
return
}

yield put(actions.modals.showModal('@MODAL.SEND.ETH'))
yield put(
actions.modals.showModal('@MODAL.SEND.ETH', { origin: 'RetrySendEth' })
)
yield take(AT.SEND_ETH_PAYMENT_UPDATED_SUCCESS)
let p = yield select(S.getPayment)
let payment: EthPaymentType = coreSagas.payment.eth.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export default ({ api, coreSagas }: { api: APIType; coreSagas: any }) => {
actions.modals.showModal(
`@MODAL.SEND.${modalName}` as ModalNamesType,
{
coin: payload
coin: payload,
origin: 'SendXlm'
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
SBQuoteType,
SBSuggestedAmountType
} from 'core/types'
import { SBFormPaymentMethod, SimpleBuyActionTypes } from './types'
import {
SBFormPaymentMethod,
SBShowModalOriginType,
SimpleBuyActionTypes
} from './types'

export const activateSBCard = (card: SBCardType) => ({
type: AT.ACTIVATE_SB_CARD,
Expand Down Expand Up @@ -425,15 +429,7 @@ export const setStep = (
})

export const showModal = (
origin:
| 'coinifyToSB'
| 'emptyFeed'
| 'pendingOrder'
| 'priceChart'
| 'settingsGeneral'
| 'settingsProfile'
| 'sideNav'
| 'welcomeModal',
origin: SBShowModalOriginType,
cryptoCurrency?: CoinType
) => ({
type: AT.SHOW_MODAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export type SBCurrencySelectFormType = {
}
export type SBFormPaymentMethod =
| SBPaymentMethodType
| SBCardType & {
| (SBCardType & {
limits: SBPaymentMethodType['limits']
type: 'USER_CARD'
}
})
export enum SimpleBuyStepType {
'CURRENCY_SELECTION',
'ENTER_AMOUNT',
Expand All @@ -52,6 +52,15 @@ export enum SimpleBuyStepType {
'TRANSFER_DETAILS',
'CANCEL_ORDER'
}
export type SBShowModalOriginType =
| 'CoinifyToSB'
| 'EmptyFeed'
| 'PendingOrder'
| 'PriceChart'
| 'SettingsGeneral'
| 'SettingsProfile'
| 'SideNav'
| 'WelcomeModal'

// State
export type SimpleBuyState = {
Expand Down Expand Up @@ -302,13 +311,7 @@ interface SetStepAction {
interface ShowModalAction {
payload: {
cryptoCurrency?: CoinType
origin:
| 'sideNav'
| 'settingsProfile'
| 'pendingOrder'
| 'welcomeModal'
| 'priceChart'
| 'emptyFeed'
origin: SBShowModalOriginType
}
type: typeof AT.SHOW_MODAL
}
Expand Down
26 changes: 22 additions & 4 deletions packages/blockchain-wallet-v4-frontend/src/data/goals/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ export default ({ api, coreSagas, networks }) => {
const { instructions } = paymentRequest

if (new Date() > new Date(paymentRequest.expires)) {
return yield put(actions.modals.showModal('BitPayInvoiceExpired'))
return yield put(
actions.modals.showModal('BitPayInvoiceExpired', {
origin: 'PaymentProtocolGoal'
})
)
}

const tx = path([0, 'outputs', 0], instructions)
Expand Down Expand Up @@ -387,7 +391,13 @@ export default ({ api, coreSagas, networks }) => {
selectors.modules.profile.getUserTiers
)).getOrElse({ current: 0 }) || { current: 0 }
if (current >= Number(tier)) return
yield put(actions.components.identityVerification.verifyIdentity(tier))
yield put(
actions.components.identityVerification.verifyIdentity(
tier,
false,
'RunKycGoal'
)
)
} catch (err) {
yield put(
actions.logs.logErrorMessage(logLocation, 'runKycGoal', err.message)
Expand Down Expand Up @@ -589,7 +599,11 @@ export default ({ api, coreSagas, networks }) => {
)
}
if (kycDocResubmit) {
return yield put(actions.modals.showModal(kycDocResubmit.name))
return yield put(
actions.modals.showModal(kycDocResubmit.name, {
origin: 'KycDocResubmitGoal'
})
)
}
if (sunriver) {
// return yield put(actions.modals.showModal(sunriver.name, sunriver.data))
Expand Down Expand Up @@ -618,7 +632,11 @@ export default ({ api, coreSagas, networks }) => {
)
}
if (airdropClaim) {
return yield put(actions.modals.showModal(airdropClaim.name))
return yield put(
actions.modals.showModal(airdropClaim.name, {
origin: 'AirdropClaimGoal'
})
)
}
if (welcomeModal) {
yield put(actions.modals.showModal(welcomeModal.name, welcomeModal.data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ export const CLOSE_ALL_MODALS = 'CLOSE_ALL_MODALS'

export const SHOW_MODAL = 'SHOW_MODAL'

export const REPLACE_MODAL = 'REPLACE_MODAL'

export const UPDATE_MODAL = 'UPDATE_MODAL'
13 changes: 2 additions & 11 deletions packages/blockchain-wallet-v4-frontend/src/data/modals/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as AT from './actionTypes'
import { ModalActionTypes, ModalNamesType } from './types'
import { ModalActionTypes, ModalNamesType, ModalPropsType } from './types'

// Remove the last modal added in the stack
export const closeModal = (): ModalActionTypes => ({ type: AT.CLOSE_MODAL })
Expand All @@ -10,21 +10,12 @@ export const closeAllModals = (): ModalActionTypes => ({
// Add a modal in the stack
export const showModal = (
type: ModalNamesType,
props = {},
props: ModalPropsType,
options = {}
): ModalActionTypes => ({
type: AT.SHOW_MODAL,
payload: { type, props, options }
})
// Replace the last modal added in the stack by this new one
export const replaceModal = (
type,
props = {},
options = {}
): ModalActionTypes => ({
type: AT.REPLACE_MODAL,
payload: { type, props, options }
})
// Update the last modal added in the stack
export const updateModalOptions = (options = {}): ModalActionTypes => ({
type: AT.UPDATE_MODAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const modals = (state = INITIAL_STATE, action) => {
? insert(nextIndex, payload, state)
: state
}
case AT.REPLACE_MODAL: {
return update(lastIndex, payload, state)
}
case AT.UPDATE_MODAL: {
const lastModal = state[state.length - 1]
const updatedModal = merge(lastModal, payload)
Expand Down

0 comments on commit 5792bf1

Please sign in to comment.