This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
fix: Relates to #138. Prevents user from importing account that is already in account list #327
Merged
amaury1093
merged 10 commits into
master
from
luke-138-prevent-import-when-account-already-loaded
Jan 7, 2019
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cced0a0
fix: Fixes #138. Prevent user from importing a JSON file with address…
ltfschoen 2f22197
fix: Fixes #138. Prevent user from recovering address from Seed Phras…
ltfschoen 18c545d
refactor: Fix eslint error
ltfschoen 3816b29
review-fix: Import accounts$ from light.js instead of accountsInfo$
ltfschoen 0d99be3
review-fix: Show short address in notification when accout already li…
ltfschoen aaff1d2
Merge branch 'master' into luke-138-prevent-import-when-account-alrea…
ltfschoen 341a124
Merge branch 'master' into luke-138-prevent-import-when-account-alrea…
ltfschoen 929d29f
review-fix: Call toLowerCase on address in this.hasExistingAddressFor…
ltfschoen cff2a59
review-fix: Use parsed address saved in createAccountStore.address in…
ltfschoen 6296cc6
Merge branch 'master' into luke-138-prevent-import-when-account-alrea…
amaury1093 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,14 @@ | |
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import React, { Component } from 'react'; | ||
import { Card, Form as FetherForm } from 'fether-ui'; | ||
import { addressShort, Card, Form as FetherForm } from 'fether-ui'; | ||
import { accounts$, withoutLoading } from '@parity/light.js'; | ||
import light from '@parity/light.js-react'; | ||
import { inject, observer } from 'mobx-react'; | ||
|
||
@light({ | ||
accounts: () => accounts$().pipe(withoutLoading()) | ||
}) | ||
@inject('createAccountStore') | ||
@observer | ||
class AccountImportOptions extends Component { | ||
|
@@ -32,19 +37,29 @@ class AccountImportOptions extends Component { | |
handleSubmitPhrase = async () => { | ||
const phrase = this.state.phrase.trim(); | ||
const { | ||
createAccountStore, | ||
createAccountStore: { setPhrase } | ||
} = this.props; | ||
|
||
this.setState({ isLoading: true, phrase }); | ||
|
||
try { | ||
await setPhrase(phrase); | ||
|
||
const addressForPhrase = createAccountStore.address.toLowerCase(); | ||
|
||
if (this.hasExistingAddressForImport(addressForPhrase)) { | ||
return; | ||
} | ||
|
||
this.handleNextStep(); | ||
} catch (e) { | ||
} catch (error) { | ||
this.setState({ | ||
isLoading: false, | ||
error: | ||
'The passphrase was not recognized. Please verify that you entered your passphrase correctly.' | ||
}); | ||
console.error(error); | ||
} | ||
}; | ||
|
||
|
@@ -54,7 +69,15 @@ class AccountImportOptions extends Component { | |
} = this.props; | ||
|
||
this.setState({ isLoading: true }); | ||
|
||
try { | ||
const json = JSON.parse(jsonString); | ||
const jsonAddress = `0x${json['address'].toLowerCase()}`; | ||
|
||
if (this.hasExistingAddressForImport(jsonAddress)) { | ||
return; | ||
} | ||
|
||
await setJsonString(jsonString); | ||
this.handleNextStep(); | ||
} catch (error) { | ||
|
@@ -67,6 +90,22 @@ class AccountImportOptions extends Component { | |
} | ||
}; | ||
|
||
hasExistingAddressForImport = addressForImport => { | ||
const { accounts } = this.props; | ||
const isExistingAddress = accounts | ||
.map(address => address && address.toLowerCase()) | ||
.includes(addressForImport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put |
||
|
||
if (isExistingAddress) { | ||
this.setState({ | ||
isLoading: false, | ||
error: `Account ${addressShort(addressForImport)} already listed` | ||
}); | ||
} | ||
|
||
return isExistingAddress; | ||
}; | ||
|
||
render () { | ||
const { | ||
history, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2015-2018 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
export const addressShort = address => | ||
address ? `${address.slice(0, 6)}..${address.slice(-4)}` : ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright 2015-2018 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
export * from './addressShort'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not parse here.
3 lines below, the
await setJsonString(jsonString);
actually parses the JSON, and createAccountStore.address will hold the parsed address. Do thehasExistingAddressForImport
then.