mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Allow for adding recently used addresses to address book.
This commit is contained in:
parent
b296640f1b
commit
b34ee4daa1
@ -251,6 +251,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
const preferencesController = this.preferencesController
|
const preferencesController = this.preferencesController
|
||||||
const txManager = this.txManager
|
const txManager = this.txManager
|
||||||
const noticeController = this.noticeController
|
const noticeController = this.noticeController
|
||||||
|
const addressBookController = this.addressBookController
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// etc
|
// etc
|
||||||
@ -278,6 +279,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
|
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
|
||||||
setCustomRpc: nodeify(this.setCustomRpc).bind(this),
|
setCustomRpc: nodeify(this.setCustomRpc).bind(this),
|
||||||
|
|
||||||
|
// AddressController
|
||||||
|
setAddressBook: nodeify(addressBookController.setAddressBook).bind(addressBookController),
|
||||||
|
|
||||||
// KeyringController
|
// KeyringController
|
||||||
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
||||||
|
@ -75,6 +75,8 @@ var actions = {
|
|||||||
// account detail screen
|
// account detail screen
|
||||||
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
|
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
|
||||||
showSendPage: showSendPage,
|
showSendPage: showSendPage,
|
||||||
|
ADD_TO_ADDRESS_BOOK: 'ADD_TO_ADDRESS_BOOK',
|
||||||
|
addToAddressBook: addToAddressBook,
|
||||||
REQUEST_ACCOUNT_EXPORT: 'REQUEST_ACCOUNT_EXPORT',
|
REQUEST_ACCOUNT_EXPORT: 'REQUEST_ACCOUNT_EXPORT',
|
||||||
requestExportAccount: requestExportAccount,
|
requestExportAccount: requestExportAccount,
|
||||||
EXPORT_ACCOUNT: 'EXPORT_ACCOUNT',
|
EXPORT_ACCOUNT: 'EXPORT_ACCOUNT',
|
||||||
@ -696,6 +698,18 @@ function setRpcTarget (newRpc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToAddressBook (recipient, nickname) {
|
||||||
|
log.debug(`background.addToAddressBook`)
|
||||||
|
return (dispatch) => {
|
||||||
|
background.setAddressBook(recipient, nickname, (err, result) => {
|
||||||
|
if (err) {
|
||||||
|
log.error(err)
|
||||||
|
return dispatch(self.displayWarning('Address book failed to update'))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setProviderType (type) {
|
function setProviderType (type) {
|
||||||
log.debug(`background.setProviderType`)
|
log.debug(`background.setProviderType`)
|
||||||
background.setProviderType(type)
|
background.setProviderType(type)
|
||||||
|
@ -59,6 +59,12 @@ EnsInput.prototype.render = function () {
|
|||||||
label: identity.name,
|
label: identity.name,
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
props.addressBook.map((identity) => {
|
||||||
|
return h('option', {
|
||||||
|
value: identity.address,
|
||||||
|
label: identity.name,
|
||||||
|
})
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
this.ensIcon(),
|
this.ensIcon(),
|
||||||
])
|
])
|
||||||
@ -94,11 +100,13 @@ EnsInput.prototype.lookupEnsName = function () {
|
|||||||
this.setState({
|
this.setState({
|
||||||
loadingEns: false,
|
loadingEns: false,
|
||||||
ensResolution: address,
|
ensResolution: address,
|
||||||
|
nickname: recipient.trim(),
|
||||||
hoverText: address + '\nClick to Copy',
|
hoverText: address + '\nClick to Copy',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
|
log.error(reason)
|
||||||
return this.setState({
|
return this.setState({
|
||||||
loadingEns: false,
|
loadingEns: false,
|
||||||
ensFailure: true,
|
ensFailure: true,
|
||||||
@ -109,10 +117,11 @@ EnsInput.prototype.lookupEnsName = function () {
|
|||||||
|
|
||||||
EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) {
|
EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) {
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
const { ensResolution } = state
|
const ensResolution = state.ensResolution
|
||||||
|
const nickname = state.nickname || ' '
|
||||||
if (ensResolution && this.props.onChange &&
|
if (ensResolution && this.props.onChange &&
|
||||||
ensResolution !== prevState.ensResolution) {
|
ensResolution !== prevState.ensResolution) {
|
||||||
this.props.onChange(ensResolution)
|
this.props.onChange(ensResolution, nickname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ function mapStateToProps (state) {
|
|||||||
identities: state.metamask.identities,
|
identities: state.metamask.identities,
|
||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
|
addressBook: state.metamask.addressBook,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.error = result.warning && result.warning.split('.')[0]
|
result.error = result.warning && result.warning.split('.')[0]
|
||||||
@ -45,6 +46,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
var identity = state.identity
|
var identity = state.identity
|
||||||
var network = state.network
|
var network = state.network
|
||||||
var identities = state.identities
|
var identities = state.identities
|
||||||
|
var addressBook = state.addressBook
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -155,6 +157,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
onChange: this.recipientDidChange.bind(this),
|
onChange: this.recipientDidChange.bind(this),
|
||||||
network,
|
network,
|
||||||
identities,
|
identities,
|
||||||
|
addressBook,
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
@ -224,13 +227,17 @@ SendTransactionScreen.prototype.back = function () {
|
|||||||
this.props.dispatch(actions.backToAccountDetail(address))
|
this.props.dispatch(actions.backToAccountDetail(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.recipientDidChange = function (recipient) {
|
SendTransactionScreen.prototype.recipientDidChange = function (recipient, nickname) {
|
||||||
this.setState({ recipient })
|
this.setState({
|
||||||
|
recipient: recipient,
|
||||||
|
nickname: nickname,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.onSubmit = function () {
|
SendTransactionScreen.prototype.onSubmit = function () {
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
const recipient = state.recipient || document.querySelector('input[name="address"]').value
|
const recipient = state.recipient || document.querySelector('input[name="address"]').value
|
||||||
|
const nickname = state.nickname || ' '
|
||||||
const input = document.querySelector('input[name="amount"]').value
|
const input = document.querySelector('input[name="amount"]').value
|
||||||
const value = util.normalizeEthStringToWei(input)
|
const value = util.normalizeEthStringToWei(input)
|
||||||
const txData = document.querySelector('input[name="txData"]').value
|
const txData = document.querySelector('input[name="txData"]').value
|
||||||
@ -259,6 +266,8 @@ SendTransactionScreen.prototype.onSubmit = function () {
|
|||||||
|
|
||||||
this.props.dispatch(actions.hideWarning())
|
this.props.dispatch(actions.hideWarning())
|
||||||
|
|
||||||
|
this.props.dispatch(actions.addToAddressBook(recipient, nickname))
|
||||||
|
|
||||||
var txParams = {
|
var txParams = {
|
||||||
from: this.props.address,
|
from: this.props.address,
|
||||||
value: '0x' + value.toString(16),
|
value: '0x' + value.toString(16),
|
||||||
|
Loading…
Reference in New Issue
Block a user