From 74bffa9b4f910a1aee08e436f16b1d4f08a565e9 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Tue, 2 Jul 2024 11:39:55 +0200 Subject: [PATCH] configure rpc url Signed-off-by: microwavedcola1 --- pages/api/tokentiers.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pages/api/tokentiers.ts b/pages/api/tokentiers.ts index dd6b8153..4a595e38 100644 --- a/pages/api/tokentiers.ts +++ b/pages/api/tokentiers.ts @@ -42,17 +42,11 @@ export const TRITON_DEDICATED_URL = process.env.NEXT_PUBLIC_TRITON_TOKEN type CurrentTiersResponse = CurrentTier[] -async function buildClient(): Promise { +async function buildClient(rpcUrl: string): Promise { try { const clientKeypair = new Keypair() const options = AnchorProvider.defaultOptions() - const rpcUrl = process.env.NEXT_PUBLIC_ENDPOINT || TRITON_DEDICATED_URL - console.log(rpcUrl, '@@@@@@@') - if (!rpcUrl) { - throw new Error('MANGO_RPC_URL environment variable is not set') - } - const connection = new Connection(rpcUrl, options) const clientWallet = new Wallet(clientKeypair) const clientProvider = new AnchorProvider(connection, clientWallet, options) @@ -76,8 +70,14 @@ export default async function handler( CurrentTiersResponse | { error: string; details: string } >, ) { + const { body } = req + console.log(body) + if (!('rpcUrl' in body)) { + throw new Error(`${body} should contain rpcUrl!`) + } + try { - const client = await buildClient() + const client = await buildClient(body['rpcUrl']) if (!client) { console.log('Client build failed') @@ -95,7 +95,6 @@ export default async function handler( const midPriceImpacts = getMidPriceImpacts( priceImpacts.length ? priceImpacts : [], ) - console.log(midPriceImpacts) const tokenThresholds: { [symbol: string]: { below1Percent: number; below2Percent: number }