Just the modal from where these tokens can be chosen and some javascript for the 1inch plugin.
<div class="modal" id="token_modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Select token</h5>
<button
id="modal_close"
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="token_list"></div>
</div>
</div>
</div>
</div>
let currentTrade = {};
let currentSelectSide;
let tokens;
async function init() {
await Moralis.start({ serverUrl, appId });
if(!Moralis.isWeb3Enabled()){
await Moralis.enableWeb3()
}
await listAvailableTokens();
currentUser = Moralis.User.current();
if (currentUser) {
document.getElementById("swap_button").disabled = false;
}
}
async function listAvailableTokens() {
const result = await Moralis.Plugins.oneInch.getSupportedTokens({
chain: "eth", // The blockchain you want to use (eth/bsc/polygon)
});
tokens = result.tokens;
tokens["0xacfc95585d80ab62f67a14c566c1b7a49fe91167"] = {
address: "0xacfc95585d80ab62f67a14c566c1b7a49fe91167",
decimals: 18,
logoURI: "https://s2.coinmarketcap.com/static/img/coins/64x64/8397.png",
name: "FEG Token",
symbol: "FEG",
};
tokens["0x42981d0bfbAf196529376EE702F2a9Eb9092fcB5"] = {
address: "0x42981d0bfbAf196529376EE702F2a9Eb9092fcB5",
decimals: 18,
logoURI: "https://s2.coinmarketcap.com/static/img/coins/64x64/16162.png",
name: "SafeMoon V2",
symbol: "SafeMoon",
};
let parent = document.getElementById("token_list");
for (const address in tokens) {
let token = tokens[address];
let div = document.createElement("div");
div.setAttribute("data-address", address);
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);
}
}
function selectToken(address) {
closeModal();
console.log(tokens);
currentTrade[currentSelectSide] = tokens[address];
console.log(currentTrade);
renderInterface();
getQuote();
}
function renderInterface() {
if (currentTrade.from) {
document.getElementById("from_token_img").src = currentTrade.from.logoURI;
document.getElementById("from_token_text").innerHTML =
currentTrade.from.symbol;
}
if (currentTrade.to) {
document.getElementById("to_token_img").src = currentTrade.to.logoURI;
document.getElementById("to_token_text").innerHTML = currentTrade.to.symbol;
}
}