Skip to content

Commit

Permalink
feat(BTC): Transfer All imported addresses from settings/addresses
Browse files Browse the repository at this point in the history
409
  • Loading branch information
plondon committed Jan 2, 2019
1 parent 0442026 commit 5742bb3
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ const allWallets = {
]
}

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

export const getData = (state, ownProps) => {
const {
exclude = [],
excludeHDWallets,
excludeImported,
excludeLockbox,
includeAll = true
Expand Down Expand Up @@ -66,9 +77,9 @@ export const getData = (state, ownProps) => {
]).map(([b1, b2, b3]) => {
const data = reduce(concat, [], [b1, b2, b3])
if (includeAll) {
return {
data: prepend(allWallets, data)
}
return { data: prepend(allWallets, data) }
} else if (excludeHDWallets) {
return { data: [allImportedAddresses] }
} else {
return { data }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,34 @@ export const logLocation = 'components/sendBtc/sagas'
export default ({ coreSagas, networks }) => {
const initialized = function*(action) {
try {
const { to, description, amount, feeType, lockboxIndex } = action.payload
const {
from,
to,
amount,
feeType,
description,
lockboxIndex
} = action.payload
yield put(A.sendBtcPaymentUpdatedLoading())
let payment = coreSagas.payment.btc.create({
network: networks.btc
})
payment = yield payment.init()
let defaultAccountR
if (lockboxIndex == null) {
if (lockboxIndex && lockboxIndex >= 0) {
const accountsR = yield select(
selectors.core.common.btc.getLockboxBtcBalances
)
defaultAccountR = accountsR.map(nth(lockboxIndex))
const xpub = defaultAccountR.map(prop('xpub')).getOrFail()
payment = yield payment.from(xpub, ADDRESS_TYPES.LOCKBOX)
} else if (from === 'allImportedAddresses') {
const addressesR = yield select(
selectors.core.common.btc.getActiveAddresses
)
const addresses = addressesR.getOrElse([]).map(prop('addr'))
payment = yield payment.from(addresses, ADDRESS_TYPES.LEGACY)
} else {
const accountsR = yield select(
selectors.core.common.btc.getAccountsBalances
)
Expand All @@ -41,13 +61,6 @@ export default ({ coreSagas, networks }) => {
)
defaultAccountR = accountsR.map(nth(defaultIndex))
payment = yield payment.from(defaultIndex, ADDRESS_TYPES.ACCOUNT)
} else {
const accountsR = yield select(
selectors.core.common.btc.getLockboxBtcBalances
)
defaultAccountR = accountsR.map(nth(lockboxIndex))
const xpub = defaultAccountR.map(prop('xpub')).getOrFail()
payment = yield payment.from(xpub, ADDRESS_TYPES.LOCKBOX)
}
const defaultFeePerByte = path(
['fees', feeType || 'regular'],
Expand All @@ -59,7 +72,7 @@ export default ({ coreSagas, networks }) => {
coin: 'BTC',
amount,
description,
from: defaultAccountR.getOrElse(),
from: from || defaultAccountR.getOrElse(),
feePerByte: defaultFeePerByte
}
yield put(initialize(FORM, initialValues))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FirstStep extends React.Component {
handleFeePerByteToggle={actions.sendBtcFirstStepFeePerByteToggled}
handleToToggle={this.handleToToggle}
excludeLockbox={value.excludeLockbox}
excludeHDWallets={this.props.excludeHDWallets}
/>
),
Failure: () => <DataError onClick={() => this.handleRefresh} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const FirstStep = props => {
priorityFeePerByte,
isPriorityFeePerByte,
totalFee,
excludeLockbox
excludeLockbox,
excludeHDWallets
} = rest
const disableLockboxSend =
from &&
Expand Down Expand Up @@ -121,9 +122,10 @@ const FirstStep = props => {
</FormLabel>
<Field
name='from'
component={SelectBoxBtcAddresses}
validate={[required]}
includeAll={false}
validate={[required]}
component={SelectBoxBtcAddresses}
excludeHDWallets={excludeHDWallets}
excludeLockbox={excludeLockbox}
/>
{watchOnly && (
Expand Down Expand Up @@ -317,18 +319,16 @@ const FirstStep = props => {
</Link>
</ColRight>
</FeeFormGroup>
{
feePerByteToggled
? <CustomFeeAlertBanner type='alert'>
<Text size='12px'>
<FormattedMessage
id='modals.sendbtc.firststep.customfeeinfo'
defaultMessage='This feature is recommended for advanced users only. By choosing a custom fee, you risk overpaying or your transaction never being confirmed.'
/>
</Text>
</CustomFeeAlertBanner>
: null
}
{feePerByteToggled ? (
<CustomFeeAlertBanner type='alert'>
<Text size='12px'>
<FormattedMessage
id='modals.sendbtc.firststep.customfeeinfo'
defaultMessage='This feature is recommended for advanced users only. By choosing a custom fee, you risk overpaying or your transaction never being confirmed.'
/>
</Text>
</CustomFeeAlertBanner>
) : null}
<FormGroup margin={'15px'}>
<Text size='13px' weight={300}>
{!isPriorityFeePerByte && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import SecondStep from './SecondStep'

class SendBtcContainer extends React.PureComponent {
componentDidMount () {
const { to, description, amount, lockboxIndex } = this.props
this.props.actions.initialized({ to, description, amount, lockboxIndex })
const { from, to, description, amount, lockboxIndex } = this.props
this.props.actions.initialized({
from,
to,
description,
amount,
lockboxIndex
})
}

componentWillUnmount () {
Expand All @@ -21,19 +27,25 @@ class SendBtcContainer extends React.PureComponent {

render () {
const {
to,
step,
position,
total,
amount,
position,
closeAll,
to,
description,
amount
excludeHDWallets
} = this.props

return (
<SendBtc position={position} total={total} closeAll={closeAll}>
{step === 1 && (
<FirstStep to={to} description={description} amount={amount} />
<FirstStep
to={to}
amount={amount}
description={description}
excludeHDWallets={excludeHDWallets}
/>
)}
{step === 2 && <SecondStep />}
</SendBtc>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { actions, selectors } from 'data'
import { actions, model, selectors } from 'data'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import Success from './template.success'
Expand All @@ -13,22 +13,22 @@ class ImportedAddressesContainer extends React.Component {
}

handleClickImport = () => {
this.props.modalsActions.showModal('ImportBtcAddress')
this.props.modalActions.showModal('ImportBtcAddress')
}

handleClickVerify = () => {
this.props.modalsActions.showModal('VerifyMessage')
this.props.modalActions.showModal('VerifyMessage')
}

handleShowPriv = address => {
this.props.modalsActions.showModal('ShowBtcPrivateKey', {
this.props.modalActions.showModal('ShowBtcPrivateKey', {
addr: address.addr,
balance: address.info.final_balance
})
}

handleSignMessage = address => {
this.props.modalsActions.showModal('SignMessage', {
this.props.modalActions.showModal('SignMessage', {
address: address.addr
})
}
Expand All @@ -38,7 +38,12 @@ class ImportedAddressesContainer extends React.Component {
this.props.coreActions.setAddressArchived(address.addr, !isArchived)
}

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

render () {
const { search, addressesWithoutRemoteData } = this.props
Expand Down Expand Up @@ -81,7 +86,7 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
coreActions: bindActionCreators(actions.core.wallet, dispatch),
modalsActions: bindActionCreators(actions.modals, dispatch)
modalActions: bindActionCreators(actions.modals, dispatch)
})

export default connect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selectors } from 'data'
import { model, selectors } from 'data'
import { curry, prop } from 'ramda'
import { utils } from 'blockchain-wallet-v4/src'
import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'
Expand Down Expand Up @@ -33,7 +33,15 @@ export const btcFromLabel = curry((payment, state) => {
const label = selectors.core.wallet.getLegacyAddressLabel(state)(
payment.from[0]
)
return label || payment.from[0]
const formValues = selectors.form.getFormValues(
model.components.sendBtc.FORM
)(state)
const { from } = formValues
if (from === 'allImportedAddresses') {
return 'All Imported Bitcoin Addresses'
} else {
return label || payment.from[0]
}
case ADDRESS_TYPES.LOCKBOX:
return selectors.core.kvStore.lockbox
.getLockboxBtcAccount(state, payment.from[0])
Expand Down

0 comments on commit 5742bb3

Please sign in to comment.