-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select which chain pays the fee for the dispatch call fee. (#300)
* First approach of basic functionality. Need styling and tests * Work in progress. Need to adjust the select on fee selector * Finishing last details. Functionality ready
- Loading branch information
1 parent
aa15668
commit 5bac4b2
Showing
7 changed files
with
212 additions
and
48 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2021 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity Bridges UI. | ||
// | ||
// Parity Bridges UI is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Parity Bridges UI is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Parity Bridges UI. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React, { useCallback } from 'react'; | ||
import { Typography, Select, MenuItem, makeStyles } from '@material-ui/core'; | ||
import ChainLogo from './ChainLogo'; | ||
import { PayFee } from '../types/transactionTypes'; | ||
import { useSourceTarget } from '../contexts/SourceTargetContextProvider'; | ||
import { useTransactionContext, useUpdateTransactionContext } from '../contexts/TransactionContext'; | ||
import { TransactionActionCreators } from '../actions/transactionActions'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
container: { | ||
minHeight: theme.spacing(2), | ||
display: 'flex', | ||
alignItems: 'center' | ||
}, | ||
item: { | ||
marginLeft: theme.spacing(0.8) | ||
} | ||
})); | ||
|
||
export default function FeePaySelector() { | ||
const classes = useStyles(); | ||
const sourceTargetDetails = useSourceTarget(); | ||
const { dispatchTransaction } = useUpdateTransactionContext(); | ||
const { payFee } = useTransactionContext(); | ||
|
||
const { | ||
sourceChainDetails: { chain: sourceChain }, | ||
targetChainDetails: { chain: targetChain } | ||
} = sourceTargetDetails; | ||
|
||
const onChange = useCallback( | ||
(event) => { | ||
dispatchTransaction(TransactionActionCreators.changeDispatchFeePayChain(event.target.value)); | ||
}, | ||
[dispatchTransaction] | ||
); | ||
|
||
const chain = payFee === PayFee.AtSourceChain ? sourceChain : targetChain; | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<Typography variant="body1" color="secondary"> | ||
Dispatch fee payed on | ||
</Typography> | ||
<div className={classes.item}> | ||
<ChainLogo chain={chain} /> | ||
</div> | ||
|
||
<div className={classes.item}> | ||
<Select | ||
onChange={onChange} | ||
value={payFee} | ||
disableUnderline | ||
renderValue={(): React.ReactNode => ( | ||
<Typography variant="body1" color="secondary" className={classes.item}> | ||
{chain} | ||
</Typography> | ||
)} | ||
> | ||
<MenuItem value={PayFee.AtSourceChain}>Source Chain </MenuItem> | ||
<MenuItem value={PayFee.AtTargetChain}>Target Chain </MenuItem> | ||
</Select> | ||
</div> | ||
</div> | ||
); | ||
} |
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,85 @@ | ||
// Copyright 2021 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity Bridges UI. | ||
// | ||
// Parity Bridges UI is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Parity Bridges UI is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Parity Bridges UI. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React from 'react'; | ||
import { Typography, Tooltip } from '@material-ui/core'; | ||
import { fade, makeStyles } from '@material-ui/core/styles'; | ||
import HelpOutlineIcon from '@material-ui/icons/HelpOutline'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
container: { | ||
minHeight: '20px', | ||
display: 'flex' | ||
}, | ||
tooltipIcon: { | ||
...theme.typography.body1, | ||
marginTop: 2, | ||
marginLeft: 2, | ||
'&:not(:hover)': { | ||
color: fade(theme.palette.text.hint, 0.75) | ||
} | ||
}, | ||
value: { | ||
backgroundColor: '#f5dada', | ||
fontFamily: 'monospace', | ||
paddingLeft: theme.spacing(0.7), | ||
paddingRight: theme.spacing(0.7), | ||
borderRadius: '3px' | ||
}, | ||
textContainer: { | ||
marginLeft: theme.spacing(0.5) | ||
} | ||
})); | ||
|
||
interface Props { | ||
chainTokens: string; | ||
amount: string; | ||
tooltip?: string; | ||
showPlus?: boolean; | ||
} | ||
|
||
interface TextStyle { | ||
text: string; | ||
background?: boolean; | ||
} | ||
|
||
const CustomTypography = ({ text, background = false }: TextStyle) => { | ||
const classes = useStyles(); | ||
return ( | ||
<div className={classes.textContainer}> | ||
<Typography variant="body1" className={background ? classes.value : ''}> | ||
{text} | ||
</Typography> | ||
</div> | ||
); | ||
}; | ||
|
||
export default function FeeValue({ tooltip = '', chainTokens, amount, showPlus = false }: Props) { | ||
const classes = useStyles(); | ||
return ( | ||
<div className={classes.container}> | ||
<CustomTypography text={amount} background /> | ||
<CustomTypography text={chainTokens} /> | ||
|
||
{tooltip && ( | ||
<Tooltip title={tooltip} arrow placement="top"> | ||
<HelpOutlineIcon className={classes.tooltipIcon} /> | ||
</Tooltip> | ||
)} | ||
{showPlus && <CustomTypography text={'+'} />} | ||
</div> | ||
); | ||
} |
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