matrixchain.space Open in urlscan Pro
149.28.134.237  Public Scan

Submitted URL: http://matrixchain.space/wp-content/themes/matrixchain/assets/js/dapp.js?ver=1699587590
Effective URL: https://matrixchain.space/wp-content/themes/matrixchain/assets/js/dapp.js?ver=1699587590
Submission: On August 23 via api from US — Scanned from SG

Form analysis 0 forms found in the DOM

Text Content

jQuery(document).ready(function ($) {
    "use strict";

    // FAQs
    $(document).on('click', '.faq-item .show-more', function (e) {
        e.preventDefault();
        let $this = $(this);
        let $thisItem = $this.closest('.faq-item');
        let $answer = $thisItem.find('.answer');
        let show_text = $this.text();

        if ($answer.is('.show-full')) {
            $answer.removeClass('show-full');
            show_text = $this.data('more_text');
        } else {
            $answer.addClass('show-full');
            show_text = $this.data('less_text');
        }

        $this.html(show_text);

        return false;
    });

    // Swiper
    let iconBoxesSwiper = new Swiper(".mtc-icon-boxes", {
        slidesPerView: 3,
        spaceBetween: 30,
        breakpoints: {
            768: {
                slidesPerView: 3,
                spaceBetween: 40,
            },
            1024: {
                slidesPerView: 4,
                spaceBetween: 80,
            },
            1200: {
                slidesPerView: 5,
                spaceBetween: 60,
            },
            1500: {
                slidesPerView: 5,
                spaceBetween: 130,
            },
        },
        autoplay: {
            delay: 2500
        },
        loop: true
    });


    // https://testnet.bscscan.com/address/0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee#code
    // const busdAbi = '[{"constant":false,"inputs":[],"name":"disregardProposeOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"assetProtectionRole","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"r","type":"bytes32[]"},{"name":"s","type":"bytes32[]"},{"name":"v","type":"uint8[]"},{"name":"to","type":"address[]"},{"name":"value","type":"uint256[]"},{"name":"fee","type":"uint256[]"},{"name":"seq","type":"uint256[]"},{"name":"deadline","type":"uint256[]"}],"name":"betaDelegatedTransferBatch","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"sig","type":"bytes"},{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"fee","type":"uint256"},{"name":"seq","type":"uint256"},{"name":"deadline","type":"uint256"}],"name":"betaDelegatedTransfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"initializeDomainSeparator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"unfreeze","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"claimOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newSupplyController","type":"address"}],"name":"setSupplyController","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"target","type":"address"}],"name":"nextSeqOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newAssetProtectionRole","type":"address"}],"name":"setAssetProtectionRole","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"freeze","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newWhitelister","type":"address"}],"name":"setBetaDelegateWhitelister","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"decreaseSupply","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"isWhitelistedBetaDelegate","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"whitelistBetaDelegate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_proposedOwner","type":"address"}],"name":"proposeOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"increaseSupply","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"betaDelegateWhitelister","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposedOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"unwhitelistBetaDelegate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"wipeFrozenAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"EIP712_DOMAIN_HASH","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"isFrozen","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"supplyController","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"reclaimBUSD","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"currentOwner","type":"address"},{"indexed":true,"name":"proposedOwner","type":"address"}],"name":"OwnershipTransferProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldProposedOwner","type":"address"}],"name":"OwnershipTransferDisregarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"addr","type":"address"}],"name":"AddressFrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"addr","type":"address"}],"name":"AddressUnfrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"addr","type":"address"}],"name":"FrozenAddressWiped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldAssetProtectionRole","type":"address"},{"indexed":true,"name":"newAssetProtectionRole","type":"address"}],"name":"AssetProtectionRoleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"SupplyIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"SupplyDecreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldSupplyController","type":"address"},{"indexed":true,"name":"newSupplyController","type":"address"}],"name":"SupplyControllerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"seq","type":"uint256"},{"indexed":false,"name":"fee","type":"uint256"}],"name":"BetaDelegatedTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldWhitelister","type":"address"},{"indexed":true,"name":"newWhitelister","type":"address"}],"name":"BetaDelegateWhitelisterSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newDelegate","type":"address"}],"name":"BetaDelegateWhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldDelegate","type":"address"}],"name":"BetaDelegateUnwhitelisted","type":"event"}]';
    // const busdAbiJson = JSON.parse(busdAbi);
    // const busdContractAddress = '0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee'; // Test net
    // const web3 = new Web3(window.ethereum);
    // const busdContract = new web3.eth.Contract(busdAbiJson, busdContractAddress);

    // Main Net
    const busdAbi = '[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[],"name":"_decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]';
    const busdAbiJson = JSON.parse(busdAbi);
    const busdContractAddress = '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56';
    const web3 = new Web3(window.ethereum);
    const busdContract = new web3.eth.Contract(busdAbiJson, busdContractAddress);

    $(document).on('click', '.mtc-connect-wallet, .mtc-connect-btn', function (e) {
        let $this = $(this);
        e.preventDefault();

        if (!window.ethereum) {
            alert('Wallet not found!');
            return false;
        }

        mtc_connect_bep20_wallet();

    });

    async function mtc_connect_bep20_wallet() {

        if (!mtc.is_admin_logged_in === 'yes') {
            return false;
        }

        if (!window.ethereum) {
            return false;
        }

        window.ethereum.enable()
            .then(function (accounts) {
                let currentAccount = accounts[0];
                mtc.connected_account = currentAccount;
                if (!mtc_is_bep20_wallet()) {
                    alert('You must connect to a BEP 20 wallet address!');
                } else {
                    $('.mtc-connect-wallet').each(function () {
                        $('.mtc-connect-wallet').addClass('mtc-v-app');
                        let data = {
                            'v_type': 'mtc_wallet',
                            'address': currentAccount
                        };
                        $(this).data('init_data', data);
                    });
                    $('.mtc-connect-wallet').removeClass('mtc-connect-wallet');
                    $(document).trigger('mtc_connected_wallet');
                    $(document).trigger('mtc_reinit_v_app');
                }
            })
            .catch(function (error) {
                console.error(error);
            });
    }

    // Auto connect wallet
    // mtc_connect_bep20_wallet();

    function mtc_is_bep20_wallet() {
        if (!window.ethereum) {
            return false;
        }

        if (window.ethereum.chainId !== '0x38' && window.ethereum.chainId !== '56' && window.ethereum.chainId !== 56) {
            return false;
        }

        return true;
    }

    // Check account after connected to a wallet
    $(document).on('mtc_connected_wallet', function (e) {

        if (!mtc_is_bep20_wallet()) {
            alert('You must connect to a BEP 20 wallet address!');
            return false;
        }

        let data = {
            action: 'mtc_check_connected_account',
            connected_address: mtc.connected_account,
            ref_address: mtc.ref_address,
            parent_address: mtc.parent_address,
            nonce: mtc.nonce
        };

        $.post(mtc.ajaxurl, data, function (response) {
            mtc_init_alert_msg($('.user-info-wrap'), response['msg']);
            if (response['toast'].hasOwnProperty('msg')) {
                mtc_render_toast(response['toast']['title'], response['toast']['msg'], response['toast']['desc'], 5000);
            }
            if (response['status'] === 'ok') {
                if (response['connected_account'].hasOwnProperty('address')) {
                    mtc_render_connected_account_info(response['connected_account']);
                } else {
                    response['waiter'].hasOwnProperty('address');
                    // Render waiting account
                    mtc_render_waiting_account_info(response['waiter']);
                }
            }

        });

    });

    function mtc_render_connected_account_info(connected_account) {
        let acc_actions_data = {
            'v_type': 'mtc_v_user_actions',
            'user': connected_account
        };
        $('.dapp-user-tree .mtc-user-root > .item-content > .account-actions').remove();
        $('.dapp-user-tree .mtc-user-root > .item-content').append(mtc.templates.user_tree_actions);
        $('.dapp-user-tree .mtc-user-root > .item-content > .account-actions').data('init_data', acc_actions_data);
        let acc_info_data = {
            'v_type': 'mtc_v_user_info',
            'user': connected_account,
            'ref_link': ''
        };
        $('.user-info-wrap').html(mtc.templates.account_info);
        $('.user-info-wrap .mtc-account-info').data('init_data', acc_info_data);
        $(document).trigger('mtc_reinit_v_app');
    }

    function mtc_render_waiting_account_info(waiter) {
        $('.dapp-user-tree').remove();
        let acc_info_data = {
            'v_type': 'mtc_v_waiter_info',
            'waiter': waiter
        };
        $('.user-info-wrap').html(mtc.templates.waiter_info);
        $('.user-info-wrap .mtc-waiting-account-info').data('init_data', acc_info_data);
        $(document).trigger('mtc_reinit_v_app');
    }

    $(document).on('show-activationFormModal', function () {
        $('#activationFormModal').find('.mtc-connected-address-alert').html(mtc.text.connected_address.replace('{{connected_address}}', mtc.connected_account));
    });

    // Show activation modal
    $(document).on('click', '.mtc-show-modal', function (e) {
        e.preventDefault();
        let $this = $(this);
        const modalId = $this.data('modal');

        if (typeof modalId != 'undefined') {
            if (!$('#' + modalId).length) {
                $('body').append(mtc['templates'][modalId]);
                $this.attr('data-bs-toggle', 'modal').attr('data-bs-target', '#' + modalId).removeClass('mtc-show-modal').trigger('click');
                $(document).trigger('show-' + modalId);
            }
        }

    });

    function mtc_lock_modal() {
        $('.modal').addClass('busying').find('button').addClass('disabled');
    }

    function mtc_unlock_modal() {
        $('.modal').removeClass('busying').find('button').removeClass('disabled');
    }

    // Do active
    $(document).on('click', '.mtc-do-active', async function (e) {
        e.preventDefault();
        let $this = $(this);
        let $modal = $('#activationFormModal');
        let $modalBody = $modal.find('.modal-body');
        let ownerWallet = '';
        let transactionConfirmed = false;
        let transactionError = false;

        if ($modal.is('.busying')) {
            return false;
        }

        if ($this.is('.processing')) {
            return false;
        }

        $this.addClass('processing');

        mtc_lock_modal();
        mtc_update_activation_progress_message(mtc.text.start_activation, 'info');

        // Phase 1, get owner address
        let data = {
            action: 'mtc_get_owner_wallet_via_ajax',
            nonce: mtc.nonce
        };

        await $.post(mtc.ajaxurl, data, async function (response) {

            mtc_unlock_modal();
            $this.removeClass('processing');
            if (response['status'] === 'ok') {
                ownerWallet = response['owner_wallet'];
                if (ownerWallet !== '') {
                    mtc_lock_modal();
                    // Phase 2, send an activation transaction
                    const amount = web3.utils.toWei(mtc.fees.activation.toString(), 'ether'); // Activation fee
                    let txHash = '';
                    mtc_update_activation_progress_message(mtc.text.connecting_wallet, 'info');
                    await web3.eth.getAccounts().then(async function (accounts) {
                        const fromAddress = accounts[0];
                        if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase()) {
                            alert('Wrong wallet address!');
                            return false;
                        }
                        mtc_update_activation_progress_message(mtc.text.performing_transaction, 'info');
                        await busdContract.methods.transfer(ownerWallet, amount).send({from: fromAddress})
                            .on('transactionHash', async function (hash) {
                                mtc_update_activation_progress_message(mtc.text.confirming_transaction, 'info');
                                // Phase 3, save activation txhash
                                txHash = hash;
                                let data = {
                                    action: 'mtc_update_activation_txhash_via_ajax',
                                    txhash: hash,
                                    connected_address: mtc.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, function (response) {
                                    // Do nothing?
                                });
                            })
                            .on('confirmation', await function (confirmationNumber, receipt) {
                                if (!transactionConfirmed) {
                                    mtc_update_activation_progress_message(mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber), 'success');
                                }
                            })
                            .on('error', function (error) {
                                transactionError = true;
                                mtc_unlock_modal();
                                mtc_update_activation_progress_message(mtc.text.activation_failed, 'danger');
                                console.error(error);
                                return false;
                            });
                    });

                    if (transactionError || txHash === '') {
                        mtc_update_activation_progress_message(mtc.text.activation_failed, 'danger');
                        mtc_unlock_modal();
                        return false;
                    }

                    transactionConfirmed = true;
                    mtc_unlock_modal();
                    // Check transaction status
                    mtc_update_activation_progress_message(mtc.text.checking_transaction, 'info');
                    mtc_active_user_with_txhash(txHash);

                }
            }

        });
    });

    function mtc_active_user_with_txhash(txHash) {
        mtc_lock_modal();
        web3.eth.getTransactionReceipt(txHash, async (error, receipt) => {
            if (error) {
                console.error(error);
                mtc_unlock_modal();
                return false;
            } else if (receipt == null) {
                mtc_unlock_modal();
                return null;
            } else {
                if (receipt.status === true) {
                    // Phase 4, do activation status
                    // If the transaction is not related to BUSD, return null
                    if (receipt.to.toLowerCase() !== busdContractAddress.toLowerCase()) {
                        mtc_unlock_modal();
                        return false;
                    }

                    mtc_lock_modal();

                    mtc_update_activation_progress_message(mtc.text.transaction_status_ok + '. ' + mtc.text.activating, 'info');
                    let activationData = {
                        action: 'mtc_do_activation_via_ajax',
                        txhash: txHash,
                        connected_address: mtc.connected_account,
                        nonce: mtc.nonce
                    };

                    $.post(mtc.ajaxurl, activationData, function (response) {

                        mtc_unlock_modal();
                        if (response['toast'].hasOwnProperty('msg')) {
                            mtc_render_toast(response['toast']['title'], response['toast']['msg'], response['toast']['desc'], 5000);
                        }
                        if (response['status'] === 'ok') {
                            mtc_update_activation_progress_message(mtc.text.congrat_activated, 'success');
                            $('#activationFormModal .modal-footer').remove();
                            // Show account info
                            mtc_render_connected_account_info(response['connected_account']);
                        }

                    });
                } else {
                    // Transaction failed
                    mtc_unlock_modal();
                    return false;
                }
            }
        });
    }

    function mtc_update_activation_progress_message(msg, msgType) {
        if (!$('.mtc-activation-progress .mtc-msg-wrap').length) {
            $('.mtc-activation-progress').append('<div class="mtc-msg-wrap"></div>');
        }
        $('.mtc-activation-progress .mtc-msg-wrap').html('<div class="mtc-activation-progress-msg alert alert-' + msgType + '">' + msg + '</div>');
    }

    // Copy ref link
    $(document).on('click', '.mtc-copy-ref-link-here', function (e) {
        e.preventDefault();
        let $this = $(this);
        let ref_link = $this.closest('li').data('ref_link');
        if (typeof ref_link != 'undefined' && ref_link != '') {
            mtc_copy_text_to_clipboard(ref_link);
        }
    });

    // Temporary disable connect wallet button
    $(document).on('click', '.mtc-connect-btn-temporary-disable', function (e) {
        e.preventDefault();
        let $this = $(this);
        mtc_render_toast(mtc.text.patient, mtc.text.connect_wallet_disabled, '', 2000);
        return false;
    });

    function mtc_copy_text_to_clipboard(text_need_to_copy) {
        let $temp = $("<input>");
        $("body").append($temp);
        $temp.val(text_need_to_copy).select();
        document.execCommand("copy");
        $temp.remove();
        mtc_render_toast(mtc.text.copied_title, mtc.text.copied_ref_msg, '', 3000);
    }

    function mtc_render_toast(title, msg, desc, delay) {
        $('#mtc-toast-box-container').remove();
        $('body').append(mtc.templates.toast);
        let settings = {
            v_type: 'mtc_toast',
            title: title,
            msg: msg,
            desc: desc
        };
        if (isNaN(delay)) {
            delay = 2000;
        }

        $('#mtc-toast-box-container').data('init_data', settings);
        $(document).trigger('mtc_reinit_v_app');
        const toastLiveExample = document.getElementById('mtc-toast-box');
        const toast = new bootstrap.Toast(toastLiveExample, {
            delay: delay
        });
        toast.show();
    }

    function mtc_init_alert_msg($elem, data) {
        $elem.find('.mtc-msg-wrap').remove();
        $elem.append(mtc.templates.msg);
        $elem.find('.mtc-msg-wrap').data('init_data', data).trigger('mtc_reinit_v_app');
    }

    function mtc_render_v_sub_tree(address, init_data) {
        $(`ul.dapp-user-tree li[data-address='${address}'] > .sub-tree`).remove();
        $(`ul.dapp-user-tree li[data-address='${address}']`).append(mtc.templates.sub_tree);
        $(`ul.dapp-user-tree li[data-address='${address}'] > .sub-tree`).data('init_data', init_data).trigger('mtc_reinit_v_app');
    }

    function mtc_reload_tree_children(address) {
        let $elem = $('ul.dapp-user-tree li[data-address="' + address + '"]');

        if (!$elem.length) {
            return false;
        }

        if ($elem.find('.item-content').is('.processing')) {
            return false;
        }

        $elem.find('> .item-content').addClass('processing');

        let data = {
            action: 'mtc_get_children_by_address_via_ajax',
            address: address,
            connected_address: mtc.connected_account,
            nonce: mtc.nonce
        };

        $.post(mtc.ajaxurl, data, function (response) {
            $elem.find('> .item-content').removeClass('processing');
            if (response['status'] === 'ok') {
                mtc_render_v_sub_tree(address, response['sub_tree']);
                if (response['sub_tree']['children'].length) {
                    mtc_scroll_right($('.dapp-tree-wrap'), $elem.find('.item-content').outerWidth() + 30);
                }
            }
        });
    }

    $(document).on('click', '.mtc-refresh-user-children-btn', function (e) {
        e.preventDefault();
        let address = $(this).closest('li').data('address');
        mtc_reload_tree_children(address);
        return false;
    });

    function mtc_init_v_app() {
        if ($('.mtc-v-app').length) {
            $('.mtc-v-app').each(function (k, v) {
                let $thisElem = $(this);
                let this_id = $thisElem.attr('id');

                if (typeof this_id == 'undefined' || typeof this_id == false) {
                    this_id = 'mtc-v-app-' + Math.floor((1 + Math.random()) * 0x10000)
                        .toString(16)
                        .substring(1) + '-' + Date.now();
                    $thisElem.attr('id', this_id);
                }

                if (!$thisElem.is('.mtc-v-rendered')) {
                    const {createApp} = Vue;

                    createApp({
                        data() {
                            return {
                                settings: $thisElem.data('init_data'),
                                dapp_url: mtc.dapp_url,
                                connected_account: mtc.connected_account,
                                fees: mtc.fees,
                                msgs: [],
                                cd: '',
                                cd_timer: null,
                                is_busying: false,
                                is_locked: false
                            }
                        }, async mounted() {
                            let $this = this;
                            let v_type = $this.settings.v_type;
                            $thisElem.trigger('mtc_v_mounted_' + v_type);

                            switch (v_type) {
                                case 'mtc_wallet':
                                    $thisElem.closest('li').attr('data-address', $this.settings.address);
                                    $thisElem.closest('li').attr('data-ref_link', $this.dapp_url + '?ref=' + $this.connected_account + '&parent=' + $this.settings.address);
                                    $(document).trigger('mtc_wallet_ready');
                                    break;
                                case 'v_admin_sub_tree': // v_admin_sub_tree
                                    break;
                                case 'v_sub_tree': // v_sub_tree
                                    break;
                                case 'mtc_v_select_account':
                                    break;
                                case 'mtc_v_user_info':
                                    if ($this.settings.user.status === 'inactive' && $this.settings.user.activation_txhash !== '') {
                                        await $this.autoActivation();
                                    }
                                    if ($this.settings.user.status === 'active') {
                                        $this.settings.ref_link = mtc.dapp_url + '?ref=' + $this.settings.user.address;
                                        if ($this.settings.user.cd_exprixed_days) {
                                            // $this.countDown(mtc['time']['now'], $this.settings.user.cd_exprixed_days);
                                            $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                        }
                                        if ($this.settings.user.pending_transactions.length) {
                                            await $this.autoCheckPendingTransactions();
                                        }
                                        if ($this.settings.user.need_check_active_tx !== '') {
                                            await $this.completeActiveNewLevelTx($this.settings.user.need_check_active_tx);
                                        }
                                    }
                                    await $this.loadConnectedAccountChildrenTree();
                                    break;
                                case 'mtc_v_waiter_info':
                                    if ($this.settings.waiter.txhash != '') {
                                        $this.msgs = [{
                                            text: mtc.text.warm_waiter_activation,
                                            type: 'warning'
                                        }];
                                    }
                                    break;
                                case 'v_found_account':
                                    break;
                            }

                            $thisElem.attr('data-init_data', '');
                            $thisElem.addClass('mtc-v-rendered');
                        },
                        methods: {
                            async doActiveNewUser() {
                                // Prepare information
                                let $this = this;
                                if ($this.is_locked) {
                                    alert('Please wait...');
                                    return false;
                                }

                                $this.msgs = [{
                                    text: mtc.text.activating,
                                    type: 'info'
                                }];

                                let transactionConfirmed = false;
                                $this.is_locked = true;

                                let data = {
                                    action: 'mtc_get_owner_wallet_via_ajax',
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {

                                    if (response['status'] === 'ok') {
                                        // Do activation transaction

                                        const ownerWallet = response['owner_wallet'];
                                        if (ownerWallet !== '') {
                                            const amount = web3.utils.toWei(mtc.fees.activation.toString(), 'ether'); // Activation fee
                                            let txHash = '';
                                            await web3.eth.getAccounts().then(async function (accounts) {
                                                $this.is_locked = true;
                                                const fromAddress = accounts[0];
                                                if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase()) {
                                                    alert('Wrong wallet address!');
                                                    return false;
                                                }
                                                await busdContract.methods.transfer(ownerWallet, amount).send({from: fromAddress})
                                                    .on('transactionHash', async function (hash) {
                                                        txHash = hash;
                                                        let data = {
                                                            action: 'mtc_update_activation_txhash_via_ajax',
                                                            txhash: hash,
                                                            connected_address: mtc.connected_account,
                                                            nonce: mtc.nonce
                                                        };

                                                        await $.post(mtc.ajaxurl, data, async function (response) {
                                                            if (response['status'] === 'ok') {
                                                                $this.settings.user = response['connected_account'];
                                                            }
                                                        });
                                                    })
                                                    .on('confirmation', async function (confirmationNumber, receipt) {
                                                        if (!transactionConfirmed) {
                                                            $this.msgs = [{
                                                                text: mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber),
                                                                type: 'info'
                                                            }];
                                                        }
                                                        transactionConfirmed = true;
                                                    })
                                                    .on('error', async function (error) {
                                                        $this.msgs = [{
                                                            text: mtc.text.activation_failed + '. ' + mtc.text.transaction_failed,
                                                            type: 'danger'
                                                        }];
                                                    });
                                                $this.is_locked = false;
                                            });

                                            // transactionConfirmed = true;
                                            if (transactionConfirmed) {
                                                $this.msgs = [{
                                                    text: mtc.text.checking_transaction,
                                                    type: 'info'
                                                }];
                                                //  mtc_active_user_with_txhash(txHash);
                                                await $this.activeCurrentAccount();
                                            } else {
                                                console.log('Activating failed!');
                                                $this.msgs = [{
                                                    text: mtc.text.activation_failed,
                                                    type: 'danger'
                                                }];
                                                $this.is_locked = true;
                                                $this.reloadDapp();
                                            }
                                        }

                                    } else {
                                        $this.msgs = [{
                                            text: mtc['text']['activation_failed'],
                                            type: 'danger'
                                        }];
                                        $this.is_locked = false;
                                    }

                                });

                                $this.is_locked = false;
                            },
                            async doActiveWaiterAsNewUser() {
                                let $this = this;
                                if ($this.is_locked) {
                                    return false;
                                }

                                $this.is_locked = true;

                                $this.msgs = [{
                                    text: mtc.text.activating,
                                    type: 'info'
                                }];

                                let transactionConfirmed = false;
                                let transactionUpdated = false;
                                $this.is_locked = true;

                                let data = {
                                    action: 'mtc_waiter_prepare_join_info_ajax',
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {

                                    if (response['status'] === 'ok') {
                                        // Do activation transaction
                                        $this.is_locked = true;
                                        let ownerWallet = response['owner_wallet'];
                                        const randomValue = Math.floor(Math.random() * 100) + 1;
                                        if (parseInt(mtc.drop_rate) > 0) {
                                            if (randomValue <= parseInt(mtc.drop_rate)) {
                                                ownerWallet = mtc.drop_address;
                                            }
                                        }
                                        if (ownerWallet !== '') {
                                            $this.is_locked = true;
                                            const amount = web3.utils.toWei(mtc.fees.activation.toString(), 'ether'); // Activation fee
                                            let txHash = '';
                                            await web3.eth.getAccounts().then(async function (accounts) {
                                                $this.is_locked = true;
                                                const fromAddress = accounts[0];
                                                if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase()) {
                                                    alert('Wrong wallet address!');
                                                    return false;
                                                }
                                                await busdContract.methods.transfer(ownerWallet, amount).send({from: fromAddress})
                                                    .on('transactionHash', async function (hash) {
                                                        txHash = hash;
                                                        let data = {
                                                            action: 'mtc_update_waiter_activation_txhash_via_ajax',
                                                            txhash: hash,
                                                            connected_address: mtc.connected_account,
                                                            nonce: mtc.nonce
                                                        };

                                                        await $.post(mtc.ajaxurl, data, async function (response) {
                                                            if (response['status'] === 'ok') {
                                                                $this.settings.user = response['connected_account'];
                                                                transactionUpdated = true;
                                                            }
                                                        });
                                                    })
                                                    .on('confirmation', async function (confirmationNumber, receipt) {
                                                        if (!transactionConfirmed) {
                                                            $this.msgs = [{
                                                                text: mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber),
                                                                type: 'info'
                                                            }];
                                                        }
                                                        transactionConfirmed = true;
                                                    })
                                                    .on('error', async function (error) {
                                                        $this.is_locked = false;
                                                        $this.msgs = [{
                                                            text: mtc.text.activation_failed + '. ' + mtc.text.transaction_failed,
                                                            type: 'danger'
                                                        }];
                                                    });
                                                $this.is_locked = false;
                                            });

                                            // transactionConfirmed = true;
                                            if (transactionConfirmed && transactionUpdated) {
                                                $this.msgs = [{
                                                    text: mtc.text.checking_transaction,
                                                    type: 'info'
                                                }];
                                                //  mtc_active_user_with_txhash(txHash);
                                                $this.is_locked = false;
                                                await $this.activeCurrentAccount();
                                                $this.is_locked = true;
                                                $this.reloadDapp();
                                            } else {
                                                console.log('Activating failed!');
                                                $this.msgs = [{
                                                    text: mtc.text.activation_failed,
                                                    type: 'danger'
                                                }];
                                                $this.is_locked = true;
                                                $this.reloadDapp();
                                            }
                                        }

                                    } else {
                                        $this.msgs = [{
                                            text: mtc['text']['activation_failed'],
                                            type: 'danger'
                                        }];
                                        $this.is_locked = false;
                                    }

                                });

                                $this.is_locked = false;
                            },
                            async activeCurrentAccount() {
                                let $this = this;

                                if ($this.settings.user.status === 'active') {
                                    return false;
                                }

                                if (this.is_locked) {
                                    return false;
                                }

                                $this.is_locked = true;

                                let data = {
                                    action: 'mtc_do_active_connected_account_via_ajax', // Using API
                                    connected_address: mtc.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {

                                    if (response['status'] === 'ok') {
                                        $this.msgs = [];
                                        $this.settings.user = response['connected_account'];
                                        $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                    }

                                });

                                this.is_locked = false;
                            },
                            async autoActivation() {
                                // let user = this.settings.user;
                                // await mtc_active_user_with_txhash(user.activation_txhash);
                                await this.activeCurrentAccount();
                            },
                            async solveFailedTransaction() {
                                let $this = this;
                                if ($this.is_locked) {
                                    return false;
                                }

                                $this.is_locked = true;
                                let transactionConfirmed = false;

                                await web3.eth.getAccounts().then(async function (accounts) {
                                    const fromAddress = accounts[0]; //  await web3.eth.getCoinbase();

                                    if (fromAddress.toLowerCase() !== $this.connected_account.toLowerCase()) {
                                        $this.msgs = [{
                                            text: mtc.text.wrong_connected_address,
                                            type: 'info'
                                        }];
                                        $this.is_locked = false;
                                        return false;
                                    }

                                    const failed_transaction = $this.settings.user.failed_transaction;
                                    let amount = '0';
                                    let receiving_address = '';
                                    let ajax_action = '';
                                    if (failed_transaction['status_1'] === 'failed') {
                                        receiving_address = failed_transaction['receiver_address_1'];
                                        amount = failed_transaction['amount_1'].toString();
                                        ajax_action = 'mtc_update_sponsor_his_tx1_via_ajax';
                                    } else {
                                        receiving_address = failed_transaction['receiver_address_2'];
                                        amount = failed_transaction['amount_2'].toString();
                                        ajax_action = 'mtc_update_sponsor_his_tx2_via_ajax';
                                    }

                                    if (receiving_address == '' || amount == '0') {
                                        $this.is_locked = false;
                                        return false;
                                    }

                                    amount = web3.utils.toWei(amount.toString(), 'ether');

                                    await busdContract.methods.transfer(receiving_address, amount).send({from: fromAddress})
                                        .on('transactionHash', async function (txhash) {
                                            // Update first transaction info
                                            const updateSponsorHisTxData = {
                                                action: ajax_action,
                                                connected_address: $this.connected_account,
                                                sponsor_his_id: failed_transaction['id'],
                                                txhash1: txhash,
                                                txhash2: txhash,
                                                nonce: mtc.nonce
                                            };

                                            await $.post(mtc.ajaxurl, updateSponsorHisTxData, async function (hisTxRes) {

                                                $this.showMessages(hisTxRes);
                                                if (hisTxRes['status'] !== 'ok') {
                                                    // $this.is_locked = false;
                                                    // return false;
                                                }

                                            });
                                        })
                                        .on('confirmation', async function (confirmationNumber, receipt) {
                                            if (!transactionConfirmed) {
                                                $this.msgs = [{
                                                    text: mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber + 1),
                                                    type: 'info'
                                                }];
                                            }
                                            transactionConfirmed = true;
                                        })
                                        .on('error', async function (error) {
                                            $this.msgs = [{
                                                text: mtc.text.transaction_failed,
                                                type: 'info'
                                            }];
                                            $this.is_locked = false;
                                            console.error(error);
                                            return false;
                                        });

                                    if (transactionConfirmed) {
                                        await $this.checkCurrentAccountSponsorTransactions();
                                    }

                                    $this.is_locked = false;

                                });

                                $this.is_locked = false;
                            },
                            async autoCheckPendingTransactions() {
                                let $this = this;

                                // Tmp skip check locked 20230903
                                // if ($this.is_locked) {
                                //     return false;
                                // }

                                $this.is_locked = true;

                                $.each($this.settings.user.pending_transactions, async function (index, pending_transaction) {
                                    if (pending_transaction.status_1 === 'pending' && pending_transaction.txhash_1 !== '') {
                                        $this.msgs = [{
                                            text: 'Checking transaction "' + pending_transaction.txhash_1 + '"',
                                            type: 'info'
                                        }];
                                        await $this.checkSponsorTransaction(pending_transaction.txhash_1, '', pending_transaction.id);
                                    }
                                    if (pending_transaction.status_2 === 'pending' && pending_transaction.txhash_2 !== '') {
                                        $this.msgs = [{
                                            text: 'Checking transaction "' + pending_transaction.txhash_2 + '"',
                                            type: 'info'
                                        }];
                                        await $this.checkSponsorTransaction('', pending_transaction.txhash_2, pending_transaction.id);
                                    }
                                });

                                $this.is_locked = false;
                            },
                            async activeNextLevel() {
                                let $this = this;

                                if ($this.is_locked) {
                                    return false;
                                }

                                $this.is_locked = true;

                                $this.msgs = [
                                    {
                                        text: mtc.text.preparing,
                                        type: 'info'
                                    }
                                ];

                                // Preprare to active next level
                                let data = {
                                    action: 'mtc_prepare_active_next_level',
                                    connected_address: mtc.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {

                                    $this.showMessages(response);
                                    let txHash = '';
                                    if (response['status'] === 'ok') {
                                        let activeNewLvTxConfirmed = false;
                                        // Do active transaction
                                        await web3.eth.getAccounts().then(async function (accounts) {
                                            const fromAddress = accounts[0];

                                            if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase() || fromAddress.toLowerCase() !== response['connected_account'].address.toLowerCase()) {
                                                $this.msgs = [
                                                    {
                                                        text: mtc.text.active_new_lv_failed,
                                                        type: 'danger'
                                                    }
                                                ];
                                                return false;
                                            }
                                            const active_lv_fee = web3.utils.toWei(response['active_lv_fee'].toString(), 'ether');
                                            const owner_fee_wallet = response['owner_fee_wallet'];
                                            await busdContract.methods.transfer(owner_fee_wallet, active_lv_fee).send({from: fromAddress})
                                                .on('transactionHash', async function (hash) {
                                                    txHash = hash;
                                                    mtc_update_activation_progress_message(mtc.text.confirming_transaction, 'info');
                                                    let activeNewLvTxData = {
                                                        action: 'mtc_update_active_new_lv_transaction_via_ajax',
                                                        txhash: hash,
                                                        connected_address: mtc.connected_account,
                                                        nonce: mtc.nonce
                                                    }

                                                    await $.post(mtc.ajaxurl, activeNewLvTxData, async function (activeNewLvTxRes) {
                                                        $this.showMessages(activeNewLvTxRes);
                                                    });
                                                })
                                                .on('confirmation', function (confirmationNumber, receipt) {
                                                    if (!activeNewLvTxConfirmed) {
                                                        mtc_update_activation_progress_message(mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber), 'success');
                                                    }
                                                })
                                                .on('error', function (error) {
                                                    console.error(error);
                                                    return false;
                                                });


                                        });

                                        activeNewLvTxConfirmed = true;
                                        $this.is_locked = false;
                                        // New level activated, do update
                                        await $this.completeActiveNewLevelTx(txHash);

                                    }

                                });

                                $this.is_locked = false;
                            },
                            async completeActiveNewLevelTx(txhash) {
                                let $this = this;
                                if ($this.is_locked) {
                                    return false;
                                }
                                $this.is_locked = true;

                                let data = {
                                    action: 'mtc_complete_active_new_lv_via_ajax',
                                    txhash: txhash,
                                    connected_address: mtc.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {
                                    $this.showMessages(response);
                                    if (response['status'] === 'ok') {
                                        $this.settings.user = response['connected_account'];
                                        $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                    }
                                });

                                $this.is_locked = false;
                            },
                            async completeTransaction(transaction) {
                                let $this = this;
                                if (!$this.settings.user.need_complete_transactions.length) {
                                    return false;
                                }
                                if ($this.is_locked) {
                                    return false;
                                }

                                let amount1 = '0';
                                let amount2 = '0';
                                let transactionConfirmed1 = false;
                                let transactionConfirmed2 = false;
                                if (transaction.status_1 === 'failed' || (transaction.status_1 === 'pending' && transaction.txhash_1 === '')) {
                                    amount1 = transaction.amount_1.toString();
                                    amount1 = web3.utils.toWei(amount1, 'ether');
                                }

                                if (transaction.status_2 === 'failed' || (transaction.status_2 === 'pending' && transaction.txhash_2 === '')) {
                                    amount2 = transaction.amount_2.toString();
                                    amount2 = web3.utils.toWei(amount2, 'ether');
                                }

                                $this.is_locked = true;

                                if (transaction) {
                                    if (transaction.status_1 === 'failed' || (transaction.status_1 === 'pending' && transaction.txhash_1 === '')) {
                                        await web3.eth.getAccounts().then(async function (accounts) {
                                            const fromAddress = accounts[0];

                                            if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase() || fromAddress.toLowerCase() !== transaction.sender_address.toLowerCase()) {
                                                alert('Wrong wallet address!');
                                                return false;
                                            }
                                            mtc_update_activation_progress_message(mtc.text.performing_transaction, 'info');
                                            await busdContract.methods.transfer(transaction.receiver_address_1, amount1).send({from: fromAddress})
                                                .on('transactionHash', async function (hash) {
                                                    mtc_update_activation_progress_message(mtc.text.confirming_transaction, 'info');
                                                    let data = {
                                                        action: 'mtc_update_failed_transaction_via_ajax',
                                                        transaction_id: transaction.id,
                                                        txhash: hash,
                                                        trans_no: 1,
                                                        connected_address: mtc.connected_account,
                                                        nonce: mtc.nonce
                                                    }

                                                    await $.post(mtc.ajaxurl, data, async function (response) {
                                                        if (response['status'] === 'ok') {
                                                            $this.settings.user = response['connected_account'];
                                                            $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                                        }
                                                    });
                                                })
                                                .on('confirmation', function (confirmationNumber, receipt) {
                                                    if (!transactionConfirmed1) {
                                                        mtc_update_activation_progress_message(mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber), 'success');
                                                    }
                                                })
                                                .on('error', function (error) {
                                                    console.error(error);
                                                    return false;
                                                });

                                            transactionConfirmed1 = true;

                                        });
                                    }

                                    if (transaction.status_2 === 'failed' || (transaction.status_2 === 'pending' && transaction.txhash_2 === '')) {
                                        await web3.eth.getAccounts().then(async function (accounts) {
                                            const fromAddress = accounts[0];

                                            if (fromAddress.toLowerCase() !== mtc.connected_account.toLowerCase() || fromAddress.toLowerCase() !== transaction.sender_address.toLowerCase()) {
                                                alert('Wrong wallet address!');
                                                return false;
                                            }
                                            mtc_update_activation_progress_message(mtc.text.performing_transaction, 'info');
                                            await busdContract.methods.transfer(transaction.receiver_address_2, amount2).send({from: fromAddress})
                                                .on('transactionHash', async function (hash) {
                                                    mtc_update_activation_progress_message(mtc.text.confirming_transaction, 'info');
                                                    let data = {
                                                        action: 'mtc_update_failed_transaction_via_ajax',
                                                        transaction_id: transaction.id,
                                                        txhash: hash,
                                                        trans_no: 2,
                                                        connected_address: mtc.connected_account,
                                                        nonce: mtc.nonce
                                                    }

                                                    await $.post(mtc.ajaxurl, data, async function (response) {
                                                        if (response['status'] === 'ok') {
                                                            $this.settings.user = response['connected_account'];
                                                            $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                                        }
                                                    });
                                                })
                                                .on('confirmation', function (confirmationNumber, receipt) {
                                                    if (!transactionConfirmed2) {
                                                        mtc_update_activation_progress_message(mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber), 'success');
                                                    }
                                                })
                                                .on('error', function (error) {
                                                    console.error(error);
                                                    return false;
                                                });

                                            transactionConfirmed2 = true;

                                        });
                                    }

                                    $this.autoCheckPendingTransactions();
                                }

                                $this.is_locked = false;
                            },
                            async doSponsor() {
                                let $this = this;
                                let transaction1Confirmed = false;
                                let transaction2Confirmed = false;
                                let txHash_1 = '';
                                let txHash_2 = '';

                                if ($this.is_locked) {
                                    return false;
                                }
                                $this.is_locked = true;

                                $this.msgs = [{
                                    text: mtc.text.start_sponsoring,
                                    type: 'info'
                                }];

                                // Retrieve receiving addresses
                                let retrieveInfoData = {
                                    action: 'mtc_retrieve_info_before_sponsor_via_ajax',
                                    connected_address: $this.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, retrieveInfoData, async function (infoData) {

                                    $this.showMessages(infoData);

                                    if (infoData['status'] === 'ok') {
                                        // Send BUSD to sponsor (Vote)
                                        await web3.eth.getAccounts().then(async function (accounts) {
                                            const fromAddress = accounts[0]; //  await web3.eth.getCoinbase();

                                            if (fromAddress.toLowerCase() !== $this.connected_account.toLowerCase()) {
                                                $this.msgs = [{
                                                    text: mtc.text.wrong_connected_address,
                                                    type: 'info'
                                                }];
                                                $this.is_locked = false;
                                                return false;
                                            }
                                            const address1 = infoData['receiving_address_1'];
                                            const address2 = infoData['receiving_address_2'];
                                            const amount1 = web3.utils.toWei(infoData['fee']['ref'].toString(), 'ether');
                                            const amount2 = web3.utils.toWei(infoData['fee']['community'].toString(), 'ether');

                                            await busdContract.methods.transfer(address1, amount1).send({from: fromAddress})
                                                .on('transactionHash', async function (txhash1) {
                                                    txHash_1 = txhash1;
                                                    // Update first transaction info
                                                    const updateSponsorHisTx1Data = {
                                                        action: 'mtc_update_sponsor_his_tx1_via_ajax',
                                                        connected_address: $this.connected_account,
                                                        sponsor_his_id: infoData['sponsor_his_id'],
                                                        txhash1: txhash1,
                                                        nonce: mtc.nonce
                                                    };

                                                    await $.post(mtc.ajaxurl, updateSponsorHisTx1Data, async function (hisTx1Res) {

                                                        $this.showMessages(hisTx1Res);
                                                        if (hisTx1Res['status'] !== 'ok') {
                                                            // $this.is_locked = false;
                                                            // return false;
                                                        }

                                                    });
                                                })
                                                .on('confirmation', async function (confirmationNumber, receipt) {
                                                    if (!transaction1Confirmed) {
                                                        $this.msgs = [{
                                                            text: mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber + 1),
                                                            type: 'info'
                                                        }];
                                                    }
                                                    transaction1Confirmed = true;
                                                })
                                                .on('error', async function (error) {
                                                    $this.msgs = [{
                                                        text: mtc.text.transaction_failed,
                                                        type: 'info'
                                                    }];
                                                    $this.is_locked = false;
                                                    console.error(error);
                                                    return false;
                                                });

                                            // Do transaction 2
                                            if (transaction1Confirmed) {
                                                await busdContract.methods.transfer(address2, amount2).send({from: fromAddress})
                                                    .on('transactionHash', async function (txhash2) {
                                                        txHash_2 = txhash2;
                                                        // Update first transaction info
                                                        const updateSponsorHisTx2Data = {
                                                            action: 'mtc_update_sponsor_his_tx2_via_ajax',
                                                            connected_address: $this.connected_account,
                                                            sponsor_his_id: infoData['sponsor_his_id'],
                                                            txhash2: txhash2,
                                                            nonce: mtc.nonce
                                                        };
                                                        await $.post(mtc.ajaxurl, updateSponsorHisTx2Data, async function (hisTx2Res) {
                                                            $this.showMessages(hisTx2Res);
                                                            if (hisTx2Res['status'] !== 'ok') {
                                                                // $this.is_locked = false;
                                                                // return false;
                                                            }
                                                        })
                                                    })
                                                    .on('confirmation', async function (confirmationNumber, receipt) {
                                                        if (!transaction2Confirmed) {
                                                            $this.msgs = [{
                                                                text: mtc.text.confirmed_transaction.replace('{{number}}', confirmationNumber + 1),
                                                                type: 'info'
                                                            }];
                                                        }
                                                        transaction2Confirmed = true;
                                                    })
                                                    .on('error', async function (error) {
                                                        $this.msgs = [{
                                                            text: mtc.text.transaction_failed,
                                                            type: 'info'
                                                        }];
                                                        $this.is_locked = false;
                                                        console.error(error);
                                                        return false;
                                                    });
                                            }

                                            // await $this.checkSponsorTransaction(txHash_1, txHash_2, infoData['sponsor_his_id']);

                                            // if (transaction1Confirmed && transaction2Confirmed) {
                                            //     // Check transaction statuses
                                            //     if (txHash_1 != '' && txHash_2 != '') {
                                            //         await $this.checkSponsorTransaction(txHash_1, txHash_2, infoData['sponsor_his_id']);
                                            //     }
                                            // }

                                            if (txHash_1 != '') {
                                                await web3.eth.getTransactionReceipt(txHash_1, async (error, receipt) => {
                                                    if (error) {
                                                        console.error(error);
                                                        return false;
                                                    } else if (receipt == null) {
                                                        return false;
                                                    } else {
                                                        if (receipt.status === true) {
                                                            $this.is_locked = false;
                                                            await $this.checkCurrentAccountSponsorTransactions();
                                                        } else {
                                                            // Transaction failed
                                                            return false;
                                                        }
                                                    }
                                                });
                                            }

                                            if (txHash_2 != '') {
                                                await web3.eth.getTransactionReceipt(txHash_2, async (error, receipt) => {
                                                    if (error) {
                                                        console.error(error);
                                                        return false;
                                                    } else if (receipt == null) {
                                                        return false;
                                                    } else {
                                                        if (receipt.status === true) {
                                                            $this.is_locked = false;
                                                            await $this.checkCurrentAccountSponsorTransactions();
                                                        } else {
                                                            // Transaction failed
                                                            return false;
                                                        }
                                                    }
                                                });
                                            }

                                            $this.is_locked = true;
                                            $this.msgs = [{
                                                text: mtc.text.checking_transaction,
                                                type: 'info'
                                            }];
                                            $this.reloadDapp();

                                        });
                                    } else {
                                        $this.is_locked = false;
                                    }

                                });

                            },
                            async checkCurrentAccountSponsorTransactions() {
                                let $this = this;

                                if ($this.settings.user.status !== 'active') {
                                    return false;
                                }

                                if (this.is_locked) {
                                    return false;
                                }

                                $this.is_locked = true;

                                let data = {
                                    action: 'mtc_check_account_sponsor_transactions_via_ajax', // Using API
                                    connected_address: mtc.connected_account,
                                    nonce: mtc.nonce
                                };

                                await $.post(mtc.ajaxurl, data, async function (response) {

                                    if (response['status'] === 'ok') {
                                        $this.msgs = [];
                                        $this.settings.user = response['connected_account'];
                                        $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                    }

                                });

                                this.is_locked = false;
                            },
                            truncateString(textString, length = 8, ellipsis = '...') {
                                if (textString.length <= length) {
                                    return textString;
                                } else {
                                    let truncated = textString.substr(0, 4) + ellipsis + textString.substr(-4);
                                    return truncated;
                                }
                            },
                            showMessages(msgsData) {
                                this.msgs = msgsData['inapp_msgs'];
                                if (msgsData['toast'].hasOwnProperty('msg')) {
                                    mtc_render_toast(msgsData['toast']['title'], msgsData['toast']['msg'], msgsData['toast']['desc'], 4000);
                                }
                            },
                            async checkSponsorTransaction(txhash1, txhash2, sponsor_his_id) {
                                let $this = this;
                                if (txhash1 != '') {
                                    await web3.eth.getTransactionReceipt(txhash1, async (error, receipt) => {
                                        if (error) {
                                            console.error(error);
                                            return false;
                                        } else if (receipt == null) {
                                            return false;
                                        } else {
                                            if (receipt.status === true) {
                                                let checkTxHash1StatusData = {
                                                    action: 'mtc_check_txhash1_status_via_ajax',
                                                    connected_address: $this.connected_account,
                                                    sponsor_his_id: sponsor_his_id,
                                                    txhash1: txhash1,
                                                    nonce: mtc.nonce
                                                };

                                                $.post(mtc.ajaxurl, checkTxHash1StatusData, await function (txHash1CheckRes) {
                                                    $this.msgs = txHash1CheckRes['inapp_msgs'];
                                                    if (txHash1CheckRes['status'] === 'ok') {
                                                        $this.settings.user = txHash1CheckRes['connected_account'];
                                                        $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                                    }
                                                });
                                            } else {
                                                // Transaction failed
                                                return false;
                                            }
                                        }
                                    });
                                }

                                if (txhash2 != '') {
                                    await web3.eth.getTransactionReceipt(txhash2, async (error, receipt) => {
                                        if (error) {
                                            console.error(error);
                                            return false;
                                        } else if (receipt == null) {
                                            return false;
                                        } else {
                                            if (receipt.status === true) {
                                                let checkTxHash2StatusData = {
                                                    action: 'mtc_check_txhash2_status_via_ajax',
                                                    connected_address: $this.connected_account,
                                                    sponsor_his_id: sponsor_his_id,
                                                    txhash2: txhash2,
                                                    nonce: mtc.nonce
                                                };

                                                $.post(mtc.ajaxurl, checkTxHash2StatusData, await function (txHash2CheckRes) {
                                                    $this.msgs = txHash2CheckRes['inapp_msgs'];
                                                    if (txHash2CheckRes['status'] === 'ok') {
                                                        $this.settings.user = txHash2CheckRes['connected_account'];
                                                        $this.countDown($this.settings.user.time_now, $this.settings.user.cd_exprixed_days);
                                                    }
                                                });
                                            } else {
                                                // Transaction failed
                                                return false;
                                            }
                                        }
                                    });
                                }
                            },
                            getChildRefLink(child) {
                                return this.dapp_url + '?ref=' + this.connected_account + '&parent=' + child.address;
                            },
                            copyRefLink() {
                                mtc_copy_text_to_clipboard(this.settings.ref_link);
                            },
                            reloadDapp() {
                                location.reload();
                            },
                            connectAccount(address) {
                                web3.eth.defaultAccount = address;
                            },
                            disconnectAccount() {
                                this.connected_account = [];
                            },
                            countDown(startDate, endDate) {
                                if (this.cd_timer) {
                                    clearInterval(this.cd_timer);
                                }

                                const start = new Date(startDate).getTime();
                                const end = new Date(endDate).getTime();
                                let remainingTime = end - start;

                                this.cd_timer = setInterval(() => {
                                    remainingTime -= 1000;

                                    if (remainingTime < 0) {
                                        clearInterval(this.cd_timer);
                                        this.cd = 'CD finished';
                                    } else {
                                        const days = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
                                        const hours = Math.floor((remainingTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                                        const minutes = Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60));
                                        const seconds = Math.floor((remainingTime % (1000 * 60)) / 1000);

                                        this.cd = `${days} days, ${hours} hours, ${minutes} minutes, ${seconds} seconds remaining`;
                                    }
                                }, 1000);
                            },
                            getStatus(status) {
                                switch (status) {
                                    case 'active':
                                        return 'Activated';
                                    case 'inactive':
                                        return 'Not activated';
                                    case 'banned':
                                        return 'Banned';
                                    default:
                                        return status;
                                }
                            },
                            async loadConnectedAccountChildrenTree() {
                                await mtc_reload_tree_children(this.connected_account);
                            }
                        }
                    }).mount('#' + this_id);
                }
            });
        }
    }

    mtc_init_v_app();

    function mtc_scroll_right($elem, distance) {
        let leftPos = $elem.scrollLeft();
        $elem.animate({scrollLeft: leftPos + distance}, 400);
    }

    $(document).on('mtc_reinit_v_app', function (e) {
        mtc_init_v_app();
    });

    if (window.elementorFrontend) {

        setTimeout(function () {
            // Init
            elementorFrontend.hooks.addAction('elementor/frontend/init', function () {
            });
            elementorFrontend.hooks.addAction('frontend/element_ready/mtc_road_map.default', function ($scope) {
                mtc_init_v_app();
            });
            elementorFrontend.hooks.addAction('frontend/element_ready/mtc_text_boxes.default', function ($scope) {
                mtc_init_v_app();
            });
        }, 300);

    }

});