0

I have a library in JS at this path in a module.

magento2\app\code\vendor_name\module_name\view\frontend\web\script.js

And it is initialised to the header with the following code:

checkout_index_index.xml

       <script src="Roman_hello::js/view/hello-init.js"/> 
</head>

And require-config.js file in vendor_name\module_name\view\frontend

with the following code:

var config = {
    map: {
        '*': {
            lazyloadScript:'vendorname_modelname::library/dist/libscript.min.js'
        }
    }
};

And on click i call the initialised library to the default.js at this path.

vendor_name\module_name\view\frontend\web\js\view\payment\default.js

but as always this gives error default.js:31

Uncaught (in promise) ReferenceError: default_var is not defined at default.js:31

below is the default.js file.

define(
    [
        'uiComponent',
        'Magento_Checkout/js/model/payment/renderer-list'
    ],
    function (
        Component,
        rendererList
    ) {
        'use strict';
        rendererList.push(
            {
                type: 'payment',
                component: 'vendor_module/js/view/payment/method-renderer/iostpay-method'
            }
        );
        return Component.extend({});
    }
);
 function log(msg) {

      console.log( msg ) ;
    }
 var transfer;
    document.addEventListener("DOMContentLoaded", async function(event) {
      await new Promise(done => setTimeout(() => done(), 500));

      IWalletJS.enable().then(function(account) {
        if(!account) return;

    const iost = IWalletJS.newIOST(IOST);

        transfer = function() {

          const tx = iost.callABI("token.iost", "transfer", ["iost", account, 'account****', "10", "dapp test memo"]);
          tx.addApprove("iost", "10");

          console.log(tx.getApproveList());
          iost.signAndSend(tx)
            .on('pending', function(txid) {
              log("txid: " + txid);

            })
            .on('success', function(result) {
              log("res: " + JSON.stringify(result));

            })
            .on('failed', function(failed) {
              log("failed: " + JSON.stringify(failed));

            })
        }


      })
    })

what thing am I missing?

7
  • can you post default.js code. Commented Nov 1, 2019 at 11:07
  • define( [ 'uiComponent', 'Magento_Checkout/js/model/payment/renderer-list' ], function ( Component, rendererList ) { 'use strict'; rendererList.push( { type: 'iostpay', component: 'Iostpay_Iostpaymagento/js/view/payment/method-renderer/iostpay-method' } ); return Component.extend({}); } ); const iost = IWalletJS.newIOST(IOST); I need this IOST to be initialised. Thanks
    – Garry
    Commented Nov 1, 2019 at 11:11
  • is this default.js code? there is no 31 line Commented Nov 1, 2019 at 11:50
  • ` const iost = IWalletJS.newIOST(IOST); ` This is the code. I want to initialise the IOST in default.js at this path ` vendor_name\module_name\view\frontend\web\js\view\payment `.
    – Garry
    Commented Nov 1, 2019 at 11:54
  • I have shortened this code, as no more characters were left to comment.
    – Garry
    Commented Nov 1, 2019 at 11:55

1 Answer 1

1

adding header from checkout_index_index.xml

 <head>
     <link src="Iostpay_Iostpaymagento::js/hello.min.js"/>     
     <link src="Iostpay_Iostpaymagento::js/test_func.js"/>   
 </head> 

And instead of import function used

    require(['abc']); 

and this initialised the class in the test_func.js file. In the plain HTML page although the import of class was not required, in magento2 importing of the class made things working fine enter code here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.