From 91c854f2e12c582124a2dcb4228bbabe4d0a4029 Mon Sep 17 00:00:00 2001 From: Daniel Kaspo Date: Tue, 13 Jun 2017 19:56:27 -0400 Subject: [PATCH] Replaced component with key in wallet-decrypt state. --- .../containers/Tabs/WalletDecrypt/index.jsx | 99 ++++++++++--------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/common/containers/Tabs/WalletDecrypt/index.jsx b/common/containers/Tabs/WalletDecrypt/index.jsx index b2e89241..529041f0 100644 --- a/common/containers/Tabs/WalletDecrypt/index.jsx +++ b/common/containers/Tabs/WalletDecrypt/index.jsx @@ -7,54 +7,60 @@ import LedgerNanoSDecrypt from './LedgerNanoSDecrypt'; import TrezorDecrypt from './TrezorDecrypt'; import ViewOnlyDecrypt from './ViewOnlyDecrypt'; -const decryptionChoices = [ - { - name: 'keystore-file', - lid: 'x_Keystore2', - component: KeystoreDecrypt - }, - { - name: 'private-key', - lid: 'x_PrivKey2', - component: PrivateKeyDecrypt - }, - { - name: 'mnemonic-phrase', - lid: 'x_Mnemonic', - component: MnemonicDecrypt - }, - { - name: 'ledger-nano-s', - lid: 'x_Ledger', - component: LedgerNanoSDecrypt - }, - { - name: 'trezor', - lid: 'x_Trezor', - component: TrezorDecrypt - }, - { - name: 'view-only', - lid: 'View with Address Only', - component: ViewOnlyDecrypt - } -]; - export default class WalletDecrypt extends Component { constructor(props) { super(props); - // functions called by things like onChange need to be bound in this way. - // https://github.com/goatslacker/alt/issues/283#issuecomment-107463147 - this.handleDecryptionChoiceChange = this.handleDecryptionChoiceChange.bind(this); + this.decryptionChoices = [ + { + name: 'keystore-file', + lid: 'x_Keystore2', + component: KeystoreDecrypt + }, + { + name: 'private-key', + lid: 'x_PrivKey2', + component: PrivateKeyDecrypt + }, + { + name: 'mnemonic-phrase', + lid: 'x_Mnemonic', + component: MnemonicDecrypt + }, + { + name: 'ledger-nano-s', + lid: 'x_Ledger', + component: LedgerNanoSDecrypt + }, + { + name: 'trezor', + lid: 'x_Trezor', + component: TrezorDecrypt + }, + { + name: 'view-only', + lid: 'View with Address Only', + component: ViewOnlyDecrypt + } + ]; this.state = { - decryptionComponent: null + decryptionChoice: this.decryptionChoices[0].name // auto-select first option. }; } + getDecryptionComponent() { + const selectedDecryptionChoice = this.decryptionChoices.find((decryptionChoice) => { + return this.state.decryptionChoice === decryptionChoice.name; + }); + + return selectedDecryptionChoice.component; + } + buildDecryptionChoices() { - return decryptionChoices.map((decryptionChoice, idx) => { + return this.decryptionChoices.map((decryptionChoice, idx) => { + const isSelected = this.state.decryptionChoice === decryptionChoice.name; + return (