Hey Guys Having been following the tutorials on youtube and notice some changes in the codes.
managed to get this far but now failing to get the token in the 1st modal select option
any help here would be much appreciated
/** Connect to Moralis server */
const serverUrl = âxxxxâ;
const appId = âxxxxxâ;
Moralis.start({ serverUrl, appId });
async function init(){
await Moralis.initPlugins();
const web3Provider = await Moralis.enableWeb3();
// Get a (ethers.js) web3Provider
}
async function ListAvailableTokes(){
const result = await Moralis.Plugins.oneInch.getSupportedTokens({
chain: âbscâ, // The blockchain you want to use (eth/bsc/polygon)
});
console.log(tokens);
const tokens = result.tokens;
let parent = document.getElementById(âtoken_listâ);
for (const bscAddress in tokens){
let token = tokens [address];
let div = document.createElement(âdivâ);
div.className = âtoken rowâ;
let html = <img class="token_list_img" src="${token.logoURI}"> <span class="token_list_text">${token.symbol}</span>
;
div.innerHTML = html;
div.onclick = () => {
selectToken(address);
};
parent.appendChild(div);
}
}
/** Add from here down */
async function login() {
let user = Moralis.User.current();
if (!user) {
try {user = await Moralis.authenticate({ signingMessage: âWelcome to Nektrâ })
console.log(user)
}
catch(error) {
console.log(error)
}
}
}
async function logOut() {
await Moralis.User.logOut();
console.log(âlogged outâ);
}
function openmodal(){
document.getElementById(âtoken_modalâ).style.display=âblockâ
}
function closemodal(){
document.getElementById(âtoken_modalâ).style.display=ânoneâ
}
init();
document.getElementById(âmodal_closeâ).onclick = closemodal;
document.getElementById(âto_select_amountâ).onclick = openmodal;
document.getElementById(âbtn-loginâ).onclick = login;
document.getElementById(âbtn-logoutâ).onclick = logOut;
INDEX FILE:
Nektr DX V1 <div class="container-fluid">
<img class="Logo" src="Pictures/android-chrome-192x192.png" width="50px" height="50px">
<a class="navbar-brand" href="#">Nektr DEX v1</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarSupportedContent" style="justify-content: center;">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 " justify-content: center;> </ul>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Swap</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Wallet</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">NFTS</a>
</li>
</div>
<div>
<button id="btn-login" class="btn btn-outline-primary my-2 my-sm-0">Metamask Login</button>
<button id="btn-logout" class="btn btn-outline-primary my-2 my-sm-0">Logout</button>
</div>
</div>
</nav>
<div calss="contrainer">
<div class="row">
<div class="col col-md-6 offset-md-3" id="window">
<h4>Swap</h4>
<div id="form">
<div class="swapbox">
<div class="select amount token_select" id="to_select_amount" style="width: 50%; float: left;"> ETH
</div>
<div class="select amount" id="select_from_amount" style="width: 50%; float: left;">
<input class="number form-control" placeholder="amount" id="from_amout" >
</div>
</div>
<div class="swapbox">
<div class="select amount token_select" id="from_select_amount" style="width: 50%; float: left;"> BNB
</div>
<div class="select amount" id="select_to_amount" style="width: 50%; float: left;">
<input class="number form-control" placeholder="amount" id="from_amout">
</div>
</div>
<button id="btn-Transfer" class="btn btn-outline-primary btn-block">Transfer</button>
</div>
</div>
</div>
</div>
<div class="modal" id="token_modal" tabindex="-1" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Select Token</h5>
<button id="modal_close"type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="token_list"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="./main.js"></script>