Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

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 #1025
  • Loading branch information
mrfelton committed Dec 15, 2018
1 parent 4190fd1 commit 140adc9
Show file tree
Hide file tree
Showing 45 changed files with 266 additions and 55 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
2 changes: 1 addition & 1 deletion app/components/Onboarding/Steps/Alias.js
Expand Up @@ -67,7 +67,7 @@ class Alias extends React.Component {
autoFocus
field="alias"
name="alias"
label={<FormattedMessage {...messages.nickname} />}
label={<FormattedMessage {...messages.alias_label} />}
initialValue={alias}
validateOnBlur={shouldValidateInline}
validateOnChange={shouldValidateInline}
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
8 changes: 6 additions & 2 deletions app/components/Onboarding/Steps/messages.js
Expand Up @@ -2,8 +2,9 @@ import { defineMessages } from 'react-intl'

/* eslint-disable max-len */
export default defineMessages({
alias_description: 'Set your nickname to help others connect with you on the Lightning Network',
alias_description: 'Set your node alias to help others connect with you on the Lightning Network',
alias_title: 'What should we call you?',
alias_label: 'Alias',
autopilot_description:
'Autopilot is an automatic network manager. Instead of manually adding people to build your network to make payments, enable autopilot to automatically connect you to the Lightning Network using 60% of your balance.',
autopilot_title: 'Autopilot',
Expand Down Expand Up @@ -47,7 +48,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 +70,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
5 changes: 4 additions & 1 deletion app/translations/af-ZA.json
Expand Up @@ -94,6 +94,7 @@
"components.Home.wallets_menu_other_title": "",
"components.LoadingBolt.loading": "",
"components.Onboarding.Steps.alias_description": "",
"components.Onboarding.Steps.alias_label": "",
"components.Onboarding.Steps.alias_title": "",
"components.Onboarding.Steps.autopilot_description": "",
"components.Onboarding.Steps.autopilot_title": "",
Expand Down Expand Up @@ -133,7 +134,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 +153,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
5 changes: 4 additions & 1 deletion app/translations/ar-SA.json
Expand Up @@ -94,6 +94,7 @@
"components.Home.wallets_menu_other_title": "",
"components.LoadingBolt.loading": "",
"components.Onboarding.Steps.alias_description": "",
"components.Onboarding.Steps.alias_label": "",
"components.Onboarding.Steps.alias_title": "",
"components.Onboarding.Steps.autopilot_description": "",
"components.Onboarding.Steps.autopilot_title": "",
Expand Down Expand Up @@ -133,7 +134,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 +153,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
5 changes: 4 additions & 1 deletion app/translations/bg-BG.json
Expand Up @@ -94,6 +94,7 @@
"components.Home.wallets_menu_other_title": "",
"components.LoadingBolt.loading": "зареждане",
"components.Onboarding.Steps.alias_description": "",
"components.Onboarding.Steps.alias_label": "",
"components.Onboarding.Steps.alias_title": "",
"components.Onboarding.Steps.autopilot_description": "",
"components.Onboarding.Steps.autopilot_title": "",
Expand Down Expand Up @@ -133,7 +134,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 +153,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

0 comments on commit 140adc9

Please sign in to comment.