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

Sameer/use airstack for ens resolution #69

Open
wants to merge 9 commits into
base: test
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/api/leaderboard/route.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ArtistTitle from '@/components/ArtistTitle';
import FrameFooter from '@/components/FrameFooter';
import Leaderboard from '@/components/Leaderboard';
import getEnsName from '@/lib/getEnsName';
import { getEnsName } from '@/lib/getEnsName';
import getEthPrice from '@/lib/getEthPrice';
import getAllIndexedData from '@/lib/getIndexedData';
import getLeaderboard from '@/lib/getLeaderboard';
Expand Down
5 changes: 4 additions & 1 deletion components/LandingPage/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Button from '@/components/Button';
import { VERCEL_URL } from '@/lib/consts';
import { getEthAddressFromAirstack } from '@/lib/getEnsName';
import { ethPublicClient } from '@/lib/publicClient';
import { useEffect, useState } from 'react';
import { isAddress } from 'viem';
Expand All @@ -11,7 +12,9 @@ const SearchBar = () => {
const handleInputChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
setCreator(e.target.value);
if (!isAddress(e.target.value)) {
const address = await ethPublicClient.getEnsAddress({ name: e.target.value });
if (e.target.value.length < 3) return;
if (!e.target.value.endsWith('.eth')) return;
const address = await getEthAddressFromAirstack(e.target.value);
if (address && isAddress(address)) {
setCreator(address);
}
Expand Down
1 change: 1 addition & 0 deletions lib/eth_getLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PublicClient } from 'viem';
export const getLogs = async (
contractAddress: String[],
topics: Array<String>,
Expand Down
2 changes: 1 addition & 1 deletion lib/getDataWithNamesAndAvatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const mapAddressToProfile = (domains: any) => {
const mapAddressToSocial = (socials: any) => {
if (!socials) return [];
const addressToSocial: any = {};
socials.forEach((social: any) => {
socials?.forEach((social: any) => {
social.userAssociatedAddresses.forEach((address: any) => {
addressToSocial[address] = {
profileName: social.profileName,
Expand Down
29 changes: 27 additions & 2 deletions lib/getEnsName.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { normalize } from 'viem/ens';
import { ethPublicClient } from './publicClient';
import { AIRSTACK_API_URL } from './consts';

const getEnsName = async (address: string) => {
export const getEnsName = async (address: string) => {
const ensName = await ethPublicClient.getEnsName({
address: normalize(address as string) as any,
});
Expand All @@ -15,4 +16,28 @@ export const getEnsAddress = async (name: string) => {
return ensAddress;
};

export default getEnsName;
const query = ` query MyQuery($creator: String){
Domains(
input: {filter: {name: {_eq: $creator}}, blockchain: ethereum}
) {
Domain {
manager
}
}
}`;

export const getEthAddressFromAirstack = async (creator: string) => {
const variables = {
creator,
};
const res = await fetch(AIRSTACK_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `${process.env.NEXT_PUBLIC_AIRSTACK_API_KEY}`,
},
body: JSON.stringify({ query, variables }),
});
const data = await res.json();
return data?.data?.Domains?.Domain?.[0]?.manager;
};
3 changes: 2 additions & 1 deletion lib/getProperAdress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isAddress } from 'viem';
import { ethPublicClient } from './publicClient';
import { getEthAddressFromAirstack } from './getEnsName';

export const getProperAddress = async (creator: string) => {
return !isAddress(creator) ? await ethPublicClient.getEnsAddress({ name: creator }) : creator;
return !isAddress(creator) ? await getEthAddressFromAirstack(creator) : creator;
};
12 changes: 4 additions & 8 deletions lib/getSortedLeaderboard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const getSortedLeaderboard = (leaderboard: any[]) =>
leaderboard.sort((a: any, b: any) => {
const rewardA = BigInt(a.totalCreatorReward);
const rewardB = BigInt(b.totalCreatorReward);
if (rewardA > rewardB) return -1;
if (rewardA < rewardB) return 1;
const getSortedLeaderboard = (leaderboard: any[]) => {
return leaderboard.sort((a: any, b: any) => {
if (a.editions > b.editions) return -1;
if (a.editions < b.editions) return 1;
else if (a.editions < b.editions) return 1;
return a.buyer.localeCompare(b.buyer);
});

};
export default getSortedLeaderboard;
16 changes: 13 additions & 3 deletions lib/publicClient.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { createPublicClient, http } from 'viem';
import { base, mainnet, optimism } from 'viem/chains';
import { base, mainnet, optimism, arbitrum, zora } from 'viem/chains';

export const ethPublicClient = createPublicClient({
chain: mainnet,
transport: http(),
transport: http(`https://eth-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_KEY}`),
});

export const optimismPublicClient = createPublicClient({
chain: optimism,
transport: http(),
transport: http(`https://opt-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_KEY}`),
});

export const basePublicClient = createPublicClient({
chain: base,
transport: http(`https://base-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_KEY}`),
});

export const arbitrumPublicClient = createPublicClient({
chain: arbitrum,
transport: http(),
});

export const zoraPublicClient = createPublicClient({
chain: zora,
transport: http(),
});
20 changes: 15 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,16 @@
resolved "https://registry.yarnpkg.com/@resvg/resvg-wasm/-/resvg-wasm-2.4.0.tgz#e01164b9a267c822e1ff797daa2fb91b663ea6f0"
integrity sha512-C7c51Nn4yTxXFKvgh2txJFNweaVcfUPQxwEUFw4aWsCmfiBDJsTSwviIF8EcwjQ6k8bPyMWCl1vw4BdxE569Cg==

"@scure/base@^1.1.3", "@scure/base@~1.1.0", "@scure/base@~1.1.2", "@scure/base@~1.1.4":
"@scure/base@^1.1.3", "@scure/base@~1.1.4":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.5.tgz#1d85d17269fe97694b9c592552dd9e5e33552157"
integrity sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ==

"@scure/base@~1.1.0", "@scure/base@~1.1.2":
version "1.1.6"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.6.tgz#8ce5d304b436e4c84f896e0550c83e4d88cb917d"
integrity sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==

"@scure/[email protected]":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.2.tgz#90e78c027d5e30f0b22c1f8d50ff12f3fb7559f8"
Expand Down Expand Up @@ -2873,6 +2878,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74"
integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==

[email protected]:
version "1.0.4"
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.4.tgz#810cd0d90cc4995c26395d2aa4cfa4037ebdf061"
integrity sha512-hEzjY+x9u9hPmBom9IIAqdJCwNLax+xrPb51vEPpERoFlIxgmZcHzsT5jKG06nvInKOBGvReAVz80Umed5CczQ==

jackspeak@^2.3.5:
version "2.3.6"
resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-2.3.6.tgz#647ecc472238aee4b06ac0e461acc21a8c505ca8"
Expand Down Expand Up @@ -4534,17 +4544,17 @@ viem@^1.1.4:
ws "8.13.0"

viem@^2.7.1:
version "2.7.15"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.7.15.tgz#0dfdcb75be196c85839950b0ccb88be0b377609c"
integrity sha512-I2RMQpg1/MC7fXVjHxeXRPU9k/WEOvZajK/KZSr7DChS0AaZ7uovsQWppwBn2wvZWguTCIRAHqzMwIEGku95yQ==
version "2.10.9"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.10.9.tgz#2ccd69cb073b547507ea86c42c122daa3128af55"
integrity sha512-XsbEXhOcmQOkI80zDLW0EdksimNuYTS61HZ03vQYpHoug7gwVHDQ83nY+nuyT7punuFx0fmRG6+HZg3yVQhptQ==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@scure/bip32" "1.3.2"
"@scure/bip39" "1.2.1"
abitype "1.0.0"
isows "1.0.3"
isows "1.0.4"
ws "8.13.0"

viem@^2.7.14:
Expand Down