Skip to content

Commit

Permalink
feat(SFOX): starts sift science
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jun 18, 2018
1 parent ba5caa7 commit fe60899
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
Expand Up @@ -23,3 +23,6 @@ export const SFOX_LOADING = '@COMPONENT.SFOX_LOADING'
export const SFOX_SUCCESS = '@COMPONENT.SFOX_SUCCESS'
export const SFOX_FAILURE = '@COMPONENT.SFOX_FAILURE'
export const SFOX_NOT_ASKED = '@COMPONENT.SFOX_NOT_ASKED'

export const ENABLE_SIFT_SCIENCE = '@COMPONENT.ENABLE_SIFT_SCIENCE'
export const DISABLE_SIFT_SCIENCE = '@COMPONENT.DISABLE_SIFT_SCIENCE'
Expand Up @@ -25,3 +25,6 @@ export const sfoxNotAsked = () => ({ type: AT.SFOX_NOT_ASKED })
export const sfoxLoading = () => ({ type: AT.SFOX_LOADING })
export const sfoxSuccess = () => ({ type: AT.SFOX_SUCCESS })
export const sfoxFailure = (error) => ({ type: AT.SFOX_FAILURE, payload: error })

export const enableSiftScience = () => ({ type: AT.ENABLE_SIFT_SCIENCE })
export const disableSiftScience = () => ({ type: AT.DISABLE_SIFT_SCIENCE })
Expand Up @@ -4,7 +4,8 @@ import { Remote } from 'blockchain-wallet-v4/src'

const INITIAL_STATE = {
sfoxBusy: Remote.NotAsked,
qaSellAddress: null
qaSellAddress: null,
siftScienceEnabled: false
}

const sfoxSignup = (state = INITIAL_STATE, action) => {
Expand All @@ -29,6 +30,12 @@ const sfoxSignup = (state = INITIAL_STATE, action) => {
case AT.SFOX_FAILURE: {
return assoc('sfoxBusy', Remote.Failure(payload), state)
}
case AT.ENABLE_SIFT_SCIENCE: {
return assoc('siftScienceEnabled', true, state)
}
case AT.DISABLE_SIFT_SCIENCE: {
return assoc('siftScienceEnabled', false, state)
}
default:
return state
}
Expand Down
@@ -0,0 +1,68 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { actions, selectors } from 'data'
import { path } from 'ramda'

class ISignThisContainer extends Component {
constructor (props) {
super(props)
this.state = { enabled: false }
}
componentDidMount () {
let receiveMessage = (e) => {
const helperDomain = path(['domains', 'walletHelper'], this.propswalletOptions)
if (!e.data.command) return
if (e.data.from !== 'sift-science') return
if (e.data.to !== 'exchange') return
if (e.origin !== helperDomain) return
switch (e.data.command) {
case 'done':
// Remove Sift Science iframe:
this.props.sfoxFrontendActions.disableSiftScience()
break
default:
return null
}

};
window.addEventListener('message', receiveMessage, false)
}

render () {
const { options, userId, siftScienceEnabled } = this.props
const walletOptions = options || path(['data'], this.props.walletOptions)
const helperDomain = path(['domains', 'walletHelper'], walletOptions)
const sfoxSiftScience = path(['platforms', 'web', 'sfox', 'config', 'siftScience'], walletOptions)

let url = `${helperDomain}/wallet-helper/sift-science/#/key/${sfoxSiftScience}/user/${userId}`
// url += scope.tradeId ? `/trade/${scope.tradeId}` : '';

if (userId) {
return null
}

if (siftScienceEnabled) {
return (
<iframe
src={url}
sandbox='allow-same-origin allow-scripts'
scrolling='no'
id='sift-science-iframe'
/>
)
}
}
}

const mapStateToProps = (state) => ({
walletOptions: path(['walletOptionsPath'], state),
userId: selectors.core.kvStore.buySell.getSfoxUser(state),
siftScienceEnabled: path(['sfoxSignup', 'siftScienceEnabled'], state)
})

const mapDispatchToProps = (dispatch) => ({
sfoxFrontendActions: bindActionCreators(actions.modules.sfox, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(ISignThisContainer)
Expand Up @@ -5,3 +5,5 @@ import { kvStorePath } from '../../paths'
export const getMetadata = path([kvStorePath, BUYSELL])

export const getSfoxTrades = path([kvStorePath, BUYSELL, 'data', 'value', 'sfox', 'trades'])

export const getSfoxUser = path([kvStorePath, BUYSELL, 'data', 'value', 'sfox', 'user'])

0 comments on commit fe60899

Please sign in to comment.