fix: failing token cloud function tests (#7074)

* fix: failing token cloud function tests

* utilize enum from chains
This commit is contained in:
Brendan Wong 2023-08-03 12:30:50 -04:00 committed by GitHub
parent 24d00f7c39
commit cd43e0beaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

@ -1,18 +1,30 @@
/* eslint-disable import/no-unused-modules */ /* eslint-disable import/no-unused-modules */
import { Chain } from '../../src/graphql/data/__generated__/types-and-hooks'
import { MetaTagInjector } from '../components/metaTagInjector' import { MetaTagInjector } from '../components/metaTagInjector'
import getToken from '../utils/getToken' import getToken from '../utils/getToken'
const convertTokenAddress = (tokenAddress: string) => { const convertTokenAddress = (tokenAddress: string, networkName: string) => {
return tokenAddress && tokenAddress === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : tokenAddress if (tokenAddress === 'NATIVE') {
switch (networkName) {
case Chain.Celo:
return '0x471EcE3750Da237f93B8E339c536989b8978a438'
case Chain.Polygon:
return '0x0000000000000000000000000000000000001010'
default:
return undefined
}
}
return tokenAddress
} }
export const onRequest: PagesFunction = async ({ params, request, next }) => { export const onRequest: PagesFunction = async ({ params, request, next }) => {
const { index } = params const { index } = params
const networkName = index[0]?.toString().toUpperCase() const networkName = index[0]?.toString().toUpperCase()
const tokenAddress = convertTokenAddress(index[1]?.toString()) const tokenString = index[1]?.toString()
if (!tokenAddress) { if (!tokenString) {
return next() return next()
} }
const tokenAddress = convertTokenAddress(tokenString, networkName)
const tokenPromise = getToken(networkName, tokenAddress, request.url) const tokenPromise = getToken(networkName, tokenAddress, request.url)
const resPromise = next() const resPromise = next()
try { try {

@ -11,7 +11,7 @@ function formatTitleName(symbol: string, name: string) {
return 'View Token on Uniswap' return 'View Token on Uniswap'
} }
export default async function getToken(networkName: string, tokenAddress: string, url: string) { export default async function getToken(networkName: string, tokenAddress: string | undefined, url: string) {
const { data } = await client.query({ const { data } = await client.query({
query: TokenDocument, query: TokenDocument,
variables: { variables: {