/**
 * Converts isEmbeddedSwap boolean to string for analytics consistency
 */
const formatIsEmbeddedSwap = (isEmbeddedSwap) => isEmbeddedSwap !== undefined ? String(isEmbeddedSwap) : undefined;
function getEventData(manifest) {
    return { walletAPI: manifest.name };
}
/**
 * Wrap call to underlying trackCall function.
 * @param trackCall
 * @returns a dictionary of event to trigger.
 */
// Disabling explicit module boundary types as we're using const
// in order to get the exact type matching the tracking wrapper API
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function trackingWrapper(trackCall) {
    const track = (event, properties) => {
        // Filter out undefined values before passing to trackCall
        if (!properties) {
            return trackCall(event, null, null);
        }
        const filteredProperties = {};
        for (const [key, value] of Object.entries(properties)) {
            if (value !== undefined) {
                filteredProperties[key] = value;
            }
        }
        return trackCall(event, filteredProperties, null);
    };
    return {
        // Generate Exchange nonce modal open
        startExchangeRequested: ({ provider, exchangeType, isEmbeddedSwap }) => {
            track(`Starts Exchange ${exchangeType} Nonce request`, {
                provider,
                exchangeType,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // Successfully generated an Exchange app nonce
        startExchangeSuccess: ({ provider, exchangeType, isEmbeddedSwap }) => {
            track(`Starts Exchange ${exchangeType} Nonce success`, {
                provider,
                exchangeType,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // Failed to generate an Exchange app nonce
        startExchangeFail: ({ provider, exchangeType, isEmbeddedSwap }) => {
            track(`Starts Exchange ${exchangeType} Nonce fail`, {
                provider,
                exchangeType,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // No Params to generate an Exchange app nonce
        startExchangeNoParams: (manifest) => {
            track("Starts Exchange no params", getEventData(manifest));
        },
        completeExchangeRequested: ({ provider, exchangeType, isEmbeddedSwap }) => {
            track(`Completes Exchange ${exchangeType} requested`, {
                provider,
                exchangeType,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // Successfully completed an Exchange
        completeExchangeSuccess: ({ provider, exchangeType, currency, isEmbeddedSwap, }) => {
            track(`Completes Exchange ${exchangeType} success`, {
                provider,
                exchangeType,
                currency,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // Failed to complete an Exchange
        completeExchangeFail: ({ provider, exchangeType, isEmbeddedSwap }) => {
            track(`Completes Exchange ${exchangeType} Nonce fail`, {
                provider,
                exchangeType,
                isEmbeddedSwap: formatIsEmbeddedSwap(isEmbeddedSwap),
            });
        },
        // No Params to complete an Exchange
        completeExchangeNoParams: (manifest) => {
            track("Completes Exchange no params", getEventData(manifest));
        },
        swapPayloadRequested: ({ provider, transactionId, fromAccountAddress, toAccountAddress, fromCurrencyId, toCurrencyId, fromAmount, quoteId, }) => {
            track("Swap payload requested", {
                provider,
                transactionId,
                fromAccountAddress,
                toAccountAddress,
                fromCurrencyId,
                toCurrencyId,
                fromAmount: String(fromAmount),
                quoteId,
            });
        },
        swapResponseRetrieved: ({ binaryPayload, signature, payinAddress, swapId, payinExtraId, extraTransactionParameters, }) => {
            track("Swap response retrieved", {
                binaryPayload,
                signature,
                payinAddress,
                swapId,
                payinExtraId,
                extraTransactionParameters,
            });
        },
    };
}
//# sourceMappingURL=tracking.js.map