mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add ability to import v3 JSON wallets
There is now a menu item labeled "JSON File" for importing, and it can digest either: - v1 MyEtherWallet JSON files - v3 Account files (used by Geth, Mist, and MyEtherWallet). Fixes #715
This commit is contained in:
parent
9126652f2e
commit
5d8a3dd99b
@ -7,8 +7,7 @@ const accountImporter = {
|
|||||||
importAccount(strategy, args) {
|
importAccount(strategy, args) {
|
||||||
try {
|
try {
|
||||||
const importer = this.strategies[strategy]
|
const importer = this.strategies[strategy]
|
||||||
const wallet = importer.apply(null, args)
|
const privateKeyHex = importer.apply(null, args)
|
||||||
const privateKeyHex = walletToPrivateKey(wallet)
|
|
||||||
return Promise.resolve(privateKeyHex)
|
return Promise.resolve(privateKeyHex)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
@ -18,11 +17,20 @@ const accountImporter = {
|
|||||||
strategies: {
|
strategies: {
|
||||||
'Private Key': (privateKey) => {
|
'Private Key': (privateKey) => {
|
||||||
const stripped = ethUtil.stripHexPrefix(privateKey)
|
const stripped = ethUtil.stripHexPrefix(privateKey)
|
||||||
const buffer = new Buffer(stripped, 'hex')
|
return stripped
|
||||||
return Wallet.fromPrivateKey(buffer)
|
|
||||||
},
|
},
|
||||||
'JSON File': (input, password) => {
|
'JSON File': (input, password) => {
|
||||||
const wallet = importers.fromEtherWallet(input, password)
|
let wallet
|
||||||
|
try {
|
||||||
|
wallet = importers.fromEtherWallet(input, password)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Attempt to import as EtherWallet format failed, trying V3...')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wallet) {
|
||||||
|
wallet = Wallet.fromV3(input, password, true)
|
||||||
|
}
|
||||||
|
|
||||||
return walletToPrivateKey(wallet)
|
return walletToPrivateKey(wallet)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -267,7 +267,7 @@ function addNewKeyring (type, opts) {
|
|||||||
|
|
||||||
function importNewAccount (strategy, args) {
|
function importNewAccount (strategy, args) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
|
||||||
background.importAccountWithStrategy(strategy, args, (err, newState) => {
|
background.importAccountWithStrategy(strategy, args, (err, newState) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
@ -630,9 +630,10 @@ function useEtherscanProvider () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showLoadingIndication () {
|
function showLoadingIndication (message) {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_LOADING,
|
type: actions.SHOW_LOADING,
|
||||||
|
value: message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ function mapStateToProps (state) {
|
|||||||
return {
|
return {
|
||||||
// state from plugin
|
// state from plugin
|
||||||
isLoading: state.appState.isLoading,
|
isLoading: state.appState.isLoading,
|
||||||
|
loadingMessage: state.appState.loadingMessage,
|
||||||
isDisclaimerConfirmed: state.metamask.isDisclaimerConfirmed,
|
isDisclaimerConfirmed: state.metamask.isDisclaimerConfirmed,
|
||||||
noActiveNotices: state.metamask.noActiveNotices,
|
noActiveNotices: state.metamask.noActiveNotices,
|
||||||
isInitialized: state.metamask.isInitialized,
|
isInitialized: state.metamask.isInitialized,
|
||||||
@ -64,7 +65,7 @@ function mapStateToProps (state) {
|
|||||||
|
|
||||||
App.prototype.render = function () {
|
App.prototype.render = function () {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
const { isLoading, transForward } = props
|
const { isLoading, loadingMessage, transForward } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ App.prototype.render = function () {
|
|||||||
},
|
},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
h(LoadingIndicator, { isLoading }),
|
h(LoadingIndicator, { isLoading, loadingMessage }),
|
||||||
|
|
||||||
// app bar
|
// app bar
|
||||||
this.renderAppBar(),
|
this.renderAppBar(),
|
||||||
|
@ -12,7 +12,7 @@ function LoadingIndicator () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LoadingIndicator.prototype.render = function () {
|
LoadingIndicator.prototype.render = function () {
|
||||||
var isLoading = this.props.isLoading
|
const { isLoading, loadingMessage } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h(ReactCSSTransitionGroup, {
|
h(ReactCSSTransitionGroup, {
|
||||||
@ -37,8 +37,14 @@ LoadingIndicator.prototype.render = function () {
|
|||||||
h('img', {
|
h('img', {
|
||||||
src: 'images/loading.svg',
|
src: 'images/loading.svg',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
showMessageIfAny(loadingMessage),
|
||||||
]) : null,
|
]) : null,
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showMessageIfAny (loadingMessage) {
|
||||||
|
if (!loadingMessage) return null
|
||||||
|
return h('span', loadingMessage)
|
||||||
|
}
|
||||||
|
@ -386,6 +386,7 @@ function reduceApp (state, action) {
|
|||||||
case actions.SHOW_LOADING:
|
case actions.SHOW_LOADING:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
loadingMessage: action.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
case actions.HIDE_LOADING:
|
case actions.HIDE_LOADING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user