Refactor method to resolve pricing record lrn
This commit is contained in:
parent
12510b0371
commit
7fcde7b30d
@ -8,7 +8,6 @@ NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS=71Jvq4Epe2FCJ7JFSF7jLXdNk1Wy4Bhqd9iL6bEFEL
|
|||||||
# Multisig address
|
# Multisig address
|
||||||
NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY
|
NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY
|
||||||
NEXT_PUBLIC_SOLANA_TOKEN_SYMBOL=GOR
|
NEXT_PUBLIC_SOLANA_TOKEN_SYMBOL=GOR
|
||||||
NEXT_PUBLIC_SOLANA_PAYMENT_AMOUNT_USD=5 # Payment amount in USD
|
|
||||||
|
|
||||||
# UI Configuration
|
# UI Configuration
|
||||||
NEXT_PUBLIC_EXAMPLE_URL=https://git.vdb.to/cerc-io/test-progressive-web-app
|
NEXT_PUBLIC_EXAMPLE_URL=https://git.vdb.to/cerc-io/test-progressive-web-app
|
||||||
|
@ -11,6 +11,7 @@ import { verifyUnusedSolanaPayment } from '@/utils/solana-verify';
|
|||||||
import { transferLNTTokens } from '@/services/laconic-transfer';
|
import { transferLNTTokens } from '@/services/laconic-transfer';
|
||||||
import { getRegistry, getRegistryConfig } from '@/config';
|
import { getRegistry, getRegistryConfig } from '@/config';
|
||||||
import { getRequiredTokenInfo } from '@/services/jupiter-price';
|
import { getRequiredTokenInfo } from '@/services/jupiter-price';
|
||||||
|
import { resolvePricingRecordLrn } from '@/services/registry';
|
||||||
|
|
||||||
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;
|
||||||
@ -182,7 +183,8 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
// Verify Solana payment
|
// Verify Solana payment
|
||||||
console.log('Step 0: Verifying Solana token payment...');
|
console.log('Step 0: Verifying Solana token payment...');
|
||||||
const targetUsdAmount = parseFloat(process.env.NEXT_PUBLIC_SOLANA_PAYMENT_AMOUNT_USD!);
|
const pricingRecordAttributes = await resolvePricingRecordLrn();
|
||||||
|
const targetUsdAmount = parseInt(pricingRecordAttributes.amount, 10);
|
||||||
const mintAddress = process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS!;
|
const mintAddress = process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS!;
|
||||||
|
|
||||||
// Calculate expected token amount based on current price
|
// Calculate expected token amount based on current price
|
||||||
|
@ -9,29 +9,16 @@ import { Connection } from '@solana/web3.js';
|
|||||||
import { sendSolanaTokenPayment } from '@/services/solana';
|
import { sendSolanaTokenPayment } from '@/services/solana';
|
||||||
import { getRequiredTokenInfo } from '@/services/jupiter-price';
|
import { getRequiredTokenInfo } from '@/services/jupiter-price';
|
||||||
import { PaymentModalProps } from '@/types';
|
import { PaymentModalProps } from '@/types';
|
||||||
import { getRegistry } from '@/config';
|
import { resolvePricingRecordLrn } from '@/services/registry';
|
||||||
|
|
||||||
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_PRICING_RECORD_LRN, 'DEPLOYMENT_RECORD_LRN 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 PRICING_RECORD_LRN = process.env.NEXT_PUBLIC_PRICING_RECORD_LRN;
|
|
||||||
const SUPPORTED_CURRENCY = "USD";
|
|
||||||
const VALID_PRICING_RECORD_FOR = "webapp-deployment";
|
|
||||||
|
|
||||||
interface DeploymentCostInfo {
|
interface DeploymentCostInfo {
|
||||||
amount: string;
|
amount: string;
|
||||||
currency: string;
|
currency: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PricingRecordAttributes {
|
|
||||||
amount: string;
|
|
||||||
currency: string;
|
|
||||||
for: string;
|
|
||||||
type: string;
|
|
||||||
version: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function PaymentModal({
|
export default function PaymentModal({
|
||||||
isOpen,
|
isOpen,
|
||||||
onClose,
|
onClose,
|
||||||
@ -49,27 +36,16 @@ export default function PaymentModal({
|
|||||||
const connection = useMemo(() => new Connection(SOLANA_RPC_URL), []);
|
const connection = useMemo(() => new Connection(SOLANA_RPC_URL), []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const registry = getRegistry();
|
const getDeploymentCostInfo = async () => {
|
||||||
|
const pricingRecordAttributes = await resolvePricingRecordLrn();
|
||||||
const resolveDeploymentCostInfo = async () => {
|
|
||||||
const result = await registry.resolveNames([PRICING_RECORD_LRN!])
|
|
||||||
const PricingRecordAttributes: PricingRecordAttributes = result[0].attributes;
|
|
||||||
|
|
||||||
if (PricingRecordAttributes.for !== VALID_PRICING_RECORD_FOR) {
|
|
||||||
throw new Error(`Incorrect pricing record type: ${PricingRecordAttributes.type}. Please provide correct pricing record lrn`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PricingRecordAttributes.currency !== SUPPORTED_CURRENCY) {
|
|
||||||
throw new Error(`Unsupported currency found in pricing record: ${PricingRecordAttributes.currency}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
setDeploymentCostInfo({
|
setDeploymentCostInfo({
|
||||||
amount: PricingRecordAttributes.amount,
|
amount: pricingRecordAttributes.amount,
|
||||||
currency:PricingRecordAttributes.currency
|
currency:pricingRecordAttributes.currency
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveDeploymentCostInfo();
|
getDeploymentCostInfo();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Get configuration from environment variables
|
// Get configuration from environment variables
|
||||||
|
@ -25,7 +25,7 @@ export const getClientRegistryConfig = () => {
|
|||||||
rpcEndpoint: process.env.NEXT_PUBLIC_REGISTRY_RPC_ENDPOINT!,
|
rpcEndpoint: process.env.NEXT_PUBLIC_REGISTRY_RPC_ENDPOINT!,
|
||||||
gqlEndpoint: process.env.NEXT_PUBLIC_REGISTRY_GQL_ENDPOINT!,
|
gqlEndpoint: process.env.NEXT_PUBLIC_REGISTRY_GQL_ENDPOINT!,
|
||||||
fee: {
|
fee: {
|
||||||
gasPrice: process.env.NEXT_PUBLIC_REGISTRY_GAS_PRICE || '0.001',
|
gasPrice: process.env.NEXT_PUBLIC_REGISTRY_GAS_PRICE!,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,14 @@
|
|||||||
import { CreateRecordResponse } from '../types';
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { getRegistry } from '@/config';
|
||||||
|
import { CreateRecordResponse, PricingRecordAttributes } from '../types';
|
||||||
|
|
||||||
|
assert(process.env.NEXT_PUBLIC_PRICING_RECORD_LRN, 'DEPLOYMENT_RECORD_LRN is required');
|
||||||
|
const PRICING_RECORD_LRN = process.env.NEXT_PUBLIC_PRICING_RECORD_LRN;
|
||||||
|
|
||||||
|
const SUPPORTED_CURRENCY = "USD";
|
||||||
|
const VALID_PRICING_RECORD_FOR = "webapp-deployment";
|
||||||
|
|
||||||
|
|
||||||
export const createApplicationDeploymentRequest = async (
|
export const createApplicationDeploymentRequest = async (
|
||||||
url: string,
|
url: string,
|
||||||
@ -49,3 +59,18 @@ export const createApplicationDeploymentRequest = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resolvePricingRecordLrn = async (): Promise<PricingRecordAttributes> => {
|
||||||
|
const registry = getRegistry();
|
||||||
|
const result = await registry.resolveNames([PRICING_RECORD_LRN])
|
||||||
|
const pricingRecordAttributes: PricingRecordAttributes = result[0].attributes;
|
||||||
|
|
||||||
|
if (pricingRecordAttributes.for !== VALID_PRICING_RECORD_FOR) {
|
||||||
|
throw new Error(`Incorrect pricing record type: ${pricingRecordAttributes.type}. Please provide correct pricing record lrn`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pricingRecordAttributes.currency !== SUPPORTED_CURRENCY) {
|
||||||
|
throw new Error(`Unsupported currency found in pricing record: ${pricingRecordAttributes.currency}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pricingRecordAttributes;
|
||||||
|
}
|
||||||
|
@ -72,3 +72,11 @@ export interface LaconicTransferResult {
|
|||||||
transactionHash?: string;
|
transactionHash?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PricingRecordAttributes {
|
||||||
|
amount: string;
|
||||||
|
currency: string;
|
||||||
|
for: string;
|
||||||
|
type: string;
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user