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');
|
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_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
|
// Allow 20% slippage due to price fluctuations
|
||||||
const ALLOWED_SLIPPAGE_FACTOR = 0.2
|
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
|
// Helper function to get the appropriate connection based on payment method
|
||||||
const getConnection = (paymentMethod: PaymentMethod): Connection => {
|
const getConnection = (paymentMethod: PaymentMethod): Connection => {
|
||||||
if (paymentMethod === 'nat-gor' && SOLANA_SOL_RPC_URL) {
|
if (paymentMethod === 'nat-gor' && GORBAGANA_RPC_URL) {
|
||||||
return new Connection(SOLANA_SOL_RPC_URL);
|
return new Connection(GORBAGANA_RPC_URL);
|
||||||
}
|
}
|
||||||
return new Connection(SOLANA_RPC_URL);
|
return new Connection(SOLANA_RPC_URL);
|
||||||
};
|
};
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui';
|
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui';
|
||||||
|
import { useWallet } from '@solana/wallet-adapter-react';
|
||||||
|
|
||||||
import URLForm from '@/components/URLForm';
|
import URLForm from '@/components/URLForm';
|
||||||
import StatusDisplay from '@/components/StatusDisplay';
|
import StatusDisplay from '@/components/StatusDisplay';
|
||||||
import { createApplicationDeploymentRequest } from '@/services/registry';
|
import { createApplicationDeploymentRequest } from '@/services/registry';
|
||||||
import { PaymentMethod, PAYMENT_METHOD_LABELS } from '@/constants/payments';
|
import { PaymentMethod, PAYMENT_METHOD_LABELS } from '@/constants/payments';
|
||||||
import { useWallet } from '@solana/wallet-adapter-react';
|
|
||||||
|
|
||||||
import { usePaymentMethod } from '@/contexts/PaymentMethodContext';
|
import { usePaymentMethod } from '@/contexts/PaymentMethodContext';
|
||||||
|
|
||||||
|
@ -13,8 +13,10 @@ import { PAYMENT_METHOD_LABELS } from '@/constants/payments';
|
|||||||
import { usePaymentMethod } from '@/contexts/PaymentMethodContext';
|
import { usePaymentMethod } from '@/contexts/PaymentMethodContext';
|
||||||
|
|
||||||
assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required');
|
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_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({
|
export default function PaymentModal({
|
||||||
isOpen,
|
isOpen,
|
||||||
@ -22,20 +24,20 @@ export default function PaymentModal({
|
|||||||
url,
|
url,
|
||||||
onPaymentComplete,
|
onPaymentComplete,
|
||||||
}: PaymentModalProps) {
|
}: PaymentModalProps) {
|
||||||
|
const { selectedPaymentMethod: paymentMethod } = usePaymentMethod();
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const { selectedPaymentMethod } = usePaymentMethod();
|
|
||||||
const paymentMethod = selectedPaymentMethod;
|
|
||||||
const [tokenAmount, setTokenAmount] = useState<number>(0);
|
const [tokenAmount, setTokenAmount] = useState<number>(0);
|
||||||
const [tokenDecimals, setTokenDecimals] = useState<number>(6); // Default fallback
|
const [tokenDecimals, setTokenDecimals] = useState<number>(6); // Default fallback
|
||||||
const [loadingPrice, setLoadingPrice] = useState(false);
|
const [loadingPrice, setLoadingPrice] = useState(false);
|
||||||
|
|
||||||
const { wallet, publicKey } = useWallet();
|
const { wallet, publicKey } = useWallet();
|
||||||
|
|
||||||
const directConnection = useMemo(() => new Connection(SOLANA_RPC_URL), []);
|
const solanaConnection = useMemo(() => new Connection(SOLANA_RPC_URL), []);
|
||||||
const solConnection = useMemo(() =>
|
const gorbaganaConnection = useMemo(() =>
|
||||||
SOLANA_SOL_RPC_URL ? new Connection(SOLANA_SOL_RPC_URL) : directConnection,
|
GORBAGANA_RPC_URL ? new Connection(GORBAGANA_RPC_URL) : solanaConnection,
|
||||||
[directConnection]
|
[solanaConnection]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get configuration from environment variables
|
// Get configuration from environment variables
|
||||||
@ -95,7 +97,7 @@ export default function PaymentModal({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wallet?.adapter) {
|
if (!wallet || !wallet.adapter) {
|
||||||
setError('Wallet not connected.');
|
setError('Wallet not connected.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,7 +113,7 @@ export default function PaymentModal({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Use different RPC connection based on payment method
|
// 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(
|
const result = await sendSolanaPayment(
|
||||||
wallet.adapter,
|
wallet.adapter,
|
||||||
@ -130,7 +132,7 @@ export default function PaymentModal({
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [paymentMethod, tokenAmount, loadingPrice, wallet, directConnection, solConnection, publicKey, onPaymentComplete]);
|
}, [paymentMethod, tokenAmount, loadingPrice, wallet, solanaConnection, gorbaganaConnection, publicKey, onPaymentComplete]);
|
||||||
|
|
||||||
const getPaymentAmountDisplay = () => {
|
const getPaymentAmountDisplay = () => {
|
||||||
if (loadingPrice) return 'Loading...';
|
if (loadingPrice) return 'Loading...';
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
|
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
|
||||||
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
|
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
|
||||||
import { BackpackWalletAdapter } from '@solana/wallet-adapter-backpack';
|
import { BackpackWalletAdapter } from '@solana/wallet-adapter-backpack';
|
||||||
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
|
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
|
||||||
import { SolflareWalletAdapter } from '@solana/wallet-adapter-solflare';
|
import { SolflareWalletAdapter } from '@solana/wallet-adapter-solflare';
|
||||||
|
|
||||||
|
import { usePaymentMethod } from '@/contexts/PaymentMethodContext';
|
||||||
|
|
||||||
// Default styles that can be overridden by your app
|
// Default styles that can be overridden by your app
|
||||||
import '@solana/wallet-adapter-react-ui/styles.css';
|
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');
|
assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required');
|
||||||
const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
|
const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
||||||
|
|
||||||
import { PaymentMethod } from '@/constants/payments';
|
import { PaymentMethod } from '@/constants/payments';
|
||||||
|
|
||||||
interface PaymentMethodContextType {
|
interface PaymentMethodContextType {
|
||||||
|
@ -72,7 +72,7 @@ export async function getRequiredTokenInfo(targetUsdAmount: number, mintAddress:
|
|||||||
* Calculates the native GOR amount needed for a given USD price
|
* Calculates the native GOR amount needed for a given USD price
|
||||||
* Uses wrapped SOL price since native GOR = SOL
|
* Uses wrapped SOL price since native GOR = SOL
|
||||||
* @param targetUsdAmount The target amount in USD
|
* @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> {
|
export async function getRequiredNativeGorInfo(targetUsdAmount: number): Promise<RequiredTokenInfo> {
|
||||||
const priceInfo = await getTokenInfo(WRAPPED_SOL_MINT_ADDRESS);
|
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)
|
// Calculate GOR amount needed (same as SOL)
|
||||||
const gorAmount = targetUsdAmount / priceInfo.usdPrice;
|
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));
|
const amountInLamports = Math.round(gorAmount * Math.pow(10, 9));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
requiredAmountInBaseUnits: amountInLamports,
|
requiredAmountInBaseUnits: amountInLamports,
|
||||||
decimals: 9 // SOL/GOR always has 9 decimals
|
decimals: 9
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ async function findAssociatedTokenAddress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send native GOR payment
|
// Send native GOR payment
|
||||||
export async function sendSolPayment(
|
export async function sendNativeGorPayment(
|
||||||
wallet: WalletAdapter,
|
wallet: WalletAdapter,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
walletPublicKey: string,
|
walletPublicKey: string,
|
||||||
@ -231,7 +231,7 @@ export async function sendSolanaPayment(
|
|||||||
|
|
||||||
switch (paymentRequest.paymentMethod) {
|
switch (paymentRequest.paymentMethod) {
|
||||||
case 'nat-gor':
|
case 'nat-gor':
|
||||||
return await sendSolPayment(wallet, connection, walletPublicKey, tokenAmount);
|
return await sendNativeGorPayment(wallet, connection, walletPublicKey, tokenAmount);
|
||||||
case 'spl-token':
|
case 'spl-token':
|
||||||
return await sendSplTokenPayment(wallet, connection, walletPublicKey, tokenAmount);
|
return await sendSplTokenPayment(wallet, connection, walletPublicKey, tokenAmount);
|
||||||
default:
|
default:
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
|
|
||||||
import { Connection, PublicKey } from '@solana/web3.js';
|
import { Connection, PublicKey } from '@solana/web3.js';
|
||||||
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||||
|
|
||||||
import { PaymentMethod } from '../constants/payments';
|
import { PaymentMethod } from '../constants/payments';
|
||||||
|
|
||||||
// Extract transaction info for native GOR transfers
|
// Extract transaction info for native GOR transfers
|
||||||
const extractSolTransferInfo = async (
|
const extractNativeGorTransferInfo = async (
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
transactionSignature: string
|
transactionSignature: string
|
||||||
): Promise<{ authority: string; amount: string; destination: string }> => {
|
): Promise<{ authority: string; amount: string; destination: string }> => {
|
||||||
@ -124,7 +126,7 @@ export const verifyUnusedSolanaPayment = async (
|
|||||||
let destination: string;
|
let destination: string;
|
||||||
|
|
||||||
if (paymentMethod === 'nat-gor') {
|
if (paymentMethod === 'nat-gor') {
|
||||||
const transferInfo = await extractSolTransferInfo(connection, transactionSignature);
|
const transferInfo = await extractNativeGorTransferInfo(connection, transactionSignature);
|
||||||
amount = transferInfo.amount;
|
amount = transferInfo.amount;
|
||||||
authority = transferInfo.authority;
|
authority = transferInfo.authority;
|
||||||
destination = transferInfo.destination;
|
destination = transferInfo.destination;
|
||||||
|
Loading…
Reference in New Issue
Block a user