diff --git a/app/api/crypto-sweep/route.ts b/app/api/crypto-sweep/route.ts index 1e3a7d7..730b0a6 100644 --- a/app/api/crypto-sweep/route.ts +++ b/app/api/crypto-sweep/route.ts @@ -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); diff --git a/app/merchant/[id]/(dashboard)/layout.tsx b/app/merchant/[id]/(dashboard)/layout.tsx index 0009ef5..fc1e73e 100644 --- a/app/merchant/[id]/(dashboard)/layout.tsx +++ b/app/merchant/[id]/(dashboard)/layout.tsx @@ -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}`); diff --git a/app/merchant/[id]/(dashboard)/page.tsx b/app/merchant/[id]/(dashboard)/page.tsx index 99c5b1a..5981bfd 100644 --- a/app/merchant/[id]/(dashboard)/page.tsx +++ b/app/merchant/[id]/(dashboard)/page.tsx @@ -132,13 +132,46 @@ export default async function MerchantDashboardPage(props: { + {/* On-chain Vault Section */} +
EVM Kasanız (Polygon/BSC/ETH)
+Solana Kasanız
+Toplam Ciro