Feature: Implemented Secure Merchant Vault Architecture with On-chain segregation and Encryption
This commit is contained in:
@@ -52,7 +52,18 @@ export async function POST(request: Request) {
|
||||
|
||||
// 4. Define Merchant Address (Fetch from transaction's merchant)
|
||||
const merchantResult = await db.query('SELECT * FROM merchants WHERE id = $1', [transaction.merchant_id]);
|
||||
const merchantAddress = merchantResult.rows[0]?.wallet_address || platformAddress;
|
||||
const merchant = merchantResult.rows[0];
|
||||
|
||||
let merchantAddress = merchant?.wallet_address || platformAddress;
|
||||
|
||||
// Use merchant's specific vault if available
|
||||
if (selectedNetwork === 'SOLANA') {
|
||||
if (merchant?.sol_vault_address) merchantAddress = merchant.sol_vault_address;
|
||||
} else {
|
||||
if (merchant?.evm_vault_address) merchantAddress = merchant.evm_vault_address;
|
||||
}
|
||||
|
||||
console.log(`[Sweep] Destination for merchant: ${merchantAddress}`);
|
||||
|
||||
// 5. Initialize Engine and Verify Payment first
|
||||
const cryptoEngine = new CryptoEngine(selectedNetwork);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
import MerchantSidebar from '@/components/merchant/MerchantSidebar';
|
||||
import { db } from '@/lib/db';
|
||||
import { ensureMerchantVaults } from '@/lib/vault-manager';
|
||||
|
||||
export default async function MerchantLayout({
|
||||
children,
|
||||
@@ -33,6 +34,15 @@ export default async function MerchantLayout({
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure vaults exist for this merchant
|
||||
if (resolvedId) {
|
||||
try {
|
||||
await ensureMerchantVaults(resolvedId);
|
||||
} catch (err) {
|
||||
console.error('[MerchantLayout] Vault sync failed:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Auth Check
|
||||
const isAuth = cookieStore.get(`merchant_auth_${resolvedId}`);
|
||||
const isShortAuth = cookieStore.get(`merchant_auth_${identifier}`);
|
||||
|
||||
@@ -132,13 +132,46 @@ export default async function MerchantDashboardPage(props: {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* On-chain Vault Section */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
<div className="bg-white p-8 rounded-[40px] border border-gray-100 shadow-sm flex items-center gap-6 group hover:border-blue-500 transition-all">
|
||||
<div className="w-16 h-16 bg-blue-50 rounded-2xl flex items-center justify-center text-blue-600 shrink-0 group-hover:bg-blue-600 group-hover:text-white transition-colors">
|
||||
<Wallet size={24} />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">EVM Kasanız (Polygon/BSC/ETH)</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-mono font-bold text-gray-900 truncate">
|
||||
{merchant.evm_vault_address || 'Henüz Oluşturulmadı'}
|
||||
</span>
|
||||
<div className="px-2 py-0.5 bg-gray-100 rounded text-[9px] font-black text-gray-400 uppercase tracking-tighter">Copy</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white p-8 rounded-[40px] border border-gray-100 shadow-sm flex items-center gap-6 group hover:border-purple-500 transition-all">
|
||||
<div className="w-16 h-16 bg-purple-50 rounded-2xl flex items-center justify-center text-purple-600 shrink-0 group-hover:bg-purple-600 group-hover:text-white transition-colors">
|
||||
<Wallet size={24} />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">Solana Kasanız</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-mono font-bold text-gray-900 truncate">
|
||||
{merchant.sol_vault_address || 'Henüz Oluşturulmadı'}
|
||||
</span>
|
||||
<div className="px-2 py-0.5 bg-gray-100 rounded text-[9px] font-black text-gray-400 uppercase tracking-tighter">Copy</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stats Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
|
||||
<div className="bg-white p-10 rounded-[40px] border border-gray-100 shadow-sm space-y-6 group hover:border-blue-500 transition-colors">
|
||||
<div className="flex justify-between items-start">
|
||||
<p className="text-[10px] font-black text-gray-400 uppercase tracking-widest">Toplam Ciro</p>
|
||||
<div className="p-3 bg-blue-50 rounded-xl text-blue-600 group-hover:bg-blue-600 group-hover:text-white transition-colors">
|
||||
<Wallet size={20} />
|
||||
<TrendingUp size={20} />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user