"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cache_1 = require("@ledgerhq/live-network/cache");
const index_1 = require("@ledgerhq/coin-canton/api/index");
const bignumber_js_1 = require("bignumber.js");
const validateAddress_1 = require("../../../bridge/validateAddress");
// The calls data can be copied to mock-data.ts from the file.
// This function creates a live API with logging for generating mock data
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
function createMockDataForAPI() {
    const signerContext = {};
    const apiGetter = (0, cache_1.makeLRUCache)(config => Promise.resolve((0, index_1.createApi)(config)), config => config.nodeUrl || "", (0, cache_1.minutes)(1000));
    return {
        getAPI: apiGetter,
        getQueuedAPI: apiGetter,
        getQueuedAndCachedAPI: apiGetter,
        signerContext,
    };
}
const createTransaction = () => {
    return {
        family: "canton",
        amount: new bignumber_js_1.BigNumber(0),
        recipient: "",
        tokenId: "Amulet",
        fee: null,
    };
};
const updateTransaction = (t, patch) => {
    return { ...t, ...patch };
};
const getTransactionStatus = async () => {
    return {
        errors: {},
        warnings: {},
        estimatedFees: new bignumber_js_1.BigNumber(0),
        amount: new bignumber_js_1.BigNumber(0),
        totalSpent: new bignumber_js_1.BigNumber(0),
    };
};
const estimateMaxSpendable = ({ account }) => {
    return Promise.resolve(account.balance || new bignumber_js_1.BigNumber(0));
};
const prepareTransaction = async (_account, transaction) => {
    return {
        ...transaction,
        fee: transaction.fee || new bignumber_js_1.BigNumber(100),
    };
};
const sync = (_initialAccount) => {
    return {
        subscribe: (observer) => {
            observer.next((acc) => acc);
            observer.complete();
            return { unsubscribe: () => { } };
        },
    };
};
const receive = (_account, _opts) => {
    return {
        subscribe: (observer) => {
            observer.next({
                address: "mock-address",
                path: "44'/60'/0'/0/0",
                publicKey: "mock-public-key",
            });
            observer.complete();
            return { unsubscribe: () => { } };
        },
    };
};
const signOperation = () => {
    return {
        subscribe: (observer) => {
            observer.next({
                operation: {
                    id: "mock-operation-id",
                    hash: "mock-hash",
                    type: "OUT",
                    value: new bignumber_js_1.BigNumber(0),
                    fee: new bignumber_js_1.BigNumber(100),
                    blockHash: "mock-block-hash",
                    blockHeight: 12345,
                    accountId: "mock-account-id",
                    date: new Date(),
                    extra: {},
                },
                signature: "mock-signature",
            });
            observer.complete();
            return { unsubscribe: () => { } };
        },
    };
};
const broadcast = async () => {
    return {
        id: "mock-operation-id",
        hash: "mock-hash",
        type: "OUT",
        value: new bignumber_js_1.BigNumber(0),
        fee: new bignumber_js_1.BigNumber(100),
        blockHash: "mock-block-hash",
        blockHeight: 12345,
        accountId: "mock-account-id",
        date: new Date(),
        extra: {},
    };
};
const scanAccounts = () => {
    return {
        subscribe: (observer) => {
            observer.next({
                type: "discovered",
                account: {
                    id: "mock-account-id",
                    name: "Mock Canton Account",
                    address: "mock-address",
                    currency: { id: "canton_network_devnet" },
                    balance: new bignumber_js_1.BigNumber(0),
                    spendableBalance: new bignumber_js_1.BigNumber(0),
                    blockHeight: 0,
                    lastSyncDate: new Date(),
                    operations: [],
                    pendingOperations: [],
                    cantonResources: {
                        instrumentUtxoCounts: {},
                        pendingTransferProposals: [],
                    },
                },
            });
            observer.complete();
            return { unsubscribe: () => { } };
        },
    };
};
const getSerializedAddressParameters = () => {
    return Buffer.from("mock-address-params");
};
const accountBridge = {
    createTransaction,
    updateTransaction,
    getTransactionStatus,
    estimateMaxSpendable,
    prepareTransaction,
    sync,
    receive,
    signOperation,
    signRawOperation: () => {
        throw new Error("signRawOperation is not supported");
    },
    broadcast,
    getSerializedAddressParameters,
    validateAddress: validateAddress_1.validateAddress,
};
const currencyBridge = {
    preload: () => Promise.resolve({}),
    hydrate: () => { },
    scanAccounts,
};
exports.default = {
    accountBridge,
    currencyBridge,
};
//# sourceMappingURL=mock.js.map