Skip to content

Commit

Permalink
Merge pull request #1845 from CityOfZion/feature/watch-address
Browse files Browse the repository at this point in the history
feature: adds watch only address (part I)
  • Loading branch information
comountainclimber committed May 16, 2019
2 parents f71e922 + 4667dd5 commit 9992a0b
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 5 deletions.
18 changes: 18 additions & 0 deletions app/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type WifLoginProps = {
wif: string,
}

type WatchOnlyLoginProps = {
address: string,
}

type LedgerLoginProps = {
publicKey: string,
signingFunction: Function,
Expand Down Expand Up @@ -51,6 +55,20 @@ export const wifLoginActions = createActions(
},
)

export const watchOnlyLoginActions = createActions(
ID,
({ address }: WatchOnlyLoginProps) => (): AccountType => {
if (!wallet.isAddress(address)) {
throw new Error('Invalid public key entered')
}

return {
address,
isHardwareLogin: false,
}
},
)

export const nep2LoginActions = createActions(
ID,
({ passphrase, encryptedWIF }: Nep2LoginProps) => async (): Promise<
Expand Down
2 changes: 1 addition & 1 deletion app/containers/EditWallet/EditWallet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
width: 100%;
height: 100%;
flex-direction: column;
width: 500px;
width: 550px;
margin-bottom: auto;
}

Expand Down
6 changes: 5 additions & 1 deletion app/containers/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import LoginPrivateKey from '../LoginPrivateKey'
import LoginNep2 from '../LoginNep2'
import LoginLedgerNanoS from '../LoginLedgerNanoS'
import LoginLocalStorage from '../LoginLocalStorage'
import LoginWatchOnly from '../LoginWatchOnly'
import Button from '../../components/Button'
import styles from './Home.scss'
import AddIcon from '../../assets/icons/add.svg'
Expand All @@ -18,7 +19,6 @@ import pack from '../../../package.json'
type State = {
tabIndex: number,
}

type Props = {
loading: boolean,
theme: ThemeType,
Expand All @@ -37,6 +37,10 @@ const LOGIN_OPTIONS = {
render: () => <LoginNep2 />,
display: 'Encrypted Key',
},
watch: {
render: () => <LoginWatchOnly />,
display: 'Watch only',
},
ledger: {
render: () => <LoginLedgerNanoS />,
display: 'Ledger',
Expand Down
4 changes: 2 additions & 2 deletions app/containers/Home/Home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ $navigation-margin: 20px;
align-items: center;
margin: auto;
min-height: 550px;
width: 600px;
width: 650px;
}

.buttonRow {
Expand Down Expand Up @@ -259,7 +259,7 @@ $navigation-margin: 20px;
.inputContainer {
display: flex;
flex-direction: column;
width: 500px;
width: 550px;
align-items: center;
}

Expand Down
62 changes: 62 additions & 0 deletions app/containers/LoginWatchOnly/LoginWatchOnly.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @flow
import React from 'react'

import Button from '../../components/Button'
import LoginIcon from '../../assets/icons/login.svg'
import styles from '../Home/Home.scss'
import TextInput from '../../components/Inputs/TextInput'

type Props = {
watchOnlyLogin: (content: string) => void,
}

type State = {
address: string,
}

export default class LoginPrivateKey extends React.Component<Props, State> {
state = {
address: '',
}

render = () => {
const { watchOnlyLogin } = this.props
const { address } = this.state

return (
<div id="loginPrivateKey" className={styles.flexContainer}>
<form
onSubmit={e => {
e.preventDefault()
watchOnlyLogin(address)
}}
>
<React.Fragment>
<div className={styles.centeredInput}>
<TextInput
textInputClassName={styles.privateKeyInput}
placeholder="Enter a public key here"
value={address}
onChange={(e: Object) =>
this.setState({ address: e.target.value })
}
autoFocus
/>
</div>
<div className={styles.privateKeyLoginButtonRow}>
<Button
id="loginButton"
primary
type="submit"
renderIcon={LoginIcon}
disabled={address.length < 10}
>
Login
</Button>
</div>
</React.Fragment>
</form>
</div>
)
}
}
17 changes: 17 additions & 0 deletions app/containers/LoginWatchOnly/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
import { compose } from 'recompose'
import { withActions, withProgress } from 'spunky'

import LoginWatchOnly from './LoginWatchOnly'
import withFailureNotification from '../../hocs/withFailureNotification'
import { watchOnlyLoginActions } from '../../actions/authActions'

const mapActionsToProps = actions => ({
watchOnlyLogin: address => actions.call({ address }),
})

export default compose(
withActions(watchOnlyLoginActions, mapActionsToProps),
withFailureNotification(watchOnlyLoginActions),
withProgress(watchOnlyLoginActions),
)(LoginWatchOnly)
2 changes: 1 addition & 1 deletion app/styles/main.global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ input::placeholder {
li {
display: flex;
margin: auto;
font-size: 12px;
font-size: 11px;
color: #ced0d4;
cursor: pointer;
padding-bottom: 10px;
Expand Down

0 comments on commit 9992a0b

Please sign in to comment.