import { MSG_SEND_TRANSACTION_TYPE, MSG_MULTI_SEND_TRANSACTION_TYPE, } from '../../../dataSource/blockchain/types';
export const extractSenseChats = (myAddress, transactions) => {
    const sendTransactions = transactions.filter((t) => t.type === MSG_SEND_TRANSACTION_TYPE ||
        t.type === MSG_MULTI_SEND_TRANSACTION_TYPE) || [];
    if (sendTransactions.length === 0) {
        return [];
    }
    const chats = new Map();
    transactions.forEach((t) => {
        let userAddress = '';
        if (t.type === MSG_MULTI_SEND_TRANSACTION_TYPE) {
        }
        else if (t.type === MSG_SEND_TRANSACTION_TYPE) {
            const { from_address, to_address, amount } = t.value;
            const isSender = from_address === myAddress;
            userAddress = isSender ? to_address : from_address;
            updateSenseChat(chats, userAddress, t, amount, isSender);
        }
    });
    return chats;
};
const updateSenseChat = (chats, addr, t, amount, isSender) => {
    var _a;
    const transactions = chats.has(addr)
        ? ((_a = chats.get(addr)) === null || _a === void 0 ? void 0 : _a.transactions) || []
        : [];
    transactions.push(t);
    chats.set(addr, {
        userAddress: addr,
        last: { amount, memo: t.memo, direction: isSender ? 'to' : 'from' },
        transactions,
    });
    return chats;
};
//# sourceMappingURL=sense.js.map