From 44c8c745d5987a2f791f8c0fbd81f9b912ce8da5 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Wed, 23 Jul 2025 19:02:01 +0530 Subject: [PATCH] Rename variables --- src/app/api/registry/route.ts | 6 +++--- src/app/page.tsx | 3 ++- src/components/PaymentModal.tsx | 22 ++++++++++++---------- src/components/WalletProviders.tsx | 7 +++++-- src/contexts/PaymentMethodContext.tsx | 1 + src/services/jupiter-price.ts | 6 +++--- src/services/solana.ts | 4 ++-- src/utils/solana-verify.ts | 6 ++++-- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/app/api/registry/route.ts b/src/app/api/registry/route.ts index 7b65443..fae5397 100644 --- a/src/app/api/registry/route.ts +++ b/src/app/api/registry/route.ts @@ -18,7 +18,7 @@ assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required'); assert(process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL, 'GORBAGANA_RPC_URL is required'); const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL; -const SOLANA_SOL_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; +const GORBAGANA_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; // Allow 20% slippage due to price fluctuations const ALLOWED_SLIPPAGE_FACTOR = 0.2 @@ -141,8 +141,8 @@ export const registryTransactionWithRetry = async ( // Helper function to get the appropriate connection based on payment method const getConnection = (paymentMethod: PaymentMethod): Connection => { - if (paymentMethod === 'nat-gor' && SOLANA_SOL_RPC_URL) { - return new Connection(SOLANA_SOL_RPC_URL); + if (paymentMethod === 'nat-gor' && GORBAGANA_RPC_URL) { + return new Connection(GORBAGANA_RPC_URL); } return new Connection(SOLANA_RPC_URL); }; diff --git a/src/app/page.tsx b/src/app/page.tsx index b778826..1bff5db 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,13 +2,14 @@ import { useCallback, useState } from 'react'; import dynamic from 'next/dynamic'; + import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'; +import { useWallet } from '@solana/wallet-adapter-react'; import URLForm from '@/components/URLForm'; import StatusDisplay from '@/components/StatusDisplay'; import { createApplicationDeploymentRequest } from '@/services/registry'; import { PaymentMethod, PAYMENT_METHOD_LABELS } from '@/constants/payments'; -import { useWallet } from '@solana/wallet-adapter-react'; import { usePaymentMethod } from '@/contexts/PaymentMethodContext'; diff --git a/src/components/PaymentModal.tsx b/src/components/PaymentModal.tsx index d576c8d..e090311 100644 --- a/src/components/PaymentModal.tsx +++ b/src/components/PaymentModal.tsx @@ -13,8 +13,10 @@ import { PAYMENT_METHOD_LABELS } from '@/constants/payments'; import { usePaymentMethod } from '@/contexts/PaymentMethodContext'; assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required'); +assert(process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL, 'GORBAGANA_RPC_URL is required'); + const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL; -const SOLANA_SOL_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; +const GORBAGANA_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; export default function PaymentModal({ isOpen, @@ -22,20 +24,20 @@ export default function PaymentModal({ url, onPaymentComplete, }: PaymentModalProps) { + const { selectedPaymentMethod: paymentMethod } = usePaymentMethod(); + const [loading, setLoading] = useState(false); const [error, setError] = useState(''); - const { selectedPaymentMethod } = usePaymentMethod(); - const paymentMethod = selectedPaymentMethod; const [tokenAmount, setTokenAmount] = useState(0); const [tokenDecimals, setTokenDecimals] = useState(6); // Default fallback const [loadingPrice, setLoadingPrice] = useState(false); const { wallet, publicKey } = useWallet(); - const directConnection = useMemo(() => new Connection(SOLANA_RPC_URL), []); - const solConnection = useMemo(() => - SOLANA_SOL_RPC_URL ? new Connection(SOLANA_SOL_RPC_URL) : directConnection, - [directConnection] + const solanaConnection = useMemo(() => new Connection(SOLANA_RPC_URL), []); + const gorbaganaConnection = useMemo(() => + GORBAGANA_RPC_URL ? new Connection(GORBAGANA_RPC_URL) : solanaConnection, + [solanaConnection] ); // Get configuration from environment variables @@ -95,7 +97,7 @@ export default function PaymentModal({ return; } - if (!wallet?.adapter) { + if (!wallet || !wallet.adapter) { setError('Wallet not connected.'); return; } @@ -111,7 +113,7 @@ export default function PaymentModal({ }; // Use different RPC connection based on payment method - const connectionToUse = paymentMethod === 'nat-gor' ? solConnection : directConnection; + const connectionToUse = paymentMethod === 'nat-gor' ? gorbaganaConnection : solanaConnection; const result = await sendSolanaPayment( wallet.adapter, @@ -130,7 +132,7 @@ export default function PaymentModal({ } finally { setLoading(false); } - }, [paymentMethod, tokenAmount, loadingPrice, wallet, directConnection, solConnection, publicKey, onPaymentComplete]); + }, [paymentMethod, tokenAmount, loadingPrice, wallet, solanaConnection, gorbaganaConnection, publicKey, onPaymentComplete]); const getPaymentAmountDisplay = () => { if (loadingPrice) return 'Loading...'; diff --git a/src/components/WalletProviders.tsx b/src/components/WalletProviders.tsx index 492e066..26b77e6 100644 --- a/src/components/WalletProviders.tsx +++ b/src/components/WalletProviders.tsx @@ -1,16 +1,19 @@ 'use client'; import { useMemo } from 'react'; +import assert from 'assert'; + import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react'; import { WalletModalProvider } from '@solana/wallet-adapter-react-ui'; import { BackpackWalletAdapter } from '@solana/wallet-adapter-backpack'; import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom'; import { SolflareWalletAdapter } from '@solana/wallet-adapter-solflare'; +import { usePaymentMethod } from '@/contexts/PaymentMethodContext'; + // Default styles that can be overridden by your app import '@solana/wallet-adapter-react-ui/styles.css'; -import assert from 'assert'; -import { usePaymentMethod } from '@/contexts/PaymentMethodContext'; + assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required'); const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL; diff --git a/src/contexts/PaymentMethodContext.tsx b/src/contexts/PaymentMethodContext.tsx index 91425be..db1d673 100644 --- a/src/contexts/PaymentMethodContext.tsx +++ b/src/contexts/PaymentMethodContext.tsx @@ -1,6 +1,7 @@ 'use client'; import React, { createContext, useContext, useState, ReactNode } from 'react'; + import { PaymentMethod } from '@/constants/payments'; interface PaymentMethodContextType { diff --git a/src/services/jupiter-price.ts b/src/services/jupiter-price.ts index 4fe7343..1383320 100644 --- a/src/services/jupiter-price.ts +++ b/src/services/jupiter-price.ts @@ -72,7 +72,7 @@ export async function getRequiredTokenInfo(targetUsdAmount: number, mintAddress: * Calculates the native GOR amount needed for a given USD price * Uses wrapped SOL price since native GOR = SOL * @param targetUsdAmount The target amount in USD - * @returns The GOR amount in lamports needed and decimals (always 9 for SOL/GOR) + * @returns The GOR amount in lamports needed and decimals (always 9) */ export async function getRequiredNativeGorInfo(targetUsdAmount: number): Promise { const priceInfo = await getTokenInfo(WRAPPED_SOL_MINT_ADDRESS); @@ -80,11 +80,11 @@ export async function getRequiredNativeGorInfo(targetUsdAmount: number): Promise // Calculate GOR amount needed (same as SOL) const gorAmount = targetUsdAmount / priceInfo.usdPrice; - // Convert to lamports (SOL/GOR has 9 decimals) + // Convert to lamports const amountInLamports = Math.round(gorAmount * Math.pow(10, 9)); return { requiredAmountInBaseUnits: amountInLamports, - decimals: 9 // SOL/GOR always has 9 decimals + decimals: 9 }; } diff --git a/src/services/solana.ts b/src/services/solana.ts index 88ebd67..75ec53a 100644 --- a/src/services/solana.ts +++ b/src/services/solana.ts @@ -35,7 +35,7 @@ async function findAssociatedTokenAddress( } // Send native GOR payment -export async function sendSolPayment( +export async function sendNativeGorPayment( wallet: WalletAdapter, connection: Connection, walletPublicKey: string, @@ -231,7 +231,7 @@ export async function sendSolanaPayment( switch (paymentRequest.paymentMethod) { case 'nat-gor': - return await sendSolPayment(wallet, connection, walletPublicKey, tokenAmount); + return await sendNativeGorPayment(wallet, connection, walletPublicKey, tokenAmount); case 'spl-token': return await sendSplTokenPayment(wallet, connection, walletPublicKey, tokenAmount); default: diff --git a/src/utils/solana-verify.ts b/src/utils/solana-verify.ts index f64ba83..a399afb 100644 --- a/src/utils/solana-verify.ts +++ b/src/utils/solana-verify.ts @@ -1,10 +1,12 @@ import BN from 'bn.js'; + import { Connection, PublicKey } from '@solana/web3.js'; import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token'; + import { PaymentMethod } from '../constants/payments'; // Extract transaction info for native GOR transfers -const extractSolTransferInfo = async ( +const extractNativeGorTransferInfo = async ( connection: Connection, transactionSignature: string ): Promise<{ authority: string; amount: string; destination: string }> => { @@ -124,7 +126,7 @@ export const verifyUnusedSolanaPayment = async ( let destination: string; if (paymentMethod === 'nat-gor') { - const transferInfo = await extractSolTransferInfo(connection, transactionSignature); + const transferInfo = await extractNativeGorTransferInfo(connection, transactionSignature); amount = transferInfo.amount; authority = transferInfo.authority; destination = transferInfo.destination;