@@ -11,15 +11,20 @@ import { randomBytes } from '@ethersproject/random'
1111import { keccak256 } from '@ethersproject/keccak256'
1212import { ZERO_ADDRESS } from '../../config'
1313import { commit } from '../../utils/eth-swap'
14- import { InputRow } from '../input-row'
14+ import { CustomDecimalInput } from '../input-row'
1515import { CurrencyBadge } from './currency-badge'
1616// @ts -ignore
1717import PowDumpSmallLogo from '../../public/assets/images/powdump_dapp_small_pow.png'
1818// @ts -ignore
1919import EthereumLogo from '../../public/assets/images/ethereum-logo.png'
2020import { Button } from '../button'
2121import dynamic from 'next/dynamic'
22- import { isSwapSupportedOnChain } from "../../utils/helpers" ;
22+ import { isSwapSupportedOnChain } from '../../utils/helpers'
23+ import { useEthBalance } from '../../hooks/useEthBalance'
24+ import { CurrencyAmount } from '@uniswap/sdk-core'
25+ import { ExtendedEther } from '../../utils/ether'
26+ import { maxAmountSpend } from '../../utils/maxAmountSpend'
27+ import { SupportedChainId } from "../../constants/chains" ;
2328
2429const PriceRow = dynamic ( ( ) => import ( './price-row' ) , {
2530 ssr : false ,
@@ -37,7 +42,7 @@ const errorsTranslations = {
3742 [ NO_POS_AMOUNT_ENTERED as string ] : 'Enter expected PoS amount' ,
3843 [ TERMS_NOT_ACCEPTED as string ] : 'Accept terms and conditions' ,
3944 [ PRICE_CANT_BE_ZERO as string ] : "Price can't be 0" ,
40- [ SWAP_NOT_SUPPORTED_ON_CHAIN as string ] : " Chain not supported for starting a swap" ,
45+ [ SWAP_NOT_SUPPORTED_ON_CHAIN as string ] : ' Chain not supported for starting a swap' ,
4146}
4247
4348type Props = {
@@ -65,7 +70,7 @@ const validateForm = ({
6570 throw new Error ( NO_WALLET_CONNECTED )
6671 }
6772
68- if ( ! chainId || ! isSwapSupportedOnChain ( chainId ) ) {
73+ if ( ! chainId || ! isSwapSupportedOnChain ( chainId ) ) {
6974 throw new Error ( 'SWAP_NOT_SUPPORTED_ON_CHAIN' )
7075 }
7176
@@ -127,6 +132,7 @@ export function DumpForm() {
127132 const deleteTxSecrets = useStore ( state => state . deleteTxSecrets )
128133 const setNotification = useStore ( state => state . setNotification )
129134 const { account, provider, chainId } = useWeb3React < Web3Provider > ( )
135+ const { balance } = useEthBalance ( )
130136
131137 const [ error , setError ] = useState ( '' )
132138
@@ -243,25 +249,66 @@ export function DumpForm() {
243249 }
244250 }
245251
252+ const currencyAmount = CurrencyAmount . fromRawAmount (
253+ // ChainId doesn't really matter here as the currency is ETH (no matter the chainID)
254+ ExtendedEther . onCreate ( chainId ? chainId : SupportedChainId . MAINNET ) ,
255+ // @ts -ignore
256+ balance
257+ )
258+
259+ const maxAmount = maxAmountSpend ( currencyAmount )
260+ const maxAmountFormatted = maxAmount ? maxAmount . toExact ( ) : "0"
261+
246262 return (
247263 < >
248- < InputRow
249- id = "pow-amount"
250- value = { ethPoWAmount }
251- onChangeInputValue = { value => {
252- setPoWAmount ( value )
253- updateFormValue ( 'ethPoWAmount' , value )
254- } }
255- disabled = { ! isSwapEnabled }
256- type = "text"
257- placeholder = "0.0"
258- pattern = { '^[0-9]*[.,]?[0-9]*$' }
259- append = { < CurrencyBadge icon = { PowDumpSmallLogo } name = { 'PoW ETH' } /> }
260- />
264+ < div >
265+ < div className = { "relative" } >
266+ < div className = "flex flex-col rounded-md bg-brown-orange pt-3 border border-1 border-transparent hover:border-gray focus-within:border-gray" >
267+
268+ < div className = { "flex" } >
269+ < div className = { " flex-1 w-72" } >
270+ < CustomDecimalInput
271+ className = { "appearance-none outline-none bg-brown-orange text-2xl text-white pl-4 group-hover:text-white" }
272+ id = "pow-amount"
273+ value = { ethPoWAmount }
274+ onChangeInputValue = { value => {
275+ setPoWAmount ( value )
276+ updateFormValue ( 'ethPoWAmount' , value )
277+ } }
278+ disabled = { ! isSwapEnabled }
279+ type = "text"
280+ placeholder = "0.0"
281+ pattern = { '^[0-9]*[.,]?[0-9]*$' }
282+ />
283+ </ div >
284+ < div className = { "mr-5 bg-brown-orange pl-2" } >
285+ < CurrencyBadge icon = { PowDumpSmallLogo } name = { 'PoW ETH' } />
286+ </ div >
287+ </ div >
288+
289+ < div className = { 'flex flex-row justify-end items-center mr-5 text-gray text-sm mb-2' } >
290+ Balance: { currencyAmount . toFixed ( 5 ) }
291+ { maxAmountFormatted === ethPoWAmount ? null : (
292+ < button
293+ disabled = { ! isSwapEnabled }
294+ className = { 'bg-gray-500 border border-0 border-transparent rounded-sm px-2 text-gray hover:cursor-pointer hover:text-white hover:border-white hover:bg-rich-black-lighter ml-1' }
295+ onClick = { ( ) => {
296+ setPoWAmount ( maxAmountFormatted )
297+ updateFormValue ( 'ethPoWAmount' , maxAmountFormatted )
298+ } }
299+ >
300+ Max
301+ </ button >
302+ ) }
303+ </ div >
304+ </ div >
305+ </ div >
306+ </ div >
307+
261308 < div className = "w-full" >
262309 < div className = "flex flex-col rounded-md dark:bg-rich-black-lighter pt-2 border border-1 border-rich-black-lightest" >
263310 < div className = "flex flex-row my-2" >
264- < div className = { `flex-1 mx-5 ${ ! isSwapEnabled ? " text-gray" : "" } ` } >
311+ < div className = { `flex-1 mx-5 ${ ! isSwapEnabled ? ' text-gray' : '' } ` } >
265312 < PriceRow />
266313 < div className = { 'h-px bg-rich-black-lightest my-2' } > </ div >
267314
@@ -300,7 +347,7 @@ export function DumpForm() {
300347 updateFormValue ( 'termsAccepted' , ! termsAccepted )
301348 } }
302349 /> { ' ' }
303- < span className = { ! isSwapEnabled ? " text-gray" : "" } > I understand and accept the Terms & Conditions </ span >
350+ < span className = { ! isSwapEnabled ? ' text-gray' : '' } > I understand and accept the Terms & Conditions </ span >
304351 </ label >
305352 </ div >
306353
0 commit comments