-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The modal has slicers to manually balance LN channels. It also has a button to evenly balance the channels.
- Loading branch information
Showing
11 changed files
with
336 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { SwapOutlined } from '@ant-design/icons'; | ||
import styled from '@emotion/styled'; | ||
import { Button, Tooltip } from 'antd'; | ||
import { usePrefixedTranslation } from 'hooks'; | ||
import { useStoreActions, useStoreState } from 'store'; | ||
import { Network } from 'types'; | ||
|
||
const Styled = { | ||
Button: styled(Button)` | ||
margin-left: 8px; | ||
`, | ||
}; | ||
|
||
interface Props { | ||
network: Network; | ||
} | ||
|
||
const BalanceChannelsButton: React.FC<Props> = ({ network }) => { | ||
const { l } = usePrefixedTranslation('cmps.common.BalanceChannelsButton'); | ||
const { showBalanceChannels } = useStoreActions(s => s.modals); | ||
const { resetChannelsInfo } = useStoreActions(s => s.lightning); | ||
const { channelsInfo } = useStoreState(s => s.lightning); | ||
|
||
const showModal = async () => { | ||
await showBalanceChannels(); | ||
await resetChannelsInfo(network); | ||
}; | ||
|
||
return ( | ||
channelsInfo.length > 0 && ( | ||
<Tooltip title={l('btn')}> | ||
<Styled.Button onClick={showModal}> | ||
<SwapOutlined /> | ||
</Styled.Button> | ||
</Tooltip> | ||
) | ||
); | ||
}; | ||
|
||
export default BalanceChannelsButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import { PercentageOutlined, ReloadOutlined } from '@ant-design/icons'; | ||
import { Button, Col, Modal, Row, Slider } from 'antd'; | ||
import { usePrefixedTranslation } from 'hooks'; | ||
import { useStoreActions, useStoreState } from 'store'; | ||
import { ChannelInfo, Network } from 'types'; | ||
import { format } from 'utils/units'; | ||
import styled from '@emotion/styled'; | ||
|
||
interface Props { | ||
network: Network; | ||
} | ||
|
||
const Styled = { | ||
Button: styled(Button)` | ||
width: 100%; | ||
`, | ||
}; | ||
|
||
const BalanceChannelsModal: React.FC<Props> = ({ network }) => { | ||
const { l } = usePrefixedTranslation('cmps.common.BalanceChannelsModal'); | ||
const { channelsInfo } = useStoreState(s => s.lightning); | ||
const { visible } = useStoreState(s => s.modals.balanceChannels); | ||
const { hideBalanceChannels } = useStoreActions(s => s.modals); | ||
const { | ||
resetChannelsInfo, | ||
manualBalanceChannelsInfo, | ||
autoBalanceChannelsInfo, | ||
updateBalanceOfChannels, | ||
} = useStoreActions(s => s.lightning); | ||
|
||
return ( | ||
<Modal | ||
title="Balance Channels" | ||
open={visible} | ||
okText={l('update')} | ||
cancelText={l('close')} | ||
onOk={() => updateBalanceOfChannels(network)} | ||
onCancel={() => hideBalanceChannels()} | ||
> | ||
{/* sliders */} | ||
{channelsInfo.map((channel: ChannelInfo, index: number) => { | ||
const { to, from, id, remoteBalance, localBalance, nextLocalBalance } = channel; | ||
const total = Number(remoteBalance) + Number(localBalance); | ||
return ( | ||
<div key={id}> | ||
<Row> | ||
<Col span={12}> | ||
{from} | ||
<br /> | ||
{format(nextLocalBalance)} | ||
</Col> | ||
<Col span={12} style={{ textAlign: 'right' }}> | ||
{to} | ||
<br /> | ||
{format(total - nextLocalBalance)} | ||
</Col> | ||
</Row> | ||
<Slider | ||
value={nextLocalBalance} | ||
onChange={value => manualBalanceChannelsInfo({ value, index })} | ||
min={0} | ||
max={total} | ||
/> | ||
</div> | ||
); | ||
})} | ||
{/* end sliders */} | ||
<br /> | ||
<Row gutter={10}> | ||
<Col span={12}> | ||
<Styled.Button onClick={() => resetChannelsInfo(network)}> | ||
<ReloadOutlined /> <span>{l('reset')}</span> | ||
</Styled.Button> | ||
</Col> | ||
<Col span={12}> | ||
<Styled.Button onClick={() => autoBalanceChannelsInfo()}> | ||
<PercentageOutlined /> <span>{l('autoBalance')}</span> | ||
</Styled.Button> | ||
</Col> | ||
</Row> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default BalanceChannelsModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.