-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulate-validation.ts
More file actions
63 lines (50 loc) · 2.58 KB
/
Copy pathsimulate-validation.ts
File metadata and controls
63 lines (50 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { getClaim, updateClaimStatus, getSession } from './src/state';
async function simulateClaimantValidationFlow() {
console.log("🚀 Starting Claimant Validation Simulation\n");
const claimCode = 'STL-D001742B1F83';
const recipientChatId = 987654321;
// Reset claim to funded for this test
await updateClaimStatus(claimCode, 'funded', {});
console.log(`1️⃣ Recipient sends: /claim ${claimCode}`);
const claim = await getClaim(claimCode);
console.log(` ✅ Bot validates code. Amount: $${claim!.amountUsd} | Destination: ${claim!.country}`);
console.log("\n2️⃣ Bot prompts: 'How would you like to receive your funds?'");
console.log(" [ 🏦 Bank account ] [ 📱 Airtime & data ]");
console.log(" [ 💳 Virtual card ] [ 🪙 Crypto wallet ]");
console.log("\n3️⃣ Recipient clicks: [ 🪙 Crypto wallet ]");
const session = getSession(recipientChatId);
session.stage = 'awaiting_payout_details';
session.pendingClaimCode = claimCode;
session.payoutMethod = 'wallet';
console.log(" 🤖 Bot: 'Please paste your wallet address (0x... for EVM, or Solana address).'");
console.log("\n4️⃣ Recipient replies with INVALID address:");
const badAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44"; // Missing last char
console.log(` 👤 User: "${badAddress}"`);
const isValidWallet = /^0x[a-fA-F0-9]{40}$/.test(badAddress);
if (!isValidWallet) {
console.log(" ⚠️ Bot: 'That doesn't look like a valid EVM wallet address.'");
console.log(" (Stage remains 'awaiting_payout_details', allowing retry)");
}
console.log("\n5️⃣ Recipient replies with VALID address:");
const goodAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
console.log(` 👤 User: "${goodAddress}"`);
const isValidGood = /^0x[a-fA-F0-9]{40}$/.test(goodAddress);
if (isValidGood) {
console.log(" ✅ Bot validates address format.");
await updateClaimStatus(claimCode, 'settled', {
payoutMethod: 'wallet',
payoutDetails: { address: goodAddress, chain: 'evm' },
});
console.log(" 💾 Supabase updated: status changed to 'settled'");
console.log(" 🚀 PAYOUT EXECUTION HOOK TRIGGERED");
}
console.log("\n" + "═".repeat(65));
console.log("📱 TELEGRAM BOT OUTPUT:");
console.log("═".repeat(65));
console.log(`✅ **Paid!**\n\n` +
`$${claim!.amountUsd} → ~${claim!.expectedLocalAmount} ${claim!.currency}\n` +
`Wallet payout to ${goodAddress.slice(0, 10)}...\n` +
`Payout confirmed by provider`);
console.log("═".repeat(65));
}
simulateClaimantValidationFlow().catch(console.error);