Skip to content

Commit

Permalink
fix address label edit
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed Jun 4, 2018
1 parent a68289d commit 9bd7830
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 51 deletions.
@@ -1,13 +1,13 @@
// UNUSED ADDRESSES
export const DELETE_UNUSED_ADDRESS_LABEL = '@EVENT.DELETE_UNUSED_ADDRESS_LABEL'
export const DELETE_UNUSED_ADDRESS_LABEL_ERROR = '@EVENT.DELETE_UNUSED_ADDRESS_LABEL_ERROR'
export const DELETE_UNUSED_ADDRESS_LABEL_LOADING = '@EVENT.DELETE_UNUSED_ADDRESS_LABEL_LOADING'
export const DELETE_UNUSED_ADDRESS_LABEL_SUCCESS = '@EVENT.DELETE_UNUSED_ADDRESS_LABEL_SUCCESS'
export const DELETE_ADDRESS_LABEL = '@EVENT.DELETE_ADDRESS_LABEL'
export const DELETE_ADDRESS_LABEL_ERROR = '@EVENT.DELETE_ADDRESS_LABEL_ERROR'
export const DELETE_ADDRESS_LABEL_LOADING = '@EVENT.DELETE_ADDRESS_LABEL_LOADING'
export const DELETE_ADDRESS_LABEL_SUCCESS = '@EVENT.DELETE_ADDRESS_LABEL_SUCCESS'

export const EDIT_UNUSED_ADDRESS_LABEL = '@EVENT.EDIT_UNUSED_ADDRESS_LABEL'
export const EDIT_UNUSED_ADDRESS_LABEL_ERROR = '@EVENT.EDIT_UNUSED_ADDRESS_LABEL_ERROR'
export const EDIT_UNUSED_ADDRESS_LABEL_LOADING = '@EVENT.EDIT_UNUSED_ADDRESS_LABEL_LOADING'
export const EDIT_UNUSED_ADDRESS_LABEL_SUCCESS = '@EVENT.EDIT_UNUSED_ADDRESS_LABEL_SUCCESS'
export const EDIT_ADDRESS_LABEL = '@EVENT.EDIT_ADDRESS_LABEL'
export const EDIT_ADDRESS_LABEL_ERROR = '@EVENT.EDIT_ADDRESS_LABEL_ERROR'
export const EDIT_ADDRESS_LABEL_LOADING = '@EVENT.EDIT_ADDRESS_LABEL_LOADING'
export const EDIT_ADDRESS_LABEL_SUCCESS = '@EVENT.EDIT_ADDRESS_LABEL_SUCCESS'

export const GENERATE_NEXT_RECEIVE_ADDRESS = '@EVENT.GENERATE_NEXT_RECEIVE_ADDRESS'
export const GENERATE_NEXT_RECEIVE_ADDRESS_ERROR = '@EVENT.GENERATE_NEXT_RECEIVE_ADDRESS_ERROR'
Expand Down
@@ -1,15 +1,15 @@
import * as AT from './actionTypes'

// UNUSED ADDRESSES
export const deleteUnusedAddressLabel = (accountIndex, walletIndex, addressIndex) => ({ type: AT.DELETE_UNUSED_ADDRESS_LABEL, payload: { accountIndex, walletIndex, addressIndex } })
export const deleteUnusedAddressLabelError = (walletIndex, message) => ({ type: AT.DELETE_UNUSED_ADDRESS_LABEL_ERROR, payload: { walletIndex, message } })
export const deleteUnusedAddressLabelLoading = (walletIndex) => ({ type: AT.DELETE_UNUSED_ADDRESS_LABEL_LOADING, payload: { walletIndex } })
export const deleteUnusedAddressLabelSuccess = (walletIndex) => ({ type: AT.DELETE_UNUSED_ADDRESS_LABEL_SUCCESS, payload: { walletIndex } })
export const deleteAddressLabel = (accountIndex, walletIndex, addressIndex) => ({ type: AT.DELETE_ADDRESS_LABEL, payload: { accountIndex, walletIndex, addressIndex } })
export const deleteAddressLabelError = (walletIndex, message) => ({ type: AT.DELETE_ADDRESS_LABEL_ERROR, payload: { walletIndex, message } })
export const deleteAddressLabelLoading = (walletIndex) => ({ type: AT.DELETE_ADDRESS_LABEL_LOADING, payload: { walletIndex } })
export const deleteAddressLabelSuccess = (walletIndex) => ({ type: AT.DELETE_ADDRESS_LABEL_SUCCESS, payload: { walletIndex } })

export const editUnusedAddressLabel = (accountIndex, walletIndex, addressIndex) => ({ type: AT.EDIT_UNUSED_ADDRESS_LABEL, payload: { accountIndex, walletIndex, addressIndex } })
export const editUnusedAddressLabelError = (walletIndex, message) => ({ type: AT.EDIT_UNUSED_ADDRESS_LABEL_ERROR, payload: { walletIndex, message } })
export const editUnusedAddressLabelLoading = (walletIndex) => ({ type: AT.EDIT_UNUSED_ADDRESS_LABEL_LOADING, payload: { walletIndex } })
export const editUnusedAddressLabelSuccess = (walletIndex) => ({ type: AT.EDIT_UNUSED_ADDRESS_LABEL_SUCCESS, payload: { walletIndex } })
export const editAddressLabel = (accountIndex, walletIndex, addressIndex) => ({ type: AT.EDIT_ADDRESS_LABEL, payload: { accountIndex, walletIndex, addressIndex } })
export const editAddressLabelError = (walletIndex, message) => ({ type: AT.EDIT_ADDRESS_LABEL_ERROR, payload: { walletIndex, message } })
export const editAddressLabelLoading = (walletIndex) => ({ type: AT.EDIT_ADDRESS_LABEL_LOADING, payload: { walletIndex } })
export const editAddressLabelSuccess = (walletIndex) => ({ type: AT.EDIT_ADDRESS_LABEL_SUCCESS, payload: { walletIndex } })

export const generateNextReceiveAddress = (walletIndex) => ({ type: AT.GENERATE_NEXT_RECEIVE_ADDRESS, payload: { walletIndex } })
export const generateNextReceiveAddressError = (walletIndex, message) => ({ type: AT.GENERATE_NEXT_RECEIVE_ADDRESS_ERROR, payload: { walletIndex, message } })
Expand Down
Expand Up @@ -6,8 +6,8 @@ export default ({ api, coreSagas }) => {
const manageAddressesSagas = sagas({ api, coreSagas })

return function * () {
yield takeLatest(AT.DELETE_UNUSED_ADDRESS_LABEL, manageAddressesSagas.deleteUnusedAddressLabel)
yield takeLatest(AT.EDIT_UNUSED_ADDRESS_LABEL, manageAddressesSagas.editUnusedAddressLabel)
yield takeLatest(AT.DELETE_ADDRESS_LABEL, manageAddressesSagas.deleteAddressLabel)
yield takeLatest(AT.EDIT_ADDRESS_LABEL, manageAddressesSagas.editAddressLabel)
yield takeLatest(AT.GENERATE_NEXT_RECEIVE_ADDRESS, manageAddressesSagas.generateNextReceiveAddress)
yield takeLatest(AT.FETCH_UNUSED_ADDRESSES, manageAddressesSagas.fetchUnusedAddresses)
yield takeLatest(AT.FETCH_USED_ADDRESSES, manageAddressesSagas.fetchUsedAddresses)
Expand Down
Expand Up @@ -6,6 +6,8 @@ import * as actions from '../../actions'
import { selectors } from '../../index'
import settings from 'config'
import { Types } from 'blockchain-wallet-v4/src'
import * as C from 'services/AlertService'
import { promptForInput } from 'services/SagaService'

export default ({ api }) => {
const logLocation = 'components/manageAddresses/sagas'
Expand Down Expand Up @@ -112,43 +114,45 @@ export default ({ api }) => {
}
}

const editUnusedAddressLabel = function * (action) {
const editAddressLabel = function * (action) {
const { accountIndex, walletIndex, addressIndex } = action.payload

try {
yield put(A.editUnusedAddressLabelLoading(accountIndex))
yield put(actions.wallet.editHdLabel(accountIndex, addressIndex))
yield put(A.editAddressLabelLoading(accountIndex))
let newLabel = yield call(promptForInput, { title: 'Rename Address Label' })
yield put(actions.core.wallet.setHdAddressLabel(accountIndex, addressIndex, newLabel))
yield put(actions.alerts.displaySuccess(C.ADDRESS_LABEL_UPDATE_SUCCESS))
yield put(A.fetchUnusedAddresses(walletIndex))
yield put(A.editUnusedAddressLabelSuccess(walletIndex))
yield put(A.editAddressLabelSuccess(walletIndex))
} catch (e) {
yield put(A.editUnusedAddressLabelError(walletIndex, e))
yield put(actions.logs.logErrorMessage(logLocation, 'editUnusedAddressLabel', e))
yield put(A.editAddressLabelError(walletIndex, e))
yield put(actions.logs.logErrorMessage(logLocation, 'editAddressLabel', e))
yield put(actions.alerts.displayError('Failed to update address label.'))
}
}

const deleteUnusedAddressLabel = function * (action) {
const deleteAddressLabel = function * (action) {
const { accountIndex, walletIndex, addressIndex } = action.payload

try {
yield put(A.deleteUnusedAddressLabelLoading(accountIndex))
yield put(A.deleteAddressLabelLoading(accountIndex))
yield put(actions.core.wallet.deleteHdAddressLabel(accountIndex, addressIndex))
yield put(A.fetchUnusedAddresses(walletIndex))
yield put(actions.alerts.displaySuccess('Address was deleted successfully.'))
yield put(A.deleteUnusedAddressLabelSuccess(walletIndex))
yield put(A.deleteAddressLabelSuccess(walletIndex))
yield put(A.fetchUnusedAddresses(walletIndex))
} catch (e) {
yield put(A.deleteUnusedAddressLabelError(walletIndex, e))
yield put(actions.logs.logErrorMessage(logLocation, 'deleteUnusedAddressLabel', e))
yield put(A.deleteAddressLabelError(walletIndex, e))
yield put(actions.logs.logErrorMessage(logLocation, 'deleteAddressLabel', e))
yield put(actions.alerts.displayError('Failed to delete address label.'))
}
}

return {
editUnusedAddressLabel,
editAddressLabel,
generateNextReceiveAddress,
fetchUnusedAddresses,
fetchUsedAddresses,
deleteUnusedAddressLabel,
deleteAddressLabel,
toggleUsedAddresses
}
}
Expand Up @@ -8,8 +8,6 @@ export const IMPORT_LEGACY_ADDRESS = 'IMPORT_LEGACY_ADDRESS'

export const VERIFY_MNEMONIC = 'VERIFY_MNEMONIC'

export const EDIT_HD_LABEL = 'EDIT_HD_LABEL'

export const SUBMIT_PROMPT_INPUT = 'SUBMIT_PROMPT_INPUT'

export const EDIT_BTC_ACCOUNT_LABEL = 'EDIT_BTC_ACCOUNT_LABEL'
Expand Down
Expand Up @@ -10,8 +10,6 @@ export const importLegacyAddress = (addr, priv, to, bipPass) => ({ type: AT.IMPO

export const verifyMnemonic = () => ({ type: AT.VERIFY_MNEMONIC })

export const editHdLabel = (accountIdx, addressIdx) => ({ type: AT.EDIT_HD_LABEL, payload: { accountIdx, addressIdx } })

export const submitPromptInput = (value) => ({ type: AT.SUBMIT_PROMPT_INPUT, payload: { value } })

export const editBtcAccountLabel = (index, label) => ({ type: AT.EDIT_BTC_ACCOUNT_LABEL, payload: { index, label } })
Expand Down
Expand Up @@ -9,7 +9,6 @@ export default ({ coreSagas }) => {
yield takeEvery(AT.TOGGLE_SECOND_PASSWORD, walletSagas.toggleSecondPassword)
yield takeEvery(AT.UPDATE_PBKDF2_ITERATIONS, walletSagas.updatePbkdf2Iterations)
yield takeEvery(AT.VERIFY_MNEMONIC, walletSagas.verifyMmenonic)
yield takeEvery(AT.EDIT_HD_LABEL, walletSagas.editHdLabel)
yield takeEvery(AT.EDIT_BTC_ACCOUNT_LABEL, walletSagas.editBtcAccountLabel)
yield takeLatest(AT.SET_MAIN_PASSWORD, walletSagas.setMainPassword)
}
Expand Down
12 changes: 0 additions & 12 deletions packages/blockchain-wallet-v4-frontend/src/data/wallet/sagas.js
Expand Up @@ -35,17 +35,6 @@ export default ({ coreSagas }) => {
yield put(actions.alerts.displaySuccess(C.MNEMONIC_VERIFY_SUCCESS))
}

const editHdLabel = function * (action) {
try {
let { accountIdx, addressIdx } = action.payload
let newLabel = yield call(promptForInput, { title: 'Rename Address Label' })
yield put(actions.core.wallet.setHdAddressLabel(accountIdx, addressIdx, newLabel))
yield put(actions.alerts.displaySuccess(C.ADDRESS_LABEL_UPDATE_SUCCESS))
} catch (error) {
yield put(actions.logs.logErrorMessage(logLocation, 'editHdLabel', error))
}
}

const editBtcAccountLabel = function * (action) {
try {
let { index, label } = action.payload
Expand All @@ -67,7 +56,6 @@ export default ({ coreSagas }) => {
toggleSecondPassword,
updatePbkdf2Iterations,
verifyMmenonic,
editHdLabel,
editBtcAccountLabel,
setMainPassword
}
Expand Down
Expand Up @@ -17,8 +17,8 @@ class UnusedAddressesContainer extends React.PureComponent {

render () {
const { account, unusedAddresses, currentReceiveIndex, isDefault, coreActions, walletActions, modalsActions, routerActions, search } = this.props
const onEditLabel = (i) => this.props.componentActions.editUnusedAddressLabel(account.index, this.props.walletIndex, i)
const onDeleteLabel = (i) => this.props.componentActions.deleteUnusedAddressLabel(account.index, this.props.walletIndex, i)
const onEditLabel = (i) => this.props.componentActions.editAddressLabel(account.index, this.props.walletIndex, i)
const onDeleteLabel = (i) => this.props.componentActions.deleteAddressLabel(account.index, this.props.walletIndex, i)
const onEditBtcAccountLabel = () => walletActions.editBtcAccountLabel(account.index, account.label)
const onShowXPub = () => modalsActions.showModal('ShowXPub', { xpub: account.xpub })
const onMakeDefault = () => coreActions.setDefaultAccountIdx(account.index)
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-wallet-v4/src/types/Wallet.js
Expand Up @@ -248,6 +248,7 @@ export const deleteHdAddressLabel = curry((accountIdx, addressIdx, wallet) => {
HDAccountList.account(accountIdx),
HDAccount.addressLabels)
const eitherW = Either.try(over(lens, AddressLabelMap.deleteLabel(addressIdx)))(wallet)
debugger
return eitherW.getOrElse(wallet)
})

Expand Down

0 comments on commit 9bd7830

Please sign in to comment.