From 63e7eb89e46aeb8a2ff359b65f1c8b5f33f2090c Mon Sep 17 00:00:00 2001 From: crptm Date: Fri, 30 Jun 2017 03:03:11 +0400 Subject: [PATCH] unlock wip --- .eslintrc.json | 9 +- common/actions/wallet.js | 29 ++++ .../WalletDecrypt/Keystore.jsx} | 0 .../WalletDecrypt/LedgerNano.jsx} | 0 .../WalletDecrypt/Mnemonic.jsx} | 0 .../components/WalletDecrypt/PrivateKey.jsx | 95 +++++++++++ .../WalletDecrypt/Trezor.jsx} | 0 .../WalletDecrypt/ViewOnly.jsx} | 0 common/components/WalletDecrypt/index.jsx | 161 ++++++++++++++++++ common/components/ui/UnlockHeader.jsx | 43 ++++- .../containers/Tabs/SendTransaction/index.jsx | 23 ++- common/containers/Tabs/ViewWallet/index.jsx | 26 +++ .../WalletDecrypt/PrivateKeyDecrypt/index.jsx | 21 --- .../containers/Tabs/WalletDecrypt/index.jsx | 129 -------------- common/index.jsx | 21 +-- common/libs/validators.js | 4 + common/libs/wallet/base.js | 7 + common/libs/wallet/privkey.js | 24 +++ common/reducers/index.js | 7 +- common/reducers/wallet.js | 20 +++ common/routing/index.jsx | 3 +- common/sagas/wallet.js | 14 ++ 22 files changed, 454 insertions(+), 182 deletions(-) create mode 100644 common/actions/wallet.js rename common/{containers/Tabs/WalletDecrypt/KeystoreDecrypt/index.jsx => components/WalletDecrypt/Keystore.jsx} (100%) rename common/{containers/Tabs/WalletDecrypt/LedgerNanoSDecrypt/index.jsx => components/WalletDecrypt/LedgerNano.jsx} (100%) rename common/{containers/Tabs/WalletDecrypt/MnemonicDecrypt/index.jsx => components/WalletDecrypt/Mnemonic.jsx} (100%) create mode 100644 common/components/WalletDecrypt/PrivateKey.jsx rename common/{containers/Tabs/WalletDecrypt/TrezorDecrypt/index.jsx => components/WalletDecrypt/Trezor.jsx} (100%) rename common/{containers/Tabs/WalletDecrypt/ViewOnlyDecrypt/index.jsx => components/WalletDecrypt/ViewOnly.jsx} (100%) create mode 100644 common/components/WalletDecrypt/index.jsx create mode 100644 common/containers/Tabs/ViewWallet/index.jsx delete mode 100644 common/containers/Tabs/WalletDecrypt/PrivateKeyDecrypt/index.jsx delete mode 100644 common/containers/Tabs/WalletDecrypt/index.jsx create mode 100644 common/libs/wallet/base.js create mode 100644 common/libs/wallet/privkey.js create mode 100644 common/reducers/wallet.js create mode 100644 common/sagas/wallet.js diff --git a/.eslintrc.json b/.eslintrc.json index 9f0c853c..d6212d8e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,7 @@ { "extends": ["eslint:recommended", "plugin:react/recommended"], "parser": "babel-eslint", - "plugins": [ - "react" - ], + "plugins": ["react"], "parserOptions": { "ecmaFeatures": { "jsx": true, @@ -19,7 +17,7 @@ }, "rules": { "comma-dangle": 1, - "quotes": [ 1, "single" ], + "quotes": [1, "single"], "no-undef": 1, "global-strict": 0, "no-extra-semi": 1, @@ -32,6 +30,7 @@ "react/jsx-uses-react": 1 }, "globals": { - "SyntheticInputEvent": false + "SyntheticInputEvent": false, + "SyntheticKeyboardEvent": false } } diff --git a/common/actions/wallet.js b/common/actions/wallet.js new file mode 100644 index 00000000..656c0ba1 --- /dev/null +++ b/common/actions/wallet.js @@ -0,0 +1,29 @@ +// @flow +import type { PrivateKeyUnlockParams } from 'libs/wallet/privkey'; +import BaseWallet from 'libs/wallet/base'; + +export type UnlockPrivateKeyAction = { + type: 'WALLET_UNLOCK_PRIVATE_KEY', + payload: PrivateKeyUnlockParams +}; + +export type SaveWalletAction = { + type: 'WALLET_SAVE', + payload: BaseWallet +}; + +export type WalletAction = UnlockPrivateKeyAction | SaveWalletAction; + +export function unlockPrivateKey(value: PrivateKeyUnlockParams): UnlockPrivateKeyAction { + return { + type: 'WALLET_UNLOCK_PRIVATE_KEY', + payload: value + }; +} + +export function saveWallet(value: BaseWallet): SaveWalletAction { + return { + type: 'WALLET_SAVE', + payload: value + }; +} diff --git a/common/containers/Tabs/WalletDecrypt/KeystoreDecrypt/index.jsx b/common/components/WalletDecrypt/Keystore.jsx similarity index 100% rename from common/containers/Tabs/WalletDecrypt/KeystoreDecrypt/index.jsx rename to common/components/WalletDecrypt/Keystore.jsx diff --git a/common/containers/Tabs/WalletDecrypt/LedgerNanoSDecrypt/index.jsx b/common/components/WalletDecrypt/LedgerNano.jsx similarity index 100% rename from common/containers/Tabs/WalletDecrypt/LedgerNanoSDecrypt/index.jsx rename to common/components/WalletDecrypt/LedgerNano.jsx diff --git a/common/containers/Tabs/WalletDecrypt/MnemonicDecrypt/index.jsx b/common/components/WalletDecrypt/Mnemonic.jsx similarity index 100% rename from common/containers/Tabs/WalletDecrypt/MnemonicDecrypt/index.jsx rename to common/components/WalletDecrypt/Mnemonic.jsx diff --git a/common/components/WalletDecrypt/PrivateKey.jsx b/common/components/WalletDecrypt/PrivateKey.jsx new file mode 100644 index 00000000..c8cd8e98 --- /dev/null +++ b/common/components/WalletDecrypt/PrivateKey.jsx @@ -0,0 +1,95 @@ +// @flow +import React, { Component } from 'react'; +import translate from 'translations'; +import { isValidPrivKey } from 'libs/validators'; +import type { PrivateKeyUnlockParams } from 'libs/wallet/privkey'; + +export type PrivateKeyValue = PrivateKeyUnlockParams & { + valid: boolean +}; + +function fixPkey(key) { + if (key.indexOf('0x') === 0) { + return key.slice(2); + } + return key; +} + +export default class PrivateKeyDecrypt extends Component { + props: { + value: PrivateKeyUnlockParams, + onChange: (value: PrivateKeyUnlockParams) => void, + onUnlock: () => void + }; + + render() { + const { key, password } = this.props.value; + const fixedPkey = fixPkey(key); + const isValid = isValidPrivKey(fixedPkey.length); + const isPassRequired = fixedPkey.length > 64; + + return ( +
+
+

+ {translate('ADD_Radio_3')} +

+
+