'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var api = require('../api.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
var logger = require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../../utils/constants/colors.cjs');
require('../../../utils/constants/values.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../shared/consts/index.cjs');
require('@dynamic-labs/multi-wallet');
var getAppOrigin = require('../../../utils/functions/getAppOrigin/getAppOrigin.cjs');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs-wallet/browser-wallet-client');
require('@dynamic-labs-sdk/client/core');
require('eventemitter3');
require('@dynamic-labs-sdk/client');
require('../../../config/ApiEndpoint.cjs');
require('../../../events/dynamicEvents.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');

const isMaliciousUrl = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, url, }) {
    try {
        const request = {
            environmentId,
            scanWebsiteUrlRequest: { url },
        };
        const data = yield api.sdkApi().scanUrl(request);
        return data.isMalicious;
    }
    catch (error) {
        return undefined;
    }
});
const simulateBlockaidUserOperation = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ environmentId, userOperation, chainId, value, entryPoint, }) {
    try {
        const request = {
            environmentId,
            simulateUserOpRequest: {
                chainId,
                entryPoint: entryPoint.address,
                operation: userOperation,
                value: value,
            },
        };
        const transactionData = yield api.sdkApi().simulateUserOp(request);
        return transactionData;
    }
    catch (error) {
        logger.logger.warn('simulateBlockaidUserOperation error', error);
        // when tx is not sponsored and blockaid is on, but user doesnt have enough gas
        if (error instanceof Error &&
            error.message.includes("AA21 didn't pay prefund")) {
            return {
                inAssets: [],
                outAssets: [],
                priceData: { nativeTokenUsdPrice: undefined },
                showTotalFiat: false,
            };
        }
        return undefined;
    }
});
const simulateBlockaidEVMTransaction = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ environmentId, chainId, from, to, value, data, }) {
    try {
        const request = {
            chainId,
            data,
            from,
            to,
            value,
        };
        const simulationRequest = {
            environmentId,
            simulateEVMTransactionRequest: request,
        };
        const transactionData = yield api.sdkApi().simulateEVMTransaction(simulationRequest);
        return transactionData;
    }
    catch (error) {
        logger.logger.warn('simulateBlockaidEVMTransaction error', error);
        return undefined;
    }
});
const simulateBlockaidSVMTransaction = (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ environmentId, chain, accountAddress, transactions, }) {
    var _e;
    try {
        const request = {
            environmentId,
            simulateSVMTransactionRequest: {
                accountAddress,
                chain,
                domain: (_e = getAppOrigin.getAppOrigin()) !== null && _e !== void 0 ? _e : 'https://example.com',
                // signAll works the same as sign, signAndSend, signAll
                method: 'signAllTransactions',
                transactions,
            },
        };
        const transactionData = yield api.sdkApi().simulateSVMTransaction(request);
        return transactionData;
    }
    catch (error) {
        logger.logger.warn('simulateBlockaidSVMTransaction error', error);
        return undefined;
    }
});

exports.isMaliciousUrl = isMaliciousUrl;
exports.simulateBlockaidEVMTransaction = simulateBlockaidEVMTransaction;
exports.simulateBlockaidSVMTransaction = simulateBlockaidSVMTransaction;
exports.simulateBlockaidUserOperation = simulateBlockaidUserOperation;
