-
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.
Adds modal that allows users to manually balance channels using a slicers, or to evenly balance the channels automatically via button.
- Loading branch information
Showing
13 changed files
with
371 additions
and
11 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,32 @@ | ||
import React from 'react'; | ||
import { SwapOutlined } from '@ant-design/icons'; | ||
import styled from '@emotion/styled'; | ||
import { Button } from 'antd'; | ||
import { usePrefixedTranslation } from 'hooks'; | ||
import { useStoreActions } 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, resetBalanceChannels } = useStoreActions(s => s.modals); | ||
|
||
return ( | ||
<Styled.Button | ||
onClick={() => resetBalanceChannels(network).then(showBalanceChannels)} | ||
> | ||
<SwapOutlined /> {l('btn')} | ||
</Styled.Button> | ||
); | ||
}; | ||
|
||
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,87 @@ | ||
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'; | ||
|
||
interface Props { | ||
network: Network; | ||
} | ||
|
||
const BalanceChannelsModal: React.FC<Props> = ({ network }) => { | ||
const { l } = usePrefixedTranslation('cmps.common.BalanceChannelsModal'); | ||
const { visible, channelsInfo } = useStoreState(s => s.modals.balanceChannels); | ||
const { | ||
resetBalanceChannels, | ||
hideBalanceChannels, | ||
autoBalanceChannels, | ||
manualBalanceChannels, | ||
updateBalanceOfChannels, | ||
} = useStoreActions(s => s.modals); | ||
|
||
const CustomModalFooter = ( | ||
<Row gutter={10} justify="end"> | ||
<Col> | ||
<Button onClick={() => hideBalanceChannels()}>{l('close')}</Button> | ||
</Col> | ||
<Col> | ||
<Button onClick={() => updateBalanceOfChannels(network)}>{l('update')}</Button> | ||
</Col> | ||
</Row> | ||
); | ||
|
||
return ( | ||
<Modal | ||
title="Balance Channels" | ||
open={visible} | ||
footer={CustomModalFooter} | ||
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 => manualBalanceChannels({ value, index })} | ||
min={0} | ||
max={total} | ||
/> | ||
</div> | ||
); | ||
})} | ||
{/* end sliders */} | ||
<br /> | ||
<Row gutter={10}> | ||
<Col span={12}> | ||
<Button onClick={() => resetBalanceChannels(network)}> | ||
<ReloadOutlined /> <span>{l('reset')}</span> | ||
</Button> | ||
</Col> | ||
<Col span={12}> | ||
<Button onClick={() => autoBalanceChannels()}> | ||
<PercentageOutlined /> <span>{l('autoBalance')}</span> | ||
</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
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.