-
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
362 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
150 changes: 150 additions & 0 deletions
150
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,150 @@ | ||
import styled from 'styled-components'; | ||
import { Input } from 'components/Guilds/common/Form/Input'; | ||
import Avatar from 'components/Guilds/Avatar'; | ||
import { useEffect, useMemo } from 'react'; | ||
import { ActionEditorProps } from '..'; | ||
import { BigNumber, 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 { useERC20Info } from 'hooks/Guilds/ether-swr/erc20/useERC20Info'; | ||
import { useGuildConfig } from 'hooks/Guilds/ether-swr/guild/useGuildConfig'; | ||
import { useParams } from 'react-router-dom'; | ||
import NumericalInput from 'components/Guilds/common/Form/NumericalInput'; | ||
|
||
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}; | ||
} | ||
`; | ||
|
||
interface REPMintState { | ||
toAddress: string; | ||
amount: BigNumber; | ||
} | ||
|
||
const Mint: React.FC<ActionEditorProps> = ({ decodedCall, updateCall }) => { | ||
// parse transfer state from calls | ||
const [repPercent, setRepPercent] = useState(0); | ||
const [repAmount, setRepAmount] = useState(0); | ||
const { guild_id: guildId } = | ||
useParams<{ chain_name?: string; guild_id?: string }>(); | ||
const { data } = useGuildConfig(guildId); | ||
const { data: tokenData } = useERC20Info(data?.token); | ||
const totalSupply = useBigNumberToNumber(tokenData?.totalSupply, 18); | ||
|
||
const parsedData = useMemo<REPMintState>(() => { | ||
if (!decodedCall) return null; | ||
return { | ||
toAddress: decodedCall.args.to, | ||
amount: decodedCall.args.amount, | ||
}; | ||
}, [decodedCall]); | ||
|
||
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 ( | ||
<div> | ||
<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> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Mint; |
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
import Avatar from 'components/Guilds/Avatar'; | ||
import useENSAvatar from 'hooks/Guilds/ether-swr/ens/useENSAvatar'; | ||
import { useMemo } from 'react'; | ||
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 { BigNumber } from 'ethers'; | ||
import useBigNumberToNumber from 'hooks/Guilds/conversions/useBigNumberToNumber'; | ||
import { useERC20Info } from 'hooks/Guilds/ether-swr/erc20/useERC20Info'; | ||
import { useGuildConfig } from 'hooks/Guilds/ether-swr/guild/useGuildConfig'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
const StyledMintIcon = styled(StyledIcon)` | ||
margin: 0; | ||
`; | ||
|
||
interface REPMintState { | ||
guildAddress: string; | ||
toAddress: string; | ||
amount: BigNumber; | ||
} | ||
|
||
const REPMintInfoLine: React.FC<ActionViewProps> = ({ decodedCall }) => { | ||
const { guild_id: guildId } = | ||
useParams<{ chain_name?: string; guild_id?: string }>(); | ||
const { data } = useGuildConfig(guildId); | ||
const { data: tokenData } = useERC20Info(data?.token); | ||
const totalSupply = useBigNumberToNumber(tokenData?.totalSupply, 18); | ||
|
||
const parsedData = useMemo<REPMintState>(() => { | ||
if (!decodedCall) return null; | ||
return { | ||
guildAddress: decodedCall.to, | ||
toAddress: decodedCall.args.to, | ||
amount: decodedCall.args.amount, | ||
}; | ||
}, [decodedCall]); | ||
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; |
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
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
Oops, something went wrong.