-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: captcha faucet * fix: env example * feat: new market, send up faucet address to api * feat: configure new markets * feat: send up token symbol * feat: new ui for captcha faucet * chore: new markets * feat: captcha faucet modal * fix: goerli facuet config * fix: error handling * fix: auto refresh token * fix: updated env types * ci: add turnstile key * fix: cleanup reused code * fix: updated wording in success modal * chore: i18n * refactor: tx success view * fix: remove txHash prop * feat: added v3.0.1 market, use new flag to determine which faucet to use * feat: handle all types of faucets * fix: don't use modal wrapper for permissioned faucets * fix: use latest temp build of utils, fixed race condtion with multiple calls in flight * feat: udated UiPoolDataProvider contracts * fix: v2 market config * fix: updated ui pool data provider for goerli v3 * fix: updated v2 goerli, removed console log * fix: update prod markets with new data provider contracts * fix: better error handling * fix: updated v3 markets * fix: op v3 testnet * feat: goerli market config * fix: add site key to env * fix: updated config for prod v2 markets * fix: market config * chore: use latest utils packages * Fix tests * fix: temporaily disalbe pokt rpcs for testing * fix: attribute name * fix: test e-mode * fix: add back in pokt rpcs * fix: remove dependency Co-authored-by: Vladimir Yumatov <vladimir@aave.com> Co-authored-by: Mark Hinschberger <foodaka@users.noreply.github.com> Co-authored-by: bojank93 <bojan@aave.com> Co-authored-by: NikitaY <right2maresko@gmail.com>
- Loading branch information
1 parent
a8b6dee
commit 74bd1ac
Showing
25 changed files
with
505 additions
and
113 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
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
128 changes: 128 additions & 0 deletions
128
src/components/transactions/Faucet/CaptchaFaucetModalContent.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,128 @@ | ||
import { Trans } from '@lingui/macro'; | ||
import { Box, Button, CircularProgress, Typography } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider'; | ||
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context'; | ||
import { selectCurrentReserves } from 'src/store/poolSelectors'; | ||
import { useRootStore } from 'src/store/root'; | ||
|
||
import { TxSuccessView } from '../FlowCommons/Success'; | ||
import { DetailsNumberLine } from '../FlowCommons/TxModalDetails'; | ||
import Turnstile from './Turnstile'; | ||
import { getNormalizedMintAmount } from './utils'; | ||
|
||
export const CaptchaFaucetModalContent = ({ underlyingAsset }: { underlyingAsset: string }) => { | ||
const { readOnlyModeAddress } = useWeb3Context(); | ||
const { account, currentMarket, currentMarketData } = useRootStore(); | ||
const reserves = useRootStore((state) => selectCurrentReserves(state)); | ||
|
||
const [captchaToken, setCaptchaToken] = useState<string>(''); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [captchaLoading, setCaptchaLoading] = useState<boolean>(true); | ||
const [txHash, setTxHash] = useState<string>(''); | ||
const [error, setError] = useState<string>(''); | ||
|
||
const faucetUrl = `${process.env.NEXT_PUBLIC_API_BASEURL}/faucet`; | ||
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY as string; | ||
|
||
const poolReserve = reserves.find( | ||
(reserve) => reserve.underlyingAsset === underlyingAsset | ||
) as ComputedReserveData; | ||
|
||
const normalizedAmount = getNormalizedMintAmount(poolReserve.symbol, poolReserve.decimals); | ||
|
||
const captchaVerify = (token: string) => { | ||
setCaptchaToken(token); | ||
setCaptchaLoading(false); | ||
}; | ||
|
||
const faucet = async () => { | ||
try { | ||
setTxHash(''); | ||
setLoading(true); | ||
setError(''); | ||
const response = await fetch(faucetUrl, { | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
address: account, | ||
captchaToken, | ||
market: currentMarket, | ||
tokenAddress: poolReserve.underlyingAsset, | ||
tokenSymbol: poolReserve.symbol, | ||
faucetAddress: currentMarketData.addresses.FAUCET, | ||
}), | ||
}); | ||
const data = await response.json(); | ||
if (!response.ok) { | ||
throw new Error(data.msg); | ||
} | ||
setTxHash(data.msg); | ||
} catch (e: unknown) { | ||
if (e instanceof Error && e.message) { | ||
setError(e.message); | ||
} else { | ||
setError('An error occurred trying to send the transaction'); | ||
} | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
if (txHash) { | ||
return ( | ||
<TxSuccessView | ||
txHash={txHash} | ||
action={<Trans>will receive</Trans>} | ||
symbol={poolReserve.symbol} | ||
amount={normalizedAmount} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<Turnstile sitekey={siteKey} onVerify={captchaVerify} autoResetOnExpire /> | ||
<Typography variant="h2" sx={{ mb: 6 }}> | ||
<Trans>Faucet</Trans> {poolReserve.symbol} | ||
</Typography> | ||
<Box | ||
sx={(theme) => ({ | ||
p: 3, | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: '4px', | ||
'.MuiBox-root:last-of-type': { | ||
mb: 0, | ||
}, | ||
})} | ||
> | ||
<DetailsNumberLine | ||
description={<Trans>Amount</Trans>} | ||
iconSymbol={poolReserve.symbol} | ||
symbol={poolReserve.symbol} | ||
value={normalizedAmount} | ||
/> | ||
</Box> | ||
<Typography variant="helperText" color="error.main"> | ||
{error} | ||
</Typography> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', mt: 12 }}> | ||
<Button | ||
variant="contained" | ||
disabled={loading || !captchaToken || readOnlyModeAddress !== undefined} | ||
onClick={faucet} | ||
size="large" | ||
sx={{ minHeight: '44px' }} | ||
> | ||
{(loading || captchaLoading) && ( | ||
<CircularProgress color="inherit" size="16px" sx={{ mr: 2 }} /> | ||
)} | ||
{<Trans>Faucet {poolReserve.symbol}</Trans>} | ||
</Button> | ||
</Box> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import { Trans } from '@lingui/macro'; | ||
import React from 'react'; | ||
import { ModalContextType, ModalType, useModalContext } from 'src/hooks/useModal'; | ||
import { useRootStore } from 'src/store/root'; | ||
|
||
import { BasicModal } from '../../primitives/BasicModal'; | ||
import { ModalWrapper } from '../FlowCommons/ModalWrapper'; | ||
import { CaptchaFaucetModalContent } from './CaptchaFaucetModalContent'; | ||
import { FaucetModalContent } from './FaucetModalContent'; | ||
|
||
export const FaucetModal = () => { | ||
const { type, close, args } = useModalContext() as ModalContextType<{ | ||
underlyingAsset: string; | ||
}>; | ||
|
||
const { isFaucetPermissioned } = useRootStore(); | ||
|
||
return ( | ||
<BasicModal open={type === ModalType.Faucet} setOpen={close}> | ||
<ModalWrapper title={<Trans>Faucet</Trans>} underlyingAsset={args.underlyingAsset}> | ||
{(params) => <FaucetModalContent {...params} />} | ||
</ModalWrapper> | ||
{isFaucetPermissioned ? ( | ||
<CaptchaFaucetModalContent underlyingAsset={args.underlyingAsset} /> | ||
) : ( | ||
<ModalWrapper title={<Trans>Faucet</Trans>} underlyingAsset={args.underlyingAsset}> | ||
{(params) => <FaucetModalContent {...params} />} | ||
</ModalWrapper> | ||
)} | ||
</BasicModal> | ||
); | ||
}; |
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.
74bd1ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit was deployed on ipfs
74bd1ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit was deployed on ipfs
74bd1ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit was deployed on ipfs
74bd1ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit was deployed on ipfs