Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ens names support for airdrop #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions pages/airdrop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Airdrop = () => {
}, [router.isReady, router.query])

const { web3 } = useContext(Web3Context)
const ens = web3.eth.ens

const onError = (error: { message: string }) => {
toast(error?.message ?? 'Error', 'error', 5000)
Expand Down Expand Up @@ -88,17 +89,31 @@ const Airdrop = () => {
},
)

const handleSubmit = () => {
const handleSubmit = async () => {
if (claimantAddress === '' || claimantEmail === '' || claimantDiscord === '' || claimantPassword === '') {
onError({ message: 'please fill all fields' })
return
}
if (!web3.utils.isAddress(claimantAddress)) {
onError({ message: 'address is not valid' })
return

let address
if (web3.utils.isAddress(claimantAddress)) {
address = claimantAddress
} else {
try {
if (web3.currentProvider) {
address = await ens.getAddress(claimantAddress)
} else {
onError({ message: 'to resolve ens name please connect metamask' })
return
}
} catch (err) {
onError({ message: 'address or ens name is not valid' })
return
}
}

createPublicEntryMutation.mutate({
address: claimantAddress,
address: address,
email: claimantEmail,
discord: claimantDiscord,
password: claimantPassword,
Expand Down Expand Up @@ -127,7 +142,7 @@ const Airdrop = () => {
<Input
variant='address'
onKeyDown={handleKeyDown}
placeholder='wallet address'
placeholder='wallet address or ens name'
type='text'
value={claimantAddress}
onChange={(e) => {
Expand Down