Rename variables
This commit is contained in:
parent
00dbc9ae8c
commit
44c8c745d5
@ -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);
|
||||
};
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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<number>(0);
|
||||
const [tokenDecimals, setTokenDecimals] = useState<number>(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...';
|
||||
|
@ -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;
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
||||
|
||||
import { PaymentMethod } from '@/constants/payments';
|
||||
|
||||
interface PaymentMethodContextType {
|
||||
|
@ -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<RequiredTokenInfo> {
|
||||
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
|
||||
};
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user