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?
default.js
code.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