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

Ability to set custom csv when opening channel #3679

Merged
merged 8 commits into from
Oct 19, 2020
41 changes: 37 additions & 4 deletions renderer/components/Channels/ChannelCreateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { intlShape } from '@zap/i18n'
import { convert } from '@zap/utils/btc'
import { CoinBig } from '@zap/utils/coin'
import { Bar, Button, Panel, Span, Text } from 'components/UI'
import { Form, NodePubkeyInput, Label, Toggle, TransactionFeeInput } from 'components/Form'
import {
Form,
NodePubkeyInput,
Label,
Toggle,
TransactionFeeInput,
IntegerInput,
} from 'components/Form'
import { CryptoValue } from 'containers/UI'
import { CurrencyFieldGroup } from 'containers/Form'
import Padlock from 'components/Icon/Padlock'
Expand Down Expand Up @@ -178,7 +185,7 @@ class ChannelCreateForm extends React.Component {
// Open a channel using the supplied details.
onSubmit = values => {
const { cryptoUnit, openChannel } = this.props
const { amountCrypto, nodePubkey } = values
const { amountCrypto, nodePubkey, remoteCsvDelay, private: isPrivate } = values

// Convert amount to satoshis.
const amountInSatoshis = convert(cryptoUnit, 'sats', amountCrypto)
Expand All @@ -195,7 +202,8 @@ class ChannelCreateForm extends React.Component {
host,
localamt: amountInSatoshis,
satPerByte,
isPrivate: values.private,
isPrivate,
remoteCsvDelay,
})
}

Expand Down Expand Up @@ -290,7 +298,10 @@ class ChannelCreateForm extends React.Component {
<Span color="gray" fontSize="s" mr={2}>
<Padlock />
</Span>
<Label htmlFor="private">
<Label
htmlFor="private"
tooltip={intl.formatMessage({ ...messages.private_tooltip })}
>
<FormattedMessage {...messages.private_label} />
</Label>
</Flex>
Expand All @@ -300,6 +311,28 @@ class ChannelCreateForm extends React.Component {
</Flex>
</>
)}

<Flex alignItems="center" justifyContent="space-between" mt={2}>
<Flex>
<Span color="gray" fontSize="s" mr={2}>
<Padlock />
</Span>
<Label
htmlFor="remoteCsvDelay"
tooltip={intl.formatMessage({ ...messages.remote_csv_delay_tooltip })}
>
<FormattedMessage {...messages.remote_csv_delay_label} />
</Label>
</Flex>

<IntegerInput
field="remoteCsvDelay"
placeholder="auto"
textAlign="right"
variant="thin"
width={80}
/>
</Flex>
</Box>
)
}
Expand Down
18 changes: 17 additions & 1 deletion renderer/components/Channels/ChannelData.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const ChannelData = ({ channel, cryptoUnitName, intl, networkInfo, viewMode, ...
totalSatoshisSent,
totalSatoshisReceived,
csvDelay,
maturityHeight,
blocksTilMaturity,
activity,
numUpdates,
fundingTxTimestamp,
Expand Down Expand Up @@ -135,6 +137,18 @@ const ChannelData = ({ channel, cryptoUnitName, intl, networkInfo, viewMode, ...
value: <Text>{csvDelay}</Text>,
}),

maturityHeight: () => ({
label: <FormattedMessage {...messages.maturity_height_label} />,
body: <FormattedMessage {...messages.maturity_height_description} />,
value: <Text>{maturityHeight}</Text>,
}),

blocksTilMaturity: () => ({
label: <FormattedMessage {...messages.blocks_til_maturity_label} />,
body: <FormattedMessage {...messages.blocks_til_maturity_description} />,
value: <Text>{blocksTilMaturity}</Text>,
}),

totalSatoshisSent: () => ({
label: <FormattedMessage {...messages.total_sent_label} />,
body: <FormattedMessage {...messages.total_sent_description} />,
Expand Down Expand Up @@ -194,11 +208,13 @@ const ChannelData = ({ channel, cryptoUnitName, intl, networkInfo, viewMode, ...
viewMode === CHANNEL_DATA_VIEW_MODE_BASIC
? [isClosing ? 'closingTxid' : 'channelPoint', 'numUpdates', 'csvDelay', 'activity']
: [
'channelPoint',
'fundingTxTimestamp',
'channelPoint',
'closingTxid',
'numUpdates',
'csvDelay',
'maturityHeight',
'blocksTilMaturity',
'activity',
'totalSatoshisSent',
'totalSatoshisReceived',
Expand Down
9 changes: 9 additions & 0 deletions renderer/components/Channels/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ export default defineMessages({
open_channel_form_description:
"To open a channel, enter the desired node's publickey@host, set the amount of BTC you'd like to commit to the channel, and submit.",
open_channel_form_next_button_text: 'Next',
remote_csv_delay_label: 'Timelock',
remote_csv_delay_tooltip:
'The number of blocks we will require our channel counterparty to wait before accessing its funds in case of unilateral close. If this is not set, we will scale the value according to the channel size.',
open_channel_summary_next_button_text: 'Open Channel with {amount}',
open_channel_form_onchain_balance: 'Your current confirmed on-chain balance:',
open_channel_notification: 'Channel opening initiated',
private_label: 'Keep this channel private',
private_tooltip: 'Whether this channel should be private, not announced to the greater network.',
search_placeholder: 'Search Channels',
view_mode_list: 'View as a list',
view_mode_card: 'View as cards',
Expand Down Expand Up @@ -115,4 +119,9 @@ export default defineMessages({
no_search_results: 'Your search did not return any results.',
crypto_amount_with_unit: '{amount} {cryptoUnitName}',
channels_filter_hint: 'Channels filter',
maturity_height_label: 'Maturity height',
maturity_height_description: 'The height at which funds can be swept into the wallet.',
blocks_til_maturity_label: 'Blocks til maturity',
blocks_til_maturity_description:
'Remaining # of blocks until the commitment output can be swept. Negative values indicate how many blocks have passed since becoming mature.',
})
2 changes: 1 addition & 1 deletion renderer/components/Form/IntegerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const preventNonNumericOnPaste = e => {
*/
class IntegerInput extends React.Component {
render() {
return <BasicInput {...this.props} pattern="[0-9]*" placeholder="0" type="number" />
return <BasicInput pattern="[0-9]*" placeholder="0" {...this.props} type="number" />
}
}

Expand Down
3 changes: 3 additions & 0 deletions renderer/reducers/channels/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const GET_SUGGESTED_NODES = 'GET_SUGGESTED_NODES'
export const RECEIVE_SUGGESTED_NODES_ERROR = 'RECEIVE_SUGGESTED_NODES_ERROR'
export const RECEIVE_SUGGESTED_NODES = 'RECEIVE_SUGGESTED_NODES'
export const CLOSE_CHANNEL_DIALOG_ID = 'CLOSE_CHANNEL_DIALOG_ID'
export const OPEN_CHANNEL = 'OPEN_CHANNEL'
export const OPEN_CHANNEL_SUCCESS = 'OPEN_CHANNEL_SUCCESS'
export const OPEN_CHANNEL_FAILURE = 'OPEN_CHANNEL_FAILURE'

export const DEFAULT_FILTER = new Set([
'ACTIVE_CHANNELS',
Expand Down
18 changes: 17 additions & 1 deletion renderer/reducers/channels/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const {
GET_SUGGESTED_NODES,
RECEIVE_SUGGESTED_NODES_ERROR,
RECEIVE_SUGGESTED_NODES,
OPEN_CHANNEL,
OPEN_CHANNEL_SUCCESS,
OPEN_CHANNEL_FAILURE,
} = constants

const CHANNEL_REFRESH_THROTTLE = 1000 * 60
Expand Down Expand Up @@ -420,7 +423,17 @@ export const pushclosechannelupdated = ({ chanId }) => dispatch => {
* @returns {(dispatch:Function, getState:Function) => Promise<void>} Thunk
*/
export const openChannel = data => async (dispatch, getState) => {
const { pubkey, host, localamt, satPerByte, isPrivate, spendUnconfirmed = true } = data
const {
pubkey,
host,
localamt,
satPerByte,
isPrivate,
remoteCsvDelay,
spendUnconfirmed = true,
} = data

dispatch({ type: OPEN_CHANNEL, data })

// Grab the activeWallet type from our local store. If the active connection type is local (light clients using
// neutrino) we will flag manually created channels as private. Other connections like remote node and BTCPay Server
Expand Down Expand Up @@ -455,16 +468,19 @@ export const openChannel = data => async (dispatch, getState) => {
localamt,
private: channelIsPrivate,
satPerByte,
remoteCsvDelay,
spendUnconfirmed,
})
dispatch(pushchannelupdated(channelData))
dispatch({ type: OPEN_CHANNEL_SUCCESS })
} catch (e) {
dispatch(
pushchannelerror({
error: `Unable to open channel: ${e.message}`,
nodePubkey: pubkey,
})
)
dispatch({ type: OPEN_CHANNEL_FAILURE })
}
}

Expand Down
4 changes: 3 additions & 1 deletion renderer/reducers/channels/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { getNodeDisplayName } from 'reducers/network'
* @param {object} channelObj Channel object
* @returns {object} Channel data
*/
export const getChannelData = channelObj => channelObj.channel || channelObj
export const getChannelData = channelObj => {
return channelObj.channel ? { ...channelObj, ...channelObj.channel } : channelObj
}

/**
* getRemoteNodePubKey - Get the remote pubkey depending on what type of channel.
Expand Down
18 changes: 16 additions & 2 deletions services/grpc/lightning.methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ async function ensurePeerConnected(payload = {}) {
if (peer) {
return peer
}
return this.connectPeer({ addr: payload })
const finalPayload = { addr: payload }
logGrpcCmd('Lightning.connectPeer', finalPayload)
return this.connectPeer({ addr: finalPayload })
}

/**
Expand All @@ -119,12 +121,22 @@ async function ensurePeerConnected(payload = {}) {
* @returns {Promise} OpenStatusUpdate
*/
async function connectAndOpen(payload = {}) {
const { pubkey, host, localamt, private: privateChannel, satPerByte, spendUnconfirmed } = payload
logGrpcCmd('Lightning.connectAndOpen', payload)
const {
pubkey,
host,
localamt,
private: privateChannel,
satPerByte,
remoteCsvDelay,
spendUnconfirmed,
} = payload
const req = {
nodePubkey: Buffer.from(pubkey, 'hex'),
localFundingAmount: Number(localamt),
private: privateChannel,
satPerByte,
remoteCsvDelay,
spendUnconfirmed,
}
try {
Expand All @@ -150,6 +162,7 @@ async function openChannel(payload = {}) {
})
return new Promise((resolve, reject) => {
try {
logGrpcCmd('Lightning.openChannel', payload)
const call = this.service.openChannel(payload)

call.on('data', data => {
Expand Down Expand Up @@ -206,6 +219,7 @@ async function closeChannel(payload = {}) {
},
force,
}
logGrpcCmd('Lightning.closeChannel', payload)
const call = this.service.closeChannel(req)

call.on('data', data => {
Expand Down
7 changes: 7 additions & 0 deletions translations/af-ZA.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"components.Channels.back_button": "",
"components.Channels.base_fee_description": "",
"components.Channels.base_fee_label": "",
"components.Channels.blocks_til_maturity_description": "",
"components.Channels.blocks_til_maturity_label": "",
"components.Channels.capacity": "",
"components.Channels.channel_activity": "",
"components.Channels.channel_activity_description": "",
Expand Down Expand Up @@ -173,6 +175,8 @@
"components.Channels.local_balance": "",
"components.Channels.local_chan_reserve_sat_description": "",
"components.Channels.local_chan_reserve_sat_label": "",
"components.Channels.maturity_height_description": "",
"components.Channels.maturity_height_label": "",
"components.Channels.more_button_text": "",
"components.Channels.no_search_results": "",
"components.Channels.node_search_description": "",
Expand All @@ -194,10 +198,13 @@
"components.Channels.pending_force_close": "",
"components.Channels.pending_open": "",
"components.Channels.private_label": "",
"components.Channels.private_tooltip": "",
"components.Channels.refresh_button_hint": "",
"components.Channels.remote_balance": "",
"components.Channels.remote_chan_reserve_sat_description": "",
"components.Channels.remote_chan_reserve_sat_label": "",
"components.Channels.remote_csv_delay_label": "",
"components.Channels.remote_csv_delay_tooltip": "",
"components.Channels.remote_pubkey": "",
"components.Channels.search_placeholder": "",
"components.Channels.show_all": "",
Expand Down
7 changes: 7 additions & 0 deletions translations/ar-SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"components.Channels.back_button": "",
"components.Channels.base_fee_description": "",
"components.Channels.base_fee_label": "",
"components.Channels.blocks_til_maturity_description": "",
"components.Channels.blocks_til_maturity_label": "",
"components.Channels.capacity": "",
"components.Channels.channel_activity": "",
"components.Channels.channel_activity_description": "",
Expand Down Expand Up @@ -173,6 +175,8 @@
"components.Channels.local_balance": "",
"components.Channels.local_chan_reserve_sat_description": "",
"components.Channels.local_chan_reserve_sat_label": "",
"components.Channels.maturity_height_description": "",
"components.Channels.maturity_height_label": "",
"components.Channels.more_button_text": "",
"components.Channels.no_search_results": "",
"components.Channels.node_search_description": "",
Expand All @@ -194,10 +198,13 @@
"components.Channels.pending_force_close": "",
"components.Channels.pending_open": "",
"components.Channels.private_label": "",
"components.Channels.private_tooltip": "",
"components.Channels.refresh_button_hint": "",
"components.Channels.remote_balance": "",
"components.Channels.remote_chan_reserve_sat_description": "",
"components.Channels.remote_chan_reserve_sat_label": "",
"components.Channels.remote_csv_delay_label": "",
"components.Channels.remote_csv_delay_tooltip": "",
"components.Channels.remote_pubkey": "",
"components.Channels.search_placeholder": "",
"components.Channels.show_all": "",
Expand Down
7 changes: 7 additions & 0 deletions translations/bg-BG.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"components.Channels.back_button": "Назад",
"components.Channels.base_fee_description": "",
"components.Channels.base_fee_label": "",
"components.Channels.blocks_til_maturity_description": "",
"components.Channels.blocks_til_maturity_label": "",
"components.Channels.capacity": "Капацитет",
"components.Channels.channel_activity": "Дейност",
"components.Channels.channel_activity_description": "",
Expand Down Expand Up @@ -173,6 +175,8 @@
"components.Channels.local_balance": "Локално салдо",
"components.Channels.local_chan_reserve_sat_description": "",
"components.Channels.local_chan_reserve_sat_label": "",
"components.Channels.maturity_height_description": "",
"components.Channels.maturity_height_label": "",
"components.Channels.more_button_text": "Още",
"components.Channels.no_search_results": "",
"components.Channels.node_search_description": "",
Expand All @@ -194,10 +198,13 @@
"components.Channels.pending_force_close": "",
"components.Channels.pending_open": "",
"components.Channels.private_label": "Дръжте този канал частен",
"components.Channels.private_tooltip": "",
"components.Channels.refresh_button_hint": "Опресняване на списъка с канали",
"components.Channels.remote_balance": "",
"components.Channels.remote_chan_reserve_sat_description": "",
"components.Channels.remote_chan_reserve_sat_label": "",
"components.Channels.remote_csv_delay_label": "",
"components.Channels.remote_csv_delay_tooltip": "",
"components.Channels.remote_pubkey": "",
"components.Channels.search_placeholder": "Търсене на канали",
"components.Channels.show_all": "(показване на всичко)",
Expand Down
Loading