Skip to content

Commit

Permalink
links to relay and faucet inside bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
- committed Sep 29, 2021
1 parent a4b840f commit 65ee301
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 152 deletions.
7 changes: 3 additions & 4 deletions src/modals/ChainModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function ChainModal({
const { chainId, library, account, activate } = useWeb3React(BridgeContextName)

const goToRelay = () => {
window.open('https://app.relaychain.com/transfer', '_blank').focus();
window.open('https://app.relaychain.com/transfer', '_blank').focus()
}

return (
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function ChainModal({

{/* Redirect to relay bridge while implementing UI integration */}
<button className="w-full col-span-1 p-px rounded bg-dark-800 hover:bg-dark-900" onClick={() => goToRelay()}>
<div className="flex items-center w-full h-full p-3 space-x-3 rounded bg-dark-1000">
<div className="flex items-center w-full h-full p-3 space-x-3 rounded">
<Image
src={NETWORK_ICON[ChainId.AVALANCHE]}
alt={`Select ${NETWORK_LABEL[ChainId.AVALANCHE]} Network`}
Expand All @@ -150,7 +150,7 @@ export default function ChainModal({
</button>

<button className="w-full col-span-1 p-px rounded bg-dark-800 hover:bg-dark-900" onClick={() => goToRelay()}>
<div className="flex items-center w-full h-full p-3 space-x-3 rounded bg-dark-1000">
<div className="flex items-center w-full h-full p-3 space-x-3 rounded">
<Image
src={NETWORK_ICON[ChainId.MATIC]}
alt={`Select ${NETWORK_LABEL[ChainId.MATIC]} Network`}
Expand All @@ -162,7 +162,6 @@ export default function ChainModal({
<ExternalLinkIcon style={{ width: '26px', height: '26px', marginLeft: 'auto' }} />
</div>
</button>

</div>
</Modal>
)
Expand Down
187 changes: 187 additions & 0 deletions src/pages/bridge/faucet/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/* eslint-disable @next/next/link-passhref */

import Head from 'next/head'
import React, { useCallback, useState } from 'react'
import { t } from '@lingui/macro'
import { formatNumberScale } from '../../../functions'
import { ButtonError } from '../../../components/Button'
import { AutoColumn } from '../../../components/Column'
import { AutoRow } from '../../../components/Row'
import DoubleGlowShadow from '../../../components/DoubleGlowShadow'
import SolarbeamLogo from '../../../components/SolarbeamLogo'
import Container from '../../../components/Container'
import Typography from '../../../components/Typography'
import { i18n } from '@lingui/core'
import Image from '../../../components/Image'
import { useActiveWeb3React } from '../../../hooks'
import Web3Connect from '../../../components/Web3Connect'
import { Loader } from 'react-feather'
import { useETHBalances } from '../../../state/wallet/hooks'
import axios from 'axios'
import ReCAPTCHA from 'react-google-recaptcha'
import { FAUCET_ADDRESS } from '../../../constants'
import NavLink from '../../../components/NavLink'

export default function Faucet(): JSX.Element {
const { chainId, account, library } = useActiveWeb3React()
const [token, setToken] = useState('')
const tokenBalance = useETHBalances([FAUCET_ADDRESS])
const [pendingTx, setPendingTx] = useState(false)
const [requested, setRequested] = useState(false)
const [faucetResult, setFaucetResult] = useState({ status: 200, message: null })
const recaptchaRef: any = React.createRef()

const onReCAPTCHAChange = async (captchaCode) => {
if (!captchaCode) {
return
}

setPendingTx(true)

try {
const faucetResponse = await axios.post('/api/faucet', { address: account, 'g-recaptcha-response': captchaCode })
if (faucetResponse.data) {
setFaucetResult(faucetResponse.data)
if (faucetResponse.data.status == 200) {
setRequested(true)
} else if (faucetResponse.data.message.indexOf('daily limit') >= 0) {
setRequested(true)
}
}
} catch (err) {
setFaucetResult({ status: 400, message: 'Failed to send the request to the server.' })
} finally {
setPendingTx(false)
}
}

const handleRequest = useCallback(async () => {
recaptchaRef.current.execute()
}, [recaptchaRef])

return (
<>
<Head>
<title>Faucet | Solarbeam</title>
<meta key="description" name="description" content="Moonriver Faucet" />
</Head>

<SolarbeamLogo />

<ReCAPTCHA
ref={recaptchaRef}
size="invisible"
sitekey={'6LeaGV4cAAAAAE2HKmub-Ilnb7raS1JfhdfhfrP1'}
onChange={onReCAPTCHAChange}
/>

<Container maxWidth="2xl" className="space-y-6">
<DoubleGlowShadow opacity="0.6">
<div className="p-4 space-y-4 rounded bg-dark-900" style={{ zIndex: 1 }}>
<div className="flex items-center justify-center mb-4 space-x-3">
<div className="grid grid-cols-3 rounded p-3px bg-dark-800 h-[46px]">
<NavLink
activeClassName="font-bold border rounded text-high-emphesis border-dark-700 bg-dark-700"
exact
href={{
pathname: '/bridge',
}}
>
<a className="flex items-center justify-center px-4 text-base font-medium text-center rounded-md text-secondary hover:text-high-emphesis ">
<Typography component="h1" variant="lg">
{i18n._(t`Bridge`)}
</Typography>
</a>
</NavLink>
<NavLink
activeClassName="font-bold border rounded text-high-emphesis border-dark-700 bg-dark-700"
exact
href={{
pathname: '/bridge/history',
}}
>
<a className="flex items-center justify-center px-4 text-base font-medium text-center rounded-md text-secondary hover:text-high-emphesis">
<Typography component="h1" variant="lg">
{i18n._(t`History`)}
</Typography>
</a>
</NavLink>
<NavLink
activeClassName="font-bold border rounded text-high-emphesis border-dark-700 bg-dark-700"
exact
href={{
pathname: '/bridge/faucet',
}}
>
<a className="flex items-center justify-center px-4 text-base font-medium text-center rounded-md text-secondary hover:text-high-emphesis">
<Typography component="h1" variant="lg">
{i18n._(t`Faucet`)}
</Typography>
</a>
</NavLink>
</div>
</div>
<div className="h-[570px] flex flex-col justify-center items-center">
<div className="p-4 mb-3 space-y-3 text-center">
<Typography component="h1" variant="base">
A Faucet is a tool that provides a small amount of MOVR for users that used the bridge to start using
Solarbeam.io without having to buy MOVR somewhere else.
</Typography>
</div>
<div className="flex flex-1 justify-center text-center items-center mt-8 mb-12">
<Image src="/images/faucet/moonriver-faucet.png" alt="Solarbeam" width={150} height={150} />
</div>
<div className="p-4 mb-3 space-y-1 text-center">
<Typography component="h1" variant="base">
Faucet balance:{' '}
{formatNumberScale(tokenBalance[FAUCET_ADDRESS]?.toSignificant(4, undefined, 2) ?? 0, false, 4)} MOVR
</Typography>
<Typography component="h1" variant="base">
Faucet Address: {FAUCET_ADDRESS}
</Typography>
</div>

<AutoColumn gap={'md'}>
<div className={'flex items-center w-full'}>
{!account ? (
<Web3Connect size="lg" color="gradient" className="w-full" />
) : (
<ButtonError
className="font-bold text-light"
onClick={handleRequest}
style={{
width: '100%',
}}
disabled={pendingTx || requested}
>
{pendingTx ? (
<div>
<AutoRow gap="6px" justify="center" align="center">
Requesting <Loader stroke="white" />
</AutoRow>
</div>
) : (
i18n._(t`Give me some MOVR`)
)}
</ButtonError>
)}
</div>
</AutoColumn>
<div className="p-4 mb-3 space-y-3 text-center">
{faucetResult?.message && (
<Typography
component="h1"
variant="base"
className={`${faucetResult?.status == 200 ? 'text-green' : 'text-red'}`}
>
{faucetResult?.message}
</Typography>
)}
</div>
</div>
</div>
</DoubleGlowShadow>
</Container>
</>
)
}
4 changes: 2 additions & 2 deletions src/pages/bridge/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export default function Bridge() {
activeClassName="font-bold border rounded text-high-emphesis border-dark-700 bg-dark-700"
exact
href={{
pathname: '/faucet',
pathname: '/bridge/faucet',
}}
>
<a className="flex items-center justify-center px-4 text-base font-medium text-center rounded-md text-secondary hover:text-high-emphesis">
Expand Down Expand Up @@ -297,7 +297,7 @@ export default function Bridge() {
{!account && activeAccount ? (
<Web3Connect size="lg" color="gradient" className="w-full" />
) : (
<div className="space-y-2 p-4 rounded bg-dark-800 mb-2 h-[480px] overflow-y-auto">
<div className="space-y-2 p-4 rounded bg-dark-800 mb-2 h-[455px] overflow-y-auto">
{allTransactions && Object.keys(allTransactions).length > 0 ? (
<>
<div className="flex px-2 hidden md:flex text-base font-bold text-primary items-center">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export default function Bridge() {
activeClassName="font-bold border rounded text-high-emphesis border-dark-700 bg-dark-700"
exact
href={{
pathname: '/faucet',
pathname: '/bridge/faucet',
}}
>
<a className="flex items-center justify-center px-4 text-base font-medium text-center rounded-md text-secondary hover:text-high-emphesis">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/eclipse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function NFTLaunchpad(): JSX.Element {
<div className="container px-0 mx-auto pb-6">
<div className={`mb-2 grid grid-cols-12 gap-4`}>
<div className="flex justify-center items-center col-span-12 lg:justify">
<Link href="/eclipse">Coming sooon</Link>
<Link href="/eclipse">Coming soon</Link>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 65ee301

Please sign in to comment.