Skip to content

Commit

Permalink
feat(onboarding): allow setting wallet name
Browse files Browse the repository at this point in the history
Allow setting the wallet name in the onboarding process rather than
the wallet alias. This makes more sense since local wallets operate
in private mode and therefore do not broadcast their address or alias
to the network.

Fix LN-Zap#1025
  • Loading branch information
mrfelton committed Dec 4, 2018
1 parent bfbe5aa commit 54be043
Show file tree
Hide file tree
Showing 44 changed files with 228 additions and 52 deletions.
14 changes: 7 additions & 7 deletions app/components/Onboarding/Onboarding.js
Expand Up @@ -5,13 +5,13 @@ import { FormattedMessage } from 'react-intl'
import { Flex, Box } from 'rebass'
import { Panel, Wizard } from 'components/UI'
import {
Alias,
Autopilot,
BtcPayServer,
ConnectionType,
ConnectionDetails,
ConnectionConfirm,
Login,
Name,
Password,
Recover,
SeedConfirm,
Expand All @@ -24,8 +24,8 @@ import messages from './messages'
class Onboarding extends React.Component {
static propTypes = {
// STATE
alias: PropTypes.string,
autopilot: PropTypes.bool,
name: PropTypes.string,
connectionType: PropTypes.string,
connectionHost: PropTypes.string,
connectionCert: PropTypes.string,
Expand All @@ -44,13 +44,13 @@ class Onboarding extends React.Component {
fetchSeed: PropTypes.func.isRequired,
recoverOldWallet: PropTypes.func.isRequired,
resetOnboarding: PropTypes.func.isRequired,
setAlias: PropTypes.func.isRequired,
setAutopilot: PropTypes.func.isRequired,
setConnectionType: PropTypes.func.isRequired,
setConnectionHost: PropTypes.func.isRequired,
setConnectionCert: PropTypes.func.isRequired,
setConnectionMacaroon: PropTypes.func.isRequired,
setConnectionString: PropTypes.func.isRequired,
setName: PropTypes.func.isRequired,
setPassword: PropTypes.func.isRequired,
startLnd: PropTypes.func.isRequired,
stopLnd: PropTypes.func.isRequired
Expand All @@ -68,8 +68,8 @@ class Onboarding extends React.Component {
getSteps = () => {
const {
// STATE
alias,
autopilot,
name,
connectionType,
connectionHost,
connectionCert,
Expand All @@ -84,13 +84,13 @@ class Onboarding extends React.Component {
unlockWalletError,
fetchingSeed,
// DISPATCH
setAlias,
setAutopilot,
setConnectionType,
setConnectionHost,
setConnectionCert,
setConnectionMacaroon,
setConnectionString,
setName,
setUnlockWalletError,
setPassword,
startLnd,
Expand Down Expand Up @@ -120,7 +120,7 @@ class Onboarding extends React.Component {
/>,
<Wizard.Step key="SeedConfirm" component={SeedConfirm} {...{ seed }} />,
<Wizard.Step key="Password" component={Password} {...{ setPassword }} />,
<Wizard.Step key="Alias" component={Alias} {...{ alias, setAlias }} />,
<Wizard.Step key="Name" component={Name} {...{ name, setName }} />,
<Wizard.Step key="Autopilot" component={Autopilot} {...{ autopilot, setAutopilot }} />,
<Wizard.Step key="WalletCreate" component={WalletCreate} {...{ createNewWallet }} />
]
Expand All @@ -134,7 +134,7 @@ class Onboarding extends React.Component {
...formSteps,
<Wizard.Step key="Recover" component={Recover} {...{ seed }} />,
<Wizard.Step key="Password" component={Password} {...{ setPassword }} />,
<Wizard.Step key="Alias" component={Alias} {...{ alias, setAlias }} />,
<Wizard.Step key="Name" component={Name} {...{ name, setName }} />,
<Wizard.Step key="Autopilot" component={Autopilot} {...{ autopilot, setAutopilot }} />,
<Wizard.Step key="WalletRecover" component={WalletRecover} {...{ recoverOldWallet }} />
]
Expand Down
84 changes: 84 additions & 0 deletions app/components/Onboarding/Steps/Name.js
@@ -0,0 +1,84 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box } from 'rebass'
import { Bar, Form, Header, Input } from 'components/UI'
import messages from './messages'

class Name extends React.Component {
static propTypes = {
wizardApi: PropTypes.object,
wizardState: PropTypes.object,
name: PropTypes.string,
setName: PropTypes.func.isRequired
}

static defaultProps = {
wizardApi: {},
wizardState: {},
name: ''
}

setFormApi = formApi => {
this.formApi = formApi
}

handleSubmit = values => {
const { setName } = this.props
setName(values.name)
}

render() {
const { wizardApi, wizardState, name, setName, intl, ...rest } = this.props
const { getApi, onChange, preSubmit, onSubmit, onSubmitFailure } = wizardApi
const { currentItem } = wizardState

return (
<Form
{...rest}
getApi={formApi => {
this.setFormApi(formApi)
if (getApi) {
getApi(formApi)
}
}}
onChange={onChange && (formState => onChange(formState, currentItem))}
preSubmit={preSubmit}
onSubmit={values => {
this.handleSubmit(values)
if (onSubmit) {
onSubmit(values)
}
}}
onSubmitFailure={onSubmitFailure}
>
{({ formState }) => {
const shouldValidateInline = formState.submits > 0
return (
<>
<Header
title={<FormattedMessage {...messages.wallet_name_title} />}
subtitle={<FormattedMessage {...messages.wallet_name_description} />}
align="left"
/>
<Bar my={4} />
<Box>
<Input
autoFocus
field="name"
name="name"
label={<FormattedMessage {...messages.wallet_name_label} />}
initialValue={name}
validateOnBlur={shouldValidateInline}
validateOnChange={shouldValidateInline}
/>
</Box>
</>
)
}}
</Form>
)
}
}

export default injectIntl(Name)
1 change: 1 addition & 0 deletions app/components/Onboarding/Steps/index.js
Expand Up @@ -5,6 +5,7 @@ export ConnectionConfirm from './ConnectionConfirm'
export ConnectionDetails from './ConnectionDetails'
export ConnectionType from './ConnectionType'
export Login from './Login'
export Name from './Name'
export Password from './Password'
export Recover from './Recover'
export SeedConfirm from './SeedConfirm'
Expand Down
5 changes: 4 additions & 1 deletion app/components/Onboarding/Steps/messages.js
Expand Up @@ -47,7 +47,6 @@ export default defineMessages({
login_title: 'Welcome back!',
macaroon_description: 'Path to the lnd macaroon file. Example: /path/to/admin.macaroon',
next: 'Next',
nickname: 'Nickname',
only: 'only',
password_confirm_placeholder: 'Confirm Password',
password_error_length: 'Password must be at least {passwordMinLength} characters long',
Expand All @@ -70,6 +69,10 @@ export default defineMessages({
unlocking: 'Unlocking',
verify_host_description: 'Please check the hostname carefully.',
verify_host_title: 'Are you sure you want to connect to',
wallet_name_description:
'Set a name for your wallet to help you identify it in Zap. This is for internal purposes only and will not be broadcast on the Lightning Network.',
wallet_name_title: 'What do you want to call this wallet?',
wallet_name_label: 'Wallet Name',
word_placeholder: 'word',
generating_seed: 'Generating Seed...'
})
3 changes: 3 additions & 0 deletions app/containers/Onboarding.js
Expand Up @@ -8,6 +8,7 @@ import {
setConnectionCert,
setConnectionMacaroon,
setConnectionString,
setName,
setPassword,
validateHost,
validateCert,
Expand All @@ -26,6 +27,7 @@ import {

const mapStateToProps = state => ({
alias: state.onboarding.alias,
name: state.onboarding.name,
autopilot: state.onboarding.autopilot,
connectionType: state.onboarding.connectionType,
connectionHost: state.onboarding.connectionHost,
Expand All @@ -51,6 +53,7 @@ const mapDispatchToProps = {
setConnectionCert,
setConnectionMacaroon,
setConnectionString,
setName,
setPassword,
setUnlockWalletError,
startLnd,
Expand Down
3 changes: 2 additions & 1 deletion app/lib/zap/controller.js
Expand Up @@ -19,7 +19,8 @@ type onboardingOptions = {
cert?: string,
macaroon?: string,
alias?: string,
autopilot?: boolean
autopilot?: boolean,
name?: string
}

const grpcSslCipherSuites = connectionType =>
Expand Down
16 changes: 10 additions & 6 deletions app/reducers/lnd.js
Expand Up @@ -287,10 +287,9 @@ export const createNewWallet = () => async (dispatch, getState) => {
type: 'local',
chain: 'bitcoin',
network: 'testnet',
settings: {
autopilot: onboardingState.autopilot,
alias: onboardingState.alias
}
autopilot: onboardingState.autopilot,
alias: onboardingState.alias,
name: onboardingState.name
}

// Save the wallet config.
Expand All @@ -301,12 +300,17 @@ export const createNewWallet = () => async (dispatch, getState) => {
await dispatch(startLnd(wallet))
}

export const recoverOldWallet = () => async dispatch => {
export const recoverOldWallet = () => async (dispatch, getState) => {
const onboardingState = getState().onboarding

// Define the wallet config.
let wallet = {
type: 'local',
chain: 'bitcoin',
network: 'testnet'
network: 'testnet',
autopilot: onboardingState.autopilot,
alias: onboardingState.alias,
name: onboardingState.name
}

// Save the wallet config.
Expand Down
10 changes: 10 additions & 0 deletions app/reducers/onboarding.js
Expand Up @@ -14,6 +14,7 @@ export const SET_CONNECTION_HOST = 'SET_CONNECTION_HOST'
export const SET_CONNECTION_CERT = 'SET_CONNECTION_CERT'
export const SET_CONNECTION_MACAROON = 'SET_CONNECTION_MACAROON'
export const SET_ALIAS = 'SET_ALIAS'
export const SET_NAME = 'SET_NAME'
export const SET_AUTOPILOT = 'SET_AUTOPILOT'
export const SET_PASSWORD = 'SET_PASSWORD'
export const SET_SEED = 'SET_SEED'
Expand Down Expand Up @@ -99,6 +100,13 @@ export function setAlias(alias) {
}
}

export function setName(name) {
return {
type: SET_NAME,
name
}
}

export function setAutopilot(autopilot) {
return {
type: SET_AUTOPILOT,
Expand Down Expand Up @@ -176,6 +184,7 @@ const ACTION_HANDLERS = {
[SET_CONNECTION_CERT]: (state, { connectionCert }) => ({ ...state, connectionCert }),
[SET_CONNECTION_MACAROON]: (state, { connectionMacaroon }) => ({ ...state, connectionMacaroon }),
[SET_ALIAS]: (state, { alias }) => ({ ...state, alias }),
[SET_NAME]: (state, { name }) => ({ ...state, name }),
[SET_AUTOPILOT]: (state, { autopilot }) => ({ ...state, autopilot }),
[SET_SEED]: (state, { seed }) => ({ ...state, seed, fetchingSeed: false }),
[SET_PASSWORD]: (state, { password }) => ({ ...state, password }),
Expand Down Expand Up @@ -228,6 +237,7 @@ const initialState = {
connectionCert: '',
connectionMacaroon: '',
alias: '',
name: '',
password: '',
seed: []
}
Expand Down
4 changes: 3 additions & 1 deletion app/translations/af-ZA.json
Expand Up @@ -133,7 +133,6 @@
"components.Onboarding.Steps.login_title": "",
"components.Onboarding.Steps.macaroon_description": "",
"components.Onboarding.Steps.next": "",
"components.Onboarding.Steps.nickname": "",
"components.Onboarding.Steps.only": "",
"components.Onboarding.Steps.password_confirm_placeholder": "",
"components.Onboarding.Steps.password_description": "",
Expand All @@ -153,6 +152,9 @@
"components.Onboarding.Steps.unlocking": "",
"components.Onboarding.Steps.verify_host_description": "",
"components.Onboarding.Steps.verify_host_title": "",
"components.Onboarding.Steps.wallet_name_description": "",
"components.Onboarding.Steps.wallet_name_label": "",
"components.Onboarding.Steps.wallet_name_title": "",
"components.Onboarding.Steps.word_placeholder": "",
"components.Onboarding.next": "",
"components.Onboarding.previous": "",
Expand Down
4 changes: 3 additions & 1 deletion app/translations/ar-SA.json
Expand Up @@ -133,7 +133,6 @@
"components.Onboarding.Steps.login_title": "",
"components.Onboarding.Steps.macaroon_description": "",
"components.Onboarding.Steps.next": "",
"components.Onboarding.Steps.nickname": "",
"components.Onboarding.Steps.only": "",
"components.Onboarding.Steps.password_confirm_placeholder": "",
"components.Onboarding.Steps.password_description": "",
Expand All @@ -153,6 +152,9 @@
"components.Onboarding.Steps.unlocking": "",
"components.Onboarding.Steps.verify_host_description": "",
"components.Onboarding.Steps.verify_host_title": "",
"components.Onboarding.Steps.wallet_name_description": "",
"components.Onboarding.Steps.wallet_name_label": "",
"components.Onboarding.Steps.wallet_name_title": "",
"components.Onboarding.Steps.word_placeholder": "",
"components.Onboarding.next": "",
"components.Onboarding.previous": "",
Expand Down
4 changes: 3 additions & 1 deletion app/translations/bg-BG.json
Expand Up @@ -133,7 +133,6 @@
"components.Onboarding.Steps.login_title": "",
"components.Onboarding.Steps.macaroon_description": "Път до lnd macaroon файла. Пример: /path/to/admin.macaroon",
"components.Onboarding.Steps.next": "Напред",
"components.Onboarding.Steps.nickname": "",
"components.Onboarding.Steps.only": "само",
"components.Onboarding.Steps.password_confirm_placeholder": "Потвърди паролата",
"components.Onboarding.Steps.password_description": "",
Expand All @@ -153,6 +152,9 @@
"components.Onboarding.Steps.unlocking": "",
"components.Onboarding.Steps.verify_host_description": "Моля, проверете името на хоста внимателно.",
"components.Onboarding.Steps.verify_host_title": "Сигурни ли сте, че искате да се свържете към",
"components.Onboarding.Steps.wallet_name_description": "",
"components.Onboarding.Steps.wallet_name_label": "",
"components.Onboarding.Steps.wallet_name_title": "",
"components.Onboarding.Steps.word_placeholder": "дума",
"components.Onboarding.next": "",
"components.Onboarding.previous": "",
Expand Down
4 changes: 3 additions & 1 deletion app/translations/ca-ES.json
Expand Up @@ -133,7 +133,6 @@
"components.Onboarding.Steps.login_title": "",
"components.Onboarding.Steps.macaroon_description": "",
"components.Onboarding.Steps.next": "",
"components.Onboarding.Steps.nickname": "",
"components.Onboarding.Steps.only": "",
"components.Onboarding.Steps.password_confirm_placeholder": "",
"components.Onboarding.Steps.password_description": "",
Expand All @@ -153,6 +152,9 @@
"components.Onboarding.Steps.unlocking": "",
"components.Onboarding.Steps.verify_host_description": "",
"components.Onboarding.Steps.verify_host_title": "",
"components.Onboarding.Steps.wallet_name_description": "",
"components.Onboarding.Steps.wallet_name_label": "",
"components.Onboarding.Steps.wallet_name_title": "",
"components.Onboarding.Steps.word_placeholder": "",
"components.Onboarding.next": "",
"components.Onboarding.previous": "",
Expand Down
4 changes: 3 additions & 1 deletion app/translations/cs-CZ.json
Expand Up @@ -133,7 +133,6 @@
"components.Onboarding.Steps.login_title": "",
"components.Onboarding.Steps.macaroon_description": "Cesta k souboru lnd macaroon. Příklad: /path/to/admin.macaroon",
"components.Onboarding.Steps.next": "Další",
"components.Onboarding.Steps.nickname": "",
"components.Onboarding.Steps.only": "",
"components.Onboarding.Steps.password_confirm_placeholder": "",
"components.Onboarding.Steps.password_description": "",
Expand All @@ -153,6 +152,9 @@
"components.Onboarding.Steps.unlocking": "",
"components.Onboarding.Steps.verify_host_description": "Prosím, pečlivě zkontrolujte název hositele.",
"components.Onboarding.Steps.verify_host_title": "Jste si jistí, že chcete připojit k",
"components.Onboarding.Steps.wallet_name_description": "",
"components.Onboarding.Steps.wallet_name_label": "",
"components.Onboarding.Steps.wallet_name_title": "",
"components.Onboarding.Steps.word_placeholder": "slovo",
"components.Onboarding.next": "",
"components.Onboarding.previous": "",
Expand Down

0 comments on commit 54be043

Please sign in to comment.