From ee50666c64cd6efbb84a4f5e45173a7212b48c96 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Mon, 23 Feb 2026 21:50:57 +0300 Subject: [PATCH] fix: route P2P deposits and verification to Asset Hub instead of relay chain DepositModal was building transactions via relay chain API, and all three edge functions (verify-deposit, process-withdraw, process-withdrawal) had RPC endpoints hardcoded or defaulting to the relay chain. This caused deposit verification to fail with "Transaction not yet finalized" and created a chain mismatch with the withdrawal system which operates on Asset Hub. - DepositModal: use assetHubApi instead of api for transfer TX - verify-deposit: RPC_HTTP/RPC_WS default to asset-hub-rpc (env override) - process-withdraw: RPC_ENDPOINT default to asset-hub-rpc (env override) - process-withdrawal: RPC_ENDPOINT default to asset-hub-rpc --- web/src/components/p2p/DepositModal.tsx | 12 ++++++------ web/supabase/functions/process-withdraw/index.ts | 4 ++-- web/supabase/functions/process-withdrawal/index.ts | 2 +- web/supabase/functions/verify-deposit/index.ts | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/web/src/components/p2p/DepositModal.tsx b/web/src/components/p2p/DepositModal.tsx index 72c41272..e365fda8 100644 --- a/web/src/components/p2p/DepositModal.tsx +++ b/web/src/components/p2p/DepositModal.tsx @@ -49,7 +49,7 @@ type DepositStep = 'select' | 'send' | 'verify' | 'success'; export function DepositModal({ isOpen, onClose, onSuccess }: DepositModalProps) { const { t } = useTranslation(); - const { api, selectedAccount } = usePezkuwi(); + const { assetHubApi, isAssetHubReady, selectedAccount } = usePezkuwi(); const { balances, signTransaction } = useWallet(); const { identityId } = useP2PIdentity(); @@ -109,7 +109,7 @@ export function DepositModal({ isOpen, onClose, onSuccess }: DepositModalProps) }; const handleSendDeposit = async () => { - if (!api || !selectedAccount) { + if (!assetHubApi || !isAssetHubReady || !selectedAccount) { toast.error(t('p2pDeposit.connectWallet')); return; } @@ -129,12 +129,12 @@ export function DepositModal({ isOpen, onClose, onSuccess }: DepositModalProps) let tx; if (token === 'HEZ') { - // Native transfer - tx = api.tx.balances.transferKeepAlive(platformWallet, amountBN); + // Native transfer on Asset Hub + tx = assetHubApi.tx.balances.transferKeepAlive(platformWallet, amountBN); } else { // Asset transfer (PEZ = asset ID 1) const assetId = token === 'PEZ' ? 1 : 0; - tx = api.tx.assets.transfer(assetId, platformWallet, amountBN); + tx = assetHubApi.tx.assets.transfer(assetId, platformWallet, amountBN); } toast.info(t('p2pDeposit.signTransaction')); @@ -146,7 +146,7 @@ export function DepositModal({ isOpen, onClose, onSuccess }: DepositModalProps) setTxHash(hash); // Capture approximate block number for faster verification try { - const header = await api.rpc.chain.getHeader(); + const header = await assetHubApi.rpc.chain.getHeader(); setBlockNumber(header.number.toNumber()); } catch { // Non-critical - verification will still work via search diff --git a/web/supabase/functions/process-withdraw/index.ts b/web/supabase/functions/process-withdraw/index.ts index eedd04e3..35158131 100644 --- a/web/supabase/functions/process-withdraw/index.ts +++ b/web/supabase/functions/process-withdraw/index.ts @@ -26,8 +26,8 @@ function getCorsHeaders(origin: string | null) { // Platform hot wallet address const PLATFORM_WALLET = '5HN6sFM7TbPQazmfhJP1kU8itw7Tb2A9UML8TwSYRwiN9q5Z' -// RPC endpoint -const RPC_ENDPOINT = 'wss://rpc.pezkuwichain.io' +// RPC endpoint — defaults to Asset Hub where user balances live +const RPC_ENDPOINT = Deno.env.get('RPC_ENDPOINT') || 'wss://asset-hub-rpc.pezkuwichain.io' // Token decimals const DECIMALS = 12 diff --git a/web/supabase/functions/process-withdrawal/index.ts b/web/supabase/functions/process-withdrawal/index.ts index f1ba8d55..1ef59443 100644 --- a/web/supabase/functions/process-withdrawal/index.ts +++ b/web/supabase/functions/process-withdrawal/index.ts @@ -28,7 +28,7 @@ import { cryptoWaitReady } from 'npm:@pezkuwi/util-crypto@14.0.11' const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!; const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!; const PLATFORM_WALLET_SEED = Deno.env.get("PLATFORM_WALLET_SEED")!; -const RPC_ENDPOINT = Deno.env.get("RPC_ENDPOINT") || "wss://rpc.pezkuwichain.io"; +const RPC_ENDPOINT = Deno.env.get("RPC_ENDPOINT") || "wss://asset-hub-rpc.pezkuwichain.io"; // Asset IDs const ASSET_IDS: Record = { diff --git a/web/supabase/functions/verify-deposit/index.ts b/web/supabase/functions/verify-deposit/index.ts index 5416eec2..5451bb85 100644 --- a/web/supabase/functions/verify-deposit/index.ts +++ b/web/supabase/functions/verify-deposit/index.ts @@ -28,9 +28,9 @@ function getCorsHeaders(origin: string | null) { // Platform hot wallet address (PRODUCTION) - Treasury_3 const PLATFORM_WALLET = '5H18ZZBU4LwPYbeEZ1JBGvibCU2edhhM8HNUtFi7GgC36CgS' -// RPC endpoints for PezkuwiChain -const RPC_HTTP = 'https://rpc.pezkuwichain.io' -const RPC_WS = 'wss://rpc.pezkuwichain.io' +// RPC endpoints — defaults to Asset Hub where user balances live +const RPC_HTTP = Deno.env.get('RPC_HTTP') || 'https://asset-hub-rpc.pezkuwichain.io' +const RPC_WS = Deno.env.get('RPC_WS') || 'wss://asset-hub-rpc.pezkuwichain.io' // Token decimals const DECIMALS = 12