"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.constructOrder = constructOrder;
exports.statusToTimestamp = statusToTimestamp;
exports.orderStatusToUIStatus = orderStatusToUIStatus;
const ethers_1 = require("ethers");
const types_1 = require("../order/types");
function constructOrder(item) {
    return {
        ...item,
        assetNative: item.destinationAsset === ethers_1.ethers.constants.AddressZero && item.sourceAsset === ethers_1.ethers.constants.AddressZero,
        amount: ethers_1.BigNumber.from(item.amount),
        insurance: item.insurance ? ethers_1.BigNumber.from(item.insurance) : ethers_1.BigNumber.from(0),
        maxReward: ethers_1.BigNumber.from(item.maxReward),
        profit: item.profit ? ethers_1.BigNumber.from(item.profit) : ethers_1.BigNumber.from(0),
        confirmedAmount: item.confirmedAmount ? ethers_1.BigNumber.from(item.confirmedAmount) : undefined,
        sourceAccount: ethers_1.ethers.utils.getAddress(item.sourceAccount),
        targetAccount: ethers_1.ethers.utils.getAddress(item.targetAccount),
        executor: item.executor !== '' ? ethers_1.ethers.utils.getAddress(item.executor) : item.executor,
    };
}
function statusToTimestamp(status, order) {
    switch (status) {
        case types_1.OrderStatus.Placed:
            return order.orderTimestamp;
        case types_1.OrderStatus.Bid:
            return order.bidTimestamp;
        case types_1.OrderStatus.Executed:
            return order.confirmationTimestamp;
        case types_1.OrderStatus.Attested:
        case types_1.OrderStatus.AttestedL3:
            return order.attestationTimestamp;
        case types_1.OrderStatus.Claimed:
            return order.claimTimestamp;
        case types_1.OrderStatus.ClaimedRefund:
            return order.refundTimestamp;
        default:
            return undefined;
    }
}
function orderStatusToUIStatus(order) {
    switch (order.status) {
        case types_1.OrderStatus.ConfirmedRefund:
            return types_1.OrderStatus.ClaimedRefund;
        case types_1.OrderStatus.Expired:
            if (order.refundTimestamp > 0) {
                return types_1.OrderStatus.ClaimedRefund;
            }
            if (order.claimTimestamp > 0) {
                return types_1.OrderStatus.Claimed;
            }
            if (order.confirmationTimestamp > 0) {
                return types_1.OrderStatus.Executed;
            }
            if (order.bidTimestamp > 0) {
                return types_1.OrderStatus.Bid;
            }
            break;
        case types_1.OrderStatus.ClaimedInsurance:
        case types_1.OrderStatus.ProcessInsurance:
            return types_1.OrderStatus.Executed;
        default:
            return order.status;
    }
    return order.status;
}
//# sourceMappingURL=helpers.js.map