diff --git a/components/buttons/List.tsx b/components/buttons/List.tsx index 2db2bc8fe..363c0ae79 100644 --- a/components/buttons/List.tsx +++ b/components/buttons/List.tsx @@ -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 @@ -57,24 +55,8 @@ const List: FC = ({ 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 diff --git a/components/portfolio/BatchListings.tsx b/components/portfolio/BatchListings.tsx index e357b7b02..1c02128c5 100644 --- a/components/portfolio/BatchListings.tsx +++ b/components/portfolio/BatchListings.tsx @@ -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 @@ -105,24 +103,7 @@ const BatchListings: FC = ({ 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( currencies && currencies[0] ? currencies[0] : defaultCurrency diff --git a/next.config.mjs b/next.config.mjs index 472d0b047..d8703b464 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -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} */ @@ -41,7 +36,7 @@ const nextConfig = { return [ { source: '/', - destination: `/${defaultChain.routePrefix}`, + destination: `/${DefaultChain.routePrefix}`, permanent: false, }, @@ -57,7 +52,7 @@ const nextConfig = { }, { source: '/collection-rankings', - destination: `/${defaultChain.routePrefix}/collection-rankings`, + destination: `/${DefaultChain.routePrefix}/collection-rankings`, permanent: true, }, ] diff --git a/package.json b/package.json index 19c2d67c6..25215237f 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/scripts/prebuild.js b/scripts/prebuild.js new file mode 100644 index 000000000..efec236c2 --- /dev/null +++ b/scripts/prebuild.js @@ -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() + } + ) +}) diff --git a/utils/chains.ts b/utils/chains.ts index cda062945..9dd98fbc3 100644 --- a/utils/chains.ts +++ b/utils/chains.ts @@ -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 = { @@ -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 = { @@ -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 [ @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/utils/usdcContracts.ts b/utils/usdcContracts.ts new file mode 100644 index 000000000..af668454f --- /dev/null +++ b/utils/usdcContracts.ts @@ -0,0 +1,11 @@ +const usdcContracts: Record = { + 1: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', //mainnet + 5: '0x07865c6e87b9f70255377e024ace6630c1eaa37f', //goerli + 10: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', //optimism + 56: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', //bnb + 137: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', //polygon + 42161: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', //arbitrum + 80001: '0x0fa8781a83e46826621b3bc094ea2a0212e71b23', //mumbai +} + +export default usdcContracts diff --git a/utils/wrappedContracts.ts b/utils/wrappedContracts.ts index 610e6e1e4..5d6f11128 100644 --- a/utils/wrappedContracts.ts +++ b/utils/wrappedContracts.ts @@ -2,6 +2,7 @@ const wrappedContracts: Record = { 1: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', //mainnet 5: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', //goerli 10: '0x4200000000000000000000000000000000000006', //optimism + 56: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', //bnb 137: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', //polygon 42161: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', //arbitrum 42170: '0x722e8bdd2ce80a4422e880164f2079488e115365', //arbitrum nova diff --git a/yarn.lock b/yarn.lock index 7d5ca758e..93f6f1086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== -comment-parser@1.3.1: - 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" @@ -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== -options-defaults@2.0.40: - 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" @@ -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" - tslib@1.14.1, 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== -tslib@2.5.0: - 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"