Skip to content

Commit

Permalink
feat(Transfer All): add transfer all to bsv imported addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jan 9, 2019
1 parent b0ae36b commit ffe6b8a
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import React from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { prepend } from 'ramda'
import { getData } from './selectors'
import SelectBoxBsv from './template'

class SelectBoxBsvAddresses extends React.PureComponent {
render () {
const { data, ...rest } = this.props
const allWallets = {
label: 'All',
options: [
{
label: 'All Bitcoin SV Wallets',
value: 'all'
}
]
}

return data.cata({
Success: value => {
const elements = this.props.includeAll
? prepend(allWallets, value.data)
: value.data
return <SelectBoxBsv elements={elements} {...rest} />
return <SelectBoxBsv elements={value.data} {...rest} />
},
Failure: message => <div>{message}</div>,
Loading: () => <div />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@ import {
not,
path,
prop,
prepend,
sequence,
reduce
} from 'ramda'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'
import { selectors } from 'data'
import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'

const allWallets = {
label: 'All',
options: [
{
label: 'All Bitcoin SV Wallets',
value: 'all'
}
]
}

const allImportedAddresses = {
label: 'Imported Addresses',
options: [
{
label: 'All Imported Bitcoin SV Addresses',
value: 'allImportedAddresses'
}
]
}

export const getData = (state, ownProps) => {
const { coin, exclude = [], excludeImported, excludeWatchOnly } = ownProps
const {
coin,
exclude = [],
excludeHDWallets,
excludeImported,
excludeWatchOnly,
includeAll = true
} = ownProps
const buildDisplay = wallet => {
if (has('balance', wallet)) {
let bsvDisplay = Exchange.displayBsvToBsv({
Expand Down Expand Up @@ -81,7 +109,16 @@ export const getData = (state, ownProps) => {
toGroup('Imported Addresses')
),
Remote.of([])
]).map(([b1, b2, b3]) => ({ data: reduce(concat, [], [b1, b2, b3]) }))
]).map(([b1, b2, b3]) => {
const data = reduce(concat, [], [b1, b2, b3])
if (includeAll) {
return { data: prepend(allWallets, data) }
} else if (excludeHDWallets) {
return { data: [allImportedAddresses] }
} else {
return { data }
}
})
}

return getAddressesData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as AT from './actionTypes'

export const initialized = index => ({
export const initialized = payload => ({
type: AT.SEND_BSV_INITIALIZED,
payload: { index }
payload
})
export const destroyed = () => ({ type: AT.SEND_BSV_DESTROYED })
export const sendBsvPaymentUpdated = payment => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'redux-form'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'
import { Exchange, Remote, utils } from 'blockchain-wallet-v4/src'
import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'

export const logLocation = 'components/sendBsv/sagas'
Expand All @@ -22,8 +22,7 @@ export const bsvDefaultFee = 4
export default ({ coreSagas, networks }) => {
const initialized = function*(action) {
try {
const { payload } = action
const { index } = payload
const { from, index } = action.payload
yield put(A.sendBsvPaymentUpdated(Remote.Loading))
let payment = coreSagas.payment.bsv.create({
network: networks.bsv
Expand All @@ -37,11 +36,23 @@ export default ({ coreSagas, networks }) => {
)
const defaultIndex = index || defaultIndexR.getOrElse(0)
const defaultAccountR = accountsR.map(nth(defaultIndex))
payment = yield payment.from(defaultIndex, ADDRESS_TYPES.ACCOUNT)
if (from === 'allImportedAddresses') {
const addressesR = yield select(
selectors.core.common.bsv.getActiveAddresses
)
const addresses = addressesR
.getOrElse([])
.filter(prop('priv'))
.map(prop('addr'))
.map(utils.bsv.fromCashAddr)
payment = yield payment.from(addresses, ADDRESS_TYPES.LEGACY)
} else {
payment = yield payment.from(defaultIndex, ADDRESS_TYPES.ACCOUNT)
}
payment = yield payment.fee(bsvDefaultFee)
const initialValues = {
coin: 'BSV',
from: defaultAccountR.getOrElse()
from: from || defaultAccountR.getOrElse()
}
yield put(initialize(FORM, initialValues))
yield put(A.sendBsvPaymentUpdated(Remote.of(payment.value())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class FirstStep extends React.Component {
enableToggle={value.enableToggle}
effectiveBalance={value.effectiveBalance}
totalFee={value.totalFee}
onSubmit={actions.sendBsvFirstStepSubmitClicked}
handleToToggle={this.handleToToggle}
onSubmit={actions.sendBsvFirstStepSubmitClicked}
excludeHDWallets={this.props.excludeHDWallets}
/>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const FirstStep = props => {
handleToToggle,
handleSubmit,
totalFee,
pristine
pristine,
excludeHDWallets
} = props

return (
Expand All @@ -59,10 +60,11 @@ const FirstStep = props => {
<Field
name='from'
coin='BSV'
component={SelectBoxBsvAddresses}
includeAll={false}
excludeWatchOnly
validate={[required]}
component={SelectBoxBsvAddresses}
excludeHDWallets={excludeHDWallets}
excludeWatchOnly
/>
</FormItem>
</FormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import SecondStep from './SecondStep'

class SendBsvContainer extends React.PureComponent {
componentDidMount () {
this.props.actions.initialized(this.props.index)
const { from, index } = this.props
this.props.actions.initialized({
from,
index
})
}

componentWillUnmount () {
this.props.actions.destroyed()
}

render () {
const { step, position, total, closeAll } = this.props
const { step, position, total, closeAll, excludeHDWallets } = this.props
return (
<SendBsv position={position} total={total} closeAll={closeAll}>
{step === 1 && <FirstStep />}
<SendBsv total={total} position={position} closeAll={closeAll}>
{step === 1 && <FirstStep excludeHDWallets={excludeHDWallets} />}
{step === 2 && <SecondStep />}
</SendBsv>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { actions } from 'data'
import { actions, model } from 'data'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { getData } from './selectors'
Expand All @@ -12,10 +12,23 @@ class ImportedAddressesContainer extends React.Component {
return !Remote.Loading.is(nextProps.data)
}

handleTransferAll = () => {
this.props.actions.showModal(model.components.sendBsv.MODAL, {
from: 'allImportedAddresses',
excludeHDWallets: true
})
}

render () {
const { data, ...rest } = this.props
return data.cata({
Success: value => <Success importedAddresses={value} {...rest} />,
Success: value => (
<Success
importedAddresses={value}
onTransferAll={this.handleTransferAll}
{...rest}
/>
),
Failure: message => <div>{message}</div>,
Loading: () => <div />,
NotAsked: () => <div />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AddressRow from '../../Btc/AddressRow'
import { FormattedMessage } from 'react-intl'
import { SettingDescription, SettingHeader } from 'components/Setting'
import {
Button,
Icon,
Table,
TableHeader,
Expand All @@ -16,9 +17,16 @@ const Wrapper = styled.section`
box-sizing: border-box;
`
const ImportedAddressesSettingHeader = SettingHeader.extend`
justify-content: flex-start;
align-items: flex-start;
justify-content: space-between;
margin-top: 30px;
`
const ImportedActions = styled.div`
display: flex;
> button {
margin-left: 10px;
}
`
const WarningWrapper = styled.div`
display: flex;
.warning-icon {
Expand All @@ -28,7 +36,7 @@ const WarningWrapper = styled.div`
`

const Success = props => {
const { importedAddresses, search } = props
const { importedAddresses, onTransferAll, search } = props

const isMatch = address =>
!search || address.addr.toLowerCase().indexOf(search) > -1
Expand All @@ -42,25 +50,35 @@ const Success = props => {
return (
<Wrapper>
<ImportedAddressesSettingHeader>
<FormattedMessage
id='scenes.settings.addresses.bsv.importedaddresses.title'
defaultMessage='Imported Bitcoin SV Addresses'
/>
</ImportedAddressesSettingHeader>
<SettingDescription>
<WarningWrapper>
<Icon
name='alert-filled'
size='22px'
className={'warning-icon'}
color='brand-yellow'
/>
<div>
<FormattedMessage
id='scenes.settings.addresses.bsv.importedaddresses.description'
defaultMessage='Imported funds are not protected by your backup phrase. To ensure these funds are secured, please transfer them directly into your wallet.'
id='scenes.settings.addresses.bsv.importedaddresses.title'
defaultMessage='Imported Bitcoin SV Addresses'
/>
</WarningWrapper>
</SettingDescription>
<SettingDescription>
<WarningWrapper>
<Icon
name='alert-filled'
size='22px'
className={'warning-icon'}
color='brand-yellow'
/>
<FormattedMessage
id='scenes.settings.addresses.bsv.importedaddresses.description'
defaultMessage='Imported funds are not protected by your backup phrase. To ensure these funds are secured, please transfer them directly into your wallet.'
/>
</WarningWrapper>
</SettingDescription>
</div>
<ImportedActions>
<Button onClick={onTransferAll} nature='primary'>
<FormattedMessage
id='scenes.settings.addresses.bch.importedaddresses.success.transferall'
defaultMessage='Transfer All'
/>
</Button>
</ImportedActions>
</ImportedAddressesSettingHeader>
{importedAddressesTableRows.length > 0 && (
<Table>
<TableHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ export const bsvFromLabel = curry((payment, state) => {
.getAccountLabel(state)(payment.fromAccountIdx)
.getOrElse(payment.from[0])
case ADDRESS_TYPES.LEGACY:
return utils.bsv.toCashAddr(payment.from[0], true)
const formValues = selectors.form.getFormValues(
model.components.sendBsv.FORM
)(state)
const { from } = formValues
if (from === 'allImportedAddresses') {
return 'All Imported Bitcoin SV Addresses'
} else {
return utils.bsv.toCashAddr(payment.from[0], true)
}
case ADDRESS_TYPES.WATCH_ONLY:
return utils.bsv.toCashAddr(payment.from[0], true)
case ADDRESS_TYPES.EXTERNAL:
Expand Down

0 comments on commit ffe6b8a

Please sign in to comment.