Skip to content

Commit

Permalink
Merge pull request #297 from reservoirprotocol/pedro/grwth-3082-list-…
Browse files Browse the repository at this point in the history
…with-erc20-on-explorer

List with erc20 on explorer
  • Loading branch information
pedromcunha authored Aug 10, 2023
2 parents 276c1fc + 4362126 commit e84536a
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 76 deletions.
22 changes: 2 additions & 20 deletions components/buttons/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import {
useAccount,
useNetwork,
useWalletClient,
mainnet,
useSwitchNetwork,
} from 'wagmi'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { ToastContext } from 'context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'
import { zeroAddress } from 'viem'

type ListingCurrencies = ComponentPropsWithoutRef<
typeof ListModal
Expand Down Expand Up @@ -57,24 +55,8 @@ const List: FC<Props> = ({
signer && marketplaceChain.id !== activeChain?.id
)

// CONFIGURABLE: Here you can configure which currencies you would like to support for listing
let listingCurrencies: ListingCurrencies = undefined
if (marketplaceChain.id === mainnet.id) {
listingCurrencies = [
{
contract: zeroAddress,
symbol: 'ETH',
coinGeckoId: 'ethereum',
},
{
contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
decimals: 6,
coinGeckoId: 'usd-coin',
},
]
}

const listingCurrencies: ListingCurrencies =
marketplaceChain.listingCurrencies
const tokenId = token?.token?.tokenId
const contract = token?.token?.contract

Expand Down
21 changes: 1 addition & 20 deletions components/portfolio/BatchListings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import BatchListModal from 'components/portfolio/BatchListModal'
import { useMediaQuery } from 'react-responsive'
import { BatchListingsTableHeading } from './BatchListingsTableHeading'
import { BatchListingsTableRow } from './BatchListingsTableRow'
import wrappedContracts from 'utils/wrappedContracts'
import { mainnet } from 'wagmi'

export type BatchListing = {
token: UserToken
Expand Down Expand Up @@ -105,24 +103,7 @@ const BatchListings: FC<Props> = ({
contract: chainCurrency.address,
symbol: chainCurrency.symbol,
}
// CONFIGURABLE: Here you can configure which currencies you would like to support for batch listing
let currencies: ListingCurrencies = [
{ ...defaultCurrency },
{
contract: wrappedContracts[chain.id],
decimals: 18,
symbol: `W${defaultCurrency.symbol}`,
},
]

if (chain.id === mainnet.id) {
currencies.push({
contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
decimals: 6,
coinGeckoId: 'usd-coin',
})
}
const currencies: ListingCurrencies = chain.listingCurrencies

const [currency, setCurrency] = useState<Currency>(
currencies && currencies[0] ? currencies[0] : defaultCurrency
Expand Down
11 changes: 3 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { DefaultChain } from './.cache/chains.mjs'
import { withSentryConfig } from '@sentry/nextjs'
import * as tsImport from 'ts-import'

const loadTS = (filePath) => tsImport.load(filePath)

const { DefaultChain: defaultChain } = await loadTS('./utils/chains.ts')

const sentryWebpackPluginOptions = {
org: process.env.SENTRY_ORG,
project: 'javascript-nextjs',
silent: true,
}

/**
* @type {import('next').NextConfig}
*/
Expand Down Expand Up @@ -41,7 +36,7 @@ const nextConfig = {
return [
{
source: '/',
destination: `/${defaultChain.routePrefix}`,
destination: `/${DefaultChain.routePrefix}`,
permanent: false,
},

Expand All @@ -57,7 +52,7 @@ const nextConfig = {
},
{
source: '/collection-rankings',
destination: `/${defaultChain.routePrefix}/collection-rankings`,
destination: `/${DefaultChain.routePrefix}/collection-rankings`,
permanent: true,
},
]
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"dev": "yarn prebuild && next",
"build": "yarn prebuild && next build",
"prebuild": "node ./scripts/prebuild.js",
"start": "yarn prebuild && next start",
"tsc": "tsc"
},
"dependencies": {
Expand Down Expand Up @@ -62,7 +63,6 @@
"@types/react": "^18.0",
"@types/react-dom": "^18.0",
"next-themes": "^0.2.0",
"ts-import": "^5.0.0-beta.0",
"typescript": "^4.9.4"
}
}
56 changes: 56 additions & 0 deletions scripts/prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { exec } = require('child_process')
const fs = require('fs')
const path = require('path')

async function listFilesInDirectory(directoryPath) {
try {
const files = await fs.readdir(directoryPath)
return files
} catch (err) {
console.error('Error reading directory:', err)
}
}

async function deleteAllFilesInDirectory(directoryPath) {
try {
const files = await fs.readdirSync(directoryPath)

for (const file of files) {
const filePath = path.join(directoryPath, file)
await fs.unlinkSync(filePath)
}
return true
} catch (err) {
return true
}
}

deleteAllFilesInDirectory('.cache').then(() => {
exec(
'tsc --module ES6 --outDir .cache ./utils/chains.ts',
(error, stdout, stderr) => {
const processFiles = async () => {
const files = fs.readdirSync('.cache')
for (fileId in files) {
const file = files[fileId]
if (file.endsWith('.js')) {
const originalPath = path.join('.cache', file)
const fileContents = await fs.readFileSync(originalPath, 'utf-8')
let modifiedContents = fileContents
files.forEach((filename) => {
const filenameWithoutExt = `./${filename.replace('.js', "'")}`
modifiedContents = modifiedContents.replace(
filenameWithoutExt,
`${filenameWithoutExt.replace("'", '')}.mjs'`
)
})
await fs.writeFileSync(originalPath, modifiedContents, 'utf-8')
const newPath = path.join('.cache', file.replace(/\.js$/, '.mjs'))
await fs.renameSync(originalPath, newPath)
}
}
}
processFiles()
}
)
})
64 changes: 64 additions & 0 deletions utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Currency } from '@reservoir0x/reservoir-kit-ui'
import wrappedContracts from './wrappedContracts'
import { zeroAddress } from 'viem'
import { arbitrum, mainnet, polygon, optimism, Chain, bsc } from 'wagmi/chains'
import usdcContracts from './usdcContracts'

//Chains that are missing from wagmi:
export const zora = {
Expand Down Expand Up @@ -128,6 +132,21 @@ export type ReservoirChain = Chain & {
coingeckoId?: string
collectionSetId?: string
community?: string
listingCurrencies?: Currency[]
}

const nativeCurrencyBase = {
contract: zeroAddress,
symbol: 'ETH',
decimals: 18,
coinGeckoId: 'ethereum',
}

const usdcCurrencyBase = {
contract: '',
symbol: 'USDC',
decimals: 6,
coinGeckoId: 'usd-coin',
}

export const DefaultChain: ReservoirChain = {
Expand Down Expand Up @@ -156,6 +175,13 @@ export const DefaultChain: ReservoirChain = {
coingeckoId: 'ethereum',
collectionSetId: process.env.NEXT_PUBLIC_ETH_COLLECTION_SET_ID,
community: process.env.NEXT_PUBLIC_ETH_COMMUNITY,
listingCurrencies: [
nativeCurrencyBase,
{
...usdcCurrencyBase,
contract: usdcContracts[mainnet.id],
},
],
}

export default [
Expand All @@ -171,6 +197,23 @@ export default [
coingeckoId: 'matic-network',
collectionSetId: process.env.NEXT_PUBLIC_POLYGON_COLLECTION_SET_ID,
community: process.env.NEXT_PUBLIC_POLYGON_COMMUNITY,
listingCurrencies: [
{
...nativeCurrencyBase,
symbol: 'MATIC',
coinGeckoId: 'matic-network',
},
{
...usdcCurrencyBase,
contract: usdcContracts[polygon.id],
},
{
contract: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
symbol: 'WETH',
decimals: 18,
coinGeckoId: 'weth',
},
],
},
{
...arbitrum,
Expand All @@ -184,6 +227,13 @@ export default [
coingeckoId: 'arbitrum-iou',
collectionSetId: process.env.NEXT_PUBLIC_ARBITRUM_COLLECTION_SET_ID,
community: process.env.NEXT_PUBLIC_ARBITRUM_COMMUNITY,
listingCurrencies: [
{ ...nativeCurrencyBase, coinGeckoId: 'arbitrum-iou' },
{
...usdcCurrencyBase,
contract: usdcContracts[arbitrum.id],
},
],
},
{
...arbitrumNova,
Expand All @@ -209,6 +259,13 @@ export default [
coingeckoId: 'optimism',
collectionSetId: process.env.NEXT_PUBLIC_OPTIMISM_COLLECTION_SET_ID,
community: process.env.NEXT_PUBLIC_OPTIMISM_COMMUNITY,
listingCurrencies: [
{ ...nativeCurrencyBase, coinGeckoId: 'optimism' },
{
...usdcCurrencyBase,
contract: usdcContracts[optimism.id],
},
],
},
{
...zora,
Expand All @@ -232,6 +289,13 @@ export default [
coingeckoId: 'binancecoin',
collectionSetId: process.env.NEXT_PUBLIC_BSC_COLLECTION_SET_ID,
community: process.env.NEXT_PUBLIC_BSC_COMMUNITY,
listingCurrencies: [
{ ...nativeCurrencyBase, coinGeckoId: 'binancecoin' },
{
...usdcCurrencyBase,
contract: usdcContracts[bsc.id],
},
],
},
{
...base,
Expand Down
11 changes: 11 additions & 0 deletions utils/usdcContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const usdcContracts: Record<number, string> = {
1: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', //mainnet
5: '0x07865c6e87b9f70255377e024ace6630c1eaa37f', //goerli
10: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', //optimism
56: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', //bnb
137: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', //polygon
42161: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', //arbitrum
80001: '0x0fa8781a83e46826621b3bc094ea2a0212e71b23', //mumbai
}

export default usdcContracts
1 change: 1 addition & 0 deletions utils/wrappedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const wrappedContracts: Record<number, string> = {
1: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', //mainnet
5: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', //goerli
10: '0x4200000000000000000000000000000000000006', //optimism
56: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', //bnb
137: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', //polygon
42161: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', //arbitrum
42170: '0x722e8bdd2ce80a4422e880164f2079488e115365', //arbitrum nova
Expand Down
24 changes: 0 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3015,11 +3015,6 @@ commander@^2.20.3:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

[email protected]:
version "1.3.1"
resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.3.1.tgz#3d7ea3adaf9345594aedee6563f422348f165c1b"
integrity sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA==

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down Expand Up @@ -4413,11 +4408,6 @@ openapi-typescript-fetch@^1.1.3:
resolved "https://registry.yarnpkg.com/openapi-typescript-fetch/-/openapi-typescript-fetch-1.1.3.tgz#354e6803b7885c7142ae11adc1b758afafd8aa2e"
integrity sha512-smLZPck4OkKMNExcw8jMgrMOGgVGx2N/s6DbKL2ftNl77g5HfoGpZGFy79RBzU/EkaO0OZpwBnslfdBfh7ZcWg==

[email protected]:
version "2.0.40"
resolved "https://registry.yarnpkg.com/options-defaults/-/options-defaults-2.0.40.tgz#18a1521519e68e561e2267a3dcb409f2fba81510"
integrity sha512-a0oW0AMaP/Uqk1gU7s3unE83wzs/MACy3wsCnNREn4wqp4KCcxRdulRjf0d2FeIxENbGJ4EBGtHTQ6J30XB6Cw==

outdent@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/outdent/-/outdent-0.8.0.tgz#2ebc3e77bf49912543f1008100ff8e7f44428eb0"
Expand Down Expand Up @@ -5098,25 +5088,11 @@ trough@^2.0.0:
resolved "https://registry.yarnpkg.com/trough/-/trough-2.1.0.tgz#0f7b511a4fde65a46f18477ab38849b22c554876"
integrity sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==

ts-import@^5.0.0-beta.0:
version "5.0.0-beta.0"
resolved "https://registry.yarnpkg.com/ts-import/-/ts-import-5.0.0-beta.0.tgz#07ed5d07df23dc64e6e25dd30b6fdd8bfc2bf0ba"
integrity sha512-YOe/xCmwDWughfeaAaGJ4UWzlCKNnt9e+oda3St6mUMkRJCTBhBso+7XApIijw7Mr9SS6NLOdav8i5EJrx7UVQ==
dependencies:
comment-parser "1.3.1"
options-defaults "2.0.40"
tslib "2.5.0"

[email protected], tslib@^1.9.0, tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

[email protected]:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tslib@^2.0.0, tslib@^2.1.0, tslib@^2.3.1:
version "2.5.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.2.tgz#1b6f07185c881557b0ffa84b111a0106989e8338"
Expand Down

2 comments on commit e84536a

@vercel
Copy link

@vercel vercel bot commented on e84536a Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

artblocks-v2 – ./

artblocks-v2-git-main-unevenlabs.vercel.app
artblocks-v2-unevenlabs.vercel.app
artblocks-v2.vercel.app

@vercel
Copy link

@vercel vercel bot commented on e84536a Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.