async function checkPaymentStatus(orderId) {
const order = await db.orders.get(orderId);
if (!order.walletId) {
return { status: 'no_wallet' };
}
const result = await waas.getWallet(order.walletId);
const wallet = result.wallet;
switch (wallet.status) {
case 'watching':
return { status: 'awaiting_payment', address: wallet.address };
case 'deposit_detected':
return {
status: 'confirming',
amount: wallet.amount,
confirmations: wallet.confirmations,
};
case 'confirmed':
if (order.status !== 'paid') {
await markOrderPaid(orderId, wallet);
}
return { status: 'paid', txHash: wallet.txHash };
case 'expired':
return { status: 'expired' };
default:
return { status: wallet.status };
}
}