Skip to content

Commit

Permalink
fixed bug invalid private key provided during import
Browse files Browse the repository at this point in the history
  • Loading branch information
backslash47 committed Jan 14, 2019
1 parent e2bc4d0 commit 46535da
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 176 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cyano-wallet",
"version": "0.7.5",
"version": "0.7.6",
"private": true,
"scripts": {
"lint": "tslint -p .",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Cyano wallet",
"author": "Matus Zamborsky <[email protected]>",
"description": "Cyano wallet - an Ontology wallet",
"version": "0.7.5",
"version": "0.7.6",

"browser_action": {
"default_title": "Open the wallet"
Expand Down
82 changes: 47 additions & 35 deletions src/popup/pages/identity/import/identityImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with The Ontology Wallet&ID. If not, see <http://www.gnu.org/licenses/>.
*/
import { get } from 'lodash';
import { get } from 'lodash';
import * as React from 'react';
import { RouterProps } from 'react-router';
import { bindActionCreators, Dispatch } from 'redux';
Expand All @@ -28,51 +28,63 @@ import { IdentityImportView, Props } from './identityImportView';

const mapStateToProps = (state: GlobalState) => ({
loading: state.loader.loading,
walletEncoded: state.wallet.wallet
walletEncoded: state.wallet.wallet,
});

const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
finishLoading: Actions.loader.finishLoading,
setWallet: Actions.wallet.setWallet,
startLoading: Actions.loader.startLoading
}, dispatch);
const mapDispatchToProps = (dispatch: Dispatch) =>
bindActionCreators(
{
finishLoading: Actions.loader.finishLoading,
setWallet: Actions.wallet.setWallet,
startLoading: Actions.loader.startLoading,
},
dispatch,
);

const enhancer = (Component: React.ComponentType<Props>) => (props: RouterProps) => (
reduxConnect(mapStateToProps, mapDispatchToProps, (reduxProps, actions, getReduxProps) => (
withProps({
handleCancel: () => {
props.history.goBack();
},
handleSubmit: async (values: object) => {
const wallet = getWallet(reduxProps.walletEncoded!);
const enhancer = (Component: React.ComponentType<Props>) => (props: RouterProps) =>
reduxConnect(mapStateToProps, mapDispatchToProps, (reduxProps, actions, getReduxProps) =>
withProps(
{
handleCancel: () => {
props.history.goBack();
},
handleSubmit: async (values: object) => {
const wallet = getWallet(reduxProps.walletEncoded!);

const password = get(values, 'password', '');
const wif = get(values, 'privateKey', '');
const password = get(values, 'password', '');
const wif = get(values, 'privateKey', '');

await actions.startLoading();
await actions.startLoading();

const { identity } = identityImportPrivateKey(wif, password, wallet.scrypt);
try {
const { identity } = identityImportPrivateKey(wif, password, wallet.scrypt);

const ontIdExist = await getBackgroundManager().checkOntId(identity.toJson(), password);
const ontIdExist = await getBackgroundManager().checkOntId(identity.toJson(), password);

await actions.finishLoading();
await actions.finishLoading();

if (ontIdExist) {
wallet.addIdentity(identity);
wallet.setDefaultIdentity(identity.ontid);
if (ontIdExist) {
wallet.addIdentity(identity);
wallet.setDefaultIdentity(identity.ontid);

await actions.setWallet(wallet.toJson());
await actions.setWallet(wallet.toJson());

props.history.push('/identity/dashboard');
} else {
props.history.push('/identity/checkFailed');
}
props.history.push('/identity/dashboard');
} else {
props.history.push('/identity/checkFailed');
}
return {};
} catch (e) {
await actions.finishLoading();

},
}, (injectedProps) => (
<Component {...injectedProps} loading={reduxProps.loading} />
))
))
)
return {
privateKey: 'Invaid private key',
};
}
},
},
(injectedProps) => <Component {...injectedProps} loading={reduxProps.loading} />,
),
);

export const IdentityImport = enhancer(IdentityImportView);
144 changes: 77 additions & 67 deletions src/popup/pages/identity/import/identityImportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
import * as React from 'react';
import { Field, Form } from 'react-final-form';
import { Button, Form as SemanticForm } from 'semantic-ui-react';
import { Button, Form as SemanticForm, Message } from 'semantic-ui-react';
import { Filler, LogoHeader, Spacer, StatusBar, View } from '../../../components';
import { required, samePassword } from '../../../utils/validate';

export interface Props {
handleSubmit: (values: object) => Promise<void>;
handleSubmit: (values: object) => Promise<object>;
handleCancel: () => void;
loading: boolean;
}
Expand All @@ -36,74 +36,84 @@ export const IdentityImportView: React.SFC<Props> = (props) => (
</View>
</View>
<View orientation="column" fluid={true} content={true} className="spread-around">
<Form
onSubmit={props.handleSubmit}
validate={samePassword}
render={(formProps) => (
<SemanticForm onSubmit={formProps.handleSubmit} className="signupForm">
<View orientation="column">
<label>Private key (WIF or HEX format)</label>
<Field
name="privateKey"
validate={required}
render={(t) => (
<SemanticForm.TextArea
rows={2}
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
<View orientation="column" className="scrollView">
<View className="content">
<Form
onSubmit={props.handleSubmit}
validate={samePassword}
render={(formProps) => (
<SemanticForm onSubmit={formProps.handleSubmit} className="signupForm">
<View orientation="column">
<label>Private key (WIF or HEX format)</label>
<Field
name="privateKey"
validate={required}
render={(t) => (
<>
{t.meta.touched && t.meta.submitError != null ? (
<Message size="small">{t.meta.submitError}</Message>
) : null}
<SemanticForm.TextArea
rows={2}
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
/>
</>
)}
/>
)}
/>
</View>
<Spacer />
<View orientation="column">
<label>Password</label>
<Field
name="password"
validate={required}
render={(t) => (
<SemanticForm.Input
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
icon="key"
type="password"
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
</View>
<Spacer />
<View orientation="column">
<label>Password</label>
<Field
name="password"
validate={required}
render={(t) => (
<SemanticForm.Input
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
icon="key"
type="password"
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
/>
)}
/>
)}
/>
</View>
<Spacer />
<View orientation="column">
<label>Password again</label>
<Field
name="passwordAgain"
render={(t) => (
<SemanticForm.Input
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
icon="key"
type="password"
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
</View>
<Spacer />
<View orientation="column">
<label>Password again</label>
<Field
name="passwordAgain"
render={(t) => (
<SemanticForm.Input
onChange={t.input.onChange}
input={{ ...t.input, value: t.input.value }}
icon="key"
type="password"
error={t.meta.touched && t.meta.invalid}
disabled={props.loading}
/>
)}
/>
)}
/>
</View>
<Filler />
<View className="buttons">
<Button disabled={props.loading} loading={props.loading}>
Restore
</Button>
<Button disabled={props.loading} onClick={props.handleCancel}>
Cancel
</Button>
</View>
</SemanticForm>
)}
/>
</View>
<Spacer />
<Filler />
<View className="buttons">
<Button disabled={props.loading} loading={props.loading}>
Restore
</Button>
<Button disabled={props.loading} onClick={props.handleCancel}>
Cancel
</Button>
</View>
</SemanticForm>
)}
/>
</View>
</View>
</View>
<StatusBar />
</View>
Expand Down
20 changes: 15 additions & 5 deletions src/popup/pages/import/import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ const enhancer = (Component: React.ComponentType<Props>) => (props: RouterProps)

await actions.startLoading();

const { wallet } = accountImportPrivateKey(privateKey, password, reduxProps.wallet);
await actions.setWallet(wallet);
try {
const { wallet } = accountImportPrivateKey(privateKey, password, reduxProps.wallet);
await actions.setWallet(wallet);

await getBackgroundManager().refreshBalance();
await getBackgroundManager().refreshBalance();

await actions.finishLoading();
await actions.finishLoading();

props.history.push('/dashboard');
props.history.push('/dashboard');

return {};
} catch (e) {
await actions.finishLoading();

return {
privateKey: 'Invaid private key',
};
}
},
},
(injectedProps) => <Component {...injectedProps} loading={reduxProps.loading} />,
Expand Down
Loading

0 comments on commit 46535da

Please sign in to comment.