-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
330 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
135 changes: 135 additions & 0 deletions
135
src/components/Guilds/ActionsBuilder/SupportedActions/REPMint/REPMintEditor.tsx
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,135 @@ | ||
import styled from 'styled-components'; | ||
import { Input } from 'components/Guilds/common/Form/Input'; | ||
import Avatar from 'components/Guilds/Avatar'; | ||
import React, { useEffect } from 'react'; | ||
import { ActionEditorProps } from '..'; | ||
import { ethers } from 'ethers'; | ||
import useENSAvatar from 'hooks/Guilds/ether-swr/ens/useENSAvatar'; | ||
import { Box } from 'components/Guilds/common/Layout'; | ||
import { shortenAddress, MAINNET_ID } from 'utils'; | ||
import { baseInputStyles } from 'components/Guilds/common/Form/Input'; | ||
import { ReactComponent as Info } from '../../../../../assets/images/info.svg'; | ||
import StyledIcon from 'components/Guilds/common/SVG'; | ||
import useBigNumberToNumber from 'hooks/Guilds/conversions/useBigNumberToNumber'; | ||
import { useState } from 'react'; | ||
import NumericalInput from 'components/Guilds/common/Form/NumericalInput'; | ||
import { useTotalSupply } from 'hooks/Guilds/guild/useTotalSupply'; | ||
import { useTokenData } from 'hooks/Guilds/guild/useTokenData'; | ||
|
||
const Control = styled(Box)` | ||
display: flex; | ||
flex-direction: column; | ||
margin: 0.75rem 0; | ||
width: 100%; | ||
`; | ||
|
||
const ControlLabel = styled(Box)` | ||
display: flex; | ||
flex-direction: row; | ||
margin-bottom: 0.75rem; | ||
color: ${({ theme }) => theme.colors.proposalText.grey}; | ||
font-size: ${({ theme }) => theme.fontSizes.body}; | ||
font-weight: ${({ theme }) => theme.fontWeights.regular}; | ||
`; | ||
|
||
const ControlRow = styled(Box)` | ||
display: flex; | ||
align-items: stretch; | ||
height: 100%; | ||
`; | ||
|
||
const RepMintInput = styled(NumericalInput)` | ||
${baseInputStyles} | ||
display: flex; | ||
align-items: center; | ||
width: 100%; | ||
&:hover, | ||
&:focus { | ||
border: 0.1rem solid ${({ theme }) => theme.colors.text}; | ||
} | ||
`; | ||
|
||
const Mint: React.FC<ActionEditorProps> = ({ decodedCall, updateCall }) => { | ||
// parse transfer state from calls | ||
const [repPercent, setRepPercent] = useState(0); | ||
const [repAmount, setRepAmount] = useState(0); | ||
const { parsedData } = useTotalSupply({ decodedCall }); | ||
const { tokenData } = useTokenData(); | ||
|
||
const totalSupply = useBigNumberToNumber(tokenData?.totalSupply, 18); | ||
|
||
const { imageUrl } = useENSAvatar(parsedData?.toAddress, MAINNET_ID); | ||
|
||
const setCallDataAmount = (value: string) => { | ||
const amount = value ? ethers.utils.parseUnits(value) : null; | ||
updateCall({ | ||
...decodedCall, | ||
args: { | ||
...decodedCall.args, | ||
amount, | ||
}, | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
setRepAmount((repPercent / 100) * totalSupply); | ||
if (repAmount) { | ||
setCallDataAmount(repAmount.toString()); | ||
} | ||
}, [repPercent, repAmount, totalSupply]); | ||
|
||
const handleRepChange = (e: number) => { | ||
if (e) { | ||
setRepPercent(e); | ||
} | ||
}; | ||
return ( | ||
<React.Fragment> | ||
<Control> | ||
<ControlLabel> | ||
Recipient | ||
<StyledIcon src={Info} /> | ||
</ControlLabel> | ||
<ControlRow> | ||
<Input | ||
value={shortenAddress(parsedData?.toAddress)} | ||
icon={ | ||
<Avatar | ||
src={imageUrl} | ||
defaultSeed={parsedData?.toAddress} | ||
size={18} | ||
/> | ||
} | ||
readOnly | ||
/> | ||
</ControlRow> | ||
</Control> | ||
<ControlRow> | ||
<Control> | ||
<ControlLabel> | ||
Reputation in % <StyledIcon src={Info} /> | ||
</ControlLabel> | ||
<ControlRow> | ||
<RepMintInput value={repPercent} onUserInput={handleRepChange} /> | ||
</ControlRow> | ||
</Control> | ||
</ControlRow> | ||
<ControlRow> | ||
<Control> | ||
<ControlLabel> | ||
Reputation Amount <StyledIcon src={Info} /> | ||
</ControlLabel> | ||
<ControlRow> | ||
<RepMintInput | ||
value={repAmount} | ||
onUserInput={handleRepChange} | ||
readOnly | ||
/> | ||
</ControlRow> | ||
</Control> | ||
</ControlRow> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default Mint; |
46 changes: 46 additions & 0 deletions
46
src/components/Guilds/ActionsBuilder/SupportedActions/REPMint/REPMintInfoLine.tsx
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,46 @@ | ||
import Avatar from 'components/Guilds/Avatar'; | ||
import useENSAvatar from 'hooks/Guilds/ether-swr/ens/useENSAvatar'; | ||
import { FiArrowRight } from 'react-icons/fi'; | ||
import { MAINNET_ID, shortenAddress } from 'utils'; | ||
import { ActionViewProps } from '..'; | ||
import { Segment } from '../common/infoLine'; | ||
import { ReactComponent as Mint } from '../../../../../assets/images/mint.svg'; | ||
import StyledIcon from 'components/Guilds/common/SVG'; | ||
import styled from 'styled-components'; | ||
import useBigNumberToNumber from 'hooks/Guilds/conversions/useBigNumberToNumber'; | ||
import { useTotalSupply } from 'hooks/Guilds/guild/useTotalSupply'; | ||
import { useTokenData } from 'hooks/Guilds/guild/useTokenData'; | ||
|
||
const StyledMintIcon = styled(StyledIcon)` | ||
margin: 0; | ||
`; | ||
|
||
const REPMintInfoLine: React.FC<ActionViewProps> = ({ decodedCall }) => { | ||
const { parsedData } = useTotalSupply({ decodedCall }); | ||
const { tokenData } = useTokenData(); | ||
|
||
const totalSupply = useBigNumberToNumber(tokenData?.totalSupply, 18); | ||
|
||
const { ensName, imageUrl } = useENSAvatar(parsedData?.toAddress, MAINNET_ID); | ||
|
||
const roundedRepAmount = useBigNumberToNumber(parsedData?.amount, 16, 3); | ||
const roundedRepPercent = roundedRepAmount / totalSupply; | ||
|
||
return ( | ||
<> | ||
<Segment> | ||
<StyledMintIcon src={Mint} /> | ||
</Segment> | ||
<Segment>Mint {roundedRepPercent} %</Segment> | ||
<Segment> | ||
<FiArrowRight /> | ||
</Segment> | ||
<Segment> | ||
<Avatar defaultSeed={parsedData?.toAddress} src={imageUrl} size={24} /> | ||
</Segment> | ||
<Segment>{ensName || shortenAddress(parsedData?.toAddress)}</Segment> | ||
</> | ||
); | ||
}; | ||
|
||
export default REPMintInfoLine; |
44 changes: 44 additions & 0 deletions
44
src/components/Guilds/ActionsBuilder/SupportedActions/REPMint/REPMintSummary.tsx
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,44 @@ | ||
import Avatar from 'components/Guilds/Avatar'; | ||
import useBigNumberToNumber from 'hooks/Guilds/conversions/useBigNumberToNumber'; | ||
import useENSAvatar from 'hooks/Guilds/ether-swr/ens/useENSAvatar'; | ||
import { MAINNET_ID, shortenAddress } from 'utils'; | ||
import { ActionViewProps } from '..'; | ||
import { Segment } from '../common/infoLine'; | ||
import { DetailCell, DetailHeader, DetailRow } from '../common/summary'; | ||
import { useTotalSupply } from 'hooks/Guilds/guild/useTotalSupply'; | ||
import { useTokenData } from 'hooks/Guilds/guild/useTokenData'; | ||
|
||
const REPMintSummary: React.FC<ActionViewProps> = ({ decodedCall }) => { | ||
const { parsedData } = useTotalSupply({ decodedCall }); | ||
const { tokenData } = useTokenData(); | ||
const { ensName, imageUrl } = useENSAvatar(parsedData?.toAddress, MAINNET_ID); | ||
|
||
const roundedRepAmount = useBigNumberToNumber(parsedData?.amount, 18, 3); | ||
|
||
return ( | ||
<> | ||
<DetailHeader> | ||
<DetailCell>Receiver</DetailCell> | ||
<DetailCell>Amount</DetailCell> | ||
</DetailHeader> | ||
|
||
<DetailRow> | ||
<DetailCell> | ||
<Segment> | ||
<Avatar | ||
defaultSeed={parsedData?.toAddress} | ||
src={imageUrl} | ||
size={24} | ||
/> | ||
</Segment> | ||
<Segment>{ensName || shortenAddress(parsedData?.toAddress)}</Segment> | ||
</DetailCell> | ||
<DetailCell> | ||
{roundedRepAmount} {tokenData?.name} | ||
</DetailCell> | ||
</DetailRow> | ||
</> | ||
); | ||
}; | ||
|
||
export default REPMintSummary; |
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.