Skip to content

Commit

Permalink
fix(apps/earn): add fallbacks for fetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlilley committed Oct 22, 2022
1 parent 84743bc commit 465461a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/earn/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChainId } from '@sushiswap/chain'
export const TRIDENT_ENABLED_NETWORKS: ChainId[] = [ChainId.OPTIMISM, ChainId.POLYGON, ChainId.METIS, ChainId.KAVA]

export const AMM_ENABLED_NETWORKS: ChainId[] = [
ChainId.ETHEREUM,
// ChainId.ETHEREUM,
ChainId.ARBITRUM,
ChainId.AVALANCHE,
ChainId.MOONRIVER,
Expand Down
1 change: 0 additions & 1 deletion apps/earn/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,5 @@ export const getUser = async (query: GetUserQuery) => {
id: query.id.toLowerCase(),
now: Math.round(new Date().getTime() / 1000),
})

return user
}
5 changes: 1 addition & 4 deletions apps/earn/pages/api/user/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { getUser, GetUserQuery } from '../../../lib/api'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
res.setHeader('Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59')
if (req.query.id === 'undefined') {
return res.status(200).send({ user: [] })
}
const user = await getUser(req.query as GetUserQuery)
res.status(200).send(user)
res.status(200).json(user)
}
1 change: 0 additions & 1 deletion packages/currency/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@sushiswap/currency",
"version": "0.0.2",
"private": true,
"description": "Sushi Currency",
"keywords": [
"sushi",
Expand Down
30 changes: 26 additions & 4 deletions packages/graph-client/fetchers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@ import { otherChains } from '@sushiswap/wagmi-config'
import { allChains, configureChains, createClient, readContract } from '@wagmi/core'
import { erc20ABI } from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID || process.env.NEXT_PUBLIC_ALCHEMY_ID
const infuraId = process.env.INFURA_ID || process.env.NEXT_PUBLIC_INFURA_ID

const { provider } = configureChains(
[...allChains, ...otherChains],
[
jsonRpcProvider({
priority: 0,
rpc: (chain) => {
if (chain.id !== 1) return null
return {
http: `https://api.securerpc.com/v1`,
webSocket: `wss://api.securerpc.com/v1`,
}
},
}),
alchemyProvider({ apiKey: alchemyId, priority: 1 }),
publicProvider({ priority: 2 }),
]
)

const { provider } = configureChains([...allChains, ...otherChains], [publicProvider()])
createClient({ provider })

export async function getTokenBalance(args: Parameters<typeof getTokenBalances>[0][0]) {
Expand All @@ -22,10 +44,10 @@ export async function getTokenBalances(args: { token: string; user: string; chai
contractInterface: erc20ABI,
})
)
).then((results) =>
results.map((result, i) => ({
).then((results) => {
return results.map((result, i) => ({
...args[i],
balance: result ? result.toString() : '0',
}))
)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const crossChainUserWithFarms: QueryResolvers['crossChainUserWithFarms']
chainId: lp.pair.chainId,
}))
)

return (user.liquidityPositions ?? [])
.map((lp) => ({
id: lp.pair.id,
Expand Down

0 comments on commit 465461a

Please sign in to comment.